Newer
Older
labs / tiddlers / system / macros / $__ou_macros_system_CollapsibleTree.tid
tags: $:/tags/Macro
title: $:/ou/macros/system/CollapsibleTree
type: text/vnd.tiddlywiki

\define collapsible-leaf-link(full-title,chunk,separator: "/")
<$set name="section" tiddler=<<__full-title__>> field="section">
<$list filter="[title[$(full-title)$]!has[section]]">
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
</$list>
<$list filter="[title[$(full-title)$]has[section]]">
<$link to=<<__full-title__>>><$text text=<<section>>/>.&nbsp;&nbsp;<$text text=<<__chunk__>>/></$link>
</$list>
</$set>
\end

\define collapsible-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> <$macrocall $name="collapsible-leaf-link" full-title=<<full-title>> chunk=<<chunk>>/>
</$list>
</$list>
</li>
\end

\define collapsible-branch-node(prefix,chunk,separator: "/")
<li>
<$set name="reveal-state" value={{{ [[$:/state/stree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$reveal type="nomatch" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="show" class="tc-btn-invisible">
<$set name="stripped" filter="[[$chunk$]removesuffix[$separator$]]" >
{{$:/core/images/folder}} <span class="collapsed-tree-branch"><<stripped>></span>
</$set>
</$button>
</$reveal>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="hide" class="tc-btn-invisible">
<$set name="stripped" filter="[[$chunk$]removesuffix[$separator$]]" >
{{$:/core/images/folder}} <span class="collapsed-tree-branch"><<stripped>></span>
</$set>
</$button>
</$reveal>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$macrocall $name="collapsible-tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
</$reveal>
</$set>
</li>
\end

\define collapsible-tree-node(prefix,separator: "/")
<ol>
<$list filter="[all[tiddlers]!has[section]removeprefix<__prefix__>splitbefore<__separator__>sortan[]!suffix<__separator__>] [all[tiddlers]has[section]sortan[section]removeprefix<__prefix__>splitbefore<__separator__>!suffix<__separator__>]" variable="chunk">
<$macrocall $name="collapsible-leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
<$list filter="[all[tiddlers]removeprefix<__prefix__>splitbefore<__separator__>sortan[]suffix<__separator__>]" variable="chunk">
<$macrocall $name="collapsible-branch-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
</ol>
\end

\define collapsible-tree(prefix: "$:/",separator: "/")
<div class="tc-tree">
<$macrocall $name="collapsible-tree-node" prefix=<<__prefix__>> separator=<<__separator__>>/>
</div>
\end