@choice-ui/command 0.0.3 → 0.0.5
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 +67 -6
- package/dist/index.js +293 -269
- package/package.json +13 -15
- package/dist/index.cjs +0 -1309
- package/dist/index.d.cts +0 -130
- package/src/command-score.ts +0 -171
- package/src/command.tsx +0 -482
- package/src/components/command-divider.tsx +0 -30
- package/src/components/command-empty.tsx +0 -30
- package/src/components/command-footer.tsx +0 -22
- package/src/components/command-group.tsx +0 -76
- package/src/components/command-input.tsx +0 -66
- package/src/components/command-item.tsx +0 -165
- package/src/components/command-list.tsx +0 -77
- package/src/components/command-loading.tsx +0 -30
- package/src/components/command-tabs.tsx +0 -20
- package/src/components/command-value.tsx +0 -23
- package/src/components/index.ts +0 -10
- package/src/context/command-context.ts +0 -5
- package/src/context/create-command-context.ts +0 -140
- package/src/context/index.ts +0 -2
- package/src/hooks/index.ts +0 -10
- package/src/hooks/use-as-ref.ts +0 -12
- package/src/hooks/use-command-state.ts +0 -18
- package/src/hooks/use-command.ts +0 -10
- package/src/hooks/use-schedule-layout-effect.ts +0 -19
- package/src/hooks/use-value.ts +0 -39
- package/src/index.ts +0 -31
- package/src/store/index.ts +0 -1
- package/src/tv.ts +0 -248
- package/src/types.ts +0 -84
- package/src/utils/constants.ts +0 -7
- package/src/utils/dom.ts +0 -19
- package/src/utils/helpers.ts +0 -45
- package/src/utils/index.ts +0 -3
package/src/tv.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { tcv } from "@choice-ui/shared"
|
|
2
|
-
|
|
3
|
-
export const commandTv = tcv({
|
|
4
|
-
slots: {
|
|
5
|
-
root: "flex h-full w-full flex-col overflow-hidden",
|
|
6
|
-
divider: "my-2 h-px",
|
|
7
|
-
},
|
|
8
|
-
variants: {
|
|
9
|
-
variant: {
|
|
10
|
-
default: {
|
|
11
|
-
root: "bg-default-background text-default-foreground",
|
|
12
|
-
divider: "bg-default-boundary",
|
|
13
|
-
},
|
|
14
|
-
dark: {
|
|
15
|
-
root: "bg-menu-background text-white",
|
|
16
|
-
divider: "bg-menu-boundary",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
export const commandInputTv = tcv({
|
|
23
|
-
slots: {
|
|
24
|
-
root: "m-2 flex items-center",
|
|
25
|
-
input: "w-full rounded-lg",
|
|
26
|
-
},
|
|
27
|
-
variants: {
|
|
28
|
-
size: {
|
|
29
|
-
default: {
|
|
30
|
-
input: "text-body-medium h-8 px-2",
|
|
31
|
-
},
|
|
32
|
-
large: {
|
|
33
|
-
input: "leading-lg tracking-lg h-10 px-4 text-body-large",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
defaultVariants: {
|
|
38
|
-
size: "default",
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
export const commandListTv = tcv({
|
|
43
|
-
slots: {
|
|
44
|
-
root: "px-2 pb-2",
|
|
45
|
-
content: "flex flex-col",
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
export const commandGroupTv = tcv({
|
|
50
|
-
slots: {
|
|
51
|
-
root: "flex flex-col gap-1 not-first:mt-4",
|
|
52
|
-
heading: "text-body-medium px-2",
|
|
53
|
-
},
|
|
54
|
-
variants: {
|
|
55
|
-
variant: {
|
|
56
|
-
default: {
|
|
57
|
-
heading: "text-secondary-foreground",
|
|
58
|
-
},
|
|
59
|
-
dark: {
|
|
60
|
-
heading: "text-white/50",
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
export const commandItemTv = tcv({
|
|
67
|
-
slots: {
|
|
68
|
-
root: ["group/item relative flex items-center rounded-lg select-none", "focus:outline-none"],
|
|
69
|
-
icon: "flex flex-shrink-0 items-center justify-center rounded-md",
|
|
70
|
-
value: "flex-1 truncate",
|
|
71
|
-
shortcut: "text-secondary-foreground",
|
|
72
|
-
},
|
|
73
|
-
variants: {
|
|
74
|
-
variant: {
|
|
75
|
-
default: {},
|
|
76
|
-
dark: {
|
|
77
|
-
root: "text-white",
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
size: {
|
|
81
|
-
default: {
|
|
82
|
-
root: "text-body-medium min-h-8 p-1",
|
|
83
|
-
icon: "h-6 min-w-6",
|
|
84
|
-
},
|
|
85
|
-
large: {
|
|
86
|
-
root: "leading-lg tracking-lg min-h-10 p-2 text-body-large",
|
|
87
|
-
icon: "h-6 min-w-6",
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
hasPrefix: {
|
|
91
|
-
true: "",
|
|
92
|
-
false: "",
|
|
93
|
-
},
|
|
94
|
-
hasSuffix: {
|
|
95
|
-
true: "",
|
|
96
|
-
false: "",
|
|
97
|
-
},
|
|
98
|
-
selected: {
|
|
99
|
-
true: {},
|
|
100
|
-
false: {},
|
|
101
|
-
},
|
|
102
|
-
disabled: {
|
|
103
|
-
true: {
|
|
104
|
-
root: "pointer-events-none",
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
compoundVariants: [
|
|
109
|
-
{
|
|
110
|
-
hasPrefix: true,
|
|
111
|
-
size: "default",
|
|
112
|
-
class: {
|
|
113
|
-
root: "gap-1 pl-1",
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
hasPrefix: false,
|
|
118
|
-
size: "default",
|
|
119
|
-
class: {
|
|
120
|
-
root: "pl-2",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
hasSuffix: true,
|
|
125
|
-
size: "default",
|
|
126
|
-
class: {
|
|
127
|
-
root: "gap-1 pr-1",
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
hasSuffix: false,
|
|
132
|
-
size: "default",
|
|
133
|
-
class: {
|
|
134
|
-
root: "pr-2",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
// large
|
|
138
|
-
{
|
|
139
|
-
hasPrefix: true,
|
|
140
|
-
size: "large",
|
|
141
|
-
class: {
|
|
142
|
-
root: "gap-2 pl-2",
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
hasPrefix: false,
|
|
147
|
-
size: "large",
|
|
148
|
-
class: {
|
|
149
|
-
root: "pl-4",
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
hasSuffix: true,
|
|
154
|
-
size: "large",
|
|
155
|
-
class: {
|
|
156
|
-
root: "gap-2 pr-2",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
hasSuffix: false,
|
|
161
|
-
size: "large",
|
|
162
|
-
class: {
|
|
163
|
-
root: "pr-4",
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
variant: "default",
|
|
168
|
-
selected: true,
|
|
169
|
-
class: {
|
|
170
|
-
root: "bg-secondary-background",
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
variant: "dark",
|
|
175
|
-
selected: true,
|
|
176
|
-
class: {
|
|
177
|
-
root: "bg-gray-700",
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
variant: "default",
|
|
182
|
-
disabled: true,
|
|
183
|
-
class: {
|
|
184
|
-
root: "text-secondary-foreground",
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
variant: "dark",
|
|
189
|
-
disabled: true,
|
|
190
|
-
class: {
|
|
191
|
-
root: "text-white/50",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
defaultVariants: {
|
|
196
|
-
size: "default",
|
|
197
|
-
hasPrefix: false,
|
|
198
|
-
hasSuffix: false,
|
|
199
|
-
variant: "default",
|
|
200
|
-
},
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
export const commandFooterTv = tcv({
|
|
204
|
-
slots: {
|
|
205
|
-
root: "flex h-10 items-center justify-between border-t px-2",
|
|
206
|
-
},
|
|
207
|
-
variants: {
|
|
208
|
-
variant: {
|
|
209
|
-
default: {
|
|
210
|
-
root: "border-default-boundary",
|
|
211
|
-
},
|
|
212
|
-
dark: {
|
|
213
|
-
root: "border-menu-boundary",
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
},
|
|
217
|
-
defaultVariants: {
|
|
218
|
-
variant: "default",
|
|
219
|
-
},
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
export const commandTabsTv = tcv({
|
|
223
|
-
slots: {
|
|
224
|
-
tabs: "mx-2 mb-2",
|
|
225
|
-
},
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
export const commandEmptyTv = tcv({
|
|
229
|
-
slots: {
|
|
230
|
-
root: "py-6 text-center",
|
|
231
|
-
},
|
|
232
|
-
variants: {
|
|
233
|
-
variant: {
|
|
234
|
-
default: {
|
|
235
|
-
root: "text-secondary-foreground",
|
|
236
|
-
},
|
|
237
|
-
dark: {
|
|
238
|
-
root: "text-white/50",
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
export const commandLoadingTv = tcv({
|
|
245
|
-
slots: {
|
|
246
|
-
root: "flex items-center justify-center py-6 text-center",
|
|
247
|
-
},
|
|
248
|
-
})
|
package/src/types.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
|
|
3
|
-
export type CommandFilter = (value: string, search: string, keywords?: string[]) => number
|
|
4
|
-
|
|
5
|
-
export interface CommandProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
6
|
-
/**
|
|
7
|
-
* Optional default item value when it is initially rendered.
|
|
8
|
-
*/
|
|
9
|
-
defaultValue?: string
|
|
10
|
-
/**
|
|
11
|
-
* Optionally set to `true` to disable selection via pointer events.
|
|
12
|
-
*/
|
|
13
|
-
disablePointerSelection?: boolean
|
|
14
|
-
/**
|
|
15
|
-
* Custom filter function for whether each command menu item should matches the given search query.
|
|
16
|
-
* It should return a number between 0 and 1, with 1 being the best match and 0 being hidden entirely.
|
|
17
|
-
* By default, uses the `command-score` library.
|
|
18
|
-
*/
|
|
19
|
-
filter?: CommandFilter
|
|
20
|
-
/**
|
|
21
|
-
* Accessible label for this command menu. Not shown visibly.
|
|
22
|
-
*/
|
|
23
|
-
label?: string
|
|
24
|
-
/**
|
|
25
|
-
* Optionally set to `true` to turn on looping around when using the arrow keys.
|
|
26
|
-
*/
|
|
27
|
-
loop?: boolean
|
|
28
|
-
/**
|
|
29
|
-
* Event handler called when the selected item of the menu changes.
|
|
30
|
-
*/
|
|
31
|
-
onChange?: (value: string) => void
|
|
32
|
-
/**
|
|
33
|
-
* Optionally set to `false` to turn off the automatic filtering and sorting.
|
|
34
|
-
* If `false`, you must conditionally render valid items based on the search query yourself.
|
|
35
|
-
*/
|
|
36
|
-
shouldFilter?: boolean
|
|
37
|
-
size?: "default" | "large"
|
|
38
|
-
/**
|
|
39
|
-
* Optional controlled state of the selected command menu item.
|
|
40
|
-
*/
|
|
41
|
-
value?: string
|
|
42
|
-
variant?: "default" | "dark"
|
|
43
|
-
/**
|
|
44
|
-
* Set to `false` to disable ctrl+n/j/p/k shortcuts. Defaults to `true`.
|
|
45
|
-
*/
|
|
46
|
-
vimBindings?: boolean
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type Context = {
|
|
50
|
-
filter: () => boolean
|
|
51
|
-
getDisablePointerSelection: () => boolean
|
|
52
|
-
group: (id: string) => () => void
|
|
53
|
-
inputId: string
|
|
54
|
-
item: (id: string, groupId?: string) => () => void
|
|
55
|
-
label?: string
|
|
56
|
-
labelId: string
|
|
57
|
-
// Ids
|
|
58
|
-
listId: string
|
|
59
|
-
// Refs
|
|
60
|
-
listInnerRef: React.MutableRefObject<HTMLDivElement | null>
|
|
61
|
-
size?: "default" | "large"
|
|
62
|
-
store: Store
|
|
63
|
-
value: (id: string, value?: string, keywords?: string[]) => void
|
|
64
|
-
variant?: "default" | "dark"
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type State = {
|
|
68
|
-
filtered: { count: number; groups: Set<string>; items: Map<string, number> }
|
|
69
|
-
search: string
|
|
70
|
-
selectedItemId?: string
|
|
71
|
-
value: string
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type Store = {
|
|
75
|
-
emit: () => void
|
|
76
|
-
setState: <K extends keyof State>(key: K, value: State[K], opts?: unknown) => void
|
|
77
|
-
snapshot: () => State
|
|
78
|
-
subscribe: (callback: () => void) => () => void
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type Group = {
|
|
82
|
-
forceMount?: boolean
|
|
83
|
-
id: string
|
|
84
|
-
}
|
package/src/utils/constants.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const GROUP_SELECTOR = `[role="presentation"]`
|
|
2
|
-
export const GROUP_ITEMS_SELECTOR = `[role="group"]`
|
|
3
|
-
export const GROUP_HEADING_SELECTOR = `[aria-hidden="true"]`
|
|
4
|
-
export const ITEM_SELECTOR = `[role="option"]`
|
|
5
|
-
export const VALID_ITEM_SELECTOR = `${ITEM_SELECTOR}:not([aria-disabled="true"])`
|
|
6
|
-
export const SELECT_EVENT = `cmdk-item-select`
|
|
7
|
-
export const VALUE_ATTR = `data-value`
|
package/src/utils/dom.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function findNextSibling(el: Element, selector: string): Element | null {
|
|
2
|
-
let sibling = el.nextElementSibling
|
|
3
|
-
|
|
4
|
-
while (sibling) {
|
|
5
|
-
if (sibling.matches(selector)) return sibling
|
|
6
|
-
sibling = sibling.nextElementSibling
|
|
7
|
-
}
|
|
8
|
-
return null
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function findPreviousSibling(el: Element, selector: string): Element | null {
|
|
12
|
-
let sibling = el.previousElementSibling
|
|
13
|
-
|
|
14
|
-
while (sibling) {
|
|
15
|
-
if (sibling.matches(selector)) return sibling
|
|
16
|
-
sibling = sibling.previousElementSibling
|
|
17
|
-
}
|
|
18
|
-
return null
|
|
19
|
-
}
|
package/src/utils/helpers.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React from "react"
|
|
2
|
-
|
|
3
|
-
export const useLayoutEffect =
|
|
4
|
-
typeof window === "undefined" ? React.useEffect : React.useLayoutEffect
|
|
5
|
-
|
|
6
|
-
export function renderChildren(children: React.ReactElement): React.ReactNode {
|
|
7
|
-
const childrenType = children.type
|
|
8
|
-
|
|
9
|
-
// The children is a function component or class component
|
|
10
|
-
if (typeof childrenType === "function") {
|
|
11
|
-
// Try to call as function component first
|
|
12
|
-
try {
|
|
13
|
-
return (childrenType as React.FunctionComponent)(children.props)
|
|
14
|
-
} catch {
|
|
15
|
-
// If it fails, it might be a class component, return the original element
|
|
16
|
-
return children
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// The children is a component with `forwardRef`
|
|
21
|
-
if (typeof childrenType === "object" && childrenType !== null && "render" in childrenType) {
|
|
22
|
-
const forwardRefComponent = childrenType as {
|
|
23
|
-
render: (props: unknown, ref: unknown) => React.ReactNode
|
|
24
|
-
}
|
|
25
|
-
return forwardRefComponent.render(children.props, null)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// It's a string, boolean, etc.
|
|
29
|
-
return children
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function SlottableWithNestedChildren(
|
|
33
|
-
{ asChild, children }: { asChild?: boolean; children?: React.ReactNode },
|
|
34
|
-
render: (child: React.ReactNode) => JSX.Element,
|
|
35
|
-
) {
|
|
36
|
-
if (asChild && React.isValidElement(children)) {
|
|
37
|
-
const renderedChild = renderChildren(children)
|
|
38
|
-
if (React.isValidElement(renderedChild)) {
|
|
39
|
-
const childProps = children.props
|
|
40
|
-
// Use a safer approach that avoids ref type issues
|
|
41
|
-
return React.cloneElement(renderedChild, {}, render(childProps.children))
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return render(children)
|
|
45
|
-
}
|
package/src/utils/index.ts
DELETED