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