| 251 | } |
| 252 | |
| 253 | export 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 | |
| 300 | export function useCommandPaletteQueryOverride( |
| 301 | group: CommandPaletteGroup, |