Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and extend tag picker functions #7548

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions core/wiki/macros/tag-picker.tid
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
title: $:/core/macros/tag-picker
tags: $:/tags/Macro
first-search-filter: [tags[]!is[system]search:title<userInput>sort[]]
second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
first-search-filter: [subfilter<tagListFilter>!is[system]search:title<userInput>sort[]]
second-search-filter: [subfilter<tagListFilter>is[system]search:title<userInput>sort[]]

\function tagpicker-dropdown-id() [<qualify "$:/state/popup/tags-auto-complete">] [[$(__tagField__)$-$(__tagListFilter__)$]substitute[]sha256[]] +[join[/]]

\define get-tagpicker-focus-selector() [data-tiddler-title="$(currentTiddlerCSSEscaped)$"] .tc-add-tag-name input

Expand Down Expand Up @@ -58,8 +60,8 @@ second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
>
<$vars
refreshTitle=<<qualify "$:/temp/NewTagName/refresh">>
nonSystemTagsFilter="[tags[]!is[system]search:title<userInput>sort[]]"
systemTagsFilter="[tags[]is[system]search:title<userInput>sort[]]"
nonSystemTagsFilter="[subfilter<tagListFilter>!is[system]search:title<userInput>sort[]]"
systemTagsFilter="[subfilter<tagListFilter>is[system]search:title<userInput>sort[]]"
>
<div class="tc-edit-add-tag">
<div>
Expand All @@ -74,7 +76,7 @@ second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
inputCancelActions=<<clear-tags-actions>>
tag="input"
placeholder={{$:/language/EditTemplate/Tags/Add/Placeholder}}
focusPopup=<<qualify "$:/state/popup/tags-auto-complete">>
focusPopup=<<tagpicker-dropdown-id>>
class="tc-edit-texteditor tc-popup-handle"
tabindex=<<tabIndex>>
focus={{{ [{$:/config/AutoFocus}match[tags]then[true]] ~[[false]] }}}
Expand All @@ -83,7 +85,7 @@ second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
configTiddlerFilter="[[$:/core/macros/tag-picker]]"
/>
</span>
<$button popup=<<qualify "$:/state/popup/tags-auto-complete">>
<$button popup=<<tagpicker-dropdown-id>>
class="tc-btn-invisible tc-btn-dropdown"
tooltip={{$:/language/EditTemplate/Tags/Dropdown/Hint}}
aria-label={{$:/language/EditTemplate/Tags/Dropdown/Caption}}
Expand Down Expand Up @@ -112,7 +114,7 @@ second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
</span>
</div>
<div class="tc-block-dropdown-wrapper">
<$reveal state=<<qualify "$:/state/popup/tags-auto-complete">> type="nomatch" text="" default="">
<$reveal state=<<tagpicker-dropdown-id>> type="nomatch" text="" default="">
<div class="tc-block-dropdown tc-block-tags-dropdown">
<$set name="userInput" value={{{ [<storeTitle>get[text]] }}}>
<$list
Expand Down Expand Up @@ -162,16 +164,17 @@ second-search-filter: [tags[]is[system]search:title<userInput>sort[]]
</$vars>
\end

\define tag-picker(actions,tagField:"tags")
\define tag-picker(actions,tagField:"tags",tiddler,tagListFilter:"[tags[]]")
\whitespace trim
<$vars saveTiddler=<<currentTiddler>> palette={{$:/palette}}>
\function targetTiddler() [<__tiddler__>is[blank]then<currentTiddler>else<__tiddler__>]
<$let saveTiddler=<<targetTiddler>> palette={{$:/palette}} tagListFilter=<<__tagListFilter__>>>
<$list
filter="[<newTagNameTiddler>match[]]"
emptyMessage="<$macrocall $name='tag-picker-inner' actions=<<__actions__>> tagField=<<__tagField__>>/>"
>
<$set name="newTagNameTiddler" value=<<qualify "$:/temp/NewTagName">>>
<$set name="newTagNameTiddler" value={{{ [[$:/temp/NewTagName]] [<__tagField__>!match[tags]] +[join[/]] [<qualify>] +[join[]] }}}>
<$macrocall $name="tag-picker-inner" actions=<<__actions__>> tagField=<<__tagField__>>/>
</$set>
</$list>
</$vars>
</$let>
\end
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
created: 20230616104546608
modified: 20230616141838664
tags: [[tag-picker Macro]] [[Macro Examples]]
title: tag-picker Macro (Examples)
type: text/vnd.tiddlywiki

<<.warning """The first example will set the tag of the <<.tid currentTiddler>> so you should copy / paste it to a new tiddler for testing. Otherwise you'll change "this tiddler" """>>

<$macrocall $name=".example" n="1"
eg="""Use all existing tags and set the ''tags'' field here: <<tag-picker>>
"""/>


<<.tip """The following examples use a temporary tiddler: $:/temp/test/tag-picker. So this tiddler will not be changed """>>

<$let transclusion="test">

<$macrocall $name=".example" n="2"
eg="""$:/temp/test/tag-picker ''tags'': <$text text={{{ [[$:/temp/test/tag-picker]get[tags]enlist-input[]join[, ]else[n/a]] }}}/>

Use all existing tags and set the $:/temp/test/tag-picker ''tags'' field: <<tag-picker tiddler:"$:/temp/test/tag-picker">>
"""/>


<$macrocall $name=".example" n="3"
eg="""$:/temp/test/tag-picker ''foo'': <$text text={{{ [[$:/temp/test/tag-picker]get[foo]enlist-input[]join[, ]else[n/a]] }}}/>

Use all existing tags and set the $:/temp/test/tag-picker ''foo'' field: <<tag-picker tagField:"foo" tiddler:"$:/temp/test/tag-picker">>
"""/>


<<.tip """The following example expects some values in the "foo" field of the tiddler $:/temp/test/tag-picker, which can be created by the example above.""">>

<$macrocall $name=".example" n="4" eg="""\define listSource() $:/temp/test/tag-picker
$:/temp/test/tag-picker foo: <$text text={{{ [[$:/temp/test/tag-picker]get[foo]enlist-input[]join[, ]else[n/a]] }}}/><br>
$:/temp/test/tag-picker bar: <$text text={{{ [[$:/temp/test/tag-picker]get[bar]enlist-input[]join[, ]else[n/a]] }}}/>

Use $:/temp/test/tag-picker ''foo'' field as source and set ''bar'': <<tag-picker tagField:"bar" tagListFilter:"[<listSource>get[foo]enlist-input[]]" tiddler:"$:/temp/test/tag-picker">>
"""/>

</$let>

18 changes: 13 additions & 5 deletions editions/tw5.com/tiddlers/macros/tag-picker_Macro.tid
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
caption: tag-picker
created: 20161128191316701
modified: 20161128191435641
modified: 20230616114543787
tags: Macros [[Core Macros]]
title: tag-picker Macro
type: text/vnd.tiddlywiki
Expand All @@ -9,9 +9,17 @@ The <<.def tag-picker>> [[macro|Macros]] generates a combination of a text box a

!! Parameters

;actions
: Action widgets to be triggered when the pill is clicked. Within the text, the variable ''tag'' contains the title of the selected tag.
;tagField
: <<.from-version 5.1.23>> The ''field'' that gets updated with the selected tag. Defaults to ''tags''.
; actions
: Action widgets to be triggered when the pill is clicked. Within the text, the variable <<.var tag>> contains the title of the selected tag.

; tagField
: <<.from-version 5.1.23>> The specified ''field'' that gets updated with the selected tag. Defaults to `tags`.

; tiddler
: <<.from-version 5.3.0>> Defines the target tiddler, which should be manipulated. Defaults to: <<.var currentTiddler>>.

; tagListFilter
: <<.from-version 5.3.0>> This parameter defaults to: `[tags[]]` which creates a list of all existing tags. If the tag list should come from a different source the filter should look similar to eg: `[<listSource>get[field-name]enlist-input[]]`.


<<.macro-examples "tag-picker">>
Loading