jaguar-form 1.0.4 → 1.0.6
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 +38 -2
- package/dist/Cascader-ZIkXvvC3.js +226 -0
- package/dist/Select-BIBk_TT6.js +415 -0
- package/dist/TreeSelect-BQCyCCqa.js +350 -0
- package/dist/{compound-D4_6P0d_.js → compound-BX_PoTK5.js} +100 -88
- package/dist/compound.js +1 -1
- package/dist/core.js +1 -1
- package/dist/date-time.js +1 -1
- package/dist/demo-plant.svg +1 -0
- package/dist/form-CSfUExUT.js +599 -0
- package/dist/form.js +3 -3
- package/dist/{icons-BI3fdIey.js → icons-BwE05e0C.js} +1 -1
- package/dist/{image-upload-VtUlQgzJ.js → image-upload-D9oPG0Eh.js} +252 -179
- package/dist/image-upload.js +1 -1
- package/dist/index.js +15 -14
- package/dist/input.js +1 -1
- package/dist/inputs-Dx3xOy9q.js +718 -0
- package/dist/{useSelection-C0OEFZUE.js → lazy-tree-NCX3ntYm.js} +96 -4
- package/dist/locale/load.js +7 -3
- package/dist/pickers-Bci1y8cc.js +634 -0
- package/dist/select.js +3 -1
- package/dist/selection-DCIzhR5q.js +197 -0
- package/dist/{slider-CNwkLMmo.js → slider-AM0Egz9P.js} +1 -1
- package/dist/slider.js +1 -1
- package/dist/store-CFSQW-Fv.js +622 -0
- package/dist/style.css +1 -1
- package/dist/tree-select.js +1 -1
- package/dist/types/components/compound/ControlGroup.d.ts +5 -2
- package/dist/types/components/compound/index.d.ts +10 -1
- package/dist/types/components/extended-inputs.d.ts +34 -0
- package/dist/types/components/image-upload/ManagedImageUpload.d.ts +11 -4
- package/dist/types/components/image-upload/index.d.ts +3 -2
- package/dist/types/components/image-upload/upload.d.ts +1 -1
- package/dist/types/components/image-upload/usePreparation.d.ts +7 -0
- package/dist/types/components/image-upload/validation.d.ts +16 -0
- package/dist/types/components/inputs.d.ts +42 -4
- package/dist/types/components/select/Cascader.d.ts +13 -0
- package/dist/types/components/select/types.d.ts +10 -1
- package/dist/types/components/select/useRemoteOptions.d.ts +18 -0
- package/dist/types/components/select.d.ts +3 -0
- package/dist/types/config/index.d.ts +3 -0
- package/dist/types/entries/input.d.ts +5 -2
- package/dist/types/entries/select.d.ts +3 -0
- package/dist/types/form/adapter.d.ts +1 -0
- package/dist/types/form/index.d.ts +85 -10
- package/dist/types/form/store.d.ts +21 -1
- package/dist/types/locale/load.d.ts +2 -1
- package/dist/types/primitives/Control.d.ts +3 -1
- package/dist/types/primitives/Popup.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/utils/cascader.d.ts +12 -0
- package/dist/types/utils/decimal.d.ts +22 -0
- package/dist/types/utils/remote-options.d.ts +24 -0
- package/dist/useControllable-QDX_UWRh.js +102 -0
- package/package.json +1 -1
- package/dist/Control-B36bu6zQ.js +0 -47
- package/dist/Select-BG2H-YnK.js +0 -252
- package/dist/TreeSelect-CkPtMg-g.js +0 -440
- package/dist/form-DTI0Sqsy.js +0 -413
- package/dist/inputs-BOP8Ryne.js +0 -403
- package/dist/pickers-C9QTR2XN.js +0 -631
- package/dist/selection-CIEa1uce.js +0 -146
- package/dist/store-DOn9K-EA.js +0 -491
- package/dist/useControllable-Zax42z2F.js +0 -87
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { useId as e, useLayoutEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
|
+
import a from "dayjs";
|
|
3
|
+
import { i as o } from "./locale-yHkdw2xz.js";
|
|
4
|
+
import { a as s, t as c } from "./useControllable-QDX_UWRh.js";
|
|
5
|
+
import { n as l, o as u, r as d, s as f } from "./selection-DCIzhR5q.js";
|
|
6
|
+
import { t as p } from "./icons-BwE05e0C.js";
|
|
7
|
+
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
8
|
+
// src/utils/date.ts
|
|
9
|
+
var _ = (e) => String(e).padStart(2, "0");
|
|
10
|
+
function v(e) {
|
|
11
|
+
return `${String(e.getFullYear()).padStart(4, "0")}-${_(e.getMonth() + 1)}-${_(e.getDate())}`;
|
|
12
|
+
}
|
|
13
|
+
function y(e) {
|
|
14
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(e)) return null;
|
|
15
|
+
let [t, n, r] = e.split("-").map(Number), i = new Date(2e3, 0, 1, 12);
|
|
16
|
+
return i.setFullYear(t, n - 1, r), v(i) === e ? i : null;
|
|
17
|
+
}
|
|
18
|
+
function b(e, t, n = 1) {
|
|
19
|
+
let r = new Date(2e3, 0, 1, 12);
|
|
20
|
+
r.setFullYear(e, t, 1);
|
|
21
|
+
let i = (r.getDay() - n + 7) % 7;
|
|
22
|
+
return Array.from({ length: 42 }, (e, n) => {
|
|
23
|
+
let a = new Date(r);
|
|
24
|
+
return a.setDate(n - i + 1), {
|
|
25
|
+
value: v(a),
|
|
26
|
+
day: a.getDate(),
|
|
27
|
+
current: a.getMonth() === t
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function x(e) {
|
|
32
|
+
if (!/^\d{2}:\d{2}(:\d{2})?$/.test(e)) return null;
|
|
33
|
+
let [t, n, r = 0] = e.split(":").map(Number);
|
|
34
|
+
return t < 24 && n < 60 && r < 60 ? t * 3600 + n * 60 + r : null;
|
|
35
|
+
}
|
|
36
|
+
function S(e, t, n = !1) {
|
|
37
|
+
let r = x(e), i = x(t);
|
|
38
|
+
return r === null || i === null || !n && i < r ? null : i < r ? 86400 + i - r : i - r;
|
|
39
|
+
}
|
|
40
|
+
function ee(e, t) {
|
|
41
|
+
return e <= t ? [e, t] : [t, e];
|
|
42
|
+
}
|
|
43
|
+
function C(e, t, n) {
|
|
44
|
+
return y(e.length === 4 ? `${e}-01-01` : e.length === 7 ? `${e}-01` : e) ? (!t || e >= t.slice(0, e.length)) && (!n || e <= n.slice(0, e.length)) : !1;
|
|
45
|
+
}
|
|
46
|
+
function w(e, t) {
|
|
47
|
+
let n = y(e), r = y(t);
|
|
48
|
+
if (!n || !r) return NaN;
|
|
49
|
+
let i = (e) => {
|
|
50
|
+
let t = /* @__PURE__ */ new Date(0);
|
|
51
|
+
return t.setUTCFullYear(e.getFullYear(), e.getMonth(), e.getDate()), t.getTime();
|
|
52
|
+
};
|
|
53
|
+
return (i(r) - i(n)) / 864e5;
|
|
54
|
+
}
|
|
55
|
+
function T(e, t, n) {
|
|
56
|
+
let r = (e) => Number.isFinite(e) ? Math.max(1, Math.floor(e)) : 1, i = x(e.minTime ?? "00:00") ?? 0, a = x(e.maxTime ?? "23:59:59") ?? 86399, o = t.split(":").map(Number), s = [
|
|
57
|
+
r(e.hourStep),
|
|
58
|
+
r(e.minuteStep),
|
|
59
|
+
r(e.secondStep)
|
|
60
|
+
], c = [
|
|
61
|
+
24,
|
|
62
|
+
60,
|
|
63
|
+
e.showSeconds === !1 ? 1 : 60
|
|
64
|
+
], l = /* @__PURE__ */ new Map(), u = (t, n, r) => `${_(t)}:${_(n)}${e.showSeconds === !1 ? "" : `:${_(r)}`}`;
|
|
65
|
+
for (let e = 0; e < 24; e += s[0]) if (!(n > 0 && e !== o[0])) for (let t = 0; t < 60; t += s[1]) {
|
|
66
|
+
if (n > 1 && t !== o[1]) continue;
|
|
67
|
+
let r = e * 3600 + t * 60, d = Math.max(0, Math.ceil((i - r) / s[2]) * s[2]), f = Math.min(c[2] - 1, a - r);
|
|
68
|
+
if (!(d > f)) {
|
|
69
|
+
if (n === 2) for (let n = d; n <= f; n += s[2]) l.set(_(n), u(e, t, n));
|
|
70
|
+
else {
|
|
71
|
+
let r = _(n === 0 ? e : t), i = o[2] ?? 0, a = (n === 1 || t === o[1]) && i >= d && i <= f && i % s[2] === 0;
|
|
72
|
+
(a || !l.has(r)) && l.set(r, u(e, t, a ? i : d));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return l;
|
|
77
|
+
}
|
|
78
|
+
function E(e, t, n) {
|
|
79
|
+
let r = y(e), i = y(t);
|
|
80
|
+
if (!r || !i || r > i) return !0;
|
|
81
|
+
for (; r <= i;) {
|
|
82
|
+
if (n(v(r))) return !0;
|
|
83
|
+
r.setDate(r.getDate() + 1);
|
|
84
|
+
}
|
|
85
|
+
return !1;
|
|
86
|
+
}
|
|
87
|
+
// src/utils/picker-validation.ts
|
|
88
|
+
var D = (e) => Number.isFinite(e) ? Math.max(1, Math.floor(e)) : 1;
|
|
89
|
+
function O(e, t) {
|
|
90
|
+
let n = x(e);
|
|
91
|
+
if (n === null) return !1;
|
|
92
|
+
let [r, i, a = 0] = e.split(":").map(Number), o = x(t.minTime ?? "00:00") ?? 0, s = x(t.maxTime ?? "23:59:59") ?? 86399;
|
|
93
|
+
return n >= o && n <= s && r % D(t.hourStep) === 0 && i % D(t.minuteStep) === 0 && a % D(t.secondStep) === 0 && (t.showSeconds !== !1 || a === 0);
|
|
94
|
+
}
|
|
95
|
+
function k(e, t) {
|
|
96
|
+
let n = x(e) ?? 0;
|
|
97
|
+
if (O(e, t)) return t.showSeconds === !1 ? e.slice(0, 5) : e.length === 5 ? `${e}:00` : e;
|
|
98
|
+
let r = e, i = t.showSeconds === !1 ? 2 : 3;
|
|
99
|
+
for (let e = 0; e < i; e++) {
|
|
100
|
+
let i = [...T(t, r, e).values()];
|
|
101
|
+
if (!i.length) return null;
|
|
102
|
+
r = i.reduce((e, t) => Math.abs((x(t) ?? 0) - n) < Math.abs((x(e) ?? 0) - n) ? t : e);
|
|
103
|
+
}
|
|
104
|
+
return r;
|
|
105
|
+
}
|
|
106
|
+
function A(e, t, n, r) {
|
|
107
|
+
if (e.length !== (n ? 2 : 1) || e.some((e) => typeof e != "string")) return !1;
|
|
108
|
+
if (t === "month" || t === "year") return e.some((e) => e.length !== (t === "month" ? 7 : 4) || !C(e, r.minDate, r.maxDate)) ? !1 : !n || e[0] <= e[1];
|
|
109
|
+
if (t === "date" || t === "datetime") {
|
|
110
|
+
if (e.some((e) => {
|
|
111
|
+
let n = e.slice(0, 10);
|
|
112
|
+
return t === "date" && e.length !== 10 || t === "datetime" && !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2})?$/.test(e) || !y(n) || !!(r.minDate && n < r.minDate || r.maxDate && n > r.maxDate || r.disabledDate?.(n));
|
|
113
|
+
})) return !1;
|
|
114
|
+
if (n) {
|
|
115
|
+
let t = e[0].slice(0, 10), n = e[1].slice(0, 10), i = w(t, n);
|
|
116
|
+
if (!Number.isFinite(i) || i < (r.minRange ?? 0) || i > (r.maxRange ?? 1e400) || r.allowDisabledInRange === !1 && r.disabledDate && (i > 36600 || E(t, n, r.disabledDate))) return !1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (t === "time" || t === "datetime") {
|
|
120
|
+
let i = e.map((e) => t === "datetime" ? e.split("T")[1] : e);
|
|
121
|
+
if (i.some((e) => !O(e, r))) return !1;
|
|
122
|
+
if (n) {
|
|
123
|
+
let n = t === "time" ? S(i[0], i[1], r.allowOvernight) : w(e[0].slice(0, 10), e[1].slice(0, 10)) * 86400 + x(i[1]) - x(i[0]);
|
|
124
|
+
if (n === null || !Number.isFinite(n) || n < (r.minDuration ?? 0) || n > (r.maxDuration ?? 1e400)) return !1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return !0;
|
|
128
|
+
}
|
|
129
|
+
// src/components/date-time/CalendarPanel.tsx
|
|
130
|
+
var j = (e, t, n = 1) => {
|
|
131
|
+
let r = new Date(2e3, 0, 1, 12);
|
|
132
|
+
return r.setFullYear(e, t, n), r;
|
|
133
|
+
};
|
|
134
|
+
function M({ value: e, kind: n, onSelect: a, start: o, end: c, p: l, hover: d, onHover: f, offset: p = 0, monthCursor: m, onMonthCursor: x }) {
|
|
135
|
+
let S = s(), { text: w, direction: T } = S, E = y(n === "month" ? `${e}-01` : n === "year" ? `${e}-01-01` : e.slice(0, 10)) ?? /* @__PURE__ */ new Date(), [D, O] = i(E.getFullYear() * 12 + E.getMonth() + p), k = m === void 0 ? D : m + p, A = Math.floor(k / 12), M = (k % 12 + 12) % 12, N = (e) => {
|
|
136
|
+
let t = Math.max(12, Math.min(119999, e));
|
|
137
|
+
x ? x(t - p) : O(t);
|
|
138
|
+
}, [P, F] = i(n === "year" ? "year" : n === "month" ? "month" : "date"), [I, L] = i(), R = r(null), z = r(null), B = (e) => N(k + e * (P === "year" ? 144 : P === "month" ? 12 : 1)), te = l.firstDayOfWeek ?? S.firstDayOfWeek ?? 1, V = (e) => !!(l.minDate && e < l.minDate || l.maxDate && e > l.maxDate || l.disabledDate?.(e) || l.disabled || l.readOnly), H = new Intl.DateTimeFormat(S.code, {
|
|
139
|
+
month: "long",
|
|
140
|
+
year: "numeric",
|
|
141
|
+
calendar: "gregory"
|
|
142
|
+
}).format(j(A, M)), U = b(A, M, te), W = v(/* @__PURE__ */ new Date()), G = Array.from({ length: 7 }, (e, t) => new Intl.DateTimeFormat(S.code, { weekday: "short" }).format(new Date(2024, 0, 7 + (t + te) % 7))), K = c ?? d, q = o && K ? ee(o, K) : null, ne = (e, t) => {
|
|
143
|
+
P === "year" ? n === "year" ? a(e) : (N(Number(e) * 12 + M), F("month")) : n === "month" ? a(e) : (N(A * 12 + t), F("date"));
|
|
144
|
+
}, re = Array.from({ length: 12 }, (e, t) => P === "month" ? `${String(A).padStart(4, "0")}-${_(t + 1)}` : String(A - 5 + t).padStart(4, "0")), J = (e) => !!(l.disabled || l.readOnly || !C(e, n === P ? l.minDate : void 0, n === P ? l.maxDate : void 0)), Y = P === "date" ? U.filter((e) => (m === void 0 || e.current) && !V(e.value)).map((e) => e.value) : re.filter((e) => !J(e)), X = I && Y.includes(I) ? I : Y.includes(e.slice(0, P === "date" ? 10 : P === "month" ? 7 : 4)) ? e.slice(0, P === "date" ? 10 : P === "month" ? 7 : 4) : Y.includes(W) ? W : Y[0], Z = (e) => {
|
|
145
|
+
L(e);
|
|
146
|
+
let t = [...R.current?.querySelectorAll("[data-picker-key]") ?? []].find((t) => t.dataset.pickerKey === e && !t.disabled);
|
|
147
|
+
return t ? (t.focus({ preventScroll: !0 }), !0) : !1;
|
|
148
|
+
};
|
|
149
|
+
t(() => {
|
|
150
|
+
let e = z.current;
|
|
151
|
+
e && (z.current = null, Z(Y.includes(e) ? e : X ?? ""));
|
|
152
|
+
}, [k, P]);
|
|
153
|
+
let Q = (e) => {
|
|
154
|
+
let t = e.target;
|
|
155
|
+
if (!(t instanceof HTMLButtonElement) || !t.dataset.pickerKey) return;
|
|
156
|
+
let n = e.key, r = T === "rtl" ? -1 : 1, i = P === "date" ? 7 : 3, a = P === "date" ? U.map((e) => e.value) : re, o = a.indexOf(t.dataset.pickerKey);
|
|
157
|
+
if (o < 0) return;
|
|
158
|
+
let s = n === "ArrowLeft" ? -r : n === "ArrowRight" ? r : n === "ArrowUp" ? -i : n === "ArrowDown" ? i : 0;
|
|
159
|
+
if (n === "PageUp" || n === "PageDown") {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
let r = n === "PageUp" ? -1 : 1;
|
|
162
|
+
if (P === "date") {
|
|
163
|
+
let n = y(t.dataset.pickerKey), i = j(n.getFullYear(), n.getMonth() + r * (e.shiftKey ? 12 : 1), 1), a = j(i.getFullYear(), i.getMonth() + 1, 0).getDate();
|
|
164
|
+
z.current = v(j(i.getFullYear(), i.getMonth(), Math.min(n.getDate(), a))), N(i.getFullYear() * 12 + i.getMonth());
|
|
165
|
+
} else z.current = t.dataset.pickerKey, B(r);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (!s && !["Home", "End"].includes(n)) return;
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
let c = n === "Home" ? o - o % i : n === "End" ? Math.min(a.length - 1, o - o % i + i - 1) : o + s, l = s < 0 || n === "End" ? -1 : 1;
|
|
171
|
+
for (; c >= 0 && c < a.length;) {
|
|
172
|
+
if (Y.includes(a[c]) && Z(a[c])) return;
|
|
173
|
+
c += l;
|
|
174
|
+
}
|
|
175
|
+
if (P === "date" && s) {
|
|
176
|
+
let e = y(t.dataset.pickerKey);
|
|
177
|
+
e.setDate(e.getDate() + s), z.current = v(e), N(e.getFullYear() * 12 + e.getMonth());
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return /* @__PURE__ */ g("div", {
|
|
181
|
+
className: "rfe-calendar",
|
|
182
|
+
role: "group",
|
|
183
|
+
"aria-label": H,
|
|
184
|
+
children: [/* @__PURE__ */ g("div", {
|
|
185
|
+
className: "rfe-calendar-header",
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ h(u, {
|
|
188
|
+
name: "previous",
|
|
189
|
+
source: l.icons?.previous,
|
|
190
|
+
label: w.previous,
|
|
191
|
+
onClick: () => B(-1)
|
|
192
|
+
}),
|
|
193
|
+
/* @__PURE__ */ h("button", {
|
|
194
|
+
type: "button",
|
|
195
|
+
className: "rfe-calendar-title",
|
|
196
|
+
onClick: () => {
|
|
197
|
+
L(void 0), F(P === "date" ? "month" : P === "month" ? "year" : "date");
|
|
198
|
+
},
|
|
199
|
+
children: P === "date" ? H : P === "month" ? A : `${A - 5} – ${A + 6}`
|
|
200
|
+
}),
|
|
201
|
+
/* @__PURE__ */ h(u, {
|
|
202
|
+
name: "next",
|
|
203
|
+
source: l.icons?.next,
|
|
204
|
+
label: w.next,
|
|
205
|
+
onClick: () => B(1)
|
|
206
|
+
})
|
|
207
|
+
]
|
|
208
|
+
}), P === "date" ? /* @__PURE__ */ g("div", {
|
|
209
|
+
className: "rfe-calendar-grid",
|
|
210
|
+
ref: R,
|
|
211
|
+
onKeyDown: Q,
|
|
212
|
+
children: [G.map((e, t) => /* @__PURE__ */ h("span", {
|
|
213
|
+
className: "rfe-weekday",
|
|
214
|
+
children: e
|
|
215
|
+
}, t)), U.map((t) => {
|
|
216
|
+
let n = t.value === e.slice(0, 10) || t.value === o || t.value === c, r = m !== void 0 && !t.current;
|
|
217
|
+
return /* @__PURE__ */ h("button", {
|
|
218
|
+
type: "button",
|
|
219
|
+
className: "rfe-day",
|
|
220
|
+
tabIndex: !r && X === t.value ? 0 : -1,
|
|
221
|
+
"data-picker-key": t.value,
|
|
222
|
+
"aria-label": t.value,
|
|
223
|
+
"aria-pressed": n,
|
|
224
|
+
"aria-current": t.value === W ? "date" : void 0,
|
|
225
|
+
"data-outside": !t.current || void 0,
|
|
226
|
+
style: r ? { visibility: "hidden" } : void 0,
|
|
227
|
+
"data-today": t.value === W || void 0,
|
|
228
|
+
"data-selected": n || void 0,
|
|
229
|
+
"data-range": !!q && t.value > q[0] && t.value < q[1] || void 0,
|
|
230
|
+
disabled: r || V(t.value),
|
|
231
|
+
onFocus: () => L(t.value),
|
|
232
|
+
onMouseEnter: () => f?.(t.value),
|
|
233
|
+
onClick: () => a(t.value),
|
|
234
|
+
children: t.day
|
|
235
|
+
}, t.value);
|
|
236
|
+
})]
|
|
237
|
+
}) : /* @__PURE__ */ h("div", {
|
|
238
|
+
className: "rfe-period-grid",
|
|
239
|
+
ref: R,
|
|
240
|
+
onKeyDown: Q,
|
|
241
|
+
children: re.map((t, n) => /* @__PURE__ */ h("button", {
|
|
242
|
+
type: "button",
|
|
243
|
+
"data-picker-key": t,
|
|
244
|
+
className: "rfe-day",
|
|
245
|
+
tabIndex: X === t ? 0 : -1,
|
|
246
|
+
"aria-pressed": t === e,
|
|
247
|
+
"data-selected": t === e || void 0,
|
|
248
|
+
disabled: J(t),
|
|
249
|
+
onFocus: () => L(t),
|
|
250
|
+
onClick: () => ne(t, n),
|
|
251
|
+
children: P === "year" ? t : new Intl.DateTimeFormat(S.code, {
|
|
252
|
+
month: "short",
|
|
253
|
+
calendar: "gregory"
|
|
254
|
+
}).format(j(A, n))
|
|
255
|
+
}, t))
|
|
256
|
+
})]
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// src/components/date-time/TimePanel.tsx
|
|
260
|
+
function N({ column: e, length: i, value: a, p: o, onSelect: c }) {
|
|
261
|
+
let u = s(), d = u.text, f = r(null), p = n(() => T(o, a, e), [
|
|
262
|
+
o.minTime,
|
|
263
|
+
o.maxTime,
|
|
264
|
+
o.hourStep,
|
|
265
|
+
o.minuteStep,
|
|
266
|
+
o.secondStep,
|
|
267
|
+
o.showSeconds,
|
|
268
|
+
a,
|
|
269
|
+
e
|
|
270
|
+
]), m = a.split(":")[e], v = [
|
|
271
|
+
d.hour,
|
|
272
|
+
d.minute,
|
|
273
|
+
d.second
|
|
274
|
+
][e], y = Array.from({ length: i }, (e, t) => _(t)), b = p.has(m) ? m : y.find((e) => p.has(e)), x = n(() => new Intl.DateTimeFormat(u.code, {
|
|
275
|
+
hour: "numeric",
|
|
276
|
+
timeZone: "UTC",
|
|
277
|
+
hourCycle: o.hourCycle ?? u.hourCycle
|
|
278
|
+
}), [
|
|
279
|
+
u.code,
|
|
280
|
+
u.hourCycle,
|
|
281
|
+
o.hourCycle
|
|
282
|
+
]);
|
|
283
|
+
return t(() => {
|
|
284
|
+
let e = f.current?.querySelector("[aria-pressed=\"true\"]") ?? f.current?.querySelector("[tabindex=\"0\"]");
|
|
285
|
+
e && f.current && (f.current.scrollTop = Math.max(0, e.offsetTop - f.current.offsetTop - f.current.clientHeight / 2 + e.offsetHeight / 2));
|
|
286
|
+
}, [b]), /* @__PURE__ */ g("div", {
|
|
287
|
+
className: "rfe-time-column",
|
|
288
|
+
role: "group",
|
|
289
|
+
"aria-label": v,
|
|
290
|
+
children: [/* @__PURE__ */ h("span", {
|
|
291
|
+
"aria-hidden": "true",
|
|
292
|
+
children: v
|
|
293
|
+
}), /* @__PURE__ */ h("div", {
|
|
294
|
+
className: "rfe-time-scroll",
|
|
295
|
+
ref: f,
|
|
296
|
+
onKeyDown: (e) => {
|
|
297
|
+
let t = e.target;
|
|
298
|
+
if (!(t instanceof HTMLButtonElement) || !t.dataset.timeKey || ![
|
|
299
|
+
"ArrowUp",
|
|
300
|
+
"ArrowDown",
|
|
301
|
+
"Home",
|
|
302
|
+
"End"
|
|
303
|
+
].includes(e.key)) return;
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
let n = l(y.length, y.indexOf(t.dataset.timeKey), e.key, (e) => p.has(y[e]));
|
|
306
|
+
n < 0 || f.current?.querySelector(`[data-time-key="${y[n]}"]`)?.focus();
|
|
307
|
+
},
|
|
308
|
+
children: y.map((t) => /* @__PURE__ */ h("button", {
|
|
309
|
+
type: "button",
|
|
310
|
+
className: "rfe-day",
|
|
311
|
+
"data-time-key": t,
|
|
312
|
+
tabIndex: b === t ? 0 : -1,
|
|
313
|
+
"aria-pressed": m === t,
|
|
314
|
+
"data-selected": m === t || void 0,
|
|
315
|
+
disabled: !p.has(t) || o.readOnly || o.disabled,
|
|
316
|
+
onClick: () => {
|
|
317
|
+
let e = p.get(t);
|
|
318
|
+
e && c(e);
|
|
319
|
+
},
|
|
320
|
+
children: e === 0 ? x.format(new Date(Date.UTC(2e3, 0, 1, Number(t)))) : t
|
|
321
|
+
}, t))
|
|
322
|
+
})]
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function P({ value: e, onSelect: t, p: n }) {
|
|
326
|
+
let { text: r } = s(), i = [
|
|
327
|
+
24,
|
|
328
|
+
60,
|
|
329
|
+
60
|
|
330
|
+
].slice(0, n.showSeconds === !1 ? 2 : 3);
|
|
331
|
+
return T(n, e, 0).size ? /* @__PURE__ */ h("div", {
|
|
332
|
+
className: "rfe-time-panel",
|
|
333
|
+
children: i.map((r, i) => /* @__PURE__ */ h(N, {
|
|
334
|
+
column: i,
|
|
335
|
+
length: r,
|
|
336
|
+
value: e,
|
|
337
|
+
p: n,
|
|
338
|
+
onSelect: t
|
|
339
|
+
}, i))
|
|
340
|
+
}) : /* @__PURE__ */ h("div", {
|
|
341
|
+
className: "rfe-empty",
|
|
342
|
+
role: "status",
|
|
343
|
+
children: r.empty
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
// src/components/date-time/Picker.tsx
|
|
347
|
+
var F = () => v(/* @__PURE__ */ new Date()), I = () => {
|
|
348
|
+
let e = /* @__PURE__ */ new Date();
|
|
349
|
+
return `${_(e.getHours())}:${_(e.getMinutes())}:${_(e.getSeconds())}`;
|
|
350
|
+
};
|
|
351
|
+
function L(e, t) {
|
|
352
|
+
let n = F(), r = k(I(), t) ?? (t.showSeconds === !1 ? "00:00" : "00:00:00");
|
|
353
|
+
return e === "time" ? r : e === "datetime" ? `${n}T${r}` : e === "month" ? n.slice(0, 7) : e === "year" ? n.slice(0, 4) : n;
|
|
354
|
+
}
|
|
355
|
+
function R({ kind: n, range: l, p: _ }) {
|
|
356
|
+
let v = s(), { text: b } = v, S = _, [C, w] = c(S.value, S.defaultValue ?? null, S.onChange), [T, E] = c(S.open, S.defaultOpen ?? !1, S.onOpenChange), D = !!(_.disabled || _.loading), O = T && !D, [j, N] = i([]), [F, R] = i(0), [z, B] = i(), [te, V] = i(!1), [H, U] = i(!1), [W, G] = i(() => (/* @__PURE__ */ new Date()).getFullYear() * 12 + (/* @__PURE__ */ new Date()).getMonth()), K = _.needConfirm ?? (n === "time" || n === "datetime"), q = Array.isArray(C) ? C : C ? [C] : [], ne = r({
|
|
357
|
+
open: !1,
|
|
358
|
+
values: q
|
|
359
|
+
}), re = () => {
|
|
360
|
+
let e = y(q[0]?.slice(0, 10) ?? "") ?? /* @__PURE__ */ new Date();
|
|
361
|
+
G(e.getFullYear() * 12 + e.getMonth()), N(q), R(0), B(void 0), V(!1), U(!1);
|
|
362
|
+
};
|
|
363
|
+
t(() => {
|
|
364
|
+
O && !ne.current.open ? re() : O && K && (ne.current.values.length !== q.length || ne.current.values.some((e, t) => e !== q[t])) && N(q), ne.current = {
|
|
365
|
+
open: O,
|
|
366
|
+
values: q
|
|
367
|
+
};
|
|
368
|
+
}, [
|
|
369
|
+
O,
|
|
370
|
+
C,
|
|
371
|
+
K
|
|
372
|
+
]), t(() => {
|
|
373
|
+
T && D && E(!1);
|
|
374
|
+
}, [T, D]);
|
|
375
|
+
let J = (e) => {
|
|
376
|
+
e && D || (e && !O && re(), !e && O && _.onBlur?.(), E(e));
|
|
377
|
+
}, Y = (e) => A(e, n, l, _), X = (e, t = !0) => {
|
|
378
|
+
D || _.readOnly || (!e.length && H ? (w(null), t && J(!1)) : Y(e) ? (V(!1), w(l ? [e[0], e[1]] : e[0]), t && J(!1)) : V(!0));
|
|
379
|
+
}, Z = (e, t = F) => {
|
|
380
|
+
if (D || _.readOnly) return;
|
|
381
|
+
if (V(!1), U(!1), !l) {
|
|
382
|
+
N([e]), K || X([e], n !== "time" && n !== "datetime");
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (n === "date" || n === "month" || n === "year") {
|
|
386
|
+
if (F === 0) {
|
|
387
|
+
N([e]), R(1);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
let t = ee(j[0] ?? e, e);
|
|
391
|
+
N(t), R(0), K || X(t);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
let r = [j[0] ?? L(n, S), j[1] ?? L(n, S)];
|
|
395
|
+
r[t] = e, N(r), R(t), K || (Y(r) ? X(r, !1) : V(!0));
|
|
396
|
+
}, Q = (e) => {
|
|
397
|
+
if (!_.format) return o(e, n, {
|
|
398
|
+
...v,
|
|
399
|
+
hourCycle: _.hourCycle ?? v.hourCycle
|
|
400
|
+
}, _.showSeconds !== !1);
|
|
401
|
+
let t = n === "time" ? `2000-01-01T${e}` : n === "month" ? `${e}-01` : n === "year" ? `${e}-01-01` : e;
|
|
402
|
+
return a(t).format(_.format);
|
|
403
|
+
}, $ = j[F] ?? L(n, S), ie = l && [
|
|
404
|
+
"date",
|
|
405
|
+
"month",
|
|
406
|
+
"year"
|
|
407
|
+
].includes(n), ae = n === "time" ? "clock" : "calendar", oe = () => {
|
|
408
|
+
O && K ? (N([]), U(!0), V(!1)) : (w(null), N([]), V(!1));
|
|
409
|
+
}, se = _["aria-label"] ?? _.floatingLabel ?? b.choose, ce = e(), le = _.id ?? ce, ue = (e) => k(e ?? I(), _) ?? e ?? I();
|
|
410
|
+
return /* @__PURE__ */ h(d, {
|
|
411
|
+
..._,
|
|
412
|
+
open: O,
|
|
413
|
+
onOpenChange: J,
|
|
414
|
+
label: se,
|
|
415
|
+
popupWidth: _.popupWidth ?? (l && (n === "time" || n === "datetime" || n === "date" && _.panels !== 1) ? 600 : n === "datetime" ? 480 : 300),
|
|
416
|
+
popupMaxHeight: _.popupMaxHeight ?? 480,
|
|
417
|
+
trigger: (e, t) => /* @__PURE__ */ h("div", {
|
|
418
|
+
ref: t,
|
|
419
|
+
className: "rfe-anchor",
|
|
420
|
+
onBlur: (e) => {
|
|
421
|
+
!O && !e.currentTarget.contains(e.relatedTarget) && _.onBlur?.();
|
|
422
|
+
},
|
|
423
|
+
children: /* @__PURE__ */ h(f, {
|
|
424
|
+
..._,
|
|
425
|
+
id: le,
|
|
426
|
+
disabled: _.disabled || _.loading,
|
|
427
|
+
floatingFilled: q.length > 0,
|
|
428
|
+
floatingOpen: O,
|
|
429
|
+
className: [_.className, `rfe-picker-icon-${_.iconPosition ?? "start"}`].filter(Boolean).join(" "),
|
|
430
|
+
actions: /* @__PURE__ */ g(m, { children: [_.clearable !== !1 && /* @__PURE__ */ h(u, {
|
|
431
|
+
name: "clear",
|
|
432
|
+
source: _.icons?.clear,
|
|
433
|
+
label: b.clear,
|
|
434
|
+
hidden: !q.length,
|
|
435
|
+
disabled: D || _.readOnly,
|
|
436
|
+
onClick: oe
|
|
437
|
+
}), /* @__PURE__ */ h("button", {
|
|
438
|
+
type: "button",
|
|
439
|
+
...e,
|
|
440
|
+
id: le,
|
|
441
|
+
"aria-invalid": _["aria-invalid"] ?? _.status === "error",
|
|
442
|
+
"aria-describedby": _["aria-describedby"],
|
|
443
|
+
className: "rfe-trigger-arrow",
|
|
444
|
+
disabled: D,
|
|
445
|
+
"aria-label": se,
|
|
446
|
+
onClick: () => J(!O),
|
|
447
|
+
onKeyDown: (e) => {
|
|
448
|
+
e.key === "ArrowDown" && (e.preventDefault(), J(!0));
|
|
449
|
+
},
|
|
450
|
+
children: /* @__PURE__ */ h(p, {
|
|
451
|
+
name: ae,
|
|
452
|
+
source: _.icons?.[ae]
|
|
453
|
+
})
|
|
454
|
+
})] }),
|
|
455
|
+
children: /* @__PURE__ */ h("div", {
|
|
456
|
+
className: "rfe-value rfe-picker-value",
|
|
457
|
+
onClick: () => J(!O),
|
|
458
|
+
children: l ? /* @__PURE__ */ g(m, { children: [
|
|
459
|
+
/* @__PURE__ */ h("span", {
|
|
460
|
+
className: q[0] ? "" : "rfe-placeholder",
|
|
461
|
+
children: q[0] ? Q(q[0]) : _.placeholder ?? b.start
|
|
462
|
+
}),
|
|
463
|
+
/* @__PURE__ */ h(p, {
|
|
464
|
+
name: "separator",
|
|
465
|
+
source: _.icons?.separator
|
|
466
|
+
}),
|
|
467
|
+
/* @__PURE__ */ h("span", {
|
|
468
|
+
className: q[1] ? "" : "rfe-placeholder",
|
|
469
|
+
children: q[1] ? Q(q[1]) : b.end
|
|
470
|
+
}),
|
|
471
|
+
n === "time" && q.length === 2 && (x(q[1]) ?? 0) < (x(q[0]) ?? 0) && /* @__PURE__ */ h("small", { children: b.nextDay })
|
|
472
|
+
] }) : /* @__PURE__ */ h("span", {
|
|
473
|
+
className: q.length ? "" : "rfe-placeholder",
|
|
474
|
+
children: q[0] ? Q(q[0]) : _.placeholder ?? b.choose
|
|
475
|
+
})
|
|
476
|
+
})
|
|
477
|
+
})
|
|
478
|
+
}),
|
|
479
|
+
children: /* @__PURE__ */ g("div", {
|
|
480
|
+
className: "rfe-picker-panel",
|
|
481
|
+
"data-readonly": _.readOnly || void 0,
|
|
482
|
+
children: [
|
|
483
|
+
l && /* @__PURE__ */ h("div", {
|
|
484
|
+
className: "rfe-range-tabs",
|
|
485
|
+
role: "group",
|
|
486
|
+
"aria-label": se,
|
|
487
|
+
children: [0, 1].map((e) => /* @__PURE__ */ h("button", {
|
|
488
|
+
className: "rfe-button",
|
|
489
|
+
type: "button",
|
|
490
|
+
"data-variant": "ghost",
|
|
491
|
+
"data-active": F === e,
|
|
492
|
+
"aria-pressed": F === e,
|
|
493
|
+
onClick: () => R(e),
|
|
494
|
+
children: j[e] ? Q(j[e]) : e === 0 ? b.start : b.end
|
|
495
|
+
}, e))
|
|
496
|
+
}),
|
|
497
|
+
n === "time" ? /* @__PURE__ */ h("div", {
|
|
498
|
+
className: l ? "rfe-dual" : "",
|
|
499
|
+
children: (l ? [0, 1] : [0]).map((e) => /* @__PURE__ */ h(P, {
|
|
500
|
+
p: _,
|
|
501
|
+
value: ue(j[e]),
|
|
502
|
+
onSelect: (t) => Z(t, e)
|
|
503
|
+
}, e))
|
|
504
|
+
}) : n === "datetime" ? /* @__PURE__ */ g("div", {
|
|
505
|
+
className: "rfe-dual",
|
|
506
|
+
children: [/* @__PURE__ */ h(M, {
|
|
507
|
+
kind: "date",
|
|
508
|
+
value: $.slice(0, 10),
|
|
509
|
+
p: _,
|
|
510
|
+
onSelect: (e) => Z(`${e}T${ue($.split("T")[1])}`, F)
|
|
511
|
+
}, `date-${F}`), /* @__PURE__ */ h(P, {
|
|
512
|
+
value: ue($.split("T")[1]),
|
|
513
|
+
p: _,
|
|
514
|
+
onSelect: (e) => Z(`${$.slice(0, 10)}T${e}`, F)
|
|
515
|
+
})]
|
|
516
|
+
}) : /* @__PURE__ */ g("div", {
|
|
517
|
+
className: l && n === "date" && _.panels !== 1 ? "rfe-dual rfe-date-dual" : void 0,
|
|
518
|
+
children: [/* @__PURE__ */ h(M, {
|
|
519
|
+
monthCursor: l && n === "date" && _.panels !== 1 ? W : void 0,
|
|
520
|
+
onMonthCursor: l && n === "date" && _.panels !== 1 ? G : void 0,
|
|
521
|
+
kind: n,
|
|
522
|
+
p: _,
|
|
523
|
+
value: $,
|
|
524
|
+
start: ie ? j[0] : void 0,
|
|
525
|
+
end: ie ? j[1] : void 0,
|
|
526
|
+
hover: z,
|
|
527
|
+
onHover: B,
|
|
528
|
+
onSelect: Z
|
|
529
|
+
}), l && n === "date" && _.panels !== 1 && /* @__PURE__ */ h(M, {
|
|
530
|
+
monthCursor: W,
|
|
531
|
+
onMonthCursor: G,
|
|
532
|
+
kind: n,
|
|
533
|
+
offset: 1,
|
|
534
|
+
p: _,
|
|
535
|
+
value: $,
|
|
536
|
+
start: j[0],
|
|
537
|
+
end: j[1],
|
|
538
|
+
hover: z,
|
|
539
|
+
onHover: B,
|
|
540
|
+
onSelect: Z
|
|
541
|
+
})]
|
|
542
|
+
}),
|
|
543
|
+
!!_.presets?.length && /* @__PURE__ */ h("div", {
|
|
544
|
+
className: "rfe-presets",
|
|
545
|
+
children: _.presets.map((e, t) => /* @__PURE__ */ h("button", {
|
|
546
|
+
className: "rfe-button",
|
|
547
|
+
type: "button",
|
|
548
|
+
"data-variant": "secondary",
|
|
549
|
+
disabled: _.readOnly || D,
|
|
550
|
+
onClick: () => {
|
|
551
|
+
let t = typeof e.value == "function" ? e.value() : e.value, n = Array.isArray(t) ? t : t ? [t] : [];
|
|
552
|
+
N(n), V(!1), U(!n.length), K || (n.length ? X(n) : (w(null), J(!1)));
|
|
553
|
+
},
|
|
554
|
+
children: e.label
|
|
555
|
+
}, t))
|
|
556
|
+
}),
|
|
557
|
+
te && /* @__PURE__ */ h("div", {
|
|
558
|
+
className: "rfe-error",
|
|
559
|
+
role: "alert",
|
|
560
|
+
children: b.invalidRange
|
|
561
|
+
}),
|
|
562
|
+
/* @__PURE__ */ g("div", {
|
|
563
|
+
className: "rfe-footer",
|
|
564
|
+
children: [
|
|
565
|
+
/* @__PURE__ */ h("button", {
|
|
566
|
+
className: "rfe-link",
|
|
567
|
+
type: "button",
|
|
568
|
+
disabled: _.readOnly || D,
|
|
569
|
+
onClick: () => Z(L(n, S)),
|
|
570
|
+
children: n === "time" ? b.now : b.today
|
|
571
|
+
}),
|
|
572
|
+
/* @__PURE__ */ h("span", { className: "rfe-spacer" }),
|
|
573
|
+
(K || l || n === "time" || n === "datetime") && /* @__PURE__ */ g(m, { children: [K && /* @__PURE__ */ h("button", {
|
|
574
|
+
type: "button",
|
|
575
|
+
className: "rfe-link",
|
|
576
|
+
onClick: () => J(!1),
|
|
577
|
+
children: b.cancel
|
|
578
|
+
}), /* @__PURE__ */ h("button", {
|
|
579
|
+
className: "rfe-button",
|
|
580
|
+
"data-variant": "primary",
|
|
581
|
+
type: "button",
|
|
582
|
+
disabled: _.readOnly || D,
|
|
583
|
+
onClick: () => X(H ? [] : j.length ? j : l ? [] : [L(n, S)]),
|
|
584
|
+
children: b.done
|
|
585
|
+
})] })
|
|
586
|
+
]
|
|
587
|
+
})
|
|
588
|
+
]
|
|
589
|
+
})
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
// src/components/pickers.tsx
|
|
593
|
+
var z = (e) => /* @__PURE__ */ h(R, {
|
|
594
|
+
kind: "date",
|
|
595
|
+
range: !1,
|
|
596
|
+
p: e
|
|
597
|
+
}), B = (e) => /* @__PURE__ */ h(R, {
|
|
598
|
+
kind: "date",
|
|
599
|
+
range: !0,
|
|
600
|
+
p: e
|
|
601
|
+
}), te = (e) => /* @__PURE__ */ h(R, {
|
|
602
|
+
kind: "time",
|
|
603
|
+
range: !1,
|
|
604
|
+
p: e
|
|
605
|
+
}), V = (e) => /* @__PURE__ */ h(R, {
|
|
606
|
+
kind: "time",
|
|
607
|
+
range: !0,
|
|
608
|
+
p: e
|
|
609
|
+
}), H = (e) => /* @__PURE__ */ h(R, {
|
|
610
|
+
kind: "datetime",
|
|
611
|
+
range: !1,
|
|
612
|
+
p: e
|
|
613
|
+
}), U = (e) => /* @__PURE__ */ h(R, {
|
|
614
|
+
kind: "datetime",
|
|
615
|
+
range: !0,
|
|
616
|
+
p: e
|
|
617
|
+
}), W = (e) => /* @__PURE__ */ h(R, {
|
|
618
|
+
kind: "month",
|
|
619
|
+
range: !1,
|
|
620
|
+
p: e
|
|
621
|
+
}), G = (e) => /* @__PURE__ */ h(R, {
|
|
622
|
+
kind: "month",
|
|
623
|
+
range: !0,
|
|
624
|
+
p: e
|
|
625
|
+
}), K = (e) => /* @__PURE__ */ h(R, {
|
|
626
|
+
kind: "year",
|
|
627
|
+
range: !1,
|
|
628
|
+
p: e
|
|
629
|
+
}), q = (e) => /* @__PURE__ */ h(R, {
|
|
630
|
+
kind: "year",
|
|
631
|
+
range: !0,
|
|
632
|
+
p: e
|
|
633
|
+
});
|
|
634
|
+
export { W as a, V as c, U as i, K as l, B as n, G as o, H as r, te as s, z as t, q as u };
|
package/dist/select.js
CHANGED