@neutro/form 0.0.1

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