solid-hook-form 1.3.4 → 1.3.6

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 FormContext: import('solid-js').Context<{}>;
1
+ export declare const FormContext: import('solid-js').Context<unknown>;
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createSignal as p, createContext as q, useContext as M } from "solid-js";
2
- const S = (e) => {
1
+ import { createSignal as p, createContext as q, createComponent as M, useContext as S } from "solid-js";
2
+ const H = (e) => {
3
3
  const n = e.target;
4
4
  return n instanceof HTMLSelectElement ? n.value : n instanceof HTMLInputElement && n.type === "checkbox" ? n.checked : n.value;
5
5
  }, y = (e, n) => {
@@ -12,20 +12,20 @@ const S = (e) => {
12
12
  return;
13
13
  }
14
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 = {}) => {
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 = {}) => {
16
16
  const i = e[n];
17
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) };
18
+ return { type: "required", message: g(r.required) };
19
+ if (r.min && Number(i) < Number(m(r.min)))
20
+ return { type: "min", message: g(r.min) };
21
+ if (r.max && Number(i) > Number(m(r.max)))
22
+ return { type: "max", message: g(r.max) };
23
+ if (r.minLength && i.length < m(r.minLength))
24
+ return { type: "minLength", message: g(r.minLength) };
25
+ if (r.maxLength && i.length > m(r.maxLength))
26
+ return { type: "maxLength", message: g(r.maxLength) };
27
+ if (r.pattern && !m(r.pattern).test(i))
28
+ return { type: "pattern", message: g(r.pattern) };
29
29
  if (r.validate) {
30
30
  const a = r.validate(i, e);
31
31
  if (a === !1)
@@ -33,7 +33,7 @@ const S = (e) => {
33
33
  if (typeof a == "string")
34
34
  return { type: "validate", message: a };
35
35
  }
36
- }, N = () => {
36
+ }, T = () => {
37
37
  const [e, n] = p({});
38
38
  return {
39
39
  errors: e,
@@ -50,24 +50,24 @@ const S = (e) => {
50
50
  n({});
51
51
  }
52
52
  };
53
- }, w = ({
53
+ }, O = ({
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 } = N(), [h, l] = p(!0), C = (t, o) => {
57
+ const r = {}, i = {}, [a, c] = p(e), { errors: f, appendError: u, removeError: F, resetErrors: b } = T(), [h, l] = p(!0), C = (t, o) => {
58
58
  const s = r[t];
59
59
  s && (o.ref = s), u(t, o);
60
60
  }, V = (t) => {
61
61
  F(t);
62
62
  }, v = (t) => {
63
- const o = i[t], s = H(a(), t, o);
63
+ const o = i[t], s = N(a(), t, o);
64
64
  s ? C(t, s) : V(t), l(!Object.keys(f()).length);
65
65
  }, I = () => {
66
66
  Object.keys(a()).forEach((t) => {
67
67
  v(t);
68
68
  });
69
69
  }, x = (t, o) => {
70
- const s = S(t);
70
+ const s = H(t);
71
71
  c((d) => ({ ...d, [o]: s })), v(o);
72
72
  }, k = (t, o = {}) => (i[t] = {
73
73
  required: o.required,
@@ -111,14 +111,21 @@ const S = (e) => {
111
111
  })), b(), l(!0);
112
112
  }
113
113
  };
114
- }, L = q({}), O = (e) => /* @__PURE__ */ React.createElement(L.Provider, { value: e.form }, e.children), A = () => {
115
- const e = M(L);
114
+ }, L = q(), A = (e) => M(L.Provider, {
115
+ get value() {
116
+ return e.form;
117
+ },
118
+ get children() {
119
+ return e.children;
120
+ }
121
+ }), D = () => {
122
+ const e = S(L);
116
123
  if (!e)
117
124
  throw new Error("useFormContext: cannot find a FormProvider");
118
125
  return e;
119
126
  };
120
127
  export {
121
- O as FormProvider,
122
- w as useForm,
123
- A as useFormContext
128
+ A as FormProvider,
129
+ O as useForm,
130
+ D as useFormContext
124
131
  };
package/dist/main.umd.cjs CHANGED
@@ -1 +1 @@
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"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-hook-form",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "type": "module",
5
5
  "main": "./dist/main.umd.cjs",
6
6
  "module": "./dist/main.js",