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

Function useCommandPaletteContextCommands

app/composables/useCommandPalette.ts:253–298  ·  view source on GitHub ↗
(
  commands: MaybeRefOrGetter<CommandPaletteContextCommandInput[]>,
)

Source from the content-addressed store, hash-verified

251}
252
253export function useCommandPaletteContextCommands(
254 commands: MaybeRefOrGetter<CommandPaletteContextCommandInput[]>,
255) {
256 const {
257 setContextCommands,
258 clearContextCommands,
259 registerContextCommandActions,
260 clearContextCommandActions,
261 } = useCommandPalette()
262 const scopeId = useId()
263
264 watch(
265 () => toValue(commands),
266 value => {
267 const serializedCommands = value.map((command, index) =>
268 stripContextCommandAction(command, `${scopeId}:${index}`),
269 )
270
271 setContextCommands(serializedCommands, scopeId)
272
273 if (import.meta.client) {
274 registerContextCommandActions(
275 scopeId,
276 value.flatMap((command, index) =>
277 command.action != null
278 ? [
279 {
280 actionId: `${scopeId}:${index}`,
281 action: command.action,
282 },
283 ]
284 : [],
285 ),
286 )
287 }
288 },
289 { immediate: true },
290 )
291
292 onScopeDispose(() => {
293 clearContextCommands(scopeId)
294 if (import.meta.client) {
295 clearContextCommandActions(scopeId)
296 }
297 })
298}
299
300export function useCommandPaletteQueryOverride(
301 group: CommandPaletteGroup,

Callers 4

setupFunction · 0.85
setupFunction · 0.85

Calls 6

useCommandPaletteFunction · 0.85
setContextCommandsFunction · 0.85
clearContextCommandsFunction · 0.85

Tested by 2

setupFunction · 0.68
setupFunction · 0.68