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.
Merge branch 'master' of https://github.com/tiddly-gittly/tw-command-…
- Loading branch information
Showing
13 changed files
with
1,752 additions
and
2,802 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
26 changes: 26 additions & 0 deletions
26
src/commandpalette/widgets/build-in-sub-plugins/search-recent.css
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,26 @@ | ||
.tw-commandpalette-search-recent-item { | ||
position: relative; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: flex-start; | ||
align-items: center; | ||
} | ||
.tw-commandpalette-search-recent-item | ||
.tw-commandpalette-search-recent-item-delete { | ||
position: absolute; | ||
right: 1em; | ||
opacity: 0.3; | ||
padding: 5px; | ||
} | ||
.tw-commandpalette-search-recent-item | ||
.tw-commandpalette-search-recent-item-delete:hover { | ||
opacity: 0.7; | ||
} | ||
.tw-commandpalette-search-recent-item | ||
.tw-commandpalette-search-recent-item-delete:active { | ||
opacity: 1; | ||
} | ||
.tw-commandpalette-search-recent-item | ||
.tw-commandpalette-search-recent-item-delete svg { | ||
width: 20px; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/commandpalette/widgets/build-in-sub-plugins/search-recent.css.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,3 @@ | ||
title: $:/plugins/linonetwo/commandpalette/widget/build-in-sub-plugins/search-recent.css | ||
type: text/css | ||
tags: $:/tags/Stylesheet |
67 changes: 67 additions & 0 deletions
67
src/commandpalette/widgets/build-in-sub-plugins/search-recent.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,67 @@ | ||
import { StateUpdater } from '@algolia/autocomplete-core'; | ||
import type { AutocompletePlugin } from '@algolia/autocomplete-js'; | ||
import { createLocalStorageRecentSearchesPlugin, RecentSearchesPluginData } from '@algolia/autocomplete-plugin-recent-searches'; | ||
import { RecentSearchesItem } from '@algolia/autocomplete-plugin-recent-searches/dist/esm/types'; | ||
import { IContext } from '../utils/context'; | ||
import { getIconSvg } from '../utils/getIconSvg'; | ||
import { lingo } from '../utils/lingo'; | ||
|
||
export const plugin = (id: string): AutocompletePlugin<RecentSearchesItem, RecentSearchesPluginData<RecentSearchesItem>> => { | ||
let setContext: StateUpdater<IContext> | undefined; | ||
let refresh: () => Promise<void> | undefined; | ||
const deleteIcon = getIconSvg('$:/core/images/delete-button', undefined); | ||
const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({ | ||
key: `recent-${id}`, | ||
subscribe(parameters) { | ||
parameters.setContext?.({ addHistoryItem: (text: string) => recentSearchesPlugin.data?.addItem({ id: text, label: text }) } satisfies IContext); | ||
setContext = parameters.setContext as unknown as StateUpdater<IContext>; | ||
refresh = parameters.refresh.bind(parameters); | ||
}, | ||
transformSource({ source }) { | ||
const onSelect = (text: string) => { | ||
setContext?.({ newQuery: text, noClose: true, noNavigate: true } satisfies IContext); | ||
}; | ||
return { | ||
...source, | ||
getItemUrl({ item }) { | ||
return item.id; | ||
}, | ||
async getItems(parameters) { | ||
if (parameters.query.length > 0) return []; | ||
const items = source.getItems(parameters); | ||
return await items; | ||
}, | ||
onSelect({ item }) { | ||
onSelect(item.id); | ||
}, | ||
templates: { | ||
...source.templates, | ||
header() { | ||
return lingo('SearchHistory'); | ||
}, | ||
item({ item, createElement }) { | ||
return createElement( | ||
'div', | ||
{ | ||
class: 'tw-commandpalette-search-recent-item', | ||
onclick: onSelect, | ||
}, | ||
createElement('span', {}, item.id), | ||
createElement('span', { | ||
class: 'tw-commandpalette-search-recent-item-delete', | ||
onclick: () => { | ||
recentSearchesPlugin.data?.removeItem(item.id); | ||
void refresh?.()?.catch?.(error => { | ||
console.error('Error in search-recent refresh', error); | ||
}); | ||
}, | ||
innerHTML: deleteIcon, | ||
}), | ||
); | ||
}, | ||
}, | ||
}; | ||
}, | ||
}); | ||
return recentSearchesPlugin; | ||
}; |
5 changes: 5 additions & 0 deletions
5
src/commandpalette/widgets/build-in-sub-plugins/search-recent.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-recent.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
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