@tachui/forms 0.7.0-alpha1 → 0.7.1-alpha
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 +321 -0
- package/dist/TextField-CGBM3x7K.js +1799 -0
- package/dist/components/index.js +25 -28
- package/dist/index.js +79 -81
- package/dist/state/index.js +240 -7
- package/dist/validation/index.js +598 -19
- package/package.json +5 -6
- package/dist/Form-ueYEcSg1.cjs +0 -2
- package/dist/Form-ueYEcSg1.cjs.map +0 -1
- package/dist/Form-ylAr3o_e.js +0 -376
- package/dist/Form-ylAr3o_e.js.map +0 -1
- package/dist/components/index.cjs +0 -2
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.js.map +0 -1
- package/dist/forms-complex-BiQsZZlT.js +0 -361
- package/dist/forms-complex-BiQsZZlT.js.map +0 -1
- package/dist/forms-complex-DLEnXXJ5.cjs +0 -2
- package/dist/forms-complex-DLEnXXJ5.cjs.map +0 -1
- package/dist/forms-core-B1bx1drO.js +0 -839
- package/dist/forms-core-B1bx1drO.js.map +0 -1
- package/dist/forms-core-W_JGVLAI.cjs +0 -9
- package/dist/forms-core-W_JGVLAI.cjs.map +0 -1
- package/dist/forms-inputs-6QdeMWFk.js +0 -1075
- package/dist/forms-inputs-6QdeMWFk.js.map +0 -1
- package/dist/forms-inputs-DQ5QI_SU.cjs +0 -2
- package/dist/forms-inputs-DQ5QI_SU.cjs.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/state/index.cjs +0 -2
- package/dist/state/index.cjs.map +0 -1
- package/dist/state/index.js.map +0 -1
- package/dist/validation/index.cjs +0 -2
- package/dist/validation/index.cjs.map +0 -1
- package/dist/validation/index.js.map +0 -1
package/dist/components/index.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C as l, a as r, c as F, d as t, D as m, E as C, N as S, P as c, e as x, f as b, R as h, b as p, h as f, g as u, S as P, T as R, i as T, j as N, U } from "../forms-inputs-6QdeMWFk.js";
|
|
3
|
-
import { C as n, M as w, S as D } from "../forms-complex-BiQsZZlT.js";
|
|
1
|
+
import { C as s, c as i, g as l, e as o, h as d, D as F, E as r, F as t, a as m, b as c, M as C, N as S, P as b, i as h, j as x, R as u, d as P, l as R, k as T, f as k, S as n, T as p, m as N, n as U, U as f } from "../TextField-CGBM3x7K.js";
|
|
4
2
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
s as Checkbox,
|
|
4
|
+
i as CheckboxGroup,
|
|
5
|
+
l as ColorField,
|
|
6
|
+
o as Combobox,
|
|
7
|
+
d as CreditCardField,
|
|
8
|
+
F as DateField,
|
|
9
|
+
r as EmailField,
|
|
10
|
+
t as Form,
|
|
11
|
+
m as FormSection,
|
|
12
|
+
c as FormUtils,
|
|
13
|
+
C as MultiSelect,
|
|
16
14
|
S as NumberField,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
b as PasswordField,
|
|
16
|
+
h as PhoneField,
|
|
17
|
+
x as PostalCodeField,
|
|
18
|
+
u as Radio,
|
|
19
|
+
P as RadioGroup,
|
|
20
|
+
R as SSNField,
|
|
21
|
+
T as SearchField,
|
|
22
|
+
k as Select,
|
|
23
|
+
n as Switch,
|
|
24
|
+
p as TextArea,
|
|
25
|
+
N as TextField,
|
|
26
|
+
U as TimeField,
|
|
27
|
+
f as URLField
|
|
30
28
|
};
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { b as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { S as k, M as G, C as H } from "./forms-complex-BiQsZZlT.js";
|
|
1
|
+
import { o as n, p as d, F as c, a as m, m as u, E as g, P as f, k as p, U as F, i as h, N as v, h as N, l as b, j as I, T as S, D as V, n as x, g as y, C as R, S as A, c as C, R as T, d as P, f as L, M as D, e as E } from "./TextField-CGBM3x7K.js";
|
|
2
|
+
import { b as K } from "./TextField-CGBM3x7K.js";
|
|
3
|
+
import { createFormState as _, createField as M, createMultiStepFormState as U } from "./state/index.js";
|
|
4
|
+
import { defaultMessageFormatter as w, ValidationPresets as $, CrossFieldValidators as k, registerFormsValidators as G, getValidationRules as H } from "./validation/index.js";
|
|
5
|
+
import { FormsComponentValidation as J, FormsValidationError as Y, VALIDATION_RULES as ee, ValidationMessageFormatter as te, ValidationUtils as re, createDebouncedValidator as ae, createFormsValidators as se, registerValidationRule as ie, unregisterValidationRule as oe, validateField as le, validateValue as ne, validateValueAsync as de } from "./validation/index.js";
|
|
7
6
|
const O = {
|
|
8
7
|
/**
|
|
9
8
|
* Email validation
|
|
@@ -246,138 +245,137 @@ const O = {
|
|
|
246
245
|
const t = (r, a, o) => {
|
|
247
246
|
e.registerComponent(r, a, o);
|
|
248
247
|
};
|
|
249
|
-
t("Form",
|
|
248
|
+
t("Form", c, {
|
|
250
249
|
category: "forms",
|
|
251
250
|
tags: ["form", "container", "validation"]
|
|
252
|
-
}), t("FormSection",
|
|
251
|
+
}), t("FormSection", m, {
|
|
253
252
|
category: "forms",
|
|
254
253
|
tags: ["form", "section", "fieldset"]
|
|
255
|
-
}), t("TextField",
|
|
254
|
+
}), t("TextField", u, {
|
|
256
255
|
category: "forms",
|
|
257
256
|
tags: ["input", "text", "validation"]
|
|
258
|
-
}), t("EmailField",
|
|
257
|
+
}), t("EmailField", g, {
|
|
259
258
|
category: "forms",
|
|
260
259
|
tags: ["input", "email", "validation"]
|
|
261
|
-
}), t("PasswordField",
|
|
260
|
+
}), t("PasswordField", f, {
|
|
262
261
|
category: "forms",
|
|
263
262
|
tags: ["input", "password", "validation"]
|
|
264
|
-
}), t("SearchField",
|
|
263
|
+
}), t("SearchField", p, {
|
|
265
264
|
category: "forms",
|
|
266
265
|
tags: ["input", "search"]
|
|
267
|
-
}), t("URLField",
|
|
266
|
+
}), t("URLField", F, {
|
|
268
267
|
category: "forms",
|
|
269
268
|
tags: ["input", "url", "validation"]
|
|
270
|
-
}), t("PhoneField",
|
|
269
|
+
}), t("PhoneField", h, {
|
|
271
270
|
category: "forms",
|
|
272
271
|
tags: ["input", "phone", "validation"]
|
|
273
|
-
}), t("NumberField",
|
|
272
|
+
}), t("NumberField", v, {
|
|
274
273
|
category: "forms",
|
|
275
274
|
tags: ["input", "number", "numeric", "validation"]
|
|
276
|
-
}), t("CreditCardField",
|
|
275
|
+
}), t("CreditCardField", N, {
|
|
277
276
|
category: "forms",
|
|
278
277
|
tags: ["input", "credit-card", "payment", "validation"]
|
|
279
|
-
}), t("SSNField",
|
|
278
|
+
}), t("SSNField", b, {
|
|
280
279
|
category: "forms",
|
|
281
280
|
tags: ["input", "ssn", "social-security", "validation"]
|
|
282
|
-
}), t("PostalCodeField",
|
|
281
|
+
}), t("PostalCodeField", I, {
|
|
283
282
|
category: "forms",
|
|
284
283
|
tags: ["input", "postal-code", "zip", "validation"]
|
|
285
|
-
}), t("TextArea",
|
|
284
|
+
}), t("TextArea", S, {
|
|
286
285
|
category: "forms",
|
|
287
286
|
tags: ["input", "textarea", "multiline"]
|
|
288
|
-
}), t("DateField",
|
|
287
|
+
}), t("DateField", V, {
|
|
289
288
|
category: "forms",
|
|
290
289
|
tags: ["input", "date", "calendar", "validation"]
|
|
291
|
-
}), t("TimeField",
|
|
290
|
+
}), t("TimeField", x, {
|
|
292
291
|
category: "forms",
|
|
293
292
|
tags: ["input", "time", "clock", "validation"]
|
|
294
|
-
}), t("ColorField",
|
|
293
|
+
}), t("ColorField", y, {
|
|
295
294
|
category: "forms",
|
|
296
295
|
tags: ["input", "color", "picker"]
|
|
297
|
-
}), t("Checkbox",
|
|
296
|
+
}), t("Checkbox", R, {
|
|
298
297
|
category: "forms",
|
|
299
298
|
tags: ["input", "checkbox", "boolean"]
|
|
300
|
-
}), t("Switch",
|
|
299
|
+
}), t("Switch", A, {
|
|
301
300
|
category: "forms",
|
|
302
301
|
tags: ["input", "switch", "toggle", "boolean"]
|
|
303
|
-
}), t("CheckboxGroup",
|
|
302
|
+
}), t("CheckboxGroup", C, {
|
|
304
303
|
category: "forms",
|
|
305
304
|
tags: ["input", "checkbox", "group", "multiple"]
|
|
306
|
-
}), t("Radio",
|
|
305
|
+
}), t("Radio", T, {
|
|
307
306
|
category: "forms",
|
|
308
307
|
tags: ["input", "radio", "choice"]
|
|
309
|
-
}), t("RadioGroup",
|
|
308
|
+
}), t("RadioGroup", P, {
|
|
310
309
|
category: "forms",
|
|
311
310
|
tags: ["input", "radio", "group", "choice"]
|
|
312
|
-
}), t("Select",
|
|
311
|
+
}), t("Select", L, {
|
|
313
312
|
category: "forms",
|
|
314
313
|
tags: ["input", "select", "dropdown", "choice"]
|
|
315
|
-
}), t("MultiSelect",
|
|
314
|
+
}), t("MultiSelect", D, {
|
|
316
315
|
category: "forms",
|
|
317
316
|
tags: ["input", "select", "multiple", "choice"]
|
|
318
|
-
}), t("Combobox",
|
|
317
|
+
}), t("Combobox", E, {
|
|
319
318
|
category: "forms",
|
|
320
319
|
tags: ["input", "combobox", "search", "choice"]
|
|
321
320
|
}), e.registerService("formsConfig", {
|
|
322
321
|
theme: "default",
|
|
323
322
|
validation: {},
|
|
324
323
|
accessibility: {}
|
|
325
|
-
}), e.registerService("validationMessageFormatter",
|
|
324
|
+
}), e.registerService("validationMessageFormatter", w), e.registerService("createFormState", _), e.registerService("createField", M), e.registerService("createMultiStepFormState", U), e.registerService("ValidationPresets", $), e.registerService("CrossFieldValidators", k), e.registerService("TextFieldFormatters", n), e.registerService("TextFieldParsers", d), e.registerService("TextFieldValidators", O), await G(), console.log("📝 TachUI Forms plugin installed successfully"), console.log(" • 24 form components (including enhanced TextField variants)"), console.log(` • ${H().length} validation rules`), console.log(" • TextField formatters and validators included");
|
|
326
325
|
},
|
|
327
326
|
async uninstall() {
|
|
328
327
|
console.log("📝 TachUI Forms plugin uninstalled");
|
|
329
328
|
}
|
|
330
|
-
},
|
|
329
|
+
}, B = async (e) => z.install(e);
|
|
331
330
|
export {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
331
|
+
R as Checkbox,
|
|
332
|
+
C as CheckboxGroup,
|
|
333
|
+
y as ColorField,
|
|
334
|
+
E as Combobox,
|
|
335
|
+
N as CreditCardField,
|
|
336
|
+
k as CrossFieldValidators,
|
|
337
|
+
V as DateField,
|
|
338
|
+
g as EmailField,
|
|
339
|
+
c as Form,
|
|
340
|
+
m as FormSection,
|
|
341
|
+
K as FormUtils,
|
|
342
|
+
J as FormsComponentValidation,
|
|
343
|
+
Y as FormsValidationError,
|
|
344
|
+
D as MultiSelect,
|
|
345
|
+
v as NumberField,
|
|
346
|
+
f as PasswordField,
|
|
347
|
+
h as PhoneField,
|
|
348
|
+
I as PostalCodeField,
|
|
349
|
+
T as Radio,
|
|
350
|
+
P as RadioGroup,
|
|
351
|
+
b as SSNField,
|
|
352
|
+
p as SearchField,
|
|
353
|
+
L as Select,
|
|
354
|
+
A as Switch,
|
|
355
|
+
S as TextArea,
|
|
356
|
+
u as TextField,
|
|
357
|
+
n as TextFieldFormatters,
|
|
358
|
+
d as TextFieldParsers,
|
|
360
359
|
O as TextFieldValidators,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
360
|
+
x as TimeField,
|
|
361
|
+
F as URLField,
|
|
362
|
+
ee as VALIDATION_RULES,
|
|
363
|
+
te as ValidationMessageFormatter,
|
|
364
|
+
$ as ValidationPresets,
|
|
365
|
+
re as ValidationUtils,
|
|
366
|
+
ae as createDebouncedValidator,
|
|
367
|
+
M as createField,
|
|
368
|
+
_ as createFormState,
|
|
369
|
+
se as createFormsValidators,
|
|
370
|
+
U as createMultiStepFormState,
|
|
372
371
|
z as default,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
372
|
+
w as defaultMessageFormatter,
|
|
373
|
+
H as getValidationRules,
|
|
374
|
+
B as installFormsPlugin,
|
|
375
|
+
G as registerFormsValidators,
|
|
376
|
+
ie as registerValidationRule,
|
|
377
|
+
oe as unregisterValidationRule,
|
|
378
|
+
le as validateField,
|
|
379
|
+
ne as validateValue,
|
|
380
|
+
de as validateValueAsync
|
|
382
381
|
};
|
|
383
|
-
//# sourceMappingURL=index.js.map
|
package/dist/state/index.js
CHANGED
|
@@ -1,9 +1,242 @@
|
|
|
1
|
-
import "@tachui/core";
|
|
2
|
-
import {
|
|
1
|
+
import { createSignal as v, createComputed as O, createEffect as C } from "@tachui/core";
|
|
2
|
+
import { validateValueAsync as k } from "../validation/index.js";
|
|
3
|
+
function P(c) {
|
|
4
|
+
const [r, n] = v(c), [s, l] = v(void 0), [h, g] = v(!1), [u, p] = v(!1), [V, E] = v(!1), [F, b] = v(!1);
|
|
5
|
+
C(() => {
|
|
6
|
+
r() !== c && p(!0);
|
|
7
|
+
});
|
|
8
|
+
const a = O(() => !s());
|
|
9
|
+
return {
|
|
10
|
+
state: O(
|
|
11
|
+
() => ({
|
|
12
|
+
value: r(),
|
|
13
|
+
error: s(),
|
|
14
|
+
touched: h(),
|
|
15
|
+
dirty: u(),
|
|
16
|
+
valid: a(),
|
|
17
|
+
validating: F(),
|
|
18
|
+
focused: V()
|
|
19
|
+
})
|
|
20
|
+
),
|
|
21
|
+
setValue: (i) => {
|
|
22
|
+
n(i), p(i !== c), h();
|
|
23
|
+
},
|
|
24
|
+
setError: l,
|
|
25
|
+
setTouched: g,
|
|
26
|
+
setFocused: E,
|
|
27
|
+
setValidating: b
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function $(c = {}) {
|
|
31
|
+
const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), [s, l] = v(!1), [h, g] = v(!1);
|
|
32
|
+
Object.keys(c).forEach((t) => {
|
|
33
|
+
const e = P(c[t]);
|
|
34
|
+
r.set(t, e);
|
|
35
|
+
});
|
|
36
|
+
const u = O(() => {
|
|
37
|
+
const t = {}, e = {}, o = {};
|
|
38
|
+
let m = !0, d = !1;
|
|
39
|
+
for (const [_, w] of r) {
|
|
40
|
+
const M = w.state();
|
|
41
|
+
t[_] = M, M.error && (e[_] = M.error, m = !1), M.touched && (o[_] = !0), M.dirty && (d = !0);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
fields: t,
|
|
45
|
+
valid: m,
|
|
46
|
+
dirty: d,
|
|
47
|
+
submitting: s(),
|
|
48
|
+
submitted: h(),
|
|
49
|
+
errors: e,
|
|
50
|
+
touched: o
|
|
51
|
+
};
|
|
52
|
+
}), p = (t, e) => {
|
|
53
|
+
if (r.has(t)) {
|
|
54
|
+
e && n.set(t, e);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const o = P(c[t]);
|
|
58
|
+
if (r.set(t, o), e && n.set(t, e), e) {
|
|
59
|
+
const m = o.state;
|
|
60
|
+
C(async () => {
|
|
61
|
+
const d = m();
|
|
62
|
+
if ((e.validateOn === "change" || e.validateOn === "blur" && d.touched || e.validateOn === "submit" && h()) && (d.dirty || d.touched)) {
|
|
63
|
+
o.setValidating(!0);
|
|
64
|
+
try {
|
|
65
|
+
const w = await T(d, e);
|
|
66
|
+
o.setError(w.valid ? void 0 : w.message);
|
|
67
|
+
} catch {
|
|
68
|
+
o.setError("Validation error occurred");
|
|
69
|
+
} finally {
|
|
70
|
+
o.setValidating(!1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, V = (t) => {
|
|
76
|
+
r.delete(t), n.delete(t);
|
|
77
|
+
}, E = (t, e) => {
|
|
78
|
+
const o = r.get(t);
|
|
79
|
+
o && o.setValue(e);
|
|
80
|
+
}, F = (t) => r.get(t)?.state().value, b = (t) => r.get(t)?.state().error, a = async (t) => {
|
|
81
|
+
const e = r.get(t), o = n.get(t);
|
|
82
|
+
if (!e || !o)
|
|
83
|
+
return !0;
|
|
84
|
+
const m = e.state();
|
|
85
|
+
e.setValidating(!0);
|
|
86
|
+
try {
|
|
87
|
+
const d = await T(m, o);
|
|
88
|
+
return e.setError(d.valid ? void 0 : d.message), d.valid;
|
|
89
|
+
} catch {
|
|
90
|
+
return e.setError("Validation error occurred"), !1;
|
|
91
|
+
} finally {
|
|
92
|
+
e.setValidating(!1);
|
|
93
|
+
}
|
|
94
|
+
}, f = async () => {
|
|
95
|
+
const t = Array.from(r.keys()).map(a);
|
|
96
|
+
return (await Promise.all(t)).every((o) => o);
|
|
97
|
+
}, i = () => {
|
|
98
|
+
for (const [t, e] of r)
|
|
99
|
+
e.setValue(c[t]), e.setError(void 0), e.setTouched(!1), e.setFocused(!1), e.setValidating(!1);
|
|
100
|
+
l(!1), g(!1);
|
|
101
|
+
}, y = async (t) => {
|
|
102
|
+
l(!0), g(!0);
|
|
103
|
+
try {
|
|
104
|
+
if (await f() && t) {
|
|
105
|
+
const o = {};
|
|
106
|
+
for (const [m, d] of r)
|
|
107
|
+
o[m] = d.state().value;
|
|
108
|
+
await t(o, u());
|
|
109
|
+
}
|
|
110
|
+
} finally {
|
|
111
|
+
l(!1);
|
|
112
|
+
}
|
|
113
|
+
}, S = (t) => {
|
|
114
|
+
const e = {}, o = t || Array.from(r.keys());
|
|
115
|
+
for (const m of o)
|
|
116
|
+
r.has(m) && (e[m] = F(m));
|
|
117
|
+
return e;
|
|
118
|
+
}, A = async (t) => {
|
|
119
|
+
const o = (t || Array.from(r.keys())).map(a);
|
|
120
|
+
return (await Promise.all(o)).every((d) => d);
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
fields: u().fields,
|
|
124
|
+
state: u(),
|
|
125
|
+
register: p,
|
|
126
|
+
unregister: V,
|
|
127
|
+
setValue: E,
|
|
128
|
+
getValue: F,
|
|
129
|
+
getError: b,
|
|
130
|
+
validateField: a,
|
|
131
|
+
validateForm: f,
|
|
132
|
+
resetForm: i,
|
|
133
|
+
submitForm: y,
|
|
134
|
+
watch: S,
|
|
135
|
+
trigger: A
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
async function T(c, r) {
|
|
139
|
+
return !r.rules || r.rules.length === 0 ? { valid: !0 } : r.debounceMs ? new Promise((n) => {
|
|
140
|
+
setTimeout(async () => {
|
|
141
|
+
const s = await k(c.value, r.rules);
|
|
142
|
+
n(s);
|
|
143
|
+
}, r.debounceMs);
|
|
144
|
+
}) : k(c.value, r.rules);
|
|
145
|
+
}
|
|
146
|
+
function B(c, r, n) {
|
|
147
|
+
const s = P(r), l = s.state;
|
|
148
|
+
n && C(async () => {
|
|
149
|
+
const u = l();
|
|
150
|
+
if ((n.validateOn === "change" || n.validateOn === "blur" && u.touched) && (u.dirty || u.touched)) {
|
|
151
|
+
s.setValidating(!0);
|
|
152
|
+
try {
|
|
153
|
+
const V = await T(u, n);
|
|
154
|
+
s.setError(V.valid ? void 0 : V.message);
|
|
155
|
+
} catch {
|
|
156
|
+
s.setError("Validation error occurred");
|
|
157
|
+
} finally {
|
|
158
|
+
s.setValidating(!1);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const h = async () => {
|
|
163
|
+
if (!n) return !0;
|
|
164
|
+
s.setValidating(!0);
|
|
165
|
+
try {
|
|
166
|
+
const u = await T(l(), n);
|
|
167
|
+
return s.setError(u.valid ? void 0 : u.message), u.valid;
|
|
168
|
+
} catch {
|
|
169
|
+
return s.setError("Validation error occurred"), !1;
|
|
170
|
+
} finally {
|
|
171
|
+
s.setValidating(!1);
|
|
172
|
+
}
|
|
173
|
+
}, g = () => {
|
|
174
|
+
s.setValue(r), s.setError(void 0), s.setTouched(!1), s.setFocused(!1), s.setValidating(!1);
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
value: () => l().value,
|
|
178
|
+
setValue: s.setValue,
|
|
179
|
+
error: () => l().error,
|
|
180
|
+
touched: () => l().touched,
|
|
181
|
+
dirty: () => l().dirty,
|
|
182
|
+
valid: () => l().valid,
|
|
183
|
+
validating: () => l().validating,
|
|
184
|
+
focused: () => l().focused,
|
|
185
|
+
onFocus: () => {
|
|
186
|
+
s.setFocused(!0);
|
|
187
|
+
},
|
|
188
|
+
onBlur: () => {
|
|
189
|
+
s.setFocused(!1), s.setTouched(!0);
|
|
190
|
+
},
|
|
191
|
+
validate: h,
|
|
192
|
+
reset: g
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function D(c, r = {}) {
|
|
196
|
+
const [n, s] = v(0), [l, h] = v(/* @__PURE__ */ new Set()), g = /* @__PURE__ */ new Map();
|
|
197
|
+
return c.forEach((a, f) => {
|
|
198
|
+
const i = Object.keys(r).filter((y) => y.startsWith(`step_${f}_`)).reduce(
|
|
199
|
+
(y, S) => {
|
|
200
|
+
const A = S.replace(`step_${f}_`, "");
|
|
201
|
+
return y[A] = r[S], y;
|
|
202
|
+
},
|
|
203
|
+
{}
|
|
204
|
+
);
|
|
205
|
+
g.set(f, $(i));
|
|
206
|
+
}), {
|
|
207
|
+
currentStep: n,
|
|
208
|
+
completedSteps: l,
|
|
209
|
+
nextStep: async (a = !0) => {
|
|
210
|
+
const f = n(), i = g.get(f);
|
|
211
|
+
return a && i && !await i.validateForm() ? !1 : f < c.length - 1 ? (h((y) => /* @__PURE__ */ new Set([...y, f])), s(f + 1), !0) : !1;
|
|
212
|
+
},
|
|
213
|
+
previousStep: () => {
|
|
214
|
+
const a = n();
|
|
215
|
+
return a > 0 ? (s(a - 1), !0) : !1;
|
|
216
|
+
},
|
|
217
|
+
goToStep: (a) => a >= 0 && a < c.length ? (s(a), !0) : !1,
|
|
218
|
+
getCurrentForm: () => g.get(n()),
|
|
219
|
+
getAllValues: () => {
|
|
220
|
+
const a = {};
|
|
221
|
+
return g.forEach((f, i) => {
|
|
222
|
+
const y = f.watch();
|
|
223
|
+
Object.keys(y).forEach((S) => {
|
|
224
|
+
a[`step_${i}_${S}`] = y[S];
|
|
225
|
+
});
|
|
226
|
+
}), a;
|
|
227
|
+
},
|
|
228
|
+
validateAllSteps: async () => {
|
|
229
|
+
const a = Array.from(g.values()).map((i) => i.validateForm());
|
|
230
|
+
return (await Promise.all(a)).every((i) => i);
|
|
231
|
+
},
|
|
232
|
+
getStepForm: (a) => g.get(a),
|
|
233
|
+
isStepCompleted: (a) => l().has(a),
|
|
234
|
+
canGoToStep: (a) => a <= n() || l().has(a)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
3
237
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
238
|
+
B as createField,
|
|
239
|
+
$ as createFormState,
|
|
240
|
+
D as createMultiStepFormState,
|
|
241
|
+
k as validateValueAsync
|
|
8
242
|
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|