I would like to be able to reorder the elements any field that is similar to the list field (i.e. a title list) in any tiddler pointed to using a macrocall (transclusion).
I’ll share my attempt with you, in case I got close to the solution and made a small mistake I can’t find.
Surely I will have to modify the part after the comment <!-- Using the following 5 lines as replacement makes dragging titles from outside into the dropdown apply the tag -->
(but because I honestly didn’t understand what the comment meant)
- If anyone has any advice, it is greatly appreciated
\define list-tiddler-field-draggable-drop-actions(tiddler,field)
\whitespace trim
<!-- Save the current ordering of the tiddlers with this tag -->
<$set name="order" filter="[list[<__tiddler__>!!<__field__>]]">
<!-- Save the new order to the field -->
<$action-listops $tiddler=<<__tiddler__>> $field=<<__field__>> $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=<<__field__>>/>-->
<!-- Using the following 5 lines as replacement makes dragging titles from outside into the dropdown apply the tag -->
<$list filter="[<actionTiddler>!contains:tags<__field__>]">
<$fieldmangler tiddler=<<actionTiddler>>>
<$action-sendmessage $message="tm-add-tag" $param=<<__field__>>/>
</$fieldmangler>
</$list>
</$set>
\end
\define list-tiddler-field-draggable(tiddler,field,subFilter,emptyMessage,itemTemplate,genesisType:"div",storyview:"")
\whitespace trim
<span class="tc-tagged-draggable-list">
<$set name="field" value=<<__field__>>>
<$list
filter="[list[<__tiddler__>!!<__field__>]$subFilter$]"
emptyMessage=<<__emptyMessage__>>
storyview=<<__storyview__>>
>
<$genesis $type=<<__genesisType__>> class="tc-menu-list-item">
<$droppable
actions="""<$macrocall $name="list-tiddler-field-draggable-drop-actions" tiddler=<<__tiddler__>> field=<<__field__>>/>"""
enable=<<tv-enable-drag-and-drop>>
>
<$genesis $type=<<__genesisType__>> class="tc-droppable-placeholder"/>
<$genesis $type=<<__genesisType__>>>
<$transclude tiddler="""$itemTemplate$""">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</$transclude>
</$genesis>
</$droppable>
</$genesis>
</$list>
<$tiddler tiddler=<<__tiddler__>>>
<$droppable
actions="""<$macrocall $name="list-tiddler-field-draggable-drop-actions" tiddler=<<__tiddler__>> field=<<__field__>>/>"""
enable=<<tv-enable-drag-and-drop>>
>
<$genesis $type=<<__genesisType__>> class="tc-droppable-placeholder"/>
<$genesis $type=<<__genesisType__>> style="height:0.5em;"/>
</$droppable>
</$tiddler>
</$set>
</span>
\end
I did this editing a copy of list-tagged-draggable-drop-actions
and list-tagged-draggable
, found in $:/core/macros/list
.
If it's convenient, here's the original code
\define list-tagged-draggable-drop-actions(tag)
\whitespace trim
<!-- 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>
<!-- Save the new order to the Tag Tiddler -->
<$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__>>/>-->
<!-- Using the following 5 lines as replacement makes dragging titles from outside into the dropdown apply the tag -->
<$list filter="[<actionTiddler>!contains:tags<__tag__>]">
<$fieldmangler tiddler=<<actionTiddler>>>
<$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
<span class="tc-tagged-draggable-list">
<$set name="tag" value=<<__tag__>>>
<$list
filter="[<__tag__>tagging[]$subFilter$]"
emptyMessage=<<__emptyMessage__>>
storyview=<<__storyview__>>
>
<$genesis $type=<<__elementTag__>> class="tc-menu-list-item">
<$droppable
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$""">
<$link to={{!!title}}>
<$view field="title"/>
</$link>
</$transclude>
</$genesis>
</$droppable>
</$genesis>
</$list>
<$tiddler tiddler="">
<$droppable
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;"/>
</$droppable>
</$tiddler>
</$set>
</span>
\end
I wonder if anyone has already tried to do something similar.