@choice-ui/command 0.0.3 → 0.0.4

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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _choice_ui_tabs from '@choice-ui/tabs';
2
2
  import * as react from 'react';
3
3
  import react__default, { HTMLProps, ReactNode } from 'react';
4
- import { InputProps } from '@choice-ui/input';
4
+ import { TextFieldProps } from '@choice-ui/text-field';
5
5
  import { KbdKey } from '@choice-ui/kbd';
6
6
  import { ScrollAreaProps } from '@choice-ui/scroll-area';
7
7
 
@@ -10,12 +10,27 @@ interface CommandEmptyProps extends HTMLProps<HTMLDivElement> {
10
10
  }
11
11
 
12
12
  interface CommandGroupProps extends HTMLProps<HTMLDivElement> {
13
+ /**
14
+ * Whether to force mount the group.
15
+ * @default false
16
+ */
13
17
  forceMount?: boolean;
18
+ /**
19
+ * The heading of the group.
20
+ */
14
21
  heading?: react__default.ReactNode;
22
+ /**
23
+ * The value of the group.
24
+ */
15
25
  value?: string;
26
+ /**
27
+ * Whether the group is hidden.
28
+ * @default false
29
+ */
30
+ hidden?: boolean;
16
31
  }
17
32
 
18
- interface CommandInputProps extends Omit<InputProps, "value" | "onChange" | "type"> {
33
+ interface CommandInputProps extends Omit<TextFieldProps, "value" | "onChange" | "type"> {
19
34
  onChange?: (search: string) => void;
20
35
  prefixElement?: ReactNode;
21
36
  suffixElement?: ReactNode;
@@ -43,12 +58,23 @@ interface CommandListProps extends ScrollAreaProps {
43
58
  }
44
59
 
45
60
  interface CommandLoadingProps extends react__default.HTMLAttributes<HTMLDivElement> {
61
+ /**
62
+ * The label of the loading.
63
+ * @default "Loading..."
64
+ */
46
65
  label?: string;
66
+ /**
67
+ * The progress of the loading.
68
+ * @default undefined
69
+ */
47
70
  progress?: number;
48
71
  }
49
72
 
50
73
  interface CommandDividerProps extends HTMLProps<HTMLDivElement> {
51
- /** 是否始终渲染此分隔符。当禁用自动过滤功能时特别有用。 */
74
+ /**
75
+ * Whether to always render this divider. Useful when automatic filtering is disabled.
76
+ * @default false
77
+ */
52
78
  alwaysRender?: boolean;
53
79
  }
54
80
 
@@ -85,17 +111,40 @@ interface CommandProps extends Omit<react__default.HTMLAttributes<HTMLDivElement
85
111
  * If `false`, you must conditionally render valid items based on the search query yourself.
86
112
  */
87
113
  shouldFilter?: boolean;
114
+ /**
115
+ * The size of the command menu.
116
+ * @default "default"
117
+ */
88
118
  size?: "default" | "large";
89
119
  /**
90
120
  * Optional controlled state of the selected command menu item.
91
121
  */
92
122
  value?: string;
123
+ /**
124
+ * The variant of the command menu.
125
+ * @default "default"
126
+ */
93
127
  variant?: "default" | "dark";
94
128
  /**
95
129
  * Set to `false` to disable ctrl+n/j/p/k shortcuts. Defaults to `true`.
96
130
  */
97
131
  vimBindings?: boolean;
98
132
  }
133
+ type Context = {
134
+ filter: () => boolean;
135
+ getDisablePointerSelection: () => boolean;
136
+ group: (id: string) => () => void;
137
+ inputId: string;
138
+ item: (id: string, groupId?: string) => () => void;
139
+ label?: string;
140
+ labelId: string;
141
+ listId: string;
142
+ listInnerRef: react__default.MutableRefObject<HTMLDivElement | null>;
143
+ size?: "default" | "large";
144
+ store: Store;
145
+ value: (id: string, value?: string, keywords?: string[]) => void;
146
+ variant?: "default" | "dark";
147
+ };
99
148
  type State = {
100
149
  filtered: {
101
150
  count: number;
@@ -106,19 +155,31 @@ type State = {
106
155
  selectedItemId?: string;
107
156
  value: string;
108
157
  };
158
+ type Store = {
159
+ emit: () => void;
160
+ setState: <K extends keyof State>(key: K, value: State[K], opts?: unknown) => void;
161
+ snapshot: () => State;
162
+ subscribe: (callback: () => void) => () => void;
163
+ };
109
164
 
110
165
  declare const defaultFilter: CommandFilter;
111
166
  declare const Command$1: react__default.ForwardRefExoticComponent<CommandProps & react__default.RefAttributes<HTMLDivElement>>;
112
167
 
168
+ declare const useCommand: () => Context;
169
+
113
170
  /** Run a selector against the store state. */
114
171
  declare function useCommandState<T>(selector: (state: State) => T): T;
115
172
 
173
+ declare function useValue(id: string, ref: react__default.RefObject<HTMLElement>, deps: (string | react__default.ReactNode | react__default.RefObject<HTMLElement>)[], aliases?: string[]): react__default.MutableRefObject<string | undefined>;
174
+
175
+ declare function commandScore(string: string, abbreviation: string, aliases?: string[]): number;
176
+
116
177
  declare const Command: react.ForwardRefExoticComponent<CommandProps & react.RefAttributes<HTMLDivElement>> & {
117
178
  Empty: react.ForwardRefExoticComponent<Omit<CommandEmptyProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
118
179
  Footer: react.ForwardRefExoticComponent<Omit<react.HTMLProps<HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
119
- Group: react.ForwardRefExoticComponent<Omit<CommandGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
180
+ Group: react.MemoExoticComponent<react.ForwardRefExoticComponent<Omit<CommandGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>>;
120
181
  Input: react.ForwardRefExoticComponent<Omit<CommandInputProps, "ref"> & react.RefAttributes<HTMLInputElement>>;
121
- Item: react.ForwardRefExoticComponent<Omit<CommandItemProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
182
+ Item: react.MemoExoticComponent<react.ForwardRefExoticComponent<Omit<CommandItemProps, "ref"> & react.RefAttributes<HTMLDivElement>>>;
122
183
  List: react.ForwardRefExoticComponent<CommandListProps & react.RefAttributes<HTMLDivElement>>;
123
184
  Loading: react.ForwardRefExoticComponent<CommandLoadingProps & react.RefAttributes<HTMLDivElement>>;
124
185
  Divider: react.ForwardRefExoticComponent<Omit<CommandDividerProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
@@ -127,4 +188,4 @@ declare const Command: react.ForwardRefExoticComponent<CommandProps & react.RefA
127
188
  TabItem: react.MemoExoticComponent<react.ForwardRefExoticComponent<Omit<_choice_ui_tabs.TabItemProps, "ref"> & react.RefAttributes<HTMLElement>>>;
128
189
  };
129
190
 
130
- export { Command, Command$1 as CommandRoot, defaultFilter, useCommandState };
191
+ export { Command, type CommandDividerProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandLoadingProps, type CommandProps, Command$1 as CommandRoot, commandScore, defaultFilter, useCommand, useCommandState, useValue };