diff options
| author | Fuwn <[email protected]> | 2025-05-15 03:13:02 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-05-15 03:13:02 -0700 |
| commit | f54528a492b153ce0dc2212c39b7f36d87a10330 (patch) | |
| tree | c24128cb0fd7776e84db4a010f4cd0315e3c8b50 /src | |
| parent | refactor(CommandPalette): Globally rename action type (diff) | |
| download | due.moe-f54528a492b153ce0dc2212c39b7f36d87a10330.tar.xz due.moe-f54528a492b153ce0dc2212c39b7f36d87a10330.zip | |
feat(CommandPalette): Add nested action support
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/CommandPalette/CommandPalette.svelte | 34 | ||||
| -rw-r--r-- | src/lib/CommandPalette/actions.ts | 32 |
2 files changed, 57 insertions, 9 deletions
diff --git a/src/lib/CommandPalette/CommandPalette.svelte b/src/lib/CommandPalette/CommandPalette.svelte index 332def8e..d0e015a5 100644 --- a/src/lib/CommandPalette/CommandPalette.svelte +++ b/src/lib/CommandPalette/CommandPalette.svelte @@ -8,7 +8,7 @@ export let open = false; let search = ''; - let filtered: CommandPaletteAction[] = []; + let filtered: (CommandPaletteAction & { id?: string })[] = []; let selectedIndex = -1; let inputRef: HTMLInputElement; let isVisible = false; @@ -20,13 +20,29 @@ if (!itemIDs.has(item.url)) itemIDs.set(item.url, index); }); - filtered = items - .filter( - (item) => - item.name.toLowerCase().includes(search.toLowerCase()) || - item.tags?.some((tag) => tag.toLowerCase().includes(search.toLowerCase())) - ) - .slice(0, 10); + const doesActionMatch = (action: CommandPaletteAction) => + action.name.toLowerCase().includes(search.toLowerCase()) || + action.tags?.some((tag) => tag.toLowerCase().includes(search.toLowerCase())); + + filtered = []; + + items.forEach((action, idx) => { + const actionMatches = doesActionMatch(action); + + if (actionMatches) filtered.push({ ...action, id: `action-${idx}` }); + + if (action.actions) { + action.actions.forEach((nestedAction, nestedIdx) => { + if (doesActionMatch(nestedAction)) { + filtered.push({ + ...nestedAction, + id: `action-${idx}-nested-${nestedIdx}`, + name: `↳ ${nestedAction.name}` + }); + } + }); + } + }); } $: if (selectedIndex >= filtered.length) selectedIndex = filtered.length - 1; @@ -124,7 +140,7 @@ /> <div class="results-container"> - {#each filtered as item, i (item.url)} + {#each filtered as item, i (item.id || item.url)} <a href={item.url} class="header-item {selectedIndex === i ? 'selected' : ''}" diff --git a/src/lib/CommandPalette/actions.ts b/src/lib/CommandPalette/actions.ts index acbc3629..16179864 100644 --- a/src/lib/CommandPalette/actions.ts +++ b/src/lib/CommandPalette/actions.ts @@ -60,6 +60,38 @@ export const defaultActions: CommandPaletteAction[] = [ 'debug', 'language', 'locale' + ], + actions: [ + { + name: 'Settings Sync', + url: '/settings#sync', + tags: ['settings'] + }, + { + name: 'RSS Feeds', + url: '/settings#feeds', + tags: ['settings'] + }, + { + name: 'Display', + url: '/settings', + tags: ['settings'] + }, + { + name: 'Calculation', + url: '/settings', + tags: ['settings'] + }, + { + name: 'Cache', + url: '/settings', + tags: ['settings'] + }, + { + name: 'Debug', + url: '/settings#debug', + tags: ['settings'] + } ] }, { |