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