@overgaming/valiform 0.4.2 → 0.4.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 +15 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +37 -33
- package/dist/nuxt/module.d.ts +9 -3
- package/dist/nuxt.cjs +2 -5
- package/dist/nuxt.js +12 -19
- package/dist/runtime/plugin.cjs +1 -1
- package/dist/runtime/plugin.js +8 -6
- package/dist/src/defineValiformConfig.d.ts +22 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/types.d.ts +4 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -32,11 +32,25 @@ export default defineNuxtConfig({
|
|
|
32
32
|
modules: ['@overgaming/valiform/nuxt'],
|
|
33
33
|
valiform: {
|
|
34
34
|
locale: 'es',
|
|
35
|
-
|
|
35
|
+
config: './valiform.config'
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
```ts
|
|
41
|
+
// valiform.config.ts
|
|
42
|
+
import { defineValiformConfig, es, en } from '@overgaming/valiform';
|
|
43
|
+
|
|
44
|
+
export default defineValiformConfig({
|
|
45
|
+
locales: { es, en },
|
|
46
|
+
rules: {
|
|
47
|
+
// custom rules with full import/closure support
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The `config` option points to a file that Nuxt bundles at build time — imports, closures and external variables all work normally. Only serializable options like `locale` go in `nuxt.config.ts`.
|
|
53
|
+
|
|
40
54
|
The Nuxt module auto-imports `<Form>`, `<Field>`, `useLocale`, `useFormContext`, `useFieldContext` and `useInputContext`.
|
|
41
55
|
|
|
42
56
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),T=Symbol("locale-context"),q=(e=null)=>{const t=o.inject(T,e);if(!t&&t!==null)throw new Error("Context with localeContextKey not found");return t},E={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"},R=o.shallowRef(new Map),B=(e,t)=>{R.value.set(e,t)},D=e=>{Object.entries(e).forEach(([t,n])=>{B(t,n)})},_=e=>R.value.get(e);function z(e){const t=e.accepted;return typeof t=="function"?t({}):t??"Must be accepted"}function U(e){return e?["yes","on","1","true"].includes(String(e).toLowerCase()):!1}function k(e,t={}){const{messages:n={}}=t;return U(e)?!0:z(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 ue(e){const t=e.containsAlpha;return typeof t=="function"?t({}):t??"Must contain at least one letter"}function ie(e){return e?/[a-zA-Z]/.test(String(e)):!0}function ce(e,t={}){const{messages:n={}}=t;return ie(e)?!0:ue(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 ve(e){return e?/\d/.test(String(e)):!0}function Me(e,t={}){const{messages:n={}}=t;return ve(e)?!0:he(n)}function Ne(e){const t=e.containsSymbol;return typeof t=="function"?t({}):t??"Must contain at least one symbol"}function we(e){return e?/[^\w\s]/.test(String(e)):!0}function Ae(e,t={}){const{messages:n={}}=t;return we(e)?!0:Ne(n)}function De(e){const t=e.containsUppercase;return typeof t=="function"?t({}):t??"Must contain at least one uppercase letter"}function Se(e){return e?/[A-Z]/.test(String(e)):!0}function Fe(e,t={}){const{messages:n={}}=t;return Se(e)?!0:De(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 xe(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 je(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return xe(e,s)?!0:Ve(r,s)}function Pe(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 Ce(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 Te(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ce(e,s)?!0:Pe(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 Re(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ee(e,s)?!0:qe(r,s)}function Be(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 Oe(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 Ie(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Oe(e,s)?!0:Be(r,s)}function Le(e,t,n){const r=e.dateBetween;return typeof r=="function"?r({startDate:t,endDate:n}):r??`Must be between ${t} and ${n}`}function We(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 _e(e,t={}){const{args:n=[],messages:r={}}=t,[s,a]=n;return We(e,s,a)?!0:Le(r,s,a)}const ze=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 Ue(e,t){const n=e.dateFormat;return typeof n=="function"?n({format:t}):n??`Must match the format ${t}`}function ke(e,t){return e?t&&typeof t=="string"?ze(t).test(String(e)):!isNaN(Date.parse(String(e))):!0}function Ke(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return ke(e,s)?!0:Ue(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),u=Number(n);return!isNaN(a)&&!isNaN(u)&&r>=a&&r<=u}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 ut(e,t={}){const{messages:n={}}=t;return at(e)?!0:ot(n)}function it(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:it(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 vt(e){const t=e.number;return typeof t=="function"?t({}):t??"Must be a valid number"}function Mt(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 Mt(e)?!0:vt(n)}function wt(e){const t=e.required;return typeof t=="function"?t({}):t??"This field is required"}function At(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 Dt(e,t={}){const{messages:n={}}=t;return At(e)?!0:wt(n)}function St(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:St(r,n)}function xt(e){const t=e.symbol;return typeof t=="function"?t({}):t??"Must contain only symbols"}function jt(e){return e?/^[^\w\s]+$/.test(String(e)):!0}function Pt(e,t={}){const{messages:n={}}=t;return jt(e)?!0:xt(n)}function Ct(e){const t=e.uppercase;return typeof t=="function"?t({}):t??"Must contain only uppercase characters"}function Tt(e){return e?/^[A-Z]+$/.test(String(e)):!0}function qt(e,t={}){const{messages:n={}}=t;return Tt(e)?!0:Ct(n)}function Et(e){const t=e.url;return typeof t=="function"?t({}):t??"Must be a valid URL"}function Rt(e){if(!e)return!0;try{const t=new URL(String(e));return["http:","https:","ftp:","ftps:"].includes(t.protocol)}catch{return!1}}function Bt(e,t={}){const{messages:n={}}=t;return Rt(e)?!0:Et(n)}const Ot=Object.freeze(Object.defineProperty({__proto__:null,accepted:k,alpha:Y,alphaSpaces:ee,alphanumeric:J,between:re,confirm:ae,containsAlpha:ce,containsAlphaSpaces:pe,containsAlphanumeric:me,containsLowercase:$e,containsNumeric:Me,containsSymbol:Ae,containsUppercase:Fe,dateAfter:je,dateAfterOrEqual:Te,dateBefore:Re,dateBeforeOrEqual:Ie,dateBetween:_e,dateFormat:Ke,email:Ge,endsWith:Qe,is:tt,length:st,lowercase:ut,matches:lt,max:dt,min:bt,not:ht,number:Nt,required:Dt,startsWith:Vt,symbol:Pt,uppercase:qt,url:Bt},Symbol.toStringTag,{value:"Module"})),It={install(e,t={}){D(Ot),t.rules&&D(t.rules);const n=o.isRef(t.locale)?t.locale:o.ref(t.locale??"en"),r={en:E};t.locales&&Object.keys(t.locales).forEach(a=>{r[a]={...r[a]??{},...t.locales[a]}});const s=o.shallowRef(r);e.provide(T,{locale:o.readonly(n),locales:o.readonly(s),setLocale:a=>{s.value[a]?n.value=a:console.warn(`Locale "${a}" not available.`)}})}},O=Symbol("form-state-context"),Lt=e=>{o.provide(O,e)},Wt=(e=null)=>{const t=o.inject(O,e);if(!t&&t!==null)throw new Error("Context with formStateContextKey not found");return t},I=Symbol("form-context"),_t=e=>{o.provide(I,e)},zt=(e=null)=>{const t=o.inject(I,e);if(!t&&t!==null)throw new Error("Context with formContextKey not found");return t};function Ut(e,t){if(!(!e||!t))return t.split(".").reduce((n,r)=>n==null?void 0:n[r],e)}function kt(e,t,n){if(!e||!t)return e;const r=t.split("."),s=r.pop(),a=r.reduce((u,l,c)=>{if(u[l]===null||u[l]===void 0){const g=r[c+1]||s;u[l]=/^\d+$/.test(g)?[]:{}}return u[l]},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([]),u=o.computed(()=>r.value),l=o.computed(()=>a.value[0]??null),c=o.computed(()=>Object.keys(s.value).every(i=>s.value[i].isValid)),g=()=>{Object.keys(s.value).forEach(i=>{var b,p;(p=(b=s.value[i]).validate)==null||p.call(b)})},f=()=>{g(),c.value&&(a.value=[],n("submit",r.value,{setErrors:m,reset:d}))},m=(...i)=>{var b;if(i.length===1){const p=i[0];if(typeof p=="object"&&!Array.isArray(p)&&p!==null){Object.keys(p).forEach($=>{m($,p[$])});return}a.value=Array.isArray(p)?p:[p]}else if(i.length===2){const[p,$]=i;(b=s.value[p])==null||b.setErrors($)}},d=()=>{a.value=[],Object.keys(s.value).forEach(i=>{s.value[i].reset()})};return Lt({getFields(){return s.value},getField(i){return s.value[i]},addField(i,b){s.value[i]=b},removeField(i){delete s.value[i]},setFieldValue(i,b){kt(r.value,i,b)},getFieldValue(i){return Ut(r.value,i)}}),_t({values:u,isValid:c,error:l,errors:a,fields:s,reset:d,setErrors:m,validate:g}),(i,b)=>(o.openBlock(),o.createElementBlock("form",{onSubmit:o.withModifiers(f,["prevent"])},[o.renderSlot(i.$slots,"default",o.normalizeProps(o.guardReactiveProps({isValid:c.value,error:l.value,errors:a.value,values:u.value,fields:s.value,reset:d,setErrors:m,validate:g})))],32))}});function L(e){if(!e||typeof e!="string")return{};const t=e.split("|").filter(Boolean),n={};for(const r of t){const[s,...a]=r.split(":"),u=s.trim();if(a.length===0)n[u]=!0;else{const c=a.join(":").split(",").map(g=>g.trim());n[u]=c.length===1?c[0]:c}}return n}const Zt=(e,t,n={},r={})=>{if(!t)return!0;const s=L(t),a=[];for(const[u,l]of Object.entries(s)){const c=_(u);if(c){const f={args:l===!0?[]:Array.isArray(l)?l:[l],messages:n,fields:r},m=c(e,f);m!==!0&&a.push(m??"Invalid value")}else console.warn(`[Forms] Validation rule "${u}" 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 P=()=>{};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=P;const a=c=>{clearTimeout(c),s(),s=P};let u;return c=>{const g=o.toValue(e),f=o.toValue(t.maxWait);return n&&a(n),g<=0||f!==void 0&&f<=0?(r&&(a(r),r=void 0),Promise.resolve(c())):new Promise((m,d)=>{s=t.rejectOnCancel?d:m,u=c,f&&!r&&(r=setTimeout(()=>{n&&a(n),r=void 0,m(u())},f)),n=setTimeout(()=>{r&&a(r),r=void 0,m(c())},g)})}}function Qt(e,t,n={}){const{eventFilter:r=Ht,...s}=n;return o.watch(e,Gt(r,t),s)}function C(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),u=o.computed(()=>o.toValue(t.rules)??null),l=o.computed(()=>o.toValue(t.messages)??{}),c=o.computed(()=>o.toValue(t.fields)??{}),g=o.computed(()=>{if(!u.value||typeof u.value!="string")return null;const i=L(u.value).confirm;if(!i||i===!0)return null;const b=c.value[i];return(b==null?void 0:b.value)??null}),f=()=>{let d;return typeof u.value=="function"?d=Yt(o.toValue(e),u.value):d=Zt(o.toValue(e),u.value,l.value,c.value),d===!0?(n.value=!0,s.value=[],!0):Array.isArray(d)?(n.value=!1,s.value=d,!1):d},m=()=>{a.value&&clearTimeout(a.value),r.value=!0,n.value=!0,s.value=[],a.value=setTimeout(()=>{r.value=!1,a.value=null},1e3)};return C(()=>o.toValue(e),()=>{r.value||f()},{debounce:300}),C(()=>o.toValue(g),()=>{r.value||o.toValue(e)&&f()},{debounce:300}),{validate:f,reset:m,isValid:o.readonly(n),errors:o.readonly(s)}}const M=Symbol("field-context"),en=e=>{o.provide(M,e)};function tn(e){if(e===void 0){const t=o.inject(M);if(!t)throw new Error("useFieldContext() must be called inside a Field component");return t}return o.inject(M,e)}const 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=Wt(),a=q(),u=o.computed({get:()=>s?s.getFieldValue(t.name):n.value,set:y=>{s?s.setFieldValue(t.name,y):n.value=y}}),l=o.computed(()=>t.validation??null),c=o.computed(()=>({...a?a.locales.value[a.locale.value]:{},...t.validationMessages??{}})),g=o.computed({get:()=>s?s.getFields():{},set:()=>{}}),f=Xt(u,{rules:l,messages:c,fields:g}),m=o.ref(!1),d=o.ref(!1),i=o.ref([]),b=o.computed(()=>u.value??null),p=o.computed(()=>f.isValid.value&&i.value.length===0),$=o.computed(()=>[...f.errors.value,...i.value]),h=o.computed(()=>$.value[0]??null),S=o.toValue(u),v=t.id??r,N=`${v}-error`,w=`${v}-help`,W=y=>{i.value=Array.isArray(y)?y:[y]},A=()=>{u.value=S,m.value=!1,d.value=!1,i.value=[],f.reset()};o.watch(()=>t.error,y=>{y?i.value=Array.isArray(y)?y:[y]:i.value=[]},{immediate:!0});const F=o.computed(()=>({id:v,name:t.name,modelValue:u.value,"aria-invalid":!!h.value,"aria-describedby":h.value?`${N} ${w}`:w,"aria-errormessage":h.value?N:void 0,"onUpdate:modelValue":y=>{u.value=y,!d.value&&y!==S&&(d.value=!0)},onBlur:()=>{m.value||(m.value=!0,f.validate())}})),V={for:v},x={id:N,role:"alert","aria-live":"polite"},j={id:w};return o.onMounted(()=>{s&&s.addField(t.name,{value:b,isValid:p,isTouched:m,isDirty:d,error:h,errors:$,setErrors:W,reset:A,validate:f.validate})}),o.onUnmounted(()=>{s&&s.removeField(t.name)}),en({inputValue:u,inputProps:F,labelProps:V,helpProps:j,errorProps:x,isValid:p,isTouched:m,isDirty:d,error:h,errors:$,validate:f.validate,reset:A}),(y,an)=>(o.openBlock(),o.createElementBlock("div",null,[o.renderSlot(y.$slots,"default",o.normalizeProps(o.guardReactiveProps({inputValue:u.value,inputProps:F.value,labelProps:V,helpProps:j,errorProps:x,isValid:p.value,isTouched:m.value,isDirty:d.value,error:h.value,errors:$.value,validate:o.unref(f).validate,reset:A})))]))}});function rn(){const e=q();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}}function sn(e){const t=o.inject(M,null);if(t)return t;const n=o.toValue(e),r=o.useId(),s=`${r}-error`,a=`${r}-help`,u=o.ref(!1),l=o.ref(!1),c=o.computed(()=>({id:r,name:r,modelValue:e.value,"aria-invalid":!1,"aria-describedby":a,"aria-errormessage":void 0,"onUpdate:modelValue":g=>{e.value=g,!l.value&&g!==n&&(l.value=!0)},onBlur:()=>{u.value||(u.value=!0)}}));return{inputValue:e,inputProps:c,labelProps:{for:r},helpProps:{id:a},errorProps:{id:s,role:"alert","aria-live":"polite"},isValid:o.computed(()=>!0),isTouched:u,isDirty:l,error:o.computed(()=>null),errors:o.computed(()=>[]),validate:()=>!0,reset:()=>{e.value=n,u.value=!1,l.value=!1}}}const on={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"};exports.Field=nn;exports.Form=Kt;exports.FormsPlugin=It;exports.en=E;exports.es=on;exports.registerRule=B;exports.registerRules=D;exports.useFieldContext=tn;exports.useFormContext=zt;exports.useInputContext=sn;exports.useLocale=rn;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),T=Symbol("locale-context"),q=(e=null)=>{const t=o.inject(T,e);if(!t&&t!==null)throw new Error("Context with localeContextKey not found");return t},E={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"},R=o.shallowRef(new Map),B=(e,t)=>{R.value.set(e,t)},D=e=>{Object.entries(e).forEach(([t,n])=>{B(t,n)})},_=e=>R.value.get(e);function z(e){const t=e.accepted;return typeof t=="function"?t({}):t??"Must be accepted"}function U(e){return e?["yes","on","1","true"].includes(String(e).toLowerCase()):!1}function k(e,t={}){const{messages:n={}}=t;return U(e)?!0:z(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 ue(e){const t=e.containsAlpha;return typeof t=="function"?t({}):t??"Must contain at least one letter"}function ie(e){return e?/[a-zA-Z]/.test(String(e)):!0}function ce(e,t={}){const{messages:n={}}=t;return ie(e)?!0:ue(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 ve(e){return e?/\d/.test(String(e)):!0}function Me(e,t={}){const{messages:n={}}=t;return ve(e)?!0:he(n)}function Ne(e){const t=e.containsSymbol;return typeof t=="function"?t({}):t??"Must contain at least one symbol"}function we(e){return e?/[^\w\s]/.test(String(e)):!0}function Ae(e,t={}){const{messages:n={}}=t;return we(e)?!0:Ne(n)}function De(e){const t=e.containsUppercase;return typeof t=="function"?t({}):t??"Must contain at least one uppercase letter"}function Se(e){return e?/[A-Z]/.test(String(e)):!0}function Fe(e,t={}){const{messages:n={}}=t;return Se(e)?!0:De(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 xe(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 je(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return xe(e,s)?!0:Ve(r,s)}function Pe(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 Ce(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 Te(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ce(e,s)?!0:Pe(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 Re(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Ee(e,s)?!0:qe(r,s)}function Be(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 Oe(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 Ie(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return Oe(e,s)?!0:Be(r,s)}function Le(e,t,n){const r=e.dateBetween;return typeof r=="function"?r({startDate:t,endDate:n}):r??`Must be between ${t} and ${n}`}function We(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 _e(e,t={}){const{args:n=[],messages:r={}}=t,[s,a]=n;return We(e,s,a)?!0:Le(r,s,a)}const ze=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 Ue(e,t){const n=e.dateFormat;return typeof n=="function"?n({format:t}):n??`Must match the format ${t}`}function ke(e,t){return e?t&&typeof t=="string"?ze(t).test(String(e)):!isNaN(Date.parse(String(e))):!0}function Ke(e,t={}){const{args:n=[],messages:r={}}=t,[s]=n;return ke(e,s)?!0:Ue(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),u=Number(n);return!isNaN(a)&&!isNaN(u)&&r>=a&&r<=u}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 ut(e,t={}){const{messages:n={}}=t;return at(e)?!0:ot(n)}function it(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:it(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 vt(e){const t=e.number;return typeof t=="function"?t({}):t??"Must be a valid number"}function Mt(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 Mt(e)?!0:vt(n)}function wt(e){const t=e.required;return typeof t=="function"?t({}):t??"This field is required"}function At(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 Dt(e,t={}){const{messages:n={}}=t;return At(e)?!0:wt(n)}function St(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:St(r,n)}function xt(e){const t=e.symbol;return typeof t=="function"?t({}):t??"Must contain only symbols"}function jt(e){return e?/^[^\w\s]+$/.test(String(e)):!0}function Pt(e,t={}){const{messages:n={}}=t;return jt(e)?!0:xt(n)}function Ct(e){const t=e.uppercase;return typeof t=="function"?t({}):t??"Must contain only uppercase characters"}function Tt(e){return e?/^[A-Z]+$/.test(String(e)):!0}function qt(e,t={}){const{messages:n={}}=t;return Tt(e)?!0:Ct(n)}function Et(e){const t=e.url;return typeof t=="function"?t({}):t??"Must be a valid URL"}function Rt(e){if(!e)return!0;try{const t=new URL(String(e));return["http:","https:","ftp:","ftps:"].includes(t.protocol)}catch{return!1}}function Bt(e,t={}){const{messages:n={}}=t;return Rt(e)?!0:Et(n)}const Ot=Object.freeze(Object.defineProperty({__proto__:null,accepted:k,alpha:Y,alphaSpaces:ee,alphanumeric:J,between:re,confirm:ae,containsAlpha:ce,containsAlphaSpaces:pe,containsAlphanumeric:me,containsLowercase:$e,containsNumeric:Me,containsSymbol:Ae,containsUppercase:Fe,dateAfter:je,dateAfterOrEqual:Te,dateBefore:Re,dateBeforeOrEqual:Ie,dateBetween:_e,dateFormat:Ke,email:Ge,endsWith:Qe,is:tt,length:st,lowercase:ut,matches:lt,max:dt,min:bt,not:ht,number:Nt,required:Dt,startsWith:Vt,symbol:Pt,uppercase:qt,url:Bt},Symbol.toStringTag,{value:"Module"})),It={install(e,t={}){D(Ot),t.rules&&D(t.rules);const n=o.isRef(t.locale)?t.locale:o.ref(t.locale??"en"),r={en:E};t.locales&&Object.keys(t.locales).forEach(a=>{r[a]={...r[a]??{},...t.locales[a]}});const s=o.shallowRef(r);e.provide(T,{locale:o.readonly(n),locales:o.readonly(s),setLocale:a=>{s.value[a]?n.value=a:console.warn(`Locale "${a}" not available.`)}})}},O=Symbol("form-state-context"),Lt=e=>{o.provide(O,e)},Wt=(e=null)=>{const t=o.inject(O,e);if(!t&&t!==null)throw new Error("Context with formStateContextKey not found");return t},I=Symbol("form-context"),_t=e=>{o.provide(I,e)},zt=(e=null)=>{const t=o.inject(I,e);if(!t&&t!==null)throw new Error("Context with formContextKey not found");return t};function Ut(e,t){if(!(!e||!t))return t.split(".").reduce((n,r)=>n==null?void 0:n[r],e)}function kt(e,t,n){if(!e||!t)return e;const r=t.split("."),s=r.pop(),a=r.reduce((u,l,c)=>{if(u[l]===null||u[l]===void 0){const g=r[c+1]||s;u[l]=/^\d+$/.test(g)?[]:{}}return u[l]},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([]),u=o.computed(()=>r.value),l=o.computed(()=>a.value[0]??null),c=o.computed(()=>Object.keys(s.value).every(i=>s.value[i].isValid)),g=()=>{Object.keys(s.value).forEach(i=>{var b,p;(p=(b=s.value[i]).validate)==null||p.call(b)})},f=()=>{g(),c.value&&(a.value=[],n("submit",r.value,{setErrors:m,reset:d}))},m=(...i)=>{var b;if(i.length===1){const p=i[0];if(typeof p=="object"&&!Array.isArray(p)&&p!==null){Object.keys(p).forEach($=>{m($,p[$])});return}a.value=Array.isArray(p)?p:[p]}else if(i.length===2){const[p,$]=i;(b=s.value[p])==null||b.setErrors($)}},d=()=>{a.value=[],Object.keys(s.value).forEach(i=>{s.value[i].reset()})};return Lt({getFields(){return s.value},getField(i){return s.value[i]},addField(i,b){s.value[i]=b},removeField(i){delete s.value[i]},setFieldValue(i,b){kt(r.value,i,b)},getFieldValue(i){return Ut(r.value,i)}}),_t({values:u,isValid:c,error:l,errors:a,fields:s,reset:d,setErrors:m,validate:g}),(i,b)=>(o.openBlock(),o.createElementBlock("form",{onSubmit:o.withModifiers(f,["prevent"])},[o.renderSlot(i.$slots,"default",o.normalizeProps(o.guardReactiveProps({isValid:c.value,error:l.value,errors:a.value,values:u.value,fields:s.value,reset:d,setErrors:m,validate:g})))],32))}});function L(e){if(!e||typeof e!="string")return{};const t=e.split("|").filter(Boolean),n={};for(const r of t){const[s,...a]=r.split(":"),u=s.trim();if(a.length===0)n[u]=!0;else{const c=a.join(":").split(",").map(g=>g.trim());n[u]=c.length===1?c[0]:c}}return n}const Zt=(e,t,n={},r={})=>{if(!t)return!0;const s=L(t),a=[];for(const[u,l]of Object.entries(s)){const c=_(u);if(c){const f={args:l===!0?[]:Array.isArray(l)?l:[l],messages:n,fields:r},m=c(e,f);m!==!0&&a.push(m??"Invalid value")}else console.warn(`[Forms] Validation rule "${u}" 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 P=()=>{};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=P;const a=c=>{clearTimeout(c),s(),s=P};let u;return c=>{const g=o.toValue(e),f=o.toValue(t.maxWait);return n&&a(n),g<=0||f!==void 0&&f<=0?(r&&(a(r),r=void 0),Promise.resolve(c())):new Promise((m,d)=>{s=t.rejectOnCancel?d:m,u=c,f&&!r&&(r=setTimeout(()=>{n&&a(n),r=void 0,m(u())},f)),n=setTimeout(()=>{r&&a(r),r=void 0,m(c())},g)})}}function Qt(e,t,n={}){const{eventFilter:r=Ht,...s}=n;return o.watch(e,Gt(r,t),s)}function C(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),u=o.computed(()=>o.toValue(t.rules)??null),l=o.computed(()=>o.toValue(t.messages)??{}),c=o.computed(()=>o.toValue(t.fields)??{}),g=o.computed(()=>{if(!u.value||typeof u.value!="string")return null;const i=L(u.value).confirm;if(!i||i===!0)return null;const b=c.value[i];return(b==null?void 0:b.value)??null}),f=()=>{let d;return typeof u.value=="function"?d=Yt(o.toValue(e),u.value):d=Zt(o.toValue(e),u.value,l.value,c.value),d===!0?(n.value=!0,s.value=[],!0):Array.isArray(d)?(n.value=!1,s.value=d,!1):d},m=()=>{a.value&&clearTimeout(a.value),r.value=!0,n.value=!0,s.value=[],a.value=setTimeout(()=>{r.value=!1,a.value=null},1e3)};return C(()=>o.toValue(e),()=>{r.value||f()},{debounce:300}),C(()=>o.toValue(g),()=>{r.value||o.toValue(e)&&f()},{debounce:300}),{validate:f,reset:m,isValid:o.readonly(n),errors:o.readonly(s)}}const M=Symbol("field-context"),en=e=>{o.provide(M,e)};function tn(e){if(e===void 0){const t=o.inject(M);if(!t)throw new Error("useFieldContext() must be called inside a Field component");return t}return o.inject(M,e)}const 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=Wt(),a=q(),u=o.computed({get:()=>s?s.getFieldValue(t.name):n.value,set:y=>{s?s.setFieldValue(t.name,y):n.value=y}}),l=o.computed(()=>t.validation??null),c=o.computed(()=>({...a?a.locales.value[a.locale.value]:{},...t.validationMessages??{}})),g=o.computed({get:()=>s?s.getFields():{},set:()=>{}}),f=Xt(u,{rules:l,messages:c,fields:g}),m=o.ref(!1),d=o.ref(!1),i=o.ref([]),b=o.computed(()=>u.value??null),p=o.computed(()=>f.isValid.value&&i.value.length===0),$=o.computed(()=>[...f.errors.value,...i.value]),h=o.computed(()=>$.value[0]??null),S=o.toValue(u),v=t.id??r,N=`${v}-error`,w=`${v}-help`,W=y=>{i.value=Array.isArray(y)?y:[y]},A=()=>{u.value=S,m.value=!1,d.value=!1,i.value=[],f.reset()};o.watch(()=>t.error,y=>{y?i.value=Array.isArray(y)?y:[y]:i.value=[]},{immediate:!0});const F=o.computed(()=>({id:v,name:t.name,modelValue:u.value,"aria-invalid":!!h.value,"aria-describedby":h.value?`${N} ${w}`:w,"aria-errormessage":h.value?N:void 0,"onUpdate:modelValue":y=>{u.value=y,!d.value&&y!==S&&(d.value=!0)},onBlur:()=>{m.value||(m.value=!0,f.validate())}})),V={for:v},x={id:N,role:"alert","aria-live":"polite"},j={id:w};return o.onMounted(()=>{s&&s.addField(t.name,{value:b,isValid:p,isTouched:m,isDirty:d,error:h,errors:$,setErrors:W,reset:A,validate:f.validate})}),o.onUnmounted(()=>{s&&s.removeField(t.name)}),en({inputValue:u,inputProps:F,labelProps:V,helpProps:j,errorProps:x,isValid:p,isTouched:m,isDirty:d,error:h,errors:$,validate:f.validate,reset:A}),(y,un)=>(o.openBlock(),o.createElementBlock("div",null,[o.renderSlot(y.$slots,"default",o.normalizeProps(o.guardReactiveProps({inputValue:u.value,inputProps:F.value,labelProps:V,helpProps:j,errorProps:x,isValid:p.value,isTouched:m.value,isDirty:d.value,error:h.value,errors:$.value,validate:o.unref(f).validate,reset:A})))]))}});function rn(){const e=q();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}}function sn(e){const t=o.inject(M,null);if(t)return t;const n=o.toValue(e),r=o.useId(),s=`${r}-error`,a=`${r}-help`,u=o.ref(!1),l=o.ref(!1),c=o.computed(()=>({id:r,name:r,modelValue:e.value,"aria-invalid":!1,"aria-describedby":a,"aria-errormessage":void 0,"onUpdate:modelValue":g=>{e.value=g,!l.value&&g!==n&&(l.value=!0)},onBlur:()=>{u.value||(u.value=!0)}}));return{inputValue:e,inputProps:c,labelProps:{for:r},helpProps:{id:a},errorProps:{id:s,role:"alert","aria-live":"polite"},isValid:o.computed(()=>!0),isTouched:u,isDirty:l,error:o.computed(()=>null),errors:o.computed(()=>[]),validate:()=>!0,reset:()=>{e.value=n,u.value=!1,l.value=!1}}}function on(e){return e}const an={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"};exports.Field=nn;exports.Form=Kt;exports.FormsPlugin=It;exports.defineValiformConfig=on;exports.en=E;exports.es=an;exports.registerRule=B;exports.registerRules=D;exports.useFieldContext=tn;exports.useFormContext=zt;exports.useInputContext=sn;exports.useLocale=rn;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inject as N, shallowRef as R, isRef as ne, ref as h, readonly as A, provide as
|
|
1
|
+
import { inject as N, shallowRef as R, isRef as ne, ref as h, readonly as A, provide as V, defineComponent as W, useModel as L, isReactive as re, reactive as se, computed as d, openBlock as I, createElementBlock as _, withModifiers as oe, renderSlot as z, normalizeProps as U, guardReactiveProps as K, mergeModels as Z, watch as k, toValue as $, useId as Y, onMounted as ae, onUnmounted as ue, unref as ie } from "vue";
|
|
2
2
|
const G = Symbol("locale-context"), H = (e = null) => {
|
|
3
3
|
const t = N(G, e);
|
|
4
4
|
if (!t && t !== null)
|
|
@@ -113,11 +113,11 @@ function xe(e, t, n) {
|
|
|
113
113
|
var r;
|
|
114
114
|
return e ? n ? e === ((r = n[t]) == null ? void 0 : r.value) : !1 : !0;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function Ve(e, t = {}) {
|
|
117
117
|
const { args: n = [], messages: r = {}, fields: s = {} } = t, [o] = n;
|
|
118
118
|
return xe(e, o, s) ? !0 : Fe(r, o);
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function je(e) {
|
|
121
121
|
const t = e.containsAlpha;
|
|
122
122
|
return typeof t == "function" ? t({}) : t ?? "Must contain at least one letter";
|
|
123
123
|
}
|
|
@@ -126,18 +126,18 @@ function Pe(e) {
|
|
|
126
126
|
}
|
|
127
127
|
function Te(e, t = {}) {
|
|
128
128
|
const { messages: n = {} } = t;
|
|
129
|
-
return Pe(e) ? !0 :
|
|
129
|
+
return Pe(e) ? !0 : je(n);
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Ce(e) {
|
|
132
132
|
const t = e.containsAlphanumeric;
|
|
133
133
|
return typeof t == "function" ? t({}) : t ?? "Must contain at least one letter or number";
|
|
134
134
|
}
|
|
135
|
-
function
|
|
135
|
+
function qe(e) {
|
|
136
136
|
return e ? /[a-zA-Z0-9]/.test(String(e)) : !0;
|
|
137
137
|
}
|
|
138
138
|
function Ee(e, t = {}) {
|
|
139
139
|
const { messages: n = {} } = t;
|
|
140
|
-
return
|
|
140
|
+
return qe(e) ? !0 : Ce(n);
|
|
141
141
|
}
|
|
142
142
|
function Be(e) {
|
|
143
143
|
const t = e.containsAlphaSpaces;
|
|
@@ -349,12 +349,12 @@ function xt(e) {
|
|
|
349
349
|
const t = e.lowercase;
|
|
350
350
|
return typeof t == "function" ? t({}) : t ?? "Must contain only lowercase characters";
|
|
351
351
|
}
|
|
352
|
-
function
|
|
352
|
+
function Vt(e) {
|
|
353
353
|
return e ? /^[a-z]+$/.test(String(e)) : !0;
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function jt(e, t = {}) {
|
|
356
356
|
const { messages: n = {} } = t;
|
|
357
|
-
return
|
|
357
|
+
return Vt(e) ? !0 : xt(n);
|
|
358
358
|
}
|
|
359
359
|
function Pt(e, t, n) {
|
|
360
360
|
const r = t.matches;
|
|
@@ -373,11 +373,11 @@ function Tt(e, t) {
|
|
|
373
373
|
return !1;
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
function
|
|
376
|
+
function Ct(e, t = {}) {
|
|
377
377
|
const { args: n = [], messages: r = {} } = t, [s] = n;
|
|
378
378
|
return Tt(e, s) ? !0 : Pt(e, r, s);
|
|
379
379
|
}
|
|
380
|
-
function
|
|
380
|
+
function qt(e, t) {
|
|
381
381
|
const n = e.max;
|
|
382
382
|
return typeof n == "function" ? n({ value: t }) : n ?? `Must be at most ${t}`;
|
|
383
383
|
}
|
|
@@ -394,7 +394,7 @@ function Et(e, t) {
|
|
|
394
394
|
}
|
|
395
395
|
function Bt(e, t = {}) {
|
|
396
396
|
const { args: n = [], messages: r = {} } = t, [s] = n;
|
|
397
|
-
return Et(e, s) ? !0 :
|
|
397
|
+
return Et(e, s) ? !0 : qt(r, s);
|
|
398
398
|
}
|
|
399
399
|
function Ot(e, t) {
|
|
400
400
|
const n = e.min;
|
|
@@ -510,7 +510,7 @@ const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
510
510
|
alphaSpaces: we,
|
|
511
511
|
alphanumeric: ve,
|
|
512
512
|
between: Se,
|
|
513
|
-
confirm:
|
|
513
|
+
confirm: Ve,
|
|
514
514
|
containsAlpha: Te,
|
|
515
515
|
containsAlphaSpaces: Re,
|
|
516
516
|
containsAlphanumeric: Ee,
|
|
@@ -528,8 +528,8 @@ const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
528
528
|
endsWith: Mt,
|
|
529
529
|
is: At,
|
|
530
530
|
length: Ft,
|
|
531
|
-
lowercase:
|
|
532
|
-
matches:
|
|
531
|
+
lowercase: jt,
|
|
532
|
+
matches: Ct,
|
|
533
533
|
max: Bt,
|
|
534
534
|
min: Wt,
|
|
535
535
|
not: _t,
|
|
@@ -556,14 +556,14 @@ const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
556
556
|
});
|
|
557
557
|
}
|
|
558
558
|
}, Q = Symbol("form-state-context"), cn = (e) => {
|
|
559
|
-
|
|
559
|
+
V(Q, e);
|
|
560
560
|
}, ln = (e = null) => {
|
|
561
561
|
const t = N(Q, e);
|
|
562
562
|
if (!t && t !== null)
|
|
563
563
|
throw new Error("Context with formStateContextKey not found");
|
|
564
564
|
return t;
|
|
565
565
|
}, X = Symbol("form-context"), fn = (e) => {
|
|
566
|
-
|
|
566
|
+
V(X, e);
|
|
567
567
|
}, Dn = (e = null) => {
|
|
568
568
|
const t = N(X, e);
|
|
569
569
|
if (!t && t !== null)
|
|
@@ -785,7 +785,7 @@ function vn(e, t = {}) {
|
|
|
785
785
|
};
|
|
786
786
|
}
|
|
787
787
|
const D = Symbol("field-context"), Mn = (e) => {
|
|
788
|
-
|
|
788
|
+
V(D, e);
|
|
789
789
|
};
|
|
790
790
|
function Fn(e) {
|
|
791
791
|
if (e === void 0) {
|
|
@@ -821,10 +821,10 @@ const xn = /* @__PURE__ */ W({
|
|
|
821
821
|
get: () => s ? s.getFields() : {},
|
|
822
822
|
set: () => {
|
|
823
823
|
}
|
|
824
|
-
}), l = vn(a, { rules: c, messages: i, fields: g }), f = h(!1), m = h(!1), u = h([]), b = d(() => a.value ?? null), p = d(() => l.isValid.value && u.value.length === 0), v = d(() => [...l.errors.value, ...u.value]), M = d(() => v.value[0] ?? null),
|
|
824
|
+
}), l = vn(a, { rules: c, messages: i, fields: g }), f = h(!1), m = h(!1), u = h([]), b = d(() => a.value ?? null), p = d(() => l.isValid.value && u.value.length === 0), v = d(() => [...l.errors.value, ...u.value]), M = d(() => v.value[0] ?? null), j = $(a), w = t.id ?? r, S = `${w}-error`, F = `${w}-help`, te = (y) => {
|
|
825
825
|
u.value = Array.isArray(y) ? y : [y];
|
|
826
826
|
}, x = () => {
|
|
827
|
-
a.value =
|
|
827
|
+
a.value = j, f.value = !1, m.value = !1, u.value = [], l.reset();
|
|
828
828
|
};
|
|
829
829
|
k(
|
|
830
830
|
() => t.error,
|
|
@@ -841,12 +841,12 @@ const xn = /* @__PURE__ */ W({
|
|
|
841
841
|
"aria-describedby": M.value ? `${S} ${F}` : F,
|
|
842
842
|
"aria-errormessage": M.value ? S : void 0,
|
|
843
843
|
"onUpdate:modelValue": (y) => {
|
|
844
|
-
a.value = y, !m.value && y !==
|
|
844
|
+
a.value = y, !m.value && y !== j && (m.value = !0);
|
|
845
845
|
},
|
|
846
846
|
onBlur: () => {
|
|
847
847
|
f.value || (f.value = !0, l.validate());
|
|
848
848
|
}
|
|
849
|
-
})), T = { for: w },
|
|
849
|
+
})), T = { for: w }, C = { id: S, role: "alert", "aria-live": "polite" }, q = { id: F };
|
|
850
850
|
return ae(() => {
|
|
851
851
|
s && s.addField(t.name, {
|
|
852
852
|
value: b,
|
|
@@ -865,8 +865,8 @@ const xn = /* @__PURE__ */ W({
|
|
|
865
865
|
inputValue: a,
|
|
866
866
|
inputProps: P,
|
|
867
867
|
labelProps: T,
|
|
868
|
-
helpProps:
|
|
869
|
-
errorProps:
|
|
868
|
+
helpProps: q,
|
|
869
|
+
errorProps: C,
|
|
870
870
|
isValid: p,
|
|
871
871
|
isTouched: f,
|
|
872
872
|
isDirty: m,
|
|
@@ -879,8 +879,8 @@ const xn = /* @__PURE__ */ W({
|
|
|
879
879
|
inputValue: a.value,
|
|
880
880
|
inputProps: P.value,
|
|
881
881
|
labelProps: T,
|
|
882
|
-
helpProps:
|
|
883
|
-
errorProps:
|
|
882
|
+
helpProps: q,
|
|
883
|
+
errorProps: C,
|
|
884
884
|
isValid: p.value,
|
|
885
885
|
isTouched: f.value,
|
|
886
886
|
isDirty: m.value,
|
|
@@ -892,7 +892,7 @@ const xn = /* @__PURE__ */ W({
|
|
|
892
892
|
]));
|
|
893
893
|
}
|
|
894
894
|
});
|
|
895
|
-
function
|
|
895
|
+
function Vn() {
|
|
896
896
|
const e = H();
|
|
897
897
|
if (!e)
|
|
898
898
|
throw new Error(
|
|
@@ -904,7 +904,7 @@ function jn() {
|
|
|
904
904
|
setLocale: e.setLocale
|
|
905
905
|
};
|
|
906
906
|
}
|
|
907
|
-
function
|
|
907
|
+
function jn(e) {
|
|
908
908
|
const t = N(D, null);
|
|
909
909
|
if (t)
|
|
910
910
|
return t;
|
|
@@ -939,7 +939,10 @@ function Vn(e) {
|
|
|
939
939
|
}
|
|
940
940
|
};
|
|
941
941
|
}
|
|
942
|
-
|
|
942
|
+
function Pn(e) {
|
|
943
|
+
return e;
|
|
944
|
+
}
|
|
945
|
+
const Tn = {
|
|
943
946
|
required: "Este campo es obligatorio",
|
|
944
947
|
email: "Por favor ingresa un email válido",
|
|
945
948
|
min: ({ value: e }) => `Debe ser al menos ${e}`,
|
|
@@ -979,12 +982,13 @@ export {
|
|
|
979
982
|
xn as Field,
|
|
980
983
|
Sn as Form,
|
|
981
984
|
An as FormsPlugin,
|
|
985
|
+
Pn as defineValiformConfig,
|
|
982
986
|
ce as en,
|
|
983
|
-
|
|
987
|
+
Tn as es,
|
|
984
988
|
le as registerRule,
|
|
985
989
|
E as registerRules,
|
|
986
990
|
Fn as useFieldContext,
|
|
987
991
|
Dn as useFormContext,
|
|
988
|
-
|
|
989
|
-
|
|
992
|
+
jn as useInputContext,
|
|
993
|
+
Vn as useLocale
|
|
990
994
|
};
|
package/dist/nuxt/module.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface NuxtModuleOptions {
|
|
2
|
+
/** Default locale key (e.g. 'es', 'en'). Serializable — safe in nuxt.config. */
|
|
3
|
+
locale?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Path to a file that default-exports a `defineValiformConfig({…})` object.
|
|
6
|
+
* Because Nuxt bundles this file at build time, imports, closures and
|
|
7
|
+
* external variables all work normally — no serialization limitations.
|
|
8
|
+
*/
|
|
9
|
+
config?: string;
|
|
4
10
|
}
|
|
5
11
|
declare const _default: NuxtModule<TOptions, TOptions, false>;
|
|
6
12
|
export default _default;
|
package/dist/nuxt.cjs
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
"use strict";const e=require("@nuxt/kit");var
|
|
2
|
-
|
|
3
|
-
`)}
|
|
4
|
-
}`;t.push(`export const customRules = ${n};`)}else t.push("export const customRules = null;");e.addTemplate({filename:"valiform/options.mjs",getContents:()=>t.join(`
|
|
5
|
-
`),write:!0}),e.addPlugin(m.resolve("./runtime/plugin")),e.addComponent({name:"Form",export:"Form",filePath:"@overgaming/valiform"}),e.addComponent({name:"Field",export:"Field",filePath:"@overgaming/valiform"}),e.addImports([{name:"useLocale",from:"@overgaming/valiform"},{name:"useFormContext",from:"@overgaming/valiform"},{name:"useFieldContext",from:"@overgaming/valiform"},{name:"useInputContext",from:"@overgaming/valiform"}])}});module.exports=c;
|
|
1
|
+
"use strict";const e=require("@nuxt/kit");var t=typeof document<"u"?document.currentScript:null;const s=e.defineNuxtModule({meta:{name:"@overgaming/valiform",configKey:"valiform",compatibility:{nuxt:">=3.0.0"}},defaults:{},async setup(i){const r=e.createResolver(typeof document>"u"?require("url").pathToFileURL(__filename).href:t&&t.tagName.toUpperCase()==="SCRIPT"&&t.src||new URL("nuxt.cjs",document.baseURI).href),{config:n,...a}=i,o=[];if(n){const m=await e.resolvePath(n);o.push(`import _config from ${JSON.stringify(m)};`)}o.push(`export const pluginOptions = ${JSON.stringify(a)};`),o.push(`export const valiformConfig = ${n?"_config":"null"};`),e.addTemplate({filename:"valiform/options.mjs",getContents:()=>o.join(`
|
|
2
|
+
`),write:!0}),e.addPlugin(r.resolve("./runtime/plugin")),e.addComponent({name:"Form",export:"Form",filePath:"@overgaming/valiform"}),e.addComponent({name:"Field",export:"Field",filePath:"@overgaming/valiform"}),e.addImports([{name:"useLocale",from:"@overgaming/valiform"},{name:"useFormContext",from:"@overgaming/valiform"},{name:"useFieldContext",from:"@overgaming/valiform"},{name:"useInputContext",from:"@overgaming/valiform"}])}});module.exports=s;
|
package/dist/nuxt.js
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
import { defineNuxtModule as
|
|
2
|
-
const
|
|
1
|
+
import { defineNuxtModule as a, createResolver as l, resolvePath as s, addTemplate as f, addPlugin as g, addComponent as i, addImports as p } from "@nuxt/kit";
|
|
2
|
+
const v = a({
|
|
3
3
|
meta: {
|
|
4
4
|
name: "@overgaming/valiform",
|
|
5
5
|
configKey: "valiform",
|
|
6
6
|
compatibility: { nuxt: ">=3.0.0" }
|
|
7
7
|
},
|
|
8
8
|
defaults: {},
|
|
9
|
-
async setup(
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
${Object.entries(o).map(([a, l]) => ` ${JSON.stringify(a)}: ${l.toString()}`).join(`,
|
|
17
|
-
`)}
|
|
18
|
-
}`;
|
|
19
|
-
e.push(`export const customRules = ${t};`);
|
|
20
|
-
} else
|
|
21
|
-
e.push("export const customRules = null;");
|
|
22
|
-
g({
|
|
9
|
+
async setup(n) {
|
|
10
|
+
const t = l(import.meta.url), { config: e, ...r } = n, o = [];
|
|
11
|
+
if (e) {
|
|
12
|
+
const m = await s(e);
|
|
13
|
+
o.push(`import _config from ${JSON.stringify(m)};`);
|
|
14
|
+
}
|
|
15
|
+
o.push(`export const pluginOptions = ${JSON.stringify(r)};`), o.push(`export const valiformConfig = ${e ? "_config" : "null"};`), f({
|
|
23
16
|
filename: "valiform/options.mjs",
|
|
24
|
-
getContents: () =>
|
|
17
|
+
getContents: () => o.join(`
|
|
25
18
|
`),
|
|
26
19
|
write: !0
|
|
27
|
-
}),
|
|
20
|
+
}), g(t.resolve("./runtime/plugin")), i({ name: "Form", export: "Form", filePath: "@overgaming/valiform" }), i({ name: "Field", export: "Field", filePath: "@overgaming/valiform" }), p([
|
|
28
21
|
{ name: "useLocale", from: "@overgaming/valiform" },
|
|
29
22
|
{ name: "useFormContext", from: "@overgaming/valiform" },
|
|
30
23
|
{ name: "useFieldContext", from: "@overgaming/valiform" },
|
|
@@ -33,5 +26,5 @@ ${Object.entries(o).map(([a, l]) => ` ${JSON.stringify(a)}: ${l.toString()}`).j
|
|
|
33
26
|
}
|
|
34
27
|
});
|
|
35
28
|
export {
|
|
36
|
-
|
|
29
|
+
v as default
|
|
37
30
|
};
|
package/dist/runtime/plugin.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const n=require("#app"),l=require("@overgaming/valiform"),i=require("#build/valiform/options.mjs"),u=n.defineNuxtPlugin(r=>{var s,e;const o={...i.pluginOptions};(s=i.valiformConfig)!=null&&s.locales&&(o.locales=i.valiformConfig.locales),r.vueApp.use(l.FormsPlugin,o),(e=i.valiformConfig)!=null&&e.rules&&l.registerRules(i.valiformConfig.rules)});module.exports=u;
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { defineNuxtPlugin as
|
|
2
|
-
import { FormsPlugin as
|
|
3
|
-
import { pluginOptions as
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
import { defineNuxtPlugin as r } from "#app";
|
|
2
|
+
import { FormsPlugin as t, registerRules as u } from "@overgaming/valiform";
|
|
3
|
+
import { pluginOptions as p, valiformConfig as o } from "#build/valiform/options.mjs";
|
|
4
|
+
const a = r((s) => {
|
|
5
|
+
var e, i;
|
|
6
|
+
const l = { ...p };
|
|
7
|
+
(e = o) != null && e.locales && (l.locales = o.locales), s.vueApp.use(t, l), (i = o) != null && i.rules && u(o.rules);
|
|
6
8
|
});
|
|
7
9
|
export {
|
|
8
|
-
|
|
10
|
+
a as default
|
|
9
11
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ValiformConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Define the Valiform configuration for a Nuxt application.
|
|
4
|
+
*
|
|
5
|
+
* Use this in a dedicated config file (e.g. `valiform.config.ts`) that you
|
|
6
|
+
* reference from `nuxt.config.ts` via the `config` option. Because Nuxt
|
|
7
|
+
* bundles this file at build time with full module resolution, imports and
|
|
8
|
+
* closures work normally — unlike inline options in `nuxt.config.ts`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* // valiform.config.ts
|
|
13
|
+
* import { defineValiformConfig, es, en } from '@overgaming/valiform';
|
|
14
|
+
* import * as rules from './rules';
|
|
15
|
+
*
|
|
16
|
+
* export default defineValiformConfig({
|
|
17
|
+
* locales: { es, en },
|
|
18
|
+
* rules
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineValiformConfig(config: ValiformConfig): ValiformConfig;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { useLocale } from './composables/useLocale';
|
|
|
6
6
|
export { useFormContext } from './context/useFormContext';
|
|
7
7
|
export { useFieldContext } from './context/useFieldContext';
|
|
8
8
|
export { useInputContext } from './context/useInputContext';
|
|
9
|
-
export type { FieldContext, FieldState, FormContext, InputProps, RuleFunction, FormsPluginOptions } from './types';
|
|
9
|
+
export type { FieldContext, FieldState, FormContext, InputProps, RuleFunction, FormsPluginOptions, ValiformConfig } from './types';
|
|
10
|
+
export { defineValiformConfig } from './defineValiformConfig';
|
|
10
11
|
export { en } from './locales/en';
|
|
11
12
|
export { es } from './locales/es';
|
package/dist/src/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overgaming/valiform",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Vue 3 form validation library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"form",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"main": "./dist/index.cjs",
|
|
23
23
|
"module": "./dist/index.js",
|
|
24
|
-
"types": "./dist/index.d.ts",
|
|
24
|
+
"types": "./dist/src/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
27
|
+
"types": "./dist/src/index.d.ts",
|
|
28
28
|
"import": "./dist/index.js",
|
|
29
29
|
"require": "./dist/index.cjs"
|
|
30
30
|
},
|
|
31
31
|
"./nuxt": {
|
|
32
|
-
"types": "./dist/nuxt.d.ts",
|
|
32
|
+
"types": "./dist/nuxt/module.d.ts",
|
|
33
33
|
"import": "./dist/nuxt.js",
|
|
34
34
|
"require": "./dist/nuxt.cjs"
|
|
35
35
|
}
|