@neutro/form 0.0.5 → 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/dist/adapters/angular.cjs +24 -6
- package/dist/adapters/angular.d.cts +163 -19
- package/dist/adapters/angular.d.ts +163 -19
- package/dist/adapters/angular.js +25 -7
- package/dist/adapters/react.cjs +5 -1
- package/dist/adapters/react.d.cts +86 -5
- package/dist/adapters/react.d.ts +86 -5
- package/dist/adapters/react.js +6 -2
- package/dist/adapters/solid.cjs +12 -3
- package/dist/adapters/solid.d.cts +161 -16
- package/dist/adapters/solid.d.ts +161 -16
- package/dist/adapters/solid.js +12 -3
- package/dist/adapters/svelte.cjs +18 -9
- package/dist/adapters/svelte.d.cts +161 -17
- package/dist/adapters/svelte.d.ts +161 -17
- package/dist/adapters/svelte.js +18 -9
- package/dist/adapters/vue.cjs +15 -4
- package/dist/adapters/vue.d.cts +161 -17
- package/dist/adapters/vue.d.ts +161 -17
- package/dist/adapters/vue.js +23 -5
- package/dist/chunk-FDAQJJJ7.js +657 -0
- package/dist/core.cjs +510 -425
- package/dist/core.d.cts +94 -7
- package/dist/core.d.ts +94 -7
- package/dist/core.js +24 -569
- package/dist/devtools.cjs +244 -0
- package/dist/devtools.d.cts +141 -0
- package/dist/devtools.d.ts +141 -0
- package/dist/devtools.js +217 -0
- package/dist/testing.cjs +667 -0
- package/dist/testing.d.cts +254 -0
- package/dist/testing.d.ts +254 -0
- package/dist/testing.js +39 -0
- package/package.json +25 -7
package/dist/core.cjs
CHANGED
|
@@ -20,577 +20,662 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/core.ts
|
|
21
21
|
var core_exports = {};
|
|
22
22
|
__export(core_exports, {
|
|
23
|
-
classValidatorAdapter: () =>
|
|
24
|
-
compileDependencyScopes: () =>
|
|
25
|
-
createForm: () =>
|
|
26
|
-
deepClone: () =>
|
|
27
|
-
extractAllPaths: () =>
|
|
28
|
-
getNestedValue: () =>
|
|
29
|
-
isDeepEqual: () =>
|
|
30
|
-
setNestedValue: () =>
|
|
31
|
-
valibotAdapter: () =>
|
|
32
|
-
yupAdapter: () =>
|
|
33
|
-
zodAdapter: () =>
|
|
23
|
+
classValidatorAdapter: () => ye,
|
|
24
|
+
compileDependencyScopes: () => fe,
|
|
25
|
+
createForm: () => be,
|
|
26
|
+
deepClone: () => x,
|
|
27
|
+
extractAllPaths: () => Y,
|
|
28
|
+
getNestedValue: () => S,
|
|
29
|
+
isDeepEqual: () => F,
|
|
30
|
+
setNestedValue: () => W,
|
|
31
|
+
valibotAdapter: () => pe,
|
|
32
|
+
yupAdapter: () => he,
|
|
33
|
+
zodAdapter: () => me
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(core_exports);
|
|
36
36
|
|
|
37
37
|
// ../core/dist/index.js
|
|
38
|
-
function
|
|
39
|
-
return (
|
|
40
|
-
let l =
|
|
38
|
+
function me(n) {
|
|
39
|
+
return (f) => {
|
|
40
|
+
let l = n.safeParse(f);
|
|
41
41
|
if (l.success) return {};
|
|
42
42
|
let a = {};
|
|
43
|
-
return l.error.issues.forEach((
|
|
44
|
-
a[
|
|
43
|
+
return l.error.issues.forEach((u) => {
|
|
44
|
+
a[u.path.join(".")] = u.message;
|
|
45
45
|
}), a;
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
return (
|
|
50
|
-
let l =
|
|
48
|
+
function pe(n) {
|
|
49
|
+
return (f) => {
|
|
50
|
+
let l = n.safeParse(f);
|
|
51
51
|
if (l.success) return {};
|
|
52
52
|
let a = {};
|
|
53
|
-
return (l.issues ?? []).forEach((
|
|
54
|
-
let
|
|
55
|
-
|
|
53
|
+
return (l.issues ?? []).forEach((u) => {
|
|
54
|
+
let d = u.path.map((p) => String(p.key)).join(".");
|
|
55
|
+
d && (a[d] = u.message);
|
|
56
56
|
}), a;
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return async (
|
|
59
|
+
function he(n) {
|
|
60
|
+
return async (f) => {
|
|
61
61
|
try {
|
|
62
|
-
return await
|
|
62
|
+
return await n.validate(f, { abortEarly: false }), {};
|
|
63
63
|
} catch (l) {
|
|
64
64
|
let a = {};
|
|
65
|
-
return l.inner && Array.isArray(l.inner) && l.inner.length > 0 ? l.inner.forEach((
|
|
66
|
-
|
|
65
|
+
return l.inner && Array.isArray(l.inner) && l.inner.length > 0 ? l.inner.forEach((u) => {
|
|
66
|
+
u.path && !a[u.path] && (a[u.path] = u.message);
|
|
67
67
|
}) : l.path && (a[l.path] = l.message), a;
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function ye(n, f) {
|
|
72
72
|
return async (l) => {
|
|
73
|
-
let a = Object.assign(new
|
|
74
|
-
return
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
}),
|
|
73
|
+
let a = Object.assign(new n(), l), u = await f(a), d = {};
|
|
74
|
+
return u.forEach((p) => {
|
|
75
|
+
let N = p.constraints ? Object.values(p.constraints) : [];
|
|
76
|
+
N.length > 0 && (d[p.property] = N[0]);
|
|
77
|
+
}), d;
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
84
|
-
if (typeof File < "u" &&
|
|
85
|
-
if (
|
|
86
|
-
if (
|
|
80
|
+
function x(n, f = /* @__PURE__ */ new WeakMap()) {
|
|
81
|
+
if (n == null || typeof n != "object") return n;
|
|
82
|
+
if (n instanceof Date) return new Date(n.getTime());
|
|
83
|
+
if (n instanceof RegExp) return new RegExp(n.source, n.flags);
|
|
84
|
+
if (typeof File < "u" && n instanceof File) return n;
|
|
85
|
+
if (f.has(n)) return f.get(n);
|
|
86
|
+
if (n instanceof Set) {
|
|
87
87
|
let a = /* @__PURE__ */ new Set();
|
|
88
|
-
|
|
88
|
+
f.set(n, a);
|
|
89
|
+
for (let u of n) a.add(x(u, f));
|
|
90
|
+
return a;
|
|
89
91
|
}
|
|
90
|
-
if (
|
|
92
|
+
if (n instanceof Map) {
|
|
91
93
|
let a = /* @__PURE__ */ new Map();
|
|
92
|
-
|
|
94
|
+
f.set(n, a);
|
|
95
|
+
for (let [u, d] of n) a.set(u, x(d, f));
|
|
96
|
+
return a;
|
|
93
97
|
}
|
|
94
|
-
if (Array.isArray(
|
|
95
|
-
let a = new Array(
|
|
96
|
-
|
|
97
|
-
for (let
|
|
98
|
+
if (Array.isArray(n)) {
|
|
99
|
+
let a = new Array(n.length);
|
|
100
|
+
f.set(n, a);
|
|
101
|
+
for (let u = 0; u < n.length; u++) a[u] = x(n[u], f);
|
|
98
102
|
return a;
|
|
99
103
|
}
|
|
100
|
-
let l = Object.create(Object.getPrototypeOf(
|
|
101
|
-
|
|
102
|
-
for (let a of Reflect.ownKeys(
|
|
103
|
-
let
|
|
104
|
-
|
|
104
|
+
let l = Object.create(Object.getPrototypeOf(n));
|
|
105
|
+
f.set(n, l);
|
|
106
|
+
for (let a of Reflect.ownKeys(n)) {
|
|
107
|
+
let u = Object.getOwnPropertyDescriptor(n, a);
|
|
108
|
+
u && Object.defineProperty(l, a, { ...u, value: x(n[a], f) });
|
|
105
109
|
}
|
|
106
110
|
return l;
|
|
107
111
|
}
|
|
108
|
-
function
|
|
109
|
-
let l =
|
|
110
|
-
for (let
|
|
112
|
+
function S(n, f) {
|
|
113
|
+
let l = f.split("."), a = n;
|
|
114
|
+
for (let u of l) {
|
|
111
115
|
if (a == null) return;
|
|
112
|
-
a = a[
|
|
116
|
+
a = a[u];
|
|
113
117
|
}
|
|
114
118
|
return a;
|
|
115
119
|
}
|
|
116
|
-
function
|
|
117
|
-
let a =
|
|
118
|
-
for (let
|
|
119
|
-
let
|
|
120
|
-
(!(
|
|
120
|
+
function W(n, f, l) {
|
|
121
|
+
let a = f.split("."), u = n;
|
|
122
|
+
for (let d = 0; d < a.length - 1; d++) {
|
|
123
|
+
let p = a[d], N = a[d + 1];
|
|
124
|
+
(!(p in u) || u[p] === null || typeof u[p] != "object") && (u[p] = Number.isNaN(Number(N)) ? {} : []), u = u[p];
|
|
121
125
|
}
|
|
122
|
-
|
|
126
|
+
u[a[a.length - 1]] = l;
|
|
123
127
|
}
|
|
124
|
-
function
|
|
125
|
-
if (
|
|
126
|
-
if (
|
|
127
|
-
if (
|
|
128
|
-
if (typeof
|
|
129
|
-
if (l.has(
|
|
130
|
-
if (l.set(
|
|
131
|
-
if (
|
|
132
|
-
for (let
|
|
128
|
+
function F(n, f, l = /* @__PURE__ */ new WeakMap()) {
|
|
129
|
+
if (n === f) return true;
|
|
130
|
+
if (n instanceof Date && f instanceof Date) return n.getTime() === f.getTime();
|
|
131
|
+
if (n instanceof RegExp && f instanceof RegExp) return n.toString() === f.toString();
|
|
132
|
+
if (typeof n != "object" || typeof f != "object" || n === null || f === null) return false;
|
|
133
|
+
if (l.has(n) && l.get(n) === f) return true;
|
|
134
|
+
if (l.set(n, f), n instanceof Set && f instanceof Set) {
|
|
135
|
+
if (n.size !== f.size) return false;
|
|
136
|
+
for (let d of n) if (!f.has(d)) return false;
|
|
133
137
|
return true;
|
|
134
138
|
}
|
|
135
|
-
if (
|
|
136
|
-
if (
|
|
137
|
-
for (let [
|
|
139
|
+
if (n instanceof Map && f instanceof Map) {
|
|
140
|
+
if (n.size !== f.size) return false;
|
|
141
|
+
for (let [d, p] of n) if (!f.has(d) || !F(p, f.get(d), l)) return false;
|
|
138
142
|
return true;
|
|
139
143
|
}
|
|
140
|
-
let a = Reflect.ownKeys(
|
|
141
|
-
if (a.length !==
|
|
142
|
-
for (let
|
|
144
|
+
let a = Reflect.ownKeys(n), u = new Set(Reflect.ownKeys(f));
|
|
145
|
+
if (a.length !== u.size) return false;
|
|
146
|
+
for (let d of a) if (!u.has(d) || !F(n[d], f[d], l)) return false;
|
|
143
147
|
return true;
|
|
144
148
|
}
|
|
145
|
-
function
|
|
146
|
-
if (
|
|
149
|
+
function Y(n, f = "") {
|
|
150
|
+
if (n === null || typeof n != "object" || n instanceof Date || typeof File < "u" && n instanceof File) return f ? [f] : [];
|
|
147
151
|
let l = [];
|
|
148
|
-
|
|
149
|
-
for (let a in
|
|
150
|
-
let
|
|
151
|
-
Array.isArray(
|
|
152
|
-
l.push(...
|
|
153
|
-
})) : l.push(...
|
|
152
|
+
f && l.push(f);
|
|
153
|
+
for (let a in n) if (Object.hasOwn(n, a)) {
|
|
154
|
+
let u = f ? `${f}.${a}` : a;
|
|
155
|
+
Array.isArray(n[a]) ? (l.push(u), n[a].forEach((d, p) => {
|
|
156
|
+
l.push(...Y(d, `${u}.${p}`));
|
|
157
|
+
})) : l.push(...Y(n[a], u));
|
|
154
158
|
}
|
|
155
159
|
return l;
|
|
156
160
|
}
|
|
157
|
-
function
|
|
158
|
-
let l = {}, a =
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
let
|
|
162
|
-
|
|
161
|
+
function fe(n, f) {
|
|
162
|
+
let l = {}, a = Y(f), u = (d, p) => {
|
|
163
|
+
if (p.has(d)) return;
|
|
164
|
+
p.add(d);
|
|
165
|
+
let N = n[d];
|
|
166
|
+
if (N) for (let g of N) u(g, p);
|
|
163
167
|
};
|
|
164
|
-
return a.forEach((
|
|
165
|
-
let
|
|
166
|
-
|
|
167
|
-
}), Object.keys(
|
|
168
|
-
if (!l[
|
|
169
|
-
let
|
|
170
|
-
|
|
168
|
+
return a.forEach((d) => {
|
|
169
|
+
let p = /* @__PURE__ */ new Set();
|
|
170
|
+
u(d, p), l[d] = Array.from(p);
|
|
171
|
+
}), Object.keys(n).forEach((d) => {
|
|
172
|
+
if (!l[d]) {
|
|
173
|
+
let p = /* @__PURE__ */ new Set();
|
|
174
|
+
u(d, p), l[d] = Array.from(p);
|
|
171
175
|
}
|
|
172
176
|
}), l;
|
|
173
177
|
}
|
|
174
|
-
function
|
|
175
|
-
return
|
|
178
|
+
function de(n) {
|
|
179
|
+
return n == null || n === "" || typeof n == "string" && !n.trim() || Array.isArray(n) && n.length === 0;
|
|
176
180
|
}
|
|
177
|
-
function
|
|
178
|
-
if (
|
|
179
|
-
if (typeof
|
|
180
|
-
let
|
|
181
|
-
return isNaN(
|
|
181
|
+
function U(n) {
|
|
182
|
+
if (n instanceof Date) return Number.isNaN(n.getTime()) ? null : n;
|
|
183
|
+
if (typeof n == "string" || typeof n == "number") {
|
|
184
|
+
let f = new Date(n);
|
|
185
|
+
return Number.isNaN(f.getTime()) ? null : f;
|
|
182
186
|
}
|
|
183
187
|
return null;
|
|
184
188
|
}
|
|
185
|
-
function
|
|
186
|
-
let a = {},
|
|
187
|
-
for (let
|
|
188
|
-
let
|
|
189
|
-
if (!
|
|
190
|
-
let
|
|
191
|
-
for (let
|
|
192
|
-
let
|
|
193
|
-
if (
|
|
194
|
-
else if (
|
|
195
|
-
else if (
|
|
196
|
-
else if (
|
|
197
|
-
if (
|
|
198
|
-
let
|
|
199
|
-
(!["http:", "https:"].includes(
|
|
189
|
+
function ge(n, f, l) {
|
|
190
|
+
let a = {}, u = l ?? Object.keys(f);
|
|
191
|
+
for (let d of u) {
|
|
192
|
+
let p = f[d];
|
|
193
|
+
if (!p) continue;
|
|
194
|
+
let N = Array.isArray(p) ? p : [p], g = S(n, d), M = typeof g == "string" ? g : String(g ?? ""), w = Array.isArray(g) ? g : null, E = !de(g);
|
|
195
|
+
for (let i of N) {
|
|
196
|
+
let h = null;
|
|
197
|
+
if (i === "required") E || (h = "Required");
|
|
198
|
+
else if (i === "accepted") g !== true && g !== 1 && g !== "yes" && g !== "true" && (h = "This field must be accepted");
|
|
199
|
+
else if (i === "email") E && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(M) && (h = "Must be a valid email address");
|
|
200
|
+
else if (i === "url") {
|
|
201
|
+
if (E) try {
|
|
202
|
+
let A = new URL(M), L = A.hostname.split("."), k = A.hostname === "localhost" || L.length >= 2 && L.every((_) => _.length > 0);
|
|
203
|
+
(!["http:", "https:"].includes(A.protocol) || !k) && (h = "Must be a valid URL");
|
|
200
204
|
} catch {
|
|
201
|
-
|
|
205
|
+
h = "Must be a valid URL";
|
|
202
206
|
}
|
|
203
|
-
} else if (
|
|
204
|
-
else if (
|
|
205
|
-
else if (
|
|
206
|
-
else if (
|
|
207
|
-
else if (
|
|
208
|
-
else if (
|
|
209
|
-
else if (
|
|
210
|
-
else if (
|
|
211
|
-
else if (typeof
|
|
212
|
-
else if ("maxLength" in
|
|
213
|
-
else if ("min" in
|
|
214
|
-
else if ("max" in
|
|
215
|
-
else if ("startsWith" in
|
|
216
|
-
else if ("endsWith" in
|
|
217
|
-
else if ("includes" in
|
|
218
|
-
else if ("pattern" in
|
|
219
|
-
let
|
|
220
|
-
|
|
221
|
-
} else if ("minItems" in
|
|
222
|
-
else if ("maxItems" in
|
|
223
|
-
else if ("contains" in
|
|
224
|
-
else if ("oneOf" in
|
|
225
|
-
else if ("notOneOf" in
|
|
226
|
-
else if ("matches" in
|
|
227
|
-
let
|
|
228
|
-
|
|
229
|
-
} else if ("doesNotMatch" in
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
} else if ("greaterThan" in
|
|
233
|
-
let
|
|
234
|
-
|
|
235
|
-
} else if ("lessThan" in
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
} else if ("after" in
|
|
239
|
-
let
|
|
240
|
-
|
|
241
|
-
} else if ("before" in
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
} else "requiredIf" in
|
|
245
|
-
if (
|
|
246
|
-
a[
|
|
207
|
+
} else if (i === "numeric") E && Number.isNaN(Number(g)) && (h = "Must be a number");
|
|
208
|
+
else if (i === "integer") E && !Number.isInteger(Number(g)) && (h = "Must be a whole number");
|
|
209
|
+
else if (i === "positive") E && Number(g) <= 0 && (h = "Must be greater than zero");
|
|
210
|
+
else if (i === "nonNegative") E && Number(g) < 0 && (h = "Must be zero or greater");
|
|
211
|
+
else if (i === "alpha") E && !/^[a-zA-Z]+$/.test(M) && (h = "Must contain letters only");
|
|
212
|
+
else if (i === "alphanumeric") E && !/^[a-zA-Z0-9]+$/.test(M) && (h = "Must contain letters and numbers only");
|
|
213
|
+
else if (i === "date") E && U(g) === null && (h = "Must be a valid date");
|
|
214
|
+
else if (i === "unique") w && new Set(w.map((L) => JSON.stringify(L))).size !== w.length && (h = "All items must be unique");
|
|
215
|
+
else if (typeof i == "object") if ("minLength" in i) E && M.length < i.minLength && (h = i.message ?? `Must be at least ${i.minLength} character${i.minLength === 1 ? "" : "s"}`);
|
|
216
|
+
else if ("maxLength" in i) E && M.length > i.maxLength && (h = i.message ?? `Must be at most ${i.maxLength} character${i.maxLength === 1 ? "" : "s"}`);
|
|
217
|
+
else if ("min" in i) E && Number(g) < i.min && (h = i.message ?? `Must be at least ${i.min}`);
|
|
218
|
+
else if ("max" in i) E && Number(g) > i.max && (h = i.message ?? `Must be at most ${i.max}`);
|
|
219
|
+
else if ("startsWith" in i) E && !M.startsWith(i.startsWith) && (h = i.message ?? `Must start with "${i.startsWith}"`);
|
|
220
|
+
else if ("endsWith" in i) E && !M.endsWith(i.endsWith) && (h = i.message ?? `Must end with "${i.endsWith}"`);
|
|
221
|
+
else if ("includes" in i) E && !M.includes(i.includes) && (h = i.message ?? `Must contain "${i.includes}"`);
|
|
222
|
+
else if ("pattern" in i) {
|
|
223
|
+
let A = typeof i.pattern == "string" ? new RegExp(i.pattern) : i.pattern;
|
|
224
|
+
E && !A.test(M) && (h = i.message ?? "Invalid format");
|
|
225
|
+
} else if ("minItems" in i) (w ? w.length : 0) < i.minItems && (h = i.message ?? `Must have at least ${i.minItems} item${i.minItems === 1 ? "" : "s"}`);
|
|
226
|
+
else if ("maxItems" in i) (w ? w.length : 0) > i.maxItems && (h = i.message ?? `Must have at most ${i.maxItems} item${i.maxItems === 1 ? "" : "s"}`);
|
|
227
|
+
else if ("contains" in i) w?.some((A) => F(A, i.contains)) || (h = i.message ?? "Must contain the required value");
|
|
228
|
+
else if ("oneOf" in i) E && !i.oneOf.some((A) => F(g, A)) && (h = i.message ?? `Must be one of: ${i.oneOf.join(", ")}`);
|
|
229
|
+
else if ("notOneOf" in i) E && i.notOneOf.some((A) => F(g, A)) && (h = i.message ?? `Must not be one of: ${i.notOneOf.join(", ")}`);
|
|
230
|
+
else if ("matches" in i) {
|
|
231
|
+
let A = S(n, i.matches);
|
|
232
|
+
F(g, A) || (h = i.message ?? "Values do not match");
|
|
233
|
+
} else if ("doesNotMatch" in i) {
|
|
234
|
+
let A = S(n, i.doesNotMatch);
|
|
235
|
+
F(g, A) && (h = i.message ?? "Values must not match");
|
|
236
|
+
} else if ("greaterThan" in i) {
|
|
237
|
+
let A = Number(S(n, i.greaterThan));
|
|
238
|
+
E && Number(g) <= A && (h = i.message ?? `Must be greater than ${A}`);
|
|
239
|
+
} else if ("lessThan" in i) {
|
|
240
|
+
let A = Number(S(n, i.lessThan));
|
|
241
|
+
E && Number(g) >= A && (h = i.message ?? `Must be less than ${A}`);
|
|
242
|
+
} else if ("after" in i) {
|
|
243
|
+
let A = U(g), L = U(S(n, i.after));
|
|
244
|
+
A && L && A <= L && (h = i.message ?? "Must be after the reference date");
|
|
245
|
+
} else if ("before" in i) {
|
|
246
|
+
let A = U(g), L = U(S(n, i.before));
|
|
247
|
+
A && L && A >= L && (h = i.message ?? "Must be before the reference date");
|
|
248
|
+
} else "requiredIf" in i ? S(n, i.requiredIf) && !E && (h = i.message ?? "Required") : "requiredUnless" in i && !S(n, i.requiredUnless) && !E && (h = i.message ?? "Required");
|
|
249
|
+
if (h !== null) {
|
|
250
|
+
a[d] = h;
|
|
247
251
|
break;
|
|
248
252
|
}
|
|
249
253
|
}
|
|
250
254
|
}
|
|
251
255
|
return a;
|
|
252
256
|
}
|
|
253
|
-
function
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
257
|
+
function be(n) {
|
|
258
|
+
let f = x(n.initialValues), l = x(f), a = {}, u = {}, d = {}, p = false, N = false, g = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), h = 0, A = /* @__PURE__ */ new Set(), L = 0, k = /* @__PURE__ */ new Map(), _ = null, G = n.dependencies ? fe(n.dependencies, f) : {}, C = () => ({ values: x(l), errors: { ...a }, touched: { ...u }, dirty: { ...d }, isSubmitting: p, isValidating: N }), H = /* @__PURE__ */ new Set(), $ = (r) => {
|
|
259
|
+
if (H.size === 0) return;
|
|
260
|
+
let e = C();
|
|
261
|
+
H.forEach((s) => {
|
|
262
|
+
try {
|
|
263
|
+
s(r, e);
|
|
264
|
+
} catch (t) {
|
|
265
|
+
console.error("[NeutroForm] _subscribeToActions listener threw:", t);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}, z = (r) => {
|
|
269
|
+
r.forEach((e) => {
|
|
270
|
+
let s = e.split("."), t = ["*"], o = "";
|
|
271
|
+
for (let c of s) o = o ? `${o}.${c}` : c, t.push(o);
|
|
272
|
+
for (let c of t) {
|
|
273
|
+
let b = M.get(c);
|
|
274
|
+
if (!b) continue;
|
|
275
|
+
let m = x(c === "*" ? l : S(l, c));
|
|
276
|
+
for (let T of b) T(m, { error: a[c], touched: u[c], dirty: d[c] });
|
|
277
|
+
}
|
|
264
278
|
});
|
|
265
|
-
},
|
|
266
|
-
if (
|
|
267
|
-
let
|
|
268
|
-
|
|
279
|
+
}, re = (r) => {
|
|
280
|
+
if (g.size > 0) {
|
|
281
|
+
let s = C();
|
|
282
|
+
for (let t of g) t(s);
|
|
269
283
|
}
|
|
270
|
-
let e = [...new Set(
|
|
284
|
+
let e = [...new Set(r.filter((s) => s !== void 0))];
|
|
271
285
|
z(e);
|
|
272
|
-
},
|
|
273
|
-
if (
|
|
274
|
-
|
|
286
|
+
}, O = (r) => {
|
|
287
|
+
if (h > 0) {
|
|
288
|
+
A.add(r);
|
|
275
289
|
return;
|
|
276
290
|
}
|
|
277
|
-
if (
|
|
278
|
-
let e =
|
|
279
|
-
|
|
291
|
+
if (g.size > 0) {
|
|
292
|
+
let e = C();
|
|
293
|
+
for (let s of g) s(e);
|
|
280
294
|
}
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
|
|
295
|
+
r && z([r]);
|
|
296
|
+
}, D = (r) => {
|
|
297
|
+
h++;
|
|
284
298
|
try {
|
|
285
|
-
|
|
299
|
+
r();
|
|
286
300
|
} finally {
|
|
287
|
-
if (
|
|
288
|
-
let e = [...
|
|
289
|
-
|
|
301
|
+
if (h--, h === 0 && A.size > 0) {
|
|
302
|
+
let e = [...A];
|
|
303
|
+
A.clear(), re(e);
|
|
290
304
|
}
|
|
291
305
|
}
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
}),
|
|
295
|
-
if (!
|
|
296
|
-
|
|
306
|
+
}, se = (r) => (g.add(r), r(C()), () => {
|
|
307
|
+
g.delete(r);
|
|
308
|
+
}), I = async (r) => {
|
|
309
|
+
if (!n.validator && !n.rules) return true;
|
|
310
|
+
if (N = true, g.size > 0) {
|
|
311
|
+
let s = C();
|
|
312
|
+
for (let t of g) t(s);
|
|
313
|
+
}
|
|
297
314
|
let e;
|
|
298
|
-
if (
|
|
299
|
-
let
|
|
300
|
-
|
|
301
|
-
let o =
|
|
302
|
-
if (!o && /\.(\d+)\./.test(
|
|
303
|
-
let c =
|
|
304
|
-
if (
|
|
305
|
-
let m =
|
|
306
|
-
o =
|
|
315
|
+
if (r && Object.keys(G).length > 0) {
|
|
316
|
+
let s = /* @__PURE__ */ new Set();
|
|
317
|
+
for (let t of r) {
|
|
318
|
+
let o = G[t];
|
|
319
|
+
if (!o && /\.(\d+)\./.test(t)) {
|
|
320
|
+
let c = t.replace(/\.(\d+)\./g, ".*."), b = G[c];
|
|
321
|
+
if (b) {
|
|
322
|
+
let m = t.match(/\.(\d+)\./), T = m ? m[1] : "";
|
|
323
|
+
o = b.map((P) => P.replace(/\.\*\./g, `.${T}.`));
|
|
307
324
|
}
|
|
308
325
|
}
|
|
309
|
-
o
|
|
310
|
-
|
|
311
|
-
|
|
326
|
+
if (o) for (let c of o) s.add(c);
|
|
327
|
+
else s.add(t);
|
|
328
|
+
}
|
|
329
|
+
e = Array.from(s);
|
|
330
|
+
} else r && (e = r);
|
|
312
331
|
try {
|
|
313
|
-
let
|
|
314
|
-
e
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
let
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let v, b = () => {
|
|
325
|
-
clearTimeout(v), p(a);
|
|
332
|
+
let s = ++L;
|
|
333
|
+
if (e) for (let c of e) k.get(c)?.abort(), k.delete(c);
|
|
334
|
+
let t = new AbortController();
|
|
335
|
+
if (e) for (let c of e) k.set(c, t);
|
|
336
|
+
let o = n.rules ? ge(l, n.rules, e) : {};
|
|
337
|
+
if (n.validator) {
|
|
338
|
+
let c = x(l), b = n.validator(c, e, t.signal);
|
|
339
|
+
if (b instanceof Promise) {
|
|
340
|
+
let m = await new Promise((T) => {
|
|
341
|
+
let P, y = () => {
|
|
342
|
+
clearTimeout(P), T(a);
|
|
326
343
|
};
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
344
|
+
t.signal.addEventListener("abort", y, { once: true }), P = setTimeout(async () => {
|
|
345
|
+
if (t.signal.removeEventListener("abort", y), t.signal.aborted) {
|
|
346
|
+
T(a);
|
|
330
347
|
return;
|
|
331
348
|
}
|
|
332
349
|
try {
|
|
333
|
-
|
|
350
|
+
T(await b);
|
|
334
351
|
} catch {
|
|
335
|
-
|
|
352
|
+
T({ _global: "Asynchronous validation transaction failed." });
|
|
336
353
|
}
|
|
337
|
-
},
|
|
354
|
+
}, n.asyncDebounceMs ?? 300);
|
|
338
355
|
});
|
|
339
|
-
if (
|
|
340
|
-
let
|
|
341
|
-
a = e ?
|
|
356
|
+
if (s === L && !t.signal.aborted) {
|
|
357
|
+
let T = { ...o, ...m };
|
|
358
|
+
a = e ? Z(a, T, e) : T;
|
|
342
359
|
}
|
|
343
360
|
} else {
|
|
344
|
-
let m = { ...o, ...
|
|
345
|
-
a = e ?
|
|
361
|
+
let m = { ...o, ...b };
|
|
362
|
+
a = e ? Z(a, m, e) : m;
|
|
346
363
|
}
|
|
347
|
-
} else a = e ?
|
|
364
|
+
} else a = e ? Z(a, o, e) : o;
|
|
348
365
|
} finally {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
366
|
+
if (e) for (let t of e) k.delete(t);
|
|
367
|
+
if (N = false, g.size > 0) {
|
|
368
|
+
let t = C();
|
|
369
|
+
for (let o of g) o(t);
|
|
370
|
+
}
|
|
371
|
+
let s = e ?? [...M.keys()].filter((t) => t !== "*");
|
|
372
|
+
z(s);
|
|
352
373
|
}
|
|
353
374
|
return Object.keys(a).length === 0;
|
|
354
|
-
},
|
|
355
|
-
let
|
|
356
|
-
return
|
|
357
|
-
Object.keys(
|
|
358
|
-
(c === o || c.startsWith(o
|
|
375
|
+
}, Z = (r, e, s) => {
|
|
376
|
+
let t = { ...r };
|
|
377
|
+
return s.forEach((o) => {
|
|
378
|
+
Object.keys(t).forEach((c) => {
|
|
379
|
+
(c === o || c.startsWith(`${o}.`)) && delete t[c];
|
|
359
380
|
});
|
|
360
381
|
}), Object.keys(e).forEach((o) => {
|
|
361
|
-
|
|
362
|
-
}),
|
|
363
|
-
}, B = (
|
|
364
|
-
let
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
let o =
|
|
368
|
-
|
|
369
|
-
}),
|
|
370
|
-
},
|
|
371
|
-
|
|
382
|
+
s.some((c) => o === c || o.startsWith(`${c}.`)) && (t[o] = e[o]);
|
|
383
|
+
}), t;
|
|
384
|
+
}, B = (r, e, s = {}) => {
|
|
385
|
+
let t = S(l, r);
|
|
386
|
+
F(t, e) || (D(() => {
|
|
387
|
+
W(l, r, e);
|
|
388
|
+
let o = S(f, r);
|
|
389
|
+
d[r] = !F(o, e), d[r] || delete d[r], s.touch && (u[r] = true);
|
|
390
|
+
}), O(r), s.validate === true && I([r]));
|
|
391
|
+
}, ie = () => {
|
|
392
|
+
_ || typeof window > "u" || typeof document > "u" || (_ = new MutationObserver((r) => {
|
|
372
393
|
let e = [];
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
let
|
|
377
|
-
(!
|
|
394
|
+
if (r.forEach((s) => {
|
|
395
|
+
s.removedNodes.forEach((t) => {
|
|
396
|
+
t instanceof HTMLElement && w.forEach((o, c) => {
|
|
397
|
+
let b = o.deref();
|
|
398
|
+
(!b || t.contains(b)) && (w.delete(c), E.delete(c), i.has(c) || (delete a[c], delete u[c], delete d[c], e.push(c)));
|
|
378
399
|
});
|
|
379
400
|
});
|
|
380
|
-
}), e.length > 0
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
401
|
+
}), e.length > 0) {
|
|
402
|
+
if (g.size > 0) {
|
|
403
|
+
let s = C();
|
|
404
|
+
for (let t of g) t(s);
|
|
405
|
+
}
|
|
406
|
+
z(e);
|
|
407
|
+
}
|
|
408
|
+
}), _.observe(document.body, { childList: true, subtree: true }));
|
|
409
|
+
}, J = (r, e, s, t) => {
|
|
410
|
+
let o = [], c = (b) => {
|
|
411
|
+
let m = {}, T = `${r}.`;
|
|
412
|
+
return Object.keys(b).forEach((P) => {
|
|
413
|
+
if (!P.startsWith(T)) {
|
|
414
|
+
m[P] = b[P];
|
|
388
415
|
return;
|
|
389
416
|
}
|
|
390
|
-
let
|
|
391
|
-
if (!
|
|
392
|
-
m[
|
|
417
|
+
let R = P.substring(T.length).match(/^(\d+)(.*)$/);
|
|
418
|
+
if (!R) {
|
|
419
|
+
m[P] = b[P];
|
|
393
420
|
return;
|
|
394
421
|
}
|
|
395
|
-
let
|
|
396
|
-
if (
|
|
397
|
-
if (
|
|
398
|
-
if (
|
|
399
|
-
let
|
|
400
|
-
m[
|
|
401
|
-
} else m[
|
|
402
|
-
} else if (
|
|
403
|
-
let
|
|
404
|
-
m[
|
|
405
|
-
} else m[
|
|
422
|
+
let v = parseInt(R[1], 10), j = R[2];
|
|
423
|
+
if (s === "remove") {
|
|
424
|
+
if (v === e) return;
|
|
425
|
+
if (v > e) {
|
|
426
|
+
let V = `${T}${v - 1}${j}`;
|
|
427
|
+
m[V] = b[P], o.push(V);
|
|
428
|
+
} else m[P] = b[P];
|
|
429
|
+
} else if (s === "insert" && t !== void 0) if (v >= t) {
|
|
430
|
+
let V = `${T}${v + 1}${j}`;
|
|
431
|
+
m[V] = b[P], o.push(V);
|
|
432
|
+
} else m[P] = b[P];
|
|
406
433
|
}), m;
|
|
407
434
|
};
|
|
408
|
-
return
|
|
409
|
-
a = c(a),
|
|
435
|
+
return D(() => {
|
|
436
|
+
a = c(a), u = c(u), d = c(d);
|
|
410
437
|
}), o;
|
|
411
|
-
},
|
|
412
|
-
let
|
|
413
|
-
let
|
|
414
|
-
return Object.keys(c).forEach((
|
|
415
|
-
if (!
|
|
416
|
-
T
|
|
438
|
+
}, ae = (r, e, s) => {
|
|
439
|
+
let t = `${r}.`, o = (c) => {
|
|
440
|
+
let b = {}, m = [];
|
|
441
|
+
return Object.keys(c).forEach((T) => {
|
|
442
|
+
if (!T.startsWith(t)) {
|
|
443
|
+
b[T] = c[T];
|
|
417
444
|
return;
|
|
418
445
|
}
|
|
419
|
-
let
|
|
420
|
-
if (!
|
|
421
|
-
T
|
|
446
|
+
let y = T.substring(t.length).match(/^(\d+)(.*)$/);
|
|
447
|
+
if (!y) {
|
|
448
|
+
b[T] = c[T];
|
|
422
449
|
return;
|
|
423
450
|
}
|
|
424
|
-
m.push({ index: parseInt(
|
|
425
|
-
}), m.forEach(({ index:
|
|
426
|
-
let
|
|
427
|
-
|
|
428
|
-
}),
|
|
451
|
+
m.push({ index: parseInt(y[1], 10), tail: y[2], key: T });
|
|
452
|
+
}), m.forEach(({ index: T, tail: P, key: y }) => {
|
|
453
|
+
let R = T;
|
|
454
|
+
T === e ? R = s : e < s && T > e && T <= s ? R = T - 1 : e > s && T >= s && T < e && (R = T + 1), b[`${t}${R}${P}`] = c[y];
|
|
455
|
+
}), b;
|
|
429
456
|
};
|
|
430
|
-
|
|
431
|
-
a = o(a),
|
|
457
|
+
D(() => {
|
|
458
|
+
a = o(a), u = o(u), d = o(d);
|
|
432
459
|
});
|
|
433
|
-
},
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
let
|
|
438
|
-
|
|
460
|
+
}, Q = (r, e) => {
|
|
461
|
+
if (e) return e;
|
|
462
|
+
if (n.validationMode) {
|
|
463
|
+
if (typeof n.validationMode == "string") return n.validationMode;
|
|
464
|
+
let s = n.validationMode.fields?.[r];
|
|
465
|
+
if (s) return s;
|
|
466
|
+
if (n.validationMode.default) return n.validationMode.default;
|
|
467
|
+
}
|
|
468
|
+
return "onTouched";
|
|
469
|
+
}, X = (r, e) => {
|
|
470
|
+
let s = M.get(r);
|
|
471
|
+
s || (s = /* @__PURE__ */ new Set(), M.set(r, s)), s.add(e);
|
|
472
|
+
let t = r === "*" ? l : S(l, r);
|
|
473
|
+
return e(x(t), { error: a[r], touched: u[r], dirty: d[r] }), () => {
|
|
474
|
+
let o = M.get(r);
|
|
475
|
+
o && (o.delete(e), o.size === 0 && M.delete(r));
|
|
439
476
|
};
|
|
440
|
-
},
|
|
477
|
+
}, oe = (r, e, s = {}) => {
|
|
441
478
|
if (!e || typeof window > "u") return () => {
|
|
442
479
|
};
|
|
443
|
-
let
|
|
444
|
-
|
|
445
|
-
let
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
let E = b;
|
|
457
|
-
if (E.checked) S = E.value;
|
|
480
|
+
let t = Array.isArray(r) ? r.join(".") : r, o = Q(t, s.validateOn);
|
|
481
|
+
ie(), w.set(t, new WeakRef(e)), E.add(t), s.persist && i.add(t), e.setAttribute("aria-invalid", a[t] ? "true" : "false"), te(t) && e.setAttribute("aria-required", "true");
|
|
482
|
+
let c = (P) => {
|
|
483
|
+
let y = P.target, R;
|
|
484
|
+
if (y.type === "checkbox") {
|
|
485
|
+
let v = y;
|
|
486
|
+
if (v.hasAttribute("value")) {
|
|
487
|
+
let j = S(l, t) || [];
|
|
488
|
+
R = v.checked ? [...j, v.value] : j.filter((V) => V !== v.value);
|
|
489
|
+
} else R = v.checked;
|
|
490
|
+
} else if (y.type === "radio") {
|
|
491
|
+
let v = y;
|
|
492
|
+
if (v.checked) R = v.value;
|
|
458
493
|
else return;
|
|
459
|
-
} else if (
|
|
494
|
+
} else if (y.tagName === "SELECT" && y.multiple) R = Array.from(y.selectedOptions).map((v) => v.value);
|
|
460
495
|
else {
|
|
461
|
-
let
|
|
462
|
-
|
|
496
|
+
let v = y.type;
|
|
497
|
+
v === "number" ? R = y.value === "" ? void 0 : parseFloat(y.value) : v === "range" ? R = parseFloat(y.value) : v === "date" || v === "datetime-local" ? R = y.value === "" ? void 0 : new Date(y.value) : R = y.value;
|
|
463
498
|
}
|
|
464
|
-
if (
|
|
465
|
-
let
|
|
466
|
-
|
|
467
|
-
let
|
|
468
|
-
|
|
469
|
-
let
|
|
470
|
-
|
|
499
|
+
if (s.format && typeof R == "string" && y instanceof HTMLInputElement) {
|
|
500
|
+
let v = ["text", "search", "tel", "url", "password"].includes(y.type), j = 0, V = 0;
|
|
501
|
+
v && (j = y.selectionStart || 0, V = y.selectionEnd || 0);
|
|
502
|
+
let K = s.format(R);
|
|
503
|
+
y.value = K;
|
|
504
|
+
let q = K.length - R.length;
|
|
505
|
+
v && document.activeElement === y && y.setSelectionRange(j + q, V + q), R = K;
|
|
471
506
|
}
|
|
472
|
-
B(
|
|
473
|
-
},
|
|
474
|
-
|
|
507
|
+
o === "onChange" ? (B(t, R, { touch: true }), I([t])) : o === "onTouched" && u[t] ? (B(t, R), I([t])) : B(t, R);
|
|
508
|
+
}, b = () => {
|
|
509
|
+
u[t] = true, $({ type: "BLUR", path: t }), o === "onBlur" || o === "onTouched" ? I([t]) : O(t);
|
|
475
510
|
};
|
|
476
|
-
e.addEventListener("input", c), e.addEventListener("change", c), e.addEventListener("blur",
|
|
477
|
-
let m =
|
|
511
|
+
e.addEventListener("input", c), e.addEventListener("change", c), e.addEventListener("blur", b);
|
|
512
|
+
let m = S(l, t);
|
|
478
513
|
if (m !== void 0) if (e instanceof HTMLInputElement && e.type === "checkbox") e.checked = e.hasAttribute("value") ? Array.isArray(m) && m.includes(e.value) : !!m;
|
|
479
514
|
else if (e instanceof HTMLInputElement && e.type === "radio") e.checked = e.value === m;
|
|
480
515
|
else if (e instanceof HTMLSelectElement && e.multiple) {
|
|
481
|
-
let
|
|
482
|
-
|
|
516
|
+
let P = Array.isArray(m) ? m : [];
|
|
517
|
+
for (let y of e.options) y.selected = P.includes(y.value);
|
|
483
518
|
} else e instanceof HTMLInputElement && (e.type === "date" || e.type === "datetime-local") && m instanceof Date ? e.value = m.toISOString().substring(0, 10) : "value" in e && (e.value = m);
|
|
484
|
-
let
|
|
485
|
-
e.setAttribute("aria-invalid",
|
|
519
|
+
let T = X(t, (P, y) => {
|
|
520
|
+
e.setAttribute("aria-invalid", y.error ? "true" : "false");
|
|
521
|
+
let R = document.querySelector(`[data-error="${t}"]`);
|
|
522
|
+
R && (R.id || (R.id = `error-desc-${t.replace(/\./g, "-")}`), e.setAttribute("aria-describedby", R.id));
|
|
486
523
|
});
|
|
487
|
-
return
|
|
488
|
-
e.removeEventListener("input", c), e.removeEventListener("change", c), e.removeEventListener("blur",
|
|
524
|
+
return O(t), $({ type: "CONNECT", path: t }), () => {
|
|
525
|
+
e.removeEventListener("input", c), e.removeEventListener("change", c), e.removeEventListener("blur", b), T(), w.delete(t), E.delete(t), $({ type: "DISCONNECT", path: t }), O(t);
|
|
489
526
|
};
|
|
490
|
-
},
|
|
491
|
-
if (
|
|
492
|
-
|
|
527
|
+
}, ee = async (r) => {
|
|
528
|
+
if ($({ type: "SUBMIT" }), p) return false;
|
|
529
|
+
p = true, Y(l).forEach((e) => {
|
|
530
|
+
u[e] = true;
|
|
531
|
+
}), O();
|
|
493
532
|
try {
|
|
494
|
-
if (await
|
|
495
|
-
let
|
|
496
|
-
return await s
|
|
533
|
+
if (await I()) {
|
|
534
|
+
let s = ne(l, w, E, i);
|
|
535
|
+
return await r(s), true;
|
|
497
536
|
}
|
|
498
537
|
return false;
|
|
499
538
|
} catch (e) {
|
|
500
|
-
return console.error("[
|
|
539
|
+
return console.error("[NeutroForm Submit Error]: ", e), false;
|
|
501
540
|
} finally {
|
|
502
|
-
|
|
541
|
+
p = false, O();
|
|
542
|
+
}
|
|
543
|
+
}, ce = (r, e) => async (s) => {
|
|
544
|
+
s && typeof s.preventDefault == "function" && s.preventDefault(), !await ee(r) && e && e({ ...a });
|
|
545
|
+
}, le = (r) => {
|
|
546
|
+
if (!r) return;
|
|
547
|
+
let e = Object.keys(r);
|
|
548
|
+
if (e.length !== 0) {
|
|
549
|
+
Object.assign(a, r);
|
|
550
|
+
for (let s of e) u[s] = true;
|
|
551
|
+
D(() => {
|
|
552
|
+
for (let s of e) O(s);
|
|
553
|
+
}), $({ type: "SET_ERRORS", errors: { ...r } });
|
|
554
|
+
}
|
|
555
|
+
}, ue = () => {
|
|
556
|
+
let r = Object.keys(a);
|
|
557
|
+
if (r.length !== 0) {
|
|
558
|
+
for (let e of r) delete a[e];
|
|
559
|
+
D(() => {
|
|
560
|
+
for (let e of r) O(e);
|
|
561
|
+
}), $({ type: "CLEAR_ERRORS" });
|
|
503
562
|
}
|
|
504
563
|
};
|
|
505
|
-
|
|
506
|
-
let e =
|
|
507
|
-
return
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
564
|
+
function te(r) {
|
|
565
|
+
let e = n.rules?.[r];
|
|
566
|
+
return e ? Array.isArray(e) ? e.includes("required") : e === "required" : false;
|
|
567
|
+
}
|
|
568
|
+
return { subscribe: se, subscribeToPath: X, get: (r) => {
|
|
569
|
+
let e = Array.isArray(r) ? r.join(".") : r;
|
|
570
|
+
return S(l, e);
|
|
571
|
+
}, set: (r, e, s) => {
|
|
572
|
+
let t = Array.isArray(r) ? r.join(".") : r;
|
|
573
|
+
B(t, e, s), $({ type: "SET", path: t, value: e, options: s });
|
|
574
|
+
}, validate: (r) => {
|
|
575
|
+
let e = r?.map((s) => Array.isArray(s) ? s.join(".") : s);
|
|
576
|
+
return $({ type: "VALIDATE", paths: e }), I(e);
|
|
577
|
+
}, connect: oe, submit: ee, handleSubmit: ce, getState: C, getPayload: () => ne(l, w, E, i), getAriaProps: (r, e) => {
|
|
578
|
+
let s = r, t = !!a[s], o = e?.errorId ?? `error-${s.replace(/\./g, "-")}`, c;
|
|
579
|
+
return (e?.required === true || e?.required !== false && te(s)) && (c = true), { "aria-invalid": t ? "true" : "false", "aria-describedby": t ? o : void 0, "aria-required": c };
|
|
580
|
+
}, batch: (r) => {
|
|
581
|
+
$({ type: "BATCH_START" });
|
|
582
|
+
try {
|
|
583
|
+
D(r);
|
|
584
|
+
} finally {
|
|
585
|
+
$({ type: "BATCH_END" });
|
|
586
|
+
}
|
|
587
|
+
}, setErrors: le, clearErrors: ue, getFieldMode: (r) => Q(r), arrayAppend: (r, e) => {
|
|
588
|
+
let s = Array.isArray(r) ? r.join(".") : r, t = S(l, s) || [];
|
|
589
|
+
Array.isArray(t) && (B(s, [...t, e]), $({ type: "ARRAY_APPEND", path: s, item: e }));
|
|
590
|
+
}, arrayInsert: (r, e, s) => {
|
|
591
|
+
let t = Array.isArray(r) ? r.join(".") : r, o = S(l, t) || [];
|
|
521
592
|
if (!Array.isArray(o) || e < 0 || e > o.length) return;
|
|
522
593
|
let c = [...o];
|
|
523
|
-
c.splice(e, 0,
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
594
|
+
c.splice(e, 0, s), D(() => {
|
|
595
|
+
W(l, t, c);
|
|
596
|
+
let b = J(t, e, "insert", e);
|
|
597
|
+
for (let m of b) O(m);
|
|
598
|
+
O(`${t}.${e}`), O(t);
|
|
599
|
+
}), I([t]), $({ type: "ARRAY_INSERT", path: t, index: e, item: s });
|
|
600
|
+
}, arrayRemove: (r, e) => {
|
|
601
|
+
let s = Array.isArray(r) ? r.join(".") : r, t = S(l, s) || [];
|
|
602
|
+
if (!Array.isArray(t) || e < 0 || e >= t.length) return;
|
|
603
|
+
let o = [...t];
|
|
604
|
+
o.splice(e, 1), D(() => {
|
|
605
|
+
W(l, s, o);
|
|
606
|
+
let c = J(s, e, "remove");
|
|
607
|
+
for (let b of c) O(b);
|
|
608
|
+
O(s);
|
|
609
|
+
}), I([s]), $({ type: "ARRAY_REMOVE", path: s, index: e });
|
|
610
|
+
}, arrayMove: (r, e, s) => {
|
|
611
|
+
let t = Array.isArray(r) ? r.join(".") : r, o = S(l, t) || [];
|
|
612
|
+
if (!Array.isArray(o) || e < 0 || e >= o.length || s < 0 || s >= o.length) return;
|
|
613
|
+
let c = [...o], [b] = c.splice(e, 1);
|
|
614
|
+
c.splice(s, 0, b), D(() => {
|
|
615
|
+
W(l, t, c), ae(t, e, s);
|
|
616
|
+
let m = Math.min(e, s), T = Math.max(e, s);
|
|
617
|
+
for (let P = m; P <= T; P++) O(`${t}.${P}`);
|
|
618
|
+
}), I([t]), $({ type: "ARRAY_MOVE", path: t, from: e, to: s });
|
|
619
|
+
}, arraySwap: (r, e, s) => {
|
|
620
|
+
let t = Array.isArray(r) ? r.join(".") : r, o = S(l, t) || [];
|
|
621
|
+
if (!Array.isArray(o) || e < 0 || e >= o.length || s < 0 || s >= o.length) return;
|
|
545
622
|
let c = [...o];
|
|
546
|
-
[c[e], c[
|
|
547
|
-
|
|
548
|
-
let
|
|
549
|
-
let
|
|
550
|
-
return Object.keys(m).forEach((
|
|
551
|
-
let
|
|
552
|
-
if (
|
|
553
|
-
let
|
|
554
|
-
|
|
555
|
-
} else if (
|
|
556
|
-
let
|
|
557
|
-
|
|
623
|
+
[c[e], c[s]] = [c[s], c[e]], D(() => {
|
|
624
|
+
W(l, t, c);
|
|
625
|
+
let b = (m) => {
|
|
626
|
+
let T = `${t}.`, P = { ...m }, y = `${T}${e}`, R = `${T}${s}`;
|
|
627
|
+
return Object.keys(m).forEach((v) => {
|
|
628
|
+
let j = v === y || v.startsWith(`${y}.`), V = v === R || v.startsWith(`${R}.`);
|
|
629
|
+
if (j) {
|
|
630
|
+
let K = v.substring(y.length), q = `${R}${K}`;
|
|
631
|
+
P[q] = m[v], m[q] === void 0 && delete P[v];
|
|
632
|
+
} else if (V) {
|
|
633
|
+
let K = v.substring(R.length), q = `${y}${K}`;
|
|
634
|
+
P[q] = m[v], m[q] === void 0 && delete P[v];
|
|
558
635
|
}
|
|
559
|
-
}),
|
|
636
|
+
}), P;
|
|
560
637
|
};
|
|
561
|
-
a =
|
|
562
|
-
}),
|
|
563
|
-
}, reset: (
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}),
|
|
567
|
-
let o =
|
|
638
|
+
a = b(a), u = b(u), d = b(d), O(`${t}.${e}`), O(`${t}.${s}`);
|
|
639
|
+
}), I([t]), $({ type: "ARRAY_SWAP", path: t, i: e, j: s });
|
|
640
|
+
}, reset: (r) => {
|
|
641
|
+
if (D(() => {
|
|
642
|
+
r && (f = x(r)), l = x(f), a = {}, u = {}, d = {}, p = false, N = false;
|
|
643
|
+
}), w.forEach((s, t) => {
|
|
644
|
+
let o = s.deref();
|
|
568
645
|
if (!o || !("value" in o)) return;
|
|
569
|
-
let c =
|
|
646
|
+
let c = S(l, t);
|
|
570
647
|
if (o instanceof HTMLInputElement && o.type === "checkbox") o.checked = o.hasAttribute("value") ? Array.isArray(c) && c.includes(o.value) : !!c;
|
|
571
648
|
else if (o instanceof HTMLInputElement && o.type === "radio") o.checked = o.value === c;
|
|
572
649
|
else if (o instanceof HTMLSelectElement && o.multiple) {
|
|
573
|
-
let
|
|
574
|
-
|
|
650
|
+
let b = Array.isArray(c) ? c : [];
|
|
651
|
+
for (let m of o.options) m.selected = b.includes(m.value);
|
|
575
652
|
} else o instanceof HTMLInputElement && (o.type === "date" || o.type === "datetime-local") && c instanceof Date ? o.value = c.toISOString().substring(0, 10) : o.value = c !== void 0 ? c : "";
|
|
576
|
-
}),
|
|
577
|
-
|
|
653
|
+
}), g.size > 0) {
|
|
654
|
+
let s = C();
|
|
655
|
+
for (let t of g) t(s);
|
|
656
|
+
}
|
|
657
|
+
z([...M.keys()].filter((s) => s !== "*"));
|
|
658
|
+
let e = M.get("*");
|
|
578
659
|
if (e) {
|
|
579
|
-
let
|
|
580
|
-
e
|
|
660
|
+
let s = x(l);
|
|
661
|
+
for (let t of e) t(s, { error: void 0, touched: void 0, dirty: void 0 });
|
|
581
662
|
}
|
|
582
|
-
|
|
583
|
-
|
|
663
|
+
$({ type: "RESET", newValues: r });
|
|
664
|
+
}, _subscribeToActions: (r) => (H.add(r), () => {
|
|
665
|
+
H.delete(r);
|
|
666
|
+
}), getConnectedCount: () => w.size, destroy: () => {
|
|
667
|
+
for (let r of k.values()) r.abort();
|
|
668
|
+
k.clear(), g.clear(), M.clear(), H.clear(), w.clear(), E.clear(), i.clear(), _ && (_.disconnect(), _ = null);
|
|
584
669
|
} };
|
|
585
670
|
}
|
|
586
|
-
function
|
|
587
|
-
let
|
|
588
|
-
return
|
|
589
|
-
if ((l.has(
|
|
590
|
-
let
|
|
591
|
-
|
|
671
|
+
function ne(n, f, l, a) {
|
|
672
|
+
let u = {};
|
|
673
|
+
return f.forEach((d, p) => {
|
|
674
|
+
if ((l.has(p) || a.has(p)) && d.deref()) {
|
|
675
|
+
let g = S(n, p);
|
|
676
|
+
g !== void 0 && W(u, p, g);
|
|
592
677
|
}
|
|
593
|
-
}),
|
|
678
|
+
}), u;
|
|
594
679
|
}
|
|
595
680
|
// Annotate the CommonJS export names for ESM import in node:
|
|
596
681
|
0 && (module.exports = {
|