@elcrm/form 0.0.88 → 0.1.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 +87 -47
- package/dist/Form.js +1 -11
- package/dist/FormInitContext.js +1 -20
- package/dist/assets/styles/Field.module.css +1 -1
- package/dist/assets/styles/Form.module.css +1 -1
- package/dist/assets/styles/Select.module.css +1 -1
- package/dist/core/Field.d.ts +14 -2
- package/dist/core/Field.js +2 -35
- package/dist/dark.css +22 -3
- package/dist/events/onEvent.js +1 -67
- package/dist/fields/Check.js +1 -86
- package/dist/fields/Code.js +1 -94
- package/dist/fields/Color.js +1 -495
- package/dist/fields/Date.js +1 -450
- package/dist/fields/Display.d.ts +1 -1
- package/dist/fields/Display.js +1 -49
- package/dist/fields/DragDrop.js +1 -189
- package/dist/fields/Email.d.ts +4 -2
- package/dist/fields/Email.js +1 -80
- package/dist/fields/File.js +1 -115
- package/dist/fields/Hidden.js +1 -33
- package/dist/fields/Input.d.ts +3 -1
- package/dist/fields/Input.js +1 -149
- package/dist/fields/Mask.js +1 -119
- package/dist/fields/Modal.js +1 -68
- package/dist/fields/Money.js +1 -125
- package/dist/fields/NativeTextField.d.ts +15 -0
- package/dist/fields/NativeTextField.js +1 -0
- package/dist/fields/Numeric.d.ts +12 -1
- package/dist/fields/Numeric.js +1 -105
- package/dist/fields/Options.js +1 -69
- package/dist/fields/Password.d.ts +1 -1
- package/dist/fields/Password.js +1 -143
- package/dist/fields/Percent.d.ts +8 -1
- package/dist/fields/Percent.js +1 -100
- package/dist/fields/Phone.d.ts +2 -2
- package/dist/fields/Phone.js +1 -128
- package/dist/fields/Radio.js +1 -88
- package/dist/fields/Range.js +1 -109
- package/dist/fields/Rating.js +1 -82
- package/dist/fields/RichText.js +1 -134
- package/dist/fields/Select.d.ts +3 -1
- package/dist/fields/Select.js +1 -171
- package/dist/fields/Tags.js +1 -97
- package/dist/fields/Textarea.d.ts +1 -1
- package/dist/fields/Textarea.js +1 -68
- package/dist/fields/Time.js +1 -444
- package/dist/fields/Url.d.ts +4 -2
- package/dist/fields/Url.js +1 -80
- package/dist/fields/emit.d.ts +9 -0
- package/dist/fields/emit.js +1 -0
- package/dist/fields/type.d.ts +1 -1
- package/dist/fields/visibility.js +1 -6
- package/dist/hooks/use.js +1 -57
- package/dist/index.js +2 -42
- package/dist/index.umd.js +2 -2
- package/dist/light.css +23 -3
- package/dist/mask/MaskPhone.js +1 -1384
- package/dist/mask/phoneDefaults.d.ts +8 -0
- package/dist/mask/phoneDefaults.js +1 -0
- package/dist/overlayZ.js +1 -25
- package/dist/package.js +1 -130
- package/dist/style.css +3 -3
- package/dist/styles/Color.module.js +1 -27
- package/dist/styles/Field.module.js +1 -77
- package/dist/styles/Form.module.js +1 -12
- package/dist/styles/Select.module.js +1 -9
- package/package.json +2 -2
package/dist/fields/Time.js
CHANGED
|
@@ -1,444 +1 @@
|
|
|
1
|
-
import e from
|
|
2
|
-
import t from "../core/Field.js";
|
|
3
|
-
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
-
import r from "../events/onEvent.js";
|
|
5
|
-
import { acquireOverlayZIndex as i, releaseOverlayZIndex as a } from "../overlayZ.js";
|
|
6
|
-
import o from "../styles/Select.module.js";
|
|
7
|
-
import s from "react";
|
|
8
|
-
import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
9
|
-
import { createPortal as d } from "react-dom";
|
|
10
|
-
//#region src/lib/fields/Time.tsx
|
|
11
|
-
function f(e) {
|
|
12
|
-
let t = window.getSelection();
|
|
13
|
-
if (!t || t.rangeCount === 0) return 0;
|
|
14
|
-
let n = t.getRangeAt(0);
|
|
15
|
-
if (!e.contains(n.startContainer)) return 0;
|
|
16
|
-
let r = document.createRange();
|
|
17
|
-
return r.selectNodeContents(e), r.setEnd(n.startContainer, n.startOffset), r.toString().length;
|
|
18
|
-
}
|
|
19
|
-
function p(e, t) {
|
|
20
|
-
let n = t.firstChild;
|
|
21
|
-
if (!n || n.nodeType !== Node.TEXT_NODE) return;
|
|
22
|
-
let r = n.textContent?.length ?? 0, i = Math.max(0, Math.min(e, r)), a = document.createRange(), o = window.getSelection();
|
|
23
|
-
o && (a.setStart(n, i), a.collapse(!0), o.removeAllRanges(), o.addRange(a), t.focus());
|
|
24
|
-
}
|
|
25
|
-
function m(e) {
|
|
26
|
-
return String(e).padStart(2, "0");
|
|
27
|
-
}
|
|
28
|
-
function h(e) {
|
|
29
|
-
return (e || "").replace(/\D/g, "");
|
|
30
|
-
}
|
|
31
|
-
function g(e) {
|
|
32
|
-
if (e == null || e === "" || typeof e != "string") return "";
|
|
33
|
-
let t = e.trim(), n = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(t);
|
|
34
|
-
if (!n) return "";
|
|
35
|
-
let r = Math.min(23, Math.max(0, parseInt(n[1], 10))), i = Math.min(59, Math.max(0, parseInt(n[2], 10)));
|
|
36
|
-
return `${m(r)}:${m(i)}`;
|
|
37
|
-
}
|
|
38
|
-
function _(e) {
|
|
39
|
-
let t = g(e);
|
|
40
|
-
if (!t) return {
|
|
41
|
-
h: null,
|
|
42
|
-
m: null
|
|
43
|
-
};
|
|
44
|
-
let [n, r] = t.split(":").map((e) => parseInt(e, 10));
|
|
45
|
-
return {
|
|
46
|
-
h: n,
|
|
47
|
-
m: r
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function v(e, t) {
|
|
51
|
-
if (e === null && t === null) return "";
|
|
52
|
-
let n = e ?? 0, r = t ?? 0;
|
|
53
|
-
return `${m(n)}:${m(r)}`;
|
|
54
|
-
}
|
|
55
|
-
function y(e, t) {
|
|
56
|
-
let n = h(e).slice(0, 2);
|
|
57
|
-
if (n === "") return null;
|
|
58
|
-
let r = parseInt(n, 10);
|
|
59
|
-
return Number.isNaN(r) ? null : Math.min(t, Math.max(0, r));
|
|
60
|
-
}
|
|
61
|
-
function b(e) {
|
|
62
|
-
let t = g(e);
|
|
63
|
-
if (!t) return null;
|
|
64
|
-
let [n, r] = t.split(":").map((e) => parseInt(e, 10));
|
|
65
|
-
return n * 60 + r;
|
|
66
|
-
}
|
|
67
|
-
function x(e, t) {
|
|
68
|
-
let n = Math.max(1, Math.round(t / 60));
|
|
69
|
-
if (n <= 1) return e;
|
|
70
|
-
let r = Math.round(e / n) * n;
|
|
71
|
-
return Math.min(59, Math.max(0, r));
|
|
72
|
-
}
|
|
73
|
-
function S(e, t, n) {
|
|
74
|
-
let r = g(e);
|
|
75
|
-
if (!r) return "";
|
|
76
|
-
let i = b(r);
|
|
77
|
-
if (i === null) return "";
|
|
78
|
-
if (t) {
|
|
79
|
-
let e = b(t);
|
|
80
|
-
e !== null && (i = Math.max(i, e));
|
|
81
|
-
}
|
|
82
|
-
if (n) {
|
|
83
|
-
let e = b(n);
|
|
84
|
-
e !== null && (i = Math.min(i, e));
|
|
85
|
-
}
|
|
86
|
-
return v(Math.floor(i / 60), i % 60);
|
|
87
|
-
}
|
|
88
|
-
function ee(e, t, n, r) {
|
|
89
|
-
if (r && r.length > 0) {
|
|
90
|
-
let e = /* @__PURE__ */ new Set(), i = [];
|
|
91
|
-
for (let a of r) {
|
|
92
|
-
let r = g(a);
|
|
93
|
-
!r || e.has(r) || (e.add(r), i.push(S(r, t, n) || r));
|
|
94
|
-
}
|
|
95
|
-
return i;
|
|
96
|
-
}
|
|
97
|
-
let i = Math.max(1, Math.round(e / 60));
|
|
98
|
-
i < 5 && (i = 15);
|
|
99
|
-
let a = t ? b(t) ?? 0 : 0, o = n ? b(n) ?? 1439 : 1439, s = Math.min(1439, o), c = [], l = Math.ceil(a / i) * i;
|
|
100
|
-
for (let e = l; e <= s; e += i) {
|
|
101
|
-
let t = Math.floor(e / 60);
|
|
102
|
-
if (t > 23) break;
|
|
103
|
-
let n = e % 60;
|
|
104
|
-
c.push(v(t, n));
|
|
105
|
-
}
|
|
106
|
-
return c;
|
|
107
|
-
}
|
|
108
|
-
function te() {
|
|
109
|
-
return /* @__PURE__ */ u("svg", {
|
|
110
|
-
viewBox: "0 0 24 24",
|
|
111
|
-
width: "20",
|
|
112
|
-
height: "20",
|
|
113
|
-
fill: "none",
|
|
114
|
-
"aria-hidden": !0,
|
|
115
|
-
children: [/* @__PURE__ */ l("circle", {
|
|
116
|
-
cx: "12",
|
|
117
|
-
cy: "12",
|
|
118
|
-
r: "8.25",
|
|
119
|
-
stroke: "currentColor",
|
|
120
|
-
strokeWidth: "1.75"
|
|
121
|
-
}), /* @__PURE__ */ l("path", {
|
|
122
|
-
d: "M12 7.5V12l3 2",
|
|
123
|
-
stroke: "currentColor",
|
|
124
|
-
strokeWidth: "1.75",
|
|
125
|
-
strokeLinecap: "round",
|
|
126
|
-
strokeLinejoin: "round"
|
|
127
|
-
})]
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function C({ value: i = "", form: a, onValue: o, onBlur: b, name: C = "", placeholder: re = "", label: w = "", hidden: ie = !1, disabled: T = !1, error: ae = "", className: E = "", after: D = "", before: O = "", step: k = 60, min: A, max: j, id: oe, spellCheck: M = !1, align: se = "start", picker: N = !1, presets: P }) {
|
|
131
|
-
let { value: ce, version: le } = n(a, C, i), F = g(ce), I = !T, L = s.useRef(null), R = s.useRef(null), ue = s.useRef(null), z = s.useRef(null), [B, V] = s.useState(!1), [H, U] = s.useState(!1), [W, G] = s.useState(null), [K, q] = s.useState(0), J = s.useId(), Y = s.useMemo(() => ee(k, A, j, P), [
|
|
132
|
-
k,
|
|
133
|
-
A,
|
|
134
|
-
j,
|
|
135
|
-
P
|
|
136
|
-
]);
|
|
137
|
-
s.useLayoutEffect(() => {
|
|
138
|
-
if (!B || !I) return;
|
|
139
|
-
let { h: e, m: t } = _(F), n = (e, t) => {
|
|
140
|
-
e && (t === null ? e.innerHTML = "<br>" : e.textContent = String(t));
|
|
141
|
-
};
|
|
142
|
-
n(L.current, e), n(R.current, t);
|
|
143
|
-
}, [
|
|
144
|
-
B,
|
|
145
|
-
F,
|
|
146
|
-
le,
|
|
147
|
-
I
|
|
148
|
-
]);
|
|
149
|
-
let X = s.useCallback(() => {
|
|
150
|
-
let e = y(L.current?.textContent || "", 23), t = y(R.current?.textContent || "", 59);
|
|
151
|
-
if (e === null && t === null) return "";
|
|
152
|
-
let n = v(e, t);
|
|
153
|
-
if (!n) return "";
|
|
154
|
-
let { h: r, m: i } = _(n);
|
|
155
|
-
return i !== null && (n = v(r, x(i, k))), n &&= S(n, A, j), n || "";
|
|
156
|
-
}, [
|
|
157
|
-
A,
|
|
158
|
-
j,
|
|
159
|
-
k
|
|
160
|
-
]), Z = s.useCallback((e) => {
|
|
161
|
-
let t = g(e);
|
|
162
|
-
if (t) {
|
|
163
|
-
let { h: e, m: n } = _(t);
|
|
164
|
-
n !== null && (t = v(e, x(n, k))), t = S(t, A, j);
|
|
165
|
-
}
|
|
166
|
-
return a && C && a.setValue({
|
|
167
|
-
name: C,
|
|
168
|
-
value: t
|
|
169
|
-
}), o && o !== a?.onValue && o({
|
|
170
|
-
value: t,
|
|
171
|
-
name: C
|
|
172
|
-
}), t;
|
|
173
|
-
}, [
|
|
174
|
-
a,
|
|
175
|
-
C,
|
|
176
|
-
o,
|
|
177
|
-
A,
|
|
178
|
-
j,
|
|
179
|
-
k
|
|
180
|
-
]), de = s.useCallback(() => {
|
|
181
|
-
if (!N || !I || Y.length === 0) return;
|
|
182
|
-
let e = z.current;
|
|
183
|
-
if (!e) return;
|
|
184
|
-
let t = Math.max(0, Y.findIndex((e) => e === F));
|
|
185
|
-
q(t >= 0 ? t : 0), G(e.getBoundingClientRect()), U(!0);
|
|
186
|
-
}, [
|
|
187
|
-
N,
|
|
188
|
-
I,
|
|
189
|
-
Y,
|
|
190
|
-
F
|
|
191
|
-
]);
|
|
192
|
-
s.useEffect(() => {
|
|
193
|
-
if (!H) return;
|
|
194
|
-
let e = () => {
|
|
195
|
-
let e = z.current;
|
|
196
|
-
e && G(e.getBoundingClientRect());
|
|
197
|
-
};
|
|
198
|
-
return window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
|
|
199
|
-
window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
|
|
200
|
-
};
|
|
201
|
-
}, [H]), s.useEffect(() => {
|
|
202
|
-
if (!H) return;
|
|
203
|
-
let e = (e) => {
|
|
204
|
-
if (e.key === "Escape") {
|
|
205
|
-
e.preventDefault(), U(!1);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
if (Y.length !== 0) {
|
|
209
|
-
if (e.key === "ArrowDown") e.preventDefault(), q((e) => (e + 1) % Y.length);
|
|
210
|
-
else if (e.key === "ArrowUp") e.preventDefault(), q((e) => e - 1 < 0 ? Y.length - 1 : e - 1);
|
|
211
|
-
else if (e.key === "Enter") {
|
|
212
|
-
e.preventDefault();
|
|
213
|
-
let t = Y[K];
|
|
214
|
-
t && (Z(t), U(!1));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
219
|
-
}, [
|
|
220
|
-
H,
|
|
221
|
-
Y,
|
|
222
|
-
K,
|
|
223
|
-
Z
|
|
224
|
-
]);
|
|
225
|
-
let Q = (e) => (t) => {
|
|
226
|
-
if (t.preventDefault(), !I) return;
|
|
227
|
-
let n = h(t.clipboardData?.getData("text/plain") ?? ""), r = e === "hour" ? 23 : 59;
|
|
228
|
-
if (n.length >= 4) {
|
|
229
|
-
let e = Math.min(23, Math.max(0, parseInt(n.slice(0, 2), 10))), t = Math.min(59, Math.max(0, parseInt(n.slice(2, 4), 10))), r = L.current, i = R.current;
|
|
230
|
-
r && (r.textContent = String(e), queueMicrotask(() => p(String(e).length, r))), i && (i.textContent = String(t), queueMicrotask(() => p(String(t).length, i)));
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
let i = n.slice(0, 2), a = t.currentTarget;
|
|
234
|
-
if (i === "") {
|
|
235
|
-
a.innerHTML = "<br>", queueMicrotask(() => p(0, a));
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
let o = parseInt(i, 10);
|
|
239
|
-
if (Number.isNaN(o)) return;
|
|
240
|
-
let s = String(Math.min(r, Math.max(0, o)));
|
|
241
|
-
a.textContent = s, queueMicrotask(() => p(s.length, a));
|
|
242
|
-
}, fe = (e) => {
|
|
243
|
-
let t = e.target, n = t.textContent || "", r = f(t), i = n.slice(0, r).replace(/\D/g, "").length, a = h(n).slice(0, 2);
|
|
244
|
-
if (a === "") {
|
|
245
|
-
t.innerHTML = "<br>", queueMicrotask(() => p(0, t));
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
let o = parseInt(a, 10);
|
|
249
|
-
if (Number.isNaN(o)) return;
|
|
250
|
-
let s = String(Math.min(23, Math.max(0, o)));
|
|
251
|
-
t.textContent = s;
|
|
252
|
-
let c = Math.min(i, s.length);
|
|
253
|
-
queueMicrotask(() => p(c, t));
|
|
254
|
-
}, pe = (e) => {
|
|
255
|
-
let t = e.target, n = t.textContent || "", r = f(t), i = n.slice(0, r).replace(/\D/g, "").length, a = h(n).slice(0, 2);
|
|
256
|
-
if (a === "") {
|
|
257
|
-
t.innerHTML = "<br>", queueMicrotask(() => p(0, t));
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
let o = parseInt(a, 10);
|
|
261
|
-
if (Number.isNaN(o)) return;
|
|
262
|
-
let s = String(Math.min(59, Math.max(0, o)));
|
|
263
|
-
t.textContent = s;
|
|
264
|
-
let c = Math.min(i, s.length);
|
|
265
|
-
queueMicrotask(() => p(c, t));
|
|
266
|
-
}, me = (e) => {
|
|
267
|
-
(e.key === "Enter" || e.key === ":") && (e.preventDefault(), R.current?.focus());
|
|
268
|
-
}, he = (e) => {
|
|
269
|
-
e.key === "Enter" && e.preventDefault();
|
|
270
|
-
}, ge = (e) => {
|
|
271
|
-
let t = e.currentTarget;
|
|
272
|
-
(t.textContent || "").trim().length || (t.innerHTML = "<br>"), I && V(!0);
|
|
273
|
-
}, _e = (e) => {
|
|
274
|
-
r.Blur(e);
|
|
275
|
-
};
|
|
276
|
-
s.useEffect(() => {
|
|
277
|
-
let e = ue.current;
|
|
278
|
-
if (!e) return;
|
|
279
|
-
let t = (t) => {
|
|
280
|
-
let n = t.relatedTarget;
|
|
281
|
-
if (n && e.contains(n)) return;
|
|
282
|
-
let r = X();
|
|
283
|
-
a && C && a.setValue({
|
|
284
|
-
name: C,
|
|
285
|
-
value: r
|
|
286
|
-
}), o && o !== a?.onValue && o({
|
|
287
|
-
value: r,
|
|
288
|
-
name: C
|
|
289
|
-
}), b && C && b({
|
|
290
|
-
value: r,
|
|
291
|
-
name: C
|
|
292
|
-
}), V(!1);
|
|
293
|
-
};
|
|
294
|
-
return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
|
|
295
|
-
}, [
|
|
296
|
-
a,
|
|
297
|
-
C,
|
|
298
|
-
b,
|
|
299
|
-
A,
|
|
300
|
-
j,
|
|
301
|
-
k,
|
|
302
|
-
X
|
|
303
|
-
]);
|
|
304
|
-
let { h: ve, m: ye } = _(F), $ = {};
|
|
305
|
-
I && ($.edit = "");
|
|
306
|
-
let be = { ...$ }, xe = { ...$ };
|
|
307
|
-
re && (be.placeholder = re);
|
|
308
|
-
let Se = F !== "" || B;
|
|
309
|
-
return ie && F === "" ? null : /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("div", {
|
|
310
|
-
ref: z,
|
|
311
|
-
children: /* @__PURE__ */ u(t, {
|
|
312
|
-
type: "time",
|
|
313
|
-
label: w,
|
|
314
|
-
error: ae,
|
|
315
|
-
element_blok: { className: [E || ""] },
|
|
316
|
-
element_input: {
|
|
317
|
-
className: [
|
|
318
|
-
e.w,
|
|
319
|
-
e.time,
|
|
320
|
-
se === "center" ? e.timeAlignCenter : ""
|
|
321
|
-
].filter(Boolean),
|
|
322
|
-
props: { "data-disabled": T || !I ? "true" : void 0 }
|
|
323
|
-
},
|
|
324
|
-
children: [
|
|
325
|
-
O ? /* @__PURE__ */ l("span", {
|
|
326
|
-
className: e.affix,
|
|
327
|
-
children: O
|
|
328
|
-
}) : null,
|
|
329
|
-
/* @__PURE__ */ u("div", {
|
|
330
|
-
ref: ue,
|
|
331
|
-
className: e.timeInner,
|
|
332
|
-
role: "group",
|
|
333
|
-
"aria-label": w || "Время",
|
|
334
|
-
children: [
|
|
335
|
-
/* @__PURE__ */ l("div", {
|
|
336
|
-
id: oe,
|
|
337
|
-
ref: L,
|
|
338
|
-
className: e.timePart,
|
|
339
|
-
contentEditable: I ? "plaintext-only" : !1,
|
|
340
|
-
suppressContentEditableWarning: !0,
|
|
341
|
-
spellCheck: M,
|
|
342
|
-
inputMode: "numeric",
|
|
343
|
-
onPaste: Q("hour"),
|
|
344
|
-
onInput: fe,
|
|
345
|
-
onKeyDown: me,
|
|
346
|
-
onFocus: ge,
|
|
347
|
-
onBlur: _e,
|
|
348
|
-
"aria-label": "Часы, 0–23",
|
|
349
|
-
...be,
|
|
350
|
-
children: !I || !B ? ve === null ? "" : m(ve) : null
|
|
351
|
-
}),
|
|
352
|
-
Se && /* @__PURE__ */ l("span", {
|
|
353
|
-
className: e.timeSep,
|
|
354
|
-
"aria-hidden": "true",
|
|
355
|
-
children: ":"
|
|
356
|
-
}),
|
|
357
|
-
/* @__PURE__ */ l("div", {
|
|
358
|
-
ref: R,
|
|
359
|
-
className: e.timePart,
|
|
360
|
-
contentEditable: I ? "plaintext-only" : !1,
|
|
361
|
-
suppressContentEditableWarning: !0,
|
|
362
|
-
spellCheck: M,
|
|
363
|
-
inputMode: "numeric",
|
|
364
|
-
onPaste: Q("minute"),
|
|
365
|
-
onInput: pe,
|
|
366
|
-
onKeyDown: he,
|
|
367
|
-
onFocus: ge,
|
|
368
|
-
onBlur: _e,
|
|
369
|
-
"aria-label": "Минуты, 0–59",
|
|
370
|
-
...xe,
|
|
371
|
-
children: !I || !B ? ye === null ? "" : m(ye) : null
|
|
372
|
-
})
|
|
373
|
-
]
|
|
374
|
-
}),
|
|
375
|
-
N ? /* @__PURE__ */ l("button", {
|
|
376
|
-
type: "button",
|
|
377
|
-
className: e.timePickerBtn,
|
|
378
|
-
disabled: !I || Y.length === 0,
|
|
379
|
-
"aria-label": "Быстрый выбор времени",
|
|
380
|
-
"aria-haspopup": "listbox",
|
|
381
|
-
"aria-expanded": H,
|
|
382
|
-
"aria-controls": J,
|
|
383
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
384
|
-
onClick: de,
|
|
385
|
-
children: /* @__PURE__ */ l(te, {})
|
|
386
|
-
}) : null,
|
|
387
|
-
D ? /* @__PURE__ */ l("span", {
|
|
388
|
-
className: e.affix,
|
|
389
|
-
children: D
|
|
390
|
-
}) : null
|
|
391
|
-
]
|
|
392
|
-
})
|
|
393
|
-
}), H && W && d(/* @__PURE__ */ l(ne, {
|
|
394
|
-
parent: W,
|
|
395
|
-
slots: Y,
|
|
396
|
-
current: F,
|
|
397
|
-
activeIndex: K,
|
|
398
|
-
listId: J,
|
|
399
|
-
className: E,
|
|
400
|
-
setOpen: U,
|
|
401
|
-
setActiveIndex: q,
|
|
402
|
-
onPick: (e) => {
|
|
403
|
-
Z(e), U(!1);
|
|
404
|
-
}
|
|
405
|
-
}), document.body)] });
|
|
406
|
-
}
|
|
407
|
-
C.displayName = "TimeField";
|
|
408
|
-
var ne = ({ parent: e, slots: t, current: n, activeIndex: r, listId: d, className: f, setOpen: p, setActiveIndex: m, onPick: h }) => {
|
|
409
|
-
let g = s.useRef(null), [_] = s.useState(() => i());
|
|
410
|
-
s.useEffect(() => () => a(_), [_]), s.useEffect(() => {
|
|
411
|
-
(g.current?.querySelector("[data-focus=\"true\"]"))?.scrollIntoView({ block: "nearest" });
|
|
412
|
-
}, [r]);
|
|
413
|
-
let v = window.innerHeight - e.bottom < 306 ? Math.max(6, e.top - 300 - 6) : Math.min(window.innerHeight - 300 - 6, e.bottom + 6), y = Math.max(e.width, 160), b = Math.min(Math.max(6, e.left), window.innerWidth - y - 6);
|
|
414
|
-
return /* @__PURE__ */ u(c, { children: [/* @__PURE__ */ l("div", {
|
|
415
|
-
className: o.o,
|
|
416
|
-
style: { zIndex: _ },
|
|
417
|
-
onClick: () => p(!1),
|
|
418
|
-
"aria-hidden": !0
|
|
419
|
-
}), /* @__PURE__ */ l("div", {
|
|
420
|
-
className: [o.l, f].filter((e) => e !== void 0).join(" "),
|
|
421
|
-
style: {
|
|
422
|
-
top: v + "px",
|
|
423
|
-
left: b + "px",
|
|
424
|
-
width: y,
|
|
425
|
-
zIndex: _ + 1
|
|
426
|
-
},
|
|
427
|
-
children: /* @__PURE__ */ l("ul", {
|
|
428
|
-
id: d,
|
|
429
|
-
role: "listbox",
|
|
430
|
-
ref: g,
|
|
431
|
-
children: t.map((e, t) => /* @__PURE__ */ l("li", {
|
|
432
|
-
id: `${d}-opt-${t}`,
|
|
433
|
-
role: "option",
|
|
434
|
-
"aria-selected": n === e,
|
|
435
|
-
"data-focus": r === t ? "true" : "false",
|
|
436
|
-
onMouseEnter: () => m(t),
|
|
437
|
-
onClick: () => h(e),
|
|
438
|
-
children: e
|
|
439
|
-
}, e))
|
|
440
|
-
})
|
|
441
|
-
})] });
|
|
442
|
-
};
|
|
443
|
-
//#endregion
|
|
444
|
-
export { C as default };
|
|
1
|
+
import e from"../styles/Field.module.js";import t from"../core/Field.js";import{useFormFieldState as n}from"../hooks/use.js";import r from"../events/onEvent.js";import{acquireOverlayZIndex as i,releaseOverlayZIndex as a}from"../overlayZ.js";import o from"../styles/Select.module.js";import s from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";import{createPortal as d}from"react-dom";function f(e){let t=window.getSelection();if(!t||t.rangeCount===0)return 0;let n=t.getRangeAt(0);if(!e.contains(n.startContainer))return 0;let r=document.createRange();return r.selectNodeContents(e),r.setEnd(n.startContainer,n.startOffset),r.toString().length}function p(e,t){let n=t.firstChild;if(!n||n.nodeType!==Node.TEXT_NODE)return;let r=n.textContent?.length??0,i=Math.max(0,Math.min(e,r)),a=document.createRange(),o=window.getSelection();o&&(a.setStart(n,i),a.collapse(!0),o.removeAllRanges(),o.addRange(a),t.focus())}function m(e){return String(e).padStart(2,`0`)}function h(e){return(e||``).replace(/\D/g,``)}function g(e){if(e==null||e===``||typeof e!=`string`)return``;let t=e.trim(),n=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(t);if(!n)return``;let r=Math.min(23,Math.max(0,parseInt(n[1],10))),i=Math.min(59,Math.max(0,parseInt(n[2],10)));return`${m(r)}:${m(i)}`}function _(e){let t=g(e);if(!t)return{h:null,m:null};let[n,r]=t.split(`:`).map(e=>parseInt(e,10));return{h:n,m:r}}function v(e,t){if(e===null&&t===null)return``;let n=e??0,r=t??0;return`${m(n)}:${m(r)}`}function y(e,t){let n=h(e).slice(0,2);if(n===``)return null;let r=parseInt(n,10);return Number.isNaN(r)?null:Math.min(t,Math.max(0,r))}function b(e){let t=g(e);if(!t)return null;let[n,r]=t.split(`:`).map(e=>parseInt(e,10));return n*60+r}function x(e,t){let n=Math.max(1,Math.round(t/60));if(n<=1)return e;let r=Math.round(e/n)*n;return Math.min(59,Math.max(0,r))}function S(e,t,n){let r=g(e);if(!r)return``;let i=b(r);if(i===null)return``;if(t){let e=b(t);e!==null&&(i=Math.max(i,e))}if(n){let e=b(n);e!==null&&(i=Math.min(i,e))}return v(Math.floor(i/60),i%60)}function ee(e,t,n,r){if(r&&r.length>0){let e=new Set,i=[];for(let a of r){let r=g(a);!r||e.has(r)||(e.add(r),i.push(S(r,t,n)||r))}return i}let i=Math.max(1,Math.round(e/60));i<5&&(i=15);let a=t?b(t)??0:0,o=n?b(n)??1439:1439,s=Math.min(1439,o),c=[],l=Math.ceil(a/i)*i;for(let e=l;e<=s;e+=i){let t=Math.floor(e/60);if(t>23)break;let n=e%60;c.push(v(t,n))}return c}function te(){return u(`svg`,{viewBox:`0 0 24 24`,width:`20`,height:`20`,fill:`none`,"aria-hidden":!0,children:[l(`circle`,{cx:`12`,cy:`12`,r:`8.25`,stroke:`currentColor`,strokeWidth:`1.75`}),l(`path`,{d:`M12 7.5V12l3 2`,stroke:`currentColor`,strokeWidth:`1.75`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function C({value:i=``,form:a,onValue:o,onBlur:b,name:C=``,placeholder:re=``,label:w=``,hidden:ie=!1,disabled:T=!1,error:ae=``,className:E=``,after:D=``,before:O=``,step:k=60,min:A,max:j,id:oe,spellCheck:M=!1,align:se=`start`,picker:N=!1,presets:P}){let{value:ce,version:le}=n(a,C,i),F=g(ce),I=!T,L=s.useRef(null),R=s.useRef(null),ue=s.useRef(null),z=s.useRef(null),[B,V]=s.useState(!1),[H,U]=s.useState(!1),[W,G]=s.useState(null),[K,q]=s.useState(0),J=s.useId(),Y=s.useMemo(()=>ee(k,A,j,P),[k,A,j,P]);s.useLayoutEffect(()=>{if(!B||!I)return;let{h:e,m:t}=_(F),n=(e,t)=>{e&&(t===null?e.innerHTML=`<br>`:e.textContent=String(t))};n(L.current,e),n(R.current,t)},[B,F,le,I]);let X=s.useCallback(()=>{let e=y(L.current?.textContent||``,23),t=y(R.current?.textContent||``,59);if(e===null&&t===null)return``;let n=v(e,t);if(!n)return``;let{h:r,m:i}=_(n);return i!==null&&(n=v(r,x(i,k))),n&&=S(n,A,j),n||``},[A,j,k]),Z=s.useCallback(e=>{let t=g(e);if(t){let{h:e,m:n}=_(t);n!==null&&(t=v(e,x(n,k))),t=S(t,A,j)}return a&&C&&a.setValue({name:C,value:t}),o&&o!==a?.onValue&&o({value:t,name:C}),t},[a,C,o,A,j,k]),de=s.useCallback(()=>{if(!N||!I||Y.length===0)return;let e=z.current;if(!e)return;let t=Math.max(0,Y.findIndex(e=>e===F));q(t>=0?t:0),G(e.getBoundingClientRect()),U(!0)},[N,I,Y,F]);s.useEffect(()=>{if(!H)return;let e=()=>{let e=z.current;e&&G(e.getBoundingClientRect())};return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[H]),s.useEffect(()=>{if(!H)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),U(!1);return}if(Y.length!==0){if(e.key===`ArrowDown`)e.preventDefault(),q(e=>(e+1)%Y.length);else if(e.key===`ArrowUp`)e.preventDefault(),q(e=>e-1<0?Y.length-1:e-1);else if(e.key===`Enter`){e.preventDefault();let t=Y[K];t&&(Z(t),U(!1))}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[H,Y,K,Z]);let Q=e=>t=>{if(t.preventDefault(),!I)return;let n=h(t.clipboardData?.getData(`text/plain`)??``),r=e===`hour`?23:59;if(n.length>=4){let e=Math.min(23,Math.max(0,parseInt(n.slice(0,2),10))),t=Math.min(59,Math.max(0,parseInt(n.slice(2,4),10))),r=L.current,i=R.current;r&&(r.textContent=String(e),queueMicrotask(()=>p(String(e).length,r))),i&&(i.textContent=String(t),queueMicrotask(()=>p(String(t).length,i)));return}let i=n.slice(0,2),a=t.currentTarget;if(i===``){a.innerHTML=`<br>`,queueMicrotask(()=>p(0,a));return}let o=parseInt(i,10);if(Number.isNaN(o))return;let s=String(Math.min(r,Math.max(0,o)));a.textContent=s,queueMicrotask(()=>p(s.length,a))},fe=e=>{let t=e.target,n=t.textContent||``,r=f(t),i=n.slice(0,r).replace(/\D/g,``).length,a=h(n).slice(0,2);if(a===``){t.innerHTML=`<br>`,queueMicrotask(()=>p(0,t));return}let o=parseInt(a,10);if(Number.isNaN(o))return;let s=String(Math.min(23,Math.max(0,o)));t.textContent=s;let c=Math.min(i,s.length);queueMicrotask(()=>p(c,t))},pe=e=>{let t=e.target,n=t.textContent||``,r=f(t),i=n.slice(0,r).replace(/\D/g,``).length,a=h(n).slice(0,2);if(a===``){t.innerHTML=`<br>`,queueMicrotask(()=>p(0,t));return}let o=parseInt(a,10);if(Number.isNaN(o))return;let s=String(Math.min(59,Math.max(0,o)));t.textContent=s;let c=Math.min(i,s.length);queueMicrotask(()=>p(c,t))},me=e=>{(e.key===`Enter`||e.key===`:`)&&(e.preventDefault(),R.current?.focus())},he=e=>{e.key===`Enter`&&e.preventDefault()},ge=e=>{let t=e.currentTarget;(t.textContent||``).trim().length||(t.innerHTML=`<br>`),I&&V(!0)},_e=e=>{r.Blur(e)};s.useEffect(()=>{let e=ue.current;if(!e)return;let t=t=>{let n=t.relatedTarget;if(n&&e.contains(n))return;let r=X();a&&C&&a.setValue({name:C,value:r}),o&&o!==a?.onValue&&o({value:r,name:C}),b&&C&&b({value:r,name:C}),V(!1)};return e.addEventListener(`focusout`,t),()=>e.removeEventListener(`focusout`,t)},[a,C,b,A,j,k,X]);let{h:ve,m:ye}=_(F),$={};I&&($.edit=``);let be={...$},xe={...$};re&&(be.placeholder=re);let Se=F!==``||B;return ie&&F===``?null:u(c,{children:[l(`div`,{ref:z,children:u(t,{type:`time`,label:w,error:ae,element_blok:{className:[E||``]},element_input:{className:[e.w,e.time,se===`center`?e.timeAlignCenter:``].filter(Boolean),props:{"data-disabled":T||!I?`true`:void 0}},children:[O?l(`span`,{className:e.affix,children:O}):null,u(`div`,{ref:ue,className:e.timeInner,role:`group`,"aria-label":w||`Время`,children:[l(`div`,{id:oe,ref:L,className:e.timePart,contentEditable:I?`plaintext-only`:!1,suppressContentEditableWarning:!0,spellCheck:M,inputMode:`numeric`,onPaste:Q(`hour`),onInput:fe,onKeyDown:me,onFocus:ge,onBlur:_e,"aria-label":`Часы, 0–23`,...be,children:!I||!B?ve===null?``:m(ve):null}),Se&&l(`span`,{className:e.timeSep,"aria-hidden":`true`,children:`:`}),l(`div`,{ref:R,className:e.timePart,contentEditable:I?`plaintext-only`:!1,suppressContentEditableWarning:!0,spellCheck:M,inputMode:`numeric`,onPaste:Q(`minute`),onInput:pe,onKeyDown:he,onFocus:ge,onBlur:_e,"aria-label":`Минуты, 0–59`,...xe,children:!I||!B?ye===null?``:m(ye):null})]}),N?l(`button`,{type:`button`,className:e.timePickerBtn,disabled:!I||Y.length===0,"aria-label":`Быстрый выбор времени`,"aria-haspopup":`listbox`,"aria-expanded":H,"aria-controls":J,onMouseDown:e=>e.preventDefault(),onClick:de,children:l(te,{})}):null,D?l(`span`,{className:e.affix,children:D}):null]})}),H&&W&&d(l(ne,{parent:W,slots:Y,current:F,activeIndex:K,listId:J,className:E,setOpen:U,setActiveIndex:q,onPick:e=>{Z(e),U(!1)}}),document.body)]})}C.displayName=`TimeField`;var ne=({parent:e,slots:t,current:n,activeIndex:r,listId:d,className:f,setOpen:p,setActiveIndex:m,onPick:h})=>{let g=s.useRef(null),[_]=s.useState(()=>i());s.useEffect(()=>()=>a(_),[_]),s.useEffect(()=>{(g.current?.querySelector(`[data-focus="true"]`))?.scrollIntoView({block:`nearest`})},[r]);let v=window.innerHeight-e.bottom<306?Math.max(6,e.top-300-6):Math.min(window.innerHeight-300-6,e.bottom+6),y=Math.max(e.width,160),b=Math.min(Math.max(6,e.left),window.innerWidth-y-6);return u(c,{children:[l(`div`,{className:o.o,style:{zIndex:_},onClick:()=>p(!1),"aria-hidden":!0}),l(`div`,{className:[o.l,f].filter(e=>e!==void 0).join(` `),style:{top:v+`px`,left:b+`px`,width:y,zIndex:_+1},children:l(`ul`,{id:d,role:`listbox`,ref:g,children:t.map((e,t)=>l(`li`,{id:`${d}-opt-${t}`,role:`option`,"aria-selected":n===e,"data-focus":r===t?`true`:`false`,onMouseEnter:()=>m(t),onClick:()=>h(e),children:e},e))})})]})};export{C as default};
|
package/dist/fields/Url.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
1
2
|
import { TInput } from './type';
|
|
2
3
|
/** UrlField — нативный input type=url. */
|
|
3
4
|
export type TUrl = TInput;
|
|
4
|
-
declare function UrlField(
|
|
5
|
+
declare function UrlField(props: TUrl): import("react/jsx-runtime").JSX.Element;
|
|
5
6
|
declare namespace UrlField {
|
|
6
7
|
var displayName: string;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
declare const _default: React.MemoExoticComponent<typeof UrlField>;
|
|
10
|
+
export default _default;
|
package/dist/fields/Url.js
CHANGED
|
@@ -1,80 +1 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
import t from "../core/Field.js";
|
|
3
|
-
import { useFormFieldState as n } from "../hooks/use.js";
|
|
4
|
-
import { isEmptyTextLike as r } from "./visibility.js";
|
|
5
|
-
import i from "react";
|
|
6
|
-
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
7
|
-
//#region src/lib/fields/Url.tsx
|
|
8
|
-
function s({ value: s = "", form: c, onValue: l, onBlur: u, name: d = "", placeholder: f = "", label: p = "", error: m = "", hidden: h = !1, disabled: g = !1, className: _ = "", after: v = "", before: y = "", maxLength: b, autoComplete: x = "url", id: S }) {
|
|
9
|
-
let { value: C, version: w } = n(c, d, s), T = !g, E = typeof C == "string" || typeof C == "number" ? String(C) : "", D = i.useRef(null);
|
|
10
|
-
i.useEffect(() => {
|
|
11
|
-
let e = D.current;
|
|
12
|
-
!e || e.value === E || (e.value = E);
|
|
13
|
-
}, [E, w]);
|
|
14
|
-
let O = (e, t = !1) => {
|
|
15
|
-
let n = {
|
|
16
|
-
value: e,
|
|
17
|
-
name: d
|
|
18
|
-
};
|
|
19
|
-
c && d && (t ? c.setValue(n) : c.onValue(n)), l && l !== c?.onValue && l(n);
|
|
20
|
-
};
|
|
21
|
-
return h && r(C) ? null : /* @__PURE__ */ o(t, {
|
|
22
|
-
type: "url",
|
|
23
|
-
label: p,
|
|
24
|
-
error: m,
|
|
25
|
-
element_blok: { className: [_ || ""] },
|
|
26
|
-
element_input: {
|
|
27
|
-
className: [e.w],
|
|
28
|
-
props: { "data-disabled": g || !T ? "true" : void 0 }
|
|
29
|
-
},
|
|
30
|
-
children: [
|
|
31
|
-
y ? /* @__PURE__ */ a("span", {
|
|
32
|
-
className: e.affix,
|
|
33
|
-
children: y
|
|
34
|
-
}) : null,
|
|
35
|
-
/* @__PURE__ */ a("div", { children: /* @__PURE__ */ a("input", {
|
|
36
|
-
id: S,
|
|
37
|
-
ref: D,
|
|
38
|
-
type: "url",
|
|
39
|
-
name: d || void 0,
|
|
40
|
-
defaultValue: E,
|
|
41
|
-
placeholder: f,
|
|
42
|
-
maxLength: b,
|
|
43
|
-
disabled: g,
|
|
44
|
-
readOnly: !T,
|
|
45
|
-
autoComplete: x,
|
|
46
|
-
inputMode: "url",
|
|
47
|
-
spellCheck: !1,
|
|
48
|
-
"aria-label": p || f || "URL",
|
|
49
|
-
onChange: (e) => O(e.target.value),
|
|
50
|
-
onBlur: (e) => {
|
|
51
|
-
let t = (e.target.value || "").trim();
|
|
52
|
-
O(t, !0), u?.({
|
|
53
|
-
value: t,
|
|
54
|
-
name: d
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
onKeyDown: (e) => {
|
|
58
|
-
e.key === "Enter" && e.preventDefault();
|
|
59
|
-
},
|
|
60
|
-
style: {
|
|
61
|
-
width: "100%",
|
|
62
|
-
border: "none",
|
|
63
|
-
outline: "none",
|
|
64
|
-
background: "transparent",
|
|
65
|
-
font: "inherit",
|
|
66
|
-
color: "inherit",
|
|
67
|
-
padding: 0,
|
|
68
|
-
margin: 0
|
|
69
|
-
}
|
|
70
|
-
}) }),
|
|
71
|
-
v ? /* @__PURE__ */ a("span", {
|
|
72
|
-
className: e.affix,
|
|
73
|
-
children: v
|
|
74
|
-
}) : null
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
s.displayName = "UrlField";
|
|
79
|
-
//#endregion
|
|
80
|
-
export { s as default };
|
|
1
|
+
import e from"./NativeTextField.js";import t from"react";import{jsx as n}from"react/jsx-runtime";function r(t){return n(e,{...t,fieldType:`url`,inputType:`url`,inputmode:t.inputmode??`url`,autoComplete:t.autoComplete??`url`,defaultAriaLabel:`URL`})}r.displayName=`UrlField`;var i=t.memo(r);export{i as default};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TValue } from '../fields/type';
|
|
2
|
+
import { UseFormApi } from '../hooks/use';
|
|
3
|
+
/**
|
|
4
|
+
* Единый emit значения в form / onValue.
|
|
5
|
+
* `commit=true` → `setValue` (bump version), но только если значение
|
|
6
|
+
* реально изменилось — иначе blur перерисовывал бы поле зря.
|
|
7
|
+
* Во время ввода (`commit=false`) — только `onValue` без notify.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createFieldEmit(form: UseFormApi | undefined, name: string, onValue?: (data: TValue) => void | Promise<void>): (value: unknown, commit?: boolean) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n){return(r,i=!1)=>{let a={value:r,name:t};if(e&&t)if(i){let n=e.getValue(t);Object.is(n,r)?e.onValue(a):e.setValue(a)}else e.onValue(a);n&&n!==e?.onValue&&n(a)}}export{e as createFieldEmit};
|
package/dist/fields/type.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type TFieldFormBindings = {
|
|
|
11
11
|
};
|
|
12
12
|
/** Подпись, доступность, видимость */
|
|
13
13
|
export type TFieldPresentation = {
|
|
14
|
-
/** Подпись поля (визуально в
|
|
14
|
+
/** Подпись поля (визуально в `.t`) */
|
|
15
15
|
label?: string;
|
|
16
16
|
placeholder?: string;
|
|
17
17
|
/** true — только просмотр, без ввода (аналог нативного disabled) */
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e) {
|
|
3
|
-
return e == null ? !0 : typeof e == "string" ? e.trim() === "" : !1;
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
export { e as isEmptyTextLike };
|
|
1
|
+
function e(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}export{e as isEmptyTextLike};
|
package/dist/hooks/use.js
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
import e from
|
|
2
|
-
//#region src/lib/hooks/use.ts
|
|
3
|
-
var t = (e, t) => Object.is(e, t);
|
|
4
|
-
function n(n = {}) {
|
|
5
|
-
let r = e.useRef({ ...n }), i = e.useRef({}), a = e.useRef({}), o = e.useCallback((e) => {
|
|
6
|
-
let t = i.current[e];
|
|
7
|
-
t && t.forEach((e) => e());
|
|
8
|
-
}, []), s = e.useCallback((e) => {
|
|
9
|
-
a.current[e] = (a.current[e] || 0) + 1;
|
|
10
|
-
}, []), c = e.useCallback((e) => {
|
|
11
|
-
!e || !e.name || (r.current[e.name] = e.value);
|
|
12
|
-
}, []), l = e.useCallback((e) => {
|
|
13
|
-
let n = r.current, i = new Set([...Object.keys(n), ...Object.keys(e)]), a = { ...e };
|
|
14
|
-
r.current = a, i.forEach((e) => {
|
|
15
|
-
let r = n[e], i = a[e];
|
|
16
|
-
t(r, i) || (s(e), o(e));
|
|
17
|
-
});
|
|
18
|
-
}, [s, o]), u = e.useCallback((e) => {
|
|
19
|
-
!e || !e.name || (r.current[e.name] = e.value, s(e.name), o(e.name));
|
|
20
|
-
}, [s, o]), d = e.useCallback((e = n) => {
|
|
21
|
-
let i = r.current, a = new Set([...Object.keys(i), ...Object.keys(e)]);
|
|
22
|
-
r.current = { ...e }, a.forEach((e) => {
|
|
23
|
-
let n = i[e], a = r.current[e];
|
|
24
|
-
t(n, a) || (s(e), o(e));
|
|
25
|
-
});
|
|
26
|
-
}, [
|
|
27
|
-
n,
|
|
28
|
-
s,
|
|
29
|
-
o
|
|
30
|
-
]), f = e.useCallback(() => ({ ...r.current }), []), p = e.useCallback((e, t) => r.current[e] ?? t, []), m = e.useCallback((e) => a.current[e] || 0, []), h = e.useCallback((e, t) => (i.current[e] || (i.current[e] = /* @__PURE__ */ new Set()), i.current[e].add(t), () => {
|
|
31
|
-
i.current[e]?.delete(t), i.current[e]?.size === 0 && delete i.current[e];
|
|
32
|
-
}), []), g = e.useRef(null);
|
|
33
|
-
return g.current ||= {}, Object.assign(g.current, {
|
|
34
|
-
valuesRef: r,
|
|
35
|
-
getValues: f,
|
|
36
|
-
setValues: l,
|
|
37
|
-
setValue: u,
|
|
38
|
-
onValue: c,
|
|
39
|
-
reset: d,
|
|
40
|
-
getValue: p,
|
|
41
|
-
getVersion: m,
|
|
42
|
-
subscribe: h
|
|
43
|
-
}), g.current;
|
|
44
|
-
}
|
|
45
|
-
function r(t, n, r) {
|
|
46
|
-
let i = e.useCallback((e) => !t || !n ? () => {} : t.subscribe(n, e), [t, n]), a = e.useCallback(() => !t || !n ? 0 : t.getVersion(n), [t, n]), o = e.useSyncExternalStore(i, a, a);
|
|
47
|
-
return {
|
|
48
|
-
value: t && n ? t.getValue(n, r) : r,
|
|
49
|
-
version: o
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function i(e, t, n = "") {
|
|
53
|
-
let { value: i } = r(e, t, n);
|
|
54
|
-
return i;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { n as useForm, i as useFormField, r as useFormFieldState };
|
|
1
|
+
import e from"react";var t=(e,t)=>Object.is(e,t);function n(n={}){let r=e.useRef({...n}),i=e.useRef(n),a=e.useRef({}),o=e.useRef({}),s=e.useCallback(e=>{let t=a.current[e];t&&t.forEach(e=>e())},[]),c=e.useCallback(e=>{o.current[e]=(o.current[e]||0)+1},[]),l=e.useCallback(e=>{!e||!e.name||(r.current[e.name]=e.value)},[]),u=e.useCallback(e=>{let n=r.current,i=new Set([...Object.keys(n),...Object.keys(e)]),a={...e};r.current=a,i.forEach(e=>{let r=n[e],i=a[e];t(r,i)||(c(e),s(e))})},[c,s]),d=e.useCallback(e=>{!e||!e.name||(r.current[e.name]=e.value,c(e.name),s(e.name))},[c,s]),f=e.useCallback(e=>{let n=e??i.current,a=r.current,o=new Set([...Object.keys(a),...Object.keys(n)]);r.current={...n},o.forEach(e=>{let n=a[e],i=r.current[e];t(n,i)||(c(e),s(e))})},[c,s]),p=e.useCallback(()=>({...r.current}),[]),m=e.useCallback((e,t)=>r.current[e]??t,[]),h=e.useCallback(e=>o.current[e]||0,[]),g=e.useCallback((e,t)=>(a.current[e]||(a.current[e]=new Set),a.current[e].add(t),()=>{a.current[e]?.delete(t),a.current[e]?.size===0&&delete a.current[e]}),[]),_=e.useRef(null);return _.current||={},Object.assign(_.current,{valuesRef:r,getValues:p,setValues:u,setValue:d,onValue:l,reset:f,getValue:m,getVersion:h,subscribe:g}),_.current}function r(t,n,r){let i=e.useCallback(e=>!t||!n?()=>{}:t.subscribe(n,e),[t,n]),a=e.useCallback(()=>!t||!n?0:t.getVersion(n),[t,n]),o=e.useSyncExternalStore(i,a,a);return{value:t&&n?t.getValue(n,r):r,version:o}}function i(e,t,n=``){let{value:i}=r(e,t,n);return i}export{n as useForm,i as useFormField,r as useFormFieldState};
|