1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-25 01:20:30 +00:00

Migrate some old macros to new syntax (#8768)

* Migrate some old macros to new syntax

* Rewrite more macros.

* Update image-picker

* Rewrite tabs macro

* Use more new syntax

* Revert thumbnail macro

* Avoid duplicated whitespace pragma

* Revert tabs macro
This commit is contained in:
Leilei332 2024-12-05 20:40:13 +08:00 committed by GitHub
parent 673a0f5605
commit 2801eee905
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 102 additions and 115 deletions

View File

@ -1,58 +1,55 @@
title: $:/core/macros/colour-picker
tags: $:/tags/Macro
\define colour-picker-update-recent()
\procedure colour-picker-update-recent()
<$action-listops
$tiddler="$:/config/ColourPicker/Recent"
$subfilter="$(colour-picker-value)$ [list[$:/config/ColourPicker/Recent]remove[$(colour-picker-value)$]] +[limit[8]]"
$subfilter="[<colour-picker-value>] [list[$:/config/ColourPicker/Recent]remove<colour-picker-value>] +[limit[8]]"
/>
\end
\define colour-picker-inner(actions)
<$button tag="a" tooltip="""$(colour-picker-value)$""">
$(colour-picker-update-recent)$
<$transclude $variable="__actions__"/>
<span style="display:inline-block; background-color: $(colour-picker-value)$; width: 100%; height: 100%; border-radius: 50%;"/>
\procedure colour-picker-inner(actions)
<$button tag="a" tooltip=<<colour-picker-value>>>
<<colour-picker-update-recent>>
<$transclude $variable="actions"/>
<span style.display="inline-block" style.backgroundColor=<<colour-picker-value>> style.width="100%" style.height="100%" style.borderRadius="50%"/>
</$button>
\end
\define colour-picker-recent-inner(actions)
\whitespace trim
<$set name="colour-picker-value" value="$(recentColour)$">
<$macrocall $name="colour-picker-inner" actions=<<__actions__>>/>
\procedure colour-picker-recent-inner(actions)
<$set name="colour-picker-value" value=<<recentColour>>>
<$transclude $variable="colour-picker-inner" actions=<<actions>>/>
</$set>
\end
\define colour-picker-recent(actions)
\whitespace trim
\procedure colour-picker-recent(actions)
{{$:/language/ColourPicker/Recent}}<$list filter="[list[$:/config/ColourPicker/Recent]]" variable="recentColour">
&#32;
<$macrocall $name="colour-picker-recent-inner" actions=<<__actions__>>/>
<$transclude $variable="colour-picker-recent-inner" actions=<<actions>>/>
</$list>
\end
\define colour-picker(actions)
\whitespace trim
\procedure colour-picker(actions)
<div class="tc-colour-chooser">
<$macrocall $name="colour-picker-recent" actions=<<__actions__>>/>
<$transclude $variable="colour-picker-recent" actions=<<actions>>/>
---
<$list filter="LightPink Pink Crimson LavenderBlush PaleVioletRed HotPink DeepPink MediumVioletRed Orchid Thistle Plum Violet Magenta Fuchsia DarkMagenta Purple MediumOrchid DarkViolet DarkOrchid Indigo BlueViolet MediumPurple MediumSlateBlue SlateBlue DarkSlateBlue Lavender GhostWhite Blue MediumBlue MidnightBlue DarkBlue Navy RoyalBlue CornflowerBlue LightSteelBlue LightSlateGrey SlateGrey DodgerBlue AliceBlue SteelBlue LightSkyBlue SkyBlue DeepSkyBlue LightBlue PowderBlue CadetBlue Azure LightCyan PaleTurquoise Cyan Aqua DarkTurquoise DarkSlateGrey DarkCyan Teal MediumTurquoise LightSeaGreen Turquoise Aquamarine MediumAquamarine MediumSpringGreen MintCream SpringGreen MediumSeaGreen SeaGreen Honeydew LightGreen PaleGreen DarkSeaGreen LimeGreen Lime ForestGreen Green DarkGreen Chartreuse LawnGreen GreenYellow DarkOliveGreen YellowGreen OliveDrab Beige LightGoldenrodYellow Ivory LightYellow Yellow Olive DarkKhaki LemonChiffon PaleGoldenrod Khaki Gold Cornsilk Goldenrod DarkGoldenrod FloralWhite OldLace Wheat Moccasin Orange PapayaWhip BlanchedAlmond NavajoWhite AntiqueWhite Tan BurlyWood Bisque DarkOrange Linen Peru PeachPuff SandyBrown Chocolate SaddleBrown Seashell Sienna LightSalmon Coral OrangeRed DarkSalmon Tomato MistyRose Salmon Snow LightCoral RosyBrown IndianRed Red Brown FireBrick DarkRed Maroon White WhiteSmoke Gainsboro LightGrey Silver DarkGrey Grey DimGrey Black" variable="colour-picker-value">
&#32;
<$macrocall $name="colour-picker-inner" actions=<<__actions__>>/>
<$transclude $variable="colour-picker-inner" actions=<<actions>>/>
</$list>
---
<$edit-text tiddler="$:/config/ColourPicker/New" tag="input" default="" placeholder=""/>
&#32;
<$edit-text tiddler="$:/config/ColourPicker/New" tag="input" default="" placeholder="" class="tc-tiny-gap-right"/>
<$edit-text tiddler="$:/config/ColourPicker/New" type="color" tag="input"/>
<$set name="colour-picker-value" value={{$:/config/ColourPicker/New}}>
<$macrocall $name="colour-picker-inner" actions=<<__actions__>>/>
<%if [{$:/config/ColourPicker/New}!is[blank]] %>
<$transclude $variable="colour-picker-inner" actions=<<actions>>/>
<%endif%>
</$set>
</div>

View File

@ -1,7 +1,7 @@
title: $:/core/macros/dumpvariables
tags: $:/tags/Macro
\define dumpvariables()
\procedure dumpvariables()
\whitespace trim
<ul>
<$list filter="[variables[]]" variable="varname">

View File

@ -1,39 +1,36 @@
created: 20170715180840889
modified: 20170715180914005
tags: $:/tags/Macro
title: $:/core/macros/image-picker
type: text/vnd.tiddlywiki
\define image-picker-thumbnail(actions)
<$button tag="a" tooltip="""$(imageTitle)$"""><$transclude $variable="__actions__"/><$transclude tiddler=<<imageTitle>>/></$button>
\procedure image-picker-thumbnail(actions)
<$button tag="a" tooltip=<<imageTitle>>><$transclude $variable="actions"/><$transclude tiddler=<<imageTitle>>/></$button>
\end
\define image-picker-list(filter,actions)
\procedure image-picker-list(filter,actions)
\whitespace trim
<$list filter="""$filter$""" variable="imageTitle">
<$macrocall $name="image-picker-thumbnail" actions=<<__actions__>>/>
<$list filter=<<filter>> variable="imageTitle">
<$transclude $variable="image-picker-thumbnail" actions=<<actions>>/>
&#32;
</$list>
\end
\define image-picker(actions,filter:"[all[shadows+tiddlers]is[image]] -[type[application/pdf]] +[!has[draft.of]$subfilter$sort[title]]",subfilter:"")
\procedure image-picker(actions,filter:"[all[shadows+tiddlers]is[image]] -[type[application/pdf]] +[!has[draft.of]$subfilter$sort[title]]",subfilter:"")
\whitespace trim
<div class="tc-image-chooser">
<$vars state-system=<<qualify "$:/state/image-picker/system">>>
<$let state-system=<<qualify "$:/state/image-picker/system">> tv-filter={{{ [<filter>search-replace[$subfilter$],<subfilter>] }}}>
<$checkbox tiddler=<<state-system>> field="text" checked="show" unchecked="hide" default="hide">
&#32;
{{$:/language/SystemTiddlers/Include/Prompt}}
<span class="tc-tiny-gap-left">{{$:/language/SystemTiddlers/Include/Prompt}}</span>
</$checkbox>
<$reveal state=<<state-system>> type="match" text="hide" default="hide" tag="div">
<$macrocall $name="image-picker-list" filter="""$filter$ +[!is[system]]""" actions=<<__actions__>>/>
<$transclude $variable="image-picker-list" filter=`$(tv-filter)$ +[!is[system]]` actions=<<actions>>/>
</$reveal>
<$reveal state=<<state-system>> type="nomatch" text="hide" default="hide" tag="div">
<$macrocall $name="image-picker-list" filter="""$filter$""" actions=<<__actions__>>/>
<$transclude $variable="image-picker-list" filter=<<tv-filter>> actions=<<actions>>/>
</$reveal>
</$vars>
</$let>
</div>
\end
\define image-picker-include-tagged-images(actions)
<$macrocall $name="image-picker" filter="[all[shadows+tiddlers]is[image]] [all[shadows+tiddlers]tag[$:/tags/Image]] -[type[application/pdf]] +[!has[draft.of]sort[title]]" actions=<<__actions__>>/>
\procedure image-picker-include-tagged-images(actions)
<$transclude $variable="image-picker" filter="[all[shadows+tiddlers]is[image]] [all[shadows+tiddlers]tag[$:/tags/Image]] -[type[application/pdf]] +[!has[draft.of]sort[title]]" actions=<<actions>>/>
\end

View File

@ -1,14 +1,18 @@
title: $:/core/macros/list
tags: $:/tags/Macro
\define list-links(filter,type:"ul",subtype:"li",class:"",emptyMessage,field:"caption")
\procedure list-links-draggable-drop-actions()
<$action-listops $tiddler=<<targetTiddler>> $field=<<targetField>> $subfilter="+[insertbefore<actionTiddler>,<currentTiddler>]"/>
\end
\whitespace trim
<$genesis $type=<<__type__>> class=<<__class__>>>
<$list filter=<<__filter__>> emptyMessage=<<__emptyMessage__>>>
<$genesis $type=<<__subtype__>>>
\procedure list-links(filter,type:"ul",subtype:"li",class:"",emptyMessage,field:"caption")
<$genesis $type=<<type>> class=<<class>>>
<$list filter=<<filter>> emptyMessage=<<emptyMessage>>>
<$genesis $type=<<subtype>>>
<$link to={{!!title}}>
<$let tv-wikilinks="no">
<$transclude field=<<__field__>>>
<$transclude field=<<field>>>
<$view field="title"/>
</$transclude>
</$let>
@ -18,24 +22,19 @@ tags: $:/tags/Macro
</$genesis>
\end
\define list-links-draggable-drop-actions()
<$action-listops $tiddler=<<targetTiddler>> $field=<<targetField>> $subfilter="+[insertbefore<actionTiddler>,<currentTiddler>]"/>
\end
\define list-links-draggable(tiddler,field:"list",emptyMessage,type:"ul",subtype:"li",class:"",itemTemplate)
\whitespace trim
\procedure list-links-draggable(tiddler,field:"list",emptyMessage,type:"ul",subtype:"li",class:"",itemTemplate)
<span class="tc-links-draggable-list">
<$vars targetTiddler="""$tiddler$""" targetField="""$field$""">
<$genesis $type=<<__type__>> class="$class$">
<$list filter="[list[$tiddler$!!$field$]]" emptyMessage=<<__emptyMessage__>>>
<$let targetTiddler=<<tiddler>> targetField=<<field>>>
<$genesis $type=<<type>> class=<<class>>>
<$list filter="[<tiddler>get<field>enlist-input[]]" emptyMessage=<<emptyMessage>>>
<$droppable
actions=<<list-links-draggable-drop-actions>>
tag="""$subtype$"""
tag=<<subtype>>
enable=<<tv-enable-drag-and-drop>>
>
<div class="tc-droppable-placeholder"/>
<div>
<$transclude tiddler="""$itemTemplate$""">
<$transclude tiddler=<<itemTemplate>>>
<$link to={{!!title}}>
<$let tv-wikilinks="no">
<$transclude field="caption">
@ -60,50 +59,48 @@ tags: $:/tags/Macro
</$droppable>
</$tiddler>
</$genesis>
</$vars>
</$let>
</span>
\end
\define list-tagged-draggable-drop-actions(tag)
\whitespace trim
\procedure list-tagged-draggable-drop-actions(tag)
<!-- Save the current ordering of the tiddlers with this tag -->
<$set name="order" filter="[<__tag__>tagging[]]">
<$set name="order" filter="[<tag>tagging[]]">
<!-- Remove any list-after or list-before fields from the tiddlers with this tag -->
<$list filter="[<__tag__>tagging[]]">
<$list filter="[<tag>tagging[]]">
<$action-deletefield $field="list-before"/>
<$action-deletefield $field="list-after"/>
</$list>
<!-- Save the new order to the Tag Tiddler -->
<$action-listops $tiddler=<<__tag__>> $field="list" $filter="+[enlist<order>] +[insertbefore<actionTiddler>,<currentTiddler>]"/>
<$action-listops $tiddler=<<tag>> $field="list" $filter="+[enlist<order>] +[insertbefore<actionTiddler>,<currentTiddler>]"/>
<!-- Make sure the newly added item has the right tag -->
<!-- Removing this line makes dragging tags within the dropdown work as intended -->
<!--<$action-listops $tiddler=<<actionTiddler>> $tags=<<__tag__>>/>-->
<!--<$action-listops $tiddler=<<actionTiddler>> $tags=<<tag>>/>-->
<!-- Using the following 5 lines as replacement makes dragging titles from outside into the dropdown apply the tag -->
<$list filter="[<actionTiddler>!contains:tags<__tag__>]">
<$list filter="[<actionTiddler>!contains:tags<tag>]">
<$fieldmangler tiddler=<<actionTiddler>>>
<$action-sendmessage $message="tm-add-tag" $param=<<__tag__>>/>
<$action-sendmessage $message="tm-add-tag" $param=<<tag>>/>
</$fieldmangler>
</$list>
</$set>
\end
\define list-tagged-draggable(tag,subFilter,emptyMessage,itemTemplate,elementTag:"div",storyview:"")
\whitespace trim
\procedure list-tagged-draggable(tag,subFilter,emptyMessage,itemTemplate,elementTag:"div",storyview:"")
<span class="tc-tagged-draggable-list">
<$set name="tag" value=<<__tag__>>>
<$set name="tag" value=<<tag>>>
<$list
filter="[<__tag__>tagging[]$subFilter$]"
emptyMessage=<<__emptyMessage__>>
storyview=<<__storyview__>>
filter=`[<tag>tagging[]$(subFilter)$]`
emptyMessage=<<emptyMessage>>
storyview=<<storyview>>
>
<$genesis $type=<<__elementTag__>> class="tc-menu-list-item">
<$genesis $type=<<elementTag>> class="tc-menu-list-item">
<$droppable
actions="""<$macrocall $name="list-tagged-draggable-drop-actions" tag=<<__tag__>>/>"""
actions="""<$macrocall $name="list-tagged-draggable-drop-actions" tag=<<tag>>/>"""
enable=<<tv-enable-drag-and-drop>>
>
<$genesis $type=<<__elementTag__>> class="tc-droppable-placeholder"/>
<$genesis $type=<<__elementTag__>>>
<$transclude tiddler="""$itemTemplate$""">
<$genesis $type=<<elementTag>> class="tc-droppable-placeholder"/>
<$genesis $type=<<elementTag>>>
<$transclude tiddler=<<itemTemplate>>>
<$link to={{!!title}}>
<$view field="title"/>
</$link>
@ -114,11 +111,11 @@ tags: $:/tags/Macro
</$list>
<$tiddler tiddler="">
<$droppable
actions="""<$macrocall $name="list-tagged-draggable-drop-actions" tag=<<__tag__>>/>"""
actions="""<$macrocall $name="list-tagged-draggable-drop-actions" tag=<<tag>>/>"""
enable=<<tv-enable-drag-and-drop>>
>
<$genesis $type=<<__elementTag__>> class="tc-droppable-placeholder"/>
<$genesis $type=<<__elementTag__>> style="height:0.5em;"/>
<$genesis $type=<<elementTag>> class="tc-droppable-placeholder"/>
<$genesis $type=<<elementTag>> style="height:0.5em;"/>
</$droppable>
</$tiddler>
</$set>

View File

@ -1,28 +1,28 @@
title: $:/core/macros/translink
tags: $:/tags/Macro
\define translink(title,mode:"block")
\procedure translink(title,mode:"block")
\whitespace trim
<$list filter="[<__mode__>match[block]]">
<%if [<mode>match[block]] %>
<div class="tc-translink">
<div>
<$link to="""$title$""">
<h1><$text text="""$title$"""/></h1>
<$link to=<<title>>>
<h1><$text text=<<title>>/></h1>
</$link>
<$transclude tiddler="""$title$""" mode="block">
<$set name="currentTiddler" value="""$title$"""><$transclude tiddler="$:/language/MissingTiddler/Hint"/></$set>
<$transclude tiddler=<<title>> mode="block">
<$set name="currentTiddler" value=<<title>>><$transclude tiddler="$:/language/MissingTiddler/Hint"/></$set>
</$transclude>
</div>
</div>
</$list>
<$list filter="[<__mode__>match[inline]]">
<%endif%>
<%if [<mode>match[inline]] %>
<span class="tc-translink">
<$link to="""$title$""">
<$text text="""$title$"""/>
<$link to=<<title>> class="tc-tiny-gap-right">
<$text text=<<title>>/>
</$link>
&#32;(<$transclude tiddler="""$title$""" mode="inline">
<$set name="currentTiddler" value="""$title$"""><$transclude tiddler="$:/language/MissingTiddler/Hint"/></$set>
(<$transclude tiddler=<<title>> mode="inline">
<$set name="currentTiddler" value=<<title>>><$transclude tiddler="$:/language/MissingTiddler/Hint"/></$set>
</$transclude>)
</span>
</$list>
<%endif%>
\end

View File

@ -1,62 +1,58 @@
title: $:/core/macros/tree
tags: $:/tags/Macro
\define leaf-link(full-title,chunk,separator: "/")
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
\procedure leaf-link(full-title,chunk,separator: "/")
<$link to=<<full-title>>><$text text=<<chunk>>/></$link>
\end
\define leaf-node(prefix,chunk)
\whitespace trim
\procedure leaf-node(prefix,chunk)
<li>
<$list filter="[<__prefix__>addsuffix<__chunk__>is[shadow]] [<__prefix__>addsuffix<__chunk__>is[tiddler]]" variable="full-title">
<$list filter="[<full-title>removeprefix<__prefix__>]" variable="chunk">
<span>{{$:/core/images/file}}</span>&#32;<$macrocall $name="leaf-link" full-title=<<full-title>> chunk=<<chunk>>/>
<$list filter="[<prefix>addsuffix<chunk>is[shadow]] [<prefix>addsuffix<chunk>is[tiddler]]" variable="full-title">
<$list filter="[<full-title>removeprefix<prefix>]" variable="chunk">
<span class="tc-tiny-gap-right">{{$:/core/images/file}}</span><$transclude $variable="leaf-link" full-title=<<full-title>> chunk=<<chunk>>/>
</$list>
</$list>
</li>
\end
\define branch-node(prefix,chunk,separator: "/")
\whitespace trim
\procedure branch-node(prefix,chunk,separator: "/")
<li>
<$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<prefix>addsuffix<chunk>] }}}>
<$reveal type="nomatch" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="show" class="tc-btn-invisible">
{{$:/core/images/folder}}&#32;<$text text=<<__chunk__>>/>
{{$:/core/images/folder}}&#32;<$text text=<<chunk>>/>
</$button>
</$reveal>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="hide" class="tc-btn-invisible">
{{$:/core/images/folder}}&#32;<$text text=<<__chunk__>>/>
{{$:/core/images/folder}}&#32;<$text text=<<chunk>>/>
</$button>
</$reveal>
&#32;
<span>(<$count filter="[all[shadows+tiddlers]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>)</span>
<span class="tc-tiny-gap-left">(<$count filter="[all[shadows+tiddlers]removeprefix<prefix>removeprefix<chunk>] -[<prefix>addsuffix<chunk>]"/>)</span>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
<$transclude $variable="tree-node" prefix={{{ [<prefix>addsuffix<chunk>] }}} separator=<<separator>>/>
</$reveal>
</$set>
</li>
\end
\define tree-node(prefix,separator: "/")
\whitespace trim
\procedure tree-node(prefix,separator: "/")
<ol>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
<$list filter="[all[shadows+tiddlers]removeprefix<prefix>splitbefore<separator>sort[]!suffix<separator>]" variable="chunk">
<$transclude $variable="leaf-node" prefix=<<prefix>> chunk=<<chunk>> separator=<<separator>>/>
</$list>
<$list filter="[all[shadows+tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sort[]suffix<__separator__>]" variable="chunk">
<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
<$list filter="[all[shadows+tiddlers]removeprefix<prefix>splitbefore<separator>sort[]suffix<separator>]" variable="chunk">
<$transclude $variable="branch-node" prefix=<<prefix>> chunk=<<chunk>> separator=<<separator>>/>
</$list>
</ol>
\end
\define tree(prefix: "$:/",separator: "/")
\whitespace trim
\procedure tree(prefix: "$:/",separator: "/")
<div class="tc-tree">
<span><$text text=<<__prefix__>>/></span>
<span><$text text=<<prefix>>/></span>
<div>
<$macrocall $name="tree-node" prefix=<<__prefix__>> separator=<<__separator__>>/>
<$transclude $variable="tree-node" prefix=<<prefix>> separator=<<separator>>/>
</div>
</div>
\end