| 215 | } |
| 216 | |
| 217 | export function useCommandPalettePackageContext( |
| 218 | context: MaybeRefOrGetter<CommandPalettePackageContext | null>, |
| 219 | options?: { |
| 220 | onOpen?: () => void | Promise<void> |
| 221 | }, |
| 222 | ) { |
| 223 | const { |
| 224 | setPackageContext, |
| 225 | clearPackageContext, |
| 226 | setPackageContextOnOpen, |
| 227 | clearPackageContextOnOpen, |
| 228 | } = useCommandPalette() |
| 229 | const scopeId = useId() |
| 230 | |
| 231 | if (import.meta.client && options?.onOpen) { |
| 232 | setPackageContextOnOpen(scopeId, options.onOpen) |
| 233 | } |
| 234 | |
| 235 | watchEffect(() => { |
| 236 | const value = toValue(context) |
| 237 | if (value) { |
| 238 | setPackageContext(value, scopeId) |
| 239 | return |
| 240 | } |
| 241 | |
| 242 | clearPackageContext(scopeId) |
| 243 | }) |
| 244 | |
| 245 | onScopeDispose(() => { |
| 246 | clearPackageContext(scopeId) |
| 247 | if (import.meta.client) { |
| 248 | clearPackageContextOnOpen(scopeId) |
| 249 | } |
| 250 | }) |
| 251 | } |
| 252 | |
| 253 | export function useCommandPaletteContextCommands( |
| 254 | commands: MaybeRefOrGetter<CommandPaletteContextCommandInput[]>, |