solid-hook-form 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/main.js +94 -317
- package/dist/main.umd.cjs +1 -1
- package/dist/types/form.d.ts +2 -3
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
### Playground
|
|
4
4
|
|
|
5
|
-
[<img width="1171" alt="Screenshot 2025-04-05 at 15 01 47" src="https://github.com/
|
|
5
|
+
[<img width="1171" alt="Screenshot 2025-04-05 at 15 01 47" src="https://github.com/tatsmaki/solid-hook-form/blob/master/assets/demo.png" />](https://solid-hook-form.vercel.app/)
|
|
6
6
|
|
|
7
7
|
### Install
|
|
8
8
|
|
package/dist/main.js
CHANGED
|
@@ -1,347 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function F(t, e) {
|
|
9
|
-
e = e ? Object.assign({}, d, e) : d;
|
|
10
|
-
const r = {
|
|
11
|
-
value: t,
|
|
12
|
-
observers: null,
|
|
13
|
-
observerSlots: null,
|
|
14
|
-
comparator: e.equals || void 0
|
|
15
|
-
}, n = (s) => (typeof s == "function" && (s = s(r.value)), R(r, s));
|
|
16
|
-
return [P.bind(r), n];
|
|
17
|
-
}
|
|
18
|
-
function et(t, e, r) {
|
|
19
|
-
const n = U(t, e, !1, g);
|
|
20
|
-
A(n);
|
|
21
|
-
}
|
|
22
|
-
function T(t, e, r) {
|
|
23
|
-
r = r ? Object.assign({}, d, r) : d;
|
|
24
|
-
const n = U(t, e, !0, 0);
|
|
25
|
-
return n.observers = null, n.observerSlots = null, n.comparator = r.equals || void 0, A(n), P.bind(n);
|
|
26
|
-
}
|
|
27
|
-
function M(t) {
|
|
28
|
-
if (l === null) return t();
|
|
29
|
-
const e = l;
|
|
30
|
-
l = null;
|
|
31
|
-
try {
|
|
32
|
-
return t();
|
|
33
|
-
} finally {
|
|
34
|
-
l = e;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function rt(t, e) {
|
|
38
|
-
const r = Symbol("context");
|
|
39
|
-
return {
|
|
40
|
-
id: r,
|
|
41
|
-
Provider: ct(r),
|
|
42
|
-
defaultValue: t
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function nt(t) {
|
|
46
|
-
let e;
|
|
47
|
-
return a && a.context && (e = a.context[t.id]) !== void 0 ? e : t.defaultValue;
|
|
48
|
-
}
|
|
49
|
-
function st(t) {
|
|
50
|
-
const e = T(t), r = T(() => V(e()));
|
|
51
|
-
return r.toArray = () => {
|
|
52
|
-
const n = r();
|
|
53
|
-
return Array.isArray(n) ? n : n != null ? [n] : [];
|
|
54
|
-
}, r;
|
|
55
|
-
}
|
|
56
|
-
function P() {
|
|
57
|
-
if (this.sources && this.state)
|
|
58
|
-
if (this.state === g) A(this);
|
|
59
|
-
else {
|
|
60
|
-
const t = f;
|
|
61
|
-
f = null, L(() => w(this)), f = t;
|
|
62
|
-
}
|
|
63
|
-
if (l) {
|
|
64
|
-
const t = this.observers ? this.observers.length : 0;
|
|
65
|
-
l.sources ? (l.sources.push(this), l.sourceSlots.push(t)) : (l.sources = [this], l.sourceSlots = [t]), this.observers ? (this.observers.push(l), this.observerSlots.push(l.sources.length - 1)) : (this.observers = [l], this.observerSlots = [l.sources.length - 1]);
|
|
66
|
-
}
|
|
67
|
-
return this.value;
|
|
68
|
-
}
|
|
69
|
-
function R(t, e, r) {
|
|
70
|
-
let n = t.value;
|
|
71
|
-
return (!t.comparator || !t.comparator(n, e)) && (t.value = e, t.observers && t.observers.length && L(() => {
|
|
72
|
-
for (let s = 0; s < t.observers.length; s += 1) {
|
|
73
|
-
const i = t.observers[s], p = C && C.running;
|
|
74
|
-
p && C.disposed.has(i), (p ? !i.tState : !i.state) && (i.pure ? f.push(i) : h.push(i), i.observers && _(i)), p || (i.state = g);
|
|
75
|
-
}
|
|
76
|
-
if (f.length > 1e6)
|
|
77
|
-
throw f = [], new Error();
|
|
78
|
-
})), e;
|
|
79
|
-
}
|
|
80
|
-
function A(t) {
|
|
81
|
-
if (!t.fn) return;
|
|
82
|
-
x(t);
|
|
83
|
-
const e = S;
|
|
84
|
-
ot(
|
|
85
|
-
t,
|
|
86
|
-
t.value,
|
|
87
|
-
e
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
function ot(t, e, r) {
|
|
91
|
-
let n;
|
|
92
|
-
const s = a, i = l;
|
|
93
|
-
l = a = t;
|
|
94
|
-
try {
|
|
95
|
-
n = t.fn(e);
|
|
96
|
-
} catch (p) {
|
|
97
|
-
return t.pure && (t.state = g, t.owned && t.owned.forEach(x), t.owned = null), t.updatedAt = r + 1, G(p);
|
|
98
|
-
} finally {
|
|
99
|
-
l = i, a = s;
|
|
100
|
-
}
|
|
101
|
-
(!t.updatedAt || t.updatedAt <= r) && (t.updatedAt != null && "observers" in t ? R(t, n) : t.value = n, t.updatedAt = r);
|
|
102
|
-
}
|
|
103
|
-
function U(t, e, r, n = g, s) {
|
|
104
|
-
const i = {
|
|
105
|
-
fn: t,
|
|
106
|
-
state: n,
|
|
107
|
-
updatedAt: null,
|
|
108
|
-
owned: null,
|
|
109
|
-
sources: null,
|
|
110
|
-
sourceSlots: null,
|
|
111
|
-
cleanups: null,
|
|
112
|
-
value: e,
|
|
113
|
-
owner: a,
|
|
114
|
-
context: a ? a.context : null,
|
|
115
|
-
pure: r
|
|
116
|
-
};
|
|
117
|
-
return a === null || a !== $ && (a.owned ? a.owned.push(i) : a.owned = [i]), i;
|
|
118
|
-
}
|
|
119
|
-
function j(t) {
|
|
120
|
-
if (t.state === 0) return;
|
|
121
|
-
if (t.state === y) return w(t);
|
|
122
|
-
if (t.suspense && M(t.suspense.inFallback)) return t.suspense.effects.push(t);
|
|
123
|
-
const e = [t];
|
|
124
|
-
for (; (t = t.owner) && (!t.updatedAt || t.updatedAt < S); )
|
|
125
|
-
t.state && e.push(t);
|
|
126
|
-
for (let r = e.length - 1; r >= 0; r--)
|
|
127
|
-
if (t = e[r], t.state === g)
|
|
128
|
-
A(t);
|
|
129
|
-
else if (t.state === y) {
|
|
130
|
-
const n = f;
|
|
131
|
-
f = null, L(() => w(t, e[0])), f = n;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function L(t, e) {
|
|
135
|
-
if (f) return t();
|
|
136
|
-
let r = !1;
|
|
137
|
-
f = [], h ? r = !0 : h = [], S++;
|
|
138
|
-
try {
|
|
139
|
-
const n = t();
|
|
140
|
-
return it(r), n;
|
|
141
|
-
} catch (n) {
|
|
142
|
-
r || (h = null), f = null, G(n);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function it(t) {
|
|
146
|
-
if (f && (H(f), f = null), t) return;
|
|
147
|
-
const e = h;
|
|
148
|
-
h = null, e.length && L(() => Z(e));
|
|
149
|
-
}
|
|
150
|
-
function H(t) {
|
|
151
|
-
for (let e = 0; e < t.length; e++) j(t[e]);
|
|
152
|
-
}
|
|
153
|
-
function w(t, e) {
|
|
154
|
-
t.state = 0;
|
|
155
|
-
for (let r = 0; r < t.sources.length; r += 1) {
|
|
156
|
-
const n = t.sources[r];
|
|
157
|
-
if (n.sources) {
|
|
158
|
-
const s = n.state;
|
|
159
|
-
s === g ? n !== e && (!n.updatedAt || n.updatedAt < S) && j(n) : s === y && w(n, e);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
function _(t) {
|
|
164
|
-
for (let e = 0; e < t.observers.length; e += 1) {
|
|
165
|
-
const r = t.observers[e];
|
|
166
|
-
r.state || (r.state = y, r.pure ? f.push(r) : h.push(r), r.observers && _(r));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function x(t) {
|
|
170
|
-
let e;
|
|
171
|
-
if (t.sources)
|
|
172
|
-
for (; t.sources.length; ) {
|
|
173
|
-
const r = t.sources.pop(), n = t.sourceSlots.pop(), s = r.observers;
|
|
174
|
-
if (s && s.length) {
|
|
175
|
-
const i = s.pop(), p = r.observerSlots.pop();
|
|
176
|
-
n < s.length && (i.sourceSlots[p] = n, s[n] = i, r.observerSlots[n] = p);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (t.tOwned) {
|
|
180
|
-
for (e = t.tOwned.length - 1; e >= 0; e--) x(t.tOwned[e]);
|
|
181
|
-
delete t.tOwned;
|
|
182
|
-
}
|
|
183
|
-
if (t.owned) {
|
|
184
|
-
for (e = t.owned.length - 1; e >= 0; e--) x(t.owned[e]);
|
|
185
|
-
t.owned = null;
|
|
186
|
-
}
|
|
187
|
-
if (t.cleanups) {
|
|
188
|
-
for (e = t.cleanups.length - 1; e >= 0; e--) t.cleanups[e]();
|
|
189
|
-
t.cleanups = null;
|
|
190
|
-
}
|
|
191
|
-
t.state = 0;
|
|
192
|
-
}
|
|
193
|
-
function ut(t) {
|
|
194
|
-
return t instanceof Error ? t : new Error(typeof t == "string" ? t : "Unknown error", {
|
|
195
|
-
cause: t
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
function G(t, e = a) {
|
|
199
|
-
throw ut(t);
|
|
200
|
-
}
|
|
201
|
-
function V(t) {
|
|
202
|
-
if (typeof t == "function" && !t.length) return V(t());
|
|
203
|
-
if (Array.isArray(t)) {
|
|
204
|
-
const e = [];
|
|
205
|
-
for (let r = 0; r < t.length; r++) {
|
|
206
|
-
const n = V(t[r]);
|
|
207
|
-
Array.isArray(n) ? e.push.apply(e, n) : e.push(n);
|
|
208
|
-
}
|
|
209
|
-
return e;
|
|
210
|
-
}
|
|
211
|
-
return t;
|
|
212
|
-
}
|
|
213
|
-
function ct(t, e) {
|
|
214
|
-
return function(n) {
|
|
215
|
-
let s;
|
|
216
|
-
return et(
|
|
217
|
-
() => s = M(() => (a.context = {
|
|
218
|
-
...a.context,
|
|
219
|
-
[t]: n.value
|
|
220
|
-
}, st(() => n.children))),
|
|
221
|
-
void 0
|
|
222
|
-
), s;
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
const lt = (t) => {
|
|
226
|
-
const e = t.target;
|
|
227
|
-
return e instanceof HTMLSelectElement ? e.value : e instanceof HTMLInputElement && e.type === "checkbox" ? e.checked : e.value;
|
|
228
|
-
}, D = (t, e) => {
|
|
229
|
-
if (t instanceof HTMLSelectElement) {
|
|
230
|
-
t.value = e;
|
|
1
|
+
import { createSignal as p, createContext as q, useContext as M } from "solid-js";
|
|
2
|
+
const S = (e) => {
|
|
3
|
+
const n = e.target;
|
|
4
|
+
return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n.value;
|
|
5
|
+
}, y = (e, n) => {
|
|
6
|
+
if (e instanceof HTMLSelectElement) {
|
|
7
|
+
e.value = n;
|
|
231
8
|
return;
|
|
232
9
|
}
|
|
233
|
-
if (
|
|
234
|
-
|
|
10
|
+
if (e instanceof HTMLInputElement && e.type === "checkbox") {
|
|
11
|
+
e.checked = n;
|
|
235
12
|
return;
|
|
236
13
|
}
|
|
237
|
-
|
|
238
|
-
},
|
|
239
|
-
const
|
|
240
|
-
if (r.required && !
|
|
241
|
-
return { type: "required", message:
|
|
242
|
-
if (r.min && Number(
|
|
243
|
-
return { type: "min", message:
|
|
244
|
-
if (r.max && Number(
|
|
245
|
-
return { type: "max", message:
|
|
246
|
-
if (r.minLength &&
|
|
247
|
-
return { type: "minLength", message:
|
|
248
|
-
if (r.maxLength &&
|
|
249
|
-
return { type: "maxLength", message:
|
|
250
|
-
if (r.pattern && !
|
|
251
|
-
return { type: "pattern", message:
|
|
14
|
+
e.value = n;
|
|
15
|
+
}, g = (e) => e instanceof RegExp || typeof e == "string" || typeof e == "number" ? e : e.value, m = (e) => typeof e == "string" ? e : typeof e.message == "string" ? e.message : "", H = (e, n, r = {}) => {
|
|
16
|
+
const i = e[n];
|
|
17
|
+
if (r.required && !i)
|
|
18
|
+
return { type: "required", message: m(r.required) };
|
|
19
|
+
if (r.min && Number(i) < Number(g(r.min)))
|
|
20
|
+
return { type: "min", message: m(r.min) };
|
|
21
|
+
if (r.max && Number(i) > Number(g(r.max)))
|
|
22
|
+
return { type: "max", message: m(r.max) };
|
|
23
|
+
if (r.minLength && i.length < g(r.minLength))
|
|
24
|
+
return { type: "minLength", message: m(r.minLength) };
|
|
25
|
+
if (r.maxLength && i.length > g(r.maxLength))
|
|
26
|
+
return { type: "maxLength", message: m(r.maxLength) };
|
|
27
|
+
if (r.pattern && !g(r.pattern).test(i))
|
|
28
|
+
return { type: "pattern", message: m(r.pattern) };
|
|
252
29
|
if (r.validate) {
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
30
|
+
const a = r.validate(i, e);
|
|
31
|
+
if (a === !1)
|
|
255
32
|
return { type: "validate" };
|
|
256
|
-
if (typeof
|
|
257
|
-
return { type: "validate", message:
|
|
33
|
+
if (typeof a == "string")
|
|
34
|
+
return { type: "validate", message: a };
|
|
258
35
|
}
|
|
259
|
-
},
|
|
260
|
-
const [
|
|
36
|
+
}, N = () => {
|
|
37
|
+
const [e, n] = p({});
|
|
261
38
|
return {
|
|
262
|
-
errors:
|
|
263
|
-
appendError: (
|
|
264
|
-
|
|
39
|
+
errors: e,
|
|
40
|
+
appendError: (c, f) => {
|
|
41
|
+
n((u) => ({ ...u, [c]: f }));
|
|
265
42
|
},
|
|
266
|
-
removeError: (
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
return delete
|
|
43
|
+
removeError: (c) => {
|
|
44
|
+
n((f) => {
|
|
45
|
+
const u = { ...f };
|
|
46
|
+
return delete u[c], u;
|
|
270
47
|
});
|
|
271
48
|
},
|
|
272
49
|
resetErrors: () => {
|
|
273
|
-
|
|
50
|
+
n({});
|
|
274
51
|
}
|
|
275
52
|
};
|
|
276
|
-
},
|
|
277
|
-
defaultValues:
|
|
278
|
-
mode:
|
|
53
|
+
}, w = ({
|
|
54
|
+
defaultValues: e,
|
|
55
|
+
mode: n = "onInput"
|
|
279
56
|
}) => {
|
|
280
|
-
const r = {},
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
},
|
|
284
|
-
|
|
285
|
-
},
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
},
|
|
289
|
-
Object.keys(
|
|
290
|
-
|
|
57
|
+
const r = {}, i = {}, [a, c] = p(e), { errors: f, appendError: u, removeError: F, resetErrors: b } = N(), [h, l] = p(!0), C = (t, o) => {
|
|
58
|
+
const s = r[t];
|
|
59
|
+
s && (o.ref = s), u(t, o);
|
|
60
|
+
}, V = (t) => {
|
|
61
|
+
F(t);
|
|
62
|
+
}, v = (t) => {
|
|
63
|
+
const o = i[t], s = H(a(), t, o);
|
|
64
|
+
s ? C(t, s) : V(t), l(!Object.keys(f()).length);
|
|
65
|
+
}, I = () => {
|
|
66
|
+
Object.keys(a()).forEach((t) => {
|
|
67
|
+
v(t);
|
|
291
68
|
});
|
|
292
|
-
},
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
},
|
|
296
|
-
required:
|
|
297
|
-
min:
|
|
298
|
-
max:
|
|
299
|
-
minLength:
|
|
300
|
-
maxLength:
|
|
301
|
-
pattern:
|
|
302
|
-
validate:
|
|
69
|
+
}, x = (t, o) => {
|
|
70
|
+
const s = S(t);
|
|
71
|
+
c((d) => ({ ...d, [o]: s })), v(o);
|
|
72
|
+
}, k = (t, o = {}) => (i[t] = {
|
|
73
|
+
required: o.required,
|
|
74
|
+
min: o.min,
|
|
75
|
+
max: o.max,
|
|
76
|
+
minLength: o.minLength,
|
|
77
|
+
maxLength: o.maxLength,
|
|
78
|
+
pattern: o.pattern,
|
|
79
|
+
validate: o.validate
|
|
303
80
|
}, {
|
|
304
|
-
name:
|
|
81
|
+
name: t,
|
|
305
82
|
// value: values()[name],
|
|
306
|
-
onInput(
|
|
307
|
-
|
|
83
|
+
onInput(s) {
|
|
84
|
+
n === "onInput" && x(s, t);
|
|
308
85
|
},
|
|
309
|
-
onChange(
|
|
310
|
-
(
|
|
86
|
+
onChange(s) {
|
|
87
|
+
(n === "onChange" || n === "onInput") && x(s, t);
|
|
311
88
|
},
|
|
312
|
-
ref(
|
|
313
|
-
r[
|
|
89
|
+
ref(s) {
|
|
90
|
+
r[t] || (r[t] = s, s && y(s, a()[t]));
|
|
314
91
|
}
|
|
315
|
-
}),
|
|
92
|
+
}), E = (t) => t ? a()[t] : a();
|
|
316
93
|
return {
|
|
317
|
-
values:
|
|
318
|
-
errors:
|
|
319
|
-
isValid:
|
|
320
|
-
register:
|
|
321
|
-
getValues:
|
|
322
|
-
setValue: (
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
|
|
94
|
+
values: a,
|
|
95
|
+
errors: f,
|
|
96
|
+
isValid: h,
|
|
97
|
+
register: k,
|
|
98
|
+
getValues: E,
|
|
99
|
+
setValue: (t, o) => {
|
|
100
|
+
c((d) => ({ ...d, [t]: o }));
|
|
101
|
+
const s = r[t];
|
|
102
|
+
s && y(s, o);
|
|
326
103
|
},
|
|
327
|
-
onSubmit: (
|
|
328
|
-
|
|
104
|
+
onSubmit: (t) => (o) => {
|
|
105
|
+
o.preventDefault(), I(), h() && t(E());
|
|
329
106
|
},
|
|
330
|
-
reset: (
|
|
331
|
-
|
|
332
|
-
...
|
|
333
|
-
...
|
|
334
|
-
})),
|
|
107
|
+
reset: (t = {}) => {
|
|
108
|
+
c(() => ({
|
|
109
|
+
...e,
|
|
110
|
+
...t
|
|
111
|
+
})), b(), l(!0);
|
|
335
112
|
}
|
|
336
113
|
};
|
|
337
|
-
},
|
|
338
|
-
const
|
|
339
|
-
if (!
|
|
114
|
+
}, L = q({}), O = (e) => /* @__PURE__ */ React.createElement(L.Provider, { value: e.form }, e.children), A = () => {
|
|
115
|
+
const e = M(L);
|
|
116
|
+
if (!e)
|
|
340
117
|
throw new Error("useFormContext: cannot find a FormProvider");
|
|
341
|
-
return
|
|
118
|
+
return e;
|
|
342
119
|
};
|
|
343
120
|
export {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
121
|
+
O as FormProvider,
|
|
122
|
+
w as useForm,
|
|
123
|
+
A as useFormContext
|
|
347
124
|
};
|
package/dist/main.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c["solid-hook-form"]={},c.solid))})(this,function(c,f){"use strict";const b=e=>{const n=e.target;return n instanceof HTMLSelectElement?n.value:n instanceof HTMLInputElement&&n.type==="checkbox"?n.checked:n.value},l=(e,n)=>{if(e instanceof HTMLSelectElement){e.value=n;return}if(e instanceof HTMLInputElement&&e.type==="checkbox"){e.checked=n;return}e.value=n},p=e=>e instanceof RegExp||typeof e=="string"||typeof e=="number"?e:e.value,m=e=>typeof e=="string"?e:typeof e.message=="string"?e.message:"",C=(e,n,r={})=>{const s=e[n];if(r.required&&!s)return{type:"required",message:m(r.required)};if(r.min&&Number(s)<Number(p(r.min)))return{type:"min",message:m(r.min)};if(r.max&&Number(s)>Number(p(r.max)))return{type:"max",message:m(r.max)};if(r.minLength&&s.length<p(r.minLength))return{type:"minLength",message:m(r.minLength)};if(r.maxLength&&s.length>p(r.maxLength))return{type:"maxLength",message:m(r.maxLength)};if(r.pattern&&!p(r.pattern).test(s))return{type:"pattern",message:m(r.pattern)};if(r.validate){const a=r.validate(s,e);if(a===!1)return{type:"validate"};if(typeof a=="string")return{type:"validate",message:a}}},S=()=>{const[e,n]=f.createSignal({});return{errors:e,appendError:(u,d)=>{n(g=>({...g,[u]:d}))},removeError:u=>{n(d=>{const g={...d};return delete g[u],g})},resetErrors:()=>{n({})}}},V=({defaultValues:e,mode:n="onInput"})=>{const r={},s={},[a,u]=f.createSignal(e),{errors:d,appendError:g,removeError:T,resetErrors:j}=S(),[x,y]=f.createSignal(!0),q=(t,o)=>{const i=r[t];i&&(o.ref=i),g(t,o)},M=t=>{T(t)},E=t=>{const o=s[t],i=C(a(),t,o);i?q(t,i):M(t),y(!Object.keys(d()).length)},P=()=>{Object.keys(a()).forEach(t=>{E(t)})},F=(t,o)=>{const i=b(t);u(h=>({...h,[o]:i})),E(o)},H=(t,o={})=>(s[t]={required:o.required,min:o.min,max:o.max,minLength:o.minLength,maxLength:o.maxLength,pattern:o.pattern,validate:o.validate},{name:t,onInput(i){n==="onInput"&&F(i,t)},onChange(i){(n==="onChange"||n==="onInput")&&F(i,t)},ref(i){r[t]||(r[t]=i,i&&l(i,a()[t]))}}),L=t=>t?a()[t]:a();return{values:a,errors:d,isValid:x,register:H,getValues:L,setValue:(t,o)=>{u(h=>({...h,[t]:o}));const i=r[t];i&&l(i,o)},onSubmit:t=>o=>{o.preventDefault(),P(),x()&&t(L())},reset:(t={})=>{u(()=>({...e,...t})),j(),y(!0)}}},v=f.createContext({}),k=e=>React.createElement(v.Provider,{value:e.form},e.children),I=()=>{const e=f.useContext(v);if(!e)throw new Error("useFormContext: cannot find a FormProvider");return e};c.FormProvider=k,c.useForm=V,c.useFormContext=I,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types/form.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Rules } from './validate';
|
|
|
4
4
|
import { FieldErrors } from './errors';
|
|
5
5
|
export type FormValues = Record<string, any>;
|
|
6
6
|
export type Ref = HTMLElement | null;
|
|
7
|
-
type RegisterReturn<F extends FormValues> = {
|
|
7
|
+
export type RegisterReturn<F extends FormValues> = {
|
|
8
8
|
name: Path<F>;
|
|
9
9
|
ref(ref: Ref): void;
|
|
10
10
|
onInput(event: Event): void;
|
|
@@ -16,7 +16,7 @@ export type GetValues<F extends FormValues> = {
|
|
|
16
16
|
<N extends FieldPath<F>>(name: N): FieldPathValue<F, N>;
|
|
17
17
|
};
|
|
18
18
|
export type SetValue<F extends FormValues> = (name: Path<F>, value: FieldPathValue<F, Path<F>>) => void;
|
|
19
|
-
type SubmitCallback<F extends FormValues> = (values: F) => void;
|
|
19
|
+
export type SubmitCallback<F extends FormValues> = (values: F) => void;
|
|
20
20
|
export type OnSubmit<F extends FormValues> = (submit: SubmitCallback<F>) => (event: SubmitEvent) => void;
|
|
21
21
|
export type Reset<F extends FormValues> = (newDefaultValues?: Partial<F>) => void;
|
|
22
22
|
export type UseFormReturn<F extends FormValues = FormValues> = {
|
|
@@ -30,4 +30,3 @@ export type UseFormReturn<F extends FormValues = FormValues> = {
|
|
|
30
30
|
reset: Reset<F>;
|
|
31
31
|
};
|
|
32
32
|
export type FormFields = Record<string, Ref>;
|
|
33
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-hook-form",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/main.umd.cjs",
|
|
6
6
|
"module": "./dist/main.js",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"solid-js": "^1.9.5"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
+
"@solidjs/testing-library": "^0.8.10",
|
|
23
|
+
"@testing-library/user-event": "^14.6.1",
|
|
24
|
+
"happy-dom": "^17.4.4",
|
|
22
25
|
"react-hook-form": "^7.55.0",
|
|
23
26
|
"typescript": "~5.7.2",
|
|
24
27
|
"vite": "^6.0.11",
|