@object-ui/plugin-form 4.0.5 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @object-ui/plugin-form
2
2
 
3
+ ## 4.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 89ae109: Fix click navigation and required-FK form rendering
8
+ - **plugin-grid**: ObjectGrid's `getSelectFields()` now always includes `id` in
9
+ the SELECT projection. Previously, when a view configured `columns` without
10
+ `id`, the SQL driver stripped it from results, and row-click handlers silently
11
+ no-oped because `record.id` was undefined.
12
+ - **plugin-form / fields**: Master-detail fields now render as a single-value
13
+ lookup picker (`LookupField`) in create/edit forms instead of a one-to-many
14
+ related-list widget. From the child-side, master-detail is the FK to the
15
+ parent record and is typically NOT NULL — it must appear in forms. Prior
16
+ behavior dropped it via the auto-layout exclusion list, which caused server
17
+ errors like "NOT NULL constraint failed: contact.account" when users tried
18
+ to create child records.
19
+
20
+ - Updated dependencies [89ae109]
21
+ - Updated dependencies [925051d]
22
+ - Updated dependencies [1b6dc64]
23
+ - @object-ui/fields@4.0.6
24
+ - @object-ui/components@4.0.6
25
+ - @object-ui/types@4.0.6
26
+ - @object-ui/core@4.0.6
27
+ - @object-ui/react@4.0.6
28
+
3
29
  ## 4.0.5
4
30
 
5
31
  ### Patch Changes
package/dist/index.js CHANGED
@@ -545,8 +545,7 @@ var G = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
545
545
  "field:formula",
546
546
  "field:summary",
547
547
  "field:auto_number",
548
- "field:autonumber",
549
- "field:master_detail"
548
+ "field:autonumber"
550
549
  ]), re = new Set([
551
550
  "field:textarea",
552
551
  "field:markdown",
@@ -562,9 +561,7 @@ var G = ({ label: e, description: t, collapsible: n = !1, collapsed: r = !1, col
562
561
  "formula",
563
562
  "summary",
564
563
  "auto_number",
565
- "autonumber",
566
- "master_detail",
567
- "masterDetail"
564
+ "autonumber"
568
565
  ]);
569
566
  function ae(e) {
570
567
  return re.has(e);
@@ -1 +1 @@
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`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`lucide-react`,`react/jsx-runtime`],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,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:c(f(e)),m(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var h=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:c=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,s.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,s.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2 mb-4`,r&&`cursor-pointer select-none`),onClick:()=>{r&&p(!f)},role:r?`button`:void 0,"aria-expanded":r?!f:void 0,children:[r&&(0,s.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4`}):(0,s.jsx)(o.ChevronDown,{className:`h-4 w-4`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,s.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,s.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||{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`}[c]),children:l})]})},g=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(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){_(e)}finally{m(!1)}})()},[l,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(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]),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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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:d,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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,s.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,s.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,s.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,s.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,s.jsx)(h,{description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},_=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,g]=(0,t.useState)(!0),[_,v]=(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){g(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){v(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){p(e.initialData||e.initialValues||{}),g(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!1)}})()},[u,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(u?.fields?.[t]){let r=u.fields[t];n.push({name:t,label:l(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},[u,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={...f,...t};if(p(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)},[f,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(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,s.jsxs)(`div`,{className:(0,a.cn)(`w-full`,c,e.className),children:[e.showStepIndicator!==!1&&(0,s.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,s.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),c=e.allowSkip||i||n<=y;return(0,s.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,s.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,c?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!c,children:[(0,s.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,s.jsx)(o.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,s.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,s.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,s.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,s.jsx)(h,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,s.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,s.jsx)(`div`,{children:e.showCancel!==!1&&(0,s.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,s.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,s.jsx)(o.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,s.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,s.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e),m(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){f(e.initialData||e.initialValues||{}),m(!1);return}if(!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let v=(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]),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=>v(e)),[e.sections,v]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T={type:`form`,layout:`vertical`,defaultValues:d,onSubmit:y,onCancel:b},E=(t,n)=>(0,s.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,s.jsx)(h,{label:t.label,description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...T,fields:v(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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,s.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,s.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},y=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`,`field:master_detail`]),b=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),x=new Set([`formula`,`summary`,`auto_number`,`autonumber`,`master_detail`,`masterDetail`]);function S(e){return b.has(e)}function C(e){return x.has(e)}function w(e){return e<=3?1:2}function T(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&S(e.type)?{...e,colSpan:t}:e)}var E=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function D(e,t){return e.filter(e=>{if(E.has(e.name)||e.type&&y.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!C(n.type):!0})}function O(e){return e<=1?`default`:e===2?`xl`:`full`}function k(e,t,n,r){let i=[...e];if(r===`create`&&(i=D(i,t)),n!==void 0)return i=T(i,n),{fields:i,columns:n};let a=w(i.length);return i=T(i,a),{fields:i,columns:a}}var A={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`},j=({schema:e,dataSource:n,className:o})=>{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),[_,v]=(0,t.useState)(null),y=e.open!==!1,b=e.drawerSide||`right`,[x,S]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){g(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){v(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){v(e)}finally{g(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let C=(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 w=(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]),T=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),E=(0,t.useMemo)(()=>{if(e.drawerWidth)return b===`left`||b===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,b]),D={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:p,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:w,onCancel:T};return(0,s.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,s.jsxs)(a.SheetHeader,{children:[e.title&&(0,s.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,s.jsx)(a.SheetDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=x[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>S(e=>({...e,[r]:!i})):void 0});let a=C(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=k(d,l,e.columns,e.mode),n=A[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},M={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`},N={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`},P=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,g]=(0,t.useState)({}),[_,v]=(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:k(f,u,e.columns,e.mode),[f,u,e.columns,e.mode,e.sections,e.customFields]),E=M[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(T?.columns&&T.columns>1)return O(T.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return O(t)}return`default`},[e.modalSize,T,e.sections])]||M.default;(0,t.useEffect)(()=>{(async()=>{if(!n){v(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){b(e),v(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){g(e.initialData||e.initialValues||{}),v(!1);return}if(!n){g(e.initialData||e.initialValues||{}),v(!1);return}try{g(await n.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{v(!1)}})()},[u,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(u?.fields?.[t]){let r=u.fields[t];n.push({name:t,label:l(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},[u,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!u&&n)return;if(e.customFields?.length){p(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!u)return;let t=e.fields||Object.keys(u.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=u.fields?.[t];a&&r.push({name:t,label:l(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})}p(r),v(!1)},[u,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let A=(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]),P=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:P,defaultValues:m,submitLabel:L,cancelLabel:R,showSubmit:F,showCancel:I,onSubmit:A,onCancel:j,showActions:!1,id:w},B=()=>{if(y)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(_)return(0,s.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,s.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,s.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,s.jsx)(h,{label:e.label,description:e.description,columns:n,gridClassName:N[n],children:(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:D(e)}})},e.name||e.label||t)})});let t=T??k(f,u,e.columns,e.mode),n=N[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},V=!_&&!y&&(F||I);return(0,s.jsx)(a.Dialog,{open:C,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(E,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,c,e.className),children:[(e.title||e.description)&&(0,s.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,s.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,s.jsx)(a.DialogDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:B()}),V&&(0,s.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[I&&(0,s.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:j,disabled:x,className:`w-full sm:w-auto`,children:R}),F&&(0,s.jsxs)(a.Button,{type:`submit`,form:w,disabled:x,className:`w-full sm:w-auto`,children:[x&&(0,s.jsx)(o.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),L]})]})})]})})},F=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,s.jsx)(g,{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,s.jsx)(_,{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,s.jsx)(v,{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,s.jsx)(j,{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,collapsible:e.collapsible,collapsed:e.collapsed})),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,s.jsx)(P,{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,s.jsx)(I,{schema:e,dataSource:t})},I=({schema:e,dataSource:n})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),c=(0,a.useIsMobile)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)(null),[g,v]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),x=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{x&&(m(e.initialData||e.initialValues||{}),v(!1))},[x,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{x?u({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}"`);u(t)}catch(e){b(e),v(!1)}})():x||v(!1)},[e.objectName,n,x]),(0,t.useEffect)(()=>{l&&!x&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),v(!1);return}if(!x){if(!n){b(Error(`DataSource is required for fetching record data (inline data not provided)`)),v(!1);return}v(!0);try{m(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),b(e)}finally{v(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,l,x]),(0,t.useEffect)(()=>{if(x&&e.customFields){f(e.customFields),v(!1);return}if(!l)return;let t=[],r=e.fields||Object.keys(l.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=l.fields?.[r];if(!a&&!x)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(c);else if(a){let s={name:r,label:o(e.objectName,r,a.label||n),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};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(s.options=a.options||[],s.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(s.inputType=`number`,s.min=a.min,s.max=a.max,s.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(s.inputType=`date`),a.type===`datetime`&&(s.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(s.maxLength=a.max_length,s.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(s.inputType=`file`,s.multiple=a.multiple,s.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}a.type===`email`&&(s.inputType=`email`),a.type===`phone`&&(s.inputType=`tel`),a.type===`url`&&(s.inputType=`url`),a.type===`password`&&(s.inputType=`password`),a.type===`time`&&(s.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(s.disabled=!0),a.visible_on&&(s.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(s)}}),f(t),!x&&e.recordId&&e.mode!==`create`&&n||v(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,x,e.recordId,n]);let S=(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={})),x&&!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,x]),C=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...t.default.useMemo(()=>{if(!l?.fields)return{};let e={};return Object.keys(l.fields).forEach(t=>{let n=l.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[l]),...p};if(y)return(0,s.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(g)return(0,s.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,s.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=d.filter(e=>i.includes(e.name));return(0,s.jsx)(h,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:T,defaultValues:w,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:S,onCancel:C}})},t.name||t.label||n)})});let E=e.sections?.length,D=E?{fields:d,columns:e.columns}:k(d,l,e.columns,e.mode),O=e.mobile,A=O?.fullscreenLongText?D.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):D.fields,j=O?.stepper,M=O?.stepperMinFields??8,N=Math.max(1,O?.stepperFieldsPerStep??1);if(!e.formType&&!E&&A.length>=2&&(j===!0||j===`auto`&&c&&A.length>=M)){let t=A,r=[];for(let e=0;e<t.length;e+=N){let n=t.slice(e,e+N);r.push({name:`step-${Math.floor(e/N)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/N)+1}`,fields:n})}return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let P={type:`form`,fields:A,layout:T,columns:D.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:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!O?.stickyActions};return(0,s.jsx)(`div`,{className:O?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":O?`true`:void 0,children:(0,s.jsx)(r.SchemaRenderer,{schema:P})})},L=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[c,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(null),f=(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]),p=(0,t.useCallback)(async t=>{l(!0),d(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){d(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{l(!1)}},[n,e]),m=(0,t.useCallback)(()=>{o(!1),d(null)},[]),h=(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,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,s.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,s.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,s.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,s.jsx)(`button`,{onClick:m,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,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,s.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,s.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsxs)(`div`,{className:`p-6`,children:[u&&(0,s.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,s.jsx)(F,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:c?`Submitting...`:`Submit`},dataSource:n})]}),(0,s.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function R(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 z=({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]),c=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,s.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,s.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,s.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?R(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,s.jsxs)(a.Card,{children:[(0,s.jsx)(a.CardHeader,{children:(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,s.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/c*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,s.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,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{children:[(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,s.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,s.jsxs)(`div`,{className:`space-y-1`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,s.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,s.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))})})]})]})},B=({schema:e})=>(0,s.jsx)(F,{schema:e});n.ComponentRegistry.register(`object-form`,B,{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`,B,{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,s.jsx)(L,{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,s.jsx)(z,{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=j,e.EmbeddableForm=L,e.FormAnalytics=z,e.FormSection=h,e.ModalForm=P,e.ObjectForm=F,e.SplitForm=v,e.TabbedForm=g,e.WizardForm=_,e.applyAutoColSpan=T,e.applyAutoLayout=k,e.filterCreateModeFields=D,e.inferColumns=w,e.inferModalSize=O,e.isAutoGeneratedFieldType=C,e.isWideFieldType=S});
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`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`lucide-react`,`react/jsx-runtime`],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,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var c=Object.create,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,m=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=d(t),a=0,o=i.length,s;a<o;a++)s=i[a],!p.call(e,s)&&s!==n&&l(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=u(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:c(f(e)),m(t||!e||!e.__esModule?l(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var h=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:c=1,children:l,className:u,gridClassName:d})=>{let[f,p]=(0,t.useState)(i);return(0,s.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[(e||n)&&(0,s.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2 mb-4`,r&&`cursor-pointer select-none`),onClick:()=>{r&&p(!f)},role:r?`button`:void 0,"aria-expanded":r?!f:void 0,children:[r&&(0,s.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:f?(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4`}):(0,s.jsx)(o.ChevronDown,{className:`h-4 w-4`})}),(0,s.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,s.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}),!f&&(0,s.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||{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`}[c]),children:l})]})},g=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null),[v,y]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(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){_(e)}finally{m(!1)}})()},[l,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(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]),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(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.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:d,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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,s.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,s.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,s.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,s.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,s.jsx)(h,{description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},_=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,g]=(0,t.useState)(!0),[_,v]=(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){g(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){v(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){p(e.initialData||e.initialValues||{}),g(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{g(!1)}})()},[u,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(u?.fields?.[t]){let r=u.fields[t];n.push({name:t,label:l(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},[u,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={...f,...t};if(p(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)},[f,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(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,s.jsxs)(`div`,{className:(0,a.cn)(`w-full`,c,e.className),children:[e.showStepIndicator!==!1&&(0,s.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,s.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),c=e.allowSkip||i||n<=y;return(0,s.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,s.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,s.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,s.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,c?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!c,children:[(0,s.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,s.jsx)(o.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,s.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,s.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,s.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,s.jsx)(h,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,s.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,s.jsx)(`div`,{children:e.showCancel!==!1&&(0,s.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,s.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,s.jsx)(o.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,s.jsx)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,s.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,s.jsx)(o.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:c}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[g,_]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){_(e),m(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){f(e.initialData||e.initialValues||{}),m(!1);return}if(!n){f(e.initialData||e.initialValues||{}),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){_(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let v=(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]),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=>v(e)),[e.sections,v]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(g)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:g.message})]});if(p)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T={type:`form`,layout:`vertical`,defaultValues:d,onSubmit:y,onCancel:b},E=(t,n)=>(0,s.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,s.jsx)(h,{label:t.label,description:t.description,columns:t.columns||1,children:(0,s.jsx)(r.SchemaRenderer,{schema:{...T,fields:v(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,s.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,s.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,s.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,s.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},y=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),b=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),x=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function S(e){return b.has(e)}function C(e){return x.has(e)}function w(e){return e<=3?1:2}function T(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&S(e.type)?{...e,colSpan:t}:e)}var E=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function D(e,t){return e.filter(e=>{if(E.has(e.name)||e.type&&y.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!C(n.type):!0})}function O(e){return e<=1?`default`:e===2?`xl`:`full`}function k(e,t,n,r){let i=[...e];if(r===`create`&&(i=D(i,t)),n!==void 0)return i=T(i,n),{fields:i,columns:n};let a=w(i.length);return i=T(i,a),{fields:i,columns:a}}var A={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`},j=({schema:e,dataSource:n,className:o})=>{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),[_,v]=(0,t.useState)(null),y=e.open!==!1,b=e.drawerSide||`right`,[x,S]=(0,t.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,t.useEffect)(()=>{(async()=>{if(!n){g(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){v(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){v(e)}finally{g(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let C=(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 w=(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]),T=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),E=(0,t.useMemo)(()=>{if(e.drawerWidth)return b===`left`||b===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,b]),D={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,defaultValues:p,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:w,onCancel:T};return(0,s.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,s.jsxs)(a.SheetHeader,{children:[e.title&&(0,s.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,s.jsx)(a.SheetDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,s.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});if(e.sections?.length){let t=[];return e.sections.forEach((e,n)=>{let r=e.name||String(n),i=x[r]??e.collapsed??!1;t.push({name:`__section_${r}`,label:e.label||``,type:`section-divider`,colSpan:4,collapsible:e.collapsible,collapsed:i,onToggle:e.collapsible?()=>S(e=>({...e,[r]:!i})):void 0});let a=C(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=k(d,l,e.columns,e.mode),n=A[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},M={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`},N={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`},P=({schema:e,dataSource:n,className:c})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,g]=(0,t.useState)({}),[_,v]=(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:k(f,u,e.columns,e.mode),[f,u,e.columns,e.mode,e.sections,e.customFields]),E=M[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(T?.columns&&T.columns>1)return O(T.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return O(t)}return`default`},[e.modalSize,T,e.sections])]||M.default;(0,t.useEffect)(()=>{(async()=>{if(!n){v(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){b(e),v(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){g(e.initialData||e.initialValues||{}),v(!1);return}if(!n){g(e.initialData||e.initialValues||{}),v(!1);return}try{g(await n.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{v(!1)}})()},[u,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(u?.fields?.[t]){let r=u.fields[t];n.push({name:t,label:l(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},[u,e.readOnly,e.mode]);(0,t.useEffect)(()=>{if(!u&&n)return;if(e.customFields?.length){p(e.customFields),v(!1);return}if(e.sections?.length){v(!1);return}if(!u)return;let t=e.fields||Object.keys(u.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=u.fields?.[t];a&&r.push({name:t,label:l(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})}p(r),v(!1)},[u,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let A=(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]),P=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:P,defaultValues:m,submitLabel:L,cancelLabel:R,showSubmit:F,showCancel:I,onSubmit:A,onCancel:j,showActions:!1,id:w},B=()=>{if(y)return(0,s.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(_)return(0,s.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,s.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,s.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,s.jsx)(h,{label:e.label,description:e.description,columns:n,gridClassName:N[n],children:(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:D(e)}})},e.name||e.label||t)})});let t=T??k(f,u,e.columns,e.mode),n=N[t.columns||1];return(0,s.jsx)(r.SchemaRenderer,{schema:{...z,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},V=!_&&!y&&(F||I);return(0,s.jsx)(a.Dialog,{open:C,onOpenChange:e.onOpenChange,children:(0,s.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(E,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,c,e.className),children:[(e.title||e.description)&&(0,s.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,s.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,s.jsx)(a.DialogDescription,{children:e.description})]}),(0,s.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:B()}),V&&(0,s.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[I&&(0,s.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:j,disabled:x,className:`w-full sm:w-auto`,children:R}),F&&(0,s.jsxs)(a.Button,{type:`submit`,form:w,disabled:x,className:`w-full sm:w-auto`,children:[x&&(0,s.jsx)(o.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),L]})]})})]})})},F=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,s.jsx)(g,{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,s.jsx)(_,{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,s.jsx)(v,{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,s.jsx)(j,{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,collapsible:e.collapsible,collapsed:e.collapsed})),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,s.jsx)(P,{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,s.jsx)(I,{schema:e,dataSource:t})},I=({schema:e,dataSource:n})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),c=(0,a.useIsMobile)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)([]),[p,m]=(0,t.useState)(null),[g,v]=(0,t.useState)(!0),[y,b]=(0,t.useState)(null),x=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{x&&(m(e.initialData||e.initialValues||{}),v(!1))},[x,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{x?u({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}"`);u(t)}catch(e){b(e),v(!1)}})():x||v(!1)},[e.objectName,n,x]),(0,t.useEffect)(()=>{l&&!x&&(async()=>{if(!e.recordId||e.mode===`create`){m(e.initialData||e.initialValues||{}),v(!1);return}if(!x){if(!n){b(Error(`DataSource is required for fetching record data (inline data not provided)`)),v(!1);return}v(!0);try{m(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),b(e)}finally{v(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,l,x]),(0,t.useEffect)(()=>{if(x&&e.customFields){f(e.customFields),v(!1);return}if(!l)return;let t=[],r=e.fields||Object.keys(l.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=l.fields?.[r];if(!a&&!x)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(c);else if(a){let s={name:r,label:o(e.objectName,r,a.label||n),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};if((a.type===`select`||a.type===`lookup`||a.type===`master_detail`)&&(s.options=a.options||[],s.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(s.inputType=`number`,s.min=a.min,s.max=a.max,s.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(s.inputType=`date`),a.type===`datetime`&&(s.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(s.maxLength=a.max_length,s.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(s.inputType=`file`,s.multiple=a.multiple,s.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;s.description=s.description?`${s.description} (${e})`:e}a.type===`email`&&(s.inputType=`email`),a.type===`phone`&&(s.inputType=`tel`),a.type===`url`&&(s.inputType=`url`),a.type===`password`&&(s.inputType=`password`),a.type===`time`&&(s.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(s.disabled=!0),a.visible_on&&(s.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(s)}}),f(t),!x&&e.recordId&&e.mode!==`create`&&n||v(!1)},[l,e.fields,e.customFields,e.readOnly,e.mode,x,e.recordId,n]);let S=(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={})),x&&!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,x]),C=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),w={...t.default.useMemo(()=>{if(!l?.fields)return{};let e={};return Object.keys(l.fields).forEach(t=>{let n=l.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[l]),...p};if(y)return(0,s.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,s.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,s.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(g)return(0,s.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,s.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,s.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let T=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,s.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=d.filter(e=>i.includes(e.name));return(0,s.jsx)(h,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,s.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:T,defaultValues:w,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:S,onCancel:C}})},t.name||t.label||n)})});let E=e.sections?.length,D=E?{fields:d,columns:e.columns}:k(d,l,e.columns,e.mode),O=e.mobile,A=O?.fullscreenLongText?D.fields.map(e=>{let t=e.type;return t===`textarea`||t===`field:textarea`||t===`string-multiline`||t===`field:markdown`||t===`field:html`?{...e,mobile_fullscreen:!0}:e}):D.fields,j=O?.stepper,M=O?.stepperMinFields??8,N=Math.max(1,O?.stepperFieldsPerStep??1);if(!e.formType&&!E&&A.length>=2&&(j===!0||j===`auto`&&c&&A.length>=M)){let t=A,r=[];for(let e=0;e<t.length;e+=N){let n=t.slice(e,e+N);r.push({name:`step-${Math.floor(e/N)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/N)+1}`,fields:n})}return(0,s.jsx)(_,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let P={type:`form`,fields:A,layout:T,columns:D.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:w,onSubmit:S,onCancel:C,className:e.className,mobileStickyActions:!!O?.stickyActions};return(0,s.jsx)(`div`,{className:O?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":O?`true`:void 0,children:(0,s.jsx)(r.SchemaRenderer,{schema:P})})},L=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[a,o]=(0,t.useState)(!1),[c,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(null),f=(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]),p=(0,t.useCallback)(async t=>{l(!0),d(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){d(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{l(!1)}},[n,e]),m=(0,t.useCallback)(()=>{o(!1),d(null)},[]),h=(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,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,s.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,s.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,s.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,s.jsx)(`button`,{onClick:m,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,s.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,s.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${i||``}`,style:h,children:(0,s.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,s.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,s.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,s.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,s.jsxs)(`div`,{className:`p-6`,children:[u&&(0,s.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:u}),(0,s.jsx)(F,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:f,onSuccess:p,submitLabel:c?`Submitting...`:`Submit`},dataSource:n})]}),(0,s.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,s.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function R(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 z=({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]),c=(0,t.useMemo)(()=>r.dailySubmissions?.length?Math.max(...r.dailySubmissions.map(e=>e.count),1):1,[r.dailySubmissions]);return(0,s.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,s.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,s.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,s.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,s.jsx)(a.Card,{children:(0,s.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,s.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,s.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?R(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,s.jsxs)(a.Card,{children:[(0,s.jsx)(a.CardHeader,{children:(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,s.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/c*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,s.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,s.jsxs)(a.Card,{children:[(0,s.jsxs)(a.CardHeader,{children:[(0,s.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,s.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,s.jsx)(a.CardContent,{children:(0,s.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,s.jsxs)(`div`,{className:`space-y-1`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,s.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,s.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,s.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,s.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))})})]})]})},B=({schema:e})=>(0,s.jsx)(F,{schema:e});n.ComponentRegistry.register(`object-form`,B,{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`,B,{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,s.jsx)(L,{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,s.jsx)(z,{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=j,e.EmbeddableForm=L,e.FormAnalytics=z,e.FormSection=h,e.ModalForm=P,e.ObjectForm=F,e.SplitForm=v,e.TabbedForm=g,e.WizardForm=_,e.applyAutoColSpan=T,e.applyAutoLayout=k,e.filterCreateModeFields=D,e.inferColumns=w,e.inferModalSize=O,e.isAutoGeneratedFieldType=C,e.isWideFieldType=S});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-form",
3
- "version": "4.0.5",
3
+ "version": "4.0.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Form plugin for Object UI",
@@ -16,11 +16,11 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "lucide-react": "^1.14.0",
19
- "@object-ui/components": "4.0.5",
20
- "@object-ui/core": "4.0.5",
21
- "@object-ui/fields": "4.0.5",
22
- "@object-ui/react": "4.0.5",
23
- "@object-ui/types": "4.0.5"
19
+ "@object-ui/components": "4.0.6",
20
+ "@object-ui/core": "4.0.6",
21
+ "@object-ui/fields": "4.0.6",
22
+ "@object-ui/react": "4.0.6",
23
+ "@object-ui/types": "4.0.6"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": "^18.0.0 || ^19.0.0",
@@ -32,7 +32,7 @@
32
32
  "typescript": "^6.0.3",
33
33
  "vite": "^8.0.10",
34
34
  "vite-plugin-dts": "^5.0.0",
35
- "@object-ui/data-objectstack": "4.0.5"
35
+ "@object-ui/data-objectstack": "4.0.6"
36
36
  },
37
37
  "keywords": [
38
38
  "objectui",