@harnessio/forms 0.15.0 → 0.16.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/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +114 -104
- package/dist/index.js.map +1 -1
- package/dist/types/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
object-assign
|
|
3
3
|
(c) Sindre Sorhus
|
|
4
4
|
@license MIT
|
|
5
|
-
*/var B,te;function we(){if(te)return B;te=1;var r=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function t(s){if(s==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(s)}function o(){try{if(!Object.assign)return!1;var s=new String("abc");if(s[5]="de",Object.getOwnPropertyNames(s)[0]==="5")return!1;for(var a={},u=0;u<10;u++)a["_"+String.fromCharCode(u)]=u;var i=Object.getOwnPropertyNames(a).map(function(f){return a[f]});if(i.join("")!=="0123456789")return!1;var l={};return"abcdefghijklmnopqrst".split("").forEach(function(f){l[f]=f}),Object.keys(Object.assign({},l)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return B=o()?Object.assign:function(s,a){for(var u,i=t(s),l,f=1;f<arguments.length;f++){u=Object(arguments[f]);for(var
|
|
5
|
+
*/var B,te;function we(){if(te)return B;te=1;var r=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function t(s){if(s==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(s)}function o(){try{if(!Object.assign)return!1;var s=new String("abc");if(s[5]="de",Object.getOwnPropertyNames(s)[0]==="5")return!1;for(var a={},u=0;u<10;u++)a["_"+String.fromCharCode(u)]=u;var i=Object.getOwnPropertyNames(a).map(function(f){return a[f]});if(i.join("")!=="0123456789")return!1;var l={};return"abcdefghijklmnopqrst".split("").forEach(function(f){l[f]=f}),Object.keys(Object.assign({},l)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}return B=o()?Object.assign:function(s,a){for(var u,i=t(s),l,f=1;f<arguments.length;f++){u=Object(arguments[f]);for(var m in u)e.call(u,m)&&(i[m]=u[m]);if(r){l=r(u);for(var d=0;d<l.length;d++)n.call(u,l[d])&&(i[l[d]]=u[l[d]])}}return i},B}/** @license React v17.0.2
|
|
6
6
|
* react-jsx-runtime.production.min.js
|
|
7
7
|
*
|
|
8
8
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
9
9
|
*
|
|
10
10
|
* This source code is licensed under the MIT license found in the
|
|
11
11
|
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*/var ne;function Fe(){if(ne)return w;ne=1,we();var r=y,e=60103;if(w.Fragment=60107,typeof Symbol=="function"&&Symbol.for){var n=Symbol.for;e=n("react.element"),w.Fragment=n("react.fragment")}var t=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o=Object.prototype.hasOwnProperty,s={key:!0,ref:!0,__self:!0,__source:!0};function a(u,i,l){var f,d={},m=null,h=null;l!==void 0&&(m=""+l),i.key!==void 0&&(m=""+i.key),i.ref!==void 0&&(h=i.ref);for(f in i)o.call(i,f)&&!s.hasOwnProperty(f)&&(d[f]=i[f]);if(u&&u.defaultProps)for(f in i=u.defaultProps,i)d[f]===void 0&&(d[f]=i[f]);return{$$typeof:e,type:u,key:m,ref:h,props:d,_owner:t.current}}return w.jsx=a,w.jsxs=a,w}var se;function Pe(){return se||(se=1,N.exports=Fe()),N.exports}var g=Pe();const fe=y.createContext({});function xe({children:r,metadata:e,inputErrorHandler:n,readonly:t}){return g.jsx(fe.Provider,{value:{metadata:e,readonly:t,inputErrorHandler:n},children:r})}function le(){const r=y.useContext(fe);return r||console.warn("useRootFormContext must be used within RootFormProvider"),r}class Ae extends y.Component{constructor(){super(...arguments);D(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,t){var s,a;console.error(n,t);const o=new Error(`Form input [${this.props.inputType}] has failed at path [${this.props.path}]. Error: ${n}, Error info: ${t}`);(a=(s=this.props).inputErrorHandler)==null||a.call(s,o)}render(){return this.state.hasError?g.jsx(g.Fragment,{}):this.props.children}}const ae=({children:r,withoutWrapper:e=!1})=>e||!r?r:g.jsx("div",{children:r}),de=y.memo(function({path:e,factory:n,onUpdate:t,onChange:o,initialValues:s,input:a,withoutWrapper:u=!1}){var z,G,K,Q,X;const i=T.useFormContext(),{formState:l}=i,{fixedValues:f={}}={},{metadata:d,readonly:m,inputErrorHandler:h}=le(),v=n==null?void 0:n.getComponent(a.inputType),O=!!(a.isVisible||typeof a.disabled=="function"||typeof((z=a.validation)==null?void 0:z.schema)=="function"||typeof((G=a.warning)==null?void 0:G.schema)=="function"),E=!!((K=a.warning)!=null&&K.schema||(Q=a.validation)!=null&&Q.schema),b=O?i.watch():{},R=E?O?T.get(b,a.path):i.watch(a.path):void 0,I=y.useMemo(()=>{if(!O)return{};let P=b;return f&&Object.keys(f).forEach(q=>{const x=f[q];P=c.set(P,q,x)}),P},[O,b,f]),V=!a.isVisible||a.isVisible(I,d),C=m||a.readonly,S=typeof a.disabled=="function"?a.disabled(I,d):a.disabled,j=(X=a.warning)==null?void 0:X.schema,L=y.useMemo(()=>{var ee,re;if(!V||typeof j>"u")return;const P=typeof j=="function"?j(I,d):j,{success:q,error:x}=P.safeParse(R),Y=(re=(ee=x==null?void 0:x.errors)==null?void 0:ee[0])==null?void 0:re.message;return!q&&Y?Y:void 0},[a.path,R,j,V,d]),H=y.useMemo(()=>({path:e,key:e,initialValues:s,onUpdate:t,onChange:o,factory:n,readonly:C,input:a,disabled:S,warning:L}),[n,s,a,o,t,e,C,l.errors,S,L]),je=y.useMemo(()=>V?g.jsxs(g.Fragment,{children:[a.before?a.before:null,g.jsx(Ae,{path:e,inputType:a.inputType,inputErrorHandler:h,children:v==null?void 0:v.renderComponent(H)}),a.after?a.after:null]}):null,[V,a.before,a.inputType,a.after,e,v,H,l.errors]);return v?g.jsx(ae,{withoutWrapper:u,children:je}):g.jsx(ae,{withoutWrapper:u,children:g.jsxs("p",{children:["Input component not found (internal type: ",a.inputType,")"]})})});class qe{getType(){return this.internalType}}function oe(){return typeof window<"u"&&"requestIdleCallback"in window?window.requestIdleCallback:function(r,e){const n=Date.now(),t=(e==null?void 0:e.timeout)||1;return setTimeout(function(){r({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-n))}})},t)}}function ue(){return typeof window<"u"&&"cancelIdleCallback"in window?window.cancelIdleCallback:clearTimeout}function De(r){const{mode:e="onSubmit",resolver:n,defaultValues:t,shouldFocusError:o,onValuesChange:s,onValidationChange:a,onSubmit:u,onInputRenderError:i,metadata:l,children:f,autoFocusPath:d,readonly:m}=r,h=T.useForm({mode:e,reValidateMode:"onChange",defaultValues:t,shouldFocusError:o,resolver:n}),v=y.useRef(!1),O=y.useRef(JSON.stringify(t??{}));y.useEffect(()=>{O.current=JSON.stringify(t??{}),h.reset(t,{})},[h.reset,t]),y.useEffect(()=>{const C=oe(),S=ue(),j=C(()=>{h.reset({},{keepErrors:!0,keepDirty:!0,keepDirtyValues:!0,keepValues:!0,keepDefaultValues:!1,keepIsSubmitted:!0,keepTouched:!0,keepIsValid:!0,keepSubmitCount:!0})});return()=>S(j)},[]);const{handleSubmit:E}=h,b=y.useRef(s);y.useEffect(()=>{b.current=s},[s]);const R=y.useRef(a);y.useEffect(()=>{R.current=a},[a]);const I=y.useRef(!1);y.useEffect(()=>{const C=h.watch(S=>{var j;I.current||JSON.stringify(S??{})!==O.current&&((j=b.current)==null||j.call(b,{...S}),v.current===!0&&(I.current=!0,h.trigger().finally(()=>{I.current=!1})))});return()=>{C.unsubscribe()}},[h]);const V=y.useRef(!0);return y.useEffect(()=>{var C;if(V.current){V.current=!1;return}(C=R.current)==null||C.call(R,{isValid:h.formState.isValid,isSubmitted:h.formState.isSubmitted})},[h.formState.isValid,h.formState.isSubmitted]),y.useEffect(()=>{if(d){const C=oe(),S=ue(),j=C(()=>{h.setFocus(d)});return()=>S(j)}},[h,d]),g.jsx(xe,{metadata:l,readonly:m,inputErrorHandler:i,children:g.jsx(T.FormProvider,{...h,children:typeof f=="function"?f({...h,submitForm:async()=>{u&&(v.current=!0,E(C=>{u(C)})())}}):f})})}const ke=r=>{const e={},n=t=>{t.forEach(o=>{const{path:s,default:a,inputs:u}=o;Array.isArray(u)?n(u):c.get(e,s)===void 0&&c.set(e,s,a)})};return Array.isArray(r.inputs)&&n(r.inputs),e};function Me(r,e){const n=r.inputs.map(t=>{const o=Ne(e,t.path);return o||t});return{...r,inputs:n}}function Ne(r,e){return r.inputs.find(n=>n.path===e)}const me="__temp_",Be=r=>me+r.split(".").join("__");function pe(r){const e={...r};return c.forOwn(e,(n,t)=>{t.startsWith(me)&&delete e[t]}),e}const Ze="Required field";function F(r){let e;if(typeof r=="string")try{e=JSON.parse(r)}catch{e=r}else e=r;if(typeof e=="string")return e;if(c.isArray(e))return F(e[0]);const n=e;return c.isObject(n)&&(n!=null&&n.message)?e==null?void 0:e.message:"Unknown error"}function he(r,e,n){let t={};if(k(t,r.inputs,e,n),n!=null&&n.prefix){const s=n==null?void 0:n.prefix.replace(/.$/,"");t=c.set({},s,t)}return p.object(A(t,e,n))}function $e(r,e,n){const t=Object.keys(r).filter(a=>/^\d+$/.test(a)&&!a.startsWith("_")).map(a=>parseInt(a,10)).sort((a,u)=>a-u);if(t.length===0)return null;const o=Math.max(...t),s=[];for(let a=0;a<=o;a++)if(t.includes(a)){const u=r[a],i=A({item:u},e,n);s.push(i.item||p.any().optional())}else s.push(p.any().optional());return p.tuple(s).rest(p.any()).optional()}function A(r,e,n){const t={};return Object.keys(r).forEach(o=>{const{_requiredOnly:s,_schemaObj:a,_input:u,_isList:i,_isArrayItem:l,_isTuple:f,_schema:d}=r[o];if(f&&!i&&!l){const m=$e(r[o],e,n);if(m){t[o]=m;return}}if(i&&a&&u){const m=p.object(A(a,e,n)),h=p.union([p.array(m).optional(),ye(u,n)]),v=ie(d,u,e,n,h);t[o]=v}else if(l&&u){const m=a!=null&&a.___array?A({___array:a.___array},e,n):{___array:p.any()},h=We(m,u,n),v=ie(d,u,e,n,h);t[o]=v}else if(d&&u){const m=Ue(d,u,e,n);t[o]=m}else s&&u?t[o]=W(u,n):t[o]=p.object(A(r[o],e,n)).optional()}),t}function ye(r,e){return p.string().superRefine((n,t)=>{var o;if((o=e==null?void 0:e.validationConfig)!=null&&o.globalValidation){const s=e.validationConfig.globalValidation(n,r,e.metadata);if(s.error)return t.addIssue({code:p.ZodIssueCode.custom,message:s.error}),!1;if(!s.continue)return!0}return!0})}function We(r,e,n){return p.union([p.array(r.___array).optional(),ye(e,n)])}function Ue(r,e,n,t){return p.any().optional().superRefine(async(o,s)=>{var u,i;if(e.required&&!(await W(e,t).safeParseAsync(o)).success)return s.addIssue({code:p.ZodIssueCode.custom,message:Z(e,t)}),p.NEVER;if((u=t==null?void 0:t.validationConfig)!=null&&u.globalValidation){const l=(i=t==null?void 0:t.validationConfig)==null?void 0:i.globalValidation(o,e,t.metadata);if(l.error)return s.addIssue({code:p.ZodIssueCode.custom,message:l.error}),p.NEVER;if(!l.continue)return!0}const a=ge(r,n);if(a){const l=await a.safeParseAsync(o);if(!l.success){const f=F(l==null?void 0:l.error.message),d=f==="Required"?Z(e,t):f;s.addIssue({code:p.ZodIssueCode.custom,message:d})}}})}function ie(r,e,n,t,o){return p.any().optional().superRefine(async(s,a)=>{var f,d;const i=await W(e,t).safeParseAsync(s);if(e.required&&!i.success){const m=F(i.error.message);return a.addIssue({code:p.ZodIssueCode.custom,message:m,fatal:!0}),p.NEVER}if(!e.required&&!i.success)return p.NEVER;if((f=t==null?void 0:t.validationConfig)!=null&&f.globalValidation){const m=(d=t==null?void 0:t.validationConfig)==null?void 0:d.globalValidation(s,e,t.metadata);if(m.error)return a.addIssue({code:p.ZodIssueCode.custom,message:F(m.error)}),p.NEVER;if(!m.continue)return!0}if(!c.isArray(s))return a.addIssue({code:p.ZodIssueCode.custom,message:"'Value is not array'"}),p.NEVER;const l=ge(r,n);if(l){const m=await l.safeParseAsync(s);if(!m.success)return a.addIssue({code:p.ZodIssueCode.custom,message:F(m.error.message)}),p.NEVER}}).pipe(o??p.any())}function k(r,e,n,t,o){e.forEach(s=>{var u,i,l,f,d,m,h;const a=n;if(!s.isVisible||(u=s.isVisible)!=null&&u.call(s,a,t==null?void 0:t.metadata)){const v=c.get(r,s.path);if((i=s.validation)!=null&&i.schema?c.set(r,s.path,c.merge(v,{_schema:(l=s.validation)==null?void 0:l.schema,_input:s})):s.required&&c.set(r,s.path,c.merge(v,{_requiredOnly:!0,_input:s})),s.inputs&&k(r,s.inputs,n,t),s.inputType==="list"){const O={};k(O,(d=(f=s.inputConfig)==null?void 0:f.inputs)==null?void 0:d.map(b=>({...b,path:b.relativePath})),n,t);const E=c.get(r,s.path);c.set(r,s.path,c.merge(E,{_schemaObj:O,_isList:!0,_input:s}))}if(!((m=s.validation)!=null&&m.schema)&&s.inputType==="array"){const O={};k(O,[{...s.inputConfig.input,path:"___array"}],n,t),c.set(r,s.path,c.merge(v,{_schemaObj:O,_schema:(h=s.validation)==null?void 0:h.schema,_isArrayItem:!0,_input:s}))}}}),e.forEach(s=>{var u;const a=n;if((!s.isVisible||(u=s.isVisible)!=null&&u.call(s,a,t==null?void 0:t.metadata))&&s.path){const i=s.path.split(".");i.forEach((l,f)=>{if(f>0&&/^\d+$/.test(l)){const d=i.slice(0,f).join("."),m=d?c.get(r,d):r;m&&typeof m=="object"&&(m._isTuple=!0)}})}})}function Z(r,e){var n,t,o;return((t=(n=e==null?void 0:e.validationConfig)==null?void 0:n.requiredMessagePerInput)==null?void 0:t[r.inputType])??((o=e==null?void 0:e.validationConfig)==null?void 0:o.requiredMessage)??Ze}function W(r,e){var t,o,s,a,u,i;if((o=(t=e==null?void 0:e.validationConfig)==null?void 0:t.requiredSchemaPerInput)!=null&&o[r.inputType])return(a=(s=e==null?void 0:e.validationConfig)==null?void 0:s.requiredSchemaPerInput)==null?void 0:a[r.inputType];if((u=e==null?void 0:e.validationConfig)!=null&&u.requiredSchema)return(i=e==null?void 0:e.validationConfig)==null?void 0:i.requiredSchema;const n=Z(r,e);return p.any().optional().superRefine((l,f)=>{typeof l=="object"&&c.isEmpty(l)&&f.addIssue({code:p.ZodIssueCode.custom,message:n}),(c.isUndefined(l)||l==="")&&f.addIssue({code:p.ZodIssueCode.custom,message:n})})}function ge(r,e){if(r instanceof p.ZodType)return r;if(typeof r=="function")return r(e)}const Je=r=>Array.isArray(r==null?void 0:r.errors),Le=(r,e)=>{const n={};for(;r.length;){const t=r[0],{code:o,message:s,path:a}=t,u=a.join(".");if(!n[u])if("unionErrors"in t){const i=t.unionErrors[0].errors[0];n[u]={message:i.message,type:i.code}}else n[u]={message:s,type:o};"unionErrors"in t&&t.unionErrors.forEach(i=>i.errors.forEach(l=>r.push(l)));{const i=n[u].types,l=i&&i[t.code];n[u]=T.appendErrors(u,e,n,o,l?[].concat(l,t.message):t.message)}r.shift()}return n};function He(r,e){return y.useCallback(async(n,t,o)=>{try{return await he(r,n,e).parseAsync(n),{values:n,errors:{}}}catch(s){if(Je(s))return{values:{},errors:_e.toNestErrors(Le(s.errors,!0),o)};throw s}},[r,e])}function be(r,e){const n=c.cloneDeep(r);return e.forEach(t=>{if(t.inputTransform){const o=c.isArray(t.inputTransform)?t.inputTransform:[t.inputTransform];let s;const a=t.path.split(".");if(a.length>1){const u=a.slice(0,-1).join("."),i=c.get(n,u);typeof i=="string"||typeof i=="number"||typeof i=="boolean"?s=void 0:s=c.get(n,t.path)}else s=c.get(n,t.path);o.forEach(u=>{const i=u(s,n);i&&(s=i.value,c.set(n,i.path??t.path,i.value))})}}),n}function ve(r,e,n){const t=[];let o={};n||(o=c.cloneDeep(r));const s=c.cloneDeep(r);return e.forEach(a=>{if(a.outputTransform){const u=c.isArray(a.outputTransform)?a.outputTransform:[a.outputTransform];let i=c.get(s,a.path);u.forEach(l=>{const f=l(i,s);f&&(i=f.value,f.path?(c.set(o,f.path,f.value),f.unset&&t.push(a.path)):c.set(o,a.path,f.value))})}}),t.forEach(a=>{c.unset(o,a)}),o}function U(r){return r.reduce((n,t)=>Array.isArray(t.inputs)?[...n,t,...U(t.inputs)]:[...n,t],[])}const ze=r=>{if(r!==void 0)return{value:r}},Ge=r=>{if(r!==void 0)return{value:r}};function J(r,e){const t=U(r.inputs).reduce((o,s)=>{const a=s.inputType==="text"||s.inputType==="boolean"||s.inputType==="number"||s.inputType==="textarea"||s.inputType==="select",u=!!s.inputTransform,i=!!s.outputTransform,l=Array.isArray(s.inputs)&&s.inputs.length>0,f=s.inputType==="list"||s.inputType==="array";return u||i?o.push({path:s.path,inputTransform:s.inputTransform,outputTransform:s.outputTransform,level:s.path.split(".").length,isPrimitive:a}):e&&!(l||f)&&o.push({path:s.path,inputTransform:ze,outputTransform:Ge,level:s.path.split(".").length,isPrimitive:a}),o},[]);return t.sort((o,s)=>o.level===s.level?o.isPrimitive?1:-1:o.level<s.level?-1:1),t}function Oe(r,e,n,t={}){const{preserve:o}=t,s=U(r.inputs),a=c.cloneDeep(e);return s.forEach(u=>{o&&o.includes(u.path)||u.isVisible&&!u.isVisible(e,n)&&c.unset(a,u.path)}),a}function Ke(r,e){const n=J(e);return be(r,n)}function Qe(r,e,n,t={}){const o=t.cleanOutput,s=J(e,o);let a=Oe(e,r,n,t);return a=ve(a,s,t.cleanOutput),a=pe(a),a}function Xe(r){const e={},n=t=>{t.forEach(o=>{const{default:s,path:a,inputs:u}=o;Array.isArray(u)?n(u):s!==void 0&&c.set(e,a,s)})};return Array.isArray(r.inputs)&&n(r.inputs),e}function Ye(){return function(r,e){if(!(typeof r>"u"))return!r||!c.isPlainObject(r)?{value:r}:{value:Object.getOwnPropertyNames(r).map(n=>({key:n,value:r[n]}))}}}function er(r){return function(e,n){if(typeof e>"u")return;if(!e||!c.isArray(e))return{value:e};const t={value:e.reduce((o,s)=>({...o,[s.key]:r!=null&&r.assignKeyToValue?s.key:s.value??(r==null?void 0:r.fallbackValue)}),{})};return r!=null&&r.unsetIfEmpty&&Object.getOwnPropertyNames(t.value).length===0?{value:void 0}:t}}function rr(){return function(r,e){if(!(typeof r>"u"))return c.isArray(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function tr(r){return function(e,n){const t=r?c.get(n,r):e;if(!(typeof t>"u")){if(c.isNull(t))return{value:void 0,path:r};if(c.isObject(t)){const o=c.omitBy(t,c.isNil);if(c.isEmpty(o))return{value:void 0,path:r}}return{value:t,path:r}}}}function nr(){return function(r,e){if(!(typeof r>"u"))return c.isString(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function sr(r){return function(e,n){const t=c.get(n,r);if(typeof t=="string")return{value:t};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function ar(r){return function(e,n){if(typeof e>"u")return;if(!e)return{value:e};const t=c.get(n,r);if(typeof t=="object"){const o=ir(t);if(Object.getOwnPropertyNames(o).length===1)return{value:e,path:r}}return{value:e}}}function or(r){return function(e,n){const t=c.get(n,r);if(typeof t=="string")return{value:[t]};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function ur(r,e){return function(n,t){if(typeof n>"u")return;if(!n)return{value:n};const o=c.get(t,r);if(c.isArray(o)){if(o.length===1)return{value:o[0],path:r};if(o.length===0&&e!=null&&e.unsetIfEmpty)return{value:void 0,path:r}}return{value:n}}}function Te(r){return typeof r=="object"?!Object.getOwnPropertyNames(r).some(e=>!Te(r[e])):c.isUndefined(r)}function ir(r){return c.omitBy(r,e=>typeof e=="object"?Te(e):c.isUndefined(e))}function M(r){const{items:e,className:n,withoutWrapper:t=!0,...o}=r,s=e.map(a=>g.jsx(de,{input:a,path:a.path,...o},`${a.inputType}_${a.path}`));return t?g.jsx(g.Fragment,{children:s}):g.jsx("div",{className:n,children:s})}M.displayName="RenderInputs";const Ee=y.forwardRef((r,e)=>{const{inputs:n,className:t,factory:o,withoutWrapper:s}=r;return s?g.jsxs(y.Fragment,{children:[n.hero,g.jsx(M,{items:n.inputs,factory:o})]}):g.jsxs("div",{className:t,ref:e,children:[n.hero,g.jsx(M,{items:n.inputs,factory:o})]})});Ee.displayName="RenderForm";function cr(r){let e=!0;return c.forOwn(r,n=>{e=e&&(n===""||c.isNull(n)||c.isUndefined(n))}),e}const fr=(r="")=>c.capitalize(r.split("_").join(" ")),Ce=(r,e=2,n,t=1e3)=>{let o=!1;const s=()=>{requestAnimationFrame(()=>{o||(e-=1,e<=0?r():s())})};return n&&Date.now()-n<=t?(r(),()=>{}):(s(),()=>{o=!0})};function lr(r,e){return{...r,inputs:r.inputs.map(n=>_(n,e))}}function _(r,e){var i,l,f;const{override:n,...t}=r,o=e&&n?n[e]:void 0,{inputConfig:s,...a}=o||{},u=o?{...t,...a}:t;if((t.inputConfig||s)&&(u.inputConfig={...t.inputConfig,...s}),u.inputs&&(u.inputs=u.inputs.map(d=>_(d,e))),u.inputType==="list"&&u.inputConfig){const d=((i=t.inputConfig)==null?void 0:i.inputs)||[],m=(s==null?void 0:s.inputs)||[];if(d.length>0||m.length>0){const h=Math.max(d.length,m.length);u.inputConfig.inputs=Array.from({length:h},(v,O)=>{var R;const E=d[O],b=m[O];if(!E&&b)return _(b,e);if(E&&!b)return _(E,e);if(E&&b){const I=E.override?{...E.override}:{};return e&&b&&(I[e]=(R=E.override)!=null&&R[e]?{...E.override[e],...b}:b),_({...E,override:I},e)}}).filter(Boolean)}else u.inputConfig.inputs&&(u.inputConfig.inputs=u.inputConfig.inputs.map(h=>_(h,e)))}if(u.inputType==="array"&&u.inputConfig){const d=(l=t.inputConfig)==null?void 0:l.input,m=s==null?void 0:s.input;if(d&&m){const h=d.override?{...d.override}:{};e&&m&&(h[e]=(f=d.override)!=null&&f[e]?{...d.override[e],...m}:m),u.inputConfig.input=_({...d,override:h},e)}else u.inputConfig.input&&(u.inputConfig.input=_(u.inputConfig.input,e))}return u}function dr(r){const{field:{onBlur:e,...n},...t}=T.useController(r),o=y.useRef(Date.now());return{...t,field:{...n,onBlur:Ce(e,2,o.current)}}}Object.defineProperty(exports,"Controller",{enumerable:!0,get:()=>T.Controller});Object.defineProperty(exports,"Form",{enumerable:!0,get:()=>T.Form});Object.defineProperty(exports,"FormProvider",{enumerable:!0,get:()=>T.FormProvider});Object.defineProperty(exports,"get",{enumerable:!0,get:()=>T.get});Object.defineProperty(exports,"set",{enumerable:!0,get:()=>T.set});Object.defineProperty(exports,"useFieldArray",{enumerable:!0,get:()=>T.useFieldArray});Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>T.useForm});Object.defineProperty(exports,"useFormContext",{enumerable:!0,get:()=>T.useFormContext});Object.defineProperty(exports,"useFormState",{enumerable:!0,get:()=>T.useFormState});Object.defineProperty(exports,"useWatch",{enumerable:!0,get:()=>T.useWatch});exports.InputComponent=qe;exports.InputComponentRenderer=de;exports.InputFactory=$;exports.InputOverrideError=ce;exports.RenderForm=Ee;exports.RenderInputs=M;exports.RootForm=De;exports.afterFrames=Ce;exports.applyFormOverrides=lr;exports.applyInputOverride=_;exports.arrayToObjectOutputTransformer=er;exports.collectDefaultValues=Xe;exports.convertDataToFormModel=Ke;exports.convertFormModelToData=Qe;exports.generateReadableLabel=fr;exports.getDefaultValuesFromFormDefinition=ke;exports.getTemporaryPath=Be;exports.getTransformers=J;exports.getValidationSchema=he;exports.inputTransformValues=be;exports.isChildrenEmpty=cr;exports.objectToArrayInputTransformer=Ye;exports.outputTransformValues=ve;exports.overrideFormDefinition=Me;exports.processValidationParseResponse=F;exports.removeTemporaryFieldsValue=pe;exports.shorthandArrayInputTransformer=or;exports.shorthandArrayOutputTransformer=ur;exports.shorthandObjectInputTransformer=sr;exports.shorthandObjectOutputTransformer=ar;exports.unsetEmptyArrayOutputTransformer=rr;exports.unsetEmptyObjectOutputTransformer=tr;exports.unsetEmptyStringOutputTransformer=nr;exports.unsetHiddenInputsValues=Oe;exports.useController=dr;exports.useRootFormContext=le;exports.useZodValidationResolver=He;
|
|
12
|
+
*/var ne;function Fe(){if(ne)return w;ne=1,we();var r=y,e=60103;if(w.Fragment=60107,typeof Symbol=="function"&&Symbol.for){var n=Symbol.for;e=n("react.element"),w.Fragment=n("react.fragment")}var t=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o=Object.prototype.hasOwnProperty,s={key:!0,ref:!0,__self:!0,__source:!0};function a(u,i,l){var f,m={},d=null,h=null;l!==void 0&&(d=""+l),i.key!==void 0&&(d=""+i.key),i.ref!==void 0&&(h=i.ref);for(f in i)o.call(i,f)&&!s.hasOwnProperty(f)&&(m[f]=i[f]);if(u&&u.defaultProps)for(f in i=u.defaultProps,i)m[f]===void 0&&(m[f]=i[f]);return{$$typeof:e,type:u,key:d,ref:h,props:m,_owner:t.current}}return w.jsx=a,w.jsxs=a,w}var se;function Pe(){return se||(se=1,N.exports=Fe()),N.exports}var g=Pe();const fe=y.createContext({});function xe({children:r,metadata:e,inputErrorHandler:n,readonly:t}){return g.jsx(fe.Provider,{value:{metadata:e,readonly:t,inputErrorHandler:n},children:r})}function le(){const r=y.useContext(fe);return r||console.warn("useRootFormContext must be used within RootFormProvider"),r}class Ae extends y.Component{constructor(){super(...arguments);D(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(n,t){var s,a;console.error(n,t);const o=new Error(`Form input [${this.props.inputType}] has failed at path [${this.props.path}]. Error: ${n}, Error info: ${t}`);(a=(s=this.props).inputErrorHandler)==null||a.call(s,o)}render(){return this.state.hasError?g.jsx(g.Fragment,{}):this.props.children}}const ae=({children:r,withoutWrapper:e=!1})=>e||!r?r:g.jsx("div",{children:r}),de=y.memo(function({path:e,factory:n,onUpdate:t,onChange:o,initialValues:s,input:a,withoutWrapper:u=!1}){var z,G,K,Q,X;const i=T.useFormContext(),{formState:l}=i,{fixedValues:f={}}={},{metadata:m,readonly:d,inputErrorHandler:h}=le(),v=n==null?void 0:n.getComponent(a.inputType),O=!!(a.isVisible||typeof a.disabled=="function"||typeof((z=a.validation)==null?void 0:z.schema)=="function"||typeof((G=a.warning)==null?void 0:G.schema)=="function"),E=!!((K=a.warning)!=null&&K.schema||(Q=a.validation)!=null&&Q.schema),b=O?i.watch():{},R=E?O?T.get(b,a.path):i.watch(a.path):void 0,I=y.useMemo(()=>{if(!O)return{};let P=b;return f&&Object.keys(f).forEach(q=>{const x=f[q];P=c.set(P,q,x)}),P},[O,b,f]),V=!a.isVisible||a.isVisible(I,m),C=d||a.readonly,S=typeof a.disabled=="function"?a.disabled(I,m):a.disabled,j=(X=a.warning)==null?void 0:X.schema,L=y.useMemo(()=>{var ee,re;if(!V||typeof j>"u")return;const P=typeof j=="function"?j(I,m):j,{success:q,error:x}=P.safeParse(R),Y=(re=(ee=x==null?void 0:x.errors)==null?void 0:ee[0])==null?void 0:re.message;return!q&&Y?Y:void 0},[a.path,R,j,V,m]),H=y.useMemo(()=>({path:e,key:e,initialValues:s,onUpdate:t,onChange:o,factory:n,readonly:C,input:a,disabled:S,warning:L}),[n,s,a,o,t,e,C,l.errors,S,L]),je=y.useMemo(()=>V?g.jsxs(g.Fragment,{children:[a.before?a.before:null,g.jsx(Ae,{path:e,inputType:a.inputType,inputErrorHandler:h,children:v==null?void 0:v.renderComponent(H)}),a.after?a.after:null]}):null,[V,a.before,a.inputType,a.after,e,v,H,l.errors]);return v?g.jsx(ae,{withoutWrapper:u,children:je}):g.jsx(ae,{withoutWrapper:u,children:g.jsxs("p",{children:["Input component not found (internal type: ",a.inputType,")"]})})});class qe{getType(){return this.internalType}}function oe(){return typeof window<"u"&&"requestIdleCallback"in window?window.requestIdleCallback:function(r,e){const n=Date.now(),t=(e==null?void 0:e.timeout)||1;return setTimeout(function(){r({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-n))}})},t)}}function ue(){return typeof window<"u"&&"cancelIdleCallback"in window?window.cancelIdleCallback:clearTimeout}function De(r){const{mode:e="onSubmit",resolver:n,defaultValues:t,shouldFocusError:o,onValuesChange:s,onValidationChange:a,onSubmit:u,onInputRenderError:i,metadata:l,children:f,autoFocusPath:m,readonly:d}=r,h=T.useForm({mode:e,reValidateMode:"onChange",defaultValues:t,shouldFocusError:o,resolver:n}),v=y.useRef(!1),O=y.useRef(JSON.stringify(t??{}));y.useEffect(()=>{O.current=JSON.stringify(t??{}),h.reset(t,{})},[h.reset,t]),y.useEffect(()=>{const C=oe(),S=ue(),j=C(()=>{h.reset({},{keepErrors:!0,keepDirty:!0,keepDirtyValues:!0,keepValues:!0,keepDefaultValues:!1,keepIsSubmitted:!0,keepTouched:!0,keepIsValid:!0,keepSubmitCount:!0})});return()=>S(j)},[]);const{handleSubmit:E}=h,b=y.useRef(s);y.useEffect(()=>{b.current=s},[s]);const R=y.useRef(a);y.useEffect(()=>{R.current=a},[a]);const I=y.useRef(!1);y.useEffect(()=>{const C=h.watch(S=>{var j;I.current||JSON.stringify(S??{})!==O.current&&((j=b.current)==null||j.call(b,{...S}),v.current===!0&&(I.current=!0,h.trigger().finally(()=>{I.current=!1})))});return()=>{C.unsubscribe()}},[h]);const V=y.useRef(!0);return y.useEffect(()=>{var C;if(V.current){V.current=!1;return}(C=R.current)==null||C.call(R,{isValid:h.formState.isValid,isSubmitted:h.formState.isSubmitted})},[h.formState.isValid,h.formState.isSubmitted]),y.useEffect(()=>{if(m){const C=oe(),S=ue(),j=C(()=>{h.setFocus(m)});return()=>S(j)}},[h,m]),g.jsx(xe,{metadata:l,readonly:d,inputErrorHandler:i,children:g.jsx(T.FormProvider,{...h,children:typeof f=="function"?f({...h,submitForm:async()=>{u&&(v.current=!0,E(C=>{u(C)})())}}):f})})}const ke=r=>{const e={},n=t=>{t.forEach(o=>{const{path:s,default:a,inputs:u}=o;Array.isArray(u)?n(u):c.get(e,s)===void 0&&c.set(e,s,a)})};return Array.isArray(r.inputs)&&n(r.inputs),e};function Me(r,e){const n=r.inputs.map(t=>{const o=Ne(e,t.path);return o||t});return{...r,inputs:n}}function Ne(r,e){return r.inputs.find(n=>n.path===e)}const me="__temp_",Be=r=>me+r.split(".").join("__");function pe(r){const e={...r};return c.forOwn(e,(n,t)=>{t.startsWith(me)&&delete e[t]}),e}const Ze="Required field";function F(r){let e;if(typeof r=="string")try{e=JSON.parse(r)}catch{e=r}else e=r;if(typeof e=="string")return e;if(c.isArray(e))return F(e[0]);const n=e;return c.isObject(n)&&(n!=null&&n.message)?e==null?void 0:e.message:"Unknown error"}function he(r,e,n){let t={};if(k(t,r.inputs,e,n),n!=null&&n.prefix){const s=n==null?void 0:n.prefix.replace(/.$/,"");t=c.set({},s,t)}return p.object(A(t,e,n))}function $e(r,e,n){const t=Object.keys(r).filter(a=>/^\d+$/.test(a)&&!a.startsWith("_")).map(a=>parseInt(a,10)).sort((a,u)=>a-u);if(t.length===0)return null;const o=Math.max(...t),s=[];for(let a=0;a<=o;a++)if(t.includes(a)){const u=r[a],i=A({item:u},e,n);s.push(i.item||p.any().optional())}else s.push(p.any().optional());return p.tuple(s).rest(p.any()).optional()}function A(r,e,n){const t={};return Object.keys(r).forEach(o=>{const{_requiredOnly:s,_schemaObj:a,_input:u,_isList:i,_isArrayItem:l,_isTuple:f,_schema:m}=r[o];if(f&&!i&&!l){const d=$e(r[o],e,n);if(d){t[o]=d;return}}if(i&&a&&u){const d=p.object(A(a,e,n)),h=p.union([p.array(d).optional(),ye(u,n)]),v=ie(m,u,e,n,h);t[o]=v}else if(l&&u){const d=a!=null&&a.___array?A({___array:a.___array},e,n):{___array:p.any()},h=We(d,u,n),v=ie(m,u,e,n,h);t[o]=v}else if(m&&u){const d=Ue(m,u,e,n);t[o]=d}else s&&u?t[o]=W(u,n):t[o]=p.object(A(r[o],e,n)).optional()}),t}function ye(r,e){return p.string().superRefine((n,t)=>{var o;if((o=e==null?void 0:e.validationConfig)!=null&&o.globalValidation){const s=e.validationConfig.globalValidation(n,r,e.metadata);if(s.error)return t.addIssue({code:p.ZodIssueCode.custom,message:s.error}),!1;if(!s.continue)return!0}return!0})}function We(r,e,n){return p.union([p.array(r.___array).optional(),ye(e,n)])}function Ue(r,e,n,t){return p.any().optional().superRefine(async(o,s)=>{var u,i;if(e.required&&!(await W(e,t).safeParseAsync(o)).success)return s.addIssue({code:p.ZodIssueCode.custom,message:Z(e,t)}),p.NEVER;if((u=t==null?void 0:t.validationConfig)!=null&&u.globalValidation){const l=(i=t==null?void 0:t.validationConfig)==null?void 0:i.globalValidation(o,e,t.metadata);if(l.error)return s.addIssue({code:p.ZodIssueCode.custom,message:l.error}),p.NEVER;if(!l.continue)return!0}const a=ge(r,n);if(a){const l=await a.safeParseAsync(o);if(!l.success){const f=F(l==null?void 0:l.error.message),m=f==="Required"?Z(e,t):f;s.addIssue({code:p.ZodIssueCode.custom,message:m})}}})}function ie(r,e,n,t,o){return p.any().optional().superRefine(async(s,a)=>{var f,m;const i=await W(e,t).safeParseAsync(s);if(e.required&&!i.success){const d=F(i.error.message);return a.addIssue({code:p.ZodIssueCode.custom,message:d,fatal:!0}),p.NEVER}if(!e.required&&!i.success)return p.NEVER;if((f=t==null?void 0:t.validationConfig)!=null&&f.globalValidation){const d=(m=t==null?void 0:t.validationConfig)==null?void 0:m.globalValidation(s,e,t.metadata);if(d.error)return a.addIssue({code:p.ZodIssueCode.custom,message:F(d.error)}),p.NEVER;if(!d.continue)return!0}if(!c.isArray(s))return a.addIssue({code:p.ZodIssueCode.custom,message:"'Value is not array'"}),p.NEVER;const l=ge(r,n);if(l){const d=await l.safeParseAsync(s);if(!d.success)return a.addIssue({code:p.ZodIssueCode.custom,message:F(d.error.message)}),p.NEVER}}).pipe(o??p.any())}function k(r,e,n,t,o){e.forEach(s=>{var u,i,l,f,m,d,h;const a=n;if(!s.isVisible||(u=s.isVisible)!=null&&u.call(s,a,t==null?void 0:t.metadata)){const v=c.get(r,s.path);if((i=s.validation)!=null&&i.schema?c.set(r,s.path,c.merge(v,{_schema:(l=s.validation)==null?void 0:l.schema,_input:s})):s.required&&c.set(r,s.path,c.merge(v,{_requiredOnly:!0,_input:s})),s.inputs&&k(r,s.inputs,n,t),s.inputType==="list"){const O={};k(O,(m=(f=s.inputConfig)==null?void 0:f.inputs)==null?void 0:m.map(b=>({...b,path:b.relativePath})),n,t);const E=c.get(r,s.path);c.set(r,s.path,c.merge(E,{_schemaObj:O,_isList:!0,_input:s}))}if(!((d=s.validation)!=null&&d.schema)&&s.inputType==="array"){const O={};k(O,[{...s.inputConfig.input,path:"___array"}],n,t),c.set(r,s.path,c.merge(v,{_schemaObj:O,_schema:(h=s.validation)==null?void 0:h.schema,_isArrayItem:!0,_input:s}))}}}),e.forEach(s=>{var u;const a=n;if((!s.isVisible||(u=s.isVisible)!=null&&u.call(s,a,t==null?void 0:t.metadata))&&s.path){const i=s.path.split(".");i.forEach((l,f)=>{if(f>0&&/^\d+$/.test(l)){const m=i.slice(0,f).join("."),d=m?c.get(r,m):r;d&&typeof d=="object"&&(d._isTuple=!0)}})}})}function Z(r,e){var n,t,o;return((t=(n=e==null?void 0:e.validationConfig)==null?void 0:n.requiredMessagePerInput)==null?void 0:t[r.inputType])??((o=e==null?void 0:e.validationConfig)==null?void 0:o.requiredMessage)??Ze}function W(r,e){var t,o,s,a,u,i;if((o=(t=e==null?void 0:e.validationConfig)==null?void 0:t.requiredSchemaPerInput)!=null&&o[r.inputType])return(a=(s=e==null?void 0:e.validationConfig)==null?void 0:s.requiredSchemaPerInput)==null?void 0:a[r.inputType];if((u=e==null?void 0:e.validationConfig)!=null&&u.requiredSchema)return(i=e==null?void 0:e.validationConfig)==null?void 0:i.requiredSchema;const n=Z(r,e);return p.any().optional().superRefine((l,f)=>{typeof l=="object"&&c.isEmpty(l)&&f.addIssue({code:p.ZodIssueCode.custom,message:n}),(c.isUndefined(l)||l==="")&&f.addIssue({code:p.ZodIssueCode.custom,message:n})})}function ge(r,e){if(r instanceof p.ZodType)return r;if(typeof r=="function")return r(e)}const Je=r=>Array.isArray(r==null?void 0:r.errors),Le=(r,e)=>{const n={};for(;r.length;){const t=r[0],{code:o,message:s,path:a}=t,u=a.join(".");if(!n[u])if("unionErrors"in t){const i=t.unionErrors[0].errors[0];n[u]={message:i.message,type:i.code}}else n[u]={message:s,type:o};"unionErrors"in t&&t.unionErrors.forEach(i=>i.errors.forEach(l=>r.push(l)));{const i=n[u].types,l=i&&i[t.code];n[u]=T.appendErrors(u,e,n,o,l?[].concat(l,t.message):t.message)}r.shift()}return n};function He(r,e){return y.useCallback(async(n,t,o)=>{try{return await he(r,n,e).parseAsync(n),{values:n,errors:{}}}catch(s){if(Je(s))return{values:{},errors:_e.toNestErrors(Le(s.errors,!0),o)};throw s}},[r,e])}function be(r,e){const n=c.cloneDeep(r);return e.forEach(t=>{if(t.inputTransform){const o=c.isArray(t.inputTransform)?t.inputTransform:[t.inputTransform];let s;const a=t.path.split(".");if(a.length>1){const u=a.slice(0,-1).join("."),i=c.get(n,u);typeof i=="string"||typeof i=="number"||typeof i=="boolean"?s=void 0:s=c.get(n,t.path)}else s=c.get(n,t.path);o.forEach(u=>{const i=u(s,n);i&&(s=i.value,c.set(n,i.path??t.path,i.value))})}}),n}function ve(r,e,n){const t=[];let o={};n||(o=c.cloneDeep(r));const s=c.cloneDeep(r);return e.forEach(a=>{if(a.outputTransform){const u=c.isArray(a.outputTransform)?a.outputTransform:[a.outputTransform];let i=c.get(s,a.path);u.forEach(l=>{const f=l(i,s);if(f)if(i=f.value,f.path){if(f.merge){const m=c.get(o,f.path);let d;m?d=c.merge({},m,f.value):d=f.value,c.set(o,f.path,d)}else c.set(o,f.path,f.value);f.unset&&t.push(a.path)}else c.set(o,a.path,f.value)})}}),t.forEach(a=>{c.unset(o,a)}),o}function U(r){return r.reduce((n,t)=>Array.isArray(t.inputs)?[...n,t,...U(t.inputs)]:[...n,t],[])}const ze=r=>{if(r!==void 0)return{value:r}},Ge=r=>{if(r!==void 0)return{value:r}};function J(r,e){const t=U(r.inputs).reduce((o,s)=>{const a=s.inputType==="text"||s.inputType==="boolean"||s.inputType==="number"||s.inputType==="textarea"||s.inputType==="select",u=!!s.inputTransform,i=!!s.outputTransform,l=Array.isArray(s.inputs)&&s.inputs.length>0,f=s.inputType==="list"||s.inputType==="array";return u||i?o.push({path:s.path,inputTransform:s.inputTransform,outputTransform:s.outputTransform,level:s.path.split(".").length,isPrimitive:a}):e&&!(l||f)&&o.push({path:s.path,inputTransform:ze,outputTransform:Ge,level:s.path.split(".").length,isPrimitive:a}),o},[]);return t.sort((o,s)=>o.level===s.level?o.isPrimitive?1:-1:o.level<s.level?-1:1),t}function Oe(r,e,n,t={}){const{preserve:o}=t,s=U(r.inputs),a=c.cloneDeep(e);return s.forEach(u=>{o&&o.includes(u.path)||u.isVisible&&!u.isVisible(e,n)&&c.unset(a,u.path)}),a}function Ke(r,e){const n=J(e);return be(r,n)}function Qe(r,e,n,t={}){const o=t.cleanOutput,s=J(e,o);let a=Oe(e,r,n,t);return a=ve(a,s,t.cleanOutput),a=pe(a),a}function Xe(r){const e={},n=t=>{t.forEach(o=>{const{default:s,path:a,inputs:u}=o;Array.isArray(u)?n(u):s!==void 0&&c.set(e,a,s)})};return Array.isArray(r.inputs)&&n(r.inputs),e}function Ye(){return function(r,e){if(!(typeof r>"u"))return!r||!c.isPlainObject(r)?{value:r}:{value:Object.getOwnPropertyNames(r).map(n=>({key:n,value:r[n]}))}}}function er(r){return function(e,n){if(typeof e>"u")return;if(!e||!c.isArray(e))return{value:e};const t={value:e.reduce((o,s)=>({...o,[s.key]:r!=null&&r.assignKeyToValue?s.key:s.value??(r==null?void 0:r.fallbackValue)}),{})};return r!=null&&r.unsetIfEmpty&&Object.getOwnPropertyNames(t.value).length===0?{value:void 0}:t}}function rr(){return function(r,e){if(!(typeof r>"u"))return c.isArray(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function tr(r){return function(e,n){const t=r?c.get(n,r):e;if(!(typeof t>"u")){if(c.isNull(t))return{value:void 0,path:r};if(c.isObject(t)){const o=c.omitBy(t,c.isNil);if(c.isEmpty(o))return{value:void 0,path:r}}return{value:t,path:r}}}}function nr(){return function(r,e){if(!(typeof r>"u"))return c.isString(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function sr(r){return function(e,n){const t=c.get(n,r);if(typeof t=="string")return{value:t};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function ar(r){return function(e,n){if(typeof e>"u")return;if(!e)return{value:e};const t=c.get(n,r);if(typeof t=="object"){const o=ir(t);if(Object.getOwnPropertyNames(o).length===1)return{value:e,path:r}}return{value:e}}}function or(r){return function(e,n){const t=c.get(n,r);if(typeof t=="string")return{value:[t]};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function ur(r,e){return function(n,t){if(typeof n>"u")return;if(!n)return{value:n};const o=c.get(t,r);if(c.isArray(o)){if(o.length===1)return{value:o[0],path:r};if(o.length===0&&e!=null&&e.unsetIfEmpty)return{value:void 0,path:r}}return{value:n}}}function Te(r){return typeof r=="object"?!Object.getOwnPropertyNames(r).some(e=>!Te(r[e])):c.isUndefined(r)}function ir(r){return c.omitBy(r,e=>typeof e=="object"?Te(e):c.isUndefined(e))}function M(r){const{items:e,className:n,withoutWrapper:t=!0,...o}=r,s=e.map(a=>g.jsx(de,{input:a,path:a.path,...o},`${a.inputType}_${a.path}`));return t?g.jsx(g.Fragment,{children:s}):g.jsx("div",{className:n,children:s})}M.displayName="RenderInputs";const Ee=y.forwardRef((r,e)=>{const{inputs:n,className:t,factory:o,withoutWrapper:s}=r;return s?g.jsxs(y.Fragment,{children:[n.hero,g.jsx(M,{items:n.inputs,factory:o})]}):g.jsxs("div",{className:t,ref:e,children:[n.hero,g.jsx(M,{items:n.inputs,factory:o})]})});Ee.displayName="RenderForm";function cr(r){let e=!0;return c.forOwn(r,n=>{e=e&&(n===""||c.isNull(n)||c.isUndefined(n))}),e}const fr=(r="")=>c.capitalize(r.split("_").join(" ")),Ce=(r,e=2,n,t=1e3)=>{let o=!1;const s=()=>{requestAnimationFrame(()=>{o||(e-=1,e<=0?r():s())})};return n&&Date.now()-n<=t?(r(),()=>{}):(s(),()=>{o=!0})};function lr(r,e){return{...r,inputs:r.inputs.map(n=>_(n,e))}}function _(r,e){var i,l,f;const{override:n,...t}=r,o=e&&n?n[e]:void 0,{inputConfig:s,...a}=o||{},u=o?{...t,...a}:t;if((t.inputConfig||s)&&(u.inputConfig={...t.inputConfig,...s}),u.inputs&&(u.inputs=u.inputs.map(m=>_(m,e))),u.inputType==="list"&&u.inputConfig){const m=((i=t.inputConfig)==null?void 0:i.inputs)||[],d=(s==null?void 0:s.inputs)||[];if(m.length>0||d.length>0){const h=Math.max(m.length,d.length);u.inputConfig.inputs=Array.from({length:h},(v,O)=>{var R;const E=m[O],b=d[O];if(!E&&b)return _(b,e);if(E&&!b)return _(E,e);if(E&&b){const I=E.override?{...E.override}:{};return e&&b&&(I[e]=(R=E.override)!=null&&R[e]?{...E.override[e],...b}:b),_({...E,override:I},e)}}).filter(Boolean)}else u.inputConfig.inputs&&(u.inputConfig.inputs=u.inputConfig.inputs.map(h=>_(h,e)))}if(u.inputType==="array"&&u.inputConfig){const m=(l=t.inputConfig)==null?void 0:l.input,d=s==null?void 0:s.input;if(m&&d){const h=m.override?{...m.override}:{};e&&d&&(h[e]=(f=m.override)!=null&&f[e]?{...m.override[e],...d}:d),u.inputConfig.input=_({...m,override:h},e)}else u.inputConfig.input&&(u.inputConfig.input=_(u.inputConfig.input,e))}return u}function dr(r){const{field:{onBlur:e,...n},...t}=T.useController(r),o=y.useRef(Date.now());return{...t,field:{...n,onBlur:Ce(e,2,o.current)}}}Object.defineProperty(exports,"Controller",{enumerable:!0,get:()=>T.Controller});Object.defineProperty(exports,"Form",{enumerable:!0,get:()=>T.Form});Object.defineProperty(exports,"FormProvider",{enumerable:!0,get:()=>T.FormProvider});Object.defineProperty(exports,"get",{enumerable:!0,get:()=>T.get});Object.defineProperty(exports,"set",{enumerable:!0,get:()=>T.set});Object.defineProperty(exports,"useFieldArray",{enumerable:!0,get:()=>T.useFieldArray});Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>T.useForm});Object.defineProperty(exports,"useFormContext",{enumerable:!0,get:()=>T.useFormContext});Object.defineProperty(exports,"useFormState",{enumerable:!0,get:()=>T.useFormState});Object.defineProperty(exports,"useWatch",{enumerable:!0,get:()=>T.useWatch});exports.InputComponent=qe;exports.InputComponentRenderer=de;exports.InputFactory=$;exports.InputOverrideError=ce;exports.RenderForm=Ee;exports.RenderInputs=M;exports.RootForm=De;exports.afterFrames=Ce;exports.applyFormOverrides=lr;exports.applyInputOverride=_;exports.arrayToObjectOutputTransformer=er;exports.collectDefaultValues=Xe;exports.convertDataToFormModel=Ke;exports.convertFormModelToData=Qe;exports.generateReadableLabel=fr;exports.getDefaultValuesFromFormDefinition=ke;exports.getTemporaryPath=Be;exports.getTransformers=J;exports.getValidationSchema=he;exports.inputTransformValues=be;exports.isChildrenEmpty=cr;exports.objectToArrayInputTransformer=Ye;exports.outputTransformValues=ve;exports.overrideFormDefinition=Me;exports.processValidationParseResponse=F;exports.removeTemporaryFieldsValue=pe;exports.shorthandArrayInputTransformer=or;exports.shorthandArrayOutputTransformer=ur;exports.shorthandObjectInputTransformer=sr;exports.shorthandObjectOutputTransformer=ar;exports.unsetEmptyArrayOutputTransformer=rr;exports.unsetEmptyObjectOutputTransformer=tr;exports.unsetEmptyStringOutputTransformer=nr;exports.unsetHiddenInputsValues=Oe;exports.useController=dr;exports.useRootFormContext=le;exports.useZodValidationResolver=He;
|
|
13
13
|
//# sourceMappingURL=index.cjs.map
|