From 6701683ddf5380a14eccf708363c1a07bf4c3d50 Mon Sep 17 00:00:00 2001 From: Cameron Fischer Date: Fri, 1 Apr 2022 07:09:59 -0400 Subject: [PATCH] Trim saga: The big macros (#6269) * adding trim: large macros and languageswitcher * adding trim: KeyboardShortcuts.tid * Hidden space to force some macros to be inline This'll be our little secret. This single byte will actually allow the uglifier to trim over thirty bytes while condensing. I know I'm not supposed to optimize TW for some 3rd party plugin, but I'm the one doing the whitespace trim work, so I'll give myself this. * More consistent nested quoting --- core/ui/ControlPanel/KeyboardShortcuts.tid | 25 +++++++++++----- core/wiki/languageswitcher.tid | 2 ++ core/wiki/macros/diff.tid | 7 +++-- core/wiki/macros/keyboard-driven-input.tid | 34 ++++++++++++++-------- core/wiki/macros/toc.tid | 31 +++++++++++++++----- 5 files changed, 69 insertions(+), 30 deletions(-) diff --git a/core/ui/ControlPanel/KeyboardShortcuts.tid b/core/ui/ControlPanel/KeyboardShortcuts.tid index 764d69b05..83cce70d9 100644 --- a/core/ui/ControlPanel/KeyboardShortcuts.tid +++ b/core/ui/ControlPanel/KeyboardShortcuts.tid @@ -5,8 +5,11 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \define lingo-base() $:/language/ControlPanel/KeyboardShortcuts/ \define new-shortcut(title) +\whitespace trim
-<$edit-shortcut tiddler="$title$" placeholder={{$:/language/ControlPanel/KeyboardShortcuts/Add/Prompt}} focus="true" style="width:auto;"/> <$button> +<$edit-shortcut tiddler="$title$" placeholder={{$:/language/ControlPanel/KeyboardShortcuts/Add/Prompt}} focus="true" style="width:auto;"/> + +<$button> <> <$action-listops $tiddler="$(shortcutTitle)$" @@ -21,6 +24,7 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \end \define shortcut-list-item(caption) +\whitespace trim @@ -31,16 +35,16 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} <$button popup=<> class="tc-btn-invisible"> {{$:/core/images/edit-button}} + <$macrocall $name="displayshortcuts" $output="text/html" shortcuts={{$(shortcutTitle)$}} prefix="" separator=" " suffix=""/> <$reveal state=<> type="popup" position="below" animate="yes">
-<$list filter="[list[$(shortcutTitle)$!!text]sort[title]]" variable="shortcut" emptyMessage=""" -
-//<>// -
-"""> +<$list + filter="[list[$(shortcutTitle)$!!text]sort[title]]" + variable="shortcut" + emptyMessage="
//<>//
">
<$button class="tc-btn-invisible" tooltip={{$:/language/ControlPanel/KeyboardShortcuts/Remove/Hint}}> <$action-listops @@ -50,6 +54,7 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} /> {{$:/core/images/close-button}} + <$macrocall $name="displayshortcuts" $output="text/html" shortcuts=<>/> @@ -65,6 +70,7 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \end \define shortcut-list(caption,prefix) +\whitespace trim <$list filter="[[$prefix$$(shortcutName)$]]" variable="shortcutTitle"> <> @@ -73,7 +79,8 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \end \define shortcut-editor() -<> +\whitespace trim +<> <> <> <> @@ -87,6 +94,7 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \end \define shortcut-item-inner() +\whitespace trim <$reveal type="nomatch" state=<> text="open"> @@ -107,6 +115,7 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} {{$:/core/images/down-arrow}} + ''<$text text=<>/>'' @@ -126,10 +135,12 @@ caption: {{$:/language/ControlPanel/KeyboardShortcuts/Caption}} \end \define shortcut-item() +\whitespace trim <$set name="dropdownStateTitle" value=<>> <> \end +\whitespace trim diff --git a/core/wiki/languageswitcher.tid b/core/wiki/languageswitcher.tid index 8df13bf31..48422fca1 100644 --- a/core/wiki/languageswitcher.tid +++ b/core/wiki/languageswitcher.tid @@ -3,6 +3,7 @@ title: $:/snippets/languageswitcher \define flag-title() $(languagePluginTitle)$/icon \end +\whitespace trim <$linkcatcher to="$:/language">
@@ -18,6 +19,7 @@ $(languagePluginTitle)$/icon + <$view field="description"> <$view field="name"> <$view field="title"/> diff --git a/core/wiki/macros/diff.tid b/core/wiki/macros/diff.tid index 50dd8bc2d..36564d084 100644 --- a/core/wiki/macros/diff.tid +++ b/core/wiki/macros/diff.tid @@ -2,6 +2,7 @@ title: $:/core/macros/diff tags: $:/tags/Macro \define compareTiddlerText(sourceTiddlerTitle,sourceSubTiddlerTitle,destTiddlerTitle,destSubTiddlerTitle) +\whitespace trim <$set name="source" tiddler=<<__sourceTiddlerTitle__>> subtiddler=<<__sourceSubTiddlerTitle__>>> <$set name="dest" tiddler=<<__destTiddlerTitle__>> subtiddler=<<__destSubTiddlerTitle__>>> <$diff-text source=<> dest=<>/> @@ -10,6 +11,7 @@ tags: $:/tags/Macro \end \define compareTiddlers(sourceTiddlerTitle,sourceSubTiddlerTitle,destTiddlerTitle,destSubTiddlerTitle,exclude) +\whitespace trim
<$set name="sourceFields" filter="[<__sourceTiddlerTitle__>fields[]sort[]]"> @@ -17,13 +19,12 @@ tags: $:/tags/Macro <$list filter="[enlist] [enlist] -[enlist<__exclude__>] +[sort[]]" variable="fieldName"> diff --git a/core/wiki/macros/keyboard-driven-input.tid b/core/wiki/macros/keyboard-driven-input.tid index b0a7ac9c0..f7563996a 100644 --- a/core/wiki/macros/keyboard-driven-input.tid +++ b/core/wiki/macros/keyboard-driven-input.tid @@ -2,17 +2,21 @@ title: $:/core/macros/keyboard-driven-input tags: $:/tags/Macro \define change-input-tab(stateTitle,tag,beforeafter,defaultState,actions) +\whitespace trim <$set name="tabsList" filter="[all[shadows+tiddlers]tag<__tag__>!has[draft.of]]"> -<$vars currentState={{{ [<__stateTitle__>!is[missing]get[text]] ~[<__defaultState__>] }}} firstTab={{{ [enlistnth[1]] }}} lastTab={{{ [enlistlast[]] }}}> -<$set name="nextTab" value={{{ [all[shadows+tiddlers]tag<__tag__>!has[draft.of]$beforeafter$] ~[[$beforeafter$]removeprefix[after]suffix[]addprefix] ~[[$beforeafter$]removeprefix[before]suffix[]addprefix] }}}> +<$let + currentState={{{ [<__stateTitle__>!is[missing]get[text]] ~[<__defaultState__>] }}} + firstTab={{{ [enlistnth[1]] }}} + lastTab={{{ [enlistlast[]] }}} + nextTab={{{ [all[shadows+tiddlers]tag<__tag__>!has[draft.of]$beforeafter$] ~[[$beforeafter$]removeprefix[after]suffix[]addprefix] ~[[$beforeafter$]removeprefix[before]suffix[]addprefix] }}}> <$action-setfield $tiddler=<<__stateTitle__>> text=<>/> $actions$ - - + \end \define keyboard-input-actions() +\whitespace trim <$list filter="[<__index__>match[]]"> <$action-setfield $tiddler=<<__storeTitle__>> text={{{ [<__tiddler__>get<__field__>] }}}/> @@ -22,6 +26,7 @@ $actions$ \end \define input-next-actions-inner() +\whitespace trim <$list filter="[minlength[1]]" variable="ignore"> <$action-setfield $tiddler=<<__selectionStateTitle__>> text=<>/> <$list filter="[<__index__>match[]]"> @@ -35,12 +40,19 @@ $actions$ \end \define input-next-actions(afterOrBefore:"after",reverse:"") +\whitespace trim <$list filter="[<__storeTitle__>get[text]minlength<__filterMinLength__>] [<__filterMinLength__>match[0]] +[limit[1]]" variable="ignore"> -<$vars userInput={{{ [<__storeTitle__>get[text]] }}} selectedItem={{{ [<__selectionStateTitle__>get[text]] }}}> -<$set name="configTiddler" value={{{ [subfilter<__configTiddlerFilter__>] }}}> -<$vars primaryListFilter={{{ [get<__firstSearchFilterField__>] }}} secondaryListFilter={{{ [get<__secondSearchFilterField__>] }}}> +<$let + userInput={{{ [<__storeTitle__>get[text]] }}} + selectedItem={{{ [<__selectionStateTitle__>get[text]] }}} + configTiddler={{{ [subfilter<__configTiddlerFilter__>] }}} + primaryListFilter={{{ [get<__firstSearchFilterField__>] }}} + secondaryListFilter={{{ [get<__secondSearchFilterField__>] }}}> <$set name="filteredList" filter="[subfilteraddsuffix[-primaryList]] =[subfilteraddsuffix[-secondaryList]]"> -<$vars nextItem={{{ [enlist$afterOrBefore$] ~[enlist$reverse$nth[1]] }}} firstItem={{{ [enlistnth[1]] }}} lastItem={{{ [enlistlast[]] }}}> +<$let + nextItem={{{ [enlist$afterOrBefore$] ~[enlist$reverse$nth[1]] }}} + firstItem={{{ [enlistnth[1]] }}} + lastItem={{{ [enlistlast[]] }}}> <$list filter="[match!match]" variable="ignore"> <$set name="nextItem" value={{{ [[$afterOrBefore$]match[before]thenaddsuffix[-userInput]] ~[] }}}> <> @@ -59,11 +71,9 @@ $actions$ <$list filter="[!match!match]" variable="ignore"> <> - + - - - + \end diff --git a/core/wiki/macros/toc.tid b/core/wiki/macros/toc.tid index c05d64020..470d0b804 100644 --- a/core/wiki/macros/toc.tid +++ b/core/wiki/macros/toc.tid @@ -2,6 +2,7 @@ title: $:/core/macros/toc tags: $:/tags/Macro \define toc-caption() +\whitespace trim <$set name="tv-wikilinks" value="no"> <$transclude field="caption"> <$view field="title"/> @@ -10,9 +11,10 @@ tags: $:/tags/Macro \end \define toc-body(tag,sort:"",itemClassFilter,exclude,path) +\whitespace trim
    <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]"""> - <$vars item=<> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> + <$let item=<> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]"""> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item">
  1. >> @@ -23,7 +25,7 @@ tags: $:/tags/Macro
  2. - +
\end @@ -33,6 +35,7 @@ tags: $:/tags/Macro \end \define toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) +\whitespace trim <$qualify name="toc-state" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item"> @@ -48,6 +51,7 @@ tags: $:/tags/Macro {{$:/core/images/down-arrow}} + <> <$reveal type="match" stateTitle=<> text="open"> @@ -59,6 +63,7 @@ tags: $:/tags/Macro \end \define toc-unlinked-expandable-body(tag,sort:"",itemClassFilter,exclude,path) +\whitespace trim <$qualify name="toc-state" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item"> @@ -66,12 +71,14 @@ tags: $:/tags/Macro <$reveal type="nomatch" stateTitle=<> text="open"> <$button setTitle=<> setTo="open" class="tc-btn-invisible tc-popup-keep"> {{$:/core/images/right-arrow}} + <> <$reveal type="match" stateTitle=<> text="open"> <$button setTitle=<> setTo="close" class="tc-btn-invisible tc-popup-keep"> {{$:/core/images/down-arrow}} + <> @@ -88,7 +95,8 @@ tags: $:/tags/Macro \end \define toc-expandable(tag,sort:"",itemClassFilter:"",exclude,path) -<$vars tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> +\whitespace trim +<$let tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]""">
    <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]"""> @@ -98,10 +106,11 @@ tags: $:/tags/Macro
- + \end \define toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path) +\whitespace trim <$qualify name="toc-state" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item" >
  • >> @@ -118,6 +127,7 @@ tags: $:/tags/Macro + <> <$reveal type="match" stateTitle=<> text="open"> @@ -129,6 +139,7 @@ tags: $:/tags/Macro \end \define toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path) +\whitespace trim <$qualify name="toc-state" title={{{ [[$:/state/toc]addsuffix<__path__>addsuffix[-]addsuffix] }}}> <$set name="toc-item-class" filter=<<__itemClassFilter__>> emptyValue="toc-item-selected" value="toc-item">
  • >> @@ -136,12 +147,14 @@ tags: $:/tags/Macro <$reveal type="nomatch" stateTitle=<> text="open"> <$button setTitle=<> setTo="open" class="tc-btn-invisible tc-popup-keep"> {{$:/core/images/right-arrow}} + <> <$reveal type="match" stateTitle=<> text="open"> <$button setTitle=<> setTo="close" class="tc-btn-invisible tc-popup-keep"> {{$:/core/images/down-arrow}} + <> @@ -159,8 +172,9 @@ tags: $:/tags/Macro \end \define toc-selective-expandable(tag,sort:"",itemClassFilter,exclude,path) -<$vars tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> - <$set name="excluded" filter="""[enlist<__exclude__>] [<__tag__>]"""> +\whitespace trim +<$let tag=<<__tag__>> sort=<<__sort__>> itemClassFilter=<<__itemClassFilter__>> path={{{ [<__path__>addsuffix[/]addsuffix<__tag__>] }}}> + <$set name="excluded" filter="[enlist<__exclude__>] [<__tag__>]">
      <$list filter="""[all[shadows+tiddlers]tag<__tag__>!has[draft.of]$sort$] -[<__tag__>] -[enlist<__exclude__>]"""> <$list filter="[all[current]toc-link[no]]" variable="ignore" emptyMessage=<> > @@ -169,10 +183,11 @@ tags: $:/tags/Macro
    - + \end \define toc-tabbed-external-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"") +\whitespace trim <$tiddler tiddler={{{ [<__selectedTiddler__>get[text]] }}}>
    <$linkcatcher to=<<__selectedTiddler__>>> @@ -196,8 +211,8 @@ tags: $:/tags/Macro \end \define toc-tabbed-internal-nav(tag,sort:"",selectedTiddler:"$:/temp/toc/selectedTiddler",unselectedText,missingText,template:"") +\whitespace trim <$linkcatcher to=<<__selectedTiddler__>>> <$macrocall $name="toc-tabbed-external-nav" tag=<<__tag__>> sort=<<__sort__>> selectedTiddler=<<__selectedTiddler__>> unselectedText=<<__unselectedText__>> missingText=<<__missingText__>> template=<<__template__>>/> \end -
  • -<$text text=<>/> +<$text text=<>/> <$set name="source" tiddler=<<__sourceTiddlerTitle__>> subtiddler=<<__sourceSubTiddlerTitle__>> field=<>> <$set name="dest" tiddler=<<__destTiddlerTitle__>> subtiddler=<<__destSubTiddlerTitle__>> field=<>> -<$diff-text source=<> dest=<>> - +<$diff-text source=<> dest=<>>