modern-cmdk 1.2.1 → 1.2.2
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/CHANGELOG.md +98 -0
- package/README.md +6 -2
- package/dist/codemod/cli.d.mts +1 -1
- package/dist/codemod/cli.mjs +1067 -603
- package/dist/codemod/transforms/data-attrs.d.mts +5 -7
- package/dist/codemod/transforms/forward-ref.d.mts +5 -7
- package/dist/codemod/transforms/import-rewrite.d.mts +5 -7
- package/dist/codemod/transforms/should-filter.d.mts +4 -6
- package/dist/core/index.d.mts +149 -149
- package/dist/core/index.mjs +5 -7
- package/dist/react/index.d.mts +76 -159
- package/dist/react/index.mjs +78 -81
- package/package.json +6 -6
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { API, FileInfo } from "jscodeshift";
|
|
2
|
-
|
|
3
2
|
//#region src/codemod/transforms/data-attrs.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* jscodeshift transform — renames cmdk data attributes in JSX and
|
|
6
|
-
* CSS selectors within string/template literals.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { transform as default };
|
|
4
|
+
* jscodeshift transform — renames cmdk data attributes in JSX and
|
|
5
|
+
* CSS selectors within string/template literals.
|
|
6
|
+
*/
|
|
7
|
+
export default function transform(fileInfo: FileInfo, api: API): string;
|
|
8
|
+
//#endregion
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { API, FileInfo } from "jscodeshift";
|
|
2
|
-
|
|
3
2
|
//#region src/codemod/transforms/forward-ref.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* jscodeshift transform — removes forwardRef wrappers and merges the
|
|
6
|
-
* ref parameter into the props object as a regular prop.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { transform as default };
|
|
4
|
+
* jscodeshift transform — removes forwardRef wrappers and merges the
|
|
5
|
+
* ref parameter into the props object as a regular prop.
|
|
6
|
+
*/
|
|
7
|
+
export default function transform(fileInfo: FileInfo, api: API): string;
|
|
8
|
+
//#endregion
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { API, FileInfo } from "jscodeshift";
|
|
2
|
-
|
|
3
2
|
//#region src/codemod/transforms/import-rewrite.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* jscodeshift transform — rewrites all import/require/re-export paths
|
|
6
|
-
* from `cmdk` to `modern-cmdk/react`.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { transform as default };
|
|
4
|
+
* jscodeshift transform — rewrites all import/require/re-export paths
|
|
5
|
+
* from `cmdk` to `modern-cmdk/react`.
|
|
6
|
+
*/
|
|
7
|
+
export default function transform(fileInfo: FileInfo, api: API): string;
|
|
8
|
+
//#endregion
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { API, FileInfo } from "jscodeshift";
|
|
2
|
-
|
|
3
2
|
//#region src/codemod/transforms/should-filter.d.ts
|
|
4
3
|
/**
|
|
5
|
-
* jscodeshift transform — migrates shouldFilter prop to filter.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
|
-
export { transform as default };
|
|
4
|
+
* jscodeshift transform — migrates shouldFilter prop to filter.
|
|
5
|
+
*/
|
|
6
|
+
export default function transform(fileInfo: FileInfo, api: API): string;
|
|
7
|
+
//#endregion
|
package/dist/core/index.d.mts
CHANGED
|
@@ -24,35 +24,35 @@ interface SearchEngine extends Disposable {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/core/types.d.ts
|
|
26
26
|
/**
|
|
27
|
-
* Branded type for command item IDs.
|
|
28
|
-
* Prevents accidental mixing with plain strings at the type level.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const id = itemId('copy');
|
|
33
|
-
* // id has type ItemId, not string — catches type errors at compile time
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
27
|
+
* Branded type for command item IDs.
|
|
28
|
+
* Prevents accidental mixing with plain strings at the type level.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const id = itemId('copy');
|
|
33
|
+
* // id has type ItemId, not string — catches type errors at compile time
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
36
|
declare const __itemIdBrand: unique symbol;
|
|
37
37
|
type ItemId = string & {
|
|
38
38
|
readonly [__itemIdBrand]: never;
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
* Branded type for group IDs.
|
|
42
|
-
* Prevents accidental mixing with plain strings or ItemId at the type level.
|
|
43
|
-
*/
|
|
41
|
+
* Branded type for group IDs.
|
|
42
|
+
* Prevents accidental mixing with plain strings or ItemId at the type level.
|
|
43
|
+
*/
|
|
44
44
|
declare const __groupIdBrand: unique symbol;
|
|
45
45
|
type GroupId = string & {
|
|
46
46
|
readonly [__groupIdBrand]: never;
|
|
47
47
|
};
|
|
48
48
|
/** Create a branded {@link ItemId} from a plain string. Ensures well-formed Unicode. */
|
|
49
|
-
declare function itemId(id: string): ItemId;
|
|
49
|
+
export declare function itemId(id: string): ItemId;
|
|
50
50
|
/** Create a branded {@link GroupId} from a plain string. Ensures well-formed Unicode. */
|
|
51
|
-
declare function groupId(id: string): GroupId;
|
|
51
|
+
export declare function groupId(id: string): GroupId;
|
|
52
52
|
/**
|
|
53
|
-
* A registered command item in the palette.
|
|
54
|
-
* All fields are readonly — state machine creates new items on update.
|
|
55
|
-
*/
|
|
53
|
+
* A registered command item in the palette.
|
|
54
|
+
* All fields are readonly — state machine creates new items on update.
|
|
55
|
+
*/
|
|
56
56
|
interface CommandItem {
|
|
57
57
|
/** Unique identifier (branded type) */
|
|
58
58
|
readonly id: ItemId;
|
|
@@ -72,9 +72,9 @@ interface CommandItem {
|
|
|
72
72
|
readonly data?: Readonly<Record<string, unknown>> | undefined;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* A command group for categorizing items.
|
|
76
|
-
* Groups are rendered with headings and sorted by priority.
|
|
77
|
-
*/
|
|
75
|
+
* A command group for categorizing items.
|
|
76
|
+
* Groups are rendered with headings and sorted by priority.
|
|
77
|
+
*/
|
|
78
78
|
interface CommandGroup {
|
|
79
79
|
/** Unique identifier (branded type) */
|
|
80
80
|
readonly id: GroupId;
|
|
@@ -84,10 +84,10 @@ interface CommandGroup {
|
|
|
84
84
|
readonly priority?: number | undefined;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
* Immutable state snapshot of the command palette.
|
|
88
|
-
* Consumed by React via `useSyncExternalStore` — each mutation
|
|
89
|
-
* produces a new object reference for efficient re-render detection.
|
|
90
|
-
*/
|
|
87
|
+
* Immutable state snapshot of the command palette.
|
|
88
|
+
* Consumed by React via `useSyncExternalStore` — each mutation
|
|
89
|
+
* produces a new object reference for efficient re-render detection.
|
|
90
|
+
*/
|
|
91
91
|
interface CommandState {
|
|
92
92
|
/** Current search query string */
|
|
93
93
|
readonly search: string;
|
|
@@ -181,7 +181,7 @@ interface FrecencyOptions {
|
|
|
181
181
|
readonly decayConfig?: FrecencyDecayConfig | undefined;
|
|
182
182
|
}
|
|
183
183
|
/** Default frecency decay configuration */
|
|
184
|
-
declare const DEFAULT_FRECENCY_DECAY: Required<FrecencyDecayConfig>;
|
|
184
|
+
export declare const DEFAULT_FRECENCY_DECAY: Required<FrecencyDecayConfig>;
|
|
185
185
|
/** Options for creating a command machine — const type param for narrowed option inference */
|
|
186
186
|
interface CommandMachineOptions {
|
|
187
187
|
/** Pre-registered items to populate on creation */
|
|
@@ -212,34 +212,34 @@ interface CommandMachineOptions {
|
|
|
212
212
|
readonly virtualizeThreshold?: number | undefined;
|
|
213
213
|
}
|
|
214
214
|
/** Default machine options */
|
|
215
|
-
declare const DEFAULT_MACHINE_OPTIONS: Partial<CommandMachineOptions>;
|
|
215
|
+
export declare const DEFAULT_MACHINE_OPTIONS: Partial<CommandMachineOptions>;
|
|
216
216
|
/** Initial state factory */
|
|
217
|
-
declare function createInitialState(options?: CommandMachineOptions): CommandState;
|
|
217
|
+
export declare function createInitialState(options?: CommandMachineOptions): CommandState;
|
|
218
218
|
//#endregion
|
|
219
219
|
//#region src/core/frecency/idb-storage.d.ts
|
|
220
220
|
/**
|
|
221
|
-
* IndexedDB-backed frecency storage using idb-keyval 6.2.2.
|
|
222
|
-
*
|
|
223
|
-
* Persists frecency data across browser sessions. Implements both
|
|
224
|
-
* `Disposable` and `AsyncDisposable` for use with `using` and `await using`.
|
|
225
|
-
*
|
|
226
|
-
* idb-keyval is lazy-loaded on first method call — consumers who import
|
|
227
|
-
* the core module without using IDB frecency pay zero cost.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```ts
|
|
231
|
-
* await using storage = new IdbFrecencyStorage();
|
|
232
|
-
* const data = await storage.load('my-app');
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
declare class IdbFrecencyStorage implements FrecencyStorage, AsyncDisposable {
|
|
221
|
+
* IndexedDB-backed frecency storage using idb-keyval 6.2.2.
|
|
222
|
+
*
|
|
223
|
+
* Persists frecency data across browser sessions. Implements both
|
|
224
|
+
* `Disposable` and `AsyncDisposable` for use with `using` and `await using`.
|
|
225
|
+
*
|
|
226
|
+
* idb-keyval is lazy-loaded on first method call — consumers who import
|
|
227
|
+
* the core module without using IDB frecency pay zero cost.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* await using storage = new IdbFrecencyStorage();
|
|
232
|
+
* const data = await storage.load('my-app');
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export declare class IdbFrecencyStorage implements FrecencyStorage, AsyncDisposable {
|
|
236
236
|
#private;
|
|
237
237
|
/**
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
238
|
+
* Create an IDB-backed frecency storage.
|
|
239
|
+
*
|
|
240
|
+
* @param dbName — IndexedDB database name (default: 'modern-cmdk')
|
|
241
|
+
* @param storeName — IndexedDB object store name (default: 'frecency')
|
|
242
|
+
*/
|
|
243
243
|
constructor(dbName?: string, storeName?: string);
|
|
244
244
|
/** Load frecency data from IndexedDB for the given namespace */
|
|
245
245
|
load(namespace: string): Promise<FrecencyData>;
|
|
@@ -255,17 +255,17 @@ declare class IdbFrecencyStorage implements FrecencyStorage, AsyncDisposable {
|
|
|
255
255
|
//#endregion
|
|
256
256
|
//#region src/core/frecency/index.d.ts
|
|
257
257
|
/**
|
|
258
|
-
* Computes a frecency bonus for an item based on usage frequency and recency.
|
|
259
|
-
* Uses hour/day/week/month bucket boundaries with
|
|
260
|
-
* configurable exponential decay weights per time bucket.
|
|
261
|
-
*/
|
|
262
|
-
declare function computeFrecencyBonus(history: FrecencyRecord, now?: number, config?: FrecencyDecayConfig): number;
|
|
258
|
+
* Computes a frecency bonus for an item based on usage frequency and recency.
|
|
259
|
+
* Uses hour/day/week/month bucket boundaries with
|
|
260
|
+
* configurable exponential decay weights per time bucket.
|
|
261
|
+
*/
|
|
262
|
+
export declare function computeFrecencyBonus(history: FrecencyRecord, now?: number, config?: FrecencyDecayConfig): number;
|
|
263
263
|
/**
|
|
264
|
-
* Stateful frecency engine that tracks item selection history and provides
|
|
265
|
-
* ranking boosts for search results. Supports pluggable storage backends
|
|
266
|
-
* and automatic flush on dispose. Uses Date.now() for timestamps.
|
|
267
|
-
*/
|
|
268
|
-
declare class FrecencyEngine implements Disposable, AsyncDisposable {
|
|
264
|
+
* Stateful frecency engine that tracks item selection history and provides
|
|
265
|
+
* ranking boosts for search results. Supports pluggable storage backends
|
|
266
|
+
* and automatic flush on dispose. Uses Date.now() for timestamps.
|
|
267
|
+
*/
|
|
268
|
+
export declare class FrecencyEngine implements Disposable, AsyncDisposable {
|
|
269
269
|
#private;
|
|
270
270
|
constructor(options: FrecencyOptions);
|
|
271
271
|
/** Load frecency data from storage */
|
|
@@ -291,11 +291,11 @@ declare class FrecencyEngine implements Disposable, AsyncDisposable {
|
|
|
291
291
|
//#endregion
|
|
292
292
|
//#region src/core/frecency/memory-storage.d.ts
|
|
293
293
|
/**
|
|
294
|
-
* In-memory implementation of FrecencyStorage using a Map.
|
|
295
|
-
* Data does not persist across page reloads. Suitable for ephemeral
|
|
296
|
-
* sessions or as the default when no persistent storage is configured.
|
|
297
|
-
*/
|
|
298
|
-
declare class MemoryFrecencyStorage implements FrecencyStorage {
|
|
294
|
+
* In-memory implementation of FrecencyStorage using a Map.
|
|
295
|
+
* Data does not persist across page reloads. Suitable for ephemeral
|
|
296
|
+
* sessions or as the default when no persistent storage is configured.
|
|
297
|
+
*/
|
|
298
|
+
export declare class MemoryFrecencyStorage implements FrecencyStorage {
|
|
299
299
|
#private;
|
|
300
300
|
load(namespace: string): FrecencyData;
|
|
301
301
|
save(namespace: string, data: FrecencyData): void;
|
|
@@ -308,9 +308,9 @@ declare class MemoryFrecencyStorage implements FrecencyStorage {
|
|
|
308
308
|
//#endregion
|
|
309
309
|
//#region src/core/keyboard/parser.d.ts
|
|
310
310
|
/**
|
|
311
|
-
* Structured representation of a keyboard shortcut after parsing.
|
|
312
|
-
* The `normalized` field provides a deterministic string for dedup and comparison.
|
|
313
|
-
*/
|
|
311
|
+
* Structured representation of a keyboard shortcut after parsing.
|
|
312
|
+
* The `normalized` field provides a deterministic string for dedup and comparison.
|
|
313
|
+
*/
|
|
314
314
|
interface ParsedShortcut {
|
|
315
315
|
readonly key: string;
|
|
316
316
|
readonly meta: boolean;
|
|
@@ -321,30 +321,30 @@ interface ParsedShortcut {
|
|
|
321
321
|
readonly normalized: string;
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
* Parse a shortcut string like "Mod+Shift+K" into a structured ParsedShortcut.
|
|
325
|
-
* Ensures valid Unicode input via ensureWellFormed helper.
|
|
326
|
-
*/
|
|
327
|
-
declare function parseShortcut(shortcut: string): ParsedShortcut;
|
|
324
|
+
* Parse a shortcut string like "Mod+Shift+K" into a structured ParsedShortcut.
|
|
325
|
+
* Ensures valid Unicode input via ensureWellFormed helper.
|
|
326
|
+
*/
|
|
327
|
+
export declare function parseShortcut(shortcut: string): ParsedShortcut;
|
|
328
328
|
/**
|
|
329
|
-
* Formats a ParsedShortcut for display using platform-appropriate symbols.
|
|
330
|
-
* On macOS: renders glyphs (⌘, ⇧, ⌥, ⌃). On other platforms: text labels joined by "+".
|
|
331
|
-
*/
|
|
332
|
-
declare function formatShortcut(parsed: ParsedShortcut): string;
|
|
329
|
+
* Formats a ParsedShortcut for display using platform-appropriate symbols.
|
|
330
|
+
* On macOS: renders glyphs (⌘, ⇧, ⌥, ⌃). On other platforms: text labels joined by "+".
|
|
331
|
+
*/
|
|
332
|
+
export declare function formatShortcut(parsed: ParsedShortcut): string;
|
|
333
333
|
//#endregion
|
|
334
334
|
//#region src/core/keyboard/matcher.d.ts
|
|
335
335
|
/**
|
|
336
|
-
* Tests whether a KeyboardEvent exactly matches a ParsedShortcut,
|
|
337
|
-
* comparing all four modifier keys (meta, ctrl, shift, alt) and the primary key.
|
|
338
|
-
*/
|
|
339
|
-
declare function matchesShortcut(event: KeyboardEvent, shortcut: ParsedShortcut): boolean;
|
|
336
|
+
* Tests whether a KeyboardEvent exactly matches a ParsedShortcut,
|
|
337
|
+
* comparing all four modifier keys (meta, ctrl, shift, alt) and the primary key.
|
|
338
|
+
*/
|
|
339
|
+
export declare function matchesShortcut(event: KeyboardEvent, shortcut: ParsedShortcut): boolean;
|
|
340
340
|
/** Match a KeyboardEvent against a list of shortcuts — Iterator Helpers .find() */
|
|
341
|
-
declare function findMatchingShortcut(event: KeyboardEvent, shortcuts: readonly ParsedShortcut[]): ParsedShortcut | null;
|
|
341
|
+
export declare function findMatchingShortcut(event: KeyboardEvent, shortcuts: readonly ParsedShortcut[]): ParsedShortcut | null;
|
|
342
342
|
/**
|
|
343
|
-
* Detects conflicting shortcut bindings by grouping on their normalized form
|
|
344
|
-
* via mapGroupBy helper. Returns only groups with two or more colliding shortcuts.
|
|
345
|
-
* mapGroupBy returns a Map directly — no Object.entries conversion needed.
|
|
346
|
-
*/
|
|
347
|
-
declare function detectConflicts(shortcuts: readonly ParsedShortcut[]): ReadonlyMap<string, readonly ParsedShortcut[]>;
|
|
343
|
+
* Detects conflicting shortcut bindings by grouping on their normalized form
|
|
344
|
+
* via mapGroupBy helper. Returns only groups with two or more colliding shortcuts.
|
|
345
|
+
* mapGroupBy returns a Map directly — no Object.entries conversion needed.
|
|
346
|
+
*/
|
|
347
|
+
export declare function detectConflicts(shortcuts: readonly ParsedShortcut[]): ReadonlyMap<string, readonly ParsedShortcut[]>;
|
|
348
348
|
//#endregion
|
|
349
349
|
//#region src/core/keyboard/index.d.ts
|
|
350
350
|
interface ShortcutBinding {
|
|
@@ -353,11 +353,11 @@ interface ShortcutBinding {
|
|
|
353
353
|
readonly handler: () => void;
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
356
|
-
* Manages keyboard shortcut bindings with global keydown listening.
|
|
357
|
-
* Supports `using` for automatic cleanup of both individual bindings and the
|
|
358
|
-
* global document listener. Detects conflicts via Map.groupBy (ES2026).
|
|
359
|
-
*/
|
|
360
|
-
declare class KeyboardShortcutRegistry implements Disposable {
|
|
356
|
+
* Manages keyboard shortcut bindings with global keydown listening.
|
|
357
|
+
* Supports `using` for automatic cleanup of both individual bindings and the
|
|
358
|
+
* global document listener. Detects conflicts via Map.groupBy (ES2026).
|
|
359
|
+
*/
|
|
360
|
+
export declare class KeyboardShortcutRegistry implements Disposable {
|
|
361
361
|
#private;
|
|
362
362
|
constructor(options?: {
|
|
363
363
|
enabled?: boolean;
|
|
@@ -379,11 +379,11 @@ declare class KeyboardShortcutRegistry implements Disposable {
|
|
|
379
379
|
//#endregion
|
|
380
380
|
//#region src/core/registry.d.ts
|
|
381
381
|
/**
|
|
382
|
-
* Manages registration and lookup of command items and groups.
|
|
383
|
-
* Uses set operation helpers (union/intersection/difference) for efficient ID operations.
|
|
384
|
-
* All registration methods return Disposable for automatic cleanup via `using`.
|
|
385
|
-
*/
|
|
386
|
-
declare class CommandRegistry implements Disposable {
|
|
382
|
+
* Manages registration and lookup of command items and groups.
|
|
383
|
+
* Uses set operation helpers (union/intersection/difference) for efficient ID operations.
|
|
384
|
+
* All registration methods return Disposable for automatic cleanup via `using`.
|
|
385
|
+
*/
|
|
386
|
+
export declare class CommandRegistry implements Disposable {
|
|
387
387
|
#private;
|
|
388
388
|
/** Register an item — returns Disposable for `using` auto-deregister */
|
|
389
389
|
registerItem(item: CommandItem): Disposable;
|
|
@@ -450,50 +450,50 @@ interface CommandMachine extends Disposable {
|
|
|
450
450
|
[Symbol.dispose](): void;
|
|
451
451
|
}
|
|
452
452
|
/**
|
|
453
|
-
* Creates a headless command palette state machine with search, frecency,
|
|
454
|
-
* and keyboard shortcut support. Implements Disposable for `using` cleanup.
|
|
455
|
-
*
|
|
456
|
-
* @example
|
|
457
|
-
* ```ts
|
|
458
|
-
* using machine = createCommandMachine({ items, loop: true });
|
|
459
|
-
* machine.subscribe(() => console.log(machine.getState()));
|
|
460
|
-
* ```
|
|
461
|
-
*/
|
|
462
|
-
declare function createCommandMachine(options?: CommandMachineOptions): CommandMachine;
|
|
453
|
+
* Creates a headless command palette state machine with search, frecency,
|
|
454
|
+
* and keyboard shortcut support. Implements Disposable for `using` cleanup.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* using machine = createCommandMachine({ items, loop: true });
|
|
459
|
+
* machine.subscribe(() => console.log(machine.getState()));
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
export declare function createCommandMachine(options?: CommandMachineOptions): CommandMachine;
|
|
463
463
|
//#endregion
|
|
464
464
|
//#region src/core/search/default-scorer.d.ts
|
|
465
465
|
/**
|
|
466
|
-
* Public API: scores a command item against a search query.
|
|
467
|
-
* Multi-strategy: exact → prefix → substring → word-boundary → fuzzy.
|
|
468
|
-
* Returns null if no match. For batch use, prefer the search engine
|
|
469
|
-
* which pre-caches lowercase and normalizes query once.
|
|
470
|
-
*/
|
|
471
|
-
declare function scoreItem(query: string, item: CommandItem): SearchResult | null;
|
|
466
|
+
* Public API: scores a command item against a search query.
|
|
467
|
+
* Multi-strategy: exact → prefix → substring → word-boundary → fuzzy.
|
|
468
|
+
* Returns null if no match. For batch use, prefer the search engine
|
|
469
|
+
* which pre-caches lowercase and normalizes query once.
|
|
470
|
+
*/
|
|
471
|
+
export declare function scoreItem(query: string, item: CommandItem): SearchResult | null;
|
|
472
472
|
//#endregion
|
|
473
473
|
//#region src/core/search/fuzzy-scorer.d.ts
|
|
474
474
|
/**
|
|
475
|
-
* Async-safe fuzzy scorer — wraps scoring in Promise for error resilience.
|
|
476
|
-
* Falls back gracefully on error via synchronous-throw capture.
|
|
477
|
-
*/
|
|
478
|
-
declare function scoreItemAsync(query: string, item: CommandItem): Promise<SearchResult | null>;
|
|
475
|
+
* Async-safe fuzzy scorer — wraps scoring in Promise for error resilience.
|
|
476
|
+
* Falls back gracefully on error via synchronous-throw capture.
|
|
477
|
+
*/
|
|
478
|
+
export declare function scoreItemAsync(query: string, item: CommandItem): Promise<SearchResult | null>;
|
|
479
479
|
/**
|
|
480
|
-
* Batch score items synchronously inside a single Promise.
|
|
481
|
-
* Eliminates per-item microtask overhead from async generators — runs the
|
|
482
|
-
* entire scoring pipeline in one synchronous pass, wrapped for error safety.
|
|
483
|
-
*/
|
|
484
|
-
declare function batchScoreItems(query: string, items: readonly CommandItem[]): Promise<SearchResult[]>;
|
|
480
|
+
* Batch score items synchronously inside a single Promise.
|
|
481
|
+
* Eliminates per-item microtask overhead from async generators — runs the
|
|
482
|
+
* entire scoring pipeline in one synchronous pass, wrapped for error safety.
|
|
483
|
+
*/
|
|
484
|
+
export declare function batchScoreItems(query: string, items: readonly CommandItem[]): Promise<SearchResult[]>;
|
|
485
485
|
//#endregion
|
|
486
486
|
//#region src/core/search/index.d.ts
|
|
487
487
|
interface SearchEngineOptions {
|
|
488
488
|
readonly scorer?: ScorerFn | undefined;
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
491
|
-
* Creates a search engine with pluggable scorer and incremental filtering.
|
|
492
|
-
* When the query extends the previous one, only prior matches are re-scored.
|
|
493
|
-
* Pre-caches lowercase at index time — zero toLowerCase() calls during search.
|
|
494
|
-
* Uses Iterator Helpers (ES2026) for result pipelines and Set.difference for pruning.
|
|
495
|
-
*/
|
|
496
|
-
declare function createSearchEngine(options?: SearchEngineOptions): SearchEngine;
|
|
491
|
+
* Creates a search engine with pluggable scorer and incremental filtering.
|
|
492
|
+
* When the query extends the previous one, only prior matches are re-scored.
|
|
493
|
+
* Pre-caches lowercase at index time — zero toLowerCase() calls during search.
|
|
494
|
+
* Uses Iterator Helpers (ES2026) for result pipelines and Set.difference for pruning.
|
|
495
|
+
*/
|
|
496
|
+
export declare function createSearchEngine(options?: SearchEngineOptions): SearchEngine;
|
|
497
497
|
//#endregion
|
|
498
498
|
//#region src/core/telemetry.d.ts
|
|
499
499
|
interface CommandTelemetryHooks {
|
|
@@ -513,29 +513,29 @@ interface TelemetryMiddleware {
|
|
|
513
513
|
readonly onSelect: (itemId: ItemId, query: string, position: number) => void;
|
|
514
514
|
}
|
|
515
515
|
/**
|
|
516
|
-
* Creates a telemetry middleware that measures command palette interactions.
|
|
517
|
-
* Uses Date.now() for millisecond-precision timestamps
|
|
518
|
-
* and subtraction for duration computation.
|
|
519
|
-
*
|
|
520
|
-
* @example
|
|
521
|
-
* ```ts
|
|
522
|
-
* const telemetry = createTelemetryMiddleware({
|
|
523
|
-
* onPaletteOpen: () => analytics.track('palette_opened'),
|
|
524
|
-
* onItemSelected: (id, query, pos) => analytics.track('item_selected', { id, query, position: pos }),
|
|
525
|
-
* });
|
|
526
|
-
* ```
|
|
527
|
-
*/
|
|
528
|
-
declare function createTelemetryMiddleware(hooks: CommandTelemetryHooks): TelemetryMiddleware;
|
|
516
|
+
* Creates a telemetry middleware that measures command palette interactions.
|
|
517
|
+
* Uses Date.now() for millisecond-precision timestamps
|
|
518
|
+
* and subtraction for duration computation.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* const telemetry = createTelemetryMiddleware({
|
|
523
|
+
* onPaletteOpen: () => analytics.track('palette_opened'),
|
|
524
|
+
* onItemSelected: (id, query, pos) => analytics.track('item_selected', { id, query, position: pos }),
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
export declare function createTelemetryMiddleware(hooks: CommandTelemetryHooks): TelemetryMiddleware;
|
|
529
529
|
//#endregion
|
|
530
530
|
//#region src/core/utils/event-emitter.d.ts
|
|
531
531
|
type EventMap = {
|
|
532
532
|
[key: string]: unknown;
|
|
533
533
|
};
|
|
534
534
|
/**
|
|
535
|
-
* Type-safe event emitter with strong references and Disposable subscriptions.
|
|
536
|
-
* Returns Disposable from `on()` for automatic unsubscription via `using`.
|
|
537
|
-
*/
|
|
538
|
-
declare class TypedEmitter<T extends EventMap> implements Disposable {
|
|
535
|
+
* Type-safe event emitter with strong references and Disposable subscriptions.
|
|
536
|
+
* Returns Disposable from `on()` for automatic unsubscription via `using`.
|
|
537
|
+
*/
|
|
538
|
+
export declare class TypedEmitter<T extends EventMap> implements Disposable {
|
|
539
539
|
#private;
|
|
540
540
|
/** Subscribe to an event. Returns a Disposable that removes the listener when disposed. */
|
|
541
541
|
on<K extends keyof T>(event: K, listener: (data: T[K]) => void): Disposable;
|
|
@@ -552,18 +552,18 @@ declare class TypedEmitter<T extends EventMap> implements Disposable {
|
|
|
552
552
|
//#endregion
|
|
553
553
|
//#region src/core/utils/scheduler.d.ts
|
|
554
554
|
/**
|
|
555
|
-
* Batched update scheduler that coalesces state updates into a single tick.
|
|
556
|
-
* Uses requestAnimationFrame in browsers, queueMicrotask in Node.js/tests.
|
|
557
|
-
*/
|
|
555
|
+
* Batched update scheduler that coalesces state updates into a single tick.
|
|
556
|
+
* Uses requestAnimationFrame in browsers, queueMicrotask in Node.js/tests.
|
|
557
|
+
*/
|
|
558
558
|
interface Scheduler extends Disposable {
|
|
559
559
|
schedule(update: () => void): void;
|
|
560
560
|
flush(): void;
|
|
561
561
|
[Symbol.dispose](): void;
|
|
562
562
|
}
|
|
563
563
|
/**
|
|
564
|
-
* Creates a batched update scheduler. Coalesces rapid state updates into a single
|
|
565
|
-
* execution pass using rAF (browser) or queueMicrotask (Node.js).
|
|
566
|
-
*/
|
|
567
|
-
declare function createScheduler(): Scheduler;
|
|
564
|
+
* Creates a batched update scheduler. Coalesces rapid state updates into a single
|
|
565
|
+
* execution pass using rAF (browser) or queueMicrotask (Node.js).
|
|
566
|
+
*/
|
|
567
|
+
export declare function createScheduler(): Scheduler;
|
|
568
568
|
//#endregion
|
|
569
|
-
export {
|
|
569
|
+
export type { CommandEvent, CommandGroup, CommandItem, CommandMachine, CommandMachineOptions, CommandState, CommandTelemetryHooks, FrecencyData, FrecencyDecayConfig, FrecencyOptions, FrecencyRecord, FrecencyStorage, GroupId, ItemId, ParsedShortcut, Scheduler, ScorerFn, SearchEngine, SearchResult, TelemetryMiddleware };
|
package/dist/core/index.mjs
CHANGED
|
@@ -366,9 +366,7 @@ function parseShortcut(shortcut) {
|
|
|
366
366
|
case "shift":
|
|
367
367
|
shift = true;
|
|
368
368
|
break;
|
|
369
|
-
case "alt":
|
|
370
|
-
alt = true;
|
|
371
|
-
break;
|
|
369
|
+
case "alt": alt = true;
|
|
372
370
|
}
|
|
373
371
|
else key = part;
|
|
374
372
|
}
|
|
@@ -1131,9 +1129,10 @@ function createCommandMachine(options = {}) {
|
|
|
1131
1129
|
const loop = options.loop ?? true;
|
|
1132
1130
|
const currentIdx = activeId ? filteredIdIndex.get(activeId) ?? -1 : -1;
|
|
1133
1131
|
let newIdx;
|
|
1134
|
-
if (direction === "next")
|
|
1135
|
-
|
|
1136
|
-
|
|
1132
|
+
if (direction === "next") {
|
|
1133
|
+
if (currentIdx === -1 || currentIdx >= filteredIds.length - 1) newIdx = loop ? 0 : filteredIds.length - 1;
|
|
1134
|
+
else newIdx = currentIdx + 1;
|
|
1135
|
+
} else if (currentIdx <= 0) newIdx = loop ? filteredIds.length - 1 : 0;
|
|
1137
1136
|
else newIdx = currentIdx - 1;
|
|
1138
1137
|
const newActiveId = filteredIds[newIdx] ?? null;
|
|
1139
1138
|
if (newActiveId !== activeId) {
|
|
@@ -1249,7 +1248,6 @@ function createCommandMachine(options = {}) {
|
|
|
1249
1248
|
case "UNREGISTER_GROUP":
|
|
1250
1249
|
registry.unregisterGroup(event.id);
|
|
1251
1250
|
refilter(state.search);
|
|
1252
|
-
break;
|
|
1253
1251
|
}
|
|
1254
1252
|
}
|
|
1255
1253
|
return {
|