1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-03 04:39:10 +00:00

add new classes toc-item-included and toc-item-excluded, simplify code using more functions

This commit is contained in:
pmario 2024-02-04 06:15:49 +01:00
parent f3a314adf0
commit e1a42ebf82

View File

@ -3,20 +3,6 @@ tags: $:/tags/Macro
\whitespace trim
<!-- v5.2.4 add "Custom Icons" -->
\procedure toc-open-icon() $:/core/images/down-arrow
\procedure toc-closed-icon() $:/core/images/right-arrow
<!-- v5.3.4 complete rewrite -->
\function tf.toc-stateTitle() [[$:/state/toc]] [<path>] "/" [<currentTiddler>] +[join[]]
\function tf.toc-newPath() [<path>addsuffix[/]addsuffix<tag>]
<!-- At the moment the following function is only used by "tabbed" tocs -->
\function tf.toc-getItemClass() [<selectedTiddler>get[text]match<currentTiddler>then[toc-item-selected]else[toc-item]]
\function tf.toc-includedClass() [tf.toc-getItemClass[]] [subfilter<tf.toc-include>match<currentTiddler>then[toc-item-included]] +[join[ ]]
\procedure toc-caption()
<span class="tc-toc-caption tc-tiny-gap-left">
<$let name="tv-wikilinks" value="no">
@ -27,45 +13,57 @@ tags: $:/tags/Macro
</span>
\end
<!-- v5.2.4 add "Custom Icons" -->
\procedure toc-open-icon() $:/core/images/down-arrow
\procedure toc-closed-icon() $:/core/images/right-arrow
<!-- v5.3.4 complete rewrite -->
\function tf.toc-stateTitle() [[$:/state/toc]] [<path>] "/" [<currentTiddler>] +[join[]]
\function tf.toc-newPath() [<path>addsuffix[/]addsuffix<tag>]
<!-- At the moment the following function is only used by "tabbed" tocs -->
\function tf.toc-getItemClass() [<selectedTiddler>get[text]match<currentTiddler>then[toc-item-selected]else[toc-item]]
\function tf.toc-includedClass() [subfilter<tf.toc-include>match<currentTiddler>then[toc-item-included]]
\function tf.toc-itemClass() [<tf.toc-getItemClass>] [<tf.toc-includedClass>] [<tf.toc-exclude>!is[blank]then[toc-item-excluded]] +[join[ ]]
<!-- tf.toc-include needs to use <tag> -->
\function tf.toc-include() [<tag>get[toc-include]]
<!-- the following functions need to use <currentTiddler> -->
\function tf.toc-exclude() [<currentTiddler>get[toc-exclude]]
<!-- the following 3 functions need to use <currentTiddler> -->
\function tf.toc-getExclude() [<currentTiddler>get[toc-exclude]]
\function tf.toc-excludeYes() [<currentTiddler>format:titlelist[]]
\function tf.toc-exclude() [<tf.toc-getExclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-getExclude>]
\procedure toc-body(tag,sort:"",itemClassFilter,exclude,path)
<ol class="tc-toc">
<!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} >
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let item=<<currentTiddler>> __path=<<tf.toc-newPath>> >
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]">
<li class=<<tf.toc-includedClass>>>
<% if [all[current]toc-link[no]] %>
<%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<$let item=<<currentTiddler>> __path=<<tf.toc-newPath>> >
<!-- adding tf.toc-exclude, excludes blocked elements from all visible sub-nodes -->
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<li class=<<tf.toc-itemClass>>>
<% if [all[current]toc-link[no]] %>
<<toc-caption>>
<% else %>
<!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<<toc-caption>>
<% else %>
<!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<<toc-caption>>
</$link>
<% endif %>
<$macrocall
$name="toc-body"
tag=<<item>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
</li>
</$set>
</$let>
<% endif %>
</$let>
</$link>
<% endif %>
<$macrocall
$name="toc-body"
tag=<<item>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
</li>
</$set>
</$let>
<% endif %>
</$list>
</ol>
\end
<!-- log -->
<!-- <$log tag=<<tag>> _t-e=<<_toc-exclude>> ct=<<currentTiddler>> sub={{{ [subfilter<_toc-exclude>]}}} exclude=<<exclude>>/> -->
<!-- log -->
<!-- =======================================
Simple toc macro which shows the full tree
@ -100,7 +98,7 @@ This macro is _not_ used by other toc-macros
\procedure toc-linked-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>> >
<li class=<<tf.toc-getItemClass>>>
<li class=<<tf.toc-itemClass>>>
<!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<<toc-item>>
@ -119,7 +117,7 @@ This macro is _not_ used by other toc-macros
\procedure toc-unlinked-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>>>
<li class=<<tf.toc-getItemClass>>>
<li class=<<tf.toc-itemClass>>>
<<toc-item isUnlinked:"yes">>
<!-- TODO auto expand -->
<% if [<toc-state>get[text]match[open]] %>
@ -139,32 +137,30 @@ Shows an expandable toc. Item always have an open/close chevron
<ol class="tc-toc toc-expandable">
<!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} >
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]">
<% if [all[current]toc-link[no]] %>
<$macrocall
$name="toc-unlinked-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% else %>
<$macrocall
$name="toc-linked-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% endif %>
</$set>
</$let>
<% endif %>
</$let>
<%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<% if [all[current]toc-link[no]] %>
<$macrocall
$name="toc-unlinked-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% else %>
<$macrocall
$name="toc-linked-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% endif %>
</$set>
</$let>
<% endif %>
</$list>
</ol>
\end
\procedure toc-linked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>>>
<li class=<<tf.toc-getItemClass>>>
<li class=<<tf.toc-itemClass>>>
<!-- v5.1.23 use target-field if present in tiddler -->
<$link to={{{ [<currentTiddler>get[target]else<currentTiddler>] }}}>
<% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %>
@ -189,7 +185,7 @@ Shows an expandable toc. Item always have an open/close chevron
\procedure toc-unlinked-selective-expandable-body(tag,sort:"",itemClassFilter,exclude,path)
<$qualify name="toc-state" title=<<tf.toc-stateTitle>> >
<li class=<<tf.toc-getItemClass>>>
<li class=<<tf.toc-itemClass>>>
<% if [all[current]tagging[]] -[subfilter<exclude>] +[limit[1]] %>
<<toc-item isUnlinked:"yes">>
<% else %>
@ -219,25 +215,23 @@ If an item has no children, there is no open/close chevron
<ol class="tc-toc toc-selective-expandable">
<!-- text substitution is needed for backwards compatibility -->
<$list filter=`[all[shadows+tiddlers]tag<tag>!has[draft.of]$(sort)$] [subfilter<tf.toc-include>] -[<tag>] -[subfilter<exclude>]`>
<$let _toc-exclude={{{ [<tf.toc-exclude>match[yes]then<tf.toc-excludeYes>] :else[<tf.toc-exclude>] }}} >
<%if [<currentTiddler>] -[subfilter<_toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<_toc-exclude>]">
<% if [all[current]toc-link[no]] %>
<$macrocall
$name="toc-unlinked-selective-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% else %>
<$macrocall
$name="toc-linked-selective-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% endif %>
</$set>
</$let>
<% endif %>
</$let>
<%if [<currentTiddler>] -[subfilter<tf.toc-exclude>] %>
<$let __path=<<tf.toc-newPath>>>
<$set name="__excluded" filter="[subfilter<exclude>] [<tag>] [subfilter<tf.toc-exclude>]">
<% if [all[current]toc-link[no]] %>
<$macrocall
$name="toc-unlinked-selective-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% else %>
<$macrocall
$name="toc-linked-selective-expandable-body"
tag=<<tag>> sort=<<sort>> itemClassFilter=<<itemClassFilter>> exclude=<<__excluded>> path=<<__path>>
/>
<% endif %>
</$set>
</$let>
<% endif %>
</$list>
</ol>
\end