generated from tiddly-gittly/TiddlyWiki-TS-Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
command-palette-prefix: | ||
caption: <<lingo Help/User/Caption $:/plugins/linonetwo/commandpalette/language/>> | ||
description: <<lingo Help/User/Description $:/plugins/linonetwo/commandpalette/language/>> | ||
tags: $:/tags/CommandPaletteHelp | ||
title: $:/plugins/linonetwo/commandpalette/commands/help/User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/commandpalette/widgets/build-in-sub-plugins/search-help.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable @typescript-eslint/strict-boolean-expressions */ | ||
import type { AutocompletePlugin } from '@algolia/autocomplete-js'; | ||
import { ITiddlerFields } from 'tiddlywiki'; | ||
import { checkIsHelp, checkIsUnderFilter } from '../utils/checkPrefix'; | ||
import { IContext } from '../utils/context'; | ||
import { lingo } from '../utils/lingo'; | ||
import { renderTextWithCache } from '../utils/renderTextWithCache'; | ||
|
||
export const plugin = { | ||
getSources(parameters) { | ||
const { widget } = parameters.state.context as IContext; | ||
if (!checkIsHelp(parameters) || checkIsUnderFilter(parameters)) return []; | ||
return [ | ||
{ | ||
sourceId: 'help', | ||
getItems({ query }) { | ||
return ($tw.wiki.filterTiddlers('[all[shadows]tag[$:/tags/CommandPaletteHelp]]') | ||
.map((title) => $tw.wiki.getTiddler(title)?.fields) | ||
.filter(Boolean) as ITiddlerFields[]) | ||
.filter((tiddler) => | ||
// TODO: add pinyinfuse | ||
$tw.wiki.filterTiddlers( | ||
`[search[${query.slice(1)}]]`, | ||
undefined, | ||
$tw.wiki.makeTiddlerIterator([ | ||
tiddler.title.replace('$:/plugins/linonetwo/commandpalette/commands/help/', ''), | ||
renderTextWithCache(tiddler.caption, widget), | ||
renderTextWithCache(tiddler.description, widget), | ||
]), | ||
).length > 0 | ||
); | ||
}, | ||
getItemUrl({ item }) { | ||
return item.title; | ||
}, | ||
onSelect({ item }) { | ||
parameters.setContext({ noNavigate: true, noClose: true, newQuery: (item['command-palette-prefix'] as string).charAt(0) } satisfies IContext); | ||
}, | ||
templates: { | ||
header() { | ||
return lingo('Help'); | ||
}, | ||
item({ item, createElement }) { | ||
const description = item.description | ||
? ` ${renderTextWithCache(item.description as string, widget)}` | ||
: ''; | ||
return createElement('div', { | ||
style: 'display:flex;flex-direction:column;', | ||
}, [ | ||
createElement('div', { style: 'margin-bottom:0.25em;' }, [ | ||
createElement('em', { style: 'margin-right:0.25em;' }, [item['command-palette-prefix'] as string]), | ||
renderTextWithCache(item.caption, widget), | ||
]), | ||
createElement('div', { style: 'margin-bottom:0.3em;' }, description), | ||
]); | ||
}, | ||
}, | ||
}, | ||
]; | ||
}, | ||
} satisfies AutocompletePlugin<ITiddlerFields, unknown>; |
5 changes: 5 additions & 0 deletions
5
src/commandpalette/widgets/build-in-sub-plugins/search-help.ts.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
title: $:/plugins/linonetwo/commandpalette/widget/build-in-sub-plugins/search-help.js | ||
tags: $:/tags/CommandPalettePlugin | ||
type: application/javascript | ||
module-type: library | ||
priority: -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters