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.
@@ -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 p, createContext as q, createComponent as M, useContext as S } from "solid-js";
2
- const H = (e) => {
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
- }, m = (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 = {}) => {
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(m(r.min)))
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(m(r.max)))
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 < m(r.minLength))
23
+ if (r.minLength && i.length < p(r.minLength))
24
24
  return { type: "minLength", message: g(r.minLength) };
25
- if (r.maxLength && i.length > m(r.maxLength))
25
+ if (r.maxLength && i.length > p(r.maxLength))
26
26
  return { type: "maxLength", message: g(r.maxLength) };
27
- if (r.pattern && !m(r.pattern).test(i))
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 a = r.validate(i, e);
31
- if (a === !1)
30
+ const c = r.validate(i, e);
31
+ if (c === !1)
32
32
  return { type: "validate" };
33
- if (typeof a == "string")
34
- return { type: "validate", message: a };
33
+ if (typeof c == "string")
34
+ return { type: "validate", message: c };
35
35
  }
36
- }, T = () => {
37
- const [e, n] = p({});
36
+ }, j = () => {
37
+ const [e, n] = d({});
38
38
  return {
39
39
  errors: e,
40
- appendError: (c, f) => {
41
- n((u) => ({ ...u, [c]: f }));
40
+ appendError: (a, f) => {
41
+ n((m) => ({ ...m, [a]: f }));
42
42
  },
43
- removeError: (c) => {
43
+ removeError: (a) => {
44
44
  n((f) => {
45
- const u = { ...f };
46
- return delete u[c], u;
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
- }, O = ({
53
+ }, A = ({
54
54
  defaultValues: e,
55
55
  mode: n = "onInput"
56
56
  }) => {
57
- const r = {}, i = {}, [a, c] = p(e), { errors: f, appendError: u, removeError: F, resetErrors: b } = T(), [h, l] = p(!0), C = (t, o) => {
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), u(t, o);
60
- }, V = (t) => {
59
+ s && (o.ref = s), m(t, o);
60
+ }, I = (t) => {
61
61
  F(t);
62
- }, v = (t) => {
63
- const o = i[t], s = N(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);
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
- }, x = (t, o) => {
70
- const s = H(t);
71
- c((d) => ({ ...d, [o]: s })), v(o);
72
- }, k = (t, o = {}) => (i[t] = {
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" && x(s, t);
94
+ n === "onInput" && v(s, t);
85
95
  },
86
96
  onChange(s) {
87
- (n === "onChange" || n === "onInput") && x(s, t);
97
+ (n === "onChange" || n === "onInput") && v(s, t);
88
98
  },
89
99
  ref(s) {
90
- r[t] || (r[t] = s, s && y(s, a()[t]));
100
+ r[t] || (r[t] = s, s && y(s, c()[t]));
91
101
  }
92
- }), E = (t) => t ? a()[t] : a();
102
+ }), x = (t) => t ? c()[t] : c();
93
103
  return {
94
- values: a,
104
+ values: c,
95
105
  errors: f,
96
- isValid: h,
97
- register: k,
98
- getValues: E,
106
+ isValid: l,
107
+ register: M,
108
+ getValues: x,
99
109
  setValue: (t, o) => {
100
- c((d) => ({ ...d, [t]: o }));
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(), I(), h() && t(E());
115
+ o.preventDefault(), k(), l() && t(x()), V();
106
116
  },
107
117
  reset: (t = {}) => {
108
- c(() => ({
118
+ a(() => ({
109
119
  ...e,
110
120
  ...t
111
- })), b(), l(!0);
121
+ })), b(), h(!0);
112
122
  }
113
123
  };
114
- }, L = q(), A = (e) => M(L.Provider, {
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
- }), D = () => {
122
- const e = S(L);
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
- A as FormProvider,
129
- O as useForm,
130
- D as useFormContext
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,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("solid-js")):typeof define=="function"&&define.amd?define(["exports","solid-js"],c):(f=typeof globalThis<"u"?globalThis:f||self,c(f["solid-hook-form"]={},f.solid))})(this,function(f,c){"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]=c.createSignal({});return{errors:e,appendError:(u,g)=>{n(d=>({...d,[u]:g}))},removeError:u=>{n(g=>{const d={...g};return delete d[u],d})},resetErrors:()=>{n({})}}},V=({defaultValues:e,mode:n="onInput"})=>{const r={},s={},[a,u]=c.createSignal(e),{errors:g,appendError:d,removeError:T,resetErrors:j}=S(),[x,y]=c.createSignal(!0),q=(t,o)=>{const i=r[t];i&&(o.ref=i),d(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(g()).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:g,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=c.createContext(),k=e=>c.createComponent(v.Provider,{get value(){return e.form},get children(){return e.children}}),I=()=>{const e=c.useContext(v);if(!e)throw new Error("useFormContext: cannot find a FormProvider");return e};f.FormProvider=k,f.useForm=V,f.useFormContext=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-hook-form",
3
- "version": "1.3.6",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/main.umd.cjs",
6
6
  "module": "./dist/main.js",