@arudovwen/form-builder-react 1.1.2 → 1.1.3
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/form-builder.es.js
CHANGED
|
@@ -14671,7 +14671,7 @@ function Fw({
|
|
|
14671
14671
|
return /* @__PURE__ */ m.jsxs("div", { className: "px-[30px] py-[10px] flex justify-between items-center bg-[#F9F9FB]", children: [
|
|
14672
14672
|
/* @__PURE__ */ m.jsxs("span", { className: "flex items-center gap-x-[6px]", children: [
|
|
14673
14673
|
" ",
|
|
14674
|
-
t && /* @__PURE__ */ m.jsx("button", { type: "button", onClick: () => s, children: /* @__PURE__ */ m.jsx(qe, { icon: "mingcute:arrow-left-fill" }) }),
|
|
14674
|
+
t && /* @__PURE__ */ m.jsx("button", { type: "button", onClick: () => s(), children: /* @__PURE__ */ m.jsx(qe, { icon: "mingcute:arrow-left-fill" }) }),
|
|
14675
14675
|
" ",
|
|
14676
14676
|
/* @__PURE__ */ m.jsx("h1", { className: "font-semibold text-lg", children: e || "" })
|
|
14677
14677
|
] }),
|
package/dist/form-builder.umd.js
CHANGED
|
@@ -65,4 +65,4 @@ attempted value: ${s}
|
|
|
65
65
|
${l===d.id?"border-dashed border-blue-400 bg-[#f7f8fa]":"border-transparent"} ${u.includes(y)?"min-h-[300px]":""}`,children:[g.jsxs("div",{className:"flex justify-between items-center",children:[g.jsx("div",{onClick:()=>a(d.id),className:"h-full flex-1 cursor-pointer py-4",children:g.jsx("h2",{className:"font-medium",children:d.title||"Section title"})}),g.jsxs("div",{className:"flex gap-x-2 items-center",children:[g.jsx("button",{type:"button",className:"p-1 border rounded-lg text-xs",onClick:()=>m(d),children:g.jsx(Pe,{icon:"fluent:edit-28-regular"})}),i.length>1&&g.jsx("button",{type:"button",className:"p-1 border rounded-lg text-xs",onClick:()=>o(d.id),children:g.jsx(Pe,{icon:"lets-icons:trash-duotone-line"})}),g.jsx("button",{type:"button",className:"p-1 rounded-lg text-xs",onClick:()=>h(y),children:g.jsx(Pe,{icon:u.includes(y)?"gravity-ui:minus":"octicon:plus-16"})})]})]}),(d==null?void 0:d.description)&&u.includes(y)&&g.jsx("p",{className:"text-sm text-gray-60 mt-2 text-gray-600",children:d==null?void 0:d.description}),u.includes(y)&&g.jsxs("div",{className:"mt-4 transition-all duration-200 h-full",id:d.id,onDragOver:f,onDragEnd:()=>s(!1),onClick:()=>a(d.id),children:[g.jsx("hr",{}),g.jsx("div",{className:"gap-y-6 mt-4 h-full",children:g.jsx(Mv,{elementData:d.questionData,sectionId:d.id})})]})]}),g.jsx("hr",{className:"mt-6 group-last:hidden"})]},d.id))})]})};function Uv({questionData:e}){const{setFormData:t}=p.useContext(ft);return p.useEffect(()=>{e&&e.length>0&&t(e)},[e,t]),g.jsx("div",{className:"bg-white p-4 border border-[#E4E7EC] rounded-lg h-full overflow-y-auto",children:g.jsx(Bv,{})})}const zv=()=>{const{setIsDragging:e,addElement:t,selectedSection:r}=p.useContext(ft),n=p.useCallback((u,c)=>{u.dataTransfer.setData("properties",JSON.stringify(c)),u.dataTransfer.effectAllowed="move",e(!0)},[e]);function o(u){if(console.log(r),!r){ce.error("Please select a section to add an element to.");return}const c={...u,id:Qe(),sectionId:r};t(c,r)}const i=sr("config"),s=i==null?void 0:i.elementColor,a=i==null?void 0:i.elementBgColor,l=i==null?void 0:i.elementBorderColor;return g.jsx("div",{className:"w-full",children:g.jsx("div",{className:"py-4 px-5 max-h-[80vh] overflow-y-auto",children:g.jsx("div",{children:g.jsx("ul",{className:"grid gap-y-[8px] mt-3",children:qb.map(u=>g.jsxs("li",{onDragStart:c=>n(c,u),onDragEnd:()=>e(!1),onClick:()=>o(u),style:{borderColor:l,color:u.color,backgroundColor:a},className:`cursor-move text-[#475467] flex justify-between items-center h-11\r
|
|
66
66
|
border border-[#98A2B3] rounded-lg py-3 px-[14px] shadow-custom\r
|
|
67
67
|
hover:shadow-lg transition-all duration-200\r
|
|
68
|
-
active:opacity-50`,draggable:!0,children:[g.jsxs("span",{className:"flex gap-x-2 items-center",children:[g.jsx("span",{style:{color:s},className:"text-gray-400",children:g.jsx(Pe,{icon:"akar-icons:drag-vertical"})}),g.jsx("span",{style:{color:s},className:"text-sm font-medium leading-[0]",children:u.label})]}),g.jsx("span",{style:{color:s},children:g.jsx(Pe,{icon:u.icon,iconClass:"w-4 h-4"})})]},u.type))})})})})},qv=p.memo(zv),Hv=({isOpen:e,onClose:t})=>{const{formData:r}=p.useContext(ft);if(!e)return null;const n=sr("config");return g.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:g.jsxs("div",{className:"max-w-[80vw] bg-white rounded-xl shadow-xl relative flex flex-col items-center w-full py-6 ",children:[g.jsx("button",{type:"button",onClick:t,className:"absolute top-3 right-4 text-sm",children:"Close"}),g.jsx("div",{className:"max-h-[90vh] overflow-y-auto h-full min-h-[600px] w-full",children:g.jsx(hf,{form_data:r,ignoreValidation:!0,config:n})})]})})};function Wv({title:e,backUrl:t}){const{addSection:r}=p.useContext(ft),[n,o]=p.useState(!1);function i(){window.location.href=t}return g.jsxs("div",{className:"px-[30px] py-[10px] flex justify-between items-center bg-[#F9F9FB]",children:[g.jsxs("span",{className:"flex items-center gap-x-[6px]",children:[" ",t&&g.jsx("button",{type:"button",onClick:()=>i,children:g.jsx(Pe,{icon:"mingcute:arrow-left-fill"})})," ",g.jsx("h1",{className:"font-semibold text-lg",children:e||""})]}),n&&g.jsx(Hv,{isOpen:n,onClose:()=>o(!1),element:void 0}),g.jsxs("div",{className:"py-4 flex justify-end gap-x-6 text-base",children:[g.jsx(Fr,{onClick:()=>r(),text:"Add section",btnClass:"text-gray-700 border-[#98A2B3] !font-medium bg-transparent",icon:"icon-park-outline:plus"}),g.jsx(Fr,{onClick:()=>o(!0),text:"Preview",btnClass:"text-gray-700 border-[#98A2B3] !font-medium",icon:"solar:eye-bold-duotone"})]})]})}const mf=({loadingClass:e})=>{const t=se("h-screen w-screen flex justify-center items-center",e);return p.useEffect(()=>{const r=sr("config"),n=(r==null?void 0:r.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",n)},[]),g.jsx("div",{className:t,children:g.jsx("span",{className:"loader"})})};function Kv({onSubmit:e,questionData:t,title:r,backUrl:n,loading:o}){return g.jsx(fl,{children:g.jsxs("div",{className:"w-full h-full bg-[#E4E7EC] flex flex-col",children:[g.jsx(id,{}),g.jsx("div",{className:"border-b bg-white border-[#E4E7EC]",children:g.jsx(Wv,{title:r,backUrl:n})}),g.jsxs("div",{className:"flex flex-1 ",children:[g.jsx("div",{className:"w-[270px] h-full border-l border-[#E4E7EC] bg-white",children:g.jsx(qv,{})}),g.jsx("div",{className:"flex-1 h-full max-h-full p-4 z-[1]",children:o?g.jsx(mf,{loadingClass:"!w-full !h-[800px]"}):g.jsx(Uv,{questionData:t})})]}),g.jsx("div",{className:"border-b bg-white border-t border-[#E4E7EC]",children:g.jsx($m,{onSubmit:e})})]})})}const Yv=({onSubmit:e,questionData:t,isReadOnly:r,config:n={buttonColor:"#333"},title:o,loading:i,backUrl:s})=>(p.useEffect(()=>{n&&dl("config",n)},[n]),g.jsx(Kv,{onSubmit:e,questionData:t,isReadOnly:r,title:o,backUrl:s,loading:i})),Er={required:"This field is required",email:"Invalid email format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},Jv=e=>({textField:de().nullable(),longText:de().nullable(),numberField:Vr().nullable().transform(r=>isNaN(r)?null:r),amountField:Vr().nullable().transform(r=>isNaN(r)?null:r),selectField:de().nullable(),checkbox:Rr().nullable(),radio:Rr().nullable(),email:de().nullable().email(Er.email),date:Ns().typeError("Invalid date").nullable()})[e]||Rr().nullable(),Gv=(e,t,r)=>t?e.type==="boolean"?e.oneOf([!0],r||Er.required):e.required(r||Er.required):e,Xv=(e,{minLength:t,maxLength:r,minLengthMessage:n,maxLengthMessage:o})=>{let i=e;return t&&(i=i.min(t,n||Er.minLength(t))),r&&(i=i.max(r,o||Er.maxLength(r))),i},Zv=(e,{minAmount:t,maxAmount:r,minAmountMessage:n,maxAmountMessage:o})=>{let i=e;return t&&(i=i.min(parseFloat(String(t)),n||Er.minAmount(t))),r&&(i=i.max(parseFloat(String(r)),o||Er.maxAmount(r))),i};function Qv(e){const t={};return e.forEach(({questionData:r})=>{r.forEach(n=>{const{id:o,type:i,isRequired:s,requiredMessage:a}=n;let l=Jv(i);l=Gv(l,s,a),i==="textField"||i==="longText"||i==="email"?l=Xv(l,n):(i==="numberField"||i==="amountField")&&(l=Zv(l,n)),t[o]=l})}),_n().shape(t)}function ew(e){return e.reduce((t,r)=>(t[r.id]=r.value,t),{})}const Uo=(e,t)=>{const r=ff[e.type];return r?g.jsxs("div",{children:[e.inputLabel&&g.jsx("label",{className:"block text-sm font-medium mb-[5px]",children:e.inputLabel}),g.jsx(r,{element:e,state:"edit",validationData:t})]}):null};function tw({form_data:e,options:t}){return g.jsx("div",{className:"grid gap-y-6",children:e.flatMap(r=>{var n;return(n=r.questionData)==null?void 0:n.map(o=>{var i,s;if(o.type==="grid"){const a=r.questionData.filter(l=>l.gridId===o.id);return g.jsx(Gs,{element:o,customClass:"p-0 min-h-[60px] border-none",children:a.map(l=>{var u;return g.jsx(Js,{col:(u=l.gridPosition)==null?void 0:u.col,customClass:"p-0",children:Uo(l,t)},l.id)})},o.id)}return o.gridId?null:g.jsxs("div",{className:se("group relative grid gap-y-[6px]",o.elementClass),children:[Uo(o,t),g.jsx("div",{className:"text-xs text-red-600 mt-1",children:(s=(i=t==null?void 0:t.errors)==null?void 0:i[o.id])==null?void 0:s.message})]},o.id)})})})}function rw({form_data:e,options:t,current:r}){var n;return g.jsx("div",{className:"grid gap-y-6",children:(n=e[r].questionData)==null?void 0:n.map(o=>{var i,s;if(o.type==="grid"){const a=e[r].questionData.filter(l=>l.gridId===o.id);return g.jsx(Gs,{element:o,customClass:"p-0 min-h-[60px] border-none",children:a.map(l=>{var u;return g.jsx(Js,{col:(u=l.gridPosition)==null?void 0:u.col,customClass:"p-0",children:Uo(l,t)},l.id)})},o.id)}return o.gridId?null:g.jsxs("div",{className:se("group relative grid gap-y-[6px]",o.elementClass),children:[Uo(o,t),g.jsx("div",{className:"text-xs text-red-600 mt-1",children:(s=(i=t==null?void 0:t.errors)==null?void 0:i[o.id])==null?void 0:s.message})]},o.id)})})}const nw=({form_data:e,answerData:t,ignoreValidation:r,onSubmitData:n,isReadOnly:o,renderType:i="multi"})=>{const[s,a]=p.useState(0),l=p.useMemo(()=>e.length,[e]),u=Qv(e),c=Ss({resolver:Cs(u),mode:"onSubmit",defaultValues:{}}),{register:f,setValue:h,watch:m,handleSubmit:d,reset:y,getValues:x,formState:{errors:b,isSubmitting:w},trigger:v}=c,E=sr("config"),k=O=>{const j=e.flatMap(D=>D.questionData.map(N=>({id:N.id,value:O[N.id],sectionId:D.id,type:N.type})));n==null||n(j)};p.useEffect(()=>{if(t!=null&&t.length){const O=ew(t);y(O)}},[t,y]);async function T(){var O;!r&&!await v((O=e==null?void 0:e[s].questionData)==null?void 0:O.map(D=>D.id))||a(j=>j+1)}function C(){a(O=>O-1)}return g.jsx(fl,{children:g.jsx(J0,{...c,children:g.jsxs("form",{onSubmit:d(k),className:"container mx-auto p-6 h-full",children:[g.jsx("div",{className:"relative w-full flex flex-col gap-y-12 py-4",children:g.jsxs("div",{children:[g.jsxs("div",{className:"mb-4",children:[(e==null?void 0:e[s].title)&&g.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:e[s].title}),(e==null?void 0:e[s].description)&&g.jsx("p",{className:"text-sm",children:e[s].description})]}),i==="multi"?g.jsx(rw,{form_data:e,options:{register:f,setValue:h,watch:m,errors:b,trigger:v,isSubmitting:w,isReadOnly:o,getValues:x},current:s}):g.jsx(tw,{form_data:e,options:{register:f,setValue:h,watch:m,errors:b,trigger:v,isSubmitting:w,isReadOnly:o,getValues:x}})]},e==null?void 0:e[s].id)}),g.jsxs("div",{className:"pt-8 flex justify-end items-center gap-4",children:[s!==0&&g.jsx(Fr,{type:"button",text:"Back",onClick:C,btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-gray-200 rounded-lg"}),s!==l-1?g.jsx(Fr,{type:"button",text:"Continue",onClick:T,style:{background:(E==null?void 0:E.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg"}):!r&&g.jsx(Fr,{isDisabled:w,isLoading:w,type:"submit",text:"Submit",style:{background:(E==null?void 0:E.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg"})]})]})})})};function hf({answerData:e,form_data:t,ignoreValidation:r,onSubmit:n,isReadOnly:o=!1,loading:i=!1,config:s={buttonColor:"#333"},renderType:a}){return p.useEffect(()=>{s&&dl("config",s)},[s]),i?g.jsx(mf,{}):t?g.jsx("div",{className:"w-full h-full",children:g.jsx(nw,{form_data:t,answerData:e,ignoreValidation:r,onSubmitData:n,isReadOnly:o,renderType:a})}):g.jsx("div",{children:g.jsx("p",{children:"Error: No form data available. Please ensure the form data is saved correctly."})})}Pt.FormBuilder=Yv,Pt.FormViewer=hf,Object.defineProperty(Pt,Symbol.toStringTag,{value:"Module"})});
|
|
68
|
+
active:opacity-50`,draggable:!0,children:[g.jsxs("span",{className:"flex gap-x-2 items-center",children:[g.jsx("span",{style:{color:s},className:"text-gray-400",children:g.jsx(Pe,{icon:"akar-icons:drag-vertical"})}),g.jsx("span",{style:{color:s},className:"text-sm font-medium leading-[0]",children:u.label})]}),g.jsx("span",{style:{color:s},children:g.jsx(Pe,{icon:u.icon,iconClass:"w-4 h-4"})})]},u.type))})})})})},qv=p.memo(zv),Hv=({isOpen:e,onClose:t})=>{const{formData:r}=p.useContext(ft);if(!e)return null;const n=sr("config");return g.jsx("div",{className:"fixed inset-0 bg-black/30 flex items-center justify-center z-[999] cursor-default no-drag select-none",children:g.jsxs("div",{className:"max-w-[80vw] bg-white rounded-xl shadow-xl relative flex flex-col items-center w-full py-6 ",children:[g.jsx("button",{type:"button",onClick:t,className:"absolute top-3 right-4 text-sm",children:"Close"}),g.jsx("div",{className:"max-h-[90vh] overflow-y-auto h-full min-h-[600px] w-full",children:g.jsx(hf,{form_data:r,ignoreValidation:!0,config:n})})]})})};function Wv({title:e,backUrl:t}){const{addSection:r}=p.useContext(ft),[n,o]=p.useState(!1);function i(){window.location.href=t}return g.jsxs("div",{className:"px-[30px] py-[10px] flex justify-between items-center bg-[#F9F9FB]",children:[g.jsxs("span",{className:"flex items-center gap-x-[6px]",children:[" ",t&&g.jsx("button",{type:"button",onClick:()=>i(),children:g.jsx(Pe,{icon:"mingcute:arrow-left-fill"})})," ",g.jsx("h1",{className:"font-semibold text-lg",children:e||""})]}),n&&g.jsx(Hv,{isOpen:n,onClose:()=>o(!1),element:void 0}),g.jsxs("div",{className:"py-4 flex justify-end gap-x-6 text-base",children:[g.jsx(Fr,{onClick:()=>r(),text:"Add section",btnClass:"text-gray-700 border-[#98A2B3] !font-medium bg-transparent",icon:"icon-park-outline:plus"}),g.jsx(Fr,{onClick:()=>o(!0),text:"Preview",btnClass:"text-gray-700 border-[#98A2B3] !font-medium",icon:"solar:eye-bold-duotone"})]})]})}const mf=({loadingClass:e})=>{const t=se("h-screen w-screen flex justify-center items-center",e);return p.useEffect(()=>{const r=sr("config"),n=(r==null?void 0:r.loaderColor)||"#333";document.documentElement.style.setProperty("--loader-color",n)},[]),g.jsx("div",{className:t,children:g.jsx("span",{className:"loader"})})};function Kv({onSubmit:e,questionData:t,title:r,backUrl:n,loading:o}){return g.jsx(fl,{children:g.jsxs("div",{className:"w-full h-full bg-[#E4E7EC] flex flex-col",children:[g.jsx(id,{}),g.jsx("div",{className:"border-b bg-white border-[#E4E7EC]",children:g.jsx(Wv,{title:r,backUrl:n})}),g.jsxs("div",{className:"flex flex-1 ",children:[g.jsx("div",{className:"w-[270px] h-full border-l border-[#E4E7EC] bg-white",children:g.jsx(qv,{})}),g.jsx("div",{className:"flex-1 h-full max-h-full p-4 z-[1]",children:o?g.jsx(mf,{loadingClass:"!w-full !h-[800px]"}):g.jsx(Uv,{questionData:t})})]}),g.jsx("div",{className:"border-b bg-white border-t border-[#E4E7EC]",children:g.jsx($m,{onSubmit:e})})]})})}const Yv=({onSubmit:e,questionData:t,isReadOnly:r,config:n={buttonColor:"#333"},title:o,loading:i,backUrl:s})=>(p.useEffect(()=>{n&&dl("config",n)},[n]),g.jsx(Kv,{onSubmit:e,questionData:t,isReadOnly:r,title:o,backUrl:s,loading:i})),Er={required:"This field is required",email:"Invalid email format",minLength:e=>`Minimum length is ${e}`,maxLength:e=>`Maximum length is ${e}`,minAmount:e=>`Minimum amount is ${e}`,maxAmount:e=>`Maximum amount is ${e}`},Jv=e=>({textField:de().nullable(),longText:de().nullable(),numberField:Vr().nullable().transform(r=>isNaN(r)?null:r),amountField:Vr().nullable().transform(r=>isNaN(r)?null:r),selectField:de().nullable(),checkbox:Rr().nullable(),radio:Rr().nullable(),email:de().nullable().email(Er.email),date:Ns().typeError("Invalid date").nullable()})[e]||Rr().nullable(),Gv=(e,t,r)=>t?e.type==="boolean"?e.oneOf([!0],r||Er.required):e.required(r||Er.required):e,Xv=(e,{minLength:t,maxLength:r,minLengthMessage:n,maxLengthMessage:o})=>{let i=e;return t&&(i=i.min(t,n||Er.minLength(t))),r&&(i=i.max(r,o||Er.maxLength(r))),i},Zv=(e,{minAmount:t,maxAmount:r,minAmountMessage:n,maxAmountMessage:o})=>{let i=e;return t&&(i=i.min(parseFloat(String(t)),n||Er.minAmount(t))),r&&(i=i.max(parseFloat(String(r)),o||Er.maxAmount(r))),i};function Qv(e){const t={};return e.forEach(({questionData:r})=>{r.forEach(n=>{const{id:o,type:i,isRequired:s,requiredMessage:a}=n;let l=Jv(i);l=Gv(l,s,a),i==="textField"||i==="longText"||i==="email"?l=Xv(l,n):(i==="numberField"||i==="amountField")&&(l=Zv(l,n)),t[o]=l})}),_n().shape(t)}function ew(e){return e.reduce((t,r)=>(t[r.id]=r.value,t),{})}const Uo=(e,t)=>{const r=ff[e.type];return r?g.jsxs("div",{children:[e.inputLabel&&g.jsx("label",{className:"block text-sm font-medium mb-[5px]",children:e.inputLabel}),g.jsx(r,{element:e,state:"edit",validationData:t})]}):null};function tw({form_data:e,options:t}){return g.jsx("div",{className:"grid gap-y-6",children:e.flatMap(r=>{var n;return(n=r.questionData)==null?void 0:n.map(o=>{var i,s;if(o.type==="grid"){const a=r.questionData.filter(l=>l.gridId===o.id);return g.jsx(Gs,{element:o,customClass:"p-0 min-h-[60px] border-none",children:a.map(l=>{var u;return g.jsx(Js,{col:(u=l.gridPosition)==null?void 0:u.col,customClass:"p-0",children:Uo(l,t)},l.id)})},o.id)}return o.gridId?null:g.jsxs("div",{className:se("group relative grid gap-y-[6px]",o.elementClass),children:[Uo(o,t),g.jsx("div",{className:"text-xs text-red-600 mt-1",children:(s=(i=t==null?void 0:t.errors)==null?void 0:i[o.id])==null?void 0:s.message})]},o.id)})})})}function rw({form_data:e,options:t,current:r}){var n;return g.jsx("div",{className:"grid gap-y-6",children:(n=e[r].questionData)==null?void 0:n.map(o=>{var i,s;if(o.type==="grid"){const a=e[r].questionData.filter(l=>l.gridId===o.id);return g.jsx(Gs,{element:o,customClass:"p-0 min-h-[60px] border-none",children:a.map(l=>{var u;return g.jsx(Js,{col:(u=l.gridPosition)==null?void 0:u.col,customClass:"p-0",children:Uo(l,t)},l.id)})},o.id)}return o.gridId?null:g.jsxs("div",{className:se("group relative grid gap-y-[6px]",o.elementClass),children:[Uo(o,t),g.jsx("div",{className:"text-xs text-red-600 mt-1",children:(s=(i=t==null?void 0:t.errors)==null?void 0:i[o.id])==null?void 0:s.message})]},o.id)})})}const nw=({form_data:e,answerData:t,ignoreValidation:r,onSubmitData:n,isReadOnly:o,renderType:i="multi"})=>{const[s,a]=p.useState(0),l=p.useMemo(()=>e.length,[e]),u=Qv(e),c=Ss({resolver:Cs(u),mode:"onSubmit",defaultValues:{}}),{register:f,setValue:h,watch:m,handleSubmit:d,reset:y,getValues:x,formState:{errors:b,isSubmitting:w},trigger:v}=c,E=sr("config"),k=O=>{const j=e.flatMap(D=>D.questionData.map(N=>({id:N.id,value:O[N.id],sectionId:D.id,type:N.type})));n==null||n(j)};p.useEffect(()=>{if(t!=null&&t.length){const O=ew(t);y(O)}},[t,y]);async function T(){var O;!r&&!await v((O=e==null?void 0:e[s].questionData)==null?void 0:O.map(D=>D.id))||a(j=>j+1)}function C(){a(O=>O-1)}return g.jsx(fl,{children:g.jsx(J0,{...c,children:g.jsxs("form",{onSubmit:d(k),className:"container mx-auto p-6 h-full",children:[g.jsx("div",{className:"relative w-full flex flex-col gap-y-12 py-4",children:g.jsxs("div",{children:[g.jsxs("div",{className:"mb-4",children:[(e==null?void 0:e[s].title)&&g.jsx("h2",{className:"text-lg font-semibold mb-[6px]",children:e[s].title}),(e==null?void 0:e[s].description)&&g.jsx("p",{className:"text-sm",children:e[s].description})]}),i==="multi"?g.jsx(rw,{form_data:e,options:{register:f,setValue:h,watch:m,errors:b,trigger:v,isSubmitting:w,isReadOnly:o,getValues:x},current:s}):g.jsx(tw,{form_data:e,options:{register:f,setValue:h,watch:m,errors:b,trigger:v,isSubmitting:w,isReadOnly:o,getValues:x}})]},e==null?void 0:e[s].id)}),g.jsxs("div",{className:"pt-8 flex justify-end items-center gap-4",children:[s!==0&&g.jsx(Fr,{type:"button",text:"Back",onClick:C,btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-gray-200 rounded-lg"}),s!==l-1?g.jsx(Fr,{type:"button",text:"Continue",onClick:T,style:{background:(E==null?void 0:E.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg"}):!r&&g.jsx(Fr,{isDisabled:w,isLoading:w,type:"submit",text:"Submit",style:{background:(E==null?void 0:E.buttonColor)||"#333"},btnClass:"text-gray-700 border-[#98A2B3] !font-medium !py-[10px] px-10 bg-blue-600 text-white rounded-lg"})]})]})})})};function hf({answerData:e,form_data:t,ignoreValidation:r,onSubmit:n,isReadOnly:o=!1,loading:i=!1,config:s={buttonColor:"#333"},renderType:a}){return p.useEffect(()=>{s&&dl("config",s)},[s]),i?g.jsx(mf,{}):t?g.jsx("div",{className:"w-full h-full",children:g.jsx(nw,{form_data:t,answerData:e,ignoreValidation:r,onSubmitData:n,isReadOnly:o,renderType:a})}):g.jsx("div",{children:g.jsx("p",{children:"Error: No form data available. Please ensure the form data is saved correctly."})})}Pt.FormBuilder=Yv,Pt.FormViewer=hf,Object.defineProperty(Pt,Symbol.toStringTag,{value:"Module"})});
|