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