@cascivo/react 0.17.1 → 1.0.0
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/README.md +4 -3
- package/dist/action-sheet/action-sheet.js +1 -1
- package/dist/breadcrumb/breadcrumb.js +7 -7
- package/dist/checkbox/checkbox.js +11 -10
- package/dist/color-picker/color-picker.js +81 -77
- package/dist/combobox/combobox.js +81 -76
- package/dist/command-menu/command-menu.js +104 -104
- package/dist/comparison/comparison.js +18 -18
- package/dist/data-table/data-table.css +1 -1
- package/dist/data-table/data-table.js +148 -121
- package/dist/data-table/data-table.module.js +29 -29
- package/dist/date-picker/date-picker.js +98 -93
- package/dist/date-range-picker/date-range-picker.js +1 -1
- package/dist/dock/dock.js +2 -2
- package/dist/dropdown/dropdown.js +43 -40
- package/dist/editable/editable.js +29 -20
- package/dist/fab/fab.js +37 -37
- package/dist/field/field.js +24 -17
- package/dist/file-uploader/file-uploader.js +24 -23
- package/dist/filter/filter.js +11 -11
- package/dist/index.d.ts +1302 -85
- package/dist/input/input.js +14 -13
- package/dist/navigation-menu/navigation-menu.js +9 -9
- package/dist/node/action-sheet/action-sheet.js +1 -1
- package/dist/node/breadcrumb/breadcrumb.js +7 -7
- package/dist/node/checkbox/checkbox.js +11 -10
- package/dist/node/color-picker/color-picker.js +81 -77
- package/dist/node/combobox/combobox.js +81 -76
- package/dist/node/command-menu/command-menu.js +104 -104
- package/dist/node/comparison/comparison.js +18 -18
- package/dist/node/data-table/data-table.js +148 -121
- package/dist/node/data-table/data-table.module.js +29 -29
- package/dist/node/date-picker/date-picker.js +98 -93
- package/dist/node/date-range-picker/date-range-picker.js +1 -1
- package/dist/node/dock/dock.js +2 -2
- package/dist/node/dropdown/dropdown.js +43 -40
- package/dist/node/editable/editable.js +29 -20
- package/dist/node/fab/fab.js +37 -37
- package/dist/node/field/field.js +24 -17
- package/dist/node/file-uploader/file-uploader.js +24 -23
- package/dist/node/filter/filter.js +11 -11
- package/dist/node/input/input.js +14 -13
- package/dist/node/navigation-menu/navigation-menu.js +9 -9
- package/dist/node/number-input/number-input.js +28 -27
- package/dist/node/overflow-menu/overflow-menu.js +7 -7
- package/dist/node/progress/progress.js +3 -3
- package/dist/node/progress-circle/progress-circle.js +8 -8
- package/dist/node/progress-indicator/progress-indicator.js +1 -1
- package/dist/node/qr-code/qr-code.js +11 -11
- package/dist/node/radial-progress/radial-progress.js +9 -9
- package/dist/node/radio/radio.js +10 -9
- package/dist/node/react/src/index.js +93 -93
- package/dist/node/resizable/resizable.js +24 -24
- package/dist/node/search/search.js +35 -31
- package/dist/node/select/select.js +15 -14
- package/dist/node/side-nav/side-nav.js +35 -35
- package/dist/node/side-nav/side-nav.module.js +27 -27
- package/dist/node/slider/slider.js +13 -12
- package/dist/node/spinner/spinner.js +4 -4
- package/dist/node/steps/steps.js +10 -10
- package/dist/node/structured-list/structured-list.js +14 -14
- package/dist/node/swap/swap.js +5 -5
- package/dist/node/switcher/switcher.js +5 -5
- package/dist/node/tags-input/tags-input.js +20 -16
- package/dist/node/textarea/textarea.js +14 -13
- package/dist/node/time-picker/time-picker.js +21 -20
- package/dist/node/toggle/toggle.js +8 -7
- package/dist/node/tree-view/tree-view.js +43 -43
- package/dist/node/virtual-list/virtual-list.js +10 -10
- package/dist/node/wheel-picker/wheel-picker.js +36 -36
- package/dist/number-input/number-input.js +28 -27
- package/dist/overflow-menu/overflow-menu.js +7 -7
- package/dist/progress/progress.js +3 -3
- package/dist/progress-circle/progress-circle.js +8 -8
- package/dist/progress-indicator/progress-indicator.js +1 -1
- package/dist/qr-code/qr-code.js +11 -11
- package/dist/radial-progress/radial-progress.js +9 -9
- package/dist/radio/radio.js +10 -9
- package/dist/react/src/index.js +93 -93
- package/dist/resizable/resizable.js +24 -24
- package/dist/search/search.js +35 -31
- package/dist/select/select.js +15 -14
- package/dist/side-nav/side-nav.css +1 -1
- package/dist/side-nav/side-nav.js +35 -35
- package/dist/side-nav/side-nav.module.js +27 -27
- package/dist/slider/slider.js +13 -12
- package/dist/spinner/spinner.js +4 -4
- package/dist/steps/steps.js +10 -10
- package/dist/structured-list/structured-list.js +14 -14
- package/dist/styles.css +2 -2
- package/dist/swap/swap.js +5 -5
- package/dist/switcher/switcher.js +5 -5
- package/dist/tags-input/tags-input.js +20 -16
- package/dist/textarea/textarea.js +14 -13
- package/dist/time-picker/time-picker.js +21 -20
- package/dist/toggle/toggle.js +8 -7
- package/dist/tree-view/tree-view.js +43 -43
- package/dist/virtual-list/virtual-list.js +10 -10
- package/dist/wheel-picker/wheel-picker.js +36 -36
- package/package.json +4 -4
- package/readme.body.md +4 -3
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
import e from "./date-picker.module.js";
|
|
4
4
|
import { useId as t, useRef as n } from "react";
|
|
5
|
-
import { batch as r, cn as i, createMachine as a, useControllableSignal as o, useMachine as s, useSignal as c, useSignalEffect as
|
|
6
|
-
import { builtin as
|
|
7
|
-
import { jsx as
|
|
5
|
+
import { batch as r, cn as i, createMachine as a, useControllableSignal as o, useMachine as s, useSignal as c, useSignalEffect as ee, useSignals as te } from "@cascivo/core";
|
|
6
|
+
import { builtin as l, currentLocale as u, t as d } from "@cascivo/i18n";
|
|
7
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
8
|
//#region ../components/src/date-picker/date-picker.tsx
|
|
9
|
-
var
|
|
9
|
+
var m = a({
|
|
10
10
|
initial: "closed",
|
|
11
11
|
states: {
|
|
12
12
|
closed: { on: { OPEN: "open" } },
|
|
13
13
|
open: { on: { CLOSE: "closed" } }
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
function
|
|
16
|
+
function ne(e) {
|
|
17
17
|
try {
|
|
18
18
|
let t = new Intl.Locale(e).weekInfo;
|
|
19
19
|
if (t) return t.firstDay % 7;
|
|
20
20
|
} catch {}
|
|
21
21
|
return 1;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function re(e, t, n) {
|
|
24
24
|
let r = new Date(Date.UTC(e, t, 1)), i = new Date(Date.UTC(e, t + 1, 0)), a = (r.getUTCDay() - n + 7) % 7, o = [];
|
|
25
25
|
for (let e = 0; e < a; e++) o.push(null);
|
|
26
26
|
for (let n = 1; n <= i.getUTCDate(); n++) o.push(new Date(Date.UTC(e, t, n)));
|
|
@@ -29,53 +29,56 @@ function te(e, t, n) {
|
|
|
29
29
|
for (let e = 0; e < o.length; e += 7) s.push(o.slice(e, e + 7));
|
|
30
30
|
return s;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function h(e, t) {
|
|
33
33
|
return new Intl.DateTimeFormat(t).format(e);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function g(e) {
|
|
36
36
|
return e.toISOString().slice(0, 10);
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function _(e) {
|
|
39
39
|
let [t, n, r] = e.split("-").map(Number);
|
|
40
40
|
return new Date(Date.UTC(t, n - 1, r));
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
function ie(...e) {
|
|
43
|
+
return e.filter(Boolean).join(" ") || void 0;
|
|
44
|
+
}
|
|
45
|
+
function v({ value: a, defaultValue: v, onValueChange: y, min: b, max: x, clearable: ae = !1, label: S, ariaLabel: oe, hint: C, error: w, size: T = "md", disabled: E = !1, labels: D, className: O, id: k, "aria-labelledby": A, "aria-describedby": se, "aria-invalid": ce }) {
|
|
46
|
+
te();
|
|
47
|
+
let [j, M] = s(m), N = t(), P = k ?? `cascade-date-picker-${N}`, F = `${N}-grid`, I = u(), L = D?.placeholder ?? d(l.datePicker.placeholder), R = D?.previousMonth ?? d(l.datePicker.previousMonth), z = D?.nextMonth ?? d(l.datePicker.nextMonth), B = D?.clear ?? d(l.datePicker.clear), V = /* @__PURE__ */ new Date(), H = g(V), [U] = o({
|
|
45
48
|
value: a,
|
|
46
|
-
defaultValue:
|
|
47
|
-
}),
|
|
48
|
-
|
|
49
|
-
if (
|
|
49
|
+
defaultValue: v
|
|
50
|
+
}), W = c(U.value ? _(U.value).getUTCFullYear() : V.getUTCFullYear()), G = c(U.value ? _(U.value).getUTCMonth() : V.getUTCMonth()), K = c(U.value), q = n(null);
|
|
51
|
+
ee(() => {
|
|
52
|
+
if (j.value !== "open") return;
|
|
50
53
|
let e = (e) => {
|
|
51
|
-
|
|
54
|
+
q.current && !q.current.contains(e.target) && M("CLOSE");
|
|
52
55
|
};
|
|
53
56
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
54
57
|
});
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
}, J = () =>
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
e.stopPropagation(), a === void 0 && (
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}) :
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}) :
|
|
69
|
-
}, Z =
|
|
58
|
+
let le = () => {
|
|
59
|
+
E || M("OPEN");
|
|
60
|
+
}, J = () => M("CLOSE"), Y = y, X = (e) => {
|
|
61
|
+
b && e < b || x && e > x || (a === void 0 && (U.value = e), Y?.(e), J());
|
|
62
|
+
}, ue = (e) => {
|
|
63
|
+
e.stopPropagation(), a === void 0 && (U.value = void 0), Y?.(void 0);
|
|
64
|
+
}, de = () => {
|
|
65
|
+
G.value === 0 ? r(() => {
|
|
66
|
+
W.value--, G.value = 11;
|
|
67
|
+
}) : G.value--;
|
|
68
|
+
}, fe = () => {
|
|
69
|
+
G.value === 11 ? r(() => {
|
|
70
|
+
W.value++, G.value = 0;
|
|
71
|
+
}) : G.value++;
|
|
72
|
+
}, Z = ne(I), pe = re(W.value, G.value, Z), me = new Intl.DateTimeFormat(I, { weekday: "short" }), he = Array.from({ length: 7 }, (e, t) => {
|
|
70
73
|
let n = new Date(Date.UTC(2024, 0, 7 + Z + t));
|
|
71
|
-
return
|
|
72
|
-
}), Q = new Intl.DateTimeFormat(
|
|
74
|
+
return me.format(n);
|
|
75
|
+
}), Q = new Intl.DateTimeFormat(I, {
|
|
73
76
|
month: "long",
|
|
74
77
|
year: "numeric"
|
|
75
|
-
}).format(new Date(Date.UTC(
|
|
76
|
-
let t =
|
|
78
|
+
}).format(new Date(Date.UTC(W.value, G.value, 1))), ge = (e) => {
|
|
79
|
+
let t = K.value;
|
|
77
80
|
if (!t) return;
|
|
78
|
-
let n =
|
|
81
|
+
let n = _(t), i;
|
|
79
82
|
if (e.key === "ArrowRight") i = new Date(Date.UTC(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate() + 1));
|
|
80
83
|
else if (e.key === "ArrowLeft") i = new Date(Date.UTC(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate() - 1));
|
|
81
84
|
else if (e.key === "ArrowDown") i = new Date(Date.UTC(n.getUTCFullYear(), n.getUTCMonth(), n.getUTCDate() + 7));
|
|
@@ -88,103 +91,105 @@ function b({ value: a, defaultValue: b, onValueChange: ne, onChange: x, min: S,
|
|
|
88
91
|
return;
|
|
89
92
|
} else return;
|
|
90
93
|
if (e.preventDefault(), i) {
|
|
91
|
-
let e =
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
let e = g(i);
|
|
95
|
+
if (b && e < b || x && e > x) return;
|
|
96
|
+
K.value = e, r(() => {
|
|
97
|
+
W.value = i.getUTCFullYear(), G.value = i.getUTCMonth();
|
|
95
98
|
});
|
|
96
99
|
}
|
|
97
|
-
}, $ =
|
|
98
|
-
return /* @__PURE__ */
|
|
99
|
-
ref:
|
|
100
|
-
className: i(e.wrapper,
|
|
101
|
-
"data-state":
|
|
102
|
-
"data-size":
|
|
100
|
+
}, $ = U.value ? h(_(U.value), I) : "";
|
|
101
|
+
return /* @__PURE__ */ p("div", {
|
|
102
|
+
ref: q,
|
|
103
|
+
className: i(e.wrapper, O),
|
|
104
|
+
"data-state": w ? "error" : j.value,
|
|
105
|
+
"data-size": T,
|
|
103
106
|
children: [
|
|
104
|
-
|
|
107
|
+
S && /* @__PURE__ */ f("label", {
|
|
105
108
|
className: e.label,
|
|
106
|
-
htmlFor:
|
|
107
|
-
children:
|
|
109
|
+
htmlFor: P,
|
|
110
|
+
children: S
|
|
108
111
|
}),
|
|
109
|
-
/* @__PURE__ */
|
|
112
|
+
/* @__PURE__ */ p("div", {
|
|
110
113
|
className: e.field,
|
|
111
|
-
children: [/* @__PURE__ */
|
|
112
|
-
id:
|
|
114
|
+
children: [/* @__PURE__ */ p("button", {
|
|
115
|
+
id: P,
|
|
113
116
|
type: "button",
|
|
114
117
|
role: "combobox",
|
|
115
|
-
"aria-expanded":
|
|
116
|
-
"aria-controls":
|
|
118
|
+
"aria-expanded": j.value === "open",
|
|
119
|
+
"aria-controls": F,
|
|
117
120
|
"aria-haspopup": "dialog",
|
|
118
|
-
"aria-
|
|
119
|
-
"aria-
|
|
121
|
+
"aria-labelledby": A,
|
|
122
|
+
"aria-label": oe,
|
|
123
|
+
"aria-invalid": w ? !0 : ce,
|
|
124
|
+
"aria-describedby": ie(w ? `${N}-error` : C ? `${N}-hint` : void 0, se),
|
|
120
125
|
className: e.trigger,
|
|
121
|
-
disabled:
|
|
122
|
-
onClick:
|
|
123
|
-
children: [/* @__PURE__ */
|
|
126
|
+
disabled: E,
|
|
127
|
+
onClick: j.value === "open" ? J : le,
|
|
128
|
+
children: [/* @__PURE__ */ f("span", {
|
|
124
129
|
className: i(e.value, $ ? void 0 : e.placeholder),
|
|
125
|
-
children: $ ||
|
|
126
|
-
}), /* @__PURE__ */
|
|
130
|
+
children: $ || L
|
|
131
|
+
}), /* @__PURE__ */ f("span", {
|
|
127
132
|
className: e.icon,
|
|
128
133
|
"aria-hidden": "true",
|
|
129
134
|
children: "📅"
|
|
130
135
|
})]
|
|
131
|
-
}),
|
|
136
|
+
}), ae && U.value !== void 0 && /* @__PURE__ */ f("button", {
|
|
132
137
|
type: "button",
|
|
133
138
|
className: e.clear,
|
|
134
|
-
"aria-label":
|
|
135
|
-
onClick:
|
|
139
|
+
"aria-label": B,
|
|
140
|
+
onClick: ue,
|
|
136
141
|
children: "✕"
|
|
137
142
|
})]
|
|
138
143
|
}),
|
|
139
|
-
/* @__PURE__ */
|
|
140
|
-
id:
|
|
144
|
+
/* @__PURE__ */ p("div", {
|
|
145
|
+
id: F,
|
|
141
146
|
role: "dialog",
|
|
142
147
|
"aria-label": Q,
|
|
143
148
|
className: e.calendar,
|
|
144
|
-
"data-state":
|
|
145
|
-
onKeyDown:
|
|
146
|
-
children: [/* @__PURE__ */
|
|
149
|
+
"data-state": j.value,
|
|
150
|
+
onKeyDown: ge,
|
|
151
|
+
children: [/* @__PURE__ */ p("div", {
|
|
147
152
|
className: e.header,
|
|
148
153
|
children: [
|
|
149
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ f("button", {
|
|
150
155
|
type: "button",
|
|
151
156
|
className: e.navButton,
|
|
152
|
-
"aria-label":
|
|
153
|
-
onClick:
|
|
157
|
+
"aria-label": R,
|
|
158
|
+
onClick: de,
|
|
154
159
|
children: "‹"
|
|
155
160
|
}),
|
|
156
|
-
/* @__PURE__ */
|
|
161
|
+
/* @__PURE__ */ f("span", {
|
|
157
162
|
className: e.monthLabel,
|
|
158
163
|
"aria-live": "polite",
|
|
159
164
|
children: Q
|
|
160
165
|
}),
|
|
161
|
-
/* @__PURE__ */
|
|
166
|
+
/* @__PURE__ */ f("button", {
|
|
162
167
|
type: "button",
|
|
163
168
|
className: e.navButton,
|
|
164
|
-
"aria-label":
|
|
165
|
-
onClick:
|
|
169
|
+
"aria-label": z,
|
|
170
|
+
onClick: fe,
|
|
166
171
|
children: "›"
|
|
167
172
|
})
|
|
168
173
|
]
|
|
169
|
-
}), /* @__PURE__ */
|
|
174
|
+
}), /* @__PURE__ */ p("table", {
|
|
170
175
|
role: "grid",
|
|
171
176
|
className: e.grid,
|
|
172
|
-
children: [/* @__PURE__ */
|
|
177
|
+
children: [/* @__PURE__ */ f("thead", { children: /* @__PURE__ */ f("tr", { children: he.map((t) => /* @__PURE__ */ f("th", {
|
|
173
178
|
className: e.weekday,
|
|
174
179
|
abbr: t,
|
|
175
180
|
scope: "col",
|
|
176
181
|
children: t
|
|
177
|
-
}, t)) }) }), /* @__PURE__ */
|
|
178
|
-
if (!t) return /* @__PURE__ */
|
|
179
|
-
let r =
|
|
180
|
-
return /* @__PURE__ */
|
|
182
|
+
}, t)) }) }), /* @__PURE__ */ f("tbody", { children: pe.map((t, n) => /* @__PURE__ */ f("tr", { children: t.map((t, n) => {
|
|
183
|
+
if (!t) return /* @__PURE__ */ f("td", { className: e.empty }, n);
|
|
184
|
+
let r = g(t), i = r === U.value, a = r === H, o = r === K.value, s = b !== void 0 && r < b || x !== void 0 && r > x;
|
|
185
|
+
return /* @__PURE__ */ f("td", {
|
|
181
186
|
className: e.cell,
|
|
182
|
-
children: /* @__PURE__ */
|
|
187
|
+
children: /* @__PURE__ */ f("button", {
|
|
183
188
|
type: "button",
|
|
184
189
|
className: e.day,
|
|
185
190
|
tabIndex: o ? 0 : -1,
|
|
186
191
|
"aria-pressed": i,
|
|
187
|
-
"aria-label":
|
|
192
|
+
"aria-label": h(t, I),
|
|
188
193
|
"aria-current": a ? "date" : void 0,
|
|
189
194
|
"aria-disabled": s || void 0,
|
|
190
195
|
"data-selected": i || void 0,
|
|
@@ -193,7 +198,7 @@ function b({ value: a, defaultValue: b, onValueChange: ne, onChange: x, min: S,
|
|
|
193
198
|
s || X(r);
|
|
194
199
|
},
|
|
195
200
|
onFocus: () => {
|
|
196
|
-
|
|
201
|
+
K.value = r;
|
|
197
202
|
},
|
|
198
203
|
children: t.getUTCDate()
|
|
199
204
|
})
|
|
@@ -201,19 +206,19 @@ function b({ value: a, defaultValue: b, onValueChange: ne, onChange: x, min: S,
|
|
|
201
206
|
}) }, n)) })]
|
|
202
207
|
})]
|
|
203
208
|
}),
|
|
204
|
-
|
|
205
|
-
id: `${
|
|
209
|
+
w && /* @__PURE__ */ f("span", {
|
|
210
|
+
id: `${N}-error`,
|
|
206
211
|
className: e.error,
|
|
207
212
|
role: "alert",
|
|
208
|
-
children:
|
|
213
|
+
children: w
|
|
209
214
|
}),
|
|
210
|
-
!
|
|
211
|
-
id: `${
|
|
215
|
+
!w && C && /* @__PURE__ */ f("span", {
|
|
216
|
+
id: `${N}-hint`,
|
|
212
217
|
className: e.hint,
|
|
213
|
-
children:
|
|
218
|
+
children: C
|
|
214
219
|
})
|
|
215
220
|
]
|
|
216
221
|
});
|
|
217
222
|
}
|
|
218
223
|
//#endregion
|
|
219
|
-
export {
|
|
224
|
+
export { v as DatePicker };
|
|
@@ -137,7 +137,7 @@ function g({ value: g, defaultValue: _, onValueChange: v, min: y, max: b, disabl
|
|
|
137
137
|
className: t.preset,
|
|
138
138
|
onClick: () => W(e),
|
|
139
139
|
children: e.label
|
|
140
|
-
}, e.label))
|
|
140
|
+
}, e.id ?? e.label))
|
|
141
141
|
}),
|
|
142
142
|
/* @__PURE__ */ f("div", {
|
|
143
143
|
className: t.calendars,
|
package/dist/node/dock/dock.js
CHANGED
|
@@ -5,9 +5,9 @@ import { getLinkComponent as t, useSignals as n } from "@cascivo/core";
|
|
|
5
5
|
import { builtin as r, t as i } from "@cascivo/i18n";
|
|
6
6
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
7
|
//#region ../components/src/dock/dock.tsx
|
|
8
|
-
function s({ items: s, activeIndex: c, className: l, ariaLabel: u }) {
|
|
8
|
+
function s({ items: s, activeIndex: c, className: l, ariaLabel: u, label: d }) {
|
|
9
9
|
return n(), /* @__PURE__ */ a("nav", {
|
|
10
|
-
"aria-label": u ?? i(r.dock.nav),
|
|
10
|
+
"aria-label": u ?? d ?? i(r.dock.nav),
|
|
11
11
|
className: [e.dock, l].filter(Boolean).join(" "),
|
|
12
12
|
children: s.map((n, r) => {
|
|
13
13
|
let i = r === c;
|
|
@@ -12,96 +12,99 @@ var p = i({
|
|
|
12
12
|
open: { on: { CLOSE: "closed" } }
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
function m(
|
|
15
|
+
function m(e) {
|
|
16
|
+
return !("kind" in e);
|
|
17
|
+
}
|
|
18
|
+
function h({ trigger: i, items: h, onSelect: g, placement: _ = "bottom-start", open: v, onOpenChange: y }) {
|
|
16
19
|
u();
|
|
17
|
-
let [
|
|
20
|
+
let [b, x] = s(p), S = n(null), C = n(null), w = n(null), T = n([]), E = c(-1), D = v !== void 0, O = D ? v : b.value === "open", k = o(O), A = h.map((e, t) => ({
|
|
18
21
|
item: e,
|
|
19
22
|
index: t
|
|
20
|
-
})).filter(({ item: e }) =>
|
|
21
|
-
|
|
23
|
+
})).filter(({ item: e }) => m(e) && !e.disabled).map(({ index: e }) => e), j = (e) => {
|
|
24
|
+
D || x(e ? "OPEN" : "CLOSE"), y?.(e);
|
|
22
25
|
};
|
|
23
26
|
l(() => {
|
|
24
|
-
let e =
|
|
25
|
-
|
|
27
|
+
let e = E.value;
|
|
28
|
+
k.value && e >= 0 && T.current[e]?.focus();
|
|
26
29
|
}), l(() => {
|
|
27
|
-
|
|
30
|
+
k.value ? E.value = A[0] ?? -1 : E.value = -1;
|
|
28
31
|
}), l(() => {
|
|
29
|
-
|
|
32
|
+
k.value ? w.current?.showPopover() : w.current?.hidePopover();
|
|
30
33
|
}), l(() => {
|
|
31
|
-
let e =
|
|
34
|
+
let e = w.current;
|
|
32
35
|
if (!e) return;
|
|
33
36
|
let t = (e) => {
|
|
34
|
-
e.newState === "closed" &&
|
|
37
|
+
e.newState === "closed" && j(!1);
|
|
35
38
|
};
|
|
36
39
|
return e.addEventListener("toggle", t), () => e.removeEventListener("toggle", t);
|
|
37
40
|
});
|
|
38
|
-
let
|
|
39
|
-
let t =
|
|
40
|
-
!t || t
|
|
41
|
-
}, M = (e) => {
|
|
42
|
-
k.length !== 0 && (T.value = k[(k.indexOf(T.value) + e + k.length) % k.length] ?? -1);
|
|
41
|
+
let M = (e) => {
|
|
42
|
+
let t = h[e];
|
|
43
|
+
!t || !m(t) || t.disabled || (g?.(t.value), j(!1), a(C.current));
|
|
43
44
|
}, N = (e) => {
|
|
45
|
+
A.length !== 0 && (E.value = A[(A.indexOf(E.value) + e + A.length) % A.length] ?? -1);
|
|
46
|
+
}, P = (e) => {
|
|
44
47
|
switch (e.key) {
|
|
45
48
|
case "ArrowDown":
|
|
46
|
-
e.preventDefault(),
|
|
49
|
+
e.preventDefault(), N(1);
|
|
47
50
|
break;
|
|
48
51
|
case "ArrowUp":
|
|
49
|
-
e.preventDefault(),
|
|
52
|
+
e.preventDefault(), N(-1);
|
|
50
53
|
break;
|
|
51
54
|
case "Home":
|
|
52
|
-
e.preventDefault(),
|
|
55
|
+
e.preventDefault(), E.value = A[0] ?? -1;
|
|
53
56
|
break;
|
|
54
57
|
case "End":
|
|
55
|
-
e.preventDefault(),
|
|
58
|
+
e.preventDefault(), E.value = A[A.length - 1] ?? -1;
|
|
56
59
|
break;
|
|
57
60
|
case "Escape":
|
|
58
|
-
e.preventDefault(),
|
|
61
|
+
e.preventDefault(), j(!1), a(C.current);
|
|
59
62
|
break;
|
|
60
63
|
case "Enter":
|
|
61
64
|
case " ":
|
|
62
|
-
e.preventDefault(),
|
|
65
|
+
e.preventDefault(), M(E.value);
|
|
63
66
|
break;
|
|
64
67
|
}
|
|
65
|
-
},
|
|
66
|
-
ref: r(
|
|
68
|
+
}, F = i, I = t(F, {
|
|
69
|
+
ref: r(C, F.props.ref),
|
|
67
70
|
onClick: (e) => {
|
|
68
|
-
|
|
71
|
+
F.props.onClick?.(e), j(!O);
|
|
69
72
|
},
|
|
70
73
|
"aria-haspopup": "menu",
|
|
71
|
-
"aria-expanded":
|
|
74
|
+
"aria-expanded": O
|
|
72
75
|
});
|
|
73
76
|
return /* @__PURE__ */ f("div", {
|
|
74
|
-
ref:
|
|
77
|
+
ref: S,
|
|
75
78
|
className: e.root,
|
|
76
|
-
children: [
|
|
77
|
-
ref:
|
|
79
|
+
children: [I, /* @__PURE__ */ d("div", {
|
|
80
|
+
ref: w,
|
|
78
81
|
popover: "auto",
|
|
79
82
|
role: "menu",
|
|
80
|
-
"data-placement":
|
|
81
|
-
"data-state":
|
|
83
|
+
"data-placement": _,
|
|
84
|
+
"data-state": O ? "open" : "closed",
|
|
82
85
|
className: e.menu,
|
|
83
|
-
onKeyDown:
|
|
84
|
-
children:
|
|
85
|
-
role: "separator",
|
|
86
|
-
className: e.separator
|
|
87
|
-
}, `sep-${n}`) : /* @__PURE__ */ f("button", {
|
|
86
|
+
onKeyDown: P,
|
|
87
|
+
children: h.map((t, n) => m(t) ? /* @__PURE__ */ f("button", {
|
|
88
88
|
type: "button",
|
|
89
89
|
role: "menuitem",
|
|
90
90
|
ref: (e) => {
|
|
91
|
-
|
|
91
|
+
T.current[n] = e;
|
|
92
92
|
},
|
|
93
|
-
tabIndex:
|
|
93
|
+
tabIndex: E.value === n ? 0 : -1,
|
|
94
94
|
disabled: t.disabled,
|
|
95
95
|
className: e.item,
|
|
96
|
-
onClick: () =>
|
|
96
|
+
onClick: () => M(n),
|
|
97
97
|
children: [t.icon && /* @__PURE__ */ d("span", {
|
|
98
98
|
className: e.icon,
|
|
99
99
|
"aria-hidden": "true",
|
|
100
100
|
children: t.icon
|
|
101
101
|
}), t.label]
|
|
102
|
-
}, t.value)
|
|
102
|
+
}, t.value) : /* @__PURE__ */ d("div", {
|
|
103
|
+
role: "separator",
|
|
104
|
+
className: e.separator
|
|
105
|
+
}, `sep-${n}`))
|
|
103
106
|
})]
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
//#endregion
|
|
107
|
-
export {
|
|
110
|
+
export { h as Dropdown };
|
|
@@ -5,50 +5,59 @@ import { useRef as t } from "react";
|
|
|
5
5
|
import { cn as n, useSignal as r, useSignalEffect as i, useSignals as a } from "@cascivo/core";
|
|
6
6
|
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
7
|
//#region ../components/src/editable/editable.tsx
|
|
8
|
-
function c({ value: c, onValueChange: l, placeholder: u, disabled: d = !1, submitOnBlur: f = !0, onCancel: p, className: m,
|
|
8
|
+
function c({ value: c, onValueChange: l, placeholder: u, disabled: d = !1, submitOnBlur: f = !0, onCancel: p, className: m, id: h, "aria-labelledby": g, "aria-describedby": _, "aria-invalid": v, ...y }) {
|
|
9
9
|
a();
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
let b = r(!1), x = r(c), S = t(null), C = t(p);
|
|
11
|
+
C.current = p;
|
|
12
|
+
let w = t(l);
|
|
13
|
+
w.current = l;
|
|
14
|
+
let T = {
|
|
15
|
+
id: h,
|
|
16
|
+
"aria-labelledby": g,
|
|
17
|
+
"aria-describedby": _,
|
|
18
|
+
"aria-invalid": v
|
|
19
|
+
};
|
|
20
|
+
b.value || (x.value = c), i(() => {
|
|
21
|
+
if (b.value) {
|
|
22
|
+
let e = S.current;
|
|
16
23
|
e && (e.focus(), e.select());
|
|
17
24
|
}
|
|
18
25
|
});
|
|
19
|
-
function
|
|
20
|
-
|
|
26
|
+
function E() {
|
|
27
|
+
w.current(x.value), b.value = !1;
|
|
21
28
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
29
|
+
function D() {
|
|
30
|
+
x.value = c, b.value = !1, C.current?.();
|
|
24
31
|
}
|
|
25
|
-
return
|
|
32
|
+
return b.value ? /* @__PURE__ */ o("div", {
|
|
26
33
|
className: n(e.wrapper, e.editing, m),
|
|
27
|
-
...
|
|
34
|
+
...y,
|
|
28
35
|
children: /* @__PURE__ */ o("input", {
|
|
29
|
-
ref:
|
|
36
|
+
ref: S,
|
|
30
37
|
className: e.input,
|
|
31
|
-
|
|
38
|
+
...T,
|
|
39
|
+
value: x.value,
|
|
32
40
|
onChange: (e) => {
|
|
33
|
-
|
|
41
|
+
x.value = e.currentTarget.value;
|
|
34
42
|
},
|
|
35
43
|
onKeyDown: (e) => {
|
|
36
|
-
e.key === "Enter" ? (e.preventDefault(),
|
|
44
|
+
e.key === "Enter" ? (e.preventDefault(), E()) : e.key === "Escape" && (e.preventDefault(), D());
|
|
37
45
|
},
|
|
38
46
|
onBlur: () => {
|
|
39
|
-
f ?
|
|
47
|
+
f ? E() : D();
|
|
40
48
|
}
|
|
41
49
|
})
|
|
42
50
|
}) : /* @__PURE__ */ o("div", {
|
|
43
51
|
className: n(e.wrapper, m),
|
|
44
52
|
"data-disabled": d ? "" : void 0,
|
|
45
|
-
...
|
|
53
|
+
...y,
|
|
46
54
|
children: /* @__PURE__ */ s("button", {
|
|
47
55
|
type: "button",
|
|
48
56
|
className: e.preview,
|
|
57
|
+
...T,
|
|
49
58
|
disabled: d,
|
|
50
59
|
onClick: () => {
|
|
51
|
-
d || (
|
|
60
|
+
d || (b.value = !0);
|
|
52
61
|
},
|
|
53
62
|
children: [/* @__PURE__ */ o("span", {
|
|
54
63
|
className: e["preview-text"],
|