title: $:/core/macros/tree
tags: $:/tags/Macro
\define leaf-node(prefix)
<$list filter="""[[$prefix$$(chunk)$]is[shadow]] [[$prefix$$(chunk)$]is[tiddler]] +[removeprefix[$prefix$]] +[limit[1]]"""
emptyMessage="""<$text text="$prefix$$(chunk)$"/>""">
{{$:/core/images/file}} <$link to="""$prefix$$(chunk)$""">
<$view field="title"/>
$link>
$list>
\end
\define branch-node(prefix)
<$reveal type="nomatch" text="" default="""$(chunk)$""">
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]""">
<$reveal type="nomatch" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="show" class="tc-btn-invisible">{{$:/core/images/folder}} <$text text="""$(chunk)$"""/>$button>
$reveal>
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$button set="""$:/state/tree/$prefix$$(chunk)$""" setTo="hide" class="tc-btn-invisible">{{$:/core/images/folder}} <$text text="""$(chunk)$"""/>$button>
$reveal>
$list>
<$list filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]] +[limit[1]]""">(<$count filter="""[all[shadows+tiddlers]prefix[$prefix$$(chunk)$]] -[[$prefix$$(chunk)$]]"""/>)
<$reveal type="match" state="""$:/state/tree/$prefix$$(chunk)$""" text="show">
<$macrocall $name="tree-node" prefix="""$prefix$$(chunk)$"""/>
$reveal>
$list>
$reveal>
\end
\define tree-node(prefix)
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[!suffix[/]]" variable="chunk">
<>
$list>
<$list filter="[all[shadows+tiddlers]removeprefix[$prefix$]splitbefore[/]sort[title]] +[suffix[/]]" variable="chunk">
<>
$list>
\end
\define tree(prefix)
<$text text="""$prefix$"""/>
<$macrocall $name="tree-node" prefix="""$prefix$"""/>
\end