@overgaming/valiform 0.1.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.
Files changed (66) hide show
  1. package/README.md +0 -0
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.js +948 -0
  4. package/dist/index.umd.cjs +1 -0
  5. package/dist/src/components/Field.vue.d.ts +56 -0
  6. package/dist/src/components/Form.vue.d.ts +39 -0
  7. package/dist/src/components/__tests__/Field.test.d.ts +1 -0
  8. package/dist/src/components/__tests__/Form.test.d.ts +1 -0
  9. package/dist/src/components/__tests__/components/CustomInput.vue.d.ts +9 -0
  10. package/dist/src/components/__tests__/components/CustomSelect.vue.d.ts +19 -0
  11. package/dist/src/components/__tests__/components/ExampleField.vue.d.ts +53 -0
  12. package/dist/src/components/__tests__/components/ExampleForm.vue.d.ts +40 -0
  13. package/dist/src/components/__tests__/components/ExampleFormWithNestedFields.vue.d.ts +51 -0
  14. package/dist/src/composables/useFormContext.d.ts +1 -0
  15. package/dist/src/composables/useLocale.d.ts +2 -0
  16. package/dist/src/composables/useValidation.d.ts +14 -0
  17. package/dist/src/context/useFieldContext.d.ts +5 -0
  18. package/dist/src/context/useFormContext.d.ts +5 -0
  19. package/dist/src/context/useFormStateContext.d.ts +5 -0
  20. package/dist/src/context/useLocaleContext.d.ts +4 -0
  21. package/dist/src/locales/en.d.ts +2 -0
  22. package/dist/src/locales/es.d.ts +2 -0
  23. package/dist/src/plugins/FormsPlugin.d.ts +5 -0
  24. package/dist/src/test/setup.d.ts +1 -0
  25. package/dist/src/types.d.ts +84 -0
  26. package/dist/src/utils/parseRules.d.ts +2 -0
  27. package/dist/src/utils/validation.d.ts +1 -0
  28. package/dist/src/utils/valueByPath.d.ts +2 -0
  29. package/dist/src/validation/index.d.ts +3 -0
  30. package/dist/src/validation/registry.d.ts +5 -0
  31. package/dist/src/validation/rules/accepted.d.ts +2 -0
  32. package/dist/src/validation/rules/alpha.d.ts +2 -0
  33. package/dist/src/validation/rules/alphaSpaces.d.ts +2 -0
  34. package/dist/src/validation/rules/alphanumeric.d.ts +2 -0
  35. package/dist/src/validation/rules/between.d.ts +2 -0
  36. package/dist/src/validation/rules/confirm.d.ts +2 -0
  37. package/dist/src/validation/rules/containsAlpha.d.ts +2 -0
  38. package/dist/src/validation/rules/containsAlphaSpaces.d.ts +2 -0
  39. package/dist/src/validation/rules/containsAlphanumeric.d.ts +2 -0
  40. package/dist/src/validation/rules/containsLowercase.d.ts +2 -0
  41. package/dist/src/validation/rules/containsNumeric.d.ts +2 -0
  42. package/dist/src/validation/rules/containsSymbol.d.ts +2 -0
  43. package/dist/src/validation/rules/containsUppercase.d.ts +2 -0
  44. package/dist/src/validation/rules/dateAfter.d.ts +2 -0
  45. package/dist/src/validation/rules/dateAfterOrEqual.d.ts +2 -0
  46. package/dist/src/validation/rules/dateBefore.d.ts +2 -0
  47. package/dist/src/validation/rules/dateBeforeOrEqual.d.ts +2 -0
  48. package/dist/src/validation/rules/dateBetween.d.ts +2 -0
  49. package/dist/src/validation/rules/dateFormat.d.ts +2 -0
  50. package/dist/src/validation/rules/email.d.ts +2 -0
  51. package/dist/src/validation/rules/endsWith.d.ts +2 -0
  52. package/dist/src/validation/rules/index.d.ts +34 -0
  53. package/dist/src/validation/rules/is.d.ts +2 -0
  54. package/dist/src/validation/rules/length.d.ts +2 -0
  55. package/dist/src/validation/rules/lowercase.d.ts +2 -0
  56. package/dist/src/validation/rules/matches.d.ts +2 -0
  57. package/dist/src/validation/rules/max.d.ts +2 -0
  58. package/dist/src/validation/rules/min.d.ts +2 -0
  59. package/dist/src/validation/rules/not.d.ts +2 -0
  60. package/dist/src/validation/rules/number.d.ts +2 -0
  61. package/dist/src/validation/rules/required.d.ts +2 -0
  62. package/dist/src/validation/rules/startsWith.d.ts +2 -0
  63. package/dist/src/validation/rules/symbol.d.ts +2 -0
  64. package/dist/src/validation/rules/uppercase.d.ts +2 -0
  65. package/dist/src/validation/rules/url.d.ts +2 -0
  66. package/package.json +60 -0
@@ -0,0 +1 @@
1
+ (function($,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):($=typeof globalThis<"u"?globalThis:$||self,o($.Valiform={},$.Vue))})(this,function($,o){"use strict";const S=Symbol("locale-context"),v=(e=null)=>{const t=o.inject(S,e);if(!t&&t!==null)throw new Error("Context with localeContextKey not found");return t},F={required:"This field is required",email:"Please enter a valid email address",min:({value:e})=>`Must be at least ${e}`,max:({value:e})=>`Must be at most ${e}`,matches:"Format is not valid",number:"Must be a valid number",accepted:"Must be accepted",alpha:"Must contain only alphabetical characters",alphanumeric:"Must contain only letters and numbers",alphaSpaces:"Must contain only letters and spaces",between:({min:e,max:t})=>`Must be between ${e} and ${t}`,confirm:({fieldName:e})=>`Must match ${e}`,containsAlpha:"Must contain at least one letter",containsAlphanumeric:"Must contain at least one letter or number",containsAlphaSpaces:"Must contain at least one letter or space",containsLowercase:"Must contain at least one lowercase letter",containsNumeric:"Must contain at least one number",containsSymbol:"Must contain at least one symbol",containsUppercase:"Must contain at least one uppercase letter",dateAfter:({date:e})=>e?`Must be after ${e}`:"Must be after today",dateAfterOrEqual:({date:e})=>e?`Must be after or equal to ${e}`:"Must be after or equal to today",dateBefore:({date:e})=>e?`Must be before ${e}`:"Must be before today",dateBeforeOrEqual:({date:e})=>e?`Must be before or equal to ${e}`:"Must be before or equal to today",dateBetween:({startDate:e,endDate:t})=>`Must be between ${e} and ${t}`,dateFormat:({format:e})=>`Must match the format ${e}`,endsWith:({suffix:e})=>Array.isArray(e)?`Must end with one of: ${e.map(t=>`"${t}"`).join(", ")}`:`Must end with "${e}"`,is:({allowedValues:e})=>`Must be one of: ${Array.isArray(e)?e.join(", "):e}`,length:({value:e,min:t,max:n})=>t!==void 0&&n!==void 0?`Must be between ${t} and ${n} characters`:e!==void 0?`Must be exactly ${e} characters`:"Invalid length",lowercase:"Must contain only lowercase characters",not:({disallowedValues:e})=>`Must not be one of: ${Array.isArray(e)?e.join(", "):e}`,startsWith:({prefix:e})=>Array.isArray(e)?`Must start with one of: ${e.join(", ")}`:`Must start with "${e}"`,symbol:"Must contain only symbols",uppercase:"Must contain only uppercase characters",url:"Must be a valid URL"},V=o.shallowRef(new Map),_=(e,t)=>{V.value.set(e,t)},j=e=>{Object.entries(e).forEach(([t,n])=>{_(t,n)})},z=e=>V.value.get(e);function I(e){const t=e.accepted;return typeof t=="function"?t({}):t??"Must be accepted"}function K(e){return e?["yes","on","1","true"].includes(String(e).toLowerCase()):!1}function U(e,t={}){const{messages:n={}}=t;return K(e)?!0:I(n)}function k(e){const t=e.alpha;return typeof t=="function"?t({}):t??"Must contain only alphabetical characters"}function Z(e){return e?/^[a-zA-Z]+$/.test(String(e)):!0}function Y(e,t={}){const{messages:n={}}=t;return Z(e)?!0:k(n)}function G(e){const t=e.alphanumeric;return typeof t=="function"?t({}):t??"Must contain only letters and numbers"}function H(e){return e?/^[a-zA-Z0-9]+$/.test(String(e)):!0}function J(e,t={}){const{messages:n={}}=t;return H(e)?!0:G(n)}function Q(e){const t=e.alphaSpaces;return typeof t=="function"?t({}):t??"Must contain only letters and spaces"}function X(e){return e?/^[a-zA-Z\s]+$/.test(String(e)):!0}function ee(e,t={}){const{messages:n={}}=t;return X(e)?!0:Q(n)}function te(e,t,n){const r=e.between;return typeof r=="function"?r({min:t,max:n}):r??`Must be between ${t} and ${n}`}function ne(e,t,n){if(!e&&e!==0)return!0;const r=Number(e);if(isNaN(r))return!1;const s=Number(t),a=Number(n);return isNaN(s)||isNaN(a)?!1:r>=s&&r<=a}function re(e,t={}){const{args:n=[],messages:r={}}=t,[s,a]=n;return ne(e,s,a)?!0:te(r,s,a)}function se(e,t){const n=e.confirm;return typeof n=="function"?n({fieldName:t}):n??`Must match ${t}`}function oe(e,t,n){var r;return e?n?e===((r=n[t])==null?void 0:r.value):!1:!0}function ae(e,t={}){const{args:n=[],messages:r={},fields:s={}}=t,[a]=n;return oe(e,a,s)?!0:se(r,a)}function ie(e){const t=e.containsAlpha;return typeof t=="function"?t({}):t??"Must contain at least one letter"}function ue(e){return e?/[a-zA-Z]/.test(String(e)):!0}function ce(e,t={}){const{messages:n={}}=t;return ue(e)?!0:ie(n)}function le(e){const t=e.containsAlphanumeric;return typeof t=="function"?t({}):t??"Must contain at least one letter or number"}function fe(e){return e?/[a-zA-Z0-9]/.test(String(e)):!0}function me(e,t={}){const{messages:n={}}=t;return fe(e)?!0:le(n)}function de(e){const t=e.containsAlphaSpaces;return typeof t=="function"?t({}):t??"Must contain at least one letter or space"}function ge(e){return e?/[a-zA-Z\s]/.test(String(e)):!0}function pe(e,t={}){const{messages:n={}}=t;return ge(e)?!0:de(n)}function be(e){const t=e.containsLowercase;return typeof t=="function"?t({}):t??"Must contain at least one lowercase letter"}function ye(e){return e?/[a-z]/.test(String(e)):!0}function $e(e,t={}){const{messages:n={}}=t;return ye(e)?!0:be(n)}function he(e){const t=e.containsNumeric;return typeof t=="function"?t({}):t??"Must contain at least one number"}function Me(e){return e?/\d/.test(String(e)):!0}function we(e,t={}){const{messages:n={}}=t;return Me(e)?!0:he(n)}function Ne(e){const t=e.containsSymbol;return typeof t=="function"?t({}):t??"Must contain at least one symbol"}function Ae(e){return e?/[^\w\s]/.test(String(e)):!0}function De(e,t={}){const{messages:n={}}=t;return Ae(e)?!0:Ne(n)}function Se(e){const t=e.containsUppercase;return typeof t=="function"?t({}):t??"Must contain at least one uppercase letter"}function ve(e){return e?/[A-Z]/.test(String(e)):!0}function Fe(e,t={}){const{messages:n={}}=t;return ve(e)?!0:Se(n)}function Ve(e,t){const n=e.dateAfter;return typeof n=="function"?n({date:t}):n??(t?`Must be after ${t}`:"Must be after today")}function je(e,t){if(!e)return!0;const n=new Date(String(e)),r=t?new Date(t):new Date;return!isNaN(n.getTime())&&!isNaN(r.getTime())&&n>r}function xe(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return je(e,s)?!0:Ve(r,s)}function Te(e,t){const n=e.dateAfterOrEqual;return typeof n=="function"?n({date:t}):n??(t?`Must be after or equal to ${t}`:"Must be after or equal to today")}function Pe(e,t){if(!e)return!0;const n=new Date(String(e)),r=t?new Date(t):new Date;return!isNaN(n.getTime())&&!isNaN(r.getTime())&&n>=r}function Ce(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Pe(e,s)?!0:Te(r,s)}function qe(e,t){const n=e.dateBefore;return typeof n=="function"?n({date:t}):n??(t?`Must be before ${t}`:"Must be before today")}function Ee(e,t){if(!e)return!0;const n=new Date(String(e)),r=t?new Date(t):new Date;return!isNaN(n.getTime())&&!isNaN(r.getTime())&&n<r}function Be(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ee(e,s)?!0:qe(r,s)}function Oe(e,t){const n=e.dateBeforeOrEqual;return typeof n=="function"?n({date:t}):n??(t?`Must be before or equal to ${t}`:"Must be before or equal to today")}function Re(e,t){if(!e)return!0;const n=new Date(String(e)),r=t?new Date(t):new Date;return!isNaN(n.getTime())&&!isNaN(r.getTime())&&n<=r}function Le(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Re(e,s)?!0:Oe(r,s)}function We(e,t,n){const r=e.dateBetween;return typeof r=="function"?r({startDate:t,endDate:n}):r??`Must be between ${t} and ${n}`}function _e(e,t,n){if(!e)return!0;const r=new Date(String(e)),s=new Date(t),a=new Date(n);return!isNaN(r.getTime())&&!isNaN(s.getTime())&&!isNaN(a.getTime())&&r>=s&&r<=a}function ze(e,t={}){const{args:n=[],messages:r={}}=t,[s,a]=n;return _e(e,s,a)?!0:We(r,s,a)}const Ie=e=>{const t=e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),n={YYYY:"\\d{4}",YY:"\\d{2}",MM:"(0[1-9]|1[012])",M:"([1-9]|1[012])",DD:"([012][0-9]|3[01])",D:"([012]?[0-9]|3[01])"};let r=t;return Object.keys(n).forEach(s=>{r=r.replace(new RegExp(s,"g"),n[s])}),new RegExp(`^${r}$`)};function Ke(e,t){const n=e.dateFormat;return typeof n=="function"?n({format:t}):n??`Must match the format ${t}`}function Ue(e,t){return e?t&&typeof t=="string"?Ie(t).test(String(e)):!isNaN(Date.parse(String(e))):!0}function ke(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ue(e,s)?!0:Ke(r,s)}function Ze(e){const t=e.email;return typeof t=="function"?t({}):t??"Please enter a valid email address"}function Ye(e){return e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(e)):!0}function Ge(e,t={}){const{messages:n={}}=t;return Ye(e)?!0:Ze(n)}function He(e,t){const n=e.endsWith;return typeof n=="function"?n({suffix:t.length===1?t[0]:t}):n??`Must end with: ${t.join(", ")}`}function Je(e,...t){if(!e)return!0;const n=String(e);return t.some(r=>n.endsWith(r))}function Qe(e,t={}){const{args:n=[],messages:r={}}=t;return Je(e,...n)?!0:He(r,n)}function Xe(e,t){const n=e.is;return typeof n=="function"?n({allowedValues:t}):n??`Must be one of: ${t.join(", ")}`}function et(e,...t){return!e&&e!==0&&e!==!1?!0:t.includes(String(e))}function tt(e,t={}){const{args:n=[],messages:r={}}=t;return et(e,...n)?!0:Xe(r,n)}function nt(e,t,n){const r=e.length;return n!==void 0?typeof r=="function"?r({min:t,max:n}):r??`Must be between ${t} and ${n} characters`:typeof r=="function"?r({value:t}):r??`Must be exactly ${t} characters`}function rt(e,t,n){if(!e&&e!==0)return!0;let r=0;if(typeof e=="string")r=e.length;else if(Array.isArray(e))r=e.length;else if(typeof e=="object"&&e!==null)r=Object.keys(e).length;else return!1;if(n!==void 0){const a=Number(t),i=Number(n);return!isNaN(a)&&!isNaN(i)&&r>=a&&r<=i}const s=Number(t);return!isNaN(s)&&r===s}function st(e,t={}){const{args:n=[],messages:r={}}=t,[s,a]=n;return rt(e,s,a)?!0:nt(r,s,a)}function ot(e){const t=e.lowercase;return typeof t=="function"?t({}):t??"Must contain only lowercase characters"}function at(e){return e?/^[a-z]+$/.test(String(e)):!0}function it(e,t={}){const{messages:n={}}=t;return at(e)?!0:ot(n)}function ut(e,t,n){const r=t.matches;return typeof r=="function"?r({value:e,pattern:n}):r??"Format is not valid"}function ct(e,t){if(!e)return!0;if(!t)return!1;try{if(t.startsWith("/")&&t.includes("/",1)){const n=t.lastIndexOf("/"),r=t.slice(1,n),s=t.slice(n+1);return new RegExp(r,s).test(String(e))}return String(e)===t}catch{return!1}}function lt(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return ct(e,s)?!0:ut(e,r,s)}function ft(e,t){const n=e.max;return typeof n=="function"?n({value:t}):n??`Must be at most ${t}`}function mt(e,t){if(!e&&e!==0)return!0;const n=Number(t);if(isNaN(n))return!1;if(typeof e=="number")return e<=n;if(typeof e=="string"){const r=Number(e);return isNaN(r)?e.length<=n:r<=n}return Array.isArray(e)?e.length<=n:!1}function dt(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return mt(e,s)?!0:ft(r,s)}function gt(e,t){const n=e.min;return typeof n=="function"?n({value:t}):n??`Must be at least ${t}`}function pt(e,t){if(!e&&e!==0)return!0;const n=Number(t);if(isNaN(n))return!1;if(typeof e=="number")return e>=n;if(typeof e=="string"){const r=Number(e);return isNaN(r)?e.length>=n:r>=n}return Array.isArray(e)?e.length>=n:!1}function bt(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return pt(e,s)?!0:gt(r,s)}function yt(e,t){const n=e.not;return typeof n=="function"?n({disallowedValues:t}):n??`Must not be one of: ${t.join(", ")}`}function $t(e,...t){return!e&&e!==0&&e!==!1?!0:!t.includes(String(e))}function ht(e,t={}){const{args:n=[],messages:r={}}=t;return $t(e,...n)?!0:yt(r,n)}function Mt(e){const t=e.number;return typeof t=="function"?t({}):t??"Must be a valid number"}function wt(e){if(e==null||e==="")return!0;if(Number.isNaN(e))return!1;const t=Number(e);return!isNaN(t)&&isFinite(t)}function Nt(e,t={}){const{messages:n={}}=t;return wt(e)?!0:Mt(n)}function At(e){const t=e.required;return typeof t=="function"?t({}):t??"This field is required"}function Dt(e){return e==null||e===""?!1:typeof e=="string"?e.trim().length>0:Array.isArray(e)?e.length>0:typeof e=="object"?Object.keys(e).length>0:e===0?!0:!!e}function St(e,t={}){const{messages:n={}}=t;return Dt(e)?!0:At(n)}function vt(e,t){const n=e.startsWith;return typeof n=="function"?n({prefix:t.length===1?t[0]:t}):n??`Must start with: ${t.join(", ")}`}function Ft(e,...t){if(!e)return!0;const n=String(e);return t.some(r=>n.startsWith(r))}function Vt(e,t={}){const{args:n=[],messages:r={}}=t;return Ft(e,...n)?!0:vt(r,n)}function jt(e){const t=e.symbol;return typeof t=="function"?t({}):t??"Must contain only symbols"}function xt(e){return e?/^[^\w\s]+$/.test(String(e)):!0}function Tt(e,t={}){const{messages:n={}}=t;return xt(e)?!0:jt(n)}function Pt(e){const t=e.uppercase;return typeof t=="function"?t({}):t??"Must contain only uppercase characters"}function Ct(e){return e?/^[A-Z]+$/.test(String(e)):!0}function qt(e,t={}){const{messages:n={}}=t;return Ct(e)?!0:Pt(n)}function Et(e){const t=e.url;return typeof t=="function"?t({}):t??"Must be a valid URL"}function Bt(e){if(!e)return!0;try{const t=new URL(String(e));return["http:","https:","ftp:","ftps:"].includes(t.protocol)}catch{return!1}}function Ot(e,t={}){const{messages:n={}}=t;return Bt(e)?!0:Et(n)}const Rt=Object.freeze(Object.defineProperty({__proto__:null,accepted:U,alpha:Y,alphaSpaces:ee,alphanumeric:J,between:re,confirm:ae,containsAlpha:ce,containsAlphaSpaces:pe,containsAlphanumeric:me,containsLowercase:$e,containsNumeric:we,containsSymbol:De,containsUppercase:Fe,dateAfter:xe,dateAfterOrEqual:Ce,dateBefore:Be,dateBeforeOrEqual:Le,dateBetween:ze,dateFormat:ke,email:Ge,endsWith:Qe,is:tt,length:st,lowercase:it,matches:lt,max:dt,min:bt,not:ht,number:Nt,required:St,startsWith:Vt,symbol:Tt,uppercase:qt,url:Ot},Symbol.toStringTag,{value:"Module"})),Lt={install(e,t={}){j(Rt),t.rules&&j(t.rules);const n=o.isRef(t.locale)?t.locale:o.ref(t.locale??"en"),r={en:F};t.locales&&Object.keys(t.locales).forEach(a=>{r[a]={...r[a]??{},...t.locales[a]}});const s=o.shallowRef(r);e.provide(S,{locale:o.readonly(n),locales:o.readonly(s),setLocale:a=>{s.value[a]?n.value=a:console.warn(`Locale "${a}" not available.`)}})}},x=Symbol("form-state-context"),Wt=e=>{o.provide(x,e)},_t=(e=null)=>{const t=o.inject(x,e);if(!t&&t!==null)throw new Error("Context with formStateContextKey not found");return t},T=Symbol("form-context"),zt=e=>{o.provide(T,e)},It=(e=null)=>{const t=o.inject(T,e);if(!t&&t!==null)throw new Error("Context with formContextKey not found");return t};function Kt(e,t){if(!(!e||!t))return t.split(".").reduce((n,r)=>n==null?void 0:n[r],e)}function Ut(e,t,n){if(!e||!t)return e;const r=t.split("."),s=r.pop(),a=r.reduce((i,d,c)=>{if(i[d]===null||i[d]===void 0){const y=r[c+1]||s;i[d]=/^\d+$/.test(y)?[]:{}}return i[d]},e);return a[s]=n,e}const kt=o.defineComponent({__name:"Form",props:{modelValue:{default:()=>({})},modelModifiers:{}},emits:o.mergeModels(["submit"],["update:modelValue"]),setup(e,{emit:t}){const n=t,r=o.useModel(e,"modelValue");o.isReactive(r.value)||(r.value=o.reactive(r.value??{}));const s=o.ref({}),a=o.ref([]),i=o.computed(()=>r.value),d=o.computed(()=>a.value[0]??null),c=o.computed(()=>Object.keys(s.value).every(u=>s.value[u].isValid)),y=()=>{Object.keys(s.value).forEach(u=>{var p,g;(g=(p=s.value[u]).validate)==null||g.call(p)})},l=()=>{y(),c.value&&(a.value=[],n("submit",r.value,{setErrors:f,reset:m}))},f=(...u)=>{var p;if(u.length===1){const g=u[0];if(typeof g=="object"&&!Array.isArray(g)&&g!==null){Object.keys(g).forEach(h=>{f(h,g[h])});return}a.value=Array.isArray(g)?g:[g]}else if(u.length===2){const[g,h]=u;(p=s.value[g])==null||p.setErrors(h)}},m=()=>{a.value=[],Object.keys(s.value).forEach(u=>{s.value[u].reset()})};return Wt({getFields(){return s.value},getField(u){return s.value[u]},addField(u,p){s.value[u]=p},removeField(u){delete s.value[u]},setFieldValue(u,p){Ut(r.value,u,p)},getFieldValue(u){return Kt(r.value,u)}}),zt({values:i,isValid:c,error:d,errors:a,fields:s,reset:m,setErrors:f,validate:y}),(u,p)=>(o.openBlock(),o.createElementBlock("form",{onSubmit:o.withModifiers(l,["prevent"])},[o.renderSlot(u.$slots,"default",o.normalizeProps(o.guardReactiveProps({isValid:c.value,error:d.value,errors:a.value,values:i.value,fields:s.value,reset:m,setErrors:f,validate:y})))],32))}});function P(e){if(!e||typeof e!="string")return{};const t=e.split("|").filter(Boolean),n={};for(const r of t){const[s,...a]=r.split(":"),i=s.trim();if(a.length===0)n[i]=!0;else{const c=a.join(":").split(",").map(y=>y.trim());n[i]=c.length===1?c[0]:c}}return n}const Zt=(e,t,n={},r={})=>{if(!t)return!0;const s=P(t),a=[];for(const[i,d]of Object.entries(s)){const c=z(i);if(c){const l={args:d===!0?[]:Array.isArray(d)?d:[d],messages:n,fields:r},f=c(e,l);f!==!0&&a.push(f??"Invalid value")}else console.warn(`[Forms] Validation rule "${i}" not found.`)}return a.length===0?!0:a},Yt=(e,t)=>{const n=t(e);return n===!0?!0:typeof n=="string"?[n]:Array.isArray(n)?n:!!n?!0:["Invalid value"]};typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const C=()=>{};function Gt(e,t){function n(...r){return new Promise((s,a)=>{Promise.resolve(e(()=>t.apply(this,r),{fn:t,thisArg:this,args:r})).then(s).catch(a)})}return n}const Ht=e=>e();function Jt(e,t={}){let n,r,s=C;const a=c=>{clearTimeout(c),s(),s=C};let i;return c=>{const y=o.toValue(e),l=o.toValue(t.maxWait);return n&&a(n),y<=0||l!==void 0&&l<=0?(r&&(a(r),r=void 0),Promise.resolve(c())):new Promise((f,m)=>{s=t.rejectOnCancel?m:f,i=c,l&&!r&&(r=setTimeout(()=>{n&&a(n),r=void 0,f(i())},l)),n=setTimeout(()=>{r&&a(r),r=void 0,f(c())},y)})}}function Qt(e,t,n={}){const{eventFilter:r=Ht,...s}=n;return o.watch(e,Gt(r,t),s)}function q(e,t,n={}){const{debounce:r=0,maxWait:s=void 0,...a}=n;return Qt(e,t,{...a,eventFilter:Jt(r,{maxWait:s})})}function Xt(e,t={}){const n=o.ref(!0),r=o.ref(!1),s=o.ref([]),a=o.ref(null),i=o.computed(()=>o.toValue(t.rules)??null),d=o.computed(()=>o.toValue(t.messages)??{}),c=o.computed(()=>o.toValue(t.fields)??{}),y=o.computed(()=>{if(!i.value||typeof i.value!="string")return null;const u=P(i.value).confirm;if(!u||u===!0)return null;const p=c.value[u];return(p==null?void 0:p.value)??null}),l=()=>{let m;return typeof i.value=="function"?m=Yt(o.toValue(e),i.value):m=Zt(o.toValue(e),i.value,d.value,c.value),m===!0?(n.value=!0,s.value=[],!0):Array.isArray(m)?(n.value=!1,s.value=m,!1):m},f=()=>{a.value&&clearTimeout(a.value),r.value=!0,n.value=!0,s.value=[],a.value=setTimeout(()=>{r.value=!1,a.value=null},1e3)};return q(()=>o.toValue(e),()=>{r.value||l()},{debounce:300}),q(()=>o.toValue(y),()=>{r.value||o.toValue(e)&&l()},{debounce:300}),{validate:l,reset:f,isValid:o.readonly(n),errors:o.readonly(s)}}const E=Symbol("field-context"),en=e=>{o.provide(E,e)},tn=(e=null)=>{const t=o.inject(E,e);if(!t&&t!==null)throw new Error("Context with fieldContextKey not found");return t},nn=o.defineComponent({__name:"Field",props:o.mergeModels({id:{},name:{},validation:{type:[String,Function,null]},validationMessages:{},error:{}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const t=e,n=o.useModel(e,"modelValue"),r=o.useId(),s=_t(),a=v(),i=o.computed({get:()=>s?s.getFieldValue(t.name):n.value,set:b=>{s?s.setFieldValue(t.name,b):n.value=b}}),d=o.computed(()=>t.validation??null),c=o.computed(()=>({...a?a.locales.value[a.locale.value]:{},...t.validationMessages??{}})),y=o.computed({get:()=>s?s.getFields():{},set:()=>{}}),l=Xt(i,{rules:d,messages:c,fields:y}),f=o.ref(!1),m=o.ref(!1),u=o.ref([]),p=o.computed(()=>i.value??null),g=o.computed(()=>l.isValid.value&&u.value.length===0),h=o.computed(()=>[...l.errors.value,...u.value]),M=o.computed(()=>h.value[0]??null),B=o.toValue(i),w=t.id??r,N=`${w}-error`,A=`${w}-help`,on=b=>{u.value=Array.isArray(b)?b:[b]},D=()=>{i.value=B,f.value=!1,m.value=!1,u.value=[],l.reset()};o.watch(()=>t.error,b=>{b?u.value=Array.isArray(b)?b:[b]:u.value=[]},{immediate:!0});const O=o.computed(()=>({id:w,name:t.name,modelValue:i.value,"aria-invalid":!!M.value,"aria-describedby":M.value?`${N} ${A}`:A,"aria-errormessage":M.value?N:void 0,"onUpdate:modelValue":b=>{i.value=b,!m.value&&b!==B&&(m.value=!0)},onBlur:()=>{f.value||(f.value=!0,l.validate())}})),R={for:w},L={id:N,role:"alert","aria-live":"polite"},W={id:A};return o.onMounted(()=>{s&&s.addField(t.name,{value:p,isValid:g,isTouched:f,isDirty:m,error:M,errors:h,setErrors:on,reset:D,validate:l.validate})}),o.onUnmounted(()=>{s&&s.removeField(t.name)}),en({inputValue:i,inputProps:O,labelProps:R,helpProps:W,errorProps:L,isValid:g,isTouched:f,isDirty:m,error:M,errors:h,validate:l.validate,reset:D}),(b,an)=>(o.openBlock(),o.createElementBlock("div",null,[o.renderSlot(b.$slots,"default",o.normalizeProps(o.guardReactiveProps({inputValue:i.value,inputProps:O.value,labelProps:R,helpProps:W,errorProps:L,isValid:g.value,isTouched:f.value,isDirty:m.value,error:M.value,errors:h.value,validate:o.unref(l).validate,reset:D})))]))}});function rn(){const e=v();if(!e)throw new Error("[Valiform] useLocale() must be used inside a component with FormsPlugin installed.");return{locale:e.locale,locales:e.locales,setLocale:e.setLocale}}const sn={required:"Este campo es obligatorio",email:"Por favor ingresa un email válido",min:({value:e})=>`Debe ser al menos ${e}`,max:({value:e})=>`Debe ser como máximo ${e}`,matches:"El formato no es válido",number:"Debe ser un número válido",accepted:"Debe ser aceptado",alpha:"Debe contener solo caracteres alfabéticos",alphanumeric:"Debe contener solo letras y números",alphaSpaces:"Debe contener solo letras y espacios",between:({min:e,max:t})=>`Debe estar entre ${e} y ${t}`,confirm:({fieldName:e})=>`Debe coincidir con ${e}`,containsAlpha:"Debe contener al menos una letra",containsAlphanumeric:"Debe contener al menos una letra o número",containsAlphaSpaces:"Debe contener al menos una letra o espacio",containsLowercase:"Debe contener al menos una letra minúscula",containsNumeric:"Debe contener al menos un número",containsSymbol:"Debe contener al menos un símbolo",containsUppercase:"Debe contener al menos una letra mayúscula",dateAfter:({date:e})=>e?`Debe ser posterior a ${e}`:"Debe ser posterior a hoy",dateAfterOrEqual:({date:e})=>e?`Debe ser posterior o igual a ${e}`:"Debe ser posterior o igual a hoy",dateBefore:({date:e})=>e?`Debe ser anterior a ${e}`:"Debe ser anterior a hoy",dateBeforeOrEqual:({date:e})=>e?`Debe ser anterior o igual a ${e}`:"Debe ser anterior o igual a hoy",dateBetween:({startDate:e,endDate:t})=>`Debe estar entre ${e} y ${t}`,dateFormat:({format:e})=>`Debe coincidir con el formato ${e}`,endsWith:({suffix:e})=>Array.isArray(e)?`Debe terminar con uno de: ${e.map(t=>`"${t}"`).join(", ")}`:`Debe terminar con "${e}"`,is:({allowedValues:e})=>`Debe ser uno de: ${Array.isArray(e)?e.join(", "):e}`,length:({value:e,min:t,max:n})=>t!==void 0&&n!==void 0?`Debe tener entre ${t} y ${n} caracteres`:e!==void 0?`Debe tener exactamente ${e} caracteres`:"Longitud inválida",lowercase:"Debe contener solo caracteres en minúscula",not:({disallowedValues:e})=>`No debe ser uno de: ${Array.isArray(e)?e.join(", "):e}`,startsWith:({prefix:e})=>Array.isArray(e)?`Debe comenzar con uno de: ${e.join(", ")}`:`Debe comenzar con "${e}"`,symbol:"Debe contener solo símbolos",uppercase:"Debe contener solo caracteres en mayúscula",url:"Debe ser una URL válida"};$.Field=nn,$.Form=kt,$.FormsPlugin=Lt,$.en=F,$.es=sn,$.useFieldContext=tn,$.useFormContext=It,$.useLocale=rn,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,56 @@
1
+ type __VLS_Props = {
2
+ id?: string | null;
3
+ name: string;
4
+ validation?: string | ((value: unknown) => unknown) | null;
5
+ validationMessages?: Record<string, unknown> | null;
6
+ error?: string | string[] | null;
7
+ };
8
+ type __VLS_PublicProps = __VLS_Props & {
9
+ modelValue?: unknown;
10
+ };
11
+ declare var __VLS_1: {
12
+ inputValue: unknown;
13
+ inputProps: {
14
+ id: string;
15
+ name: string;
16
+ modelValue: unknown;
17
+ 'aria-invalid': boolean;
18
+ 'aria-describedby': string;
19
+ 'aria-errormessage': string | undefined;
20
+ 'onUpdate:modelValue': (value: unknown) => void;
21
+ onBlur: () => void;
22
+ };
23
+ labelProps: {
24
+ for: string;
25
+ };
26
+ helpProps: {
27
+ id: string;
28
+ };
29
+ errorProps: {
30
+ id: string;
31
+ role: "alert";
32
+ 'aria-live': "polite";
33
+ };
34
+ isValid: boolean;
35
+ isTouched: boolean;
36
+ isDirty: boolean;
37
+ error: string;
38
+ errors: string[];
39
+ validate: () => boolean;
40
+ reset: () => void;
41
+ };
42
+ type __VLS_Slots = {} & {
43
+ default?: (props: typeof __VLS_1) => any;
44
+ };
45
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
46
+ "update:modelValue": (value: unknown) => any;
47
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
48
+ "onUpdate:modelValue"?: (value: unknown) => any;
49
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
50
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
51
+ export default _default;
52
+ type __VLS_WithSlots<T, S> = T & {
53
+ new (): {
54
+ $slots: S;
55
+ };
56
+ };
@@ -0,0 +1,39 @@
1
+ import type { FieldState } from '../types';
2
+ declare const setErrors: (...args: unknown[]) => void;
3
+ declare const reset: () => void;
4
+ type __VLS_PublicProps = {
5
+ modelValue?: Record<string, unknown>;
6
+ };
7
+ declare var __VLS_1: {
8
+ isValid: boolean;
9
+ error: string;
10
+ errors: string[];
11
+ values: Record<string, unknown>;
12
+ fields: Record<string, FieldState>;
13
+ reset: () => void;
14
+ setErrors: (...args: unknown[]) => void;
15
+ validate: () => void;
16
+ };
17
+ type __VLS_Slots = {} & {
18
+ default?: (props: typeof __VLS_1) => any;
19
+ };
20
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
+ "update:modelValue": (value: Record<string, unknown>) => any;
22
+ submit: (values: Record<string, unknown>, helpers: {
23
+ setErrors: typeof setErrors;
24
+ reset: typeof reset;
25
+ }) => any;
26
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
27
+ "onUpdate:modelValue"?: (value: Record<string, unknown>) => any;
28
+ onSubmit?: (values: Record<string, unknown>, helpers: {
29
+ setErrors: typeof setErrors;
30
+ reset: typeof reset;
31
+ }) => any;
32
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
33
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
34
+ export default _default;
35
+ type __VLS_WithSlots<T, S> = T & {
36
+ new (): {
37
+ $slots: S;
38
+ };
39
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ type __VLS_PublicProps = {
2
+ modelValue?: unknown;
3
+ };
4
+ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
5
+ "update:modelValue": (value: unknown) => any;
6
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
7
+ "onUpdate:modelValue"?: (value: unknown) => any;
8
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ export default _default;
@@ -0,0 +1,19 @@
1
+ type __VLS_PublicProps = {
2
+ modelValue?: unknown;
3
+ };
4
+ declare var __VLS_1: {};
5
+ type __VLS_Slots = {} & {
6
+ default?: (props: typeof __VLS_1) => any;
7
+ };
8
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
9
+ "update:modelValue": (value: unknown) => any;
10
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
11
+ "onUpdate:modelValue"?: (value: unknown) => any;
12
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
13
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
14
+ export default _default;
15
+ type __VLS_WithSlots<T, S> = T & {
16
+ new (): {
17
+ $slots: S;
18
+ };
19
+ };
@@ -0,0 +1,53 @@
1
+ type __VLS_Props = {
2
+ name?: string;
3
+ initialValue?: string;
4
+ validation?: string | ((value: unknown) => unknown) | null;
5
+ validationMessages?: Record<string, unknown> | null;
6
+ };
7
+ declare var __VLS_8: {
8
+ inputValue: unknown;
9
+ inputProps: {
10
+ id: string;
11
+ name: string;
12
+ modelValue: unknown;
13
+ 'aria-invalid': boolean;
14
+ 'aria-describedby': string;
15
+ 'aria-errormessage': string | undefined;
16
+ 'onUpdate:modelValue': (value: unknown) => void;
17
+ onBlur: () => void;
18
+ };
19
+ labelProps: {
20
+ for: string;
21
+ };
22
+ helpProps: {
23
+ id: string;
24
+ };
25
+ errorProps: {
26
+ id: string;
27
+ role: "alert";
28
+ 'aria-live': "polite";
29
+ };
30
+ isValid: boolean;
31
+ isTouched: boolean;
32
+ isDirty: boolean;
33
+ error: string;
34
+ errors: string[];
35
+ validate: () => boolean;
36
+ reset: () => void;
37
+ };
38
+ type __VLS_Slots = {} & {
39
+ default?: (props: typeof __VLS_8) => any;
40
+ };
41
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
42
+ name: string;
43
+ validation: string | ((value: unknown) => unknown) | null;
44
+ validationMessages: Record<string, unknown> | null;
45
+ initialValue: string;
46
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
47
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
48
+ export default _default;
49
+ type __VLS_WithSlots<T, S> = T & {
50
+ new (): {
51
+ $slots: S;
52
+ };
53
+ };
@@ -0,0 +1,40 @@
1
+ interface FormValues {
2
+ name: string;
3
+ email: string;
4
+ password: string;
5
+ confirmPassword: string;
6
+ }
7
+ type __VLS_Props = {
8
+ handleSubmit?: (values: Record<string, unknown>, helpers: {
9
+ setErrors: (...args: unknown[]) => void;
10
+ reset: () => void;
11
+ }) => void;
12
+ initialValues?: FormValues;
13
+ };
14
+ declare var __VLS_32: {
15
+ isValid: boolean;
16
+ error: string;
17
+ errors: string[];
18
+ values: Record<string, unknown>;
19
+ fields: Record<string, import("../../../types.js").FieldState>;
20
+ reset: () => void;
21
+ setErrors: (...args: unknown[]) => void;
22
+ validate: () => void;
23
+ };
24
+ type __VLS_Slots = {} & {
25
+ default?: (props: typeof __VLS_32) => any;
26
+ };
27
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
28
+ handleSubmit: (values: Record<string, unknown>, helpers: {
29
+ setErrors: (...args: unknown[]) => void;
30
+ reset: () => void;
31
+ }) => void;
32
+ initialValues: FormValues;
33
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
35
+ export default _default;
36
+ type __VLS_WithSlots<T, S> = T & {
37
+ new (): {
38
+ $slots: S;
39
+ };
40
+ };
@@ -0,0 +1,51 @@
1
+ interface Skill {
2
+ name: string;
3
+ level: string;
4
+ }
5
+ interface FormValues {
6
+ user: {
7
+ firstName: string;
8
+ lastName: string;
9
+ email: string;
10
+ };
11
+ address: {
12
+ street: string;
13
+ city: string;
14
+ postalCode: string;
15
+ };
16
+ skills: Skill[];
17
+ }
18
+ type __VLS_Props = {
19
+ handleSubmit?: (values: Record<string, unknown>, helpers: {
20
+ setErrors: (...args: unknown[]) => void;
21
+ reset: () => void;
22
+ }) => void;
23
+ initialValues?: FormValues;
24
+ };
25
+ declare var __VLS_52: {
26
+ isValid: boolean;
27
+ error: string;
28
+ errors: string[];
29
+ values: Record<string, unknown>;
30
+ fields: Record<string, import("../../../types.js").FieldState>;
31
+ reset: () => void;
32
+ setErrors: (...args: unknown[]) => void;
33
+ validate: () => void;
34
+ };
35
+ type __VLS_Slots = {} & {
36
+ default?: (props: typeof __VLS_52) => any;
37
+ };
38
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
39
+ handleSubmit: (values: Record<string, unknown>, helpers: {
40
+ setErrors: (...args: unknown[]) => void;
41
+ reset: () => void;
42
+ }) => void;
43
+ initialValues: FormValues;
44
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
45
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
46
+ export default _default;
47
+ type __VLS_WithSlots<T, S> = T & {
48
+ new (): {
49
+ $slots: S;
50
+ };
51
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { LocaleContextData } from '../types';
2
+ export declare function useLocale(): LocaleContextData;
@@ -0,0 +1,14 @@
1
+ import type { MaybeRefOrGetter, Ref } from 'vue';
2
+ import type { FieldState, LocaleMessages } from '../types';
3
+ type UseValidationOptions = {
4
+ rules?: MaybeRefOrGetter<string | ((value: unknown) => unknown) | null>;
5
+ messages?: MaybeRefOrGetter<LocaleMessages>;
6
+ fields?: MaybeRefOrGetter<Record<string, FieldState>>;
7
+ };
8
+ export declare function useValidation(valueRef: MaybeRefOrGetter<unknown>, options?: UseValidationOptions): {
9
+ validate: () => boolean;
10
+ reset: () => void;
11
+ isValid: Readonly<Ref<boolean, boolean>>;
12
+ errors: Readonly<Ref<readonly string[], readonly string[]>>;
13
+ };
14
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { FieldContext } from '../types';
3
+ export declare const fieldContextKey: InjectionKey<FieldContext>;
4
+ export declare const useFieldContextProvider: (data: FieldContext) => void;
5
+ export declare const useFieldContext: (defaultData?: FieldContext | null) => FieldContext | null;
@@ -0,0 +1,5 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { FormContext } from '../types';
3
+ export declare const formContextKey: InjectionKey<FormContext>;
4
+ export declare const useFormContextProvider: (data: FormContext) => void;
5
+ export declare const useFormContext: (defaultData?: FormContext | null) => FormContext | null;
@@ -0,0 +1,5 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { FormStateContext } from '../types';
3
+ export declare const formStateContextKey: InjectionKey<FormStateContext>;
4
+ export declare const useFormStateContextProvider: (data: FormStateContext) => void;
5
+ export declare const useFormStateContext: (defaultData?: FormStateContext | null) => FormStateContext | null;
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { LocaleContextData } from '../types';
3
+ export declare const localeContextKey: InjectionKey<LocaleContextData>;
4
+ export declare const useLocaleContext: (defaultData?: LocaleContextData | null) => LocaleContextData | null;
@@ -0,0 +1,2 @@
1
+ import type { LocaleMessages } from '../types';
2
+ export declare const en: LocaleMessages;
@@ -0,0 +1,2 @@
1
+ import type { LocaleMessages } from '../types';
2
+ export declare const es: LocaleMessages;
@@ -0,0 +1,5 @@
1
+ import type { App } from 'vue';
2
+ import type { FormsPluginOptions } from '../types';
3
+ export declare const FormsPlugin: {
4
+ install(app: App, options?: FormsPluginOptions): void;
5
+ };
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
@@ -0,0 +1,84 @@
1
+ import type { ComputedRef, Ref, ShallowRef, WritableComputedRef } from 'vue';
2
+ export type RuleValue = true | string | string[];
3
+ export type ParsedRules = Record<string, RuleValue>;
4
+ export type LocaleMessageFn = (args: Record<string, unknown>) => string;
5
+ export type LocaleMessage = string | LocaleMessageFn;
6
+ export type LocaleMessages = Partial<Record<string, LocaleMessage>>;
7
+ export type RuleOptions = {
8
+ args: string[];
9
+ messages: LocaleMessages;
10
+ fields: Record<string, FieldState>;
11
+ };
12
+ export type RuleFunction = (value: unknown, options: RuleOptions) => true | string | undefined;
13
+ export type ValidationResult = true | string[];
14
+ export interface FieldState {
15
+ value: ComputedRef<unknown>;
16
+ isValid: ComputedRef<boolean>;
17
+ isTouched: Ref<boolean>;
18
+ isDirty: Ref<boolean>;
19
+ error: ComputedRef<string | null>;
20
+ errors: ComputedRef<string[]>;
21
+ setErrors: (input: string | string[]) => void;
22
+ reset: () => void;
23
+ validate: () => boolean | void;
24
+ }
25
+ export type InputProps = {
26
+ id: string;
27
+ name: string;
28
+ modelValue: unknown;
29
+ 'aria-invalid': boolean;
30
+ 'aria-describedby': string;
31
+ 'aria-errormessage': string | undefined;
32
+ 'onUpdate:modelValue': (value: unknown) => void;
33
+ onBlur: () => void;
34
+ };
35
+ export interface FieldContext {
36
+ inputValue: WritableComputedRef<unknown>;
37
+ inputProps: ComputedRef<InputProps>;
38
+ labelProps: {
39
+ for: string;
40
+ };
41
+ helpProps: {
42
+ id: string;
43
+ };
44
+ errorProps: {
45
+ id: string;
46
+ role: string;
47
+ 'aria-live': string;
48
+ };
49
+ isValid: ComputedRef<boolean>;
50
+ isTouched: Ref<boolean>;
51
+ isDirty: Ref<boolean>;
52
+ error: ComputedRef<string | null>;
53
+ errors: ComputedRef<string[]>;
54
+ validate: () => boolean | void;
55
+ reset: () => void;
56
+ }
57
+ export interface FormStateContext {
58
+ getFields: () => Record<string, FieldState>;
59
+ getField: (name: string) => FieldState | undefined;
60
+ addField: (name: string, field: FieldState) => void;
61
+ removeField: (name: string) => void;
62
+ setFieldValue: (name: string, value: unknown) => void;
63
+ getFieldValue: (name: string) => unknown;
64
+ }
65
+ export interface FormContext {
66
+ values: ComputedRef<Record<string, unknown>>;
67
+ isValid: ComputedRef<boolean>;
68
+ error: ComputedRef<string | null>;
69
+ errors: Ref<string[]>;
70
+ fields: Ref<Record<string, FieldState>>;
71
+ reset: () => void;
72
+ setErrors: (...args: unknown[]) => void;
73
+ validate: () => void;
74
+ }
75
+ export interface LocaleContextData {
76
+ locale: Readonly<Ref<string>>;
77
+ locales: Readonly<ShallowRef<Record<string, LocaleMessages>>>;
78
+ setLocale: (locale: string) => void;
79
+ }
80
+ export type FormsPluginOptions = {
81
+ locale?: string | Ref<string>;
82
+ locales?: Record<string, LocaleMessages>;
83
+ rules?: Record<string, RuleFunction>;
84
+ };
@@ -0,0 +1,2 @@
1
+ import type { ParsedRules } from '../types';
2
+ export declare function parseRules(ruleString: string): ParsedRules;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function getValueByPath(obj: Record<string, unknown>, path: string): unknown;
2
+ export declare function setValueByPath(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>;
@@ -0,0 +1,3 @@
1
+ import type { FieldState, LocaleMessages, ValidationResult } from '../types';
2
+ export declare const validateStringRules: (value: unknown, rules: string | null, messages?: LocaleMessages, fields?: Record<string, FieldState>) => ValidationResult;
3
+ export declare const validateFunction: (value: unknown, fn: (value: unknown) => unknown) => ValidationResult;
@@ -0,0 +1,5 @@
1
+ import type { RuleFunction } from '../types';
2
+ export declare const registerRule: (name: string, handler: RuleFunction) => void;
3
+ export declare const registerRules: (rulesObject: Record<string, RuleFunction>) => void;
4
+ export declare const getRule: (name: string) => RuleFunction | undefined;
5
+ export declare const getRules: () => Map<string, RuleFunction>;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function accepted(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function alpha(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function alphaSpaces(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function alphanumeric(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function between(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function confirm(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsAlpha(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsAlphaSpaces(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsAlphanumeric(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsLowercase(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsNumeric(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsSymbol(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function containsUppercase(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateAfter(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateAfterOrEqual(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateBefore(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateBeforeOrEqual(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateBetween(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function dateFormat(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function email(value: unknown, options?: Partial<RuleOptions>): true | string;
@@ -0,0 +1,2 @@
1
+ import type { RuleOptions } from '../../types';
2
+ export declare function endsWith(value: unknown, options?: Partial<RuleOptions>): true | string;