@vertz/ui-primitives 0.2.41 → 0.2.42
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/shared/chunk-06m8prfg.js +52 -0
- package/dist/shared/chunk-0n9jj8xr.js +24 -0
- package/dist/shared/chunk-1ben27xq.js +317 -0
- package/dist/shared/chunk-1j2mj0sa.js +45 -0
- package/dist/shared/chunk-250hj18f.js +243 -0
- package/dist/shared/chunk-2h4m9c71.js +38 -0
- package/dist/shared/chunk-2sbx20hv.js +128 -0
- package/dist/shared/chunk-2ye674gr.js +70 -0
- package/dist/shared/chunk-34d8385y.js +15 -0
- package/dist/shared/chunk-4d7bm8h0.js +113 -0
- package/dist/shared/chunk-4zjgxr7x.js +157 -0
- package/dist/shared/chunk-5c150wvr.js +140 -0
- package/dist/shared/chunk-5gycdypd.js +58 -0
- package/dist/shared/chunk-6mm7fhp8.js +105 -0
- package/dist/shared/chunk-6zmnqvh6.js +109 -0
- package/dist/shared/{chunk-yy3ft5mb.js → chunk-7amn5d71.js} +2 -2
- package/dist/shared/chunk-7pbff2hg.js +118 -0
- package/dist/shared/chunk-7zpjshwz.js +194 -0
- package/dist/shared/chunk-993ff51d.js +155 -0
- package/dist/shared/chunk-9pdt5aw7.js +24 -0
- package/dist/shared/chunk-a71m4xkv.js +106 -0
- package/dist/shared/chunk-aj8m39pk.js +127 -0
- package/dist/shared/chunk-ajawpc05.js +305 -0
- package/dist/shared/chunk-b7mzwqhj.js +125 -0
- package/dist/shared/chunk-bb887de4.js +200 -0
- package/dist/shared/chunk-bfsmbrxc.js +111 -0
- package/dist/shared/chunk-c2f63m5n.js +56 -0
- package/dist/shared/chunk-c5r3s5km.js +263 -0
- package/dist/shared/chunk-caba5bhd.js +427 -0
- package/dist/shared/chunk-crym07yc.js +264 -0
- package/dist/shared/{chunk-5964gmv0.js → chunk-csjtyvam.js} +62 -88
- package/dist/shared/chunk-d6rtejz3.js +128 -0
- package/dist/shared/chunk-dvaf0bmq.js +140 -0
- package/dist/shared/chunk-dwkv9ya6.js +22 -0
- package/dist/shared/chunk-e0ckxrjg.js +41 -0
- package/dist/shared/chunk-ennxcymj.js +225 -0
- package/dist/shared/{chunk-1jd1n0dt.js → chunk-ey38de46.js} +19 -47
- package/dist/shared/chunk-f0v1gs5e.js +52 -0
- package/dist/shared/chunk-f86rsf84.js +231 -0
- package/dist/shared/{chunk-3sahbk4d.js → chunk-fdse46x5.js} +6 -1
- package/dist/shared/chunk-gj4hrssn.js +135 -0
- package/dist/shared/chunk-gyvq4gk9.js +24 -0
- package/dist/shared/chunk-hbnps9sq.js +229 -0
- package/dist/shared/{chunk-fhss32ya.js → chunk-hdmpyeq9.js} +43 -132
- package/dist/shared/chunk-hgnkd4he.js +256 -0
- package/dist/shared/chunk-hpcyffm7.js +185 -0
- package/dist/shared/chunk-hpmvwx0h.js +99 -0
- package/dist/shared/chunk-hz0e504p.js +69 -0
- package/dist/shared/chunk-hzk4wfq9.js +43 -0
- package/dist/shared/chunk-j7znzkpa.js +48 -0
- package/dist/shared/chunk-j9kxgrnn.js +167 -0
- package/dist/shared/chunk-jetwnv0w.js +130 -0
- package/dist/shared/chunk-jjdg26c1.js +155 -0
- package/dist/shared/chunk-k0m4yh86.js +123 -0
- package/dist/shared/chunk-k43q9cjr.js +82 -0
- package/dist/shared/chunk-k9k8tbr5.js +119 -0
- package/dist/shared/chunk-meaj7br1.js +232 -0
- package/dist/shared/chunk-mgj0n08k.js +34 -0
- package/dist/shared/chunk-mjz4rp6c.js +46 -0
- package/dist/shared/chunk-n4rr5gme.js +239 -0
- package/dist/shared/chunk-nk55etpp.js +65 -0
- package/dist/shared/chunk-nkh1ks3k.js +264 -0
- package/dist/shared/chunk-pgvpvbpe.js +26 -0
- package/dist/shared/chunk-pma8gnv7.js +178 -0
- package/dist/shared/chunk-q7xv6xze.js +131 -0
- package/dist/shared/chunk-qey801nq.js +22 -0
- package/dist/shared/chunk-s6b4c3tj.js +58 -0
- package/dist/shared/chunk-sq27a4h0.js +36 -0
- package/dist/shared/chunk-taa5pj15.js +103 -0
- package/dist/shared/chunk-tc5rpvyx.js +127 -0
- package/dist/shared/chunk-tescm0b3.js +192 -0
- package/dist/shared/chunk-tkftdwnq.js +71 -0
- package/dist/shared/chunk-tqhnjcfp.js +116 -0
- package/dist/shared/chunk-vfknb5ht.js +183 -0
- package/dist/shared/chunk-vsc369w3.js +185 -0
- package/dist/shared/chunk-whq9s8v5.js +301 -0
- package/dist/shared/{chunk-hze1f32t.js → chunk-wrqddgaj.js} +1 -1
- package/dist/shared/chunk-yzbmkx4r.js +155 -0
- package/dist/shared/chunk-zaen0ajc.js +347 -0
- package/dist/src/accordion/accordion-composed.js +1 -1
- package/dist/src/accordion/accordion.js +1 -1
- package/dist/src/alert/alert-composed.js +1 -1
- package/dist/src/alert-dialog/alert-dialog-composed.js +1 -1
- package/dist/src/alert-dialog/alert-dialog.js +1 -1
- package/dist/src/avatar/avatar-composed.js +1 -1
- package/dist/src/badge/badge-composed.js +1 -1
- package/dist/src/badge/badge.js +1 -1
- package/dist/src/breadcrumb/breadcrumb-composed.js +1 -1
- package/dist/src/button/button-composed.js +1 -1
- package/dist/src/button/button.js +1 -1
- package/dist/src/calendar/calendar-composed.js +1 -1
- package/dist/src/calendar/calendar.js +1 -1
- package/dist/src/card/card-composed.js +1 -1
- package/dist/src/carousel/carousel-composed.js +1 -1
- package/dist/src/carousel/carousel.js +1 -1
- package/dist/src/checkbox/checkbox-composed.js +1 -1
- package/dist/src/checkbox/checkbox.js +1 -1
- package/dist/src/collapsible/collapsible-composed.js +1 -1
- package/dist/src/collapsible/collapsible.js +1 -1
- package/dist/src/combobox/combobox-composed.js +1 -1
- package/dist/src/combobox/combobox.js +1 -1
- package/dist/src/command/command-composed.js +1 -1
- package/dist/src/command/command.js +1 -1
- package/dist/src/composed/with-styles.js +1 -1
- package/dist/src/context-menu/context-menu-composed.js +1 -1
- package/dist/src/context-menu/context-menu.js +1 -1
- package/dist/src/date-picker/date-picker-composed.js +1 -1
- package/dist/src/date-picker/date-picker.js +1 -1
- package/dist/src/dialog/dialog-composed.js +1 -1
- package/dist/src/dialog/dialog-stack-parts.js +1 -1
- package/dist/src/dialog/dialog.js +1 -1
- package/dist/src/dropdown-menu/dropdown-menu-composed.js +1 -1
- package/dist/src/dropdown-menu/dropdown-menu.js +1 -1
- package/dist/src/empty-state/empty-state-composed.js +1 -1
- package/dist/src/form-group/form-group-composed.js +1 -1
- package/dist/src/hover-card/hover-card-composed.js +1 -1
- package/dist/src/hover-card/hover-card.js +1 -1
- package/dist/src/input/input-composed.js +1 -1
- package/dist/src/label/label-composed.js +1 -1
- package/dist/src/list/list-composed.js +1 -1
- package/dist/src/menu/menu-composed.js +1 -1
- package/dist/src/menu/menu.js +1 -1
- package/dist/src/menubar/menubar-composed.js +1 -1
- package/dist/src/menubar/menubar.js +1 -1
- package/dist/src/navigation-menu/navigation-menu-composed.js +1 -1
- package/dist/src/navigation-menu/navigation-menu.js +1 -1
- package/dist/src/pagination/pagination-composed.js +1 -1
- package/dist/src/popover/popover-composed.js +1 -1
- package/dist/src/popover/popover.js +1 -1
- package/dist/src/progress/progress-composed.js +1 -1
- package/dist/src/progress/progress.js +1 -1
- package/dist/src/radio/radio-composed.js +1 -1
- package/dist/src/radio/radio.js +1 -1
- package/dist/src/resizable-panel/resizable-panel-composed.js +1 -1
- package/dist/src/resizable-panel/resizable-panel.js +1 -1
- package/dist/src/scroll-area/scroll-area-composed.js +1 -1
- package/dist/src/scroll-area/scroll-area.js +1 -1
- package/dist/src/select/select-composed.js +1 -1
- package/dist/src/select/select.js +1 -1
- package/dist/src/separator/separator-composed.js +1 -1
- package/dist/src/sheet/sheet-composed.js +1 -1
- package/dist/src/sheet/sheet.js +1 -1
- package/dist/src/skeleton/skeleton-composed.js +1 -1
- package/dist/src/slider/slider-composed.js +1 -1
- package/dist/src/slider/slider.js +1 -1
- package/dist/src/switch/switch-composed.js +1 -1
- package/dist/src/switch/switch.js +1 -1
- package/dist/src/table/table-composed.js +1 -1
- package/dist/src/tabs/tabs-composed.js +1 -1
- package/dist/src/tabs/tabs.js +1 -1
- package/dist/src/textarea/textarea-composed.js +1 -1
- package/dist/src/toast/toast.js +1 -1
- package/dist/src/toggle/toggle-composed.js +1 -1
- package/dist/src/toggle/toggle.js +1 -1
- package/dist/src/toggle-group/toggle-group-composed.js +1 -1
- package/dist/src/toggle-group/toggle-group.js +1 -1
- package/dist/src/tooltip/tooltip-composed.js +1 -1
- package/dist/src/tooltip/tooltip.js +1 -1
- package/package.json +3 -3
- package/dist/shared/chunk-144kbnmx.js +0 -95
- package/dist/shared/chunk-1ewxfgsa.js +0 -167
- package/dist/shared/chunk-1hm0mbke.js +0 -258
- package/dist/shared/chunk-22rt6ws9.js +0 -69
- package/dist/shared/chunk-2ssqz188.js +0 -162
- package/dist/shared/chunk-33he7ay9.js +0 -218
- package/dist/shared/chunk-3jack97k.js +0 -509
- package/dist/shared/chunk-75pegjs7.js +0 -26
- package/dist/shared/chunk-862x7dja.js +0 -398
- package/dist/shared/chunk-8pk1pn5h.js +0 -215
- package/dist/shared/chunk-8t0nm721.js +0 -152
- package/dist/shared/chunk-94twh4s4.js +0 -28
- package/dist/shared/chunk-9yb26c0w.js +0 -232
- package/dist/shared/chunk-a82r2pnq.js +0 -67
- package/dist/shared/chunk-axpbdpgx.js +0 -177
- package/dist/shared/chunk-b3j6mym6.js +0 -203
- package/dist/shared/chunk-b4zzg457.js +0 -410
- package/dist/shared/chunk-b9qxfcsy.js +0 -60
- package/dist/shared/chunk-bc2qqkhr.js +0 -194
- package/dist/shared/chunk-bv12nkdm.js +0 -149
- package/dist/shared/chunk-bvxc1ww4.js +0 -164
- package/dist/shared/chunk-czv0kqj4.js +0 -107
- package/dist/shared/chunk-d83ag07h.js +0 -189
- package/dist/shared/chunk-de18ashk.js +0 -134
- package/dist/shared/chunk-dvk4h36t.js +0 -140
- package/dist/shared/chunk-dxvnerw2.js +0 -353
- package/dist/shared/chunk-e399pzdq.js +0 -241
- package/dist/shared/chunk-e4qha9as.js +0 -180
- package/dist/shared/chunk-eb2d9v6k.js +0 -68
- package/dist/shared/chunk-ect26sp5.js +0 -353
- package/dist/shared/chunk-ev367pq3.js +0 -102
- package/dist/shared/chunk-fjykbv0v.js +0 -214
- package/dist/shared/chunk-gdddk6nh.js +0 -96
- package/dist/shared/chunk-ghkw5bjq.js +0 -55
- package/dist/shared/chunk-hfjtkytb.js +0 -310
- package/dist/shared/chunk-hpvjfj0j.js +0 -31
- package/dist/shared/chunk-jpyjk616.js +0 -52
- package/dist/shared/chunk-k6d53tne.js +0 -206
- package/dist/shared/chunk-knzg86am.js +0 -168
- package/dist/shared/chunk-ktbf6xrt.js +0 -179
- package/dist/shared/chunk-m8y2p66x.js +0 -252
- package/dist/shared/chunk-metxdt5x.js +0 -28
- package/dist/shared/chunk-mgae1d93.js +0 -157
- package/dist/shared/chunk-mtx2cfbx.js +0 -175
- package/dist/shared/chunk-n436p5cb.js +0 -260
- package/dist/shared/chunk-nj420k31.js +0 -54
- package/dist/shared/chunk-nsmvdxgp.js +0 -213
- package/dist/shared/chunk-pcms04vq.js +0 -162
- package/dist/shared/chunk-pqskzq8t.js +0 -79
- package/dist/shared/chunk-pwr60kyd.js +0 -321
- package/dist/shared/chunk-pzknpa1y.js +0 -327
- package/dist/shared/chunk-q77y3rg4.js +0 -189
- package/dist/shared/chunk-qhnany7w.js +0 -179
- package/dist/shared/chunk-rdr0rtpr.js +0 -131
- package/dist/shared/chunk-rj52ty6r.js +0 -147
- package/dist/shared/chunk-rnqc7735.js +0 -125
- package/dist/shared/chunk-rtk30950.js +0 -202
- package/dist/shared/chunk-s0xgd8vg.js +0 -266
- package/dist/shared/chunk-s415735j.js +0 -357
- package/dist/shared/chunk-s62e7jf4.js +0 -30
- package/dist/shared/chunk-snd8e6r8.js +0 -418
- package/dist/shared/chunk-spng4yb9.js +0 -73
- package/dist/shared/chunk-t887wwjc.js +0 -168
- package/dist/shared/chunk-tn0m98j8.js +0 -42
- package/dist/shared/chunk-v0b5pkcq.js +0 -30
- package/dist/shared/chunk-v5tj7veh.js +0 -284
- package/dist/shared/chunk-vkscwzpr.js +0 -294
- package/dist/shared/chunk-vv187snj.js +0 -112
- package/dist/shared/chunk-xv4wd0kf.js +0 -293
- package/dist/shared/chunk-y1hpsqzy.js +0 -185
- package/dist/shared/chunk-yfzddvxc.js +0 -71
- package/dist/shared/chunk-yzgzx2dh.js +0 -311
- package/dist/shared/chunk-z5j7ztf2.js +0 -467
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-q7xbcj9q.js";
|
|
4
|
+
|
|
5
|
+
// src/dialog/dialog-stack-parts.tsx
|
|
6
|
+
import { jsxDEV as jsxDEV_7x81h0kn } from "@vertz/ui/jsx-dev-runtime";
|
|
7
|
+
import { DialogHandleContext, DialogIdContext, useContext } from "@vertz/ui";
|
|
8
|
+
function useDialogId() {
|
|
9
|
+
const id = useContext(DialogIdContext);
|
|
10
|
+
if (!id) {
|
|
11
|
+
throw new Error("Dialog sub-component must be used inside a dialog opened via DialogStack");
|
|
12
|
+
}
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
function useDialogHandle() {
|
|
16
|
+
const handle = useContext(DialogHandleContext);
|
|
17
|
+
if (!handle) {
|
|
18
|
+
throw new Error("Dialog sub-component must be used inside a dialog opened via DialogStack");
|
|
19
|
+
}
|
|
20
|
+
return handle;
|
|
21
|
+
}
|
|
22
|
+
function StackDialogTitle({
|
|
23
|
+
children,
|
|
24
|
+
className: cls,
|
|
25
|
+
class: classProp
|
|
26
|
+
}) {
|
|
27
|
+
const dialogId = useDialogId();
|
|
28
|
+
return jsxDEV_7x81h0kn("h2", {
|
|
29
|
+
id: `${dialogId}-title`,
|
|
30
|
+
"data-part": "title",
|
|
31
|
+
class: cn(cls ?? classProp),
|
|
32
|
+
children
|
|
33
|
+
}, undefined, false, undefined, this);
|
|
34
|
+
}
|
|
35
|
+
function StackDialogDescription({
|
|
36
|
+
children,
|
|
37
|
+
className: cls,
|
|
38
|
+
class: classProp
|
|
39
|
+
}) {
|
|
40
|
+
const dialogId = useDialogId();
|
|
41
|
+
return jsxDEV_7x81h0kn("p", {
|
|
42
|
+
id: `${dialogId}-desc`,
|
|
43
|
+
"data-part": "description",
|
|
44
|
+
class: cn(cls ?? classProp),
|
|
45
|
+
children
|
|
46
|
+
}, undefined, false, undefined, this);
|
|
47
|
+
}
|
|
48
|
+
function StackDialogHeader({
|
|
49
|
+
children,
|
|
50
|
+
className: cls,
|
|
51
|
+
class: classProp
|
|
52
|
+
}) {
|
|
53
|
+
return jsxDEV_7x81h0kn("div", {
|
|
54
|
+
"data-part": "header",
|
|
55
|
+
class: cn(cls ?? classProp),
|
|
56
|
+
children
|
|
57
|
+
}, undefined, false, undefined, this);
|
|
58
|
+
}
|
|
59
|
+
function StackDialogFooter({
|
|
60
|
+
children,
|
|
61
|
+
className: cls,
|
|
62
|
+
class: classProp
|
|
63
|
+
}) {
|
|
64
|
+
return jsxDEV_7x81h0kn("div", {
|
|
65
|
+
"data-part": "footer",
|
|
66
|
+
class: cn(cls ?? classProp),
|
|
67
|
+
children
|
|
68
|
+
}, undefined, false, undefined, this);
|
|
69
|
+
}
|
|
70
|
+
function StackDialogBody({
|
|
71
|
+
children,
|
|
72
|
+
className: cls,
|
|
73
|
+
class: classProp
|
|
74
|
+
}) {
|
|
75
|
+
return jsxDEV_7x81h0kn("div", {
|
|
76
|
+
"data-part": "body",
|
|
77
|
+
class: cn(cls ?? classProp),
|
|
78
|
+
children
|
|
79
|
+
}, undefined, false, undefined, this);
|
|
80
|
+
}
|
|
81
|
+
function StackDialogCancel({
|
|
82
|
+
children,
|
|
83
|
+
className: cls,
|
|
84
|
+
class: classProp
|
|
85
|
+
}) {
|
|
86
|
+
const handle = useDialogHandle();
|
|
87
|
+
return jsxDEV_7x81h0kn("button", {
|
|
88
|
+
type: "button",
|
|
89
|
+
"data-part": "cancel",
|
|
90
|
+
class: cn(cls ?? classProp),
|
|
91
|
+
onClick: () => handle.close(),
|
|
92
|
+
children
|
|
93
|
+
}, undefined, false, undefined, this);
|
|
94
|
+
}
|
|
95
|
+
function StackDialogClose({
|
|
96
|
+
children,
|
|
97
|
+
className: cls,
|
|
98
|
+
class: classProp
|
|
99
|
+
}) {
|
|
100
|
+
const handle = useDialogHandle();
|
|
101
|
+
return jsxDEV_7x81h0kn("button", {
|
|
102
|
+
type: "button",
|
|
103
|
+
"data-part": "close",
|
|
104
|
+
"aria-label": children ? undefined : "Close",
|
|
105
|
+
class: cn(cls ?? classProp),
|
|
106
|
+
onClick: () => handle.close(),
|
|
107
|
+
children: children ?? "×"
|
|
108
|
+
}, undefined, false, undefined, this);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { StackDialogTitle, StackDialogDescription, StackDialogHeader, StackDialogFooter, StackDialogBody, StackDialogCancel, StackDialogClose };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
uniqueId
|
|
3
|
+
} from "./chunk-8y1jf6xr.js";
|
|
4
|
+
import {
|
|
5
|
+
Keys,
|
|
6
|
+
isKey
|
|
7
|
+
} from "./chunk-7867pr13.js";
|
|
8
|
+
import {
|
|
9
|
+
applyAttrs
|
|
10
|
+
} from "./chunk-2db2dnp3.js";
|
|
11
|
+
|
|
12
|
+
// src/checkbox/checkbox.tsx
|
|
13
|
+
import { jsxDEV as jsxDEV_7x81h0kn } from "@vertz/ui/jsx-dev-runtime";
|
|
14
|
+
function dataStateFor(checked) {
|
|
15
|
+
if (checked === "mixed")
|
|
16
|
+
return "indeterminate";
|
|
17
|
+
return checked ? "checked" : "unchecked";
|
|
18
|
+
}
|
|
19
|
+
function ariaCheckedFor(checked) {
|
|
20
|
+
if (checked === "mixed")
|
|
21
|
+
return "mixed";
|
|
22
|
+
return String(checked);
|
|
23
|
+
}
|
|
24
|
+
function CheckboxRoot(options = {}) {
|
|
25
|
+
const { defaultChecked = false, disabled = false, onCheckedChange, ...attrs } = options;
|
|
26
|
+
let checked = defaultChecked;
|
|
27
|
+
function toggle() {
|
|
28
|
+
if (disabled)
|
|
29
|
+
return;
|
|
30
|
+
checked = checked === "mixed" ? true : !checked;
|
|
31
|
+
onCheckedChange?.(checked);
|
|
32
|
+
}
|
|
33
|
+
const el = jsxDEV_7x81h0kn("button", {
|
|
34
|
+
type: "button",
|
|
35
|
+
role: "checkbox",
|
|
36
|
+
id: uniqueId("checkbox"),
|
|
37
|
+
"aria-checked": ariaCheckedFor(checked),
|
|
38
|
+
"data-state": dataStateFor(checked),
|
|
39
|
+
disabled,
|
|
40
|
+
"aria-disabled": disabled ? "true" : undefined,
|
|
41
|
+
onClick: toggle,
|
|
42
|
+
onKeydown: (e) => {
|
|
43
|
+
if (isKey(e, Keys.Space)) {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
toggle();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, undefined, false, undefined, this);
|
|
49
|
+
applyAttrs(el, attrs);
|
|
50
|
+
return el;
|
|
51
|
+
}
|
|
52
|
+
var Checkbox = {
|
|
53
|
+
Root: CheckboxRoot
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { Checkbox };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-q7xbcj9q.js";
|
|
4
|
+
import {
|
|
5
|
+
uniqueId
|
|
6
|
+
} from "./chunk-8y1jf6xr.js";
|
|
7
|
+
import {
|
|
8
|
+
Keys,
|
|
9
|
+
isKey
|
|
10
|
+
} from "./chunk-7867pr13.js";
|
|
11
|
+
|
|
12
|
+
// src/command/command-composed.tsx
|
|
13
|
+
import { jsxDEV as jsxDEV_7x81h0kn } from "@vertz/ui/jsx-dev-runtime";
|
|
14
|
+
import { createContext, useContext } from "@vertz/ui";
|
|
15
|
+
var CommandContext = createContext(undefined, "@vertz/ui-primitives::CommandContext");
|
|
16
|
+
function useCommandContext(componentName) {
|
|
17
|
+
const ctx = useContext(CommandContext);
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
throw new Error(`<Command.${componentName}> must be used inside <Command>. ` + "Ensure it is a direct or nested child of the Command root component.");
|
|
20
|
+
}
|
|
21
|
+
return ctx;
|
|
22
|
+
}
|
|
23
|
+
function CommandInput({ className: cls, class: classProp }) {
|
|
24
|
+
const ctx = useCommandContext("Input");
|
|
25
|
+
return jsxDEV_7x81h0kn("input", {
|
|
26
|
+
type: "text",
|
|
27
|
+
role: "combobox",
|
|
28
|
+
"aria-autocomplete": "list",
|
|
29
|
+
"aria-expanded": "true",
|
|
30
|
+
"aria-controls": ctx.listId,
|
|
31
|
+
"data-command-input": "",
|
|
32
|
+
placeholder: ctx.placeholder,
|
|
33
|
+
class: cn(ctx.classes?.input, cls ?? classProp),
|
|
34
|
+
onInput: (e) => {
|
|
35
|
+
ctx.handleInput(e.target);
|
|
36
|
+
},
|
|
37
|
+
onKeydown: (e) => {
|
|
38
|
+
ctx.handleKeydown(e, e.target);
|
|
39
|
+
}
|
|
40
|
+
}, undefined, false, undefined, this);
|
|
41
|
+
}
|
|
42
|
+
function CommandList({ children, className: cls, class: classProp }) {
|
|
43
|
+
const ctx = useCommandContext("List");
|
|
44
|
+
return jsxDEV_7x81h0kn("div", {
|
|
45
|
+
role: "listbox",
|
|
46
|
+
id: ctx.listId,
|
|
47
|
+
class: cn(ctx.classes?.list, cls ?? classProp),
|
|
48
|
+
children
|
|
49
|
+
}, undefined, false, undefined, this);
|
|
50
|
+
}
|
|
51
|
+
function CommandEmpty({ children, className: cls, class: classProp }) {
|
|
52
|
+
const ctx = useCommandContext("Empty");
|
|
53
|
+
return jsxDEV_7x81h0kn("div", {
|
|
54
|
+
"data-part": "command-empty",
|
|
55
|
+
"data-command-empty": "",
|
|
56
|
+
"aria-hidden": "true",
|
|
57
|
+
style: "display: none",
|
|
58
|
+
class: cn(ctx.classes?.empty, cls ?? classProp),
|
|
59
|
+
children
|
|
60
|
+
}, undefined, false, undefined, this);
|
|
61
|
+
}
|
|
62
|
+
function CommandItem({
|
|
63
|
+
value,
|
|
64
|
+
children,
|
|
65
|
+
keywords,
|
|
66
|
+
className: cls,
|
|
67
|
+
class: classProp
|
|
68
|
+
}) {
|
|
69
|
+
const ctx = useCommandContext("Item");
|
|
70
|
+
const isInitialActive = ctx.claimInitialActive();
|
|
71
|
+
return jsxDEV_7x81h0kn("div", {
|
|
72
|
+
role: "option",
|
|
73
|
+
"data-value": value,
|
|
74
|
+
"aria-selected": isInitialActive ? "true" : "false",
|
|
75
|
+
"data-keywords": keywords && keywords.length > 0 ? keywords.join(" ") : undefined,
|
|
76
|
+
class: cn(ctx.classes?.item, cls ?? classProp),
|
|
77
|
+
onClick: () => {
|
|
78
|
+
ctx.getOnSelect()?.(value);
|
|
79
|
+
},
|
|
80
|
+
children
|
|
81
|
+
}, undefined, false, undefined, this);
|
|
82
|
+
}
|
|
83
|
+
function CommandGroup({ label, children, className: cls, class: classProp }) {
|
|
84
|
+
const ctx = useCommandContext("Group");
|
|
85
|
+
const headingId = uniqueId("command-group");
|
|
86
|
+
return jsxDEV_7x81h0kn("div", {
|
|
87
|
+
role: "group",
|
|
88
|
+
"aria-labelledby": headingId,
|
|
89
|
+
"data-command-group": "",
|
|
90
|
+
class: cn(ctx.classes?.group, cls ?? classProp),
|
|
91
|
+
children: [
|
|
92
|
+
jsxDEV_7x81h0kn("div", {
|
|
93
|
+
id: headingId,
|
|
94
|
+
"data-command-group-heading": "",
|
|
95
|
+
class: cn(ctx.classes?.groupHeading),
|
|
96
|
+
children: label
|
|
97
|
+
}, undefined, false, undefined, this),
|
|
98
|
+
children
|
|
99
|
+
]
|
|
100
|
+
}, undefined, true, undefined, this);
|
|
101
|
+
}
|
|
102
|
+
function CommandSeparator({ className: cls, class: classProp }) {
|
|
103
|
+
const ctx = useCommandContext("Separator");
|
|
104
|
+
return jsxDEV_7x81h0kn("hr", {
|
|
105
|
+
role: "separator",
|
|
106
|
+
class: cn(ctx.classes?.separator, cls ?? classProp)
|
|
107
|
+
}, undefined, false, undefined, this);
|
|
108
|
+
}
|
|
109
|
+
function ComposedCommandRoot({
|
|
110
|
+
children,
|
|
111
|
+
classes,
|
|
112
|
+
filter: customFilter,
|
|
113
|
+
onSelect,
|
|
114
|
+
onInputChange,
|
|
115
|
+
placeholder
|
|
116
|
+
}) {
|
|
117
|
+
const rootId = uniqueId("command");
|
|
118
|
+
const listId = uniqueId("command-list");
|
|
119
|
+
const defaultFilter = (value, search) => value.toLowerCase().includes(search.toLowerCase());
|
|
120
|
+
const filterFn = customFilter ?? defaultFilter;
|
|
121
|
+
const state = {
|
|
122
|
+
activeIndex: 0,
|
|
123
|
+
initialClaimed: false
|
|
124
|
+
};
|
|
125
|
+
function claimInitialActive() {
|
|
126
|
+
if (state.initialClaimed)
|
|
127
|
+
return false;
|
|
128
|
+
state.initialClaimed = true;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
function findRoot(el) {
|
|
132
|
+
let current = el;
|
|
133
|
+
while (current) {
|
|
134
|
+
if (current.id === rootId)
|
|
135
|
+
return current;
|
|
136
|
+
current = current.parentElement;
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function getItemsFrom(root) {
|
|
141
|
+
return [...root.querySelectorAll('[role="option"]')];
|
|
142
|
+
}
|
|
143
|
+
function getVisibleItemsFrom(root) {
|
|
144
|
+
return getItemsFrom(root).filter((item) => item.getAttribute("aria-hidden") !== "true");
|
|
145
|
+
}
|
|
146
|
+
function updateActiveItemIn(root) {
|
|
147
|
+
const allItems = getItemsFrom(root);
|
|
148
|
+
const visible = getVisibleItemsFrom(root);
|
|
149
|
+
for (const item of allItems) {
|
|
150
|
+
item.setAttribute("aria-selected", "false");
|
|
151
|
+
}
|
|
152
|
+
if (visible.length > 0 && state.activeIndex >= 0 && state.activeIndex < visible.length) {
|
|
153
|
+
visible[state.activeIndex]?.setAttribute("aria-selected", "true");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function runFilterFrom(inputEl, root) {
|
|
157
|
+
const search = inputEl.value ?? "";
|
|
158
|
+
const allItems = getItemsFrom(root);
|
|
159
|
+
let visibleCount = 0;
|
|
160
|
+
for (const item of allItems) {
|
|
161
|
+
const value = item.getAttribute("data-value") ?? "";
|
|
162
|
+
const text = item.textContent ?? "";
|
|
163
|
+
const keywords = item.getAttribute("data-keywords") ?? "";
|
|
164
|
+
const searchable = `${value} ${text} ${keywords}`;
|
|
165
|
+
const matches = search === "" || filterFn(searchable, search);
|
|
166
|
+
item.setAttribute("aria-hidden", String(!matches));
|
|
167
|
+
item.style.display = matches ? "" : "none";
|
|
168
|
+
if (matches)
|
|
169
|
+
visibleCount++;
|
|
170
|
+
}
|
|
171
|
+
const groups = root.querySelectorAll("[data-command-group]");
|
|
172
|
+
for (const group of groups) {
|
|
173
|
+
const groupItems = group.querySelectorAll('[role="option"]');
|
|
174
|
+
const hasVisible = [...groupItems].some((item) => item.getAttribute("aria-hidden") !== "true");
|
|
175
|
+
const heading = group.querySelector("[data-command-group-heading]");
|
|
176
|
+
if (heading) {
|
|
177
|
+
heading.setAttribute("aria-hidden", String(!hasVisible));
|
|
178
|
+
heading.style.display = hasVisible ? "" : "none";
|
|
179
|
+
}
|
|
180
|
+
group.style.display = hasVisible ? "" : "none";
|
|
181
|
+
}
|
|
182
|
+
const emptyEl = root.querySelector("[data-command-empty]");
|
|
183
|
+
if (emptyEl) {
|
|
184
|
+
const hide = visibleCount > 0;
|
|
185
|
+
emptyEl.setAttribute("aria-hidden", String(hide));
|
|
186
|
+
emptyEl.style.display = hide ? "none" : "";
|
|
187
|
+
}
|
|
188
|
+
state.activeIndex = 0;
|
|
189
|
+
updateActiveItemIn(root);
|
|
190
|
+
}
|
|
191
|
+
function handleInput(inputEl) {
|
|
192
|
+
const root = findRoot(inputEl);
|
|
193
|
+
if (!root)
|
|
194
|
+
return;
|
|
195
|
+
onInputChange?.(inputEl.value);
|
|
196
|
+
runFilterFrom(inputEl, root);
|
|
197
|
+
}
|
|
198
|
+
function handleKeydown(event, inputEl) {
|
|
199
|
+
const root = findRoot(inputEl);
|
|
200
|
+
if (!root)
|
|
201
|
+
return;
|
|
202
|
+
const visible = getVisibleItemsFrom(root);
|
|
203
|
+
if (isKey(event, Keys.ArrowDown)) {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
const next = Math.min(state.activeIndex + 1, visible.length - 1);
|
|
206
|
+
state.activeIndex = next;
|
|
207
|
+
updateActiveItemIn(root);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (isKey(event, Keys.ArrowUp)) {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
const prev = Math.max(state.activeIndex - 1, 0);
|
|
213
|
+
state.activeIndex = prev;
|
|
214
|
+
updateActiveItemIn(root);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (isKey(event, Keys.Enter)) {
|
|
218
|
+
event.preventDefault();
|
|
219
|
+
const active = visible[state.activeIndex];
|
|
220
|
+
if (active) {
|
|
221
|
+
const val = active.getAttribute("data-value");
|
|
222
|
+
if (val !== null) {
|
|
223
|
+
onSelect?.(val);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (isKey(event, Keys.Escape)) {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
inputEl.value = "";
|
|
231
|
+
onInputChange?.("");
|
|
232
|
+
runFilterFrom(inputEl, root);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const ctx = {
|
|
236
|
+
rootId,
|
|
237
|
+
listId,
|
|
238
|
+
classes,
|
|
239
|
+
getOnSelect: () => onSelect,
|
|
240
|
+
placeholder,
|
|
241
|
+
handleInput,
|
|
242
|
+
handleKeydown,
|
|
243
|
+
claimInitialActive
|
|
244
|
+
};
|
|
245
|
+
return jsxDEV_7x81h0kn(CommandContext.Provider, {
|
|
246
|
+
value: ctx,
|
|
247
|
+
children: jsxDEV_7x81h0kn("div", {
|
|
248
|
+
id: rootId,
|
|
249
|
+
class: cn(classes?.root),
|
|
250
|
+
children
|
|
251
|
+
}, undefined, false, undefined, this)
|
|
252
|
+
}, undefined, false, undefined, this);
|
|
253
|
+
}
|
|
254
|
+
var ComposedCommand = Object.assign(ComposedCommandRoot, {
|
|
255
|
+
Input: CommandInput,
|
|
256
|
+
List: CommandList,
|
|
257
|
+
Empty: CommandEmpty,
|
|
258
|
+
Item: CommandItem,
|
|
259
|
+
Group: CommandGroup,
|
|
260
|
+
Separator: CommandSeparator
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
export { ComposedCommand };
|