@object-ui/plugin-form 3.1.2 → 3.1.4

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.
@@ -1,6 +1,6 @@
1
- (function(_,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("@object-ui/core"),require("@object-ui/react"),require("@object-ui/fields"),require("@object-ui/components"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react","@object-ui/core","@object-ui/react","@object-ui/fields","@object-ui/components","lucide-react"],i):(_=typeof globalThis<"u"?globalThis:_||self,i(_.ObjectUIPluginForm={},_.React,_.core,_.react,_.fields,_.components,_.lucideReact))})(this,(function(_,i,ee,H,W,u,J){"use strict";var te={exports:{}},Q={};var ae;function he(){if(ae)return Q;ae=1;var e=Symbol.for("react.transitional.element"),l=Symbol.for("react.fragment");function o(x,s,p){var g=null;if(p!==void 0&&(g=""+p),s.key!==void 0&&(g=""+s.key),"key"in s){p={};for(var E in s)E!=="key"&&(p[E]=s[E])}else p=s;return s=p.ref,{$$typeof:e,type:x,key:g,ref:s!==void 0?s:null,props:p}}return Q.Fragment=l,Q.jsx=o,Q.jsxs=o,Q}var Z={};var de;function Fe(){return de||(de=1,process.env.NODE_ENV!=="production"&&(function(){function e(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===j?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case V:return"Fragment";case L:return"Profiler";case z:return"StrictMode";case n:return"Suspense";case d:return"SuspenseList";case T:return"Activity"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case I:return"Portal";case q:return r.displayName||"Context";case G:return(r._context.displayName||"Context")+".Consumer";case m:var S=r.render;return r=r.displayName,r||(r=S.displayName||S.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case a:return S=r.displayName||null,S!==null?S:e(r.type)||"Memo";case f:S=r._payload,r=r._init;try{return e(r(S))}catch{}}return null}function l(r){return""+r}function o(r){try{l(r);var S=!1}catch{S=!0}if(S){S=console;var M=S.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return M.call(S,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),l(r)}}function x(r){if(r===V)return"<>";if(typeof r=="object"&&r!==null&&r.$$typeof===f)return"<...>";try{var S=e(r);return S?"<"+S+">":"<...>"}catch{return"<...>"}}function s(){var r=c.A;return r===null?null:r.getOwner()}function p(){return Error("react-stack-top-frame")}function g(r){if(P.call(r,"key")){var S=Object.getOwnPropertyDescriptor(r,"key").get;if(S&&S.isReactWarning)return!1}return r.key!==void 0}function E(r,S){function M(){w||(w=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",S))}M.isReactWarning=!0,Object.defineProperty(r,"key",{get:M,configurable:!0})}function A(){var r=e(this.type);return y[r]||(y[r]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),r=this.props.ref,r!==void 0?r:null}function k(r,S,M,R,le,oe){var Y=M.ref;return r={$$typeof:C,type:r,key:S,props:M,_owner:R},(Y!==void 0?Y:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:A}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(r,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:le}),Object.defineProperty(r,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:oe}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function O(r,S,M,R,le,oe){var Y=S.children;if(Y!==void 0)if(R)if(h(Y)){for(R=0;R<Y.length;R++)v(Y[R]);Object.freeze&&Object.freeze(Y)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else v(Y);if(P.call(S,"key")){Y=e(r);var X=Object.keys(S).filter(function(Pe){return Pe!=="key"});R=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",D[Y+R]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`lucide-react`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`lucide-react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginForm={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e.lucide_react))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var s=Object.create,c=Object.defineProperty,l=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,d=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=u(t),a=0,o=i.length,s;a<o;a++)s=i[a],!f.call(e,s)&&s!==n&&c(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=l(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:s(d(e)),m(t||!e||!e.__esModule?c(n,`default`,{value:e,enumerable:!0}):n,e)))(t);var h=p((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),g=p((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,R,Y,X,Y),D[Y+R]=!0)}if(Y=null,M!==void 0&&(o(M),Y=""+M),g(S)&&(o(S.key),Y=""+S.key),"key"in S){M={};for(var se in S)se!=="key"&&(M[se]=S[se])}else M=S;return Y&&E(M,typeof r=="function"?r.displayName||r.name||"Unknown":r),k(r,Y,M,s(),le,oe)}function v(r){N(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===f&&(r._payload.status==="fulfilled"?N(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function N(r){return typeof r=="object"&&r!==null&&r.$$typeof===C}var F=i,C=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),V=Symbol.for("react.fragment"),z=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),q=Symbol.for("react.context"),m=Symbol.for("react.forward_ref"),n=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),a=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),T=Symbol.for("react.activity"),j=Symbol.for("react.client.reference"),c=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=Object.prototype.hasOwnProperty,h=Array.isArray,b=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(r){return r()}};var w,y={},$=F.react_stack_bottom_frame.bind(F,p)(),U=b(x(p)),D={};Z.Fragment=V,Z.jsx=function(r,S,M){var R=1e4>c.recentlyCreatedOwnerStacks++;return O(r,S,M,!1,R?Error("react-stack-top-frame"):$,R?b(x(r)):U)},Z.jsxs=function(r,S,M){var R=1e4>c.recentlyCreatedOwnerStacks++;return O(r,S,M,!0,R?Error("react-stack-top-frame"):$,R?b(x(r)):U)}})()),Z}var ue;function Ee(){return ue||(ue=1,process.env.NODE_ENV==="production"?te.exports=he():te.exports=Fe()),te.exports}var t=Ee();const B=({label:e,description:l,collapsible:o=!1,collapsed:x=!1,columns:s=1,children:p,className:g,gridClassName:E})=>{const[A,k]=i.useState(x),O={1:"grid-cols-1",2:"grid-cols-1 md:grid-cols-2",3:"grid-cols-1 md:grid-cols-2 lg:grid-cols-3",4:"grid-cols-1 md:grid-cols-2 lg:grid-cols-4"},v=()=>{o&&k(!A)};return t.jsxs("div",{className:u.cn("form-section",g),children:[(e||l)&&t.jsxs("div",{className:u.cn("flex items-start gap-2 mb-4",o&&"cursor-pointer select-none"),onClick:v,role:o?"button":void 0,"aria-expanded":o?!A:void 0,children:[o&&t.jsx("span",{className:"mt-0.5 text-muted-foreground",children:A?t.jsx(J.ChevronRight,{className:"h-4 w-4"}):t.jsx(J.ChevronDown,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex-1",children:[e&&t.jsx("h3",{className:"text-base font-semibold text-foreground",children:e}),l&&t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:l})]})]}),!A&&t.jsx("div",{className:u.cn("grid gap-4",E||O[s]),children:p})]})},ce=({schema:e,dataSource:l,className:o})=>{const{fieldLabel:x}=H.useSafeFieldLabel(),[s,p]=i.useState(null),[g,E]=i.useState({}),[A,k]=i.useState(!0),[O,v]=i.useState(null),[N,F]=i.useState(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||"tab-0");i.useEffect(()=>{(async()=>{if(!l){k(!1);return}try{const n=await l.getObjectSchema(e.objectName);p(n)}catch(n){v(n)}})()},[e.objectName,l]),i.useEffect(()=>{(s||!l)&&(async()=>{if(e.mode==="create"||!e.recordId||!l){E(e.initialData||e.initialValues||{}),k(!1);return}try{const n=await l.findOne(e.objectName,e.recordId);E(n||{})}catch(n){v(n)}finally{k(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,l,e.objectName]);const C=i.useCallback(m=>{const n=[];for(const d of m.fields){const a=typeof d=="string"?d:d.name;if(typeof d=="object")n.push(d);else if(s?.fields?.[a]){const f=s.fields[a];n.push({name:a,label:x(e.objectName,a,f.label||a),type:W.mapFieldTypeToFormType(f.type),required:f.required||!1,disabled:e.readOnly||e.mode==="view"||f.readonly,placeholder:f.placeholder,description:f.help||f.description,validation:W.buildValidationRules(f),field:f,options:f.options,multiple:f.multiple})}else n.push({name:a,label:a,type:"input"})}return n},[s,e.readOnly,e.mode]),I=i.useCallback(async m=>{if(!l)return e.onSuccess&&await e.onSuccess(m),m;try{let n;return e.mode==="create"?n=await l.create(e.objectName,m):e.mode==="edit"&&e.recordId&&(n=await l.update(e.objectName,e.recordId,m)),e.onSuccess&&await e.onSuccess(n),n}catch(n){throw e.onError&&e.onError(n),n}},[e,l]),V=i.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),z=(m,n)=>m.name||m.label||`tab-${n}`;if(O)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:O.message})]});if(A)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const G={type:"form",fields:e.sections.flatMap(m=>C(m)),layout:"vertical",defaultValues:g,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:I,onCancel:V},q=e.tabPosition==="left"||e.tabPosition==="right";return t.jsx("div",{className:u.cn("w-full",o,e.className),children:t.jsxs(u.Tabs,{value:N,onValueChange:F,orientation:q?"vertical":"horizontal",className:u.cn(q&&"flex gap-4"),children:[t.jsx(u.TabsList,{className:u.cn(q?"flex-col h-auto":"",e.tabPosition==="bottom"&&"order-last",e.tabPosition==="right"&&"order-last"),children:e.sections.map((m,n)=>t.jsx(u.TabsTrigger,{value:z(m,n),className:q?"w-full justify-start":"",children:m.label||`Tab ${n+1}`},z(m,n)))}),t.jsx("div",{className:"flex-1",children:e.sections.map((m,n)=>t.jsx(u.TabsContent,{value:z(m,n),className:"mt-0",children:t.jsx(B,{description:m.description,columns:m.columns||1,children:t.jsx(H.SchemaRenderer,{schema:{...G,fields:C(m),showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1}})})},z(m,n)))})]})})},fe=({schema:e,dataSource:l,className:o})=>{const{fieldLabel:x}=H.useSafeFieldLabel(),[s,p]=i.useState(null),[g,E]=i.useState({}),[A,k]=i.useState(!0),[O,v]=i.useState(null),[N,F]=i.useState(0),[C,I]=i.useState(new Set),[V,z]=i.useState(!1),L=e.sections.length,G=N===0,q=N===L-1;i.useEffect(()=>{(async()=>{if(!l){k(!1);return}try{const h=await l.getObjectSchema(e.objectName);p(h)}catch(h){v(h)}})()},[e.objectName,l]),i.useEffect(()=>{(s||!l)&&(async()=>{if(e.mode==="create"||!e.recordId||!l){E(e.initialData||e.initialValues||{}),k(!1);return}try{const h=await l.findOne(e.objectName,e.recordId);E(h||{})}catch(h){v(h)}finally{k(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,l,e.objectName]);const m=i.useCallback(P=>{const h=[];for(const b of P.fields){const w=typeof b=="string"?b:b.name;if(typeof b=="object")h.push(b);else if(s?.fields?.[w]){const y=s.fields[w];h.push({name:w,label:x(e.objectName,w,y.label||w),type:W.mapFieldTypeToFormType(y.type),required:y.required||!1,disabled:e.readOnly||e.mode==="view"||y.readonly,placeholder:y.placeholder,description:y.help||y.description,validation:W.buildValidationRules(y),field:y,options:y.options,multiple:y.multiple})}else h.push({name:w,label:w,type:"input"})}return h},[s,e.readOnly,e.mode]),n=i.useMemo(()=>N>=0&&N<L?m(e.sections[N]):[],[N,L,e.sections,m]),d=i.useCallback(async P=>{const h={...g,...P};if(E(h),I(b=>new Set(b).add(N)),q){z(!0);try{if(!l)return e.onSuccess&&await e.onSuccess(h),h;let b;return e.mode==="create"?b=await l.create(e.objectName,h):e.mode==="edit"&&e.recordId&&(b=await l.update(e.objectName,e.recordId,h)),e.onSuccess&&await e.onSuccess(b),b}catch(b){throw e.onError&&e.onError(b),b}finally{z(!1)}}else a(N+1)},[g,N,q,e,l]),a=i.useCallback(P=>{P>=0&&P<L&&(F(P),e.onStepChange&&e.onStepChange(P))},[L,e]),f=i.useCallback(()=>{a(N-1)},[N,a]),T=i.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),j=i.useCallback(P=>{(e.allowSkip||C.has(P)||P<=N)&&a(P)},[e.allowSkip,C,N,a]);if(O)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:O.message})]});if(A)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const c=e.sections[N];return t.jsxs("div",{className:u.cn("w-full",o,e.className),children:[e.showStepIndicator!==!1&&t.jsx("nav",{"aria-label":"Progress",className:"mb-8",children:t.jsx("ol",{className:"flex items-center",children:e.sections.map((P,h)=>{const b=h===N,w=C.has(h),y=e.allowSkip||w||h<=N;return t.jsxs("li",{className:u.cn("relative flex-1",h!==L-1&&"pr-8 sm:pr-12"),children:[h!==L-1&&t.jsx("div",{className:"absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5","aria-hidden":"true",children:t.jsx("div",{className:u.cn("h-full",w?"bg-primary":"bg-muted")})}),t.jsxs("button",{type:"button",className:u.cn("group relative flex items-center",y?"cursor-pointer":"cursor-not-allowed"),onClick:()=>j(h),disabled:!y,children:[t.jsx("span",{className:u.cn("flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors",w&&"bg-primary text-primary-foreground",b&&!w&&"border-2 border-primary bg-background text-primary",!b&&!w&&"border-2 border-muted bg-background text-muted-foreground"),children:w?t.jsx(J.Check,{className:"h-3 w-3 sm:h-4 sm:w-4"}):h+1}),t.jsx("span",{className:"ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",children:t.jsx("span",{className:u.cn(b?"text-foreground":"text-muted-foreground"),children:P.label||`Step ${h+1}`})})]})]},h)})})}),t.jsx("div",{className:"min-h-[200px]",children:c&&t.jsx(B,{label:c.label,description:c.description,columns:c.columns||1,children:n.length>0?t.jsx(H.SchemaRenderer,{schema:{type:"form",fields:n,layout:"vertical",defaultValues:g,showSubmit:!1,showCancel:!1,onSubmit:d}}):t.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No fields configured for this step"})})}),t.jsxs("div",{className:"flex items-center justify-between mt-6 pt-4 border-t",children:[t.jsx("div",{children:e.showCancel!==!1&&t.jsx(u.Button,{variant:"ghost",onClick:T,children:e.cancelText||"Cancel"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm text-muted-foreground mr-2",children:["Step ",N+1," of ",L]}),!G&&t.jsxs(u.Button,{variant:"outline",onClick:f,children:[t.jsx(J.ChevronLeft,{className:"h-4 w-4 mr-1"}),e.prevText||"Back"]}),q?t.jsx(u.Button,{onClick:()=>d(g),disabled:V||e.mode==="view",children:V?"Submitting...":e.submitText||(e.mode==="create"?"Create":"Update")}):t.jsxs(u.Button,{onClick:()=>d(g),children:[e.nextText||"Next",t.jsx(J.ChevronRight,{className:"h-4 w-4 ml-1"})]})]})]})]})},be=({schema:e,dataSource:l,className:o})=>{const{fieldLabel:x}=H.useSafeFieldLabel(),[s,p]=i.useState(null),[g,E]=i.useState({}),[A,k]=i.useState(!0),[O,v]=i.useState(null);i.useEffect(()=>{(async()=>{if(!l){k(!1);return}try{const n=await l.getObjectSchema(e.objectName);p(n)}catch(n){v(n),k(!1)}})()},[e.objectName,l]),i.useEffect(()=>{(s||!l)&&(async()=>{if(e.mode==="create"||!e.recordId){E(e.initialData||e.initialValues||{}),k(!1);return}if(!l){E(e.initialData||e.initialValues||{}),k(!1);return}try{const n=await l.findOne(e.objectName,e.recordId);E(n||{})}catch(n){v(n)}finally{k(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,l,e.objectName]);const N=i.useCallback(m=>{const n=[];for(const d of m.fields){const a=typeof d=="string"?d:d.name;if(typeof d=="object")n.push(d);else if(s?.fields?.[a]){const f=s.fields[a];n.push({name:a,label:x(e.objectName,a,f.label||a),type:W.mapFieldTypeToFormType(f.type),required:f.required||!1,disabled:e.readOnly||e.mode==="view"||f.readonly,placeholder:f.placeholder,description:f.help||f.description,validation:W.buildValidationRules(f),field:f,options:f.options,multiple:f.multiple})}else n.push({name:a,label:a,type:"input"})}return n},[s,e.readOnly,e.mode]),F=i.useCallback(async m=>{if(!l)return e.onSuccess&&await e.onSuccess(m),m;try{let n;return e.mode==="create"?n=await l.create(e.objectName,m):e.mode==="edit"&&e.recordId&&(n=await l.update(e.objectName,e.recordId,m)),e.onSuccess&&await e.onSuccess(n),n}catch(n){throw e.onError&&e.onError(n),n}},[e,l]),C=i.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),I=i.useMemo(()=>e.sections.slice(0,1),[e.sections]),V=i.useMemo(()=>e.sections.slice(1),[e.sections]);i.useMemo(()=>e.sections.flatMap(m=>N(m)),[e.sections,N]);const z=e.splitDirection||"horizontal",L=e.splitSize||50;if(O)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:O.message})]});if(A)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const G={type:"form",layout:"vertical",defaultValues:g,onSubmit:F,onCancel:C},q=(m,n)=>t.jsx("div",{className:"space-y-4 p-4",children:m.map((d,a)=>t.jsx(B,{label:d.label,description:d.description,columns:d.columns||1,children:t.jsx(H.SchemaRenderer,{schema:{...G,fields:N(d),showSubmit:n&&e.showSubmit!==!1&&e.mode!=="view",showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText}})},d.name||d.label||a))});return t.jsx("div",{className:u.cn("w-full",o,e.className),children:t.jsxs(u.ResizablePanelGroup,{orientation:z,className:"min-h-[300px] rounded-lg border",children:[t.jsx(u.ResizablePanel,{defaultSize:L,minSize:20,children:q(I,V.length===0)}),V.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(u.ResizableHandle,{withHandle:e.splitResizable!==!1}),t.jsx(u.ResizablePanel,{defaultSize:100-L,minSize:20,children:q(V,!0)})]})]})})},ke=new Set(["field:textarea","field:markdown","field:html","field:grid","field:rich-text","textarea","markdown","html","grid","rich-text"]),Oe=new Set(["formula","summary","auto_number","autonumber"]);function me(e){return ke.has(e)}function pe(e){return Oe.has(e)}function ye(e){return e<=3?1:2}function re(e,l){return l<=1?e:e.map(o=>o.colSpan!==void 0?o:o.type&&me(o.type)?{...o,colSpan:l}:o)}function xe(e,l){return l?.fields?e.filter(o=>{const x=l.fields[o.name];return x?!pe(x.type):!0}):e}function ie(e){return e<=1?"default":e===2?"xl":"full"}function K(e,l,o,x){let s=[...e];if(x==="create"&&(s=xe(s,l)),o!==void 0)return s=re(s,o),{fields:s,columns:o};const p=ye(s.length);return s=re(s,p),{fields:s,columns:p}}const ge={1:void 0,2:"grid gap-4 grid-cols-1 @md:grid-cols-2",3:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",4:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"},je=({schema:e,dataSource:l,className:o})=>{const{fieldLabel:x}=H.useSafeFieldLabel(),[s,p]=i.useState(null),[g,E]=i.useState([]),[A,k]=i.useState({}),[O,v]=i.useState(!0),[N,F]=i.useState(null),C=e.open!==!1,I=e.drawerSide||"right";i.useEffect(()=>{(async()=>{if(!l){v(!1);return}try{const a=await l.getObjectSchema(e.objectName);p(a)}catch(a){F(a),v(!1)}})()},[e.objectName,l]),i.useEffect(()=>{(s||!l)&&(async()=>{if(e.mode==="create"||!e.recordId){k(e.initialData||e.initialValues||{}),v(!1);return}if(!l){k(e.initialData||e.initialValues||{}),v(!1);return}try{const a=await l.findOne(e.objectName,e.recordId);k(a||{})}catch(a){F(a)}finally{v(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,l,e.objectName]);const V=i.useCallback(d=>{const a=[];for(const f of d.fields){const T=typeof f=="string"?f:f.name;if(typeof f=="object")a.push(f);else if(s?.fields?.[T]){const j=s.fields[T];a.push({name:T,label:x(e.objectName,T,j.label||T),type:W.mapFieldTypeToFormType(j.type),required:j.required||!1,disabled:e.readOnly||e.mode==="view"||j.readonly,placeholder:j.placeholder,description:j.help||j.description,validation:W.buildValidationRules(j),field:j,options:j.options,multiple:j.multiple})}else a.push({name:T,label:T,type:"input"})}return a},[s,e.readOnly,e.mode]);i.useEffect(()=>{if(!s&&l)return;if(e.customFields?.length){E(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!s)return;const d=e.fields||Object.keys(s.fields||{}),a=[];for(const f of d){const T=typeof f=="string"?f:f.name;if(!T)continue;const j=s.fields?.[T];j&&a.push({name:T,label:x(e.objectName,T,j.label||T),type:W.mapFieldTypeToFormType(j.type),required:j.required||!1,disabled:e.readOnly||e.mode==="view"||j.readonly,placeholder:j.placeholder,description:j.help||j.description,validation:W.buildValidationRules(j),field:j,options:j.options,multiple:j.multiple})}E(a),v(!1)},[s,e.fields,e.customFields,e.sections,e.readOnly,e.mode,l]);const z=i.useCallback(async d=>{if(!l)return e.onSuccess&&await e.onSuccess(d),e.onOpenChange?.(!1),d;try{let a;return e.mode==="create"?a=await l.create(e.objectName,d):e.mode==="edit"&&e.recordId&&(a=await l.update(e.objectName,e.recordId,d)),e.onSuccess&&await e.onSuccess(a),e.onOpenChange?.(!1),a}catch(a){throw e.onError&&e.onError(a),a}},[e,l]),L=i.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),G=i.useMemo(()=>e.drawerWidth?I==="left"||I==="right"?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}:void 0,[e.drawerWidth,I]),m={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:A,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:z,onCancel:L},n=()=>{if(N)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:N.message})]});if(O)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});if(e.sections?.length)return t.jsx("div",{className:"space-y-6",children:e.sections.map((f,T)=>{const j=f.columns||1;return t.jsx(B,{label:f.label,description:f.description,columns:j,gridClassName:ge[j],children:t.jsx(H.SchemaRenderer,{schema:{...m,fields:V(f),showSubmit:T===e.sections.length-1&&m.showSubmit,showCancel:T===e.sections.length-1&&m.showCancel}})},f.name||f.label||T)})});const d=K(g,s,e.columns,e.mode),a=ge[d.columns||1];return t.jsx(H.SchemaRenderer,{schema:{...m,fields:d.fields,columns:d.columns,...a?{fieldContainerClass:a}:{}}})};return t.jsx(u.Sheet,{open:C,onOpenChange:e.onOpenChange,children:t.jsxs(u.SheetContent,{side:I,className:u.cn("overflow-y-auto",o,e.className),style:G,children:[(e.title||e.description)&&t.jsxs(u.SheetHeader,{children:[e.title&&t.jsx(u.SheetTitle,{children:e.title}),e.description&&t.jsx(u.SheetDescription,{children:e.description})]}),t.jsx("div",{className:"@container py-4",children:n()})]})})},we={sm:"sm:max-w-sm",default:"sm:max-w-lg",lg:"sm:max-w-2xl",xl:"sm:max-w-5xl",full:"sm:max-w-[95vw] sm:w-full"},Ne={1:void 0,2:"grid gap-4 grid-cols-1 @md:grid-cols-2",3:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3",4:"grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4"},Se=({schema:e,dataSource:l,className:o})=>{const{fieldLabel:x}=H.useSafeFieldLabel(),[s,p]=i.useState(null),[g,E]=i.useState([]),[A,k]=i.useState({}),[O,v]=i.useState(!0),[N,F]=i.useState(null),[C,I]=i.useState(!1),V=e.open!==!1,z=i.useId(),L=i.useMemo(()=>e.sections?.length||e.customFields?.length?null:K(g,s,e.columns,e.mode),[g,s,e.columns,e.mode,e.sections,e.customFields]),G=i.useMemo(()=>{if(e.modalSize)return e.modalSize;if(L?.columns&&L.columns>1)return ie(L.columns);if(e.sections?.length){const w=Math.max(...e.sections.map(y=>Number(y.columns)||1));if(w>1)return ie(w)}return"default"},[e.modalSize,L,e.sections]),q=we[G]||we.default;i.useEffect(()=>{(async()=>{if(!l){v(!1);return}try{const y=await l.getObjectSchema(e.objectName);p(y)}catch(y){F(y),v(!1)}})()},[e.objectName,l]),i.useEffect(()=>{(s||!l)&&(async()=>{if(e.mode==="create"||!e.recordId){k(e.initialData||e.initialValues||{}),v(!1);return}if(!l){k(e.initialData||e.initialValues||{}),v(!1);return}try{const y=await l.findOne(e.objectName,e.recordId);k(y||{})}catch(y){F(y)}finally{v(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,l,e.objectName]);const m=i.useCallback(w=>{const y=[];for(const $ of w.fields){const U=typeof $=="string"?$:$.name;if(typeof $=="object")y.push($);else if(s?.fields?.[U]){const D=s.fields[U];y.push({name:U,label:x(e.objectName,U,D.label||U),type:W.mapFieldTypeToFormType(D.type),required:D.required||!1,disabled:e.readOnly||e.mode==="view"||D.readonly,placeholder:D.placeholder,description:D.help||D.description,validation:W.buildValidationRules(D),field:D,options:D.options,multiple:D.multiple})}else y.push({name:U,label:U,type:"input"})}return y},[s,e.readOnly,e.mode]);i.useEffect(()=>{if(!s&&l)return;if(e.customFields?.length){E(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!s)return;const w=e.fields||Object.keys(s.fields||{}),y=[];for(const $ of w){const U=typeof $=="string"?$:$.name;if(!U)continue;const D=s.fields?.[U];D&&y.push({name:U,label:x(e.objectName,U,D.label||U),type:W.mapFieldTypeToFormType(D.type),required:D.required||!1,disabled:e.readOnly||e.mode==="view"||D.readonly,placeholder:D.placeholder,description:D.help||D.description,validation:W.buildValidationRules(D),field:D,options:D.options,multiple:D.multiple})}E(y),v(!1)},[s,e.fields,e.customFields,e.sections,e.readOnly,e.mode,l]);const n=i.useCallback(async w=>{I(!0);try{if(!l)return e.onSuccess&&await e.onSuccess(w),e.onOpenChange?.(!1),w;let y;return e.mode==="create"?y=await l.create(e.objectName,w):e.mode==="edit"&&e.recordId&&(y=await l.update(e.objectName,e.recordId,w)),e.onSuccess&&await e.onSuccess(y),e.onOpenChange?.(!1),y}catch(y){throw e.onError&&e.onError(y),y}finally{I(!1)}},[e,l]),d=i.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),a=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",f=e.showSubmit!==!1&&e.mode!=="view",T=e.showCancel!==!1,j=e.submitText||(e.mode==="create"?"Create":"Update"),c=e.cancelText||"Cancel",P={type:"form",layout:a,defaultValues:A,submitLabel:j,cancelLabel:c,showSubmit:f,showCancel:T,onSubmit:n,onCancel:d,showActions:!1,id:z},h=()=>{if(N)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:N.message})]});if(O)return t.jsx("div",{className:"space-y-4","data-testid":"modal-form-skeleton",children:[1,2,3].map($=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(u.Skeleton,{className:"h-4 w-24"}),t.jsx(u.Skeleton,{className:"h-10 w-full"})]},$))});if(e.sections?.length)return t.jsx("div",{className:"space-y-6",children:e.sections.map(($,U)=>{const D=$.columns||1;return t.jsx(B,{label:$.label,description:$.description,columns:D,gridClassName:Ne[D],children:t.jsx(H.SchemaRenderer,{schema:{...P,fields:m($)}})},$.name||$.label||U)})});const w=L??K(g,s,e.columns,e.mode),y=Ne[w.columns||1];return t.jsx(H.SchemaRenderer,{schema:{...P,fields:w.fields,columns:w.columns,...y?{fieldContainerClass:y}:{}}})},b=!O&&!N&&(f||T);return t.jsx(u.Dialog,{open:V,onOpenChange:e.onOpenChange,children:t.jsxs(u.MobileDialogContent,{className:u.cn(q,"flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0",o,e.className),children:[(e.title||e.description)&&t.jsxs(u.DialogHeader,{className:"shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b",children:[e.title&&t.jsx(u.DialogTitle,{children:e.title}),e.description&&t.jsx(u.DialogDescription,{children:e.description})]}),t.jsx("div",{className:"@container flex-1 overflow-y-auto px-4 sm:px-6 py-4",children:h()}),b&&t.jsx("div",{className:"shrink-0 border-t px-4 sm:px-6 py-3 bg-background","data-testid":"modal-form-footer",children:t.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:justify-end",children:[T&&t.jsx(u.Button,{type:"button",variant:"outline",onClick:d,disabled:C,className:"w-full sm:w-auto",children:c}),f&&t.jsxs(u.Button,{type:"submit",form:z,disabled:C,className:"w-full sm:w-auto",children:[C&&t.jsx(J.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),j]})]})})]})})},ne=({schema:e,dataSource:l})=>{if(e.formType==="tabbed"&&e.sections?.length)return t.jsx(ce,{schema:{...e,formType:"tabbed",sections:e.sections.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:l,className:e.className});if(e.formType==="wizard"&&e.sections?.length)return t.jsx(fe,{schema:{...e,formType:"wizard",sections:e.sections.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:l,className:e.className});if(e.formType==="split"&&e.sections?.length)return t.jsx(be,{schema:{...e,formType:"split",sections:e.sections.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:l,className:e.className});if(e.formType==="drawer"){const{layout:o,...x}=e,s=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(je,{schema:{...x,layout:s,formType:"drawer",sections:e.sections?.map(p=>({name:p.name,label:p.label,description:p.description,columns:p.columns,fields:p.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:l,className:e.className})}if(e.formType==="modal"){const{layout:o,...x}=e,s=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(Se,{schema:{...x,layout:s,formType:"modal",sections:e.sections?.map(p=>({name:p.name,label:p.label,description:p.description,columns:p.columns,fields:p.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:l,className:e.className})}return t.jsx(De,{schema:e,dataSource:l})},De=({schema:e,dataSource:l})=>{const{fieldLabel:o}=H.useSafeFieldLabel(),[x,s]=i.useState(null),[p,g]=i.useState([]),[E,A]=i.useState(null),[k,O]=i.useState(!0),[v,N]=i.useState(null),F=e.customFields&&e.customFields.length>0;i.useEffect(()=>{F&&(A(e.initialData||e.initialValues||{}),O(!1))},[F,e.initialData,e.initialValues]),i.useEffect(()=>{const n=async()=>{try{if(!l)throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");const d=await l.getObjectSchema(e.objectName);if(!d)throw new Error(`No schema found for object "${e.objectName}"`);s(d)}catch(d){N(d),O(!1)}};F?s({name:e.objectName,fields:{}}):e.objectName&&l?n():F||O(!1)},[e.objectName,l,F]),i.useEffect(()=>{x&&!F&&(async()=>{if(!e.recordId||e.mode==="create"){A(e.initialData||e.initialValues||{}),O(!1);return}if(!F){if(!l){N(new Error("DataSource is required for fetching record data (inline data not provided)")),O(!1);return}O(!0);try{const d=await l.findOne(e.objectName,e.recordId);A(d)}catch(d){console.error("Failed to fetch record:",d),N(d)}finally{O(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,l,x,F]),i.useEffect(()=>{if(F&&e.customFields){g(e.customFields),O(!1);return}if(!x)return;const n=[],d=e.fields||Object.keys(x.fields||{});(Array.isArray(d)?d:Object.keys(d)).forEach(T=>{const j=typeof T=="string"?T:T.name;if(!j)return;const c=x.fields?.[j];if(!c&&!F)return;const P=!c?.permissions||c?.permissions.write!==!1;if(e.mode!=="view"&&!P)return;const h=e.customFields?.find(b=>b.name===j);if(h)n.push(h);else if(c){const b={name:j,label:o(e.objectName,j,c.label||T),type:W.mapFieldTypeToFormType(c.type),required:c.required||!1,disabled:e.readOnly||e.mode==="view"||c.readonly,placeholder:c.placeholder,description:c.help||c.description,validation:W.buildValidationRules(c),field:c};if((c.type==="select"||c.type==="lookup"||c.type==="master_detail")&&(b.options=c.options||[],b.multiple=c.multiple),(c.type==="number"||c.type==="currency"||c.type==="percent")&&(b.inputType="number",b.min=c.min,b.max=c.max,b.step=c.precision?Math.pow(10,-c.precision):void 0),c.type==="date"&&(b.inputType="date"),c.type==="datetime"&&(b.inputType="datetime-local"),(c.type==="text"||c.type==="textarea"||c.type==="markdown"||c.type==="html")&&(b.maxLength=c.max_length,b.minLength=c.min_length),(c.type==="file"||c.type==="image")&&(b.inputType="file",b.multiple=c.multiple,b.accept=c.accept?c.accept.join(","):void 0,c.max_size)){const w=`Max size: ${W.formatFileSize(c.max_size)}`;b.description=b.description?`${b.description} (${w})`:w}c.type==="email"&&(b.inputType="email"),c.type==="phone"&&(b.inputType="tel"),c.type==="url"&&(b.inputType="url"),c.type==="password"&&(b.inputType="password"),c.type==="time"&&(b.inputType="time"),(c.type==="formula"||c.type==="summary"||c.type==="auto_number")&&(b.disabled=!0),c.visible_on&&(b.visible=w=>W.evaluateCondition(c.visible_on,w)),n.push(b)}}),g(n),!F&&e.recordId&&e.mode!=="create"&&l||O(!1)},[x,e.fields,e.customFields,e.readOnly,e.mode,F,e.recordId,l]);const C=i.useCallback(async(n,d)=>{if(n&&(n.nativeEvent||n._reactName==="onSubmit")&&(console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."),d===void 0&&(d=n,n={})),F&&!l)return e.onSuccess&&await e.onSuccess(n),n;if(!l)throw new Error("DataSource is required for form submission (inline mode not configured)");try{let a;if(e.mode==="create")a=await l.create(e.objectName,n);else if(e.mode==="edit"&&e.recordId)a=await l.update(e.objectName,e.recordId,n);else throw new Error("Invalid form mode or missing record ID");return e.onSuccess&&await e.onSuccess(a),a}catch(a){throw console.error("Failed to submit form:",a),e.onError&&e.onError(a),a}},[e,l,F]),I=i.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),z={...i.useMemo(()=>{if(!x?.fields)return{};const n={};return Object.keys(x.fields).forEach(d=>{const a=x.fields[d];a.defaultValue!==void 0&&(n[d]=a.defaultValue)}),n},[x]),...E};if(v)return t.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:v.message})]});if(k)return t.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const L=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical";if(e.sections?.length&&(!e.formType||e.formType==="simple"))return t.jsx("div",{className:"w-full space-y-6",children:e.sections.map((n,d)=>{const a=n.fields.map(T=>typeof T=="string"?T:T.name),f=p.filter(T=>a.includes(T.name));return t.jsx(B,{label:n.label,description:n.description,collapsible:n.collapsible,collapsed:n.collapsed,columns:n.columns,children:t.jsx(H.SchemaRenderer,{schema:{type:"form",fields:f,layout:L,defaultValues:z,showSubmit:d===e.sections.length-1&&e.showSubmit!==!1&&e.mode!=="view",showCancel:d===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,onSubmit:C,onCancel:I}})},n.name||n.label||d)})});const q=e.sections?.length?{fields:p,columns:e.columns}:K(p,x,e.columns,e.mode),m={type:"form",fields:q.fields,layout:L,columns:q.columns,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:z,onSubmit:C,onCancel:I,className:e.className};return t.jsx("div",{className:"w-full",children:t.jsx(H.SchemaRenderer,{schema:m})})},ve=({config:e,dataSource:l,prefillParams:o,className:x})=>{const[s,p]=i.useState(!1),[g,E]=i.useState(!1),[A,k]=i.useState(null),O=i.useMemo(()=>{const C={};if(o)for(const[I,V]of Object.entries(o))C[I]=V;return typeof window<"u"&&new URLSearchParams(window.location.search).forEach((V,z)=>{z in C||(C[z]=V)}),Object.keys(C).length>0?C:void 0},[o]),v=i.useCallback(async C=>{E(!0),k(null);try{if(l&&await l.create(e.objectName,C),p(!0),e.thankYouPage?.redirectUrl){const I=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},I)}}catch(I){k(I instanceof Error?I.message:"Failed to submit form. Please try again.")}finally{E(!1)}},[l,e]),N=i.useCallback(()=>{p(!1),k(null)},[]),F=i.useMemo(()=>{const C={};return e.branding?.backgroundColor&&(C.backgroundColor=e.branding.backgroundColor),C},[e.branding]);if(s){const C=e.thankYouPage;return t.jsx("div",{className:`min-h-screen flex items-center justify-center p-4 ${x||""}`,style:F,children:t.jsxs("div",{className:"max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4",children:[t.jsx("div",{className:"text-4xl",children:"✓"}),t.jsx("h2",{className:"text-xl font-semibold text-foreground",children:C?.title||"Thank You!"}),t.jsx("p",{className:"text-muted-foreground",children:C?.message||"Your submission has been received successfully."}),e.allowMultiple&&t.jsx("button",{onClick:N,className:"mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors",children:"Submit Another Response"}),C?.redirectUrl&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Redirecting in ",Math.ceil((C.redirectDelay??3e3)/1e3)," seconds..."]})]})})}return t.jsx("div",{className:`min-h-screen flex items-center justify-center p-4 ${x||""}`,style:F,children:t.jsxs("div",{className:"max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden",children:[t.jsxs("div",{className:"p-6 border-b",style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&t.jsx("img",{src:e.branding.logo,alt:"Logo",className:"h-8 mb-4"}),e.title&&t.jsx("h1",{className:"text-xl font-semibold text-foreground",children:e.title}),e.description&&t.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:e.description})]}),t.jsxs("div",{className:"p-6",children:[A&&t.jsx("div",{className:"mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive",children:A}),t.jsx(ne,{schema:{type:"object-form",objectName:e.objectName,mode:"create",fields:e.fields,customFields:e.customFields,initialData:O,onSuccess:v,submitLabel:g?"Submitting...":"Submit"},dataSource:l})]}),t.jsx("div",{className:"px-6 py-3 border-t bg-muted/20 text-center",children:t.jsx("p",{className:"text-xs text-muted-foreground",children:"Powered by ObjectStack"})})]})})};function _e(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}const Ce=({formId:e,formTitle:l,metrics:o,className:x})=>{const s=i.useMemo(()=>{if(!o.abandonedSubmissions)return 100;const g=o.totalSubmissions+o.abandonedSubmissions;return g===0?0:Math.round(o.totalSubmissions/g*100)},[o.totalSubmissions,o.abandonedSubmissions]),p=i.useMemo(()=>o.dailySubmissions?.length?Math.max(...o.dailySubmissions.map(g=>g.count),1):1,[o.dailySubmissions]);return t.jsxs("div",{className:`space-y-4 ${x||""}`,children:[t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:l||"Form Analytics"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["Form ID: ",e]})]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[t.jsx(u.Card,{children:t.jsxs(u.CardHeader,{className:"pb-2",children:[t.jsx(u.CardDescription,{children:"Total Submissions"}),t.jsx(u.CardTitle,{className:"text-2xl",children:o.totalSubmissions.toLocaleString()})]})}),t.jsxs(u.Card,{children:[t.jsxs(u.CardHeader,{className:"pb-2",children:[t.jsx(u.CardDescription,{children:"Fill Rate"}),t.jsxs(u.CardTitle,{className:"text-2xl",children:[s,"%"]})]}),t.jsx(u.CardContent,{children:t.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:t.jsx("div",{className:"bg-primary rounded-full h-2 transition-all",style:{width:`${s}%`}})})})]}),t.jsx(u.Card,{children:t.jsxs(u.CardHeader,{className:"pb-2",children:[t.jsx(u.CardDescription,{children:"Avg. Completion Time"}),t.jsx(u.CardTitle,{className:"text-2xl",children:o.avgCompletionTime?_e(o.avgCompletionTime):"—"})]})})]}),o.dailySubmissions&&o.dailySubmissions.length>0&&t.jsxs(u.Card,{children:[t.jsx(u.CardHeader,{children:t.jsx(u.CardTitle,{className:"text-sm font-medium",children:"Daily Submissions"})}),t.jsx(u.CardContent,{children:t.jsx("div",{className:"flex items-end gap-1 h-32",children:o.dailySubmissions.map((g,E)=>t.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1",children:[t.jsx("div",{className:"w-full bg-primary/80 rounded-t transition-all hover:bg-primary",style:{height:`${g.count/p*100}%`,minHeight:g.count>0?"4px":"0"},title:`${g.date}: ${g.count} submissions`}),t.jsx("span",{className:"text-[10px] text-muted-foreground truncate w-full text-center",children:g.date.slice(-5)})]},E))})})]}),o.fieldDropOff&&o.fieldDropOff.length>0&&t.jsxs(u.Card,{children:[t.jsxs(u.CardHeader,{children:[t.jsx(u.CardTitle,{className:"text-sm font-medium",children:"Field Completion Rates"}),t.jsx(u.CardDescription,{children:"Percentage of users who completed each field"})]}),t.jsx(u.CardContent,{children:t.jsx("div",{className:"space-y-3",children:o.fieldDropOff.map((g,E)=>t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex justify-between text-sm",children:[t.jsx("span",{className:"text-foreground",children:g.label}),t.jsxs("span",{className:"text-muted-foreground",children:[g.completionRate,"%"]})]}),t.jsx("div",{className:"w-full bg-muted rounded-full h-1.5",children:t.jsx("div",{className:`rounded-full h-1.5 transition-all ${g.completionRate>=80?"bg-green-500":g.completionRate>=50?"bg-yellow-500":"bg-destructive"}`,style:{width:`${g.completionRate}%`}})})]},E))})})]})]})},Te=({schema:e})=>t.jsx(ne,{schema:e});ee.ComponentRegistry.register("object-form",Te,{namespace:"plugin-form",label:"Object Form",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields"},{name:"mode",type:"enum",label:"Mode",enum:["create","edit","view"]},{name:"formType",type:"enum",label:"Form Type",enum:["simple","tabbed","wizard","split","drawer","modal"]},{name:"sections",type:"array",label:"Sections"},{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"layout",type:"enum",label:"Layout",enum:["vertical","horizontal","inline","grid"]},{name:"columns",type:"number",label:"Columns"},{name:"defaultTab",type:"string",label:"Default Tab"},{name:"tabPosition",type:"enum",label:"Tab Position",enum:["top","bottom","left","right"]},{name:"allowSkip",type:"boolean",label:"Allow Skip Steps"},{name:"showStepIndicator",type:"boolean",label:"Show Step Indicator"},{name:"splitDirection",type:"enum",label:"Split Direction",enum:["horizontal","vertical"]},{name:"splitSize",type:"number",label:"Split Panel Size (%)"},{name:"splitResizable",type:"boolean",label:"Split Resizable"},{name:"drawerSide",type:"enum",label:"Drawer Side",enum:["top","bottom","left","right"]},{name:"drawerWidth",type:"string",label:"Drawer Width"},{name:"modalSize",type:"enum",label:"Modal Size",enum:["sm","default","lg","xl","full"]}]}),ee.ComponentRegistry.register("form",Te,{namespace:"view",skipFallback:!0,label:"Data Form View",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields"},{name:"mode",type:"enum",label:"Mode",enum:["create","edit","view"]}]});const Ie=({schema:e})=>t.jsx(ve,{config:e});ee.ComponentRegistry.register("embeddable-form",Ie,{namespace:"plugin-form",label:"Embeddable Form",category:"plugin",inputs:[{name:"formId",type:"string",label:"Form ID",required:!0},{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"title",type:"string",label:"Form Title"},{name:"description",type:"string",label:"Description"},{name:"fields",type:"array",label:"Fields"},{name:"allowMultiple",type:"boolean",label:"Allow Multiple Submissions"}]});const Le=({schema:e})=>t.jsx(Ce,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}});ee.ComponentRegistry.register("form-analytics",Le,{namespace:"plugin-form",label:"Form Analytics",category:"plugin",inputs:[{name:"formId",type:"string",label:"Form ID",required:!0},{name:"formTitle",type:"string",label:"Form Title"},{name:"metrics",type:"object",label:"Submission Metrics"}]}),_.DrawerForm=je,_.EmbeddableForm=ve,_.FormAnalytics=Ce,_.FormSection=B,_.ModalForm=Se,_.ObjectForm=ne,_.SplitForm=be,_.TabbedForm=ce,_.WizardForm=fe,_.applyAutoColSpan=re,_.applyAutoLayout=K,_.filterCreateModeFields=xe,_.inferColumns=ye,_.inferModalSize=ie,_.isAutoGeneratedFieldType=pe,_.isWideFieldType=me,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})}));
6
+ <%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),_=p(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=h():t.exports=g()}))(),v=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:s=1,children:c,className:l,gridClassName:u})=>{let[d,f]=(0,t.useState)(i),p={1:`grid-cols-1`,2:`grid-cols-1 md:grid-cols-2`,3:`grid-cols-1 md:grid-cols-2 lg:grid-cols-3`,4:`grid-cols-1 md:grid-cols-2 lg:grid-cols-4`};return(0,_.jsxs)(`div`,{className:(0,a.cn)(`form-section`,l),children:[(e||n)&&(0,_.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2 mb-4`,r&&`cursor-pointer select-none`),onClick:()=>{r&&f(!d)},role:r?`button`:void 0,"aria-expanded":r?!d:void 0,children:[r&&(0,_.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:d?(0,_.jsx)(o.ChevronRight,{className:`h-4 w-4`}):(0,_.jsx)(o.ChevronDown,{className:`h-4 w-4`})}),(0,_.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,_.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!d&&(0,_.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,u||p[s]),children:c})]})},y=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[c,l]=(0,t.useState)(null),[u,d]=(0,t.useState)({}),[f,p]=(0,t.useState)(!0),[m,h]=(0,t.useState)(null),[g,y]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){p(!1);return}try{l(await n.getObjectSchema(e.objectName))}catch(e){h(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(c||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){d(e.initialData||e.initialValues||{}),p(!1);return}try{d(await n.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{p(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let b=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(c?.fields?.[t]){let r=c.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[c,e.readOnly,e.mode]),x=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),S=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),C=(e,t)=>e.name||e.label||`tab-${t}`;if(m)return(0,_.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:m.message})]});if(f)return(0,_.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,_.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let w={type:`form`,fields:e.sections.flatMap(e=>b(e)),layout:`vertical`,defaultValues:u,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:x,onCancel:S},T=e.tabPosition===`left`||e.tabPosition===`right`;return(0,_.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,_.jsxs)(a.Tabs,{value:g,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,_.jsx)(a.TabsList,{className:(0,a.cn)(T?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,_.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,_.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,_.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,_.jsx)(v,{description:t.description,columns:t.columns||1,children:(0,_.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},b=({schema:e,dataSource:n,className:s})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,g]=(0,t.useState)(null),[y,b]=(0,t.useState)(0),[x,S]=(0,t.useState)(new Set),[C,w]=(0,t.useState)(!1),T=e.sections.length,E=y===0,D=y===T-1;t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){g(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){g(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let O=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:c(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]),k=(0,t.useMemo)(()=>y>=0&&y<T?O(e.sections[y]):[],[y,T,e.sections,O]),A=(0,t.useCallback)(async t=>{let r={...d,...t};if(f(r),S(e=>new Set(e).add(y)),D){w(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(r),r;let t;return e.mode===`create`?t=await n.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(t=await n.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(t),t}catch(t){throw e.onError&&e.onError(t),t}finally{w(!1)}}else j(y+1)},[d,y,D,e,n]),j=(0,t.useCallback)(t=>{t>=0&&t<T&&(b(t),e.onStepChange&&e.onStepChange(t))},[T,e]),M=(0,t.useCallback)(()=>{j(y-1)},[y,j]),N=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),P=(0,t.useCallback)(t=>{(e.allowSkip||x.has(t)||t<=y)&&j(t)},[e.allowSkip,x,y,j]);if(h)return(0,_.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,_.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,_.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,_.jsxs)(`div`,{className:(0,a.cn)(`w-full`,s,e.className),children:[e.showStepIndicator!==!1&&(0,_.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,_.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),s=e.allowSkip||i||n<=y;return(0,_.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,_.jsx)(`div`,{className:`absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5`,"aria-hidden":`true`,children:(0,_.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,_.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,s?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!s,children:[(0,_.jsx)(`span`,{className:(0,a.cn)(`flex h-6 w-6 sm:h-8 sm:w-8 items-center justify-center rounded-full text-xs sm:text-sm font-medium transition-colors`,i&&`bg-primary text-primary-foreground`,r&&!i&&`border-2 border-primary bg-background text-primary`,!r&&!i&&`border-2 border-muted bg-background text-muted-foreground`),children:i?(0,_.jsx)(o.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,_.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,_.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,_.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,_.jsx)(v,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,_.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:d,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,_.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,_.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,_.jsx)(`div`,{children:e.showCancel!==!1&&(0,_.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,_.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,_.jsx)(o.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,_.jsx)(a.Button,{onClick:()=>A(d),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,_.jsxs)(a.Button,{onClick:()=>A(d),children:[e.nextText||`Next`,(0,_.jsx)(o.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},x=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[c,l]=(0,t.useState)(null),[u,d]=(0,t.useState)({}),[f,p]=(0,t.useState)(!0),[m,h]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){p(!1);return}try{l(await n.getObjectSchema(e.objectName))}catch(e){h(e),p(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(c||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){d(e.initialData||e.initialValues||{}),p(!1);return}if(!n){d(e.initialData||e.initialValues||{}),p(!1);return}try{d(await n.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{p(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let g=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(c?.fields?.[t]){let r=c.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[c,e.readOnly,e.mode]),y=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),b=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x=(0,t.useMemo)(()=>e.sections.slice(0,1),[e.sections]),S=(0,t.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,t.useMemo)(()=>e.sections.flatMap(e=>g(e)),[e.sections,g]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(m)return(0,_.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:m.message})]});if(f)return(0,_.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,_.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T={type:`form`,layout:`vertical`,defaultValues:u,onSubmit:y,onCancel:b},E=(t,n)=>(0,_.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,_.jsx)(v,{label:t.label,description:t.description,columns:t.columns||1,children:(0,_.jsx)(r.SchemaRenderer,{schema:{...T,fields:g(t),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||i))});return(0,_.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,_.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,_.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,_.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},S=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),C=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function w(e){return S.has(e)}function T(e){return C.has(e)}function E(e){return e<=3?1:2}function D(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&w(e.type)?{...e,colSpan:t}:e)}function O(e,t){return t?.fields?e.filter(e=>{let n=t.fields[e.name];return n?!T(n.type):!0}):e}function k(e){return e<=1?`default`:e===2?`xl`:`full`}function A(e,t,n,r){let i=[...e];if(r===`create`&&(i=O(i,t)),n!==void 0)return i=D(i,n),{fields:i,columns:n};let a=E(i.length);return i=D(i,a),{fields:i,columns:a}}var j={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},M=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[c,l]=(0,t.useState)(null),[u,d]=(0,t.useState)([]),[f,p]=(0,t.useState)({}),[m,h]=(0,t.useState)(!0),[g,y]=(0,t.useState)(null),b=e.open!==!1,x=e.drawerSide||`right`;(0,t.useEffect)(()=>{(async()=>{if(!n){h(!1);return}try{l(await n.getObjectSchema(e.objectName))}catch(e){y(e),h(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(c||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){p(e.initialData||e.initialValues||{}),h(!1);return}if(!n){p(e.initialData||e.initialValues||{}),h(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){y(e)}finally{h(!1)}})()},[c,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let S=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(c?.fields?.[t]){let r=c.fields[t];n.push({name:t,label:s(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[c,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!c&&n)return;if(e.customFields?.length){d(e.customFields),h(!1);return}if(e.sections?.length){h(!1);return}if(!c)return;let t=e.fields||Object.keys(c.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=c.fields?.[t];a&&r.push({name:t,label:s(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}d(r),h(!1)},[c,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let C=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;try{let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n]),w=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),T=(0,t.useMemo)(()=>{if(e.drawerWidth)return x===`left`||x===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,x]),E={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:f,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:C,onCancel:w};return(0,_.jsx)(a.Sheet,{open:b,onOpenChange:e.onOpenChange,children:(0,_.jsxs)(a.SheetContent,{side:x,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:T,children:[(e.title||e.description)&&(0,_.jsxs)(a.SheetHeader,{children:[e.title&&(0,_.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,_.jsx)(a.SheetDescription,{children:e.description})]}),(0,_.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(g)return(0,_.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(m)return(0,_.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,_.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length)return(0,_.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((t,n)=>{let i=t.columns||1;return(0,_.jsx)(v,{label:t.label,description:t.description,columns:i,gridClassName:j[i],children:(0,_.jsx)(r.SchemaRenderer,{schema:{...E,fields:S(t),showSubmit:n===e.sections.length-1&&E.showSubmit,showCancel:n===e.sections.length-1&&E.showCancel}})},t.name||t.label||n)})});let t=A(u,c,e.columns,e.mode),n=j[t.columns||1];return(0,_.jsx)(r.SchemaRenderer,{schema:{...E,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},N={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},P={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},F=({schema:e,dataSource:n,className:s})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)({}),[h,g]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!1),C=e.open!==!1,w=(0,t.useId)(),T=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:A(d,l,e.columns,e.mode),[d,l,e.columns,e.mode,e.sections,e.customFields]),E=N[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(T?.columns&&T.columns>1)return k(T.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return k(t)}return`default`},[e.modalSize,T,e.sections])]||N.default;(0,t.useEffect)(()=>{(async()=>{if(!n){g(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){b(e),g(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){m(e.initialData||e.initialValues||{}),g(!1);return}if(!n){m(e.initialData||e.initialValues||{}),g(!1);return}try{m(await n.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{g(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let D=(0,t.useCallback)(t=>{let n=[];for(let r of t.fields){let t=typeof r==`string`?r:r.name;if(typeof r==`object`)n.push(r);else if(l?.fields?.[t]){let r=l.fields[t];n.push({name:t,label:c(e.objectName,t,r.label||t),type:(0,i.mapFieldTypeToFormType)(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:(0,i.buildValidationRules)(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!l&&n)return;if(e.customFields?.length){f(e.customFields),g(!1);return}if(e.sections?.length){g(!1);return}if(!l)return;let t=e.fields||Object.keys(l.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=l.fields?.[t];a&&r.push({name:t,label:c(e.objectName,t,a.label||t),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:(0,i.buildValidationRules)(a),field:a,options:a.options,multiple:a.multiple})}f(r),g(!1)},[l,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let O=(0,t.useCallback)(async t=>{S(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r;return e.mode===`create`?r=await n.create(e.objectName,t):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,t)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{S(!1)}},[e,n]),j=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),M=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,F=e.showSubmit!==!1&&e.mode!==`view`,I=e.showCancel!==!1,L=e.submitText||(e.mode===`create`?`Create`:`Update`),R=e.cancelText||`Cancel`,z={type:`form`,layout:M,defaultValues:p,submitLabel:L,cancelLabel:R,showSubmit:F,showCancel:I,onSubmit:O,onCancel:j,showActions:!1,id:w},B=()=>{if(y)return(0,_.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(h)return(0,_.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,_.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,_.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,_.jsx)(v,{label:e.label,description:e.description,columns:n,gridClassName:P[n],children:(0,_.jsx)(r.SchemaRenderer,{schema:{...z,fields:D(e)}})},e.name||e.label||t)})});let t=T??A(d,l,e.columns,e.mode),n=P[t.columns||1];return(0,_.jsx)(r.SchemaRenderer,{schema:{...z,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},V=!h&&!y&&(F||I);return(0,_.jsx)(a.Dialog,{open:C,onOpenChange:e.onOpenChange,children:(0,_.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(E,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,s,e.className),children:[(e.title||e.description)&&(0,_.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,_.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,_.jsx)(a.DialogDescription,{children:e.description})]}),(0,_.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:B()}),V&&(0,_.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,_.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[I&&(0,_.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:j,disabled:x,className:`w-full sm:w-auto`,children:R}),F&&(0,_.jsxs)(a.Button,{type:`submit`,form:w,disabled:x,className:`w-full sm:w-auto`,children:[x&&(0,_.jsx)(o.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),L]})]})})]})})},I=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,_.jsx)(y,{schema:{...e,formType:`tabbed`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:t,className:e.className});if(e.formType===`wizard`&&e.sections?.length)return(0,_.jsx)(b,{schema:{...e,formType:`wizard`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:t,className:e.className});if(e.formType===`split`&&e.sections?.length)return(0,_.jsx)(x,{schema:{...e,formType:`split`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:t,className:e.className});if(e.formType===`drawer`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,_.jsx)(M,{schema:{...r,layout:i,formType:`drawer`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:t,className:e.className})}if(e.formType===`modal`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,_.jsx)(F,{schema:{...r,layout:i,formType:`modal`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:t,className:e.className})}return(0,_.jsx)(L,{schema:e,dataSource:t})},L=({schema:e,dataSource:n})=>{let{fieldLabel:a}=(0,r.useSafeFieldLabel)(),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)([]),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)(!0),[m,h]=(0,t.useState)(null),g=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{g&&(d(e.initialData||e.initialValues||{}),p(!1))},[g,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{g?s({name:e.objectName,fields:{}}):e.objectName&&n?(async()=>{try{if(!n)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let t=await n.getObjectSchema(e.objectName);if(!t)throw Error(`No schema found for object "${e.objectName}"`);s(t)}catch(e){h(e),p(!1)}})():g||p(!1)},[e.objectName,n,g]),(0,t.useEffect)(()=>{o&&!g&&(async()=>{if(!e.recordId||e.mode===`create`){d(e.initialData||e.initialValues||{}),p(!1);return}if(!g){if(!n){h(Error(`DataSource is required for fetching record data (inline data not provided)`)),p(!1);return}p(!0);try{d(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),h(e)}finally{p(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,o,g]),(0,t.useEffect)(()=>{if(g&&e.customFields){l(e.customFields),p(!1);return}if(!o)return;let t=[],r=e.fields||Object.keys(o.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let s=o.fields?.[r];if(!s&&!g)return;let c=!s?.permissions||s?.permissions.write!==!1;if(e.mode!==`view`&&!c)return;let l=e.customFields?.find(e=>e.name===r);if(l)t.push(l);else if(s){let o={name:r,label:a(e.objectName,r,s.label||n),type:(0,i.mapFieldTypeToFormType)(s.type),required:s.required||!1,disabled:e.readOnly||e.mode===`view`||s.readonly,placeholder:s.placeholder,description:s.help||s.description,validation:(0,i.buildValidationRules)(s),field:s};if((s.type===`select`||s.type===`lookup`||s.type===`master_detail`)&&(o.options=s.options||[],o.multiple=s.multiple),(s.type===`number`||s.type===`currency`||s.type===`percent`)&&(o.inputType=`number`,o.min=s.min,o.max=s.max,o.step=s.precision?10**-s.precision:void 0),s.type===`date`&&(o.inputType=`date`),s.type===`datetime`&&(o.inputType=`datetime-local`),(s.type===`text`||s.type===`textarea`||s.type===`markdown`||s.type===`html`)&&(o.maxLength=s.max_length,o.minLength=s.min_length),(s.type===`file`||s.type===`image`)&&(o.inputType=`file`,o.multiple=s.multiple,o.accept=s.accept?s.accept.join(`,`):void 0,s.max_size)){let e=`Max size: ${(0,i.formatFileSize)(s.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}s.type===`email`&&(o.inputType=`email`),s.type===`phone`&&(o.inputType=`tel`),s.type===`url`&&(o.inputType=`url`),s.type===`password`&&(o.inputType=`password`),s.type===`time`&&(o.inputType=`time`),(s.type===`formula`||s.type===`summary`||s.type===`auto_number`)&&(o.disabled=!0),s.visible_on&&(o.visible=e=>(0,i.evaluateCondition)(s.visible_on,e)),t.push(o)}}),l(t),!g&&e.recordId&&e.mode!==`create`&&n||p(!1)},[o,e.fields,e.customFields,e.readOnly,e.mode,g,e.recordId,n]);let y=(0,t.useCallback)(async(t,r)=>{if(t&&(t.nativeEvent||t._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=t,t={})),g&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);try{let r;if(e.mode===`create`)r=await n.create(e.objectName,t);else if(e.mode===`edit`&&e.recordId)r=await n.update(e.objectName,e.recordId,t);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,g]),b=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x={...t.default.useMemo(()=>{if(!o?.fields)return{};let e={};return Object.keys(o.fields).forEach(t=>{let n=o.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[o]),...u};if(m)return(0,_.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,_.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,_.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:m.message})]});if(f)return(0,_.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,_.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,_.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let S=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,_.jsx)(`div`,{className:`w-full space-y-6`,children:e.sections.map((t,n)=>{let i=t.fields.map(e=>typeof e==`string`?e:e.name),a=c.filter(e=>i.includes(e.name));return(0,_.jsx)(v,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,_.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:S,defaultValues:x,showSubmit:n===e.sections.length-1&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:y,onCancel:b}})},t.name||t.label||n)})});let C=e.sections?.length?{fields:c,columns:e.columns}:A(c,o,e.columns,e.mode);return(0,_.jsx)(`div`,{className:`w-full`,children:(0,_.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:C.fields,layout:S,columns:C.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:x,onSubmit:y,onCancel:b,className:e.className}})})},R=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[s,c]=(0,t.useState)(!1),[l,u]=(0,t.useState)(null),d=(0,t.useMemo)(()=>{let e={};if(r)for(let[t,n]of Object.entries(r))e[t]=n;return typeof window<`u`&&new URLSearchParams(window.location.search).forEach((t,n)=>{n in e||(e[n]=t)}),Object.keys(e).length>0?e:void 0},[r]),f=(0,t.useCallback)(async t=>{c(!0),u(null);try{if(n&&await n.create(e.objectName,t),o(!0),e.thankYouPage?.redirectUrl){let t=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},t)}}catch(e){u(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{c(!1)}},[n,e]),p=(0,t.useCallback)(()=>{o(!1),u(null)},[]),m=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(a){let t=e.thankYouPage;return(0,_.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:m,children:(0,_.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,_.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,_.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,_.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,_.jsx)(`button`,{onClick:p,className:`mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors`,children:`Submit Another Response`}),t?.redirectUrl&&(0,_.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,_.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:m,children:(0,_.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,_.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,_.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,_.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,_.jsxs)(`div`,{className:`p-6`,children:[l&&(0,_.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:l}),(0,_.jsx)(I,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:d,onSuccess:f,submitLabel:s?`Submitting...`:`Submit`},dataSource:n})]}),(0,_.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,_.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function z(e){return e<60?`${Math.round(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.round(e%60)}s`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}var B=({formId:e,formTitle:n,metrics:r,className:i})=>{let o=(0,t.useMemo)(()=>{if(!r.abandonedSubmissions)return 100;let e=r.totalSubmissions+r.abandonedSubmissions;return e===0?0:Math.round(r.totalSubmissions/e*100)},[r.totalSubmissions,r.abandonedSubmissions]),s=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,_.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,_.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,_.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,_.jsx)(a.Card,{children:(0,_.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,_.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,_.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,_.jsxs)(a.Card,{children:[(0,_.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,_.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,_.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,_.jsx)(a.CardContent,{children:(0,_.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,_.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,_.jsx)(a.Card,{children:(0,_.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,_.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,_.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?z(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,_.jsxs)(a.Card,{children:[(0,_.jsx)(a.CardHeader,{children:(0,_.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,_.jsx)(a.CardContent,{children:(0,_.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,_.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,_.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/s*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,_.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),r.fieldDropOff&&r.fieldDropOff.length>0&&(0,_.jsxs)(a.Card,{children:[(0,_.jsxs)(a.CardHeader,{children:[(0,_.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,_.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,_.jsx)(a.CardContent,{children:(0,_.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,_.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,_.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,_.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,_.jsx)(`div`,{className:`rounded-full h-1.5 transition-all ${e.completionRate>=80?`bg-green-500`:e.completionRate>=50?`bg-yellow-500`:`bg-destructive`}`,style:{width:`${e.completionRate}%`}})})]},t))})})]})]})},V=({schema:e})=>(0,_.jsx)(I,{schema:e});n.ComponentRegistry.register(`object-form`,V,{namespace:`plugin-form`,label:`Object Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]},{name:`formType`,type:`enum`,label:`Form Type`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]},{name:`sections`,type:`array`,label:`Sections`},{name:`title`,type:`string`,label:`Title`},{name:`description`,type:`string`,label:`Description`},{name:`layout`,type:`enum`,label:`Layout`,enum:[`vertical`,`horizontal`,`inline`,`grid`]},{name:`columns`,type:`number`,label:`Columns`},{name:`defaultTab`,type:`string`,label:`Default Tab`},{name:`tabPosition`,type:`enum`,label:`Tab Position`,enum:[`top`,`bottom`,`left`,`right`]},{name:`allowSkip`,type:`boolean`,label:`Allow Skip Steps`},{name:`showStepIndicator`,type:`boolean`,label:`Show Step Indicator`},{name:`splitDirection`,type:`enum`,label:`Split Direction`,enum:[`horizontal`,`vertical`]},{name:`splitSize`,type:`number`,label:`Split Panel Size (%)`},{name:`splitResizable`,type:`boolean`,label:`Split Resizable`},{name:`drawerSide`,type:`enum`,label:`Drawer Side`,enum:[`top`,`bottom`,`left`,`right`]},{name:`drawerWidth`,type:`string`,label:`Drawer Width`},{name:`modalSize`,type:`enum`,label:`Modal Size`,enum:[`sm`,`default`,`lg`,`xl`,`full`]}]}),n.ComponentRegistry.register(`form`,V,{namespace:`view`,skipFallback:!0,label:`Data Form View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`fields`,type:`array`,label:`Fields`},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`,`view`]}]}),n.ComponentRegistry.register(`embeddable-form`,({schema:e})=>(0,_.jsx)(R,{config:e}),{namespace:`plugin-form`,label:`Embeddable Form`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`title`,type:`string`,label:`Form Title`},{name:`description`,type:`string`,label:`Description`},{name:`fields`,type:`array`,label:`Fields`},{name:`allowMultiple`,type:`boolean`,label:`Allow Multiple Submissions`}]}),n.ComponentRegistry.register(`form-analytics`,({schema:e})=>(0,_.jsx)(B,{formId:e.formId,formTitle:e.formTitle,metrics:e.metrics||{totalSubmissions:0}}),{namespace:`plugin-form`,label:`Form Analytics`,category:`plugin`,inputs:[{name:`formId`,type:`string`,label:`Form ID`,required:!0},{name:`formTitle`,type:`string`,label:`Form Title`},{name:`metrics`,type:`object`,label:`Submission Metrics`}]}),e.DrawerForm=M,e.EmbeddableForm=R,e.FormAnalytics=B,e.FormSection=v,e.ModalForm=F,e.ObjectForm=I,e.SplitForm=x,e.TabbedForm=y,e.WizardForm=b,e.applyAutoColSpan=D,e.applyAutoLayout=A,e.filterCreateModeFields=O,e.inferColumns=E,e.inferModalSize=k,e.isAutoGeneratedFieldType=T,e.isWideFieldType=w});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-form",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Form plugin for Object UI",
@@ -15,24 +15,24 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "lucide-react": "^0.576.0",
19
- "@object-ui/components": "3.1.2",
20
- "@object-ui/core": "3.1.2",
21
- "@object-ui/fields": "3.1.2",
22
- "@object-ui/react": "3.1.2",
23
- "@object-ui/types": "3.1.2"
18
+ "lucide-react": "^0.577.0",
19
+ "@object-ui/components": "3.1.4",
20
+ "@object-ui/core": "3.1.4",
21
+ "@object-ui/fields": "3.1.4",
22
+ "@object-ui/react": "3.1.4",
23
+ "@object-ui/types": "3.1.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^18.0.0 || ^19.0.0",
27
27
  "react-dom": "^18.0.0 || ^19.0.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@vitejs/plugin-react": "^5.1.4",
31
- "msw": "^2.12.10",
30
+ "@vitejs/plugin-react": "^6.0.1",
31
+ "msw": "^2.12.14",
32
32
  "typescript": "^5.9.3",
33
- "vite": "^7.3.1",
33
+ "vite": "^8.0.1",
34
34
  "vite-plugin-dts": "^4.5.4",
35
- "@object-ui/data-objectstack": "3.1.2"
35
+ "@object-ui/data-objectstack": "3.1.4"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "vite build",
@@ -19,7 +19,7 @@ const BASE_URL = process.env.OBJECTSTACK_API_URL || 'http://localhost';
19
19
  const mockSchema = ContactObject;
20
20
 
21
21
  const mockRecord = {
22
- _id: '1',
22
+ id: '1',
23
23
  name: 'Alice Johnson',
24
24
  email: 'alice@example.com',
25
25
  status: 'Active'