solid-hook-form 1.3.6 → 1.4.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/logic/get_value.d.ts +1 -1
- package/dist/main.js +63 -53
- package/dist/main.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getFieldValue: (event: Event) => string | boolean;
|
|
1
|
+
export declare const getFieldValue: (event: Event) => string | boolean | FileList | null;
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createSignal as
|
|
2
|
-
const
|
|
1
|
+
import { createSignal as d, createContext as H, createComponent as T, useContext as q } from "solid-js";
|
|
2
|
+
const S = (e) => {
|
|
3
3
|
const n = e.target;
|
|
4
|
-
return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n.value;
|
|
4
|
+
return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n instanceof HTMLInputElement && n.type === "file" ? n.files : n.value;
|
|
5
5
|
}, y = (e, n) => {
|
|
6
6
|
if (e instanceof HTMLSelectElement) {
|
|
7
7
|
e.value = n;
|
|
@@ -11,65 +11,75 @@ const H = (e) => {
|
|
|
11
11
|
e.checked = n;
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
e.value = n;
|
|
15
|
-
},
|
|
14
|
+
e instanceof HTMLInputElement && e.type === "file" || (e.value = n);
|
|
15
|
+
}, p = (e) => e instanceof RegExp || typeof e == "string" || typeof e == "number" ? e : e.value, g = (e) => typeof e == "string" ? e : typeof e.message == "string" ? e.message : "", N = (e, n, r = {}) => {
|
|
16
16
|
const i = e[n];
|
|
17
17
|
if (r.required && !i)
|
|
18
18
|
return { type: "required", message: g(r.required) };
|
|
19
|
-
if (r.min && Number(i) < Number(
|
|
19
|
+
if (r.min && Number(i) < Number(p(r.min)))
|
|
20
20
|
return { type: "min", message: g(r.min) };
|
|
21
|
-
if (r.max && Number(i) > Number(
|
|
21
|
+
if (r.max && Number(i) > Number(p(r.max)))
|
|
22
22
|
return { type: "max", message: g(r.max) };
|
|
23
|
-
if (r.minLength && i.length <
|
|
23
|
+
if (r.minLength && i.length < p(r.minLength))
|
|
24
24
|
return { type: "minLength", message: g(r.minLength) };
|
|
25
|
-
if (r.maxLength && i.length >
|
|
25
|
+
if (r.maxLength && i.length > p(r.maxLength))
|
|
26
26
|
return { type: "maxLength", message: g(r.maxLength) };
|
|
27
|
-
if (r.pattern && !
|
|
27
|
+
if (r.pattern && !p(r.pattern).test(i))
|
|
28
28
|
return { type: "pattern", message: g(r.pattern) };
|
|
29
29
|
if (r.validate) {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
30
|
+
const c = r.validate(i, e);
|
|
31
|
+
if (c === !1)
|
|
32
32
|
return { type: "validate" };
|
|
33
|
-
if (typeof
|
|
34
|
-
return { type: "validate", message:
|
|
33
|
+
if (typeof c == "string")
|
|
34
|
+
return { type: "validate", message: c };
|
|
35
35
|
}
|
|
36
|
-
},
|
|
37
|
-
const [e, n] =
|
|
36
|
+
}, j = () => {
|
|
37
|
+
const [e, n] = d({});
|
|
38
38
|
return {
|
|
39
39
|
errors: e,
|
|
40
|
-
appendError: (
|
|
41
|
-
n((
|
|
40
|
+
appendError: (a, f) => {
|
|
41
|
+
n((m) => ({ ...m, [a]: f }));
|
|
42
42
|
},
|
|
43
|
-
removeError: (
|
|
43
|
+
removeError: (a) => {
|
|
44
44
|
n((f) => {
|
|
45
|
-
const
|
|
46
|
-
return delete
|
|
45
|
+
const m = { ...f };
|
|
46
|
+
return delete m[a], m;
|
|
47
47
|
});
|
|
48
48
|
},
|
|
49
49
|
resetErrors: () => {
|
|
50
50
|
n({});
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
},
|
|
53
|
+
}, A = ({
|
|
54
54
|
defaultValues: e,
|
|
55
55
|
mode: n = "onInput"
|
|
56
56
|
}) => {
|
|
57
|
-
const r = {}, i = {}, [
|
|
57
|
+
const r = {}, i = {}, [c, a] = d(e), { errors: f, appendError: m, removeError: F, resetErrors: b } = j(), [l, h] = d(!0), C = (t, o) => {
|
|
58
58
|
const s = r[t];
|
|
59
|
-
s && (o.ref = s),
|
|
60
|
-
},
|
|
59
|
+
s && (o.ref = s), m(t, o);
|
|
60
|
+
}, I = (t) => {
|
|
61
61
|
F(t);
|
|
62
|
-
},
|
|
63
|
-
const o = i[t], s = N(
|
|
64
|
-
s ? C(t, s) :
|
|
65
|
-
},
|
|
66
|
-
Object.keys(
|
|
67
|
-
|
|
62
|
+
}, E = (t) => {
|
|
63
|
+
const o = i[t], s = N(c(), t, o);
|
|
64
|
+
s ? C(t, s) : I(t), h(!Object.keys(f()).length);
|
|
65
|
+
}, k = () => {
|
|
66
|
+
Object.keys(c()).forEach((t) => {
|
|
67
|
+
E(t);
|
|
68
68
|
});
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
}, V = () => {
|
|
70
|
+
var o;
|
|
71
|
+
const t = Object.keys(r);
|
|
72
|
+
for (const s of t) {
|
|
73
|
+
const u = f()[s];
|
|
74
|
+
if (u) {
|
|
75
|
+
(o = u.ref) == null || o.focus();
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, v = (t, o) => {
|
|
80
|
+
const s = S(t);
|
|
81
|
+
a((u) => ({ ...u, [o]: s })), E(o);
|
|
82
|
+
}, M = (t, o = {}) => (i[t] = {
|
|
73
83
|
required: o.required,
|
|
74
84
|
min: o.min,
|
|
75
85
|
max: o.max,
|
|
@@ -81,51 +91,51 @@ const H = (e) => {
|
|
|
81
91
|
name: t,
|
|
82
92
|
// value: values()[name],
|
|
83
93
|
onInput(s) {
|
|
84
|
-
n === "onInput" &&
|
|
94
|
+
n === "onInput" && v(s, t);
|
|
85
95
|
},
|
|
86
96
|
onChange(s) {
|
|
87
|
-
(n === "onChange" || n === "onInput") &&
|
|
97
|
+
(n === "onChange" || n === "onInput") && v(s, t);
|
|
88
98
|
},
|
|
89
99
|
ref(s) {
|
|
90
|
-
r[t] || (r[t] = s, s && y(s,
|
|
100
|
+
r[t] || (r[t] = s, s && y(s, c()[t]));
|
|
91
101
|
}
|
|
92
|
-
}),
|
|
102
|
+
}), x = (t) => t ? c()[t] : c();
|
|
93
103
|
return {
|
|
94
|
-
values:
|
|
104
|
+
values: c,
|
|
95
105
|
errors: f,
|
|
96
|
-
isValid:
|
|
97
|
-
register:
|
|
98
|
-
getValues:
|
|
106
|
+
isValid: l,
|
|
107
|
+
register: M,
|
|
108
|
+
getValues: x,
|
|
99
109
|
setValue: (t, o) => {
|
|
100
|
-
|
|
110
|
+
a((u) => ({ ...u, [t]: o }));
|
|
101
111
|
const s = r[t];
|
|
102
112
|
s && y(s, o);
|
|
103
113
|
},
|
|
104
114
|
onSubmit: (t) => (o) => {
|
|
105
|
-
o.preventDefault(),
|
|
115
|
+
o.preventDefault(), k(), l() && t(x()), V();
|
|
106
116
|
},
|
|
107
117
|
reset: (t = {}) => {
|
|
108
|
-
|
|
118
|
+
a(() => ({
|
|
109
119
|
...e,
|
|
110
120
|
...t
|
|
111
|
-
})), b(),
|
|
121
|
+
})), b(), h(!0);
|
|
112
122
|
}
|
|
113
123
|
};
|
|
114
|
-
}, L =
|
|
124
|
+
}, L = H(), D = (e) => T(L.Provider, {
|
|
115
125
|
get value() {
|
|
116
126
|
return e.form;
|
|
117
127
|
},
|
|
118
128
|
get children() {
|
|
119
129
|
return e.children;
|
|
120
130
|
}
|
|
121
|
-
}),
|
|
122
|
-
const e =
|
|
131
|
+
}), z = () => {
|
|
132
|
+
const e = q(L);
|
|
123
133
|
if (!e)
|
|
124
134
|
throw new Error("useFormContext: cannot find a FormProvider");
|
|
125
135
|
return e;
|
|
126
136
|
};
|
|
127
137
|
export {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
D as FormProvider,
|
|
139
|
+
A as useForm,
|
|
140
|
+
z as useFormContext
|
|
131
141
|
};
|
package/dist/main.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,
|
|
1
|
+
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f["solid-hook-form"]={},f.solid))})(this,function(f,a){"use strict";const b=e=>{const n=e.target;return n instanceof HTMLSelectElement?n.value:n instanceof HTMLInputElement&&n.type==="checkbox"?n.checked:n instanceof HTMLInputElement&&n.type==="file"?n.files:n.value},h=(e,n)=>{if(e instanceof HTMLSelectElement){e.value=n;return}if(e instanceof HTMLInputElement&&e.type==="checkbox"){e.checked=n;return}e instanceof HTMLInputElement&&e.type==="file"||(e.value=n)},l=e=>e instanceof RegExp||typeof e=="string"||typeof e=="number"?e:e.value,d=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:d(r.required)};if(r.min&&Number(s)<Number(l(r.min)))return{type:"min",message:d(r.min)};if(r.max&&Number(s)>Number(l(r.max)))return{type:"max",message:d(r.max)};if(r.minLength&&s.length<l(r.minLength))return{type:"minLength",message:d(r.minLength)};if(r.maxLength&&s.length>l(r.maxLength))return{type:"maxLength",message:d(r.maxLength)};if(r.pattern&&!l(r.pattern).test(s))return{type:"pattern",message:d(r.pattern)};if(r.validate){const c=r.validate(s,e);if(c===!1)return{type:"validate"};if(typeof c=="string")return{type:"validate",message:c}}},k=()=>{const[e,n]=a.createSignal({});return{errors:e,appendError:(u,m)=>{n(p=>({...p,[u]:m}))},removeError:u=>{n(m=>{const p={...m};return delete p[u],p})},resetErrors:()=>{n({})}}},I=({defaultValues:e,mode:n="onInput"})=>{const r={},s={},[c,u]=a.createSignal(e),{errors:m,appendError:p,removeError:M,resetErrors:V}=k(),[v,E]=a.createSignal(!0),j=(t,o)=>{const i=r[t];i&&(o.ref=i),p(t,o)},q=t=>{M(t)},x=t=>{const o=s[t],i=C(c(),t,o);i?j(t,i):q(t),E(!Object.keys(m()).length)},H=()=>{Object.keys(c()).forEach(t=>{x(t)})},P=()=>{var o;const t=Object.keys(r);for(const i of t){const g=m()[i];if(g){(o=g.ref)==null||o.focus();break}}},L=(t,o)=>{const i=b(t);u(g=>({...g,[o]:i})),x(o)},N=(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"&&L(i,t)},onChange(i){(n==="onChange"||n==="onInput")&&L(i,t)},ref(i){r[t]||(r[t]=i,i&&h(i,c()[t]))}}),F=t=>t?c()[t]:c();return{values:c,errors:m,isValid:v,register:N,getValues:F,setValue:(t,o)=>{u(g=>({...g,[t]:o}));const i=r[t];i&&h(i,o)},onSubmit:t=>o=>{o.preventDefault(),H(),v()&&t(F()),P()},reset:(t={})=>{u(()=>({...e,...t})),V(),E(!0)}}},y=a.createContext(),S=e=>a.createComponent(y.Provider,{get value(){return e.form},get children(){return e.children}}),T=()=>{const e=a.useContext(y);if(!e)throw new Error("useFormContext: cannot find a FormProvider");return e};f.FormProvider=S,f.useForm=I,f.useFormContext=T,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|