@harnessio/forms 0.13.1 → 0.14.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/core/utils/transform-utils.d.ts +3 -2
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +392 -374
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,9 +10,9 @@ type TransformItem = {
|
|
|
10
10
|
/** convert data model to form model using input transformer functions */
|
|
11
11
|
export declare function inputTransformValues(values: Record<string, any>, transformerItems: TransformItem[]): Record<string, any>;
|
|
12
12
|
/** convert form model to data model using output transformer functions */
|
|
13
|
-
export declare function outputTransformValues(values: Record<string, any>, transformerItems: TransformItem[]): Record<string, any>;
|
|
13
|
+
export declare function outputTransformValues(values: Record<string, any>, transformerItems: TransformItem[], cleanOutput?: boolean): Record<string, any>;
|
|
14
14
|
/** Collect all input/output transformer functions */
|
|
15
|
-
export declare function getTransformers(formDefinition: IFormDefinition): TransformItem[];
|
|
15
|
+
export declare function getTransformers(formDefinition: IFormDefinition, addDefaultTransformer?: boolean): TransformItem[];
|
|
16
16
|
/** Remove values for inputs that are hidden */
|
|
17
17
|
export declare function unsetHiddenInputsValues(formDefinition: IFormDefinition, values: Record<string, any>, metadata?: any, options?: {
|
|
18
18
|
preserve?: string[];
|
|
@@ -22,5 +22,6 @@ export declare function convertDataToFormModel(inputData: Record<string, any>, f
|
|
|
22
22
|
/** Convert form model to data */
|
|
23
23
|
export declare function convertFormModelToData(formData: Record<string, any>, formDefinition: IFormDefinition, metadata?: any, options?: {
|
|
24
24
|
preserve?: string[];
|
|
25
|
+
cleanOutput?: boolean;
|
|
25
26
|
}): Record<string, any>;
|
|
26
27
|
export {};
|
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
|
|
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={};/*
|
|
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
|
|
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
|
|
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 I;te=1,Ve();var r=y,e=60103;if(I.Fragment=60107,typeof Symbol=="function"&&Symbol.for){var n=Symbol.for;e=n("react.element"),I.Fragment=n("react.fragment")}var t=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a=Object.prototype.hasOwnProperty,s={key:!0,ref:!0,__self:!0,__source:!0};function o(u,i,f){var l,h={},d=null,p=null;f!==void 0&&(d=""+f),i.key!==void 0&&(d=""+i.key),i.ref!==void 0&&(p=i.ref);for(l in i)a.call(i,l)&&!s.hasOwnProperty(l)&&(h[l]=i[l]);if(u&&u.defaultProps)for(l in i=u.defaultProps,i)h[l]===void 0&&(h[l]=i[l]);return{$$typeof:e,type:u,key:d,ref:p,props:h,_owner:t.current}}return I.jsx=o,I.jsxs=o,I}var ne;function Fe(){return ne||(ne=1,D.exports=we()),D.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,o;console.error(n,t);const a=new Error(`Form input [${this.props.inputType}] has failed at path [${this.props.path}]. Error: ${n}, Error info: ${t}`);(o=(s=this.props).inputErrorHandler)==null||o.call(s,a)}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:a,initialValues:s,input:o,withoutWrapper:u=!1}){var H,z,G,K,Q;const i=v.useFormContext(),{formState:f}=i,{fixedValues:l={}}={},{metadata:h,readonly:d,inputErrorHandler:p}=fe(),b=n==null?void 0:n.getComponent(o.inputType),O=!!(o.isVisible||typeof o.disabled=="function"||typeof((H=o.validation)==null?void 0:H.schema)=="function"||typeof((z=o.warning)==null?void 0:z.schema)=="function"),w=!!((G=o.warning)!=null&&G.schema||(K=o.validation)!=null&&K.schema),j=O?i.watch():{},S=w?O?v.get(j,o.path):i.watch(o.path):void 0,_=y.useMemo(()=>{if(!O)return{};let F=j;return l&&Object.keys(l).forEach(A=>{const P=l[A];F=c.set(F,A,P)}),F},[O,j,l]),C=!o.isVisible||o.isVisible(_,h),E=d||o.readonly,R=typeof o.disabled=="function"?o.disabled(_,h):o.disabled,T=(Q=o.warning)==null?void 0:Q.schema,J=y.useMemo(()=>{var Y,ee;if(!C||typeof T>"u")return;const F=typeof T=="function"?T(_,h):T,{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},[o.path,S,T,C,h]),L=y.useMemo(()=>({path:e,key:e,initialValues:s,onUpdate:t,onChange:a,factory:n,readonly:E,input:o,disabled:R,warning:J}),[n,s,o,a,t,e,E,f.errors,R,J]),je=y.useMemo(()=>C?g.jsxs(g.Fragment,{children:[o.before?o.before:null,g.jsx(xe,{path:e,inputType:o.inputType,inputErrorHandler:p,children:b==null?void 0:b.renderComponent(L)}),o.after?o.after:null]}):null,[C,o.before,o.inputType,o.after,e,b,L,f.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: ",o.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:a,onValuesChange:s,onValidationChange:o,onSubmit:u,onInputRenderError:i,metadata:f,children:l,autoFocusPath:h,readonly:d}=r,p=v.useForm({mode:e,reValidateMode:"onChange",defaultValues:t,shouldFocusError:a,resolver:n}),b=y.useRef(!1),O=y.useRef(JSON.stringify(t??{}));y.useEffect(()=>{O.current=JSON.stringify(t??{}),p.reset(t,{})},[p.reset,t]),y.useEffect(()=>{const E=ae(),R=oe(),T=E(()=>{p.reset({},{keepErrors:!0,keepDirty:!0,keepDirtyValues:!0,keepValues:!0,keepDefaultValues:!1,keepIsSubmitted:!0,keepTouched:!0,keepIsValid:!0,keepSubmitCount:!0})});return()=>R(T)},[]);const{handleSubmit:w}=p,j=y.useRef(s);y.useEffect(()=>{j.current=s},[s]);const S=y.useRef(o);y.useEffect(()=>{S.current=o},[o]);const _=y.useRef(!1);y.useEffect(()=>{const E=p.watch(R=>{var T;_.current||JSON.stringify(R??{})!==O.current&&((T=j.current)==null||T.call(j,{...R}),b.current===!0&&(_.current=!0,p.trigger().finally(()=>{_.current=!1})))});return()=>{E.unsubscribe()}},[p]);const C=y.useRef(!0);return y.useEffect(()=>{var E;if(C.current){C.current=!1;return}(E=S.current)==null||E.call(S,{isValid:p.formState.isValid,isSubmitted:p.formState.isSubmitted})},[p.formState.isValid,p.formState.isSubmitted]),y.useEffect(()=>{if(h){const E=ae(),R=oe(),T=E(()=>{p.setFocus(h)});return()=>R(T)}},[p,h]),g.jsx(Pe,{metadata:f,readonly:d,inputErrorHandler:i,children:g.jsx(v.FormProvider,{...p,children:typeof l=="function"?l({...p,submitForm:async()=>{u&&(b.current=!0,w(E=>{u(E)})())}}):l})})}const ke=r=>{const e={},n=t=>{t.forEach(a=>{const{path:s,default:o,inputs:u}=a;Array.isArray(u)?n(u):c.get(e,s)===void 0&&c.set(e,s,o)})};return Array.isArray(r.inputs)&&n(r.inputs),e};function Ne(r,e){const n=r.inputs.map(t=>{const a=De(e,t.path);return a||t});return{...r,inputs:n}}function De(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 c.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(c.isArray(e))return V(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 m.object(x(t,e,n))}function $e(r,e,n){const t=Object.keys(r).filter(o=>/^\d+$/.test(o)&&!o.startsWith("_")).map(o=>parseInt(o,10)).sort((o,u)=>o-u);if(t.length===0)return null;const a=Math.max(...t),s=[];for(let o=0;o<=a;o++)if(t.includes(o)){const u=r[o],i=x({item:u},e,n);s.push(i.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(a=>{const{_requiredOnly:s,_schemaObj:o,_input:u,_isList:i,_isArrayItem:f,_isTuple:l,_schema:h}=r[a];if(l&&!i&&!f){const d=$e(r[a],e,n);if(d){t[a]=d;return}}if(i&&o&&u){const d=m.object(x(o,e,n)),p=m.union([m.array(d).optional(),pe(u,n)]),b=ue(h,u,e,n,p);t[a]=b}else if(f&&u){const d=o!=null&&o.___array?x({___array:o.___array},e,n):{___array:m.any()},p=Be(d,u,n),b=ue(h,u,e,n,p);t[a]=b}else if(h&&u){const d=We(h,u,e,n);t[a]=d}else s&&u?t[a]=B(u,n):t[a]=m.object(x(r[a],e,n)).optional()}),t}function pe(r,e){return m.string().superRefine((n,t)=>{var a;if((a=e==null?void 0:e.validationConfig)!=null&&a.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(a,s)=>{var u,i;if(e.required&&!(await B(e,t).safeParseAsync(a)).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 f=(i=t==null?void 0:t.validationConfig)==null?void 0:i.globalValidation(a,e,t.metadata);if(f.error)return s.addIssue({code:m.ZodIssueCode.custom,message:f.error}),m.NEVER;if(!f.continue)return!0}const o=ye(r,n);if(o){const f=await o.safeParseAsync(a);if(!f.success){const l=V(f==null?void 0:f.error.message),h=l==="Required"?Z(e,t):l;s.addIssue({code:m.ZodIssueCode.custom,message:h})}}})}function ue(r,e,n,t,a){return m.any().optional().superRefine(async(s,o)=>{var l,h;const i=await B(e,t).safeParseAsync(s);if(e.required&&!i.success){const d=V(i.error.message);return o.addIssue({code:m.ZodIssueCode.custom,message:d,fatal:!0}),m.NEVER}if(!e.required&&!i.success)return m.NEVER;if((l=t==null?void 0:t.validationConfig)!=null&&l.globalValidation){const d=(h=t==null?void 0:t.validationConfig)==null?void 0:h.globalValidation(s,e,t.metadata);if(d.error)return o.addIssue({code:m.ZodIssueCode.custom,message:V(d.error)}),m.NEVER;if(!d.continue)return!0}if(!c.isArray(s))return o.addIssue({code:m.ZodIssueCode.custom,message:"'Value is not array'"}),m.NEVER;const f=ye(r,n);if(f){const d=await f.safeParseAsync(s);if(!d.success)return o.addIssue({code:m.ZodIssueCode.custom,message:V(d.error.message)}),m.NEVER}}).pipe(a??m.any())}function k(r,e,n,t,a){e.forEach(s=>{var u,i,f,l,h,d,p;const o=n;if(!s.isVisible||(u=s.isVisible)!=null&&u.call(s,o,t==null?void 0:t.metadata)){const b=c.get(r,s.path);if((i=s.validation)!=null&&i.schema?c.set(r,s.path,c.merge(b,{_schema:(f=s.validation)==null?void 0:f.schema,_input:s})):s.required&&c.set(r,s.path,c.merge(b,{_requiredOnly:!0,_input:s})),s.inputs&&k(r,s.inputs,n,t),s.inputType==="list"){const O={};k(O,(h=(l=s.inputConfig)==null?void 0:l.inputs)==null?void 0:h.map(j=>({...j,path:j.relativePath})),n,t);const w=c.get(r,s.path);c.set(r,s.path,c.merge(w,{_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(b,{_schemaObj:O,_schema:(p=s.validation)==null?void 0:p.schema,_isArrayItem:!0,_input:s}))}}}),e.forEach(s=>{var u;const o=n;if((!s.isVisible||(u=s.isVisible)!=null&&u.call(s,o,t==null?void 0:t.metadata))&&s.path){const i=s.path.split(".");i.forEach((f,l)=>{if(l>0&&/^\d+$/.test(f)){const h=i.slice(0,l).join("."),d=h?c.get(r,h):r;d&&typeof d=="object"&&(d._isTuple=!0)}})}})}function Z(r,e){var n,t,a;return((t=(n=e==null?void 0:e.validationConfig)==null?void 0:n.requiredMessagePerInput)==null?void 0:t[r.inputType])??((a=e==null?void 0:e.validationConfig)==null?void 0:a.requiredMessage)??Ze}function B(r,e){var t,a,s,o,u,i;if((a=(t=e==null?void 0:e.validationConfig)==null?void 0:t.requiredSchemaPerInput)!=null&&a[r.inputType])return(o=(s=e==null?void 0:e.validationConfig)==null?void 0:s.requiredSchemaPerInput)==null?void 0:o[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 m.any().optional().superRefine((f,l)=>{typeof f=="object"&&c.isEmpty(f)&&l.addIssue({code:m.ZodIssueCode.custom,message:n}),(c.isUndefined(f)||f==="")&&l.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:a,message:s,path:o}=t,u=o.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:a};"unionErrors"in t&&t.unionErrors.forEach(i=>i.errors.forEach(f=>r.push(f)));{const i=n[u].types,f=i&&i[t.code];n[u]=v.appendErrors(u,e,n,a,f?[].concat(f,t.message):t.message)}r.shift()}return n};function Le(r,e){return y.useCallback(async(n,t,a)=>{try{return await he(r,n,e).parseAsync(n),{values:n,errors:{}}}catch(s){if(Ue(s))return{values:{},errors:Ce.toNestErrors(Je(s.errors,!0),a)};throw s}},[r,e])}function ge(r,e){const n=c.cloneDeep(r);return e.forEach(t=>{t.inputTransform&&(c.isArray(t.inputTransform)?t.inputTransform:[t.inputTransform]).forEach(s=>{let o;const u=t.path.split(".");if(u.length>1){const f=u.slice(0,-1).join("."),l=c.get(n,f);typeof l=="string"||typeof l=="number"||typeof l=="boolean"?o=void 0:o=c.get(n,t.path)}else o=c.get(n,t.path);const i=s(o,n);i&&c.set(n,i.path??t.path,i.value)})}),n}function be(r,e){const n=[],t=c.cloneDeep(r);return e.forEach(a=>{a.outputTransform&&(c.isArray(a.outputTransform)?a.outputTransform:[a.outputTransform]).forEach(o=>{const u=c.get(t,a.path),i=o(u,t);i&&(i.path?(c.set(t,i.path,i.value),i.unset&&n.push(a.path)):c.set(t,a.path,i.value))})}),n.forEach(a=>{c.unset(t,a)}),t}function W(r){return r.reduce((n,t)=>Array.isArray(t.inputs)?[...n,t,...W(t.inputs)]:[...n,t],[])}function U(r){const n=W(r.inputs).reduce((t,a)=>{const s=a.inputType==="text"||a.inputType==="boolean"||a.inputType==="number"||a.inputType==="textarea"||a.inputType==="select";return(a.inputTransform||a.outputTransform)&&t.push({...c.pick(a,"path","inputTransform","outputTransform"),level:a.path.split(".").length,isPrimitive:s}),t},[]);return n.sort((t,a)=>t.level===a.level?t.isPrimitive?1:-1:t.level<a.level?-1:1),n}function ve(r,e,n,t={}){const{preserve:a}=t,s=W(r.inputs),o=c.cloneDeep(e);return s.forEach(u=>{a&&a.includes(u.path)||u.isVisible&&!u.isVisible(e,n)&&c.unset(o,u.path)}),o}function He(r,e){const n=U(e);return ge(r,n)}function ze(r,e,n,t={}){const a=U(e);let s=ve(e,r,n,t);return s=be(s,a),s=me(s),s}function Ge(r){const e={},n=t=>{t.forEach(a=>{const{default:s,path:o,inputs:u}=a;Array.isArray(u)?n(u):s!==void 0&&c.set(e,o,s)})};return Array.isArray(r.inputs)&&n(r.inputs),e}function Ke(){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 Qe(r){return function(e,n){if(typeof e>"u")return;if(!e||!c.isArray(e))return{value:e};const t={value:e.reduce((a,s)=>({...a,[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 Xe(){return function(r,e){if(!(typeof r>"u"))return c.isArray(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function Ye(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 a=c.omitBy(t,c.isNil);if(c.isEmpty(a))return{value:void 0,path:r}}return{value:t,path:r}}}}function er(){return function(r,e){if(!(typeof r>"u"))return c.isString(r)&&c.isEmpty(r)?{value:void 0}:{value:r}}}function rr(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 tr(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 a=ar(t);if(Object.getOwnPropertyNames(a).length===1)return{value:e,path:r}}return{value:e}}}function nr(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 sr(r,e){return function(n,t){if(typeof n>"u")return;if(!n)return{value:n};const a=c.get(t,r);if(c.isArray(a)){if(a.length===1)return{value:a[0],path:r};if(a.length===0&&e!=null&&e.unsetIfEmpty)return{value:void 0,path:r}}return{value:n}}}function Oe(r){return typeof r=="object"?!Object.getOwnPropertyNames(r).some(e=>!Oe(r[e])):c.isUndefined(r)}function ar(r){return c.omitBy(r,e=>typeof e=="object"?Oe(e):c.isUndefined(e))}function N(r){const{items:e,className:n,withoutWrapper:t=!0,...a}=r,s=e.map(o=>g.jsx(le,{input:o,path:o.path,...a},`${o.inputType}_${o.path}`));return t?g.jsx(g.Fragment,{children:s}):g.jsx("div",{className:n,children:s})}N.displayName="RenderInputs";const Ee=y.forwardRef((r,e)=>{const{inputs:n,className:t,factory:a,withoutWrapper:s}=r;return s?g.jsxs(y.Fragment,{children:[n.hero,g.jsx(N,{items:n.inputs,factory:a})]}):g.jsxs("div",{className:t,ref:e,children:[n.hero,g.jsx(N,{items:n.inputs,factory:a})]})});Ee.displayName="RenderForm";function or(r){let e=!0;return c.forOwn(r,n=>{e=e&&(n===""||c.isNull(n)||c.isUndefined(n))}),e}const ur=(r="")=>c.capitalize(r.split("_").join(" ")),Te=(r,e=2,n,t=1e3)=>{let a=!1;const s=()=>{requestAnimationFrame(()=>{a||(e-=1,e<=0?r():s())})};return n&&Date.now()-n<=t?(r(),()=>{}):(s(),()=>{a=!0})};function ir(r){const{field:{onBlur:e,...n},...t}=v.useController(r),a=y.useRef(Date.now());return{...t,field:{...n,onBlur:Te(e,2,a.current)}}}Object.defineProperty(exports,"Controller",{enumerable:!0,get:()=>v.Controller});Object.defineProperty(exports,"Form",{enumerable:!0,get:()=>v.Form});Object.defineProperty(exports,"FormProvider",{enumerable:!0,get:()=>v.FormProvider});Object.defineProperty(exports,"get",{enumerable:!0,get:()=>v.get});Object.defineProperty(exports,"set",{enumerable:!0,get:()=>v.set});Object.defineProperty(exports,"useFieldArray",{enumerable:!0,get:()=>v.useFieldArray});Object.defineProperty(exports,"useForm",{enumerable:!0,get:()=>v.useForm});Object.defineProperty(exports,"useFormContext",{enumerable:!0,get:()=>v.useFormContext});Object.defineProperty(exports,"useFormState",{enumerable:!0,get:()=>v.useFormState});Object.defineProperty(exports,"useWatch",{enumerable:!0,get:()=>v.useWatch});exports.InputComponent=Ae;exports.InputComponentRenderer=le;exports.InputFactory=$;exports.InputOverrideError=ie;exports.RenderForm=Ee;exports.RenderInputs=N;exports.RootForm=qe;exports.afterFrames=Te;exports.arrayToObjectOutputTransformer=Qe;exports.collectDefaultValues=Ge;exports.convertDataToFormModel=He;exports.convertFormModelToData=ze;exports.generateReadableLabel=ur;exports.getDefaultValuesFromFormDefinition=ke;exports.getTemporaryPath=Me;exports.getTransformers=U;exports.getValidationSchema=he;exports.inputTransformValues=ge;exports.isChildrenEmpty=or;exports.objectToArrayInputTransformer=Ke;exports.outputTransformValues=be;exports.overrideFormDefinition=Ne;exports.processValidationParseResponse=V;exports.removeTemporaryFieldsValue=me;exports.shorthandArrayInputTransformer=nr;exports.shorthandArrayOutputTransformer=sr;exports.shorthandObjectInputTransformer=rr;exports.shorthandObjectOutputTransformer=tr;exports.unsetEmptyArrayOutputTransformer=Xe;exports.unsetEmptyObjectOutputTransformer=Ye;exports.unsetEmptyStringOutputTransformer=er;exports.unsetHiddenInputsValues=ve;exports.useController=ir;exports.useRootFormContext=fe;exports.useZodValidationResolver=Le;
|
|
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;
|
|
13
13
|
//# sourceMappingURL=index.cjs.map
|