From e741816a7063b8cd315812288f8a8aa9748d0a9e Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 6 Apr 2025 22:06:58 +0100 Subject: [PATCH] Use parse tree to render source text of filter --- core/modules/filters.js | 9 ++- core/modules/filters/inspect.js | 1 + core/wiki/macros/inspect-filter.tid | 71 +++++++++++-------- .../tiddlers/filters/inspect Operator.tid | 7 +- themes/tiddlywiki/vanilla/base.tid | 37 ++++++++-- 5 files changed, 85 insertions(+), 40 deletions(-) diff --git a/core/modules/filters.js b/core/modules/filters.js index 2f541378b..5cc1de32c 100644 --- a/core/modules/filters.js +++ b/core/modules/filters.js @@ -235,7 +235,7 @@ exports.compileFilter = function(filterString,options) { this.filterCache = Object.create(null); this.filterCacheCount = 0; } - if(this.filterCache[filterString] !== undefined && !wrappers) { + if(this.filterCache[filterString] !== undefined && !wrappers.prefix && !wrappers.operator) { return this.filterCache[filterString]; } var filterParseTree; @@ -290,6 +290,7 @@ exports.compileFilter = function(filterString,options) { } // Invoke the appropriate filteroperator module results = operatorFunction(accumulator,{ + parseTree: operator, operator: operator.operator, operatorName: operatorName, operand: operands.length > 0 ? operands[0] : undefined, @@ -391,7 +392,9 @@ exports.compileFilter = function(filterString,options) { this.filterCache = Object.create(null); this.filterCacheCount = 0; } - this.filterCache[filterString] = fnMeasured; - this.filterCacheCount++; + if(!wrappers.prefix && !wrappers.operator) { + this.filterCache[filterString] = fnMeasured; + this.filterCacheCount++; + } return fnMeasured; }; diff --git a/core/modules/filters/inspect.js b/core/modules/filters/inspect.js index 54704084f..af44ab426 100644 --- a/core/modules/filters/inspect.js +++ b/core/modules/filters/inspect.js @@ -43,6 +43,7 @@ exports.inspect = function(source,operator,options) { var details = { operatorName: innerOperator.operatorName, operands: innerOperator.operands, + parseTree: innerOperator.parseTree, prefix: innerOperator.prefix, suffix: innerOperator.suffix, suffixes: innerOperator.suffixes, diff --git a/core/wiki/macros/inspect-filter.tid b/core/wiki/macros/inspect-filter.tid index b65a1a083..2285e5092 100644 --- a/core/wiki/macros/inspect-filter.tid +++ b/core/wiki/macros/inspect-filter.tid @@ -3,7 +3,7 @@ tags: $:/tags/Macro \whitespace trim -\procedure inspect-list(jsonList,prompt,class:"tc-box") +\procedure inspect-list(jsonList,class:"tc-box") <$let transclusion={{{ [[list-]addsuffix] }}} > @@ -11,22 +11,20 @@ tags: $:/tags/Macro <$let state=<> stateFolded={{{ [addsuffix[folded]] }}} - folded={{{ [get[text]else[yes]match[yes]] }}} + folded={{{ [get[text]else[no]match[yes]] }}} stateMaxRows={{{ [addsuffix[max-rows]] }}} - maxRows={{{ [get[text]!match[]else[50]] }}} + maxRows={{{ [get[text]!match[]else[10]] }}} >
<$button class="tc-btn-invisible" style.fill="inherit"> <%if [match[yes]] %> <$action-setfield $tiddler=<> text="no"/> - {{$:/core/images/right-arrow}} <%else%> <$action-setfield $tiddler=<> text="yes"/> - {{$:/core/images/down-arrow}} <%endif%> + <$text text={{{ [jsonindexes[]count[]] }}}/> + {{$:/core/images/right-arrow}} - <$text text=<>/> - <$text text={{{ [jsonindexes[]count[]] }}}/>
<%if [!match[yes]] %>
@@ -45,7 +43,7 @@ tags: $:/tags/Macro <%if [jsonindexes[]count[]compare:number:gt] %> <$button class="tc-btn-invisible" style.fill="inherit"> - <$action-setfield $tiddler=<> text={{{ [add[50]] }}}/> + <$action-setfield $tiddler=<> text={{{ [add[10]] }}}/> {{$:/core/images/chevron-down}} <%endif%> @@ -60,7 +58,7 @@ tags: $:/tags/Macro \procedure inspect-operator(jsonOperator)
- + <$text text={{{ [jsonget[prefix]] }}} /> <$text text={{{ [jsonget[operatorName]] }}} /> @@ -72,14 +70,25 @@ tags: $:/tags/Macro <%endif%> <$list filter="[jsonindexes[operands]nsort[]]" variable="indexOperand"> - - <$text text={{{ [jsonget[operands],] }}} /> - +
+
+ <%if [jsonget[parseTree],[operands],,[variable]match[true]] %> + <$text text="<"/><$text text={{{ [jsonget[parseTree],[operands],,[text]] }}}/><$text text=">"/> + <%elseif [jsonget[parseTree],[operands],,[indirect]match[true]] %> + <$text text="{"/><$text text={{{ [jsonget[parseTree],[operands],,[text]] }}}/><$text text="}"/> + <%else%> + <$text text="["/><$text text={{{ [jsonget[parseTree],[operands],,[text]] }}}/><$text text="]"/> + <%endif%> +
+
+ <$text text={{{ [jsonget[operands],] }}} /> +
+
- <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/> - <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box"/> + <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/> + <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} class="tc-box tc-inspect-output-box"/>
\end inspect-operator @@ -87,7 +96,7 @@ tags: $:/tags/Macro \procedure inspect-run(jsonRun)
- :<$text text={{{ [jsonget[prefixName]] }}} /> + :<$text text={{{ [jsonget[prefixName]] }}} /> <%if [jsonindexes[suffixes]length[]compare:number:gt[0]] %> <$list filter="[jsonindexes[suffixes]nsort[]]" variable="indexSuffix"> @@ -97,32 +106,34 @@ tags: $:/tags/Macro <%endif%>
- <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/> + <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/> <$list filter="[jsonindexes[operators]nsort[]]" variable="indexOperator"> <$let transclusion={{{ [[operator-]addsuffix] }}}> <$transclude $variable="inspect-operator" jsonOperator={{{ [jsonextract[operators],] }}}/> - <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box"> + <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} class="tc-box tc-inspect-output-box">
\end inspect-run \procedure inspect-filter(filter,inputFilter:"[all[tiddlers]]",orientation:"horizontal") <$let json={{{ [subfilterinspect] }}}> -
match[horizontal]then[tc-inspect-filter-box-horizontal]] +[join[ ]] }}}> -
- Filter - <$text text={{{ [jsonget[inputFilter]] }}}/> -
-
- <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/> - <$list filter="[jsonindexes[runs]nsort[]]" variable="indexRun"> - <$let transclusion={{{ [[run-]addsuffix] }}}> - <$transclude $variable="inspect-run" jsonRun={{{ [jsonextract[runs],] }}}/> - - - <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box"/> +
match[horizontal]then[tc-inspect-filter-box-horizontal]] +[join[ ]] }}}> +
+
+ Filter + <$text text={{{ [jsonget[inputFilter]] }}}/> +
+
+ <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/> + <$list filter="[jsonindexes[runs]nsort[]]" variable="indexRun"> + <$let transclusion={{{ [[run-]addsuffix] }}}> + <$transclude $variable="inspect-run" jsonRun={{{ [jsonextract[runs],] }}}/> + + + <$transclude $variable="inspect-list" jsonList={{{ [jsonextract[output]] }}} class="tc-box tc-inspect-output-box"/> +
diff --git a/editions/tw5.com/tiddlers/filters/inspect Operator.tid b/editions/tw5.com/tiddlers/filters/inspect Operator.tid index ab86e15d2..3e3a6d449 100644 --- a/editions/tw5.com/tiddlers/filters/inspect Operator.tid +++ b/editions/tw5.com/tiddlers/filters/inspect Operator.tid @@ -28,7 +28,10 @@ The JSON object contains the following properties: !! Examples -<$transclude $variable="inspect-filter" filter="[all[shadows+tiddlers]tag[$:/tags/MenuBar]!has[draft.of]] -[all[tiddlers+shadows]tag[$:/tags/TopLeftBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/topleftbar]] -[all[tiddlers+shadows]tag[$:/tags/TopRightBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/toprightbar]]" inputFilter="[all[tiddlers]]"/> +<$transclude $variable="inspect-filter" filter="1 2 3" inputFilter="[all[tiddlers]]"/> -<$transclude $variable="inspect-filter" filter="[all[shadows+tiddlers]tag[$:/tags/MenuBar]!has[draft.of]] -[all[tiddlers+shadows]tag[$:/tags/TopLeftBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/topleftbar]] -[all[tiddlers+shadows]tag[$:/tags/TopRightBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/toprightbar]]" inputFilter="[all[tiddlers]]" orientation="vertical"/> +<$transclude $variable="inspect-filter" filter="[title] [{$:/palette}length[]] [[marker]]" inputFilter="[all[tiddlers]]"/> +<$transclude $variable="inspect-filter" filter="[all[shadows+tiddlers]tag[$:/tags/MenuBar]!has[draft.of]] -[all[tiddlers+shadows]tag[$:/tags/TopLeftBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/topleftbar]]" inputFilter="[all[tiddlers]]"/> + +<$transclude $variable="inspect-filter" filter="[all[shadows+tiddlers]tag[$:/tags/MenuBar]!has[draft.of]] -[all[tiddlers+shadows]tag[$:/tags/TopLeftBar]limit[1]then[]else[$:/plugins/tiddlywiki/menubar/items/topleftbar]]" inputFilter="[all[tiddlers]]" orientation="vertical"/> diff --git a/themes/tiddlywiki/vanilla/base.tid b/themes/tiddlywiki/vanilla/base.tid index 1641eb1fb..e67b03718 100644 --- a/themes/tiddlywiki/vanilla/base.tid +++ b/themes/tiddlywiki/vanilla/base.tid @@ -3510,9 +3510,17 @@ span.tc-translink > a:first-child { color: var(--box-background-color); fill: var(--box-background-color); background-color: var(--box-foreground-color); + display: flex; + align-items: center; +} + +.tc-box-header button { + color: var(--box-background-color); + background-color: var(--box-foreground-color); } .tc-box-content { + min-width: 4em; padding: 0.25em; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; @@ -3549,6 +3557,24 @@ span.tc-translink > a:first-child { background-color: var(--box-background-color); } +.tc-split-pill { + display: inline-block; + padding: 0.125em 0.25em; + margin: 0 0.25em; + border-radius: 6px; + color: var(--box-foreground-color); + background-color: var(--box-background-color); +} + +.tc-split-pill-top { + border-bottom: 1px solid var(--box-foreground-color); +} + +.tc-split-pill-bottom { + +} + + /* ** Filter Inspection */ @@ -3558,11 +3584,12 @@ span.tc-translink > a:first-child { --box-foreground-color: <>; } -.tc-inspect-filter-box.tc-inspect-filter-box-horizontal > .tc-box-content { - overflow: scroll +.tc-inspect-filter-box.tc-inspect-filter-box-horizontal { + overflow: scroll; + display: flex; } -.tc-inspect-filter-box.tc-inspect-filter-box-horizontal > .tc-box-content, +.tc-inspect-filter-box.tc-inspect-filter-box-horizontal > .tc-box > .tc-box-content, .tc-inspect-filter-box.tc-inspect-filter-box-horizontal .tc-inspect-run-box > .tc-box-content, .tc-inspect-filter-box.tc-inspect-filter-box-horizontal .tc-inspect-operator-box > .tc-box-content { display: flex; @@ -3581,12 +3608,12 @@ span.tc-translink > a:first-child { --box-foreground-color: #400; } -.tc-inspect-input-box { +.tc-box.tc-inspect-input-box { --box-background-color: #fcf; --box-foreground-color: #404; } -.tc-inspect-output-box { +.tc-box.tc-inspect-output-box { --box-background-color: #cff; --box-foreground-color: #044; }