@apia/validations 0.1.3 → 0.2.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/dist/index.js CHANGED
@@ -1 +1,2229 @@
1
- import{jsx as f,jsxs as D}from"react/jsx-runtime";import{customEvents as Xa,propsStore as W,usePropsSelector as Oe,useUpdateEffect as Ja,useUnmount as Fe,useMount as ye,PropsSelectorUndefinedObject as xe,formatMessage as Za,toBoolean as Ya}from"@apia/util";import{uniqueId as el}from"lodash";import c from"react";import{shallowEqual as ce}from"react-redux";import{makeStyledComponent as al,getVariant as ll}from"@apia/theme";import{notify as Ve}from"@apia/notifications";import{RequiredMark as A,Captcha as il,Checkbox as rl,IconButton as nl,getFieldErrorStyles as tl,DateInput as ol,parseNumberInputValueToNumber as $e,NumberInput as sl}from"@apia/components";import{Box as G,Input as ve,Label as Pe,Radio as ul,Select as dl,Switch as ml,Textarea as cl}from"theme-ui";const q=c.createContext({});function M(){const e=c.useContext(q);if(!e)throw new Error("There is no FormContext");return e}function vl({rules:e,value:a}){return xl(e).validate(a)}var fl=Object.defineProperty,we=Object.getOwnPropertySymbols,pl=Object.prototype.hasOwnProperty,bl=Object.prototype.propertyIsEnumerable,Se=(e,a,l)=>a in e?fl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,hl=(e,a)=>{for(var l in a||(a={}))pl.call(a,l)&&Se(e,l,a[l]);if(we)for(var l of we(a))bl.call(a,l)&&Se(e,l,a[l]);return e},fe=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});function gl(e,a){return fe(this,null,function*(){let l=null;const i=e.validationValueParser?e.validationValueParser(e.value):e.value;return e.validationFunction&&(l=yield e.validationFunction(i,a)),(!e.validationFunction||l===!0)&&e.validationRules?l=vl({rules:e.validationRules,value:i}):l===null&&(l=!0),l})}function Ne(e){return e===!0}function Ol(e){return!("errors"in e)}function Fl(e,a){return fe(this,null,function*(){const l=document.getElementById(`ValidationForm-${e}`),i=l?.querySelector(`[name="${a.name}"], #${a.name}`);return i?new Promise(r=>{const n=new CustomEvent(Xa.focus,{bubbles:!0});i.focus(),i.dispatchEvent(n),i.scrollIntoView({block:"center",behavior:"auto"}),r(!0)}):!1})}let X;function I(e,...a){if(!X[e])return"";let l=X[e];return a.forEach((i,r)=>{l=l.replace(`%${r}`,i.toString())}),l}function Re(e){const a=e?.match(/'confirm:(\w+):(.+?)']/);if(a)return(l,i)=>{var r,n;return l===((r=R.getFieldStore(i,a[1]))==null?void 0:r.value)?!0:I("confirm",(n=a[2])!=null?n:a[1])}}function Ce(e){const a={};if(e){const l=e.match(/validate\[([^\]]+)\]/);if(l)return l[1].replaceAll("~","").split(",").forEach(i=>{const r=i.match(/(\w+)(?:=([\w\d]+))?/);if(r){const n=r[1];if(n==="pattern"&&r[2])a[n]=new RegExp(r[2]);else if(r[2]){const o=r[2].split(","),u=o.length<2?o.join():o;a[n]=u}else a[n]=!0}}),a}return{}}function yl(){return fe(this,null,function*(){var e;X||(X=(yield import(`../lang/${(e=document.documentElement.lang)!=null?e:"es"}.ts`).catch(a=>{throw Ve({type:"danger",message:window.NO_LANGUAGE_EXCEPTION}),a})).default)})}function xl(e){const a=hl({},e);return a?{validate:l=>{var i;const r=l??"";let n=!0;if(n&&a.pattern){let o;if(a.pattern instanceof RegExp)o=a.pattern;else{const u=a.pattern.match(/(?:^\/(.+)\/(\w+)?$)|(^.*$)/),t=u[1],s=u[2],m=u[3];o=new RegExp(t||m,s||void 0)}n=!!l.match(o)||((i=a.patternMessage)!=null?i:window.MSG_INVALID_REG_EXP)}if(n===!0&&a.maxLength&&(n=r.length<=a.maxLength||I("lengthmax",a.maxLength)),n===!0&&a.minLength&&(n=r.length>=a.minLength||I("lengthmin",a.minLength)),n===!0&&a.max&&a.min&&(n=Number(r)<=a.max&&Number(r)>=a.min||I("digitltd",a.min,a.max)),n===!0&&a.min&&(n=Number(r)>=a.min||I("digitmin",a.min)),n===!0&&a.max&&(n=Number(r)<=a.max||I("digitltd",0,a.max)),n===!0&&a.validName&&(n=!!r.match(/^[a-zA-Z0-9_.]*$/)||window.GNR_INVALID_NAME),n===!0&&(a.alpha||a.nodigit)&&(n=!!r.match(/^[a-zA-Z]*$/)||I("alpha")),n===!0&&a.alphanum&&(n=!!r.match(/^[a-zA-Z0-9]*$/)||I("alphanum")),n===!0&&(a.digit||a.number)&&(n=!!r.match(/^[0-9]*$/)||I("digit")),n===!0&&a.email&&(n=!!r.match(/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/)||I("email")),n===!0&&a.differs&&(n=r!==a.differs||I("differs",a.differs)),n===!0&&a.length_str&&(n=r.length>=a.length_str[0]&&r.length<=a.length_str[1]||I("length_str",...a.length_str)),n===!0&&a.length_fix&&(n=r.length===a.length_fix||I("length_fix",a.length_fix)),n===!0&&a.words_min)return r.split(" ").length>=a.words_min||I("words_min",a.words_min);if(n===!0&&a.words_max)return r.split(" ").length<=a.words_max||I("words_max",a.words_max);if(n===!0&&a.words_range){const o=r.split(" ").length;return o<=a.words_range[0]&&o>=a.words_range[1]||I("words_range",...a.words_range)}return n===!0&&a.required&&(n=Array.isArray(l)&&l.length>0||typeof l=="number"||!Array.isArray(r)&&!!r||I("required")),n}}:{validate:()=>!0}}var Vl=Object.defineProperty,$l=Object.defineProperties,Pl=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,Ie=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable,je=(e,a,l)=>a in e?Vl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Z=(e,a)=>{for(var l in a||(a={}))Ie.call(a,l)&&je(e,l,a[l]);if(J)for(var l of J(a))Ee.call(a,l)&&je(e,l,a[l]);return e},wl=(e,a)=>$l(e,Pl(a)),Sl=(e,a)=>{var l={};for(var i in e)Ie.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&J)for(var i of J(e))a.indexOf(i)<0&&Ee.call(e,i)&&(l[i]=e[i]);return l},Nl=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});const R=new class{constructor(){this.activeForms=[],this.timeouts={},this.existsField=(e,a)=>{var l,i;return!!((i=(l=this.getFormStore(e))==null?void 0:l.fields)!=null&&i.includes(a))},this.registerField=(e,a,l={registerIfExists:!0})=>{var i,r,n;const o=this.getFormStore(e);o===void 0&&this.registerForm(e),(i=this.getFormStore(e))!=null&&i.fields.includes(a.name)||this.updateFormStore(e,{fields:[...(n=(r=this.getFormStore(e))==null?void 0:r.fields)!=null?n:[],a.name]});const u=this.getFieldStore(e,a.name);if((o!=null&&o.avoidFieldsOverride||!l.registerIfExists)&&u){const t=a,s=Sl(t,["value"]);this.updateField(e,s,{markFormAsTouched:!1,avoidPropagation:l.avoidPropagation});return}this.updateFieldStore(e,a.name,a,l.avoidPropagation)},this.registerForm=(e,a={avoidFieldsOverride:!1})=>{var l;if(this.activeForms.includes(e)){this.updateFormStore(e,{avoidFieldsOverride:a.avoidFieldsOverride}),a.initialValues&&Object.entries(a.initialValues).forEach(([i,r])=>{r instanceof Object&&this.updateField(e,Z({name:i},r))});return}this.activeForms.push(e),this.updateFormStore(e,{avoidFieldsOverride:a.avoidFieldsOverride,fields:[],isTouched:!1,isValid:!1,name:e,validationResult:null}),Object.entries((l=a.initialValues)!=null?l:{}).forEach(([i,r])=>{this.updateField(e,{name:i,value:r},{markFormAsTouched:!1})})},this.setFieldValue=(e,a,l,i)=>{this.getFieldStore(e,a)?this.updateField(e,{name:a,value:l,error:null},i):this.registerField(e,{name:a,value:l}),this.getFormStore(e).isValid&&this.updateFormStore(e,{isValid:!1})},this.setFormIsTouched=(e,a=!0)=>{this.updateFormStore(e,{isTouched:a})},this.unregisterField=(e,a)=>{this.getFormStore(e)&&this.updateFormStore(e,{fields:this.getFormStore(e).fields.filter(l=>l!==a)}),W.removeField(this.makeFieldName(e,a))},this.unregisterForm=e=>{var a,l;(l=(a=this.getFormStore(e))==null?void 0:a.fields)==null||l.forEach(i=>W.removeField(this.makeFieldName(e,i))),this.activeForms=this.activeForms.filter(i=>i!==e),W.removeField(this.makeFormName(e)),delete this.timeouts[e]},this.updateField=(e,a,l)=>{var i,r;const n=(i=this.getFieldStore(e,a.name))==null?void 0:i.value;this.getFormStore(e)?this.updateFormStore(e,{isValid:!1}):this.registerForm(e);const o=a.value!==void 0&&a.value!==n&&l?.markFormAsTouched!==!1;this.existsField(e,a.name)||this.registerField(e,a,{avoidPropagation:l?.avoidPropagation}),this.updateFieldStore(e,a.name,wl(Z({},a),{isTouched:o||((r=this.getFieldStore(e,a.name))==null?void 0:r.isTouched)}),l?.avoidPropagation),o&&this.setFormIsTouched(e)},this.updateMultipleFields=(e,a,l)=>{a.forEach(i=>this.updateField(e,i,l))},this.validateForm=e=>Nl(this,null,function*(){var a;const l=this.getFormStore(e).fields.map(t=>this.getFieldStore(e,t)),i={errors:{}},r={submitValues:{},values:{}};let n=!1,o=!1;const u={};for(const t of l.filter(s=>s!==void 0)){const s=yield gl(t,e);u[t.name]=s,Ne(s)?(r.submitValues[(a=t.submitName)!=null?a:t.name]=t.submitValueParser?t.submitValueParser(t.value):t.value,r.values[t.name]=t.value):(this.updateField(e,{name:t.name,error:s}),n||(yield Fl(e,t))&&(n=!0),o=!0,i.errors[t.name]=s)}return o?(n||(Ve({message:window.MSG_WRONG_VALIDATION_NO_FOCUSED_FILE,type:"danger"}),console.error("Campos que fallaron la validaci\xF3n",u)),this.updateFormStore(e,{isValid:!1,validationResult:i}),i):(this.updateFormStore(e,{isValid:!0,validationResult:r}),r)})}getFieldStore(e,a){return W.getFieldProps(this.makeFieldName(e,a))}getFormStore(e){return W.getFieldProps(this.makeFormName(e))}updateFieldStore(e,a,l,i){W.updateField(this.makeFieldName(e,a),Z(Z({},this.getFieldStore(e,a)),l),{noEmit:i})}updateFormStore(e,a){W.updateField(this.makeFormName(e),a)}enableFormTouch(e){this.timeouts[e]=!0}makeFieldName(e,a){return`validation_${e}_${a}`}makeFormName(e){return`validation_${e}`}};function Te(e,a,l){return Oe(R.makeFormName(e),a,l)}function B(e,a,l,i){const r=R.makeFieldName(e,a);return Oe(r,l,i)}const Rl={".fieldWrapper":{display:"flex",flexDirection:"column",alignItems:"stretch","&.checkbox":{alignItems:"center"}},".error":{borderLeftStyle:"solid",borderLeftWidth:"4px",borderLeftColor:"danger"},".touched":{borderStyle:"solid",borderWidth:"1px",borderColor:"orange"}};var Cl=(e,a,l)=>new Promise((i,r)=>{var n=t=>{try{u(l.next(t))}catch(s){r(s)}},o=t=>{try{u(l.throw(t))}catch(s){r(s)}},u=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,o);u((l=l.apply(e,a)).next())});const Il=({avoidFieldsOverride:e,avoidFieldsTouch:a,children:l,className:i,name:r,initialValues:n,onUnmount:o,onValidate:u,unregisterOnUnmount:t})=>{const s=c.useMemo(()=>r??`ValidationForm${el()}`,[]),m=Te(s,x=>x.validationResult,ce);Ja(()=>{m&&u&&u(m)},[m]);const d=c.useCallback(x=>{x.preventDefault(),R.validateForm(s)},[s]),v=c.useMemo(()=>({avoidFieldsTouch:a,name:s,validate:()=>Cl(void 0,null,function*(){return R.validateForm(s)})}),[s,a]);Fe(()=>{o?.(),t!==!1&&R.unregisterForm(s)});const[p,$]=c.useState(!1);return ye(()=>{R.registerForm(s,{avoidFieldsOverride:e??n!==void 0,initialValues:n}),$(!0)}),p?f(q.Provider,{value:v,children:f("form",{className:i,id:`ValidationForm-${s}`,name:s,onSubmit:d,children:l})}):null},El=al("Form","layout.common.validations.form",Rl,Il);var jl=Object.defineProperty,_e=Object.getOwnPropertySymbols,Tl=Object.prototype.hasOwnProperty,_l=Object.prototype.propertyIsEnumerable,ke=(e,a,l)=>a in e?jl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ue=(e,a)=>{for(var l in a||(a={}))Tl.call(a,l)&&ke(e,l,a[l]);if(_e)for(var l of _e(a))_l.call(a,l)&&ke(e,l,a[l]);return e};function _(e){var a;const l=c.useContext(q),i=(a=e.formName)!=null?a:l.name;if(!i)throw console.error(e),new Error(`useField: It was not possible to determine the formName in field with name ${e.name}`);c.useMemo(()=>{R.registerField(i,Ue(Ue({},e),e.initialValue!==void 0?{value:e.initialValue}:null),{avoidPropagation:!0,registerIfExists:!e.avoidRegisterIfExists})},[]),ye(()=>{var d;e.initialValue!==void 0&&(!((d=R.getFormStore(i))!=null&&d.avoidFieldsOverride)&&!e.avoidRegisterIfExists||R.getFieldStore(i,e.name)===void 0)&&R.setFieldValue(i,e.name,e.initialValue)}),Fe(()=>{e.removeOnUnmount&&R.unregisterField(i,e.name)});const{name:r,value:n,error:o,isTouched:u}=B(i,e.name,d=>d,(d,v)=>d===xe&&e.initialValue!==void 0?!0:ce(d,v)),[t,s]=c.useState(e.initialValue);c.useEffect(()=>{s(n)},[n]);const m=c.useCallback(d=>{const v=d;let p;typeof v=="object"&&v&&v.target!==void 0&&v.target.value!==void 0?p=v.target.value:p=d,s(p),R.setFieldValue(i,e.name,p)},[e.name,i]);return{error:o,isTouched:u,name:r,onChange:m,updateValidations:c.useCallback(({validationFunction:d,validationRules:v})=>{R.updateField(i,{name:e.name,validationFunction:d,validationRules:v})},[i,e.name]),value:t??e.initialValue}}function Q(e,a){const{error:l,isTouched:i}=_({name:e,formName:a,avoidRegisterIfExists:!0,removeOnUnmount:!1}),{avoidFieldsTouch:r}=M();return l?"error":!r&&i?"touched":""}function kl({formName:e,name:a}){const{name:l}=M();if(!e&&!l)throw new Error(`useFieldValue: It was not possible to determine the formName in field with name ${a}`);const{value:i}=B(e??l,a,r=>r,(r,n)=>r===xe&&n?.value===void 0?!0:ce(r?.value,n?.value));return i}var Ul=Object.defineProperty,De=Object.getOwnPropertySymbols,Dl=Object.prototype.hasOwnProperty,Ll=Object.prototype.propertyIsEnumerable,Le=(e,a,l)=>a in e?Ul(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,We=(e,a)=>{for(var l in a||(a={}))Dl.call(a,l)&&Le(e,l,a[l]);if(De)for(var l of De(a))Ll.call(a,l)&&Le(e,l,a[l]);return e};function U({customValidation:e,validationClass:a,validationFunction:l,validationRules:i}){const r=c.useMemo(()=>a!==void 0?Re(a):void 0,[a]),n=c.useCallback((u,t)=>{var s;let m=(s=l?.(u,t))!=null?s:!0;return typeof m=="string"||(e&&(m=e(u,t)),typeof m=="string")?m:r?r(u,t):!0},[r,e,l]),o=c.useMemo(()=>We(We({},i),a!==void 0?Ce(a):{}),[a,i]);return{actualValidationFunction:n,actualValidationRules:o}}const pe=({name:e})=>{const a=M(),l=B(a.name,e,i=>i?.error);return l?f(G,{as:"strong",role:"alert",sx:{color:"danger"},dangerouslySetInnerHTML:{__html:l}}):null};var Wl=Object.defineProperty,ql=Object.defineProperties,Al=Object.getOwnPropertyDescriptors,Y=Object.getOwnPropertySymbols,qe=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,Me=(e,a,l)=>a in e?Wl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ze=(e,a)=>{for(var l in a||(a={}))qe.call(a,l)&&Me(e,l,a[l]);if(Y)for(var l of Y(a))Ae.call(a,l)&&Me(e,l,a[l]);return e},He=(e,a)=>ql(e,Al(a)),Ml=(e,a)=>{var l={};for(var i in e)qe.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&Y)for(var i of Y(e))a.indexOf(i)<0&&Ae.call(e,i)&&(l[i]=e[i]);return l};const k=e=>{var a=e,{name:l,label:i,avoidSemicolon:r,children:n,className:o,as:u="label",type:t}=a,s=Ml(a,["name","label","avoidSemicolon","children","className","as","type"]);const{name:m}=M(),d=B(m,l,v=>{var p;return(p=v?.validationRules)==null?void 0:p.required});return t==="checkbox"?D(G,He(ze({className:`fieldWrapper checkboxWrapper ${o??""}`},s),{as:u,children:[window.SHOW_REQUIRED_POSITION!=="0"&&i&&f(A,{isRequired:d}),n,D("span",{children:[i,window.SHOW_REQUIRED_POSITION==="0"&&i&&f(A,{isRequired:d})]}),f(pe,{name:l})]})):D(G,He(ze({className:`fieldWrapper ${o??""}`},s),{as:u,children:[D(G,{as:"span",children:[window.SHOW_REQUIRED_POSITION!=="0"&&i&&f(A,{isRequired:d}),i,!r&&i&&f("abbr",{className:"semicolon",children:": "}),window.SHOW_REQUIRED_POSITION==="0"&&i&&f(A,{isRequired:d})]}),n,f(pe,{name:l})]}))};var Ge=Object.getOwnPropertySymbols,zl=Object.prototype.hasOwnProperty,Hl=Object.prototype.propertyIsEnumerable,Gl=(e,a)=>{var l={};for(var i in e)zl.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&Ge)for(var i of Ge(e))a.indexOf(i)<0&&Hl.call(e,i)&&(l[i]=e[i]);return l};const Bl=({className:e,name:a,imageUrl:l,avoidRegisterIfExists:i,avoidSemicolon:r,formName:n,label:o,removeOnUnmount:u,submitName:t,submitValueParser:s,validationValueParser:m})=>{const d=_({name:a,avoidRegisterIfExists:i,formName:n,initialValue:"",removeOnUnmount:u,submitName:t,submitValueParser:s,validationValueParser:m,validationRules:{required:!0}}),{error:v,updateValidations:p,onChange:$,isTouched:x}=d,w=Gl(d,["error","updateValidations","onChange","isTouched"]),S=c.useCallback(h=>{$(h)},[$]),O=Q(a);return f(k,{name:a,label:o,className:`input ${e??""}`,avoidSemicolon:r,children:f(il,{name:a,imageUrl:l,onChange:S,value:w.value,className:O})})};var Ql=Object.defineProperty,Kl=Object.defineProperties,Xl=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ke=(e,a,l)=>a in e?Ql(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Xe=(e,a)=>{for(var l in a||(a={}))Be.call(a,l)&&Ke(e,l,a[l]);if(ee)for(var l of ee(a))Qe.call(a,l)&&Ke(e,l,a[l]);return e},Jl=(e,a)=>Kl(e,Xl(a)),Je=(e,a)=>{var l={};for(var i in e)Be.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ee)for(var i of ee(e))a.indexOf(i)<0&&Qe.call(e,i)&&(l[i]=e[i]);return l};const Ze=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,native:o,onChange:u,type:t,avoidRegisterIfExists:s,formName:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S,value:O}=l,h=Je(l,["avoidSemicolon","className","label","native","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),F,V;const{actualValidationFunction:g,actualValidationRules:E}=U({validationClass:x,validationFunction:w,validationRules:S}),P=_({avoidRegisterIfExists:s,formName:m,name:v,initialValue:(F=d===!0||d==="on")!=null?F:!1,removeOnUnmount:p,submitValueParser:$,validationFunction:g,validationRules:E}),{value:N,onChange:j,updateValidations:C,isTouched:b}=P,y=Je(P,["value","onChange","updateValidations","isTouched"]);return f(k,{name:v,label:n,className:`checkbox ${r??""}`,avoidSemicolon:i,children:f(rl,Jl(Xe(Xe({},h),y),{native:o,"aria-label":(V=h["aria-label"])!=null?V:n,onChange:T=>{j(T.target.checked),u&&u(T)},checked:N===!0||N==="on",ref:a}))})});Ze.displayName="Checkbox";var Zl=Object.defineProperty,Yl=Object.defineProperties,ei=Object.getOwnPropertyDescriptors,ae=Object.getOwnPropertySymbols,Ye=Object.prototype.hasOwnProperty,ea=Object.prototype.propertyIsEnumerable,aa=(e,a,l)=>a in e?Zl(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,la=(e,a)=>{for(var l in a||(a={}))Ye.call(a,l)&&aa(e,l,a[l]);if(ae)for(var l of ae(a))ea.call(a,l)&&aa(e,l,a[l]);return e},ai=(e,a)=>Yl(e,ei(a)),ia=(e,a)=>{var l={};for(var i in e)Ye.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ae)for(var i of ae(e))a.indexOf(i)<0&&ea.call(e,i)&&(l[i]=e[i]);return l};const ra=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,avoidRegisterIfExists:t,formName:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=ia(l,["avoidSemicolon","className","label","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g,E;const{name:P}=c.useContext(q),N=s??P,{actualValidationFunction:j,actualValidationRules:C}=U({validationClass:$,validationFunction:x,validationRules:w}),b=_({formName:N,name:d,initialValue:(V=(F=m??S)!=null?F:(h=R.getFieldStore(N,d))==null?void 0:h.value)!=null?V:"",removeOnUnmount:v,submitValueParser:p,validationFunction:j,validationRules:C}),{error:y,updateValidations:T,onChange:K,isTouched:Ka}=b,z=ia(b,["error","updateValidations","onChange","isTouched"]),he=c.useCallback(H=>{K(H),o?.(H)},[K,o]),L=Q(d);return D(k,{name:d,label:n,sx:c.useCallback(()=>({display:"flex",flexDirection:"column",alignItems:"start"}),[]),className:`deletableInput ${r??""}`,avoidSemicolon:i,children:[f(ve,ai(la(la({type:u},O),z),{"aria-label":(g=O["aria-label"])!=null?g:n,ref:a,onChange:he,value:(E=z.value)!=null?E:"",className:`deletableInput__input ${L??""}`})),f(nl,{icon:"Close",className:"deletableInput__deleteButton",onClick:()=>K("")})]})});ra.displayName="DeletableInput";var li=Object.defineProperty,ii=Object.defineProperties,ri=Object.getOwnPropertyDescriptors,le=Object.getOwnPropertySymbols,na=Object.prototype.hasOwnProperty,ta=Object.prototype.propertyIsEnumerable,oa=(e,a,l)=>a in e?li(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ni=(e,a)=>{for(var l in a||(a={}))na.call(a,l)&&oa(e,l,a[l]);if(le)for(var l of le(a))ta.call(a,l)&&oa(e,l,a[l]);return e},ti=(e,a)=>ii(e,ri(a)),oi=(e,a)=>{var l={};for(var i in e)na.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&le)for(var i of le(e))a.indexOf(i)<0&&ta.call(e,i)&&(l[i]=e[i]);return l};const si=e=>{var a=e,{avoidSemicolon:l,children:i,required:r}=a,n=oi(a,["avoidSemicolon","children","required"]);return D(Pe,ti(ni({},n),{children:[window.SHOW_REQUIRED_POSITION!=="0"&&f(A,{isRequired:r}),i,!l&&": ",window.SHOW_REQUIRED_POSITION==="0"&&f(A,{isRequired:r})]}))};var ui=Object.defineProperty,di=Object.defineProperties,mi=Object.getOwnPropertyDescriptors,ie=Object.getOwnPropertySymbols,sa=Object.prototype.hasOwnProperty,ua=Object.prototype.propertyIsEnumerable,da=(e,a,l)=>a in e?ui(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ma=(e,a)=>{for(var l in a||(a={}))sa.call(a,l)&&da(e,l,a[l]);if(ie)for(var l of ie(a))ua.call(a,l)&&da(e,l,a[l]);return e},ci=(e,a)=>di(e,mi(a)),ca=(e,a)=>{var l={};for(var i in e)sa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ie)for(var i of ie(e))a.indexOf(i)<0&&ua.call(e,i)&&(l[i]=e[i]);return l};const va=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,avoidRegisterIfExists:o,formName:u,initialValue:t,name:s,removeOnUnmount:m,submitValueParser:d,validationClass:v,validationFunction:p,validationRules:$}=l,x=ca(l,["avoidSemicolon","className","label","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules"]),w;const{name:S}=M(),{actualValidationFunction:O,actualValidationRules:h}=U({customValidation(C){return C!=null?!0:I("required")},validationClass:v,validationFunction:p,validationRules:$}),F=_({formName:S,name:s,removeOnUnmount:m,submitValueParser:d,validationFunction:O,validationRules:h}),{error:V,onChange:g,value:E,updateValidations:P,isTouched:N}=F,j=ca(F,["error","onChange","value","updateValidations","isTouched"]);return f(k,{name:s,label:n,className:`input ${r??""}`,avoidSemicolon:i,children:f(ve,ci(ma(ma({},x),j),{type:"file","aria-label":(w=x["aria-label"])!=null?w:n,ref:a,sx:tl(!V),onChange:c.useCallback(C=>{var b,y,T;g((T=(y=(b=C.target)==null?void 0:b.files)==null?void 0:y[0])!=null?T:null)},[g])}))})}));va.displayName="FileInput";var vi=Object.defineProperty,fi=Object.defineProperties,pi=Object.getOwnPropertyDescriptors,re=Object.getOwnPropertySymbols,fa=Object.prototype.hasOwnProperty,pa=Object.prototype.propertyIsEnumerable,ba=(e,a,l)=>a in e?vi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,ne=(e,a)=>{for(var l in a||(a={}))fa.call(a,l)&&ba(e,l,a[l]);if(re)for(var l of re(a))pa.call(a,l)&&ba(e,l,a[l]);return e},ha=(e,a)=>fi(e,pi(a)),ga=(e,a)=>{var l={};for(var i in e)fa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&re)for(var i of re(e))a.indexOf(i)<0&&pa.call(e,i)&&(l[i]=e[i]);return l};const Oa=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,avoidRegisterIfExists:t,formName:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=ga(l,["avoidSemicolon","className","label","onChange","type","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g,E,P,N;const{name:j}=c.useContext(q),C=s??j,{actualValidationFunction:b,actualValidationRules:y}=U({validationClass:$,validationFunction:x,validationRules:w}),T=_({formName:C,name:d,initialValue:(V=(F=m??S)!=null?F:(h=R.getFieldStore(C,d))==null?void 0:h.value)!=null?V:"",removeOnUnmount:v,submitValueParser:p,validationFunction:b,validationRules:y}),{error:K,updateValidations:Ka,onChange:z,isTouched:he}=T,L=ga(T,["error","updateValidations","onChange","isTouched"]),H=c.useCallback(me=>{z(me),typeof me=="string"?o?.({target:a}):o?.(me)},[z,o,a]),ge=Q(d);return f(k,{name:d,label:n,className:`input ${r??""}`,avoidSemicolon:i,children:u==="date"?f(ol,ha(ne(ne({},O),L),{"aria-label":(g=O["aria-label"])!=null?g:n,onError:void 0,ref:a,onChange:H,value:(E=L.value)!=null?E:"",className:ge})):f(ve,ha(ne(ne({type:u},O),L),{"aria-label":(P=O["aria-label"])!=null?P:n,ref:a,onChange:H,value:(N=L.value)!=null?N:"",className:ge}))})}));Oa.displayName="Input";var bi=Object.defineProperty,hi=Object.defineProperties,gi=Object.getOwnPropertyDescriptors,te=Object.getOwnPropertySymbols,Fa=Object.prototype.hasOwnProperty,ya=Object.prototype.propertyIsEnumerable,xa=(e,a,l)=>a in e?bi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Va=(e,a)=>{for(var l in a||(a={}))Fa.call(a,l)&&xa(e,l,a[l]);if(te)for(var l of te(a))ya.call(a,l)&&xa(e,l,a[l]);return e},$a=(e,a)=>hi(e,gi(a)),Oi=(e,a)=>{var l={};for(var i in e)Fa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&te)for(var i of te(e))a.indexOf(i)<0&&ya.call(e,i)&&(l[i]=e[i]);return l};const Pa=c.memo(c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,avoidRegisterIfExists:u,formName:t,initialValue:s,name:m,removeOnUnmount:d,submitValueParser:v,validationClass:p,validationFunction:$,validationRules:x,value:w}=l,S=Oi(l,["avoidSemicolon","className","label","onChange","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),O,h,F;const{name:V}=c.useContext(q),g=t??V,{actualValidationFunction:E,actualValidationRules:P}=U({validationClass:p,validationFunction:$,validationRules:x}),{onChange:N,value:j}=_({formName:g,name:m,initialValue:(F=(h=s??w)!=null?h:(O=R.getFieldStore(g,m))==null?void 0:O.value)!=null?F:"",removeOnUnmount:d,submitValueParser:c.useCallback(y=>$e(y??""),[]),validationValueParser:c.useCallback(y=>$e(y??""),[]),validationFunction:E,validationRules:P}),C=c.useCallback(y=>{y.error?(o?.($a(Va({},y),{value:""})),N(""),R.updateField(g,{name:m,error:Za(window.GNR_NUMERIC,{TOK:""})})):(N(y.value),o?.(y),R.updateField(g,{name:m,error:null}))},[g,m,N,o]),b=Q(m);return f(k,{name:m,label:n,sx:c.useMemo(()=>({display:"flex",flexDirection:"column",alignItems:"start"}),[]),className:`input ${r??""}`,avoidSemicolon:i,children:f(sl,$a(Va({ref:a},S),{name:m,value:j,onChange:C,className:b}))})}));Pa.displayName="NumberInputf";var Fi=Object.defineProperty,yi=Object.defineProperties,xi=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertySymbols,wa=Object.prototype.hasOwnProperty,Sa=Object.prototype.propertyIsEnumerable,Na=(e,a,l)=>a in e?Fi(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ra=(e,a)=>{for(var l in a||(a={}))wa.call(a,l)&&Na(e,l,a[l]);if(oe)for(var l of oe(a))Sa.call(a,l)&&Na(e,l,a[l]);return e},Vi=(e,a)=>yi(e,xi(a)),Ca=(e,a)=>{var l={};for(var i in e)wa.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&oe)for(var i of oe(e))a.indexOf(i)<0&&Sa.call(e,i)&&(l[i]=e[i]);return l};const Ia=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,options:t,value:s,avoidRegisterIfExists:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S}=l,O=Ca(l,["avoidSemicolon","className","formName","label","onChange","options","value","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules"]);const{actualValidationFunction:h,actualValidationRules:F}=U({validationClass:x,validationFunction:w,validationRules:S}),V=_({formName:n,name:v,initialValue:d??s,removeOnUnmount:p,submitValueParser:$,validationFunction:h,validationRules:F}),{value:g,updateValidations:E,onChange:P,isTouched:N}=V,j=Ca(V,["value","updateValidations","onChange","isTouched"]),C=c.useCallback(b=>{P(b),u&&u(b)},[P,u]);return f(k,{name:v,label:o,className:`radio ${r??""}`,avoidSemicolon:i,as:"ul",children:t?.map(b=>f("li",{children:D(Pe,{title:b.label,className:"radio-label",children:[f(ul,Vi(Ra(Ra({},O),j),{role:"radio",className:"radio-button","aria-label":b.label,ref:a,value:b.value,checked:g===b.value,onChange:C})),f(G,{as:"span",className:"radio-text",children:b.label})]})},b.value))})});Ia.displayName="Radio";var $i=Object.defineProperty,Pi=Object.defineProperties,wi=Object.getOwnPropertyDescriptors,se=Object.getOwnPropertySymbols,Ea=Object.prototype.hasOwnProperty,ja=Object.prototype.propertyIsEnumerable,Ta=(e,a,l)=>a in e?$i(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,be=(e,a)=>{for(var l in a||(a={}))Ea.call(a,l)&&Ta(e,l,a[l]);if(se)for(var l of se(a))ja.call(a,l)&&Ta(e,l,a[l]);return e},Si=(e,a)=>Pi(e,wi(a)),_a=(e,a)=>{var l={};for(var i in e)Ea.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&se)for(var i of se(e))a.indexOf(i)<0&&ja.call(e,i)&&(l[i]=e[i]);return l};const ka=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,options:t,avoidRegisterIfExists:s,initialValue:m,name:d,removeOnUnmount:v,submitValueParser:p,validationClass:$,validationFunction:x,validationRules:w,value:S}=l,O=_a(l,["avoidSemicolon","className","formName","label","onChange","options","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),h,F,V,g;const{actualValidationFunction:E,actualValidationRules:P}=U({validationClass:$,validationFunction:x,validationRules:w}),N=_({avoidRegisterIfExists:s,initialValue:(F=m??S)!=null?F:(h=t[0])==null?void 0:h.value,name:d,removeOnUnmount:v,submitValueParser:p,validationFunction:E,validationRules:P}),{updateValidations:j,onChange:C,isTouched:b}=N,y=_a(N,["updateValidations","onChange","isTouched"]);return f(k,{name:d,label:o,className:`select ${r??""}`,avoidSemicolon:i,children:D(dl,Si(be(be(be({},ll("forms.select")),O),y),{onChange:c.useCallback(T=>{C(T),u&&u(T)},[C,u]),"aria-label":(V=O["aria-label"])!=null?V:o,ref:a,value:(g=y.value)!=null?g:"",children:[t?.map(T=>f("option",{value:T.value,children:T.label},T.value)),O.children]}))})});ka.displayName="Select";var Ni=Object.defineProperty,Ri=Object.defineProperties,Ci=Object.getOwnPropertyDescriptors,ue=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Da=Object.prototype.propertyIsEnumerable,La=(e,a,l)=>a in e?Ni(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Wa=(e,a)=>{for(var l in a||(a={}))Ua.call(a,l)&&La(e,l,a[l]);if(ue)for(var l of ue(a))Da.call(a,l)&&La(e,l,a[l]);return e},Ii=(e,a)=>Ri(e,Ci(a)),qa=(e,a)=>{var l={};for(var i in e)Ua.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&ue)for(var i of ue(e))a.indexOf(i)<0&&Da.call(e,i)&&(l[i]=e[i]);return l};const Aa=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,label:n,onChange:o,type:u,reverse:t=!1,avoidRegisterIfExists:s,formName:m,initialValue:d,name:v,removeOnUnmount:p,submitValueParser:$,validationClass:x,validationFunction:w,validationRules:S,value:O}=l,h=qa(l,["avoidSemicolon","className","label","onChange","type","reverse","avoidRegisterIfExists","formName","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),F,V;const{actualValidationFunction:g,actualValidationRules:E}=U({validationClass:x,validationFunction:w,validationRules:S}),P=_({avoidRegisterIfExists:s,formName:m,name:v,initialValue:(d??"off")==="on"||Ya(d)?"on":"off",removeOnUnmount:p,submitValueParser:$,validationFunction:g,validationRules:E}),{onChange:N,updateValidations:j,isTouched:C}=P,b=qa(P,["onChange","updateValidations","isTouched"]);return f(k,{name:v,label:n,className:`switchbox ${r??""}`,avoidSemicolon:i,children:f(ml,Ii(Wa(Wa({},h),b),{"aria-label":(F=h["aria-label"])!=null?F:n,onChange:y=>{N(y.target.checked!==t?"on":"off"),o&&o(y)},checked:((V=b.value)!=null?V:"off")==="on"!==t,ref:a}))})});Aa.displayName="Switchbox";var Ei=Object.defineProperty,ji=Object.defineProperties,Ti=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertySymbols,Ma=Object.prototype.hasOwnProperty,za=Object.prototype.propertyIsEnumerable,Ha=(e,a,l)=>a in e?Ei(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,Ga=(e,a)=>{for(var l in a||(a={}))Ma.call(a,l)&&Ha(e,l,a[l]);if(de)for(var l of de(a))za.call(a,l)&&Ha(e,l,a[l]);return e},_i=(e,a)=>ji(e,Ti(a)),Ba=(e,a)=>{var l={};for(var i in e)Ma.call(e,i)&&a.indexOf(i)<0&&(l[i]=e[i]);if(e!=null&&de)for(var i of de(e))a.indexOf(i)<0&&za.call(e,i)&&(l[i]=e[i]);return l};const Qa=c.forwardRef((e,a)=>{var l=e,{avoidSemicolon:i,className:r,formName:n,label:o,onChange:u,avoidRegisterIfExists:t,initialValue:s,name:m,removeOnUnmount:d,submitValueParser:v,validationClass:p,validationFunction:$,validationRules:x,value:w}=l,S=Ba(l,["avoidSemicolon","className","formName","label","onChange","avoidRegisterIfExists","initialValue","name","removeOnUnmount","submitValueParser","validationClass","validationFunction","validationRules","value"]),O,h;const{actualValidationFunction:F,actualValidationRules:V}=U({validationClass:p,validationFunction:$,validationRules:x}),g=_({avoidRegisterIfExists:t,formName:n,initialValue:s??w,name:m,removeOnUnmount:d,submitValueParser:v,validationRules:V,validationFunction:F}),{updateValidations:E,onChange:P,isTouched:N}=g,j=Ba(g,["updateValidations","onChange","isTouched"]),C=c.useCallback(b=>{P(b),u&&u(b)},[P,u]);return f(k,{name:m,label:o,className:`textarea ${r??""}`,avoidSemicolon:i,children:f(cl,_i(Ga(Ga({},S),j),{"aria-label":(O=S["aria-label"])!=null?O:o,ref:a,value:(h=j.value)!=null?h:"",onChange:C}))})});Qa.displayName="Textarea";export{Bl as Captcha,Ze as Checkbox,ra as DeletableInput,si as FieldLabel,k as FieldWrapper,va as FileInput,El as Form,q as FormContext,Oa as Input,Pa as NumberInputf,Ia as Radio,ka as Select,Aa as Switchbox,Qa as Textarea,pe as ValidationError,Ce as classToValidate,Re as classToValidationFunction,Ne as hasSucceedFieldValidation,Ol as hasSucceedFormValidation,yl as initValidations,_ as useField,B as useFieldSelector,Q as useFieldStatesClassNames,kl as useFieldValue,M as useFormContext,Te as useFormSelector,U as useValidationClass,R as validationsStore};
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { customEvents, propsStore, usePropsSelector, useUpdateEffect, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, toBoolean } from '@apia/util';
3
+ import { uniqueId } from 'lodash';
4
+ import React from 'react';
5
+ import { shallowEqual } from 'react-redux';
6
+ import { injectStyles, Box, getVariant, Input as Input$1, Label, Radio as Radio$1, Select as Select$1, Switch, Textarea as Textarea$1 } from '@apia/theme';
7
+ import { notify } from '@apia/notifications';
8
+ import { RequiredMark, Captcha, Checkbox as Checkbox$1, IconButton, getFieldErrorStyles, DateInput, parseNumberInputValueToNumber, NumberInput } from '@apia/components';
9
+
10
+ const FormContext = React.createContext(
11
+ {}
12
+ );
13
+ function useFormContext() {
14
+ const formContext = React.useContext(FormContext);
15
+ if (!formContext)
16
+ throw new Error("There is no FormContext");
17
+ return formContext;
18
+ }
19
+
20
+ function validateByRules({
21
+ rules,
22
+ value
23
+ }) {
24
+ const validationResult = getValidations(rules).validate(value);
25
+ return validationResult;
26
+ }
27
+
28
+ var __defProp$e = Object.defineProperty;
29
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
30
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
31
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
32
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
33
+ var __spreadValues$e = (a, b) => {
34
+ for (var prop in b || (b = {}))
35
+ if (__hasOwnProp$f.call(b, prop))
36
+ __defNormalProp$e(a, prop, b[prop]);
37
+ if (__getOwnPropSymbols$f)
38
+ for (var prop of __getOwnPropSymbols$f(b)) {
39
+ if (__propIsEnum$f.call(b, prop))
40
+ __defNormalProp$e(a, prop, b[prop]);
41
+ }
42
+ return a;
43
+ };
44
+ var __async$2 = (__this, __arguments, generator) => {
45
+ return new Promise((resolve, reject) => {
46
+ var fulfilled = (value) => {
47
+ try {
48
+ step(generator.next(value));
49
+ } catch (e) {
50
+ reject(e);
51
+ }
52
+ };
53
+ var rejected = (value) => {
54
+ try {
55
+ step(generator.throw(value));
56
+ } catch (e) {
57
+ reject(e);
58
+ }
59
+ };
60
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
61
+ step((generator = generator.apply(__this, __arguments)).next());
62
+ });
63
+ };
64
+ function validateField(field, formName) {
65
+ return __async$2(this, null, function* () {
66
+ let validationResult = null;
67
+ const fieldValue = field.validationValueParser ? field.validationValueParser(field.value) : field.value;
68
+ if (field.validationFunction) {
69
+ validationResult = yield field.validationFunction(fieldValue, formName);
70
+ }
71
+ if ((!field.validationFunction || validationResult === true) && field.validationRules) {
72
+ validationResult = validateByRules({
73
+ rules: field.validationRules,
74
+ value: fieldValue
75
+ });
76
+ } else if (validationResult === null)
77
+ validationResult = true;
78
+ return validationResult;
79
+ });
80
+ }
81
+ function hasSucceedFieldValidation(result) {
82
+ return result === true;
83
+ }
84
+ function hasSucceedFormValidation(result) {
85
+ return !("errors" in result);
86
+ }
87
+ function focusOnField(formName, field) {
88
+ return __async$2(this, null, function* () {
89
+ const formElement = document.getElementById(
90
+ `ValidationForm-${formName}`
91
+ );
92
+ const fieldElement = formElement == null ? void 0 : formElement.querySelector(
93
+ `[name="${field.name}"], #${field.name}`
94
+ );
95
+ if (fieldElement) {
96
+ return new Promise((resolve) => {
97
+ const event = new CustomEvent(customEvents.focus, { bubbles: true });
98
+ fieldElement.focus();
99
+ fieldElement.dispatchEvent(event);
100
+ fieldElement.scrollIntoView({
101
+ block: "center",
102
+ behavior: "auto"
103
+ });
104
+ resolve(true);
105
+ });
106
+ }
107
+ return false;
108
+ });
109
+ }
110
+ let langDefinition;
111
+ function lang(errorCode, ...replacements) {
112
+ if (!langDefinition[errorCode])
113
+ return "";
114
+ let returnString = langDefinition[errorCode];
115
+ replacements.forEach((replace, index) => {
116
+ returnString = returnString.replace(`%${index}`, replace.toString());
117
+ });
118
+ return returnString;
119
+ }
120
+ function classToValidationFunction(className) {
121
+ const match = className == null ? void 0 : className.match(/'confirm:(\w+):(.+?)']/);
122
+ if (match) {
123
+ const validationFunction = (value, formName) => {
124
+ var _a, _b;
125
+ return value === ((_a = validationsStore.getFieldStore(formName, match[1])) == null ? void 0 : _a.value) ? true : lang("confirm", (_b = match[2]) != null ? _b : match[1]);
126
+ };
127
+ return validationFunction;
128
+ }
129
+ return void 0;
130
+ }
131
+ function classToValidate(className) {
132
+ const validations = {};
133
+ if (className) {
134
+ const match = className.match(/validate\[([^\]]+)\]/);
135
+ if (match) {
136
+ const definitions = match[1].replaceAll("~", "").split(",");
137
+ definitions.forEach((definition) => {
138
+ const definitionMatch = definition.match(/(\w+)(?:=([\w\d]+))?/);
139
+ if (definitionMatch) {
140
+ const prop = definitionMatch[1];
141
+ if (prop === "pattern" && definitionMatch[2])
142
+ validations[prop] = new RegExp(definitionMatch[2]);
143
+ else if (definitionMatch[2]) {
144
+ const value = definitionMatch[2].split(",");
145
+ const actualValue = value.length < 2 ? value.join() : value;
146
+ validations[prop] = actualValue;
147
+ } else
148
+ validations[prop] = true;
149
+ }
150
+ });
151
+ return validations;
152
+ }
153
+ }
154
+ return {};
155
+ }
156
+ function initValidations() {
157
+ return __async$2(this, null, function* () {
158
+ var _a;
159
+ if (langDefinition)
160
+ return;
161
+ const code = (_a = document.documentElement.lang) != null ? _a : "es";
162
+ langDefinition = (yield import(
163
+ /* webpackChunkName: "val-lang-[request]" */
164
+ `../lang/${code}.ts`
165
+ ).catch((error) => {
166
+ notify({
167
+ type: "danger",
168
+ message: window.NO_LANGUAGE_EXCEPTION
169
+ });
170
+ throw error;
171
+ })).default;
172
+ });
173
+ }
174
+ function getValidations(outerValidation) {
175
+ const validation = __spreadValues$e({}, outerValidation);
176
+ if (!validation)
177
+ return {
178
+ validate: () => {
179
+ return true;
180
+ }
181
+ };
182
+ return {
183
+ validate: (outerV) => {
184
+ var _a;
185
+ const v = outerV != null ? outerV : "";
186
+ let returnValue = true;
187
+ if (returnValue && validation.pattern) {
188
+ let actualRegexp;
189
+ if (!(validation.pattern instanceof RegExp)) {
190
+ const patternResult = validation.pattern.match(
191
+ /(?:^\/(.+)\/(\w+)?$)|(^.*$)/
192
+ );
193
+ const regexp = patternResult[1];
194
+ const flags = patternResult[2];
195
+ const stringPattern = patternResult[3];
196
+ actualRegexp = new RegExp(
197
+ regexp || stringPattern,
198
+ flags || void 0
199
+ );
200
+ } else
201
+ actualRegexp = validation.pattern;
202
+ returnValue = !!outerV.match(actualRegexp) || ((_a = validation.patternMessage) != null ? _a : window.MSG_INVALID_REG_EXP);
203
+ }
204
+ if (returnValue === true && validation.maxLength)
205
+ returnValue = v.length <= validation.maxLength || lang("lengthmax", validation.maxLength);
206
+ if (returnValue === true && validation.minLength)
207
+ returnValue = v.length >= validation.minLength || lang("lengthmin", validation.minLength);
208
+ if (returnValue === true && validation.max && validation.min)
209
+ returnValue = Number(v) <= validation.max && Number(v) >= validation.min || lang("digitltd", validation.min, validation.max);
210
+ if (returnValue === true && validation.min)
211
+ returnValue = Number(v) >= validation.min || lang("digitmin", validation.min);
212
+ if (returnValue === true && validation.max)
213
+ returnValue = Number(v) <= validation.max || lang("digitltd", 0, validation.max);
214
+ if (returnValue === true && validation.validName)
215
+ returnValue = !!v.match(/^[a-zA-Z0-9_.]*$/) || window.GNR_INVALID_NAME;
216
+ if (returnValue === true && (validation.alpha || validation.nodigit))
217
+ returnValue = !!v.match(/^[a-zA-Z]*$/) || lang("alpha");
218
+ if (returnValue === true && validation.alphanum)
219
+ returnValue = !!v.match(/^[a-zA-Z0-9]*$/) || lang("alphanum");
220
+ if (returnValue === true && (validation.digit || validation.number))
221
+ returnValue = !!v.match(/^[0-9]*$/) || lang("digit");
222
+ if (returnValue === true && validation.email)
223
+ returnValue = !!v.match(
224
+ // eslint-disable-next-line no-control-regex
225
+ /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/
226
+ ) || lang("email");
227
+ if (returnValue === true && validation.differs)
228
+ returnValue = v !== validation.differs || lang("differs", validation.differs);
229
+ if (returnValue === true && validation.length_str)
230
+ returnValue = v.length >= validation.length_str[0] && v.length <= validation.length_str[1] || lang("length_str", ...validation.length_str);
231
+ if (returnValue === true && validation.length_fix)
232
+ returnValue = v.length === validation.length_fix || lang("length_fix", validation.length_fix);
233
+ if (returnValue === true && validation.words_min) {
234
+ const words = v.split(" ").length;
235
+ return words >= validation.words_min || lang("words_min", validation.words_min);
236
+ }
237
+ if (returnValue === true && validation.words_max) {
238
+ const words = v.split(" ").length;
239
+ return words <= validation.words_max || lang("words_max", validation.words_max);
240
+ }
241
+ if (returnValue === true && validation.words_range) {
242
+ const words = v.split(" ").length;
243
+ return words <= validation.words_range[0] && words >= validation.words_range[1] || lang("words_range", ...validation.words_range);
244
+ }
245
+ if (returnValue === true && validation.required)
246
+ returnValue = Array.isArray(outerV) && outerV.length > 0 || typeof outerV === "number" || !Array.isArray(v) && !!v || lang("required");
247
+ return returnValue;
248
+ }
249
+ };
250
+ }
251
+
252
+ var __defProp$d = Object.defineProperty;
253
+ var __defProps$b = Object.defineProperties;
254
+ var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
255
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
256
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
257
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
258
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
259
+ var __spreadValues$d = (a, b) => {
260
+ for (var prop in b || (b = {}))
261
+ if (__hasOwnProp$e.call(b, prop))
262
+ __defNormalProp$d(a, prop, b[prop]);
263
+ if (__getOwnPropSymbols$e)
264
+ for (var prop of __getOwnPropSymbols$e(b)) {
265
+ if (__propIsEnum$e.call(b, prop))
266
+ __defNormalProp$d(a, prop, b[prop]);
267
+ }
268
+ return a;
269
+ };
270
+ var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
271
+ var __objRest$b = (source, exclude) => {
272
+ var target = {};
273
+ for (var prop in source)
274
+ if (__hasOwnProp$e.call(source, prop) && exclude.indexOf(prop) < 0)
275
+ target[prop] = source[prop];
276
+ if (source != null && __getOwnPropSymbols$e)
277
+ for (var prop of __getOwnPropSymbols$e(source)) {
278
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$e.call(source, prop))
279
+ target[prop] = source[prop];
280
+ }
281
+ return target;
282
+ };
283
+ var __async$1 = (__this, __arguments, generator) => {
284
+ return new Promise((resolve, reject) => {
285
+ var fulfilled = (value) => {
286
+ try {
287
+ step(generator.next(value));
288
+ } catch (e) {
289
+ reject(e);
290
+ }
291
+ };
292
+ var rejected = (value) => {
293
+ try {
294
+ step(generator.throw(value));
295
+ } catch (e) {
296
+ reject(e);
297
+ }
298
+ };
299
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
300
+ step((generator = generator.apply(__this, __arguments)).next());
301
+ });
302
+ };
303
+ const validationsStore = new class {
304
+ constructor() {
305
+ this.activeForms = [];
306
+ this.timeouts = {};
307
+ this.existsField = (formName, fieldName) => {
308
+ var _a, _b;
309
+ return !!((_b = (_a = this.getFormStore(formName)) == null ? void 0 : _a.fields) == null ? void 0 : _b.includes(fieldName));
310
+ };
311
+ this.registerField = (formName, registerData, options = { registerIfExists: true }) => {
312
+ var _a, _b, _c;
313
+ const formProps = this.getFormStore(formName);
314
+ if (formProps === void 0)
315
+ this.registerForm(formName);
316
+ if (!((_a = this.getFormStore(formName)) == null ? void 0 : _a.fields.includes(registerData.name)))
317
+ this.updateFormStore(formName, {
318
+ fields: [
319
+ ...(_c = (_b = this.getFormStore(formName)) == null ? void 0 : _b.fields) != null ? _c : [],
320
+ registerData.name
321
+ ]
322
+ });
323
+ const existsInStore = this.getFieldStore(formName, registerData.name);
324
+ if (((formProps == null ? void 0 : formProps.avoidFieldsOverride) || !options.registerIfExists) && existsInStore) {
325
+ const _d = registerData, updateData = __objRest$b(_d, ["value"]);
326
+ this.updateField(formName, updateData, {
327
+ markFormAsTouched: false,
328
+ avoidPropagation: options.avoidPropagation
329
+ });
330
+ return;
331
+ }
332
+ this.updateFieldStore(
333
+ formName,
334
+ registerData.name,
335
+ registerData,
336
+ options.avoidPropagation
337
+ );
338
+ };
339
+ /**
340
+ * Inicializa el estado de un nuevo formulario
341
+ */
342
+ this.registerForm = (formName, props = { avoidFieldsOverride: false }) => {
343
+ var _a;
344
+ if (this.activeForms.includes(formName)) {
345
+ this.updateFormStore(formName, {
346
+ avoidFieldsOverride: props.avoidFieldsOverride
347
+ });
348
+ if (props.initialValues)
349
+ Object.entries(props.initialValues).forEach(([fieldId, fieldProps]) => {
350
+ if (fieldProps instanceof Object)
351
+ this.updateField(formName, __spreadValues$d({ name: fieldId }, fieldProps));
352
+ });
353
+ return;
354
+ }
355
+ this.activeForms.push(formName);
356
+ this.updateFormStore(formName, {
357
+ avoidFieldsOverride: props.avoidFieldsOverride,
358
+ fields: [],
359
+ isTouched: false,
360
+ isValid: false,
361
+ name: formName,
362
+ validationResult: null
363
+ });
364
+ Object.entries((_a = props.initialValues) != null ? _a : {}).forEach(([name, value]) => {
365
+ this.updateField(formName, { name, value }, { markFormAsTouched: false });
366
+ });
367
+ };
368
+ /**
369
+ * Setea el valor del campo con el nombre provisto. Si el campo no existe
370
+ * en el formulario lo crea.
371
+ */
372
+ this.setFieldValue = (formName, fieldName, newValue, options) => {
373
+ if (!this.getFieldStore(formName, fieldName))
374
+ this.registerField(formName, { name: fieldName, value: newValue });
375
+ else
376
+ this.updateField(
377
+ formName,
378
+ {
379
+ name: fieldName,
380
+ value: newValue,
381
+ error: null
382
+ },
383
+ options
384
+ );
385
+ if (this.getFormStore(formName).isValid)
386
+ this.updateFormStore(formName, { isValid: false });
387
+ };
388
+ this.setFormIsTouched = (formName, isTouched = true) => {
389
+ this.updateFormStore(formName, { isTouched });
390
+ };
391
+ /**
392
+ * Elimina un campo del registro de validación de un formulario. De esta
393
+ * forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
394
+ * aplicará.
395
+ */
396
+ this.unregisterField = (formName, fieldName) => {
397
+ if (this.getFormStore(formName))
398
+ this.updateFormStore(formName, {
399
+ fields: this.getFormStore(formName).fields.filter((current) => {
400
+ return current !== fieldName;
401
+ })
402
+ });
403
+ propsStore.removeField(this.makeFieldName(formName, fieldName));
404
+ };
405
+ /**
406
+ * Elimina un formulario del store de validación junto con todos los campos
407
+ * asociados al mismo.
408
+ */
409
+ this.unregisterForm = (formName) => {
410
+ var _a, _b;
411
+ (_b = (_a = this.getFormStore(formName)) == null ? void 0 : _a.fields) == null ? void 0 : _b.forEach((current) => {
412
+ return propsStore.removeField(this.makeFieldName(formName, current));
413
+ });
414
+ this.activeForms = this.activeForms.filter((current) => {
415
+ return current !== formName;
416
+ });
417
+ propsStore.removeField(this.makeFormName(formName));
418
+ delete this.timeouts[formName];
419
+ };
420
+ /**
421
+ * Actualiza las propiedades de un campo, si no existe, lo registra en el
422
+ * formulario.
423
+ */
424
+ this.updateField = (formName, field, options) => {
425
+ var _a, _b;
426
+ const previousValue = (_a = this.getFieldStore(formName, field.name)) == null ? void 0 : _a.value;
427
+ if (this.getFormStore(formName))
428
+ this.updateFormStore(formName, { isValid: false });
429
+ else
430
+ this.registerForm(formName);
431
+ const isTouched = field.value !== void 0 && field.value !== previousValue && (options == null ? void 0 : options.markFormAsTouched) !== false;
432
+ if (!this.existsField(formName, field.name))
433
+ this.registerField(formName, field, {
434
+ avoidPropagation: options == null ? void 0 : options.avoidPropagation
435
+ });
436
+ this.updateFieldStore(
437
+ formName,
438
+ field.name,
439
+ __spreadProps$b(__spreadValues$d({}, field), {
440
+ isTouched: isTouched || ((_b = this.getFieldStore(formName, field.name)) == null ? void 0 : _b.isTouched)
441
+ }),
442
+ options == null ? void 0 : options.avoidPropagation
443
+ );
444
+ if (isTouched)
445
+ this.setFormIsTouched(formName);
446
+ };
447
+ /**
448
+ * Actualiza múltiples campos al mismo tiempo.
449
+ */
450
+ this.updateMultipleFields = (formName, fields, options) => {
451
+ fields.forEach((current) => {
452
+ return this.updateField(formName, current, options);
453
+ });
454
+ };
455
+ /**
456
+ * Ejecuta la validación sobre un formulario. En caso de que la validación
457
+ * falle, se intenta hacer foco sobre el campo que no pudo validar.
458
+ * Es importante notar que en caso de que un campo requiera validación,
459
+ * debería estar presente en el DOM.
460
+ *
461
+ * No es necesario que el campo esté visible, ya que en caso de estar oculto
462
+ * (por ejemplo por ser hijo de un acordeón), se emitirá un evento para
463
+ * expandir al elemento padre que lo estuviera ocultando.
464
+ *
465
+ * @returns Devuelve una promesa que al ser resuelta otorga un objeto de tipo
466
+ * TValidationResult. Este tipo está pensado para ser usado en conjunto con
467
+ * el método hasSucceedFormValidation, que determinará si la validación fue
468
+ * exitosa o hubo errores.
469
+ *
470
+ * @example
471
+ *
472
+ * const result = await validationStore.validateForm('myForm');
473
+ * if(hasSucceedValidation(result)) {
474
+ * console.log('Success!', result);
475
+ * } else {
476
+ * console.error('Validation error', result);
477
+ * }
478
+ */
479
+ this.validateForm = (formName) => __async$1(this, null, function* () {
480
+ var _a;
481
+ const state = this.getFormStore(formName);
482
+ const fields = state.fields.map((current) => {
483
+ return this.getFieldStore(formName, current);
484
+ });
485
+ const validationErrors = { errors: {} };
486
+ const validationValues = {
487
+ submitValues: {},
488
+ values: {}
489
+ };
490
+ let hasFiredFocus = false;
491
+ let existsErrors = false;
492
+ const fieldsWithError = {};
493
+ for (const field of fields.filter((current) => {
494
+ return current !== void 0;
495
+ })) {
496
+ const validationResult = yield validateField(field, formName);
497
+ fieldsWithError[field.name] = validationResult;
498
+ if (hasSucceedFieldValidation(validationResult)) {
499
+ validationValues.submitValues[(_a = field.submitName) != null ? _a : field.name] = field.submitValueParser ? field.submitValueParser(field.value) : field.value;
500
+ validationValues.values[field.name] = field.value;
501
+ } else {
502
+ this.updateField(formName, {
503
+ name: field.name,
504
+ error: validationResult
505
+ });
506
+ if (!hasFiredFocus) {
507
+ if (yield focusOnField(formName, field))
508
+ hasFiredFocus = true;
509
+ }
510
+ existsErrors = true;
511
+ validationErrors.errors[field.name] = validationResult;
512
+ }
513
+ }
514
+ if (existsErrors) {
515
+ if (!hasFiredFocus) {
516
+ notify({
517
+ message: window.MSG_WRONG_VALIDATION_NO_FOCUSED_FILE,
518
+ type: "danger"
519
+ });
520
+ console.error("Campos que fallaron la validaci\xF3n", fieldsWithError);
521
+ }
522
+ this.updateFormStore(formName, {
523
+ isValid: false,
524
+ validationResult: validationErrors
525
+ });
526
+ return validationErrors;
527
+ }
528
+ this.updateFormStore(formName, {
529
+ isValid: true,
530
+ validationResult: validationValues
531
+ });
532
+ return validationValues;
533
+ });
534
+ }
535
+ getFieldStore(formName, fieldName) {
536
+ return propsStore.getFieldProps(
537
+ this.makeFieldName(formName, fieldName)
538
+ );
539
+ }
540
+ getFormStore(formName) {
541
+ return propsStore.getFieldProps(this.makeFormName(formName));
542
+ }
543
+ updateFieldStore(formName, fieldName, props, noEmit) {
544
+ propsStore.updateField(
545
+ this.makeFieldName(formName, fieldName),
546
+ __spreadValues$d(__spreadValues$d({}, this.getFieldStore(formName, fieldName)), props),
547
+ { noEmit }
548
+ );
549
+ }
550
+ updateFormStore(formName, newState) {
551
+ propsStore.updateField(this.makeFormName(formName), newState);
552
+ }
553
+ enableFormTouch(formName) {
554
+ this.timeouts[formName] = true;
555
+ }
556
+ makeFieldName(formName, fieldName) {
557
+ return `validation_${formName}_${fieldName}`;
558
+ }
559
+ makeFormName(formName) {
560
+ return `validation_${formName}`;
561
+ }
562
+ }();
563
+ function useFormSelector(formName, selector, comparator) {
564
+ return usePropsSelector(
565
+ validationsStore.makeFormName(formName),
566
+ selector,
567
+ comparator
568
+ );
569
+ }
570
+ function useFieldSelector(formName, fieldName, confOrSelector, comparator) {
571
+ const fieldId = validationsStore.makeFieldName(formName, fieldName);
572
+ return usePropsSelector(fieldId, confOrSelector, comparator);
573
+ }
574
+
575
+ const formStyles = {
576
+ ".fieldWrapper": {
577
+ display: "flex",
578
+ flexDirection: "column",
579
+ alignItems: "stretch",
580
+ "&.checkbox": {
581
+ alignItems: "center"
582
+ }
583
+ },
584
+ ".error": {
585
+ borderLeftStyle: "solid",
586
+ borderLeftWidth: "4px",
587
+ borderLeftColor: "danger"
588
+ },
589
+ ".touched": {
590
+ borderStyle: "solid",
591
+ borderWidth: "1px",
592
+ borderColor: "orange"
593
+ }
594
+ };
595
+
596
+ var __defProp$c = Object.defineProperty;
597
+ var __defProps$a = Object.defineProperties;
598
+ var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
599
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
600
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
601
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
602
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
603
+ var __spreadValues$c = (a, b) => {
604
+ for (var prop in b || (b = {}))
605
+ if (__hasOwnProp$d.call(b, prop))
606
+ __defNormalProp$c(a, prop, b[prop]);
607
+ if (__getOwnPropSymbols$d)
608
+ for (var prop of __getOwnPropSymbols$d(b)) {
609
+ if (__propIsEnum$d.call(b, prop))
610
+ __defNormalProp$c(a, prop, b[prop]);
611
+ }
612
+ return a;
613
+ };
614
+ var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
615
+ var __async = (__this, __arguments, generator) => {
616
+ return new Promise((resolve, reject) => {
617
+ var fulfilled = (value) => {
618
+ try {
619
+ step(generator.next(value));
620
+ } catch (e) {
621
+ reject(e);
622
+ }
623
+ };
624
+ var rejected = (value) => {
625
+ try {
626
+ step(generator.throw(value));
627
+ } catch (e) {
628
+ reject(e);
629
+ }
630
+ };
631
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
632
+ step((generator = generator.apply(__this, __arguments)).next());
633
+ });
634
+ };
635
+ const Form = ({
636
+ avoidFieldsOverride,
637
+ avoidFieldsTouch,
638
+ children,
639
+ className,
640
+ name,
641
+ initialValues,
642
+ onUnmount,
643
+ onValidate,
644
+ unregisterOnUnmount
645
+ }) => {
646
+ const actualName = React.useMemo(
647
+ () => name != null ? name : `ValidationForm${uniqueId()}`,
648
+ // eslint-disable-next-line react-hooks/exhaustive-deps
649
+ []
650
+ );
651
+ const validationResult = useFormSelector(
652
+ actualName,
653
+ (props) => props.validationResult,
654
+ shallowEqual
655
+ );
656
+ useUpdateEffect(() => {
657
+ if (validationResult && onValidate)
658
+ onValidate(validationResult);
659
+ }, [validationResult]);
660
+ const handleSubmit = React.useCallback(
661
+ (ev) => {
662
+ ev.preventDefault();
663
+ void validationsStore.validateForm(actualName);
664
+ },
665
+ [actualName]
666
+ );
667
+ const contextValue = React.useMemo(
668
+ () => ({
669
+ avoidFieldsTouch,
670
+ name: actualName,
671
+ validate: () => __async(void 0, null, function* () {
672
+ return validationsStore.validateForm(actualName);
673
+ })
674
+ }),
675
+ [actualName, avoidFieldsTouch]
676
+ );
677
+ useUnmount(() => {
678
+ onUnmount == null ? void 0 : onUnmount();
679
+ if (unregisterOnUnmount !== false)
680
+ validationsStore.unregisterForm(actualName);
681
+ });
682
+ const [hasRegistered, setHasRegistered] = React.useState(false);
683
+ useMount(() => {
684
+ validationsStore.registerForm(actualName, {
685
+ avoidFieldsOverride: avoidFieldsOverride != null ? avoidFieldsOverride : initialValues !== void 0,
686
+ initialValues
687
+ });
688
+ setHasRegistered(true);
689
+ });
690
+ if (!hasRegistered)
691
+ return null;
692
+ return /* @__PURE__ */ jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
693
+ Box,
694
+ __spreadProps$a(__spreadValues$c(__spreadProps$a(__spreadValues$c({
695
+ as: "form"
696
+ }, getVariant("layout.common.validations.form")), {
697
+ className,
698
+ id: `ValidationForm-${actualName}`
699
+ }), { name: actualName }), {
700
+ onSubmit: handleSubmit,
701
+ children
702
+ })
703
+ ) });
704
+ };
705
+ injectStyles("layout.common.validations.form", formStyles);
706
+
707
+ var __defProp$b = Object.defineProperty;
708
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
709
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
710
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
711
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
712
+ var __spreadValues$b = (a, b) => {
713
+ for (var prop in b || (b = {}))
714
+ if (__hasOwnProp$c.call(b, prop))
715
+ __defNormalProp$b(a, prop, b[prop]);
716
+ if (__getOwnPropSymbols$c)
717
+ for (var prop of __getOwnPropSymbols$c(b)) {
718
+ if (__propIsEnum$c.call(b, prop))
719
+ __defNormalProp$b(a, prop, b[prop]);
720
+ }
721
+ return a;
722
+ };
723
+ function useField(fieldDefinition) {
724
+ var _a;
725
+ const formContext = React.useContext(FormContext);
726
+ const formName = (_a = fieldDefinition.formName) != null ? _a : formContext.name;
727
+ if (!formName) {
728
+ console.error(fieldDefinition);
729
+ throw new Error(
730
+ `useField: It was not possible to determine the formName in field with name ${fieldDefinition.name}`
731
+ );
732
+ }
733
+ React.useMemo(() => {
734
+ validationsStore.registerField(
735
+ formName,
736
+ __spreadValues$b(__spreadValues$b({}, fieldDefinition), fieldDefinition.initialValue !== void 0 ? { value: fieldDefinition.initialValue } : null),
737
+ {
738
+ avoidPropagation: true,
739
+ registerIfExists: !fieldDefinition.avoidRegisterIfExists
740
+ }
741
+ );
742
+ }, []);
743
+ useMount(() => {
744
+ var _a2;
745
+ if (fieldDefinition.initialValue !== void 0 && (!((_a2 = validationsStore.getFormStore(formName)) == null ? void 0 : _a2.avoidFieldsOverride) && !fieldDefinition.avoidRegisterIfExists || validationsStore.getFieldStore(formName, fieldDefinition.name) === void 0))
746
+ validationsStore.setFieldValue(
747
+ formName,
748
+ fieldDefinition.name,
749
+ fieldDefinition.initialValue
750
+ );
751
+ });
752
+ useUnmount(() => {
753
+ if (fieldDefinition.removeOnUnmount)
754
+ validationsStore.unregisterField(formName, fieldDefinition.name);
755
+ });
756
+ const {
757
+ name,
758
+ value: storeValue,
759
+ error,
760
+ isTouched
761
+ } = useFieldSelector(
762
+ formName,
763
+ fieldDefinition.name,
764
+ (props) => {
765
+ return props;
766
+ },
767
+ (a, b) => {
768
+ if (a === PropsSelectorUndefinedObject && fieldDefinition.initialValue !== void 0)
769
+ return true;
770
+ return shallowEqual(a, b);
771
+ }
772
+ );
773
+ const [localValue, setLocalValue] = React.useState(
774
+ fieldDefinition.initialValue
775
+ );
776
+ React.useEffect(() => {
777
+ setLocalValue(storeValue);
778
+ }, [storeValue]);
779
+ const onChange = React.useCallback(
780
+ (ev) => {
781
+ const reactChangeEvent = ev;
782
+ let newValue;
783
+ if (typeof reactChangeEvent === "object" && reactChangeEvent && reactChangeEvent.target !== void 0 && reactChangeEvent.target.value !== void 0) {
784
+ newValue = reactChangeEvent.target.value;
785
+ } else
786
+ newValue = ev;
787
+ setLocalValue(newValue);
788
+ validationsStore.setFieldValue(formName, fieldDefinition.name, newValue);
789
+ },
790
+ [fieldDefinition.name, formName]
791
+ );
792
+ return {
793
+ error,
794
+ isTouched,
795
+ name,
796
+ onChange,
797
+ updateValidations: React.useCallback(
798
+ ({
799
+ validationFunction,
800
+ validationRules
801
+ }) => {
802
+ validationsStore.updateField(formName, {
803
+ name: fieldDefinition.name,
804
+ validationFunction,
805
+ validationRules
806
+ });
807
+ },
808
+ [formName, fieldDefinition.name]
809
+ ),
810
+ value: localValue != null ? localValue : fieldDefinition.initialValue
811
+ };
812
+ }
813
+
814
+ function useFieldStatesClassNames(name, formName) {
815
+ const { error, isTouched } = useField({
816
+ name,
817
+ formName,
818
+ avoidRegisterIfExists: true,
819
+ removeOnUnmount: false
820
+ });
821
+ const { avoidFieldsTouch } = useFormContext();
822
+ if (error)
823
+ return "error";
824
+ if (!avoidFieldsTouch && isTouched)
825
+ return "touched";
826
+ return "";
827
+ }
828
+
829
+ function useFieldValue({ formName, name }) {
830
+ const { name: hookFormName } = useFormContext();
831
+ if (!formName && !hookFormName) {
832
+ throw new Error(
833
+ `useFieldValue: It was not possible to determine the formName in field with name ${name}`
834
+ );
835
+ }
836
+ const { value } = useFieldSelector(
837
+ formName != null ? formName : hookFormName,
838
+ name,
839
+ (props) => {
840
+ return props;
841
+ },
842
+ (a, b) => {
843
+ if (a === PropsSelectorUndefinedObject && (b == null ? void 0 : b.value) === void 0)
844
+ return true;
845
+ return shallowEqual(a == null ? void 0 : a.value, b == null ? void 0 : b.value);
846
+ }
847
+ );
848
+ return value;
849
+ }
850
+
851
+ var __defProp$a = Object.defineProperty;
852
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
853
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
854
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
855
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
856
+ var __spreadValues$a = (a, b) => {
857
+ for (var prop in b || (b = {}))
858
+ if (__hasOwnProp$b.call(b, prop))
859
+ __defNormalProp$a(a, prop, b[prop]);
860
+ if (__getOwnPropSymbols$b)
861
+ for (var prop of __getOwnPropSymbols$b(b)) {
862
+ if (__propIsEnum$b.call(b, prop))
863
+ __defNormalProp$a(a, prop, b[prop]);
864
+ }
865
+ return a;
866
+ };
867
+ function useValidationClass({
868
+ customValidation,
869
+ validationClass,
870
+ validationFunction,
871
+ validationRules
872
+ }) {
873
+ const classesValidationFunction = React.useMemo(
874
+ () => validationClass !== void 0 ? classToValidationFunction(validationClass) : void 0,
875
+ [validationClass]
876
+ );
877
+ const actualValidationFunction = React.useCallback(
878
+ (currentValue, parameterFormName) => {
879
+ var _a;
880
+ let result = (_a = validationFunction == null ? void 0 : validationFunction(currentValue, parameterFormName)) != null ? _a : true;
881
+ if (typeof result === "string")
882
+ return result;
883
+ if (customValidation) {
884
+ result = customValidation(currentValue, parameterFormName);
885
+ }
886
+ if (typeof result === "string")
887
+ return result;
888
+ if (classesValidationFunction)
889
+ return classesValidationFunction(currentValue, parameterFormName);
890
+ return true;
891
+ },
892
+ [classesValidationFunction, customValidation, validationFunction]
893
+ );
894
+ const actualValidationRules = React.useMemo(() => {
895
+ return __spreadValues$a(__spreadValues$a({}, validationRules), validationClass !== void 0 ? classToValidate(validationClass) : {});
896
+ }, [validationClass, validationRules]);
897
+ return {
898
+ actualValidationFunction,
899
+ actualValidationRules
900
+ };
901
+ }
902
+
903
+ const ValidationError = ({ name }) => {
904
+ const formContext = useFormContext();
905
+ const error = useFieldSelector(formContext.name, name, (state) => {
906
+ return state == null ? void 0 : state.error;
907
+ });
908
+ return error ? /* @__PURE__ */ jsx(
909
+ Box,
910
+ {
911
+ as: "strong",
912
+ role: "alert",
913
+ sx: {
914
+ color: "danger"
915
+ },
916
+ dangerouslySetInnerHTML: { __html: error }
917
+ }
918
+ ) : null;
919
+ };
920
+
921
+ var __defProp$9 = Object.defineProperty;
922
+ var __defProps$9 = Object.defineProperties;
923
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
924
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
925
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
926
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
927
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
928
+ var __spreadValues$9 = (a, b) => {
929
+ for (var prop in b || (b = {}))
930
+ if (__hasOwnProp$a.call(b, prop))
931
+ __defNormalProp$9(a, prop, b[prop]);
932
+ if (__getOwnPropSymbols$a)
933
+ for (var prop of __getOwnPropSymbols$a(b)) {
934
+ if (__propIsEnum$a.call(b, prop))
935
+ __defNormalProp$9(a, prop, b[prop]);
936
+ }
937
+ return a;
938
+ };
939
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
940
+ var __objRest$a = (source, exclude) => {
941
+ var target = {};
942
+ for (var prop in source)
943
+ if (__hasOwnProp$a.call(source, prop) && exclude.indexOf(prop) < 0)
944
+ target[prop] = source[prop];
945
+ if (source != null && __getOwnPropSymbols$a)
946
+ for (var prop of __getOwnPropSymbols$a(source)) {
947
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$a.call(source, prop))
948
+ target[prop] = source[prop];
949
+ }
950
+ return target;
951
+ };
952
+ const FieldWrapper = (_a) => {
953
+ var _b = _a, {
954
+ name,
955
+ label,
956
+ avoidSemicolon,
957
+ children,
958
+ className,
959
+ as = "label",
960
+ type
961
+ } = _b, props = __objRest$a(_b, [
962
+ "name",
963
+ "label",
964
+ "avoidSemicolon",
965
+ "children",
966
+ "className",
967
+ "as",
968
+ "type"
969
+ ]);
970
+ const { name: formName } = useFormContext();
971
+ const isRequired = useFieldSelector(
972
+ formName,
973
+ name,
974
+ (global) => {
975
+ var _a2;
976
+ return (_a2 = global == null ? void 0 : global.validationRules) == null ? void 0 : _a2.required;
977
+ }
978
+ );
979
+ if (type === "checkbox") {
980
+ return /* @__PURE__ */ jsxs(
981
+ Box,
982
+ __spreadProps$9(__spreadValues$9({
983
+ className: `fieldWrapper checkboxWrapper ${className != null ? className : ""}`
984
+ }, props), {
985
+ as,
986
+ children: [
987
+ window.SHOW_REQUIRED_POSITION !== "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired }),
988
+ children,
989
+ /* @__PURE__ */ jsxs("span", { children: [
990
+ label,
991
+ window.SHOW_REQUIRED_POSITION === "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired })
992
+ ] }),
993
+ /* @__PURE__ */ jsx(ValidationError, { name })
994
+ ]
995
+ })
996
+ );
997
+ }
998
+ return /* @__PURE__ */ jsxs(Box, __spreadProps$9(__spreadValues$9({ className: `fieldWrapper ${className != null ? className : ""}` }, props), { as, children: [
999
+ /* @__PURE__ */ jsxs(Box, { as: "span", children: [
1000
+ window.SHOW_REQUIRED_POSITION !== "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired }),
1001
+ label,
1002
+ !avoidSemicolon && label && /* @__PURE__ */ jsx("abbr", { className: "semicolon", children: ": " }),
1003
+ window.SHOW_REQUIRED_POSITION === "0" && label && /* @__PURE__ */ jsx(RequiredMark, { isRequired })
1004
+ ] }),
1005
+ children,
1006
+ /* @__PURE__ */ jsx(ValidationError, { name })
1007
+ ] }));
1008
+ };
1009
+
1010
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
1011
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
1012
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
1013
+ var __objRest$9 = (source, exclude) => {
1014
+ var target = {};
1015
+ for (var prop in source)
1016
+ if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
1017
+ target[prop] = source[prop];
1018
+ if (source != null && __getOwnPropSymbols$9)
1019
+ for (var prop of __getOwnPropSymbols$9(source)) {
1020
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
1021
+ target[prop] = source[prop];
1022
+ }
1023
+ return target;
1024
+ };
1025
+ const InnerCaptcha = ({
1026
+ className,
1027
+ name,
1028
+ imageUrl,
1029
+ /**
1030
+ * useField
1031
+ */
1032
+ avoidRegisterIfExists,
1033
+ avoidSemicolon,
1034
+ formName,
1035
+ label,
1036
+ removeOnUnmount,
1037
+ submitName,
1038
+ submitValueParser,
1039
+ validationValueParser
1040
+ }) => {
1041
+ const _a = useField({
1042
+ name,
1043
+ avoidRegisterIfExists,
1044
+ formName,
1045
+ initialValue: "",
1046
+ removeOnUnmount,
1047
+ submitName,
1048
+ submitValueParser,
1049
+ validationValueParser,
1050
+ validationRules: { required: true }
1051
+ }), { error, updateValidations, onChange, isTouched } = _a, validationProps = __objRest$9(_a, ["error", "updateValidations", "onChange", "isTouched"]);
1052
+ const handleOnChange = React.useCallback(
1053
+ (ev) => {
1054
+ onChange(ev);
1055
+ },
1056
+ [onChange]
1057
+ );
1058
+ const stateClassName = useFieldStatesClassNames(name);
1059
+ return /* @__PURE__ */ jsx(
1060
+ FieldWrapper,
1061
+ {
1062
+ name,
1063
+ label,
1064
+ className: `input ${className != null ? className : ""}`,
1065
+ avoidSemicolon,
1066
+ children: /* @__PURE__ */ jsx(
1067
+ Captcha,
1068
+ {
1069
+ name,
1070
+ imageUrl,
1071
+ onChange: handleOnChange,
1072
+ value: validationProps.value,
1073
+ className: stateClassName
1074
+ }
1075
+ )
1076
+ }
1077
+ );
1078
+ };
1079
+
1080
+ var __defProp$8 = Object.defineProperty;
1081
+ var __defProps$8 = Object.defineProperties;
1082
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1083
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
1084
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
1085
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
1086
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1087
+ var __spreadValues$8 = (a, b) => {
1088
+ for (var prop in b || (b = {}))
1089
+ if (__hasOwnProp$8.call(b, prop))
1090
+ __defNormalProp$8(a, prop, b[prop]);
1091
+ if (__getOwnPropSymbols$8)
1092
+ for (var prop of __getOwnPropSymbols$8(b)) {
1093
+ if (__propIsEnum$8.call(b, prop))
1094
+ __defNormalProp$8(a, prop, b[prop]);
1095
+ }
1096
+ return a;
1097
+ };
1098
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1099
+ var __objRest$8 = (source, exclude) => {
1100
+ var target = {};
1101
+ for (var prop in source)
1102
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
1103
+ target[prop] = source[prop];
1104
+ if (source != null && __getOwnPropSymbols$8)
1105
+ for (var prop of __getOwnPropSymbols$8(source)) {
1106
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
1107
+ target[prop] = source[prop];
1108
+ }
1109
+ return target;
1110
+ };
1111
+ const Checkbox = React.forwardRef(
1112
+ (_a, ref) => {
1113
+ var _b = _a, {
1114
+ avoidSemicolon,
1115
+ className,
1116
+ label,
1117
+ native,
1118
+ onChange: outerOnChange,
1119
+ type,
1120
+ avoidRegisterIfExists: avoidRegisterIfExists,
1121
+ formName,
1122
+ initialValue,
1123
+ name,
1124
+ removeOnUnmount,
1125
+ submitValueParser,
1126
+ validationClass,
1127
+ validationFunction,
1128
+ validationRules,
1129
+ value
1130
+ } = _b, props = __objRest$8(_b, [
1131
+ "avoidSemicolon",
1132
+ "className",
1133
+ "label",
1134
+ "native",
1135
+ "onChange",
1136
+ "type",
1137
+ /**
1138
+ * useField
1139
+ */
1140
+ "avoidRegisterIfExists",
1141
+ "formName",
1142
+ "initialValue",
1143
+ "name",
1144
+ "removeOnUnmount",
1145
+ "submitValueParser",
1146
+ "validationClass",
1147
+ "validationFunction",
1148
+ "validationRules",
1149
+ "value"
1150
+ ]);
1151
+ var _a2, _c;
1152
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1153
+ validationClass,
1154
+ validationFunction,
1155
+ validationRules
1156
+ });
1157
+ const _b2 = useField({
1158
+ avoidRegisterIfExists,
1159
+ formName,
1160
+ name,
1161
+ initialValue: (_a2 = initialValue === true || initialValue === "on") != null ? _a2 : false,
1162
+ removeOnUnmount,
1163
+ submitValueParser,
1164
+ validationFunction: actualValidationFunction,
1165
+ validationRules: actualValidationRules
1166
+ }), {
1167
+ value: innerValue,
1168
+ onChange,
1169
+ updateValidations,
1170
+ isTouched
1171
+ } = _b2, inputProps = __objRest$8(_b2, [
1172
+ "value",
1173
+ "onChange",
1174
+ "updateValidations",
1175
+ "isTouched"
1176
+ ]);
1177
+ return /* @__PURE__ */ jsx(
1178
+ FieldWrapper,
1179
+ {
1180
+ name,
1181
+ label,
1182
+ className: `checkbox ${className != null ? className : ""}`,
1183
+ avoidSemicolon,
1184
+ children: /* @__PURE__ */ jsx(
1185
+ Checkbox$1,
1186
+ __spreadProps$8(__spreadValues$8(__spreadValues$8({}, props), inputProps), {
1187
+ native,
1188
+ "aria-label": (_c = props["aria-label"]) != null ? _c : label,
1189
+ onChange: (ev) => {
1190
+ onChange(ev.target.checked);
1191
+ if (outerOnChange)
1192
+ outerOnChange(ev);
1193
+ },
1194
+ checked: innerValue === true || innerValue === "on",
1195
+ ref
1196
+ })
1197
+ )
1198
+ }
1199
+ );
1200
+ }
1201
+ );
1202
+ Checkbox.displayName = "Checkbox";
1203
+
1204
+ var __defProp$7 = Object.defineProperty;
1205
+ var __defProps$7 = Object.defineProperties;
1206
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1207
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
1208
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
1209
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
1210
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1211
+ var __spreadValues$7 = (a, b) => {
1212
+ for (var prop in b || (b = {}))
1213
+ if (__hasOwnProp$7.call(b, prop))
1214
+ __defNormalProp$7(a, prop, b[prop]);
1215
+ if (__getOwnPropSymbols$7)
1216
+ for (var prop of __getOwnPropSymbols$7(b)) {
1217
+ if (__propIsEnum$7.call(b, prop))
1218
+ __defNormalProp$7(a, prop, b[prop]);
1219
+ }
1220
+ return a;
1221
+ };
1222
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1223
+ var __objRest$7 = (source, exclude) => {
1224
+ var target = {};
1225
+ for (var prop in source)
1226
+ if (__hasOwnProp$7.call(source, prop) && exclude.indexOf(prop) < 0)
1227
+ target[prop] = source[prop];
1228
+ if (source != null && __getOwnPropSymbols$7)
1229
+ for (var prop of __getOwnPropSymbols$7(source)) {
1230
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$7.call(source, prop))
1231
+ target[prop] = source[prop];
1232
+ }
1233
+ return target;
1234
+ };
1235
+ const DeletableInput = React.forwardRef(
1236
+ (_a, ref) => {
1237
+ var _b = _a, {
1238
+ avoidSemicolon,
1239
+ className,
1240
+ label,
1241
+ onChange: outerOnChange,
1242
+ type,
1243
+ avoidRegisterIfExists: avoidRegisterIfExists,
1244
+ formName: propsFormName,
1245
+ initialValue,
1246
+ name,
1247
+ removeOnUnmount,
1248
+ submitValueParser,
1249
+ validationClass,
1250
+ validationFunction,
1251
+ validationRules,
1252
+ value
1253
+ } = _b, props = __objRest$7(_b, [
1254
+ "avoidSemicolon",
1255
+ "className",
1256
+ "label",
1257
+ "onChange",
1258
+ "type",
1259
+ /**
1260
+ * useField
1261
+ */
1262
+ "avoidRegisterIfExists",
1263
+ "formName",
1264
+ "initialValue",
1265
+ "name",
1266
+ "removeOnUnmount",
1267
+ "submitValueParser",
1268
+ "validationClass",
1269
+ "validationFunction",
1270
+ "validationRules",
1271
+ "value"
1272
+ ]);
1273
+ var _a2, _b2, _c, _e, _f;
1274
+ const { name: contextFormName } = React.useContext(FormContext);
1275
+ const formName = propsFormName != null ? propsFormName : contextFormName;
1276
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1277
+ validationClass,
1278
+ validationFunction,
1279
+ validationRules
1280
+ });
1281
+ const _d = useField({
1282
+ formName,
1283
+ name,
1284
+ initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1285
+ removeOnUnmount,
1286
+ submitValueParser,
1287
+ validationFunction: actualValidationFunction,
1288
+ validationRules: actualValidationRules
1289
+ }), {
1290
+ error,
1291
+ updateValidations,
1292
+ onChange,
1293
+ isTouched
1294
+ } = _d, validationProps = __objRest$7(_d, [
1295
+ "error",
1296
+ "updateValidations",
1297
+ "onChange",
1298
+ "isTouched"
1299
+ ]);
1300
+ const handleOnChange = React.useCallback(
1301
+ (ev) => {
1302
+ onChange(ev);
1303
+ outerOnChange == null ? void 0 : outerOnChange(ev);
1304
+ },
1305
+ [onChange, outerOnChange]
1306
+ );
1307
+ const stateClassName = useFieldStatesClassNames(name);
1308
+ return /* @__PURE__ */ jsxs(
1309
+ FieldWrapper,
1310
+ {
1311
+ name,
1312
+ label,
1313
+ sx: React.useCallback(
1314
+ () => ({
1315
+ display: "flex",
1316
+ flexDirection: "column",
1317
+ alignItems: "start"
1318
+ }),
1319
+ []
1320
+ ),
1321
+ className: `deletableInput ${className != null ? className : ""}`,
1322
+ avoidSemicolon,
1323
+ children: [
1324
+ /* @__PURE__ */ jsx(
1325
+ Input$1,
1326
+ __spreadProps$7(__spreadValues$7(__spreadValues$7({
1327
+ type
1328
+ }, props), validationProps), {
1329
+ "aria-label": (_e = props["aria-label"]) != null ? _e : label,
1330
+ ref,
1331
+ onChange: handleOnChange,
1332
+ value: (_f = validationProps.value) != null ? _f : "",
1333
+ className: `deletableInput__input ${stateClassName != null ? stateClassName : ""}`
1334
+ })
1335
+ ),
1336
+ /* @__PURE__ */ jsx(
1337
+ IconButton,
1338
+ {
1339
+ icon: "Close",
1340
+ className: "deletableInput__deleteButton",
1341
+ onClick: () => onChange("")
1342
+ }
1343
+ )
1344
+ ]
1345
+ }
1346
+ );
1347
+ }
1348
+ );
1349
+ DeletableInput.displayName = "DeletableInput";
1350
+
1351
+ var __defProp$6 = Object.defineProperty;
1352
+ var __defProps$6 = Object.defineProperties;
1353
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1354
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
1355
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
1356
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
1357
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1358
+ var __spreadValues$6 = (a, b) => {
1359
+ for (var prop in b || (b = {}))
1360
+ if (__hasOwnProp$6.call(b, prop))
1361
+ __defNormalProp$6(a, prop, b[prop]);
1362
+ if (__getOwnPropSymbols$6)
1363
+ for (var prop of __getOwnPropSymbols$6(b)) {
1364
+ if (__propIsEnum$6.call(b, prop))
1365
+ __defNormalProp$6(a, prop, b[prop]);
1366
+ }
1367
+ return a;
1368
+ };
1369
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
1370
+ var __objRest$6 = (source, exclude) => {
1371
+ var target = {};
1372
+ for (var prop in source)
1373
+ if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
1374
+ target[prop] = source[prop];
1375
+ if (source != null && __getOwnPropSymbols$6)
1376
+ for (var prop of __getOwnPropSymbols$6(source)) {
1377
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
1378
+ target[prop] = source[prop];
1379
+ }
1380
+ return target;
1381
+ };
1382
+ const FileInput = React.memo(
1383
+ React.forwardRef(
1384
+ (_a, ref) => {
1385
+ var _b = _a, {
1386
+ avoidSemicolon,
1387
+ className,
1388
+ label,
1389
+ avoidRegisterIfExists: avoidRegisterIfExists,
1390
+ formName: propsFormName,
1391
+ initialValue,
1392
+ name,
1393
+ removeOnUnmount,
1394
+ submitValueParser,
1395
+ validationClass,
1396
+ validationFunction,
1397
+ validationRules
1398
+ } = _b, props = __objRest$6(_b, [
1399
+ "avoidSemicolon",
1400
+ "className",
1401
+ "label",
1402
+ /**
1403
+ * useField
1404
+ */
1405
+ "avoidRegisterIfExists",
1406
+ "formName",
1407
+ "initialValue",
1408
+ "name",
1409
+ "removeOnUnmount",
1410
+ "submitValueParser",
1411
+ "validationClass",
1412
+ "validationFunction",
1413
+ "validationRules"
1414
+ ]);
1415
+ var _b2;
1416
+ const { name: formName } = useFormContext();
1417
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1418
+ customValidation(fileValue) {
1419
+ return fileValue !== null && fileValue !== void 0 ? true : lang("required");
1420
+ },
1421
+ validationClass,
1422
+ validationFunction,
1423
+ validationRules
1424
+ });
1425
+ const _a2 = useField({
1426
+ formName,
1427
+ name,
1428
+ removeOnUnmount,
1429
+ submitValueParser,
1430
+ validationFunction: actualValidationFunction,
1431
+ validationRules: actualValidationRules
1432
+ }), {
1433
+ error,
1434
+ onChange,
1435
+ value,
1436
+ updateValidations,
1437
+ isTouched
1438
+ } = _a2, validationProps = __objRest$6(_a2, [
1439
+ "error",
1440
+ "onChange",
1441
+ "value",
1442
+ "updateValidations",
1443
+ "isTouched"
1444
+ ]);
1445
+ return /* @__PURE__ */ jsx(
1446
+ FieldWrapper,
1447
+ {
1448
+ name,
1449
+ label,
1450
+ className: `input ${className != null ? className : ""}`,
1451
+ avoidSemicolon,
1452
+ children: /* @__PURE__ */ jsx(
1453
+ Input$1,
1454
+ __spreadProps$6(__spreadValues$6(__spreadValues$6({}, props), validationProps), {
1455
+ type: "file",
1456
+ "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
1457
+ ref,
1458
+ sx: getFieldErrorStyles(!error),
1459
+ onChange: React.useCallback(
1460
+ (ev) => {
1461
+ var _a3, _b3, _c;
1462
+ onChange((_c = (_b3 = (_a3 = ev.target) == null ? void 0 : _a3.files) == null ? void 0 : _b3[0]) != null ? _c : null);
1463
+ },
1464
+ [onChange]
1465
+ )
1466
+ })
1467
+ )
1468
+ }
1469
+ );
1470
+ }
1471
+ )
1472
+ );
1473
+ FileInput.displayName = "FileInput";
1474
+
1475
+ var __defProp$5 = Object.defineProperty;
1476
+ var __defProps$5 = Object.defineProperties;
1477
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
1478
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
1479
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
1480
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
1481
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1482
+ var __spreadValues$5 = (a, b) => {
1483
+ for (var prop in b || (b = {}))
1484
+ if (__hasOwnProp$5.call(b, prop))
1485
+ __defNormalProp$5(a, prop, b[prop]);
1486
+ if (__getOwnPropSymbols$5)
1487
+ for (var prop of __getOwnPropSymbols$5(b)) {
1488
+ if (__propIsEnum$5.call(b, prop))
1489
+ __defNormalProp$5(a, prop, b[prop]);
1490
+ }
1491
+ return a;
1492
+ };
1493
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
1494
+ var __objRest$5 = (source, exclude) => {
1495
+ var target = {};
1496
+ for (var prop in source)
1497
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
1498
+ target[prop] = source[prop];
1499
+ if (source != null && __getOwnPropSymbols$5)
1500
+ for (var prop of __getOwnPropSymbols$5(source)) {
1501
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
1502
+ target[prop] = source[prop];
1503
+ }
1504
+ return target;
1505
+ };
1506
+ const Input = React.memo(
1507
+ React.forwardRef(
1508
+ (_a, ref) => {
1509
+ var _b = _a, {
1510
+ avoidSemicolon,
1511
+ className,
1512
+ label,
1513
+ onChange: outerOnChange,
1514
+ type,
1515
+ avoidRegisterIfExists: avoidRegisterIfExists,
1516
+ formName: propsFormName,
1517
+ initialValue,
1518
+ name,
1519
+ removeOnUnmount,
1520
+ submitValueParser,
1521
+ validationClass,
1522
+ validationFunction,
1523
+ validationRules,
1524
+ value
1525
+ } = _b, props = __objRest$5(_b, [
1526
+ "avoidSemicolon",
1527
+ "className",
1528
+ "label",
1529
+ "onChange",
1530
+ "type",
1531
+ /**
1532
+ * useField
1533
+ */
1534
+ "avoidRegisterIfExists",
1535
+ "formName",
1536
+ "initialValue",
1537
+ "name",
1538
+ "removeOnUnmount",
1539
+ "submitValueParser",
1540
+ "validationClass",
1541
+ "validationFunction",
1542
+ "validationRules",
1543
+ "value"
1544
+ ]);
1545
+ var _a2, _b2, _c, _e, _f, _g, _h;
1546
+ const { name: contextFormName } = React.useContext(FormContext);
1547
+ const formName = propsFormName != null ? propsFormName : contextFormName;
1548
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1549
+ validationClass,
1550
+ validationFunction,
1551
+ validationRules
1552
+ });
1553
+ const _d = useField({
1554
+ formName,
1555
+ name,
1556
+ initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1557
+ removeOnUnmount,
1558
+ submitValueParser,
1559
+ validationFunction: actualValidationFunction,
1560
+ validationRules: actualValidationRules
1561
+ }), {
1562
+ error,
1563
+ updateValidations,
1564
+ onChange,
1565
+ isTouched
1566
+ } = _d, validationProps = __objRest$5(_d, [
1567
+ "error",
1568
+ "updateValidations",
1569
+ "onChange",
1570
+ "isTouched"
1571
+ ]);
1572
+ const handleOnChange = React.useCallback(
1573
+ (ev) => {
1574
+ onChange(ev);
1575
+ if (typeof ev === "string") {
1576
+ outerOnChange == null ? void 0 : outerOnChange({
1577
+ target: ref
1578
+ });
1579
+ } else {
1580
+ outerOnChange == null ? void 0 : outerOnChange(ev);
1581
+ }
1582
+ },
1583
+ [onChange, outerOnChange, ref]
1584
+ );
1585
+ const stateClassName = useFieldStatesClassNames(name);
1586
+ return /* @__PURE__ */ jsx(
1587
+ FieldWrapper,
1588
+ {
1589
+ name,
1590
+ label,
1591
+ className: `input ${className != null ? className : ""}`,
1592
+ avoidSemicolon,
1593
+ children: type === "date" ? /* @__PURE__ */ jsx(
1594
+ DateInput,
1595
+ __spreadProps$5(__spreadValues$5(__spreadValues$5({}, props), validationProps), {
1596
+ "aria-label": (_e = props["aria-label"]) != null ? _e : label,
1597
+ onError: void 0,
1598
+ ref,
1599
+ onChange: handleOnChange,
1600
+ value: (_f = validationProps.value) != null ? _f : "",
1601
+ className: stateClassName
1602
+ })
1603
+ ) : /* @__PURE__ */ jsx(
1604
+ Input$1,
1605
+ __spreadProps$5(__spreadValues$5(__spreadValues$5({
1606
+ type
1607
+ }, props), validationProps), {
1608
+ "aria-label": (_g = props["aria-label"]) != null ? _g : label,
1609
+ ref,
1610
+ onChange: handleOnChange,
1611
+ value: (_h = validationProps.value) != null ? _h : "",
1612
+ className: stateClassName
1613
+ })
1614
+ )
1615
+ }
1616
+ );
1617
+ }
1618
+ )
1619
+ );
1620
+ Input.displayName = "Input";
1621
+
1622
+ var __defProp$4 = Object.defineProperty;
1623
+ var __defProps$4 = Object.defineProperties;
1624
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
1625
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1626
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1627
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1628
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1629
+ var __spreadValues$4 = (a, b) => {
1630
+ for (var prop in b || (b = {}))
1631
+ if (__hasOwnProp$4.call(b, prop))
1632
+ __defNormalProp$4(a, prop, b[prop]);
1633
+ if (__getOwnPropSymbols$4)
1634
+ for (var prop of __getOwnPropSymbols$4(b)) {
1635
+ if (__propIsEnum$4.call(b, prop))
1636
+ __defNormalProp$4(a, prop, b[prop]);
1637
+ }
1638
+ return a;
1639
+ };
1640
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
1641
+ var __objRest$4 = (source, exclude) => {
1642
+ var target = {};
1643
+ for (var prop in source)
1644
+ if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
1645
+ target[prop] = source[prop];
1646
+ if (source != null && __getOwnPropSymbols$4)
1647
+ for (var prop of __getOwnPropSymbols$4(source)) {
1648
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
1649
+ target[prop] = source[prop];
1650
+ }
1651
+ return target;
1652
+ };
1653
+ const NumberInputf = React.memo(
1654
+ React.forwardRef(
1655
+ (_a, ref) => {
1656
+ var _b = _a, {
1657
+ avoidSemicolon,
1658
+ className,
1659
+ label,
1660
+ onChange: outerOnChange,
1661
+ avoidRegisterIfExists: avoidRegisterIfExists,
1662
+ formName: propsFormName,
1663
+ initialValue,
1664
+ name,
1665
+ removeOnUnmount,
1666
+ submitValueParser,
1667
+ validationClass,
1668
+ validationFunction,
1669
+ validationRules,
1670
+ value
1671
+ } = _b, props = __objRest$4(_b, [
1672
+ "avoidSemicolon",
1673
+ "className",
1674
+ "label",
1675
+ "onChange",
1676
+ /**
1677
+ * useField
1678
+ */
1679
+ "avoidRegisterIfExists",
1680
+ "formName",
1681
+ "initialValue",
1682
+ "name",
1683
+ "removeOnUnmount",
1684
+ "submitValueParser",
1685
+ "validationClass",
1686
+ "validationFunction",
1687
+ "validationRules",
1688
+ "value"
1689
+ ]);
1690
+ var _a2, _b2, _c;
1691
+ const { name: contextFormName } = React.useContext(FormContext);
1692
+ const formName = propsFormName != null ? propsFormName : contextFormName;
1693
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1694
+ validationClass,
1695
+ validationFunction,
1696
+ validationRules
1697
+ });
1698
+ const { onChange, value: innerValue } = useField({
1699
+ formName,
1700
+ name,
1701
+ initialValue: (_c = (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = validationsStore.getFieldStore(formName, name)) == null ? void 0 : _a2.value) != null ? _c : "",
1702
+ removeOnUnmount,
1703
+ submitValueParser: React.useCallback(
1704
+ (current) => parseNumberInputValueToNumber(current != null ? current : ""),
1705
+ []
1706
+ ),
1707
+ validationValueParser: React.useCallback(
1708
+ (current) => parseNumberInputValueToNumber(current != null ? current : ""),
1709
+ []
1710
+ ),
1711
+ validationFunction: actualValidationFunction,
1712
+ validationRules: actualValidationRules
1713
+ });
1714
+ const handleOnChange = React.useCallback(
1715
+ (ev) => {
1716
+ if (ev.error) {
1717
+ outerOnChange == null ? void 0 : outerOnChange(__spreadProps$4(__spreadValues$4({}, ev), { value: "" }));
1718
+ onChange("");
1719
+ validationsStore.updateField(formName, {
1720
+ name,
1721
+ error: formatMessage(window.GNR_NUMERIC, { TOK: "" })
1722
+ });
1723
+ } else {
1724
+ onChange(ev.value);
1725
+ outerOnChange == null ? void 0 : outerOnChange(ev);
1726
+ validationsStore.updateField(formName, { name, error: null });
1727
+ }
1728
+ },
1729
+ [formName, name, onChange, outerOnChange]
1730
+ );
1731
+ const stateClassName = useFieldStatesClassNames(name);
1732
+ return /* @__PURE__ */ jsx(
1733
+ FieldWrapper,
1734
+ {
1735
+ name,
1736
+ label,
1737
+ sx: React.useMemo(
1738
+ () => ({
1739
+ display: "flex",
1740
+ flexDirection: "column",
1741
+ alignItems: "start"
1742
+ }),
1743
+ []
1744
+ ),
1745
+ className: `input ${className != null ? className : ""}`,
1746
+ avoidSemicolon,
1747
+ children: /* @__PURE__ */ jsx(
1748
+ NumberInput,
1749
+ __spreadProps$4(__spreadValues$4({
1750
+ ref
1751
+ }, props), {
1752
+ name,
1753
+ value: innerValue,
1754
+ onChange: handleOnChange,
1755
+ className: stateClassName
1756
+ })
1757
+ )
1758
+ }
1759
+ );
1760
+ }
1761
+ )
1762
+ );
1763
+ NumberInputf.displayName = "NumberInputf";
1764
+
1765
+ var __defProp$3 = Object.defineProperty;
1766
+ var __defProps$3 = Object.defineProperties;
1767
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
1768
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1769
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1770
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1771
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1772
+ var __spreadValues$3 = (a, b) => {
1773
+ for (var prop in b || (b = {}))
1774
+ if (__hasOwnProp$3.call(b, prop))
1775
+ __defNormalProp$3(a, prop, b[prop]);
1776
+ if (__getOwnPropSymbols$3)
1777
+ for (var prop of __getOwnPropSymbols$3(b)) {
1778
+ if (__propIsEnum$3.call(b, prop))
1779
+ __defNormalProp$3(a, prop, b[prop]);
1780
+ }
1781
+ return a;
1782
+ };
1783
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
1784
+ var __objRest$3 = (source, exclude) => {
1785
+ var target = {};
1786
+ for (var prop in source)
1787
+ if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
1788
+ target[prop] = source[prop];
1789
+ if (source != null && __getOwnPropSymbols$3)
1790
+ for (var prop of __getOwnPropSymbols$3(source)) {
1791
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
1792
+ target[prop] = source[prop];
1793
+ }
1794
+ return target;
1795
+ };
1796
+ const Radio = React.forwardRef(
1797
+ (_a, ref) => {
1798
+ var _b = _a, {
1799
+ avoidSemicolon,
1800
+ className,
1801
+ formName,
1802
+ label,
1803
+ onChange: outerOnChange,
1804
+ options,
1805
+ value: outerValue,
1806
+ avoidRegisterIfExists: avoidRegisterIfExists,
1807
+ initialValue,
1808
+ name,
1809
+ removeOnUnmount,
1810
+ submitValueParser,
1811
+ validationClass,
1812
+ validationFunction,
1813
+ validationRules
1814
+ } = _b, props = __objRest$3(_b, [
1815
+ "avoidSemicolon",
1816
+ "className",
1817
+ "formName",
1818
+ "label",
1819
+ "onChange",
1820
+ "options",
1821
+ "value",
1822
+ /**
1823
+ * useField
1824
+ */
1825
+ "avoidRegisterIfExists",
1826
+ "initialValue",
1827
+ "name",
1828
+ "removeOnUnmount",
1829
+ "submitValueParser",
1830
+ "validationClass",
1831
+ "validationFunction",
1832
+ "validationRules"
1833
+ ]);
1834
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1835
+ validationClass,
1836
+ validationFunction,
1837
+ validationRules
1838
+ });
1839
+ const _a2 = useField({
1840
+ formName,
1841
+ name,
1842
+ initialValue: initialValue != null ? initialValue : outerValue,
1843
+ removeOnUnmount,
1844
+ submitValueParser,
1845
+ validationFunction: actualValidationFunction,
1846
+ validationRules: actualValidationRules
1847
+ }), { value, updateValidations, onChange, isTouched } = _a2, inputProps = __objRest$3(_a2, ["value", "updateValidations", "onChange", "isTouched"]);
1848
+ const handleOnChange = React.useCallback(
1849
+ (ev) => {
1850
+ onChange(ev);
1851
+ if (outerOnChange) {
1852
+ outerOnChange(ev);
1853
+ }
1854
+ },
1855
+ [onChange, outerOnChange]
1856
+ );
1857
+ return /* @__PURE__ */ jsx(
1858
+ FieldWrapper,
1859
+ {
1860
+ name,
1861
+ label,
1862
+ className: `radio ${className != null ? className : ""}`,
1863
+ avoidSemicolon,
1864
+ as: "ul",
1865
+ children: options == null ? void 0 : options.map((option) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Label, { title: option.label, className: "radio-label", children: [
1866
+ /* @__PURE__ */ jsx(
1867
+ Radio$1,
1868
+ __spreadProps$3(__spreadValues$3(__spreadValues$3({}, props), inputProps), {
1869
+ role: "radio",
1870
+ className: "radio-button",
1871
+ "aria-label": option.label,
1872
+ ref,
1873
+ value: option.value,
1874
+ checked: value === option.value,
1875
+ onChange: handleOnChange
1876
+ })
1877
+ ),
1878
+ /* @__PURE__ */ jsx(Box, { as: "span", className: "radio-text", children: option.label })
1879
+ ] }) }, option.value))
1880
+ }
1881
+ );
1882
+ }
1883
+ );
1884
+ Radio.displayName = "Radio";
1885
+
1886
+ var __defProp$2 = Object.defineProperty;
1887
+ var __defProps$2 = Object.defineProperties;
1888
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1889
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1890
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1891
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1892
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1893
+ var __spreadValues$2 = (a, b) => {
1894
+ for (var prop in b || (b = {}))
1895
+ if (__hasOwnProp$2.call(b, prop))
1896
+ __defNormalProp$2(a, prop, b[prop]);
1897
+ if (__getOwnPropSymbols$2)
1898
+ for (var prop of __getOwnPropSymbols$2(b)) {
1899
+ if (__propIsEnum$2.call(b, prop))
1900
+ __defNormalProp$2(a, prop, b[prop]);
1901
+ }
1902
+ return a;
1903
+ };
1904
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1905
+ var __objRest$2 = (source, exclude) => {
1906
+ var target = {};
1907
+ for (var prop in source)
1908
+ if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
1909
+ target[prop] = source[prop];
1910
+ if (source != null && __getOwnPropSymbols$2)
1911
+ for (var prop of __getOwnPropSymbols$2(source)) {
1912
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
1913
+ target[prop] = source[prop];
1914
+ }
1915
+ return target;
1916
+ };
1917
+ const Select = React.forwardRef(
1918
+ (_a, ref) => {
1919
+ var _b = _a, {
1920
+ avoidSemicolon,
1921
+ className,
1922
+ formName,
1923
+ label,
1924
+ onChange: outerOnChange,
1925
+ options,
1926
+ avoidRegisterIfExists: avoidRegisterIfExists,
1927
+ initialValue,
1928
+ name,
1929
+ removeOnUnmount,
1930
+ submitValueParser,
1931
+ validationClass,
1932
+ validationFunction,
1933
+ validationRules,
1934
+ value
1935
+ } = _b, props = __objRest$2(_b, [
1936
+ "avoidSemicolon",
1937
+ "className",
1938
+ "formName",
1939
+ "label",
1940
+ "onChange",
1941
+ "options",
1942
+ /**
1943
+ * useField
1944
+ */
1945
+ "avoidRegisterIfExists",
1946
+ "initialValue",
1947
+ "name",
1948
+ "removeOnUnmount",
1949
+ "submitValueParser",
1950
+ "validationClass",
1951
+ "validationFunction",
1952
+ "validationRules",
1953
+ "value"
1954
+ ]);
1955
+ var _a2, _b2, _d, _e;
1956
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
1957
+ validationClass,
1958
+ validationFunction,
1959
+ validationRules
1960
+ });
1961
+ const _c = useField({
1962
+ avoidRegisterIfExists,
1963
+ initialValue: (_b2 = initialValue != null ? initialValue : value) != null ? _b2 : (_a2 = options[0]) == null ? void 0 : _a2.value,
1964
+ name,
1965
+ removeOnUnmount,
1966
+ submitValueParser,
1967
+ validationFunction: actualValidationFunction,
1968
+ validationRules: actualValidationRules
1969
+ }), { updateValidations, onChange, isTouched } = _c, inputProps = __objRest$2(_c, ["updateValidations", "onChange", "isTouched"]);
1970
+ return /* @__PURE__ */ jsx(
1971
+ FieldWrapper,
1972
+ {
1973
+ name,
1974
+ label,
1975
+ className: `select ${className != null ? className : ""}`,
1976
+ avoidSemicolon,
1977
+ children: /* @__PURE__ */ jsxs(
1978
+ Select$1,
1979
+ __spreadProps$2(__spreadValues$2(__spreadValues$2(__spreadValues$2({}, getVariant("forms.select")), props), inputProps), {
1980
+ onChange: React.useCallback(
1981
+ (ev) => {
1982
+ onChange(ev);
1983
+ if (outerOnChange) {
1984
+ outerOnChange(ev);
1985
+ }
1986
+ },
1987
+ [onChange, outerOnChange]
1988
+ ),
1989
+ "aria-label": (_d = props["aria-label"]) != null ? _d : label,
1990
+ ref,
1991
+ value: (_e = inputProps.value) != null ? _e : "",
1992
+ children: [
1993
+ options == null ? void 0 : options.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value)),
1994
+ props.children
1995
+ ]
1996
+ })
1997
+ )
1998
+ }
1999
+ );
2000
+ }
2001
+ );
2002
+ Select.displayName = "Select";
2003
+
2004
+ var __defProp$1 = Object.defineProperty;
2005
+ var __defProps$1 = Object.defineProperties;
2006
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
2007
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2008
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2009
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2010
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2011
+ var __spreadValues$1 = (a, b) => {
2012
+ for (var prop in b || (b = {}))
2013
+ if (__hasOwnProp$1.call(b, prop))
2014
+ __defNormalProp$1(a, prop, b[prop]);
2015
+ if (__getOwnPropSymbols$1)
2016
+ for (var prop of __getOwnPropSymbols$1(b)) {
2017
+ if (__propIsEnum$1.call(b, prop))
2018
+ __defNormalProp$1(a, prop, b[prop]);
2019
+ }
2020
+ return a;
2021
+ };
2022
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2023
+ var __objRest$1 = (source, exclude) => {
2024
+ var target = {};
2025
+ for (var prop in source)
2026
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
2027
+ target[prop] = source[prop];
2028
+ if (source != null && __getOwnPropSymbols$1)
2029
+ for (var prop of __getOwnPropSymbols$1(source)) {
2030
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
2031
+ target[prop] = source[prop];
2032
+ }
2033
+ return target;
2034
+ };
2035
+ const Switchbox = React.forwardRef(
2036
+ (_a, ref) => {
2037
+ var _b = _a, {
2038
+ avoidSemicolon,
2039
+ className,
2040
+ label,
2041
+ onChange: outerOnChange,
2042
+ type,
2043
+ reverse = false,
2044
+ avoidRegisterIfExists,
2045
+ formName,
2046
+ initialValue,
2047
+ name,
2048
+ removeOnUnmount,
2049
+ submitValueParser,
2050
+ validationClass,
2051
+ validationFunction,
2052
+ validationRules,
2053
+ value
2054
+ } = _b, props = __objRest$1(_b, [
2055
+ "avoidSemicolon",
2056
+ "className",
2057
+ "label",
2058
+ "onChange",
2059
+ "type",
2060
+ "reverse",
2061
+ "avoidRegisterIfExists",
2062
+ "formName",
2063
+ "initialValue",
2064
+ "name",
2065
+ "removeOnUnmount",
2066
+ "submitValueParser",
2067
+ "validationClass",
2068
+ "validationFunction",
2069
+ "validationRules",
2070
+ "value"
2071
+ ]);
2072
+ var _b2, _c;
2073
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
2074
+ validationClass,
2075
+ validationFunction,
2076
+ validationRules
2077
+ });
2078
+ const _a2 = useField({
2079
+ avoidRegisterIfExists,
2080
+ formName,
2081
+ name,
2082
+ initialValue: (initialValue != null ? initialValue : "off") === "on" || toBoolean(initialValue) ? "on" : "off",
2083
+ removeOnUnmount,
2084
+ submitValueParser,
2085
+ validationFunction: actualValidationFunction,
2086
+ validationRules: actualValidationRules
2087
+ }), { onChange, updateValidations, isTouched } = _a2, inputProps = __objRest$1(_a2, ["onChange", "updateValidations", "isTouched"]);
2088
+ return /* @__PURE__ */ jsx(
2089
+ FieldWrapper,
2090
+ {
2091
+ name,
2092
+ label,
2093
+ className: `switchbox ${className != null ? className : ""}`,
2094
+ avoidSemicolon,
2095
+ children: /* @__PURE__ */ jsx(
2096
+ Switch,
2097
+ __spreadProps$1(__spreadValues$1(__spreadValues$1({}, props), inputProps), {
2098
+ "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
2099
+ onChange: (ev) => {
2100
+ onChange(ev.target.checked !== reverse ? "on" : "off");
2101
+ if (outerOnChange) {
2102
+ outerOnChange(ev);
2103
+ }
2104
+ },
2105
+ checked: ((_c = inputProps.value) != null ? _c : "off") === "on" !== reverse,
2106
+ ref
2107
+ })
2108
+ )
2109
+ }
2110
+ );
2111
+ }
2112
+ );
2113
+ Switchbox.displayName = "Switchbox";
2114
+
2115
+ var __defProp = Object.defineProperty;
2116
+ var __defProps = Object.defineProperties;
2117
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2118
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2119
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2120
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2121
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2122
+ var __spreadValues = (a, b) => {
2123
+ for (var prop in b || (b = {}))
2124
+ if (__hasOwnProp.call(b, prop))
2125
+ __defNormalProp(a, prop, b[prop]);
2126
+ if (__getOwnPropSymbols)
2127
+ for (var prop of __getOwnPropSymbols(b)) {
2128
+ if (__propIsEnum.call(b, prop))
2129
+ __defNormalProp(a, prop, b[prop]);
2130
+ }
2131
+ return a;
2132
+ };
2133
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2134
+ var __objRest = (source, exclude) => {
2135
+ var target = {};
2136
+ for (var prop in source)
2137
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
2138
+ target[prop] = source[prop];
2139
+ if (source != null && __getOwnPropSymbols)
2140
+ for (var prop of __getOwnPropSymbols(source)) {
2141
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
2142
+ target[prop] = source[prop];
2143
+ }
2144
+ return target;
2145
+ };
2146
+ const Textarea = React.forwardRef(
2147
+ (_a, ref) => {
2148
+ var _b = _a, {
2149
+ avoidSemicolon,
2150
+ className,
2151
+ formName,
2152
+ label,
2153
+ onChange: outerOnChange,
2154
+ avoidRegisterIfExists: avoidRegisterIfExists,
2155
+ initialValue,
2156
+ name,
2157
+ removeOnUnmount,
2158
+ submitValueParser,
2159
+ validationClass,
2160
+ validationFunction,
2161
+ validationRules,
2162
+ value
2163
+ } = _b, props = __objRest(_b, [
2164
+ "avoidSemicolon",
2165
+ "className",
2166
+ "formName",
2167
+ "label",
2168
+ "onChange",
2169
+ /**
2170
+ * useField
2171
+ */
2172
+ "avoidRegisterIfExists",
2173
+ "initialValue",
2174
+ "name",
2175
+ "removeOnUnmount",
2176
+ "submitValueParser",
2177
+ "validationClass",
2178
+ "validationFunction",
2179
+ "validationRules",
2180
+ "value"
2181
+ ]);
2182
+ var _b2, _c;
2183
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
2184
+ validationClass,
2185
+ validationFunction,
2186
+ validationRules
2187
+ });
2188
+ const _a2 = useField({
2189
+ avoidRegisterIfExists,
2190
+ formName,
2191
+ initialValue: initialValue != null ? initialValue : value,
2192
+ name,
2193
+ removeOnUnmount,
2194
+ submitValueParser,
2195
+ validationRules: actualValidationRules,
2196
+ validationFunction: actualValidationFunction
2197
+ }), { updateValidations, onChange, isTouched } = _a2, inputProps = __objRest(_a2, ["updateValidations", "onChange", "isTouched"]);
2198
+ const handleOnChange = React.useCallback(
2199
+ (ev) => {
2200
+ onChange(ev);
2201
+ if (outerOnChange) {
2202
+ outerOnChange(ev);
2203
+ }
2204
+ },
2205
+ [onChange, outerOnChange]
2206
+ );
2207
+ return /* @__PURE__ */ jsx(
2208
+ FieldWrapper,
2209
+ {
2210
+ name,
2211
+ label,
2212
+ className: `textarea ${className != null ? className : ""}`,
2213
+ avoidSemicolon,
2214
+ children: /* @__PURE__ */ jsx(
2215
+ Textarea$1,
2216
+ __spreadProps(__spreadValues(__spreadValues({}, props), inputProps), {
2217
+ "aria-label": (_b2 = props["aria-label"]) != null ? _b2 : label,
2218
+ ref,
2219
+ value: (_c = inputProps.value) != null ? _c : "",
2220
+ onChange: handleOnChange
2221
+ })
2222
+ )
2223
+ }
2224
+ );
2225
+ }
2226
+ );
2227
+ Textarea.displayName = "Textarea";
2228
+
2229
+ export { InnerCaptcha as Captcha, Checkbox, DeletableInput, FieldWrapper, FileInput, Form, FormContext, Input, NumberInputf, Radio, Select, Switchbox, Textarea, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };