modern-cmdk 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +76 -172
- package/THIRD-PARTY-NOTICES.md +303 -0
- package/dist/codemod/bin.mjs +14 -0
- package/dist/codemod/chunk-jscodeshift.mjs +36210 -0
- package/dist/codemod/chunk-print-options.mjs +43 -0
- package/dist/codemod/chunk-worker.mjs +476 -0
- package/dist/codemod/cli.mjs +298 -43659
- package/dist/codemod/transforms/data-attrs.mjs +551 -38
- package/dist/codemod/transforms/forward-ref.mjs +197 -32
- package/dist/codemod/transforms/import-rewrite.mjs +389 -30
- package/dist/codemod/transforms/should-filter.mjs +199 -10
- package/dist/codemod/worker.mjs +1 -0
- package/dist/core/index.d.mts +6 -1
- package/dist/core/index.mjs +12 -4
- package/dist/react/chunk-dialog.mjs +237 -0
- package/dist/react/dialog.d.mts +18 -0
- package/dist/react/dialog.mjs +2 -0
- package/dist/react/index.d.mts +26 -334
- package/dist/react/index.mjs +54 -1377
- package/dist/react/styles.css +2 -2
- package/package.json +12 -18
- package/dist/codemod/cli.d.mts +0 -16
- package/dist/codemod/transforms/data-attrs.d.mts +0 -6
- package/dist/codemod/transforms/forward-ref.d.mts +0 -6
- package/dist/codemod/transforms/import-rewrite.d.mts +0 -6
- package/dist/codemod/transforms/should-filter.d.mts +0 -5
package/dist/react/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
|
+
import { CommandDialog, CommandDialogProps } from "./dialog.mjs";
|
|
2
3
|
import { Component, ComponentPropsWithRef, Context, ErrorInfo, ReactNode } from "react";
|
|
4
|
+
import { CommandItem as CommandItem$1, CommandMachine, CommandMachineOptions, CommandState, GroupId, ItemId } from "modern-cmdk";
|
|
3
5
|
/** Activity mode — maps directly to React's Activity API */
|
|
4
6
|
type ActivityMode = "visible" | "hidden";
|
|
5
7
|
/** Props for the CommandActivity wrapper that controls visibility via React's Activity API. */
|
|
@@ -14,347 +16,24 @@ interface CommandActivityProps {
|
|
|
14
16
|
* Falls back to conditional rendering if Activity is unavailable.
|
|
15
17
|
*/
|
|
16
18
|
export declare function CommandActivity({ mode, children }: CommandActivityProps): ReactNode;
|
|
17
|
-
/** Result of scoring a single item against a query */
|
|
18
|
-
interface SearchResult {
|
|
19
|
-
readonly id: ItemId;
|
|
20
|
-
readonly score: number;
|
|
21
|
-
/** Character ranges that matched (for highlighting) — half-open [start, end) tuples, end exclusive */
|
|
22
|
-
readonly matches: ReadonlyArray<readonly [start: number, end: number]>;
|
|
23
|
-
}
|
|
24
|
-
/** Search engine interface — pluggable into the state machine */
|
|
25
|
-
interface SearchEngine extends Disposable {
|
|
26
|
-
/** Index items for fast lookup (call on registration) */
|
|
27
|
-
index(items: readonly CommandItem$1[]): void;
|
|
28
|
-
/** Search items by query, return ordered results — uses Iterator pipeline */
|
|
29
|
-
search(query: string, items: readonly CommandItem$1[]): IteratorObject<SearchResult>;
|
|
30
|
-
/** Remove items from index by id */
|
|
31
|
-
remove(ids: ReadonlySet<ItemId>): void;
|
|
32
|
-
/** Clear the entire index */
|
|
33
|
-
clear(): void;
|
|
34
|
-
/** Dispose resources */
|
|
35
|
-
[Symbol.dispose](): void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Branded type for command item IDs.
|
|
39
|
-
* Prevents accidental mixing with plain strings at the type level.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```ts
|
|
43
|
-
* const id = itemId('copy');
|
|
44
|
-
* // id has type ItemId, not string — catches type errors at compile time
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
declare const __itemIdBrand: unique symbol;
|
|
48
|
-
type ItemId = string & {
|
|
49
|
-
readonly [__itemIdBrand]: never;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Branded type for group IDs.
|
|
53
|
-
* Prevents accidental mixing with plain strings or ItemId at the type level.
|
|
54
|
-
*/
|
|
55
|
-
declare const __groupIdBrand: unique symbol;
|
|
56
|
-
type GroupId = string & {
|
|
57
|
-
readonly [__groupIdBrand]: never;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* A registered command item in the palette.
|
|
61
|
-
* All fields are readonly — state machine creates new items on update.
|
|
62
|
-
*/
|
|
63
|
-
interface CommandItem$1 {
|
|
64
|
-
/** Unique identifier (branded type) */
|
|
65
|
-
readonly id: ItemId;
|
|
66
|
-
/** Display text — also used as the primary search target */
|
|
67
|
-
readonly value: string;
|
|
68
|
-
/** Additional searchable terms (matched but not displayed) */
|
|
69
|
-
readonly keywords?: readonly string[] | undefined;
|
|
70
|
-
/** Group this item belongs to (items without groupId are ungrouped) */
|
|
71
|
-
readonly groupId?: GroupId | undefined;
|
|
72
|
-
/** Keyboard shortcut string (e.g., "Ctrl+C", "Mod+K") */
|
|
73
|
-
readonly shortcut?: string | undefined;
|
|
74
|
-
/** Whether this item is disabled (excluded from filtering and selection) */
|
|
75
|
-
readonly disabled?: boolean | undefined;
|
|
76
|
-
/** Callback fired when this item is selected */
|
|
77
|
-
readonly onSelect?: (() => void) | undefined;
|
|
78
|
-
/** Arbitrary metadata attached to the item */
|
|
79
|
-
readonly data?: Readonly<Record<string, unknown>> | undefined;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* A command group for categorizing items.
|
|
83
|
-
* Groups are rendered with headings and sorted by priority.
|
|
84
|
-
*/
|
|
85
|
-
interface CommandGroup$1 {
|
|
86
|
-
/** Unique identifier (branded type) */
|
|
87
|
-
readonly id: GroupId;
|
|
88
|
-
/** Display heading text (rendered above the group's items) */
|
|
89
|
-
readonly heading?: string | undefined;
|
|
90
|
-
/** Sort priority — lower values appear first (default: 0) */
|
|
91
|
-
readonly priority?: number | undefined;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Immutable state snapshot of the command palette.
|
|
95
|
-
* Consumed by React via `useSyncExternalStore` — each mutation
|
|
96
|
-
* produces a new object reference for efficient re-render detection.
|
|
97
|
-
*/
|
|
98
|
-
interface CommandState {
|
|
99
|
-
/** Current search query string */
|
|
100
|
-
readonly search: string;
|
|
101
|
-
/** Currently active (highlighted) item ID, or null if none */
|
|
102
|
-
readonly activeId: ItemId | null;
|
|
103
|
-
/** Ordered list of item IDs that pass the current filter */
|
|
104
|
-
readonly filteredIds: readonly ItemId[];
|
|
105
|
-
/** Map of group IDs to their visible item IDs */
|
|
106
|
-
readonly groupedIds: ReadonlyMap<GroupId, readonly ItemId[]>;
|
|
107
|
-
/** Count of visible items (shortcut for `filteredIds.length`) */
|
|
108
|
-
readonly filteredCount: number;
|
|
109
|
-
/** Whether async items are currently loading */
|
|
110
|
-
readonly loading: boolean;
|
|
111
|
-
/** Current page identifier (for multi-page navigation) */
|
|
112
|
-
readonly page: string;
|
|
113
|
-
/** Stack of previous pages for back-navigation */
|
|
114
|
-
readonly pageStack: readonly string[];
|
|
115
|
-
/** Whether the command palette dialog is open */
|
|
116
|
-
readonly open: boolean;
|
|
117
|
-
/** Epoch-millisecond timestamp of the last state mutation */
|
|
118
|
-
readonly lastUpdated: number;
|
|
119
|
-
}
|
|
120
|
-
/** All possible events the state machine accepts */
|
|
121
|
-
type CommandEvent = {
|
|
122
|
-
readonly type: "SEARCH_CHANGE";
|
|
123
|
-
readonly query: string;
|
|
124
|
-
} | {
|
|
125
|
-
readonly type: "ITEM_SELECT";
|
|
126
|
-
readonly id: ItemId;
|
|
127
|
-
} | {
|
|
128
|
-
readonly type: "ITEM_ACTIVATE";
|
|
129
|
-
readonly id: ItemId;
|
|
130
|
-
} | {
|
|
131
|
-
readonly type: "NAVIGATE";
|
|
132
|
-
readonly direction: "next" | "prev" | "first" | "last";
|
|
133
|
-
} | {
|
|
134
|
-
readonly type: "PAGE_PUSH";
|
|
135
|
-
readonly page: string;
|
|
136
|
-
} | {
|
|
137
|
-
readonly type: "PAGE_POP";
|
|
138
|
-
} | {
|
|
139
|
-
readonly type: "OPEN";
|
|
140
|
-
} | {
|
|
141
|
-
readonly type: "CLOSE";
|
|
142
|
-
} | {
|
|
143
|
-
readonly type: "TOGGLE";
|
|
144
|
-
} | {
|
|
145
|
-
readonly type: "ITEMS_LOADED";
|
|
146
|
-
readonly items: readonly CommandItem$1[];
|
|
147
|
-
} | {
|
|
148
|
-
readonly type: "REGISTER_ITEM";
|
|
149
|
-
readonly item: CommandItem$1;
|
|
150
|
-
} | {
|
|
151
|
-
readonly type: "UNREGISTER_ITEM";
|
|
152
|
-
readonly id: ItemId;
|
|
153
|
-
} | {
|
|
154
|
-
readonly type: "REGISTER_GROUP";
|
|
155
|
-
readonly group: CommandGroup$1;
|
|
156
|
-
} | {
|
|
157
|
-
readonly type: "UNREGISTER_GROUP";
|
|
158
|
-
readonly id: GroupId;
|
|
159
|
-
};
|
|
160
|
-
/** Frecency record for a single item */
|
|
161
|
-
interface FrecencyRecord {
|
|
162
|
-
readonly frequency: number;
|
|
163
|
-
/** Epoch-millisecond timestamp of last usage */
|
|
164
|
-
readonly lastUsed: number;
|
|
165
|
-
}
|
|
166
|
-
/** Complete frecency data for persistence */
|
|
167
|
-
interface FrecencyData {
|
|
168
|
-
readonly records: ReadonlyMap<ItemId, FrecencyRecord>;
|
|
169
|
-
}
|
|
170
|
-
/** Pluggable frecency storage interface */
|
|
171
|
-
interface FrecencyStorage extends Disposable {
|
|
172
|
-
load(namespace: string): FrecencyData | Promise<FrecencyData>;
|
|
173
|
-
save(namespace: string, data: FrecencyData): void | Promise<void>;
|
|
174
|
-
}
|
|
175
|
-
/** Frecency step-weight configuration per recency bucket (hour/day/week/month/older) */
|
|
176
|
-
interface FrecencyDecayConfig {
|
|
177
|
-
readonly hourWeight?: number | undefined;
|
|
178
|
-
readonly dayWeight?: number | undefined;
|
|
179
|
-
readonly weekWeight?: number | undefined;
|
|
180
|
-
readonly monthWeight?: number | undefined;
|
|
181
|
-
readonly olderWeight?: number | undefined;
|
|
182
|
-
}
|
|
183
|
-
/** Frecency configuration options */
|
|
184
|
-
interface FrecencyOptions {
|
|
185
|
-
readonly enabled: boolean;
|
|
186
|
-
readonly storage?: FrecencyStorage | undefined;
|
|
187
|
-
readonly namespace?: string | undefined;
|
|
188
|
-
readonly decayConfig?: FrecencyDecayConfig | undefined;
|
|
189
|
-
}
|
|
190
|
-
/** Options for creating a command machine */
|
|
191
|
-
interface CommandMachineOptions {
|
|
192
|
-
/** Pre-registered items to populate on creation */
|
|
193
|
-
readonly items?: readonly CommandItem$1[] | undefined;
|
|
194
|
-
/** Pre-registered groups for item categorization */
|
|
195
|
-
readonly groups?: readonly CommandGroup$1[] | undefined;
|
|
196
|
-
/** Custom filter function, or `false` to disable filtering entirely */
|
|
197
|
-
readonly filter?: ((item: CommandItem$1, query: string) => number | false) | false | undefined;
|
|
198
|
-
/** Accessible label for the command palette */
|
|
199
|
-
readonly label?: string | undefined;
|
|
200
|
-
/** Initial open state */
|
|
201
|
-
readonly open?: boolean | undefined;
|
|
202
|
-
/** Frecency configuration for usage-aware ranking */
|
|
203
|
-
readonly frecency?: FrecencyOptions | undefined;
|
|
204
|
-
/** Pluggable search engine — drop-in replacement for the default scorer (e.g., WASM engine) */
|
|
205
|
-
readonly search?: SearchEngine | undefined;
|
|
206
|
-
/** Callback fired when an item is selected */
|
|
207
|
-
readonly onSelect?: ((id: ItemId) => void) | undefined;
|
|
208
|
-
/** Callback fired when the active (highlighted) item changes */
|
|
209
|
-
readonly onActiveChange?: ((id: ItemId | null) => void) | undefined;
|
|
210
|
-
/** Callback fired when the dialog open state changes */
|
|
211
|
-
readonly onOpenChange?: ((open: boolean) => void) | undefined;
|
|
212
|
-
/** Callback fired when the search query changes */
|
|
213
|
-
readonly onSearchChange?: ((query: string) => void) | undefined;
|
|
214
|
-
/** Whether keyboard navigation loops from last to first item (default: true) */
|
|
215
|
-
readonly loop?: boolean | undefined;
|
|
216
|
-
/** Accepted but not read yet: Command.List uses fixed thresholds (on above 100 matches, off at 50 or fewer) (default: 100) */
|
|
217
|
-
readonly virtualizeThreshold?: number | undefined;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Structured representation of a keyboard shortcut after parsing.
|
|
221
|
-
* The `normalized` field provides a deterministic string for dedup and comparison.
|
|
222
|
-
*/
|
|
223
|
-
interface ParsedShortcut {
|
|
224
|
-
readonly key: string;
|
|
225
|
-
readonly meta: boolean;
|
|
226
|
-
readonly ctrl: boolean;
|
|
227
|
-
readonly shift: boolean;
|
|
228
|
-
readonly alt: boolean;
|
|
229
|
-
readonly raw: string;
|
|
230
|
-
readonly normalized: string;
|
|
231
|
-
}
|
|
232
|
-
interface ShortcutBinding {
|
|
233
|
-
readonly shortcut: ParsedShortcut;
|
|
234
|
-
readonly itemId: ItemId;
|
|
235
|
-
readonly handler: () => void;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Manages keyboard shortcut bindings with global keydown listening.
|
|
239
|
-
* Supports `using` for automatic cleanup of both individual bindings and the
|
|
240
|
-
* global document listener. Detects conflicts with the local mapGroupBy helper (core/utils/group-by.ts).
|
|
241
|
-
*/
|
|
242
|
-
declare class KeyboardShortcutRegistry implements Disposable {
|
|
243
|
-
#private;
|
|
244
|
-
constructor(options?: {
|
|
245
|
-
enabled?: boolean;
|
|
246
|
-
});
|
|
247
|
-
/** Register a shortcut binding — returns Disposable for `using` auto-deregister */
|
|
248
|
-
register(shortcutStr: string, itemId: ItemId, handler: () => void): Disposable;
|
|
249
|
-
/** Unregister a shortcut by its string representation */
|
|
250
|
-
unregister(shortcutStr: string): void;
|
|
251
|
-
/** Unregister all shortcuts for a given item — Map spec allows deletion during iteration */
|
|
252
|
-
unregisterByItem(itemId: ItemId): void;
|
|
253
|
-
/** Check for conflicting shortcuts */
|
|
254
|
-
getConflicts(): ReadonlyMap<string, readonly ParsedShortcut[]>;
|
|
255
|
-
/** Enable or disable global shortcut listening */
|
|
256
|
-
setEnabled(enabled: boolean): void;
|
|
257
|
-
/** Get all registered bindings */
|
|
258
|
-
getBindings(): ReadonlyMap<string, ShortcutBinding>;
|
|
259
|
-
[Symbol.dispose](): void;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Manages registration and lookup of command items and groups.
|
|
263
|
-
* Uses set operation helpers (union/intersection/difference) for efficient ID operations.
|
|
264
|
-
* All registration methods return Disposable for automatic cleanup via `using`.
|
|
265
|
-
*/
|
|
266
|
-
declare class CommandRegistry implements Disposable {
|
|
267
|
-
#private;
|
|
268
|
-
/** Register an item — returns Disposable for `using` auto-deregister */
|
|
269
|
-
registerItem(item: CommandItem$1): Disposable;
|
|
270
|
-
/** Register multiple items at once — single Disposable for batch cleanup. for...of for hot path. */
|
|
271
|
-
registerItems(items: readonly CommandItem$1[]): Disposable;
|
|
272
|
-
/** Unregister a single item — O(1) Map/Set delete, indexOf+toSpliced for order */
|
|
273
|
-
unregisterItem(id: ItemId): void;
|
|
274
|
-
/** Bulk unregister — for...of for hot path */
|
|
275
|
-
unregisterItems(ids: ReadonlySet<ItemId>): void;
|
|
276
|
-
/** Register a group */
|
|
277
|
-
registerGroup(group: CommandGroup$1): Disposable;
|
|
278
|
-
/** Unregister a group */
|
|
279
|
-
unregisterGroup(id: GroupId): void;
|
|
280
|
-
/** Get an item by ID — O(1) */
|
|
281
|
-
getItem(id: ItemId): CommandItem$1 | undefined;
|
|
282
|
-
/** Get a group by ID — O(1) */
|
|
283
|
-
getGroup(id: GroupId): CommandGroup$1 | undefined;
|
|
284
|
-
/** Get all registered items in insertion order — cached between mutations */
|
|
285
|
-
getItems(): readonly CommandItem$1[];
|
|
286
|
-
/** Get all registered groups sorted by priority — cached between group mutations */
|
|
287
|
-
getGroups(): readonly CommandGroup$1[];
|
|
288
|
-
/** Get items grouped by groupId — direct Map, no Object.entries conversion */
|
|
289
|
-
getGroupedItems(): ReadonlyMap<GroupId, readonly CommandItem$1[]>;
|
|
290
|
-
/** Get item IDs as a Set — returns internal set (O(1), no allocation) */
|
|
291
|
-
getItemIds(): ReadonlySet<ItemId>;
|
|
292
|
-
/** Find intersection of registered items with a candidate set */
|
|
293
|
-
intersectWith(candidateIds: ReadonlySet<ItemId>): ReadonlySet<ItemId>;
|
|
294
|
-
/** Find items registered but not in a given set */
|
|
295
|
-
differenceFrom(otherIds: ReadonlySet<ItemId>): ReadonlySet<ItemId>;
|
|
296
|
-
/** Union of registered IDs with another set */
|
|
297
|
-
unionWith(otherIds: ReadonlySet<ItemId>): ReadonlySet<ItemId>;
|
|
298
|
-
/** Check if registered items are a subset of the given set */
|
|
299
|
-
isSubsetOf(otherIds: ReadonlySet<ItemId>): boolean;
|
|
300
|
-
/** Check if registered items are a superset of the given set */
|
|
301
|
-
isSupersetOf(otherIds: ReadonlySet<ItemId>): boolean;
|
|
302
|
-
/** Check if registered items share no IDs with the given set */
|
|
303
|
-
isDisjointFrom(otherIds: ReadonlySet<ItemId>): boolean;
|
|
304
|
-
/** Symmetric difference between registered IDs and another set */
|
|
305
|
-
symmetricDifferenceWith(otherIds: ReadonlySet<ItemId>): ReadonlySet<ItemId>;
|
|
306
|
-
/** Total number of registered items */
|
|
307
|
-
get size(): number;
|
|
308
|
-
/** Total number of registered groups */
|
|
309
|
-
get groupCount(): number;
|
|
310
|
-
/** Clear all items and groups */
|
|
311
|
-
clear(): void;
|
|
312
|
-
[Symbol.dispose](): void;
|
|
313
|
-
}
|
|
314
|
-
/** Command machine — explicit resource management via `using` */
|
|
315
|
-
interface CommandMachine extends Disposable {
|
|
316
|
-
getState(): CommandState;
|
|
317
|
-
send(event: CommandEvent): void;
|
|
318
|
-
/** Subscribe to state changes — useSyncExternalStore-compatible (returns cleanup function) */
|
|
319
|
-
subscribe(listener: () => void): () => void;
|
|
320
|
-
/** Subscribe to full state changes — returns Disposable for `using` pattern */
|
|
321
|
-
subscribeState(listener: (state: CommandState) => void): Disposable;
|
|
322
|
-
getRegistry(): CommandRegistry;
|
|
323
|
-
getKeyboardRegistry(): KeyboardShortcutRegistry;
|
|
324
|
-
/** Get the current set of filtered item IDs — O(1) membership checks */
|
|
325
|
-
getFilteredIdSet(): ReadonlySet<ItemId>;
|
|
326
|
-
/** Get the index map for filtered IDs — O(1) positional lookup */
|
|
327
|
-
getFilteredIdIndex(): ReadonlyMap<ItemId, number>;
|
|
328
|
-
[Symbol.dispose](): void;
|
|
329
|
-
}
|
|
330
19
|
interface CommandAsyncItemsProps {
|
|
331
|
-
/** Promise that resolves to items */
|
|
20
|
+
/** Promise that resolves to items; keep it stable across renders (state, a ref, or `useMemo`) or the boundary re-suspends on every render */
|
|
332
21
|
readonly items: Promise<readonly CommandItem$1[]>;
|
|
333
22
|
/** Fallback content while loading */
|
|
334
23
|
readonly fallback?: ReactNode;
|
|
335
24
|
/** Render function for resolved items */
|
|
336
25
|
readonly children: (items: readonly CommandItem$1[]) => ReactNode;
|
|
337
26
|
}
|
|
338
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Suspense-based async item loader that resolves a promise of items using React 19 `use()`.
|
|
29
|
+
*
|
|
30
|
+
* The `items` promise must be kept stable across renders (held in state, a ref, or `useMemo`):
|
|
31
|
+
* a new promise on every render, such as `items={fetchItems()}`, suspends again on every render.
|
|
32
|
+
*/
|
|
339
33
|
export declare function CommandAsyncItems({ items, fallback, children }: CommandAsyncItemsProps): ReactNode;
|
|
340
34
|
interface CommandBadgeProps extends ComponentPropsWithRef<"span"> {}
|
|
341
35
|
/** Inline badge for categorization or status indicators on command items. */
|
|
342
36
|
export declare function CommandBadge({ ref, children, ...props }: CommandBadgeProps): ReactNode;
|
|
343
|
-
interface CommandDialogProps extends CommandMachineOptions {
|
|
344
|
-
readonly children?: ReactNode;
|
|
345
|
-
readonly className?: string;
|
|
346
|
-
readonly overlayClassName?: string;
|
|
347
|
-
readonly contentClassName?: string;
|
|
348
|
-
readonly label?: string;
|
|
349
|
-
readonly open?: boolean;
|
|
350
|
-
readonly onOpenChange?: (open: boolean) => void;
|
|
351
|
-
/** Accessible description for screen readers (default: 'Type a command or search...') */
|
|
352
|
-
readonly description?: string;
|
|
353
|
-
/** Container element for the portal (default: document.body) */
|
|
354
|
-
readonly container?: HTMLElement | null;
|
|
355
|
-
}
|
|
356
|
-
/** Dialog variant that wraps the command palette in a Radix UI Dialog with focus trap and overlay. */
|
|
357
|
-
export declare function CommandDialog({ children, className, overlayClassName, contentClassName, label, description, open: controlledOpen, onOpenChange, container, ...machineOptions }: CommandDialogProps): ReactNode;
|
|
358
37
|
interface CommandEmptyProps extends ComponentPropsWithRef<"div"> {}
|
|
359
38
|
/** Rendered when no items match the current search query. */
|
|
360
39
|
export declare function CommandEmpty({ ref, children, ...props }: CommandEmptyProps): ReactNode;
|
|
@@ -386,6 +65,7 @@ export declare function CommandInput({ ref, placeholder, onValueChange, ...props
|
|
|
386
65
|
interface CommandItemProps extends Omit<ComponentPropsWithRef<"div">, "onSelect" | "value"> {
|
|
387
66
|
readonly value: string;
|
|
388
67
|
readonly keywords?: readonly string[];
|
|
68
|
+
/** Called when the item is selected by click, Enter or shortcut (no argument in 1.x; the value arrives in 2.0) */
|
|
389
69
|
readonly onSelect?: () => void;
|
|
390
70
|
readonly disabled?: boolean;
|
|
391
71
|
readonly shortcut?: string;
|
|
@@ -471,7 +151,7 @@ interface CommandContextValue {
|
|
|
471
151
|
readonly filteredIdSet: ReadonlySet<ItemId>;
|
|
472
152
|
/** IDs currently visible in virtual viewport + overscan. null = not virtualizing (render all filtered). */
|
|
473
153
|
readonly visibleIdSet: ReadonlySet<ItemId> | null;
|
|
474
|
-
/** Map of visible item IDs to their
|
|
154
|
+
/** Map of visible item IDs to their translate offsets in px. null = not virtualizing. */
|
|
475
155
|
readonly virtualPositionMap: ReadonlyMap<ItemId, number> | null;
|
|
476
156
|
readonly rootId: CommandRootId;
|
|
477
157
|
readonly listId: string;
|
|
@@ -496,7 +176,7 @@ interface CommandStateContextValue {
|
|
|
496
176
|
readonly filteredIdSet: ReadonlySet<ItemId>;
|
|
497
177
|
/** IDs currently visible in virtual viewport + overscan. null = not virtualizing (render all filtered). */
|
|
498
178
|
readonly visibleIdSet: ReadonlySet<ItemId> | null;
|
|
499
|
-
/** Map of visible item IDs to their
|
|
179
|
+
/** Map of visible item IDs to their translate offsets in px. null = not virtualizing. */
|
|
500
180
|
readonly virtualPositionMap: ReadonlyMap<ItemId, number> | null;
|
|
501
181
|
}
|
|
502
182
|
export declare const CommandStableContext: Context<CommandStableContextValue | null>;
|
|
@@ -507,7 +187,16 @@ interface CommandGroupContextValue {
|
|
|
507
187
|
}
|
|
508
188
|
interface CommandErrorBoundaryProps {
|
|
509
189
|
readonly children: ReactNode;
|
|
510
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Rendered in place of the children after an error. A function receives the error and a `reset`
|
|
192
|
+
* callback that clears it, so the children render again (a retry button, for example).
|
|
193
|
+
*/
|
|
194
|
+
readonly fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);
|
|
195
|
+
/**
|
|
196
|
+
* While the boundary shows its fallback, a change in these values (compared entry by entry with
|
|
197
|
+
* `Object.is`; a different length counts as a change) clears the error and renders the children again.
|
|
198
|
+
*/
|
|
199
|
+
readonly resetKeys?: readonly unknown[];
|
|
511
200
|
readonly onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
512
201
|
}
|
|
513
202
|
interface CommandErrorBoundaryState {
|
|
@@ -518,6 +207,9 @@ export declare class CommandErrorBoundary extends Component<CommandErrorBoundary
|
|
|
518
207
|
override state: CommandErrorBoundaryState;
|
|
519
208
|
static getDerivedStateFromError(error: Error): CommandErrorBoundaryState;
|
|
520
209
|
override componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
210
|
+
override componentDidUpdate(prevProps: CommandErrorBoundaryProps, prevState: CommandErrorBoundaryState): void;
|
|
211
|
+
/** Clears the captured error so the children render again. */
|
|
212
|
+
reset: () => void;
|
|
521
213
|
override render(): ReactNode;
|
|
522
214
|
}
|
|
523
215
|
interface UseCommandReturn {
|
|
@@ -594,4 +286,4 @@ interface VirtualizerReturn {
|
|
|
594
286
|
}
|
|
595
287
|
/** Lightweight virtualizer for large item lists using ResizeObserver and scroll tracking. */
|
|
596
288
|
export declare function useVirtualizer(options: VirtualizerOptions): VirtualizerReturn;
|
|
597
|
-
export type
|
|
289
|
+
export { type ActivityMode, type CommandActivityProps, type CommandAsyncItemsProps, type CommandBadgeProps, type CommandContextValue, CommandDialog, type CommandDialogProps, type CommandEmptyProps, type CommandErrorBoundaryProps, type CommandGroupContextValue, type CommandGroupProps, type CommandHighlightProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandLoadingProps, type CommandPageId, type CommandPageProps, type CommandRootId, type CommandRootProps, type CommandSeparatorProps, type CommandShortcutProps, type CommandStableContextValue, type CommandStateContextValue, type RegisterGroupOptions, type RegisterItemOptions, type UseCommandReturn, type VirtualItem, type VirtualizerOptions, type VirtualizerReturn };
|