@harnessio/forms 0.14.0 → 0.15.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 CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";var Re=Object.defineProperty;var Se=(r,e,n)=>e in r?Re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n;var q=(r,e,n)=>Se(r,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es"),y=require("react"),T=require("react-hook-form"),Ie=require("zod"),_e=require("@hookform/resolvers");function Ce(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const n in r)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(r,n);Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>r[n]})}}return e.default=r,Object.freeze(e)}const m=Ce(Ie);class ie extends Error{constructor(e){super(`Input component '${e}' is already registered.`)}}class ${constructor(e){q(this,"componentBank");q(this,"allowOverride");this.allowOverride=(e==null?void 0:e.allowOverride)??!1,this.componentBank=new Map}registerComponent(e){if(!this.allowOverride&&this.getComponent(e.internalType))throw new ie(e.internalType);this.componentBank.set(e.internalType,e)}getComponent(e){if(e&&!i.isEmpty(e))return this.componentBank.get(e)}listRegisteredComponents(){return Array.from(this.componentBank.keys())}clone(){const e=new $({allowOverride:this.allowOverride});return this.listRegisteredComponents().forEach(n=>{e.registerComponent(this.componentBank.get(n))}),e}}var N={exports:{}},C={};/*
1
+ "use strict";var Re=Object.defineProperty;var Ie=(r,e,n)=>e in r?Re(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n;var D=(r,e,n)=>Ie(r,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-es"),y=require("react"),T=require("react-hook-form"),Se=require("zod"),_e=require("@hookform/resolvers");function Ve(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const n in r)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(r,n);Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>r[n]})}}return e.default=r,Object.freeze(e)}const p=Ve(Se);class ce extends Error{constructor(e){super(`Input component '${e}' is already registered.`)}}class ${constructor(e){D(this,"componentBank");D(this,"allowOverride");this.allowOverride=(e==null?void 0:e.allowOverride)??!1,this.componentBank=new Map}registerComponent(e){if(!this.allowOverride&&this.getComponent(e.internalType))throw new ce(e.internalType);this.componentBank.set(e.internalType,e)}getComponent(e){if(e&&!c.isEmpty(e))return this.componentBank.get(e)}listRegisteredComponents(){return Array.from(this.componentBank.keys())}clone(){const e=new $({allowOverride:this.allowOverride});return this.listRegisteredComponents().forEach(n=>{e.registerComponent(this.componentBank.get(n))}),e}}var N={exports:{}},w={};/*
2
2
  object-assign
3
3
  (c) Sindre Sorhus
4
4
  @license MIT
5
- */var M,re;function Ve(){if(re)return M;re=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 c=Object.getOwnPropertyNames(a).map(function(f){return a[f]});if(c.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 M=o()?Object.assign:function(s,a){for(var u,c=t(s),l,f=1;f<arguments.length;f++){u=Object(arguments[f]);for(var h in u)e.call(u,h)&&(c[h]=u[h]);if(r){l=r(u);for(var d=0;d<l.length;d++)n.call(u,l[d])&&(c[l[d]]=u[l[d]])}}return c},M}/** @license React v17.0.2
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 d in u)e.call(u,d)&&(i[d]=u[d]);if(r){l=r(u);for(var m=0;m<l.length;m++)n.call(u,l[m])&&(i[l[m]]=u[l[m]])}}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 te;function we(){if(te)return C;te=1,Ve();var r=y,e=60103;if(C.Fragment=60107,typeof Symbol=="function"&&Symbol.for){var n=Symbol.for;e=n("react.element"),C.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,c,l){var f,h={},d=null,p=null;l!==void 0&&(d=""+l),c.key!==void 0&&(d=""+c.key),c.ref!==void 0&&(p=c.ref);for(f in c)o.call(c,f)&&!s.hasOwnProperty(f)&&(h[f]=c[f]);if(u&&u.defaultProps)for(f in c=u.defaultProps,c)h[f]===void 0&&(h[f]=c[f]);return{$$typeof:e,type:u,key:d,ref:p,props:h,_owner:t.current}}return C.jsx=a,C.jsxs=a,C}var ne;function Fe(){return ne||(ne=1,N.exports=we()),N.exports}var g=Fe();const ce=y.createContext({});function Pe({children:r,metadata:e,inputErrorHandler:n,readonly:t}){return g.jsx(ce.Provider,{value:{metadata:e,readonly:t,inputErrorHandler:n},children:r})}function fe(){const r=y.useContext(ce);return r||console.warn("useRootFormContext must be used within RootFormProvider"),r}class xe extends y.Component{constructor(){super(...arguments);q(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 se=({children:r,withoutWrapper:e=!1})=>e||!r?r:g.jsx("div",{children:r}),le=y.memo(function({path:e,factory:n,onUpdate:t,onChange:o,initialValues:s,input:a,withoutWrapper:u=!1}){var H,z,G,K,Q;const c=T.useFormContext(),{formState:l}=c,{fixedValues:f={}}={},{metadata:h,readonly:d,inputErrorHandler:p}=fe(),b=n==null?void 0:n.getComponent(a.inputType),v=!!(a.isVisible||typeof a.disabled=="function"||typeof((H=a.validation)==null?void 0:H.schema)=="function"||typeof((z=a.warning)==null?void 0:z.schema)=="function"),w=!!((G=a.warning)!=null&&G.schema||(K=a.validation)!=null&&K.schema),j=v?c.watch():{},S=w?v?T.get(j,a.path):c.watch(a.path):void 0,I=y.useMemo(()=>{if(!v)return{};let F=j;return f&&Object.keys(f).forEach(A=>{const P=f[A];F=i.set(F,A,P)}),F},[v,j,f]),_=!a.isVisible||a.isVisible(I,h),O=d||a.readonly,R=typeof a.disabled=="function"?a.disabled(I,h):a.disabled,E=(Q=a.warning)==null?void 0:Q.schema,J=y.useMemo(()=>{var Y,ee;if(!_||typeof E>"u")return;const F=typeof E=="function"?E(I,h):E,{success:A,error:P}=F.safeParse(S),X=(ee=(Y=P==null?void 0:P.errors)==null?void 0:Y[0])==null?void 0:ee.message;return!A&&X?X:void 0},[a.path,S,E,_,h]),L=y.useMemo(()=>({path:e,key:e,initialValues:s,onUpdate:t,onChange:o,factory:n,readonly:O,input:a,disabled:R,warning:J}),[n,s,a,o,t,e,O,l.errors,R,J]),je=y.useMemo(()=>_?g.jsxs(g.Fragment,{children:[a.before?a.before:null,g.jsx(xe,{path:e,inputType:a.inputType,inputErrorHandler:p,children:b==null?void 0:b.renderComponent(L)}),a.after?a.after:null]}):null,[_,a.before,a.inputType,a.after,e,b,L,l.errors]);return b?g.jsx(se,{withoutWrapper:u,children:je}):g.jsx(se,{withoutWrapper:u,children:g.jsxs("p",{children:["Input component not found (internal type: ",a.inputType,")"]})})});class Ae{getType(){return this.internalType}}function ae(){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 oe(){return typeof window<"u"&&"cancelIdleCallback"in window?window.cancelIdleCallback:clearTimeout}function qe(r){const{mode:e="onSubmit",resolver:n,defaultValues:t,shouldFocusError:o,onValuesChange:s,onValidationChange:a,onSubmit:u,onInputRenderError:c,metadata:l,children:f,autoFocusPath:h,readonly:d}=r,p=T.useForm({mode:e,reValidateMode:"onChange",defaultValues:t,shouldFocusError:o,resolver:n}),b=y.useRef(!1),v=y.useRef(JSON.stringify(t??{}));y.useEffect(()=>{v.current=JSON.stringify(t??{}),p.reset(t,{})},[p.reset,t]),y.useEffect(()=>{const O=ae(),R=oe(),E=O(()=>{p.reset({},{keepErrors:!0,keepDirty:!0,keepDirtyValues:!0,keepValues:!0,keepDefaultValues:!1,keepIsSubmitted:!0,keepTouched:!0,keepIsValid:!0,keepSubmitCount:!0})});return()=>R(E)},[]);const{handleSubmit:w}=p,j=y.useRef(s);y.useEffect(()=>{j.current=s},[s]);const S=y.useRef(a);y.useEffect(()=>{S.current=a},[a]);const I=y.useRef(!1);y.useEffect(()=>{const O=p.watch(R=>{var E;I.current||JSON.stringify(R??{})!==v.current&&((E=j.current)==null||E.call(j,{...R}),b.current===!0&&(I.current=!0,p.trigger().finally(()=>{I.current=!1})))});return()=>{O.unsubscribe()}},[p]);const _=y.useRef(!0);return y.useEffect(()=>{var O;if(_.current){_.current=!1;return}(O=S.current)==null||O.call(S,{isValid:p.formState.isValid,isSubmitted:p.formState.isSubmitted})},[p.formState.isValid,p.formState.isSubmitted]),y.useEffect(()=>{if(h){const O=ae(),R=oe(),E=O(()=>{p.setFocus(h)});return()=>R(E)}},[p,h]),g.jsx(Pe,{metadata:l,readonly:d,inputErrorHandler:c,children:g.jsx(T.FormProvider,{...p,children:typeof f=="function"?f({...p,submitForm:async()=>{u&&(b.current=!0,w(O=>{u(O)})())}}):f})})}const De=r=>{const e={},n=t=>{t.forEach(o=>{const{path:s,default:a,inputs:u}=o;Array.isArray(u)?n(u):i.get(e,s)===void 0&&i.set(e,s,a)})};return Array.isArray(r.inputs)&&n(r.inputs),e};function ke(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 de="__temp_",Me=r=>de+r.split(".").join("__");function me(r){const e={...r};return i.forOwn(e,(n,t)=>{t.startsWith(de)&&delete e[t]}),e}const Ze="Required field";function V(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(i.isArray(e))return V(e[0]);const n=e;return i.isObject(n)&&(n!=null&&n.message)?e==null?void 0:e.message:"Unknown error"}function he(r,e,n){let t={};if(D(t,r.inputs,e,n),n!=null&&n.prefix){const s=n==null?void 0:n.prefix.replace(/.$/,"");t=i.set({},s,t)}return m.object(x(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],c=x({item:u},e,n);s.push(c.item||m.any().optional())}else s.push(m.any().optional());return m.tuple(s).rest(m.any()).optional()}function x(r,e,n){const t={};return Object.keys(r).forEach(o=>{const{_requiredOnly:s,_schemaObj:a,_input:u,_isList:c,_isArrayItem:l,_isTuple:f,_schema:h}=r[o];if(f&&!c&&!l){const d=$e(r[o],e,n);if(d){t[o]=d;return}}if(c&&a&&u){const d=m.object(x(a,e,n)),p=m.union([m.array(d).optional(),pe(u,n)]),b=ue(h,u,e,n,p);t[o]=b}else if(l&&u){const d=a!=null&&a.___array?x({___array:a.___array},e,n):{___array:m.any()},p=Be(d,u,n),b=ue(h,u,e,n,p);t[o]=b}else if(h&&u){const d=We(h,u,e,n);t[o]=d}else s&&u?t[o]=B(u,n):t[o]=m.object(x(r[o],e,n)).optional()}),t}function pe(r,e){return m.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:m.ZodIssueCode.custom,message:s.error}),!1;if(!s.continue)return!0}return!0})}function Be(r,e,n){return m.union([m.array(r.___array).optional(),pe(e,n)])}function We(r,e,n,t){return m.any().optional().superRefine(async(o,s)=>{var u,c;if(e.required&&!(await B(e,t).safeParseAsync(o)).success)return s.addIssue({code:m.ZodIssueCode.custom,message:Z(e,t)}),m.NEVER;if((u=t==null?void 0:t.validationConfig)!=null&&u.globalValidation){const l=(c=t==null?void 0:t.validationConfig)==null?void 0:c.globalValidation(o,e,t.metadata);if(l.error)return s.addIssue({code:m.ZodIssueCode.custom,message:l.error}),m.NEVER;if(!l.continue)return!0}const a=ye(r,n);if(a){const l=await a.safeParseAsync(o);if(!l.success){const f=V(l==null?void 0:l.error.message),h=f==="Required"?Z(e,t):f;s.addIssue({code:m.ZodIssueCode.custom,message:h})}}})}function ue(r,e,n,t,o){return m.any().optional().superRefine(async(s,a)=>{var f,h;const c=await B(e,t).safeParseAsync(s);if(e.required&&!c.success){const d=V(c.error.message);return a.addIssue({code:m.ZodIssueCode.custom,message:d,fatal:!0}),m.NEVER}if(!e.required&&!c.success)return m.NEVER;if((f=t==null?void 0:t.validationConfig)!=null&&f.globalValidation){const d=(h=t==null?void 0:t.validationConfig)==null?void 0:h.globalValidation(s,e,t.metadata);if(d.error)return a.addIssue({code:m.ZodIssueCode.custom,message:V(d.error)}),m.NEVER;if(!d.continue)return!0}if(!i.isArray(s))return a.addIssue({code:m.ZodIssueCode.custom,message:"'Value is not array'"}),m.NEVER;const l=ye(r,n);if(l){const d=await l.safeParseAsync(s);if(!d.success)return a.addIssue({code:m.ZodIssueCode.custom,message:V(d.error.message)}),m.NEVER}}).pipe(o??m.any())}function D(r,e,n,t,o){e.forEach(s=>{var u,c,l,f,h,d,p;const a=n;if(!s.isVisible||(u=s.isVisible)!=null&&u.call(s,a,t==null?void 0:t.metadata)){const b=i.get(r,s.path);if((c=s.validation)!=null&&c.schema?i.set(r,s.path,i.merge(b,{_schema:(l=s.validation)==null?void 0:l.schema,_input:s})):s.required&&i.set(r,s.path,i.merge(b,{_requiredOnly:!0,_input:s})),s.inputs&&D(r,s.inputs,n,t),s.inputType==="list"){const v={};D(v,(h=(f=s.inputConfig)==null?void 0:f.inputs)==null?void 0:h.map(j=>({...j,path:j.relativePath})),n,t);const w=i.get(r,s.path);i.set(r,s.path,i.merge(w,{_schemaObj:v,_isList:!0,_input:s}))}if(!((d=s.validation)!=null&&d.schema)&&s.inputType==="array"){const v={};D(v,[{...s.inputConfig.input,path:"___array"}],n,t),i.set(r,s.path,i.merge(b,{_schemaObj:v,_schema:(p=s.validation)==null?void 0:p.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 c=s.path.split(".");c.forEach((l,f)=>{if(f>0&&/^\d+$/.test(l)){const h=c.slice(0,f).join("."),d=h?i.get(r,h):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 B(r,e){var t,o,s,a,u,c;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(c=e==null?void 0:e.validationConfig)==null?void 0:c.requiredSchema;const n=Z(r,e);return m.any().optional().superRefine((l,f)=>{typeof l=="object"&&i.isEmpty(l)&&f.addIssue({code:m.ZodIssueCode.custom,message:n}),(i.isUndefined(l)||l==="")&&f.addIssue({code:m.ZodIssueCode.custom,message:n})})}function ye(r,e){if(r instanceof m.ZodType)return r;if(typeof r=="function")return r(e)}const Ue=r=>Array.isArray(r==null?void 0:r.errors),Je=(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 c=t.unionErrors[0].errors[0];n[u]={message:c.message,type:c.code}}else n[u]={message:s,type:o};"unionErrors"in t&&t.unionErrors.forEach(c=>c.errors.forEach(l=>r.push(l)));{const c=n[u].types,l=c&&c[t.code];n[u]=T.appendErrors(u,e,n,o,l?[].concat(l,t.message):t.message)}r.shift()}return n};function Le(r,e){return y.useCallback(async(n,t,o)=>{try{return await he(r,n,e).parseAsync(n),{values:n,errors:{}}}catch(s){if(Ue(s))return{values:{},errors:_e.toNestErrors(Je(s.errors,!0),o)};throw s}},[r,e])}function ge(r,e){const n=i.cloneDeep(r);return e.forEach(t=>{t.inputTransform&&(i.isArray(t.inputTransform)?t.inputTransform:[t.inputTransform]).forEach(s=>{let a;const u=t.path.split(".");if(u.length>1){const l=u.slice(0,-1).join("."),f=i.get(n,l);typeof f=="string"||typeof f=="number"||typeof f=="boolean"?a=void 0:a=i.get(n,t.path)}else a=i.get(n,t.path);const c=s(a,n);c&&i.set(n,c.path??t.path,c.value)})}),n}function be(r,e,n){const t=[];let o={};n||(o=i.cloneDeep(r));const s=i.cloneDeep(r);return e.forEach(a=>{a.outputTransform&&(i.isArray(a.outputTransform)?a.outputTransform:[a.outputTransform]).forEach(c=>{const l=i.get(s,a.path),f=c(l,s);f&&(f.path?(i.set(o,f.path,f.value),f.unset&&t.push(a.path)):i.set(o,a.path,f.value))})}),t.forEach(a=>{i.unset(o,a)}),o}function W(r){return r.reduce((n,t)=>Array.isArray(t.inputs)?[...n,t,...W(t.inputs)]:[...n,t],[])}const He=r=>{if(r!==void 0)return{value:r}},ze=r=>{if(r!==void 0)return{value:r}};function U(r,e){const t=W(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,c=!!s.outputTransform,l=Array.isArray(s.inputs)&&s.inputs.length>0,f=s.inputType==="list"||s.inputType==="array";return u||c?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:He,outputTransform:ze,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 Te(r,e,n,t={}){const{preserve:o}=t,s=W(r.inputs),a=i.cloneDeep(e);return s.forEach(u=>{o&&o.includes(u.path)||u.isVisible&&!u.isVisible(e,n)&&i.unset(a,u.path)}),a}function Ge(r,e){const n=U(e);return ge(r,n)}function Ke(r,e,n,t={}){const o=t.cleanOutput,s=U(e,o);let a=Te(e,r,n,t);return a=be(a,s,t.cleanOutput),a=me(a),a}function Qe(r){const e={},n=t=>{t.forEach(o=>{const{default:s,path:a,inputs:u}=o;Array.isArray(u)?n(u):s!==void 0&&i.set(e,a,s)})};return Array.isArray(r.inputs)&&n(r.inputs),e}function Xe(){return function(r,e){if(!(typeof r>"u"))return!r||!i.isPlainObject(r)?{value:r}:{value:Object.getOwnPropertyNames(r).map(n=>({key:n,value:r[n]}))}}}function Ye(r){return function(e,n){if(typeof e>"u")return;if(!e||!i.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 er(){return function(r,e){if(!(typeof r>"u"))return i.isArray(r)&&i.isEmpty(r)?{value:void 0}:{value:r}}}function rr(r){return function(e,n){const t=r?i.get(n,r):e;if(!(typeof t>"u")){if(i.isNull(t))return{value:void 0,path:r};if(i.isObject(t)){const o=i.omitBy(t,i.isNil);if(i.isEmpty(o))return{value:void 0,path:r}}return{value:t,path:r}}}}function tr(){return function(r,e){if(!(typeof r>"u"))return i.isString(r)&&i.isEmpty(r)?{value:void 0}:{value:r}}}function nr(r){return function(e,n){const t=i.get(n,r);if(typeof t=="string")return{value:t};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function sr(r){return function(e,n){if(typeof e>"u")return;if(!e)return{value:e};const t=i.get(n,r);if(typeof t=="object"){const o=ur(t);if(Object.getOwnPropertyNames(o).length===1)return{value:e,path:r}}return{value:e}}}function ar(r){return function(e,n){const t=i.get(n,r);if(typeof t=="string")return{value:[t]};if(!(typeof t=="number"||typeof t=="boolean")&&e!==void 0)return{value:e}}}function or(r,e){return function(n,t){if(typeof n>"u")return;if(!n)return{value:n};const o=i.get(t,r);if(i.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 ve(r){return typeof r=="object"?!Object.getOwnPropertyNames(r).some(e=>!ve(r[e])):i.isUndefined(r)}function ur(r){return i.omitBy(r,e=>typeof e=="object"?ve(e):i.isUndefined(e))}function k(r){const{items:e,className:n,withoutWrapper:t=!0,...o}=r,s=e.map(a=>g.jsx(le,{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})}k.displayName="RenderInputs";const Oe=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(k,{items:n.inputs,factory:o})]}):g.jsxs("div",{className:t,ref:e,children:[n.hero,g.jsx(k,{items:n.inputs,factory:o})]})});Oe.displayName="RenderForm";function ir(r){let e=!0;return i.forOwn(r,n=>{e=e&&(n===""||i.isNull(n)||i.isUndefined(n))}),e}const cr=(r="")=>i.capitalize(r.split("_").join(" ")),Ee=(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 fr(r){const{field:{onBlur:e,...n},...t}=T.useController(r),o=y.useRef(Date.now());return{...t,field:{...n,onBlur:Ee(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=Ae;exports.InputComponentRenderer=le;exports.InputFactory=$;exports.InputOverrideError=ie;exports.RenderForm=Oe;exports.RenderInputs=k;exports.RootForm=qe;exports.afterFrames=Ee;exports.arrayToObjectOutputTransformer=Ye;exports.collectDefaultValues=Qe;exports.convertDataToFormModel=Ge;exports.convertFormModelToData=Ke;exports.generateReadableLabel=cr;exports.getDefaultValuesFromFormDefinition=De;exports.getTemporaryPath=Me;exports.getTransformers=U;exports.getValidationSchema=he;exports.inputTransformValues=ge;exports.isChildrenEmpty=ir;exports.objectToArrayInputTransformer=Xe;exports.outputTransformValues=be;exports.overrideFormDefinition=ke;exports.processValidationParseResponse=V;exports.removeTemporaryFieldsValue=me;exports.shorthandArrayInputTransformer=ar;exports.shorthandArrayOutputTransformer=or;exports.shorthandObjectInputTransformer=nr;exports.shorthandObjectOutputTransformer=sr;exports.unsetEmptyArrayOutputTransformer=er;exports.unsetEmptyObjectOutputTransformer=rr;exports.unsetEmptyStringOutputTransformer=tr;exports.unsetHiddenInputsValues=Te;exports.useController=fr;exports.useRootFormContext=fe;exports.useZodValidationResolver=Le;
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;
13
13
  //# sourceMappingURL=index.cjs.map