use-command-palette 0.1.1

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.
@@ -0,0 +1,132 @@
1
+ import { InputHTMLAttributes, RefCallback } from 'react';
2
+
3
+ interface CommandItem {
4
+ id: string;
5
+ label: string;
6
+ keywords?: string[];
7
+ group?: string;
8
+ disabled?: boolean;
9
+ children?: CommandItem[];
10
+ [key: string]: unknown;
11
+ }
12
+ interface GroupedItems {
13
+ group: string | undefined;
14
+ items: CommandItem[];
15
+ }
16
+ interface UseCommandPaletteOptions {
17
+ items: CommandItem[];
18
+ onSelect: (item: CommandItem) => void;
19
+ filterFn?: (items: CommandItem[], query: string) => CommandItem[] | Promise<CommandItem[]>;
20
+ defaultOpen?: boolean;
21
+ /** Pass a value to enable controlled mode; omit for uncontrolled */
22
+ isOpen?: boolean;
23
+ onOpenChange?: (open: boolean) => void;
24
+ hotkey?: string | string[];
25
+ closeOnSelect?: boolean;
26
+ animationDuration?: number;
27
+ recent?: {
28
+ enabled: boolean;
29
+ max?: number;
30
+ storageKey?: string;
31
+ };
32
+ }
33
+ interface ContainerProps {
34
+ role: 'dialog';
35
+ 'aria-modal': true;
36
+ 'aria-label': string;
37
+ }
38
+ interface ListProps {
39
+ role: 'listbox';
40
+ id: string;
41
+ }
42
+ interface ItemProps {
43
+ role: 'option';
44
+ 'aria-selected': boolean;
45
+ 'aria-disabled': boolean;
46
+ onClick: () => void;
47
+ onMouseEnter: () => void;
48
+ id: string;
49
+ }
50
+ type InputPropsOverrides = Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'onKeyDown' | 'role' | 'autoComplete' | 'aria-expanded' | 'aria-controls' | 'aria-activedescendant'>;
51
+ interface InputProps extends InputPropsOverrides {
52
+ ref: RefCallback<HTMLInputElement>;
53
+ value: string;
54
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
55
+ onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
56
+ role: 'combobox';
57
+ 'aria-expanded': boolean;
58
+ 'aria-controls': string;
59
+ 'aria-activedescendant': string | undefined;
60
+ autoComplete: 'off';
61
+ }
62
+ type AnimationState = 'entering' | 'entered' | 'exiting' | 'exited';
63
+ interface AnnouncerProps {
64
+ 'aria-live': 'polite';
65
+ 'aria-atomic': true;
66
+ style: React.CSSProperties;
67
+ }
68
+ interface UseCommandPaletteReturn {
69
+ isOpen: boolean;
70
+ query: string;
71
+ highlightedIndex: number;
72
+ filteredItems: CommandItem[];
73
+ groupedItems: GroupedItems[];
74
+ isLoading: boolean;
75
+ isMounted: boolean;
76
+ animationState: AnimationState;
77
+ recentItems: CommandItem[];
78
+ currentPage: CommandItem | null;
79
+ breadcrumb: CommandItem[];
80
+ canGoBack: boolean;
81
+ announcement: string;
82
+ open: () => void;
83
+ close: () => void;
84
+ toggle: () => void;
85
+ setQuery: (query: string) => void;
86
+ selectItem: (item: CommandItem) => void;
87
+ highlightIndex: (index: number) => void;
88
+ goToPage: (item: CommandItem) => void;
89
+ goBack: () => void;
90
+ getContainerProps: () => ContainerProps;
91
+ getListProps: () => ListProps;
92
+ getItemProps: (args: {
93
+ index: number;
94
+ item: CommandItem;
95
+ }) => ItemProps;
96
+ getInputProps: (overrides?: InputPropsOverrides) => InputProps;
97
+ getAnnouncerProps: () => AnnouncerProps;
98
+ }
99
+
100
+ declare function useCommandPalette({ items, onSelect, filterFn, defaultOpen, isOpen: controlledIsOpen, onOpenChange, hotkey, closeOnSelect, animationDuration, recent, }: UseCommandPaletteOptions): UseCommandPaletteReturn;
101
+
102
+ declare function useRegisterCommands(commands: CommandItem[], deps: unknown[]): void;
103
+
104
+ declare function useRegisteredCommands(): {
105
+ commands: CommandItem[];
106
+ };
107
+
108
+ type Listener = () => void;
109
+ declare class CommandRegistry {
110
+ private store;
111
+ private listeners;
112
+ register(key: string, commands: CommandItem[]): void;
113
+ unregister(key: string): void;
114
+ getAll(): CommandItem[];
115
+ subscribe(listener: Listener): () => void;
116
+ private notify;
117
+ }
118
+ declare const registry: CommandRegistry;
119
+
120
+ /**
121
+ * Scores how well `query` matches `text` using fuzzy matching.
122
+ *
123
+ * Scoring tiers:
124
+ * - Exact substring at a word boundary → highest (150)
125
+ * - Exact substring elsewhere → high (100 - small position penalty)
126
+ * - Fuzzy (chars in order, not adjacent) → lower (accumulates per-char points)
127
+ *
128
+ * Returns `null` when there is no match at all.
129
+ */
130
+ declare function fuzzyScore(text: string, query: string): number | null;
131
+
132
+ export { type AnimationState, type AnnouncerProps, type CommandItem, type ContainerProps, type GroupedItems, type InputProps, type InputPropsOverrides, type ItemProps, type ListProps, type UseCommandPaletteOptions, type UseCommandPaletteReturn, fuzzyScore, registry, useCommandPalette, useRegisterCommands, useRegisteredCommands };