MCPcopy
hub / github.com/npmx-dev/npmx.dev / useCommandPalette

Function useCommandPalette

app/composables/useCommandPalette.ts:34–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32}
33
34export function useCommandPalette() {
35 const isOpen = useState('command-palette:is-open', () => false)
36 const query = useState('command-palette:query', () => '')
37 const view = useState<CommandPaletteView>('command-palette:view', () => 'root')
38 const announcement = useState('command-palette:announcement', () => '')
39 const packageContext = useState<CommandPalettePackageContext | null>(
40 'command-palette:package-context',
41 () => null,
42 )
43 const packageContextScopeId = useState<string | null>(
44 'command-palette:package-context-scope-id',
45 () => null,
46 )
47 const contextCommands = useState<
48 Array<{ scopeId: string; commands: CommandPaletteContextCommand[] }>
49 >('command-palette:context-commands', () => [])
50 const queryOverrides = useState<Array<{ scopeId: string; group: CommandPaletteGroup }>>(
51 'command-palette:query-overrides',
52 () => [],
53 )
54
55 function open() {
56 isOpen.value = true
57
58 if (import.meta.client) {
59 const scopeId = packageContextScopeId.value
60 if (!scopeId) return
61
62 const onOpen = packageContextOpenRegistry.get(scopeId)
63 if (!onOpen) return
64
65 void Promise.resolve(onOpen()).catch(() => {})
66 }
67 }
68
69 function close() {
70 isOpen.value = false
71 query.value = ''
72 view.value = 'root'
73 }
74
75 function toggle() {
76 if (isOpen.value) {
77 close()
78 return
79 }
80
81 open()
82 }
83
84 function setView(nextView: CommandPaletteView) {
85 view.value = nextView
86 query.value = ''
87 }
88
89 function announce(message: string) {
90 if (!message) return
91

Callers 13

setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85
setupFunction · 0.85

Calls

no outgoing calls

Tested by 4

setupFunction · 0.68
setupFunction · 0.68
setupFunction · 0.68
setupFunction · 0.68