1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-10 02:38:06 +00:00

Add some handy drag-and-drop macros

And refactor the tag template to use one of them
This commit is contained in:
Jermolene
2017-03-20 22:11:06 +00:00
parent bea33efd63
commit 5ed7ade44f
2 changed files with 87 additions and 35 deletions

View File

@@ -14,3 +14,87 @@ tags: $:/tags/Macro
</$list>
</$type$>
\end
\define list-links-draggable-drop-actions()
<$action-listops $tiddler=<<targetTiddler>> $field=<<targetField>> $subfilter="+[insertbefore:currentTiddler<actionTiddler>]"/>
\end
\define list-links-draggable(tiddler,field:"list",type:"ul",subtype:"li",class:"",itemTemplate)
<$vars targetTiddler="""$tiddler$""" targetField="""$field$""">
<$type$ class="$class$">
<$list filter="[list[$tiddler$!!$field$]]">
<$droppable actions=<<list-links-draggable-drop-actions>> tag="""$subtype$""">
<div class="tc-droppable-placeholder">
&nbsp;
</div>
<div>
<$link to={{!!title}}>
<$transclude tiddler="""$itemTemplate$""">
<$transclude field="caption">
<$view field="title"/>
</$transclude>
</$transclude>
</$link>
</div>
</$droppable>
</$list>
<$tiddler tiddler="">
<$droppable actions=<<list-links-draggable-drop-actions>> tag="""$subtype$""">
<div class="tc-droppable-placeholder">
&nbsp;
</div>
<div>
&nbsp;
</div>
</$droppable>
</$tiddler>
</$type$>
</$vars>
\end
\define list-tagged-draggable-drop-actions()
<!-- Save the current ordering of the tiddlers with this tag -->
<$set name="order" filter="[<tag>tagging[]]">
<!-- Remove any list-after or list-before fields from the tiddlers with this tag -->
<$list filter="[<tag>tagging[]]">
<$action-deletefield $field="list-before"/>
<$action-deletefield $field="list-after"/>
</$list>
<!-- Assign the list field of the tag with the current ordering -->
<$action-setfield $tiddler=<<tag>> $field="list" $value=<<order>>/>
<!-- Add the newly inserted item to the list -->
<$action-listops $tiddler=<<tag>> $field="list" $subfilter="+[insertbefore:currentTiddler<actionTiddler>]"/>
<!-- Make sure the newly added item has the right tag -->
<$action-listops $tiddler=<<actionTiddler>> $field="tags" $subfilter="+[<tag>]"/>
</$set>
\end
\define list-tagged-draggable(tag,itemTemplate)
<$set name="tag" value="""$tag$""">
<$list filter="[<tag>tagging[]]">
<div class="tc-menu-list-item">
<$droppable actions=<<list-tagged-draggable-drop-actions>>>
<div class="tc-droppable-placeholder">
&nbsp;
</div>
<div>
<$transclude tiddler="""$itemTemplate$""">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</$transclude>
</div>
</$droppable>
</div>
</$list>
<$tiddler tiddler="">
<$droppable actions=<<list-tagged-draggable-drop-actions>>>
<div class="tc-droppable-placeholder">
&nbsp;
</div>
<div style="height:0.5em;">
</div>
</$droppable>
</$tiddler>
</$set>
\end