mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-04-12 05:43:16 +00:00
Use parse tree to render source text of filter
This commit is contained in:
parent
002c319518
commit
e741816a70
@ -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;
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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<class>] }}}
|
||||
>
|
||||
@ -11,22 +11,20 @@ tags: $:/tags/Macro
|
||||
<$let
|
||||
state=<<qualify "$:/temp/filter-inspector">>
|
||||
stateFolded={{{ [<state>addsuffix[folded]] }}}
|
||||
folded={{{ [<stateFolded>get[text]else[yes]match[yes]] }}}
|
||||
folded={{{ [<stateFolded>get[text]else[no]match[yes]] }}}
|
||||
stateMaxRows={{{ [<state>addsuffix[max-rows]] }}}
|
||||
maxRows={{{ [<stateMaxRows>get[text]!match[]else[50]] }}}
|
||||
maxRows={{{ [<stateMaxRows>get[text]!match[]else[10]] }}}
|
||||
>
|
||||
<div class="tc-box-header">
|
||||
<$button class="tc-btn-invisible" style.fill="inherit">
|
||||
<%if [<folded>match[yes]] %>
|
||||
<$action-setfield $tiddler=<<stateFolded>> text="no"/>
|
||||
{{$:/core/images/right-arrow}}
|
||||
<%else%>
|
||||
<$action-setfield $tiddler=<<stateFolded>> text="yes"/>
|
||||
{{$:/core/images/down-arrow}}
|
||||
<%endif%>
|
||||
<$text text={{{ [<jsonList>jsonindexes[]count[]] }}}/>
|
||||
{{$:/core/images/right-arrow}}
|
||||
</$button>
|
||||
<$text text=<<prompt>>/>
|
||||
<span class="tc-pill"><$text text={{{ [<jsonList>jsonindexes[]count[]] }}}/></span>
|
||||
</div>
|
||||
<%if [<folded>!match[yes]] %>
|
||||
<div class="tc-box-content">
|
||||
@ -45,7 +43,7 @@ tags: $:/tags/Macro
|
||||
</$list>
|
||||
<%if [<jsonList>jsonindexes[]count[]compare:number:gt<maxRows>] %>
|
||||
<$button class="tc-btn-invisible" style.fill="inherit">
|
||||
<$action-setfield $tiddler=<<stateMaxRows>> text={{{ [<maxRows>add[50]] }}}/>
|
||||
<$action-setfield $tiddler=<<stateMaxRows>> text={{{ [<maxRows>add[10]] }}}/>
|
||||
{{$:/core/images/chevron-down}}
|
||||
</$button>
|
||||
<%endif%>
|
||||
@ -60,7 +58,7 @@ tags: $:/tags/Macro
|
||||
\procedure inspect-operator(jsonOperator)
|
||||
<div class="tc-box tc-inspect-operator-box">
|
||||
<div class="tc-box-header">
|
||||
<span class="tc-pill">
|
||||
<span class="">
|
||||
<$text text={{{ [<jsonOperator>jsonget[prefix]] }}} />
|
||||
<$text text={{{ [<jsonOperator>jsonget[operatorName]] }}} />
|
||||
</span>
|
||||
@ -72,14 +70,25 @@ tags: $:/tags/Macro
|
||||
</$list>
|
||||
<%endif%>
|
||||
<$list filter="[<jsonOperator>jsonindexes[operands]nsort[]]" variable="indexOperand">
|
||||
<span class="tc-pill">
|
||||
<$text text={{{ [<jsonOperator>jsonget[operands],<indexOperand>] }}} />
|
||||
</span>
|
||||
<div class="tc-split-pill">
|
||||
<div class="tc-split-pill-top">
|
||||
<%if [<jsonOperator>jsonget[parseTree],[operands],<indexOperand>,[variable]match[true]] %>
|
||||
<$text text="<"/><$text text={{{ [<jsonOperator>jsonget[parseTree],[operands],<indexOperand>,[text]] }}}/><$text text=">"/>
|
||||
<%elseif [<jsonOperator>jsonget[parseTree],[operands],<indexOperand>,[indirect]match[true]] %>
|
||||
<$text text="{"/><$text text={{{ [<jsonOperator>jsonget[parseTree],[operands],<indexOperand>,[text]] }}}/><$text text="}"/>
|
||||
<%else%>
|
||||
<$text text="["/><$text text={{{ [<jsonOperator>jsonget[parseTree],[operands],<indexOperand>,[text]] }}}/><$text text="]"/>
|
||||
<%endif%>
|
||||
</div>
|
||||
<div class="tc-split-pill-bottom">
|
||||
<$text text={{{ [<jsonOperator>jsonget[operands],<indexOperand>] }}} />
|
||||
</div>
|
||||
</div>
|
||||
</$list>
|
||||
</div>
|
||||
<div class="tc-box-content">
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonOperator>jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonOperator>jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box"/>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonOperator>jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonOperator>jsonextract[output]] }}} class="tc-box tc-inspect-output-box"/>
|
||||
</div>
|
||||
</div>
|
||||
\end inspect-operator
|
||||
@ -87,7 +96,7 @@ tags: $:/tags/Macro
|
||||
\procedure inspect-run(jsonRun)
|
||||
<div class="tc-box tc-inspect-run-box">
|
||||
<div class="tc-box-header">
|
||||
<span class="tc-pill">:<$text text={{{ [<jsonRun>jsonget[prefixName]] }}} /></span>
|
||||
<span class="">:<$text text={{{ [<jsonRun>jsonget[prefixName]] }}} /></span>
|
||||
<%if [<jsonRun>jsonindexes[suffixes]length[]compare:number:gt[0]] %>
|
||||
<$list filter="[<jsonRun>jsonindexes[suffixes]nsort[]]" variable="indexSuffix">
|
||||
<span class="tc-pill">
|
||||
@ -97,32 +106,34 @@ tags: $:/tags/Macro
|
||||
<%endif%>
|
||||
</div>
|
||||
<div class="tc-box-content">
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/>
|
||||
<$list filter="[<jsonRun>jsonindexes[operators]nsort[]]" variable="indexOperator">
|
||||
<$let transclusion={{{ [[operator-]addsuffix<indexOperator>] }}}>
|
||||
<$transclude $variable="inspect-operator" jsonOperator={{{ [<jsonRun>jsonextract[operators],<indexOperator>] }}}/>
|
||||
</$let>
|
||||
</$list>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box">
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[output]] }}} class="tc-box tc-inspect-output-box">
|
||||
</div>
|
||||
</div>
|
||||
\end inspect-run
|
||||
|
||||
\procedure inspect-filter(filter,inputFilter:"[all[tiddlers]]",orientation:"horizontal")
|
||||
<$let json={{{ [subfilter<inputFilter>inspect<filter>] }}}>
|
||||
<div class={{{ tc-box tc-inspect-filter-box [<orientation>match[horizontal]then[tc-inspect-filter-box-horizontal]] +[join[ ]] }}}>
|
||||
<div class="tc-box-header">
|
||||
Filter
|
||||
<span class="tc-pill"><$text text={{{ [<json>jsonget[inputFilter]] }}}/></span>
|
||||
</div>
|
||||
<div class="tc-box-content">
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<json>jsonextract[input]] }}} prompt="In" class="tc-box tc-inspect-input-box"/>
|
||||
<$list filter="[<json>jsonindexes[runs]nsort[]]" variable="indexRun">
|
||||
<$let transclusion={{{ [[run-]addsuffix<indexRun>] }}}>
|
||||
<$transclude $variable="inspect-run" jsonRun={{{ [<json>jsonextract[runs],<indexRun>] }}}/>
|
||||
</$let>
|
||||
</$list>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<json>jsonextract[output]] }}} prompt="Out" class="tc-box tc-inspect-output-box"/>
|
||||
<div class={{{ tc-inspect-filter-box [<orientation>match[horizontal]then[tc-inspect-filter-box-horizontal]] +[join[ ]] }}}>
|
||||
<div class="tc-box">
|
||||
<div class="tc-box-header">
|
||||
Filter
|
||||
<span class="tc-pill"><$text text={{{ [<json>jsonget[inputFilter]] }}}/></span>
|
||||
</div>
|
||||
<div class="tc-box-content">
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<json>jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/>
|
||||
<$list filter="[<json>jsonindexes[runs]nsort[]]" variable="indexRun">
|
||||
<$let transclusion={{{ [[run-]addsuffix<indexRun>] }}}>
|
||||
<$transclude $variable="inspect-run" jsonRun={{{ [<json>jsonextract[runs],<indexRun>] }}}/>
|
||||
</$let>
|
||||
</$list>
|
||||
<$transclude $variable="inspect-list" jsonList={{{ [<json>jsonextract[output]] }}} class="tc-box tc-inspect-output-box"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</$let>
|
||||
|
@ -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<currentTiddler>] [{$:/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"/>
|
||||
|
@ -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: <<colour code-foreground>>;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user