@object-ui/plugin-form 6.0.3 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @object-ui/plugin-form
2
2
 
3
+ ## 6.1.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [991b62d]
8
+ - @object-ui/core@6.1.0
9
+ - @object-ui/types@6.1.0
10
+ - @object-ui/components@6.1.0
11
+ - @object-ui/fields@6.1.0
12
+ - @object-ui/react@6.1.0
13
+ - @object-ui/permissions@6.1.0
14
+
15
+ ## 6.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - @object-ui/types@6.0.4
20
+ - @object-ui/core@6.0.4
21
+ - @object-ui/react@6.0.4
22
+ - @object-ui/components@6.0.4
23
+ - @object-ui/fields@6.0.4
24
+ - @object-ui/permissions@6.0.4
25
+
3
26
  ## 6.0.3
4
27
 
5
28
  ### Patch Changes
@@ -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(`@object-ui/permissions`),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`,`@object-ui/permissions`,`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._object_ui_permissions,e.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:l,className:u,gridClassName:d,showBorder:f})=>{let[p,m]=(0,t.useState)(i),h={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`},g=()=>{r&&m(!p)},_=f??!!e,v=e||n?(0,c.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2`,!_&&`mb-4`,r&&`cursor-pointer select-none`),onClick:g,role:r?`button`:void 0,"aria-expanded":r?!p:void 0,children:[r&&(0,c.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:p?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})}),(0,c.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,c.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}):null,y=p?null:(0,c.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||h[o]),children:l});return _?(0,c.jsxs)(a.Card,{className:(0,a.cn)(`form-section`,u),children:[v&&(0,c.jsxs)(a.CardHeader,{className:`pb-3`,children:[e&&(0,c.jsx)(a.CardTitle,{className:`text-base`,children:e}),n&&(0,c.jsx)(a.CardDescription,{children:n}),r&&(0,c.jsx)(`button`,{type:`button`,className:`absolute right-4 top-4 text-muted-foreground`,onClick:g,"aria-expanded":!p,"aria-label":p?`Expand section`:`Collapse section`,children:p?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})})]}),y&&(0,c.jsx)(a.CardContent,{children:y})]}):(0,c.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[v,y]})},_=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(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: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},[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(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,c.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,c.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,c.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,c.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,c.jsx)(g,{description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,h]=(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){h(!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||{}),h(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{h(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let O=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(u?.fields?.[t]){let a=u.fields[t];n.push(r({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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[u,e.readOnly,e.mode,e.objectName]),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,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,c.jsxs)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:[e.showStepIndicator!==!1&&(0,c.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,c.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),o=e.allowSkip||i||n<=y;return(0,c.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,c.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!o,children:[(0,c.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,c.jsx)(s.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,c.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,c.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,c.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,c.jsx)(g,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,c.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,c.jsx)(`div`,{children:e.showCancel!==!1&&(0,c.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,c.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,c.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,c.jsx)(s.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,c.jsxs)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:[C&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,c.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},y=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(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=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(l?.fields?.[t]){let a=l.fields[t];n.push(r({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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode,e.objectName]),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(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,c.jsx)(g,{label:t.label,description:t.description,columns:t.columns||1,children:(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,c.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,c.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},b=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),x=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),S=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function C(e){return x.has(e)}function w(e){return S.has(e)}function T(e){return e<=3?1:2}function E(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&C(e.type)?{...e,colSpan:t}:e)}var D=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function O(e,t){return e.filter(e=>!(D.has(e.name)||t?.fields?.[e.name]?.readonly===!0))}function k(e,t){return e.filter(e=>{if(D.has(e.name)||e.type&&b.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!w(n.type):!0})}function A(e,t){return e.filter(e=>{if(e.type&&b.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!w(n.type):!0})}function j(e){return e<=1?`default`:e===2?`xl`:`full`}function M(e,t,n,r){let i=[...e];if(i=O(i,t),r===`create`&&(i=A(i,t)),n!==void 0)return i=E(i,n),{fields:i,columns:n};let a=T(i.length);return i=E(i,a),{fields:i,columns:a}}var N=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),P=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function F(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!N.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(P.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var I={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`},L=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(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: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},[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: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})}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,i=F(t,l);return e.mode===`create`?r=await n.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,l]),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,c.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,c.jsxs)(a.SheetHeader,{children:[e.title&&(0,c.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,c.jsx)(a.SheetDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=M(d,l,e.columns,e.mode),n=I[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},R={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`},z={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`},B=({schema:e,dataSource:n,className:l})=>{let{fieldLabel:u}=(0,r.useSafeFieldLabel)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(!1),E=e.open!==!1,D=(0,t.useId)(),O=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:M(h,p,e.columns,e.mode),[h,p,e.columns,e.mode,e.sections,e.customFields]),k=R[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(O?.columns&&O.columns>1)return j(O.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return j(t)}return`default`},[e.modalSize,O,e.sections])]||R.default;(0,t.useEffect)(()=>{(async()=>{if(!n){x(!1);return}try{m(await n.getObjectSchema(e.objectName))}catch(e){C(e),x(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(p||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){y(e.initialData||e.initialValues||{}),x(!1);return}if(!n){y(e.initialData||e.initialValues||{}),x(!1);return}try{y(await n.findOne(e.objectName,e.recordId)||{})}catch(e){C(e)}finally{x(!1)}})()},[p,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let A=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(p?.fields?.[t]){let a=p.fields[t];n.push(r({name:t,label:u(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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[p,e.readOnly,e.mode,e.objectName]);(0,t.useEffect)(()=>{if(!p&&n)return;if(e.customFields?.length){_(e.customFields),x(!1);return}if(e.sections?.length){x(!1);return}if(!p)return;let t=e.fields||Object.keys(p.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=p.fields?.[t];a&&r.push({name:t,label:u(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})}_(r),x(!1)},[p,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let N=(0,t.useCallback)(async t=>{T(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=F(t,p);if(d?.isLoaded){let t={};for(let n of Object.keys(i))d.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}return e.mode===`create`?r=await n.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{T(!1)}},[e,n,p,d]),P=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),I=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,L=e.showSubmit!==!1&&e.mode!==`view`,B=e.showCancel!==!1,V=e.submitText||(e.mode===`create`?`Create`:`Update`),H=e.cancelText||`Cancel`,U={type:`form`,layout:I,defaultValues:v,submitLabel:V,cancelLabel:H,showSubmit:L,showCancel:B,onSubmit:N,onCancel:P,showActions:!1,id:D},W=()=>{if(S)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(b)return(0,c.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,c.jsxs)(`div`,{className:`space-y-2`,children:[(0,c.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,c.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,c.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,c.jsx)(g,{label:e.label,description:e.description,columns:n,gridClassName:z[n],children:(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(A(e))}})},e.name||e.label||t)})});let t=O??M(h,p,e.columns,e.mode),n=z[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!b&&!S&&(L||B);return(0,c.jsx)(a.Dialog,{open:E,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(k,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,l,e.className),children:[(e.title||e.description)&&(0,c.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,c.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,c.jsx)(a.DialogDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,c.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[B&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:P,disabled:w,className:`w-full sm:w-auto`,children:H}),L&&(0,c.jsxs)(a.Button,{type:`submit`,form:D,disabled:w,className:`w-full sm:w-auto`,children:[w&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),V]})]})})]})})},V=({schema:e,dataSource:n})=>{let i=(0,o.usePermissions)(),a=(0,t.useMemo)(()=>{if(!i?.isLoaded)return e;let t=t=>t?.name?i.checkField(e.objectName,t.name,`read`)?!i.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,n=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)}))}},[e,i]),{sectionLabel:s}=(0,r.useSafeFieldLabel)(),l=e=>e?.name?s(a.objectName,e.name,e.label||e.name):e?.label;if(a.formType===`tabbed`&&a.sections?.length)return(0,c.jsx)(_,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,c.jsx)(v,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,c.jsx)(y,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(L,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(B,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,c.jsx)(H,{schema:a,dataSource:n})},H=({schema:e,dataSource:n})=>{let{fieldLabel:s,sectionLabel:l}=(0,r.useSafeFieldLabel)(),u=(0,a.useIsMobile)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t)d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),T=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{T&&(b(e.initialData||e.initialValues||{}),S(!1))},[T,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{T?m({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}"`);m(t)}catch(e){w(e),S(!1)}})():T||S(!1)},[e.objectName,n,T]),(0,t.useEffect)(()=>{p&&!T&&(async()=>{if(!e.recordId||e.mode===`create`){b(e.initialData||e.initialValues||{}),S(!1);return}if(!T){if(!n){w(Error(`DataSource is required for fetching record data (inline data not provided)`)),S(!1);return}S(!0);try{b(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),w(e)}finally{S(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,p,T]);let E=(0,t.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e},[]);(0,t.useEffect)(()=>{if(T&&e.customFields){_(e.customFields.map(E)),S(!1);return}if(!p)return;let t=[],r=e.fields||Object.keys(p.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=p.fields?.[r];if(!a&&!T)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(E(c));else if(a){let o={name:r,label:s(e.objectName,r,a.label||n),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||p?.managedBy&&p.managedBy!==`platform`,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`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(o)}}),_(t),!T&&e.recordId&&e.mode!==`create`&&n||S(!1)},[p,e.fields,e.customFields,e.readOnly,e.mode,T,e.recordId,n]);let D=(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={})),T&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=t;if(d?.isLoaded&&t&&typeof t==`object`){i={};for(let n of Object.keys(t))d.checkField(e.objectName,n,`write`)&&(i[n]=t[n])}try{let t;if(e.mode===`create`)t=await n.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)t=await n.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(t),t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,T,d]),O=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),k={...t.default.useMemo(()=>{if(!p?.fields)return{};let e={};return Object.keys(p.fields).forEach(t=>{let n=p.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[p]),...y};if(C)return(0,c.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,c.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,c.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=f(h.filter(e=>i.includes(e.name)));return(0,c.jsx)(g,{label:t.name?l(e.objectName,t.name,t.label||t.name):t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,showBorder:t.showBorder,children:(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:A,defaultValues:k,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:D,onCancel:O}})},t.name||t.label||n)})});let j=e.sections?.length,N=f(h),P=j?{fields:N,columns:e.columns}:M(N,p,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.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}):P.fields,L=F?.stepper,R=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&u&&I.length>=R)){let t=I,r=[];for(let e=0;e<t.length;e+=z){let n=t.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:n})}return(0,c.jsx)(v,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let B={type:`form`,fields:I,layout:A,columns:P.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:k,onSubmit:D,onCancel:O,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,c.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,c.jsx)(r.SchemaRenderer,{schema:B})})},U={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},W=`_company_website_2`,G=1500;function K(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function q(e){return e&&e.map(e=>{let t=U[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var J=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[o,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(!1),[f,p]=(0,t.useState)(null),[m,h]=(0,t.useState)(!(e.consent?.required??!!e.consent)),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(null),y=(0,t.useRef)(Date.now());(0,t.useEffect)(()=>{o||(y.current=Date.now())},[o]);let b=e.honeypot===!1?null:e.honeypot||W,x=e.minFillTime??G,S=(0,t.useMemo)(()=>q(e.customFields),[e.customFields]),C=(0,t.useMemo)(()=>{if(!n||S&&S.length>0||!e.fields||e.fields.length===0)return;let t=async(e,t)=>t;return{...n,create:t,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[n,S,e.fields]),w=(0,t.useMemo)(()=>{let t={};if(r)for(let[e,n]of Object.entries(r))t[e]=n;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[r,e.allowedPrefillFields]),T=(0,t.useCallback)(async t=>{if(e.consent?.required&&!m){_(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(_(null),b&&v.current?.value){l(!0);return}if(x>0&&Date.now()-y.current<x){p(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...t};b&&delete r[b],e.captchaToken&&(r._captcha=e.captchaToken),d(!0),p(null);try{n&&await n.create(e.objectName,r),l(!0);let t=e.thankYouPage?.redirectUrl;if(t)if(K(t,e.allowedRedirectHosts)){let n=e.thankYouPage?.redirectDelay??3e3;setTimeout(()=>{window.location.href=t},n)}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,t),p(e.texts?.redirectBlocked??null)}catch(e){p(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{d(!1)}},[n,e,m,b,x]),E=(0,t.useCallback)(()=>{l(!1),p(null)},[]),D=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(o){let t=e.thankYouPage,n=e.texts??{},r=Math.ceil((t?.redirectDelay??3e3)/1e3),o=(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(r));return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,c.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,c.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,c.jsx)(s.CheckCircle2,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,c.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,onClick:E,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})})}let O=e.texts??{},k=!!e.consent?.required,A=`${e.formId}-consent`;return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,c.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,c.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,c.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,c.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,c.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,c.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:O.requiredHint??`* Required field`})]}),(0,c.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[f&&(0,c.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:f}),(0,c.jsx)(V,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:S,initialData:w,onSuccess:T,submitText:u?O.submitting??`Submitting...`:O.submit??`Submit`},dataSource:C}),b&&(0,c.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,c.jsx)(`label`,{htmlFor:`${e.formId}-${b}`,children:`Do not fill this field`}),(0,c.jsx)(`input`,{ref:v,id:`${e.formId}-${b}`,type:`text`,name:b,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,c.jsxs)(`div`,{className:`mt-4`,children:[(0,c.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,c.jsx)(`input`,{type:`checkbox`,id:A,checked:m,onChange:e=>{h(e.target.checked),e.target.checked&&_(null)},"aria-required":k||void 0,"aria-invalid":g?`true`:void 0,"aria-describedby":g?`${A}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,c.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??O.consentLabelDefault??`I agree to the privacy policy.`,k&&(0,c.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,c.jsxs)(c.Fragment,{children:[` `,(0,c.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:O.consentLink??`Privacy policy`})]})]})]}),g&&(0,c.jsx)(`p`,{id:`${A}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:g})]}),u&&(0,c.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,c.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,c.jsx)(`span`,{children:O.submitting??`Submitting…`})]})]}),(0,c.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,c.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,c.jsx)(s.Lock,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,c.jsx)(`span`,{children:O.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,c.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,c.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,c.jsx)(s.ShieldCheck,{className:`h-3 w-3`,"aria-hidden":`true`}),O.consentLink??`Privacy policy`]}),(0,c.jsx)(`span`,{children:O.poweredBy??`Powered by ObjectStack`})]})]})]})})};function Y(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 X=({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,c.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,c.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,c.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,c.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?Y(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsx)(a.CardHeader,{children:(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,c.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,c.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,c.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,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{children:[(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,c.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,c.jsxs)(`div`,{className:`space-y-1`,children:[(0,c.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,c.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,c.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,c.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))})})]})]})},Z=({schema:e})=>(0,c.jsx)(V,{schema:e});n.ComponentRegistry.register(`object-form`,Z,{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`,Z,{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,c.jsx)(J,{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,c.jsx)(X,{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=L,e.EmbeddableForm=J,e.FormAnalytics=X,e.FormSection=g,e.ModalForm=B,e.ObjectForm=V,e.SplitForm=y,e.TabbedForm=_,e.WizardForm=v,e.applyAutoColSpan=E,e.applyAutoLayout=M,e.filterAutoGeneratedFields=A,e.filterCreateModeFields=k,e.filterSystemFields=O,e.inferColumns=T,e.inferModalSize=j,e.isAutoGeneratedFieldType=w,e.isWideFieldType=C});
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("@object-ui/permissions"),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`,`@object-ui/permissions`,`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._object_ui_permissions,e.lucide_react,e.react_jsx_runtime))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var g=({label:e,description:n,collapsible:r=!1,collapsed:i=!1,columns:o=1,children:l,className:u,gridClassName:d,showBorder:f})=>{let[p,m]=(0,t.useState)(i),h={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`},g=()=>{r&&m(!p)},_=f??!!e,v=e||n?(0,c.jsxs)(`div`,{className:(0,a.cn)(`flex items-start gap-2`,!_&&`mb-4`,r&&`cursor-pointer select-none`),onClick:g,role:r?`button`:void 0,"aria-expanded":r?!p:void 0,children:[r&&(0,c.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:p?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})}),(0,c.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,c.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),n&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:n})]})]}):null,y=p?null:(0,c.jsx)(`div`,{className:(0,a.cn)(`grid gap-4`,d||h[o]),children:l});return _?(0,c.jsxs)(a.Card,{className:(0,a.cn)(`form-section`,u),children:[v&&(0,c.jsxs)(a.CardHeader,{className:`pb-3`,children:[e&&(0,c.jsx)(a.CardTitle,{className:`text-base`,children:e}),n&&(0,c.jsx)(a.CardDescription,{children:n}),r&&(0,c.jsx)(`button`,{type:`button`,className:`absolute right-4 top-4 text-muted-foreground`,onClick:g,"aria-expanded":!p,"aria-label":p?`Expand section`:`Collapse section`,children:p?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4`})})]}),y&&(0,c.jsx)(a.CardContent,{children:y})]}):(0,c.jsxs)(`div`,{className:(0,a.cn)(`form-section`,u),children:[v,y]})},_=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(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: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},[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(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.Tabs,{value:v,onValueChange:y,orientation:T?`vertical`:`horizontal`,className:(0,a.cn)(T&&`flex gap-4`),children:[(0,c.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,c.jsx)(a.TabsTrigger,{value:C(e,t),className:T?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},C(e,t)))}),(0,c.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,c.jsx)(a.TabsContent,{value:C(t,n),className:`mt-0`,children:(0,c.jsx)(g,{description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...w,fields:b(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},v=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:l}=(0,r.useSafeFieldLabel)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)({}),[m,h]=(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){h(!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||{}),h(!1);return}try{p(await n.findOne(e.objectName,e.recordId)||{})}catch(e){v(e)}finally{h(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let O=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(u?.fields?.[t]){let a=u.fields[t];n.push(r({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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[u,e.readOnly,e.mode,e.objectName]),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,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(m)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let F=e.sections[y];return(0,c.jsxs)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:[e.showStepIndicator!==!1&&(0,c.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,c.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===y,i=x.has(n),o=e.allowSkip||i||n<=y;return(0,c.jsxs)(`li`,{className:(0,a.cn)(`relative flex-1`,n!==T-1&&`pr-8 sm:pr-12`),children:[n!==T-1&&(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,c.jsxs)(`button`,{type:`button`,className:(0,a.cn)(`group relative flex items-center`,o?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>P(n),disabled:!o,children:[(0,c.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,c.jsx)(s.Check,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,c.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,c.jsx)(`span`,{className:(0,a.cn)(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,c.jsx)(`div`,{className:`min-h-[200px]`,children:F&&(0,c.jsx)(g,{label:F.label,description:F.description,columns:F.columns||1,children:k.length>0?(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:k,layout:`vertical`,defaultValues:f,showSubmit:!1,showCancel:!1,onSubmit:A}}):(0,c.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,c.jsx)(`div`,{children:e.showCancel!==!1&&(0,c.jsx)(a.Button,{variant:`ghost`,onClick:N,children:e.cancelText||`Cancel`})}),(0,c.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,c.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,y+1,` of `,T]}),!E&&(0,c.jsxs)(a.Button,{variant:`outline`,onClick:M,children:[(0,c.jsx)(s.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),D?(0,c.jsxs)(a.Button,{onClick:()=>A(f),disabled:C||e.mode===`view`,children:[C&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),C?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,c.jsxs)(a.Button,{onClick:()=>A(f),children:[e.nextText||`Next`,(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},y=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,_]=(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=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(l?.fields?.[t]){let a=l.fields[t];n.push(r({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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[l,e.readOnly,e.mode,e.objectName]),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(h)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:h.message})]});if(p)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,c.jsx)(g,{label:t.label,description:t.description,columns:t.columns||1,children:(0,c.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,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,o,e.className),children:(0,c.jsxs)(a.ResizablePanelGroup,{orientation:C,className:`min-h-[300px] rounded-lg border`,children:[(0,c.jsx)(a.ResizablePanel,{defaultSize:w,minSize:20,children:E(x,S.length===0)}),S.length>0&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.ResizableHandle,{withHandle:e.splitResizable!==!1}),(0,c.jsx)(a.ResizablePanel,{defaultSize:100-w,minSize:20,children:E(S,!0)})]})]})})},b=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),x=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),S=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function C(e){return x.has(e)}function w(e){return S.has(e)}function T(e){return e<=3?1:2}function E(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&C(e.type)?{...e,colSpan:t}:e)}var D=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`last_modified_at`,`lastModifiedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`last_modified_by`,`lastModifiedBy`,`organization_id`,`organizationId`,`org_id`,`orgId`,`tenant_id`,`tenantId`,`owner`,`owner_id`,`_version`,`_rev`]);function O(e,t){return e.filter(e=>!(D.has(e.name)||t?.fields?.[e.name]?.readonly===!0))}function k(e,t){return e.filter(e=>{if(D.has(e.name)||e.type&&b.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!w(n.type):!0})}function A(e,t){return e.filter(e=>{if(e.type&&b.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!w(n.type):!0})}function j(e){return e<=1?`default`:e===2?`xl`:`full`}function M(e,t,n,r){let i=[...e];if(i=O(i,t),r===`create`&&(i=A(i,t)),n!==void 0)return i=E(i,n),{fields:i,columns:n};let a=T(i.length);return i=E(i,a),{fields:i,columns:a}}var N=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),P=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function F(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!N.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(P.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var I={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`},L=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(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: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},[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: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})}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,i=F(t,l);return e.mode===`create`?r=await n.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,n,l]),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,c.jsx)(a.Sheet,{open:y,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.SheetContent,{side:b,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:E,children:[(e.title||e.description)&&(0,c.jsxs)(a.SheetHeader,{children:[e.title&&(0,c.jsx)(a.SheetTitle,{children:e.title}),e.description&&(0,c.jsx)(a.SheetDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(_)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:_.message})]});if(h)return(0,c.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.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,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t}})}let t=M(d,l,e.columns,e.mode),n=I[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...D,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},R={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`},z={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`},B=({schema:e,dataSource:n,className:l})=>{let{fieldLabel:u}=(0,r.useSafeFieldLabel)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[v,y]=(0,t.useState)({}),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),[w,T]=(0,t.useState)(!1),E=e.open!==!1,D=(0,t.useId)(),O=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:M(h,p,e.columns,e.mode),[h,p,e.columns,e.mode,e.sections,e.customFields]),k=R[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(O?.columns&&O.columns>1)return j(O.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return j(t)}return`default`},[e.modalSize,O,e.sections])]||R.default;(0,t.useEffect)(()=>{(async()=>{if(!n){x(!1);return}try{m(await n.getObjectSchema(e.objectName))}catch(e){C(e),x(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(p||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){y(e.initialData||e.initialValues||{}),x(!1);return}if(!n){y(e.initialData||e.initialValues||{}),x(!1);return}try{y(await n.findOne(e.objectName,e.recordId)||{})}catch(e){C(e)}finally{x(!1)}})()},[p,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let A=(0,t.useCallback)(t=>{let n=[],r=(e,t)=>typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e;for(let a of t.fields){let t=typeof a==`string`?a:a.name;if(typeof a==`object`)n.push(r(a,a.visibleOn));else if(p?.fields?.[t]){let a=p.fields[t];n.push(r({name:t,label:u(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},a.visible_on??a.visibleOn))}else n.push({name:t,label:t,type:`input`})}return n},[p,e.readOnly,e.mode,e.objectName]);(0,t.useEffect)(()=>{if(!p&&n)return;if(e.customFields?.length){_(e.customFields),x(!1);return}if(e.sections?.length){x(!1);return}if(!p)return;let t=e.fields||Object.keys(p.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=p.fields?.[t];a&&r.push({name:t,label:u(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})}_(r),x(!1)},[p,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let N=(0,t.useCallback)(async t=>{T(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=F(t,p);if(d?.isLoaded){let t={};for(let n of Object.keys(i))d.checkField(e.objectName,n,`write`)&&(t[n]=i[n]);i=t}return e.mode===`create`?r=await n.create(e.objectName,i):e.mode===`edit`&&e.recordId&&(r=await n.update(e.objectName,e.recordId,i)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{T(!1)}},[e,n,p,d]),P=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),I=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,L=e.showSubmit!==!1&&e.mode!==`view`,B=e.showCancel!==!1,V=e.submitText||(e.mode===`create`?`Create`:`Update`),H=e.cancelText||`Cancel`,U={type:`form`,layout:I,defaultValues:v,submitLabel:V,cancelLabel:H,showSubmit:L,showCancel:B,onSubmit:N,onCancel:P,showActions:!1,id:D},W=()=>{if(S)return(0,c.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:S.message})]});if(b)return(0,c.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,c.jsxs)(`div`,{className:`space-y-2`,children:[(0,c.jsx)(a.Skeleton,{className:`h-4 w-24`}),(0,c.jsx)(a.Skeleton,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,c.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,c.jsx)(g,{label:e.label,description:e.description,columns:n,gridClassName:z[n],children:(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(A(e))}})},e.name||e.label||t)})});let t=O??M(h,p,e.columns,e.mode),n=z[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...U,fields:f(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!b&&!S&&(L||B);return(0,c.jsx)(a.Dialog,{open:E,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(k,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,l,e.className),children:[(e.title||e.description)&&(0,c.jsxs)(a.DialogHeader,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,c.jsx)(a.DialogTitle,{children:e.title}),e.description&&(0,c.jsx)(a.DialogDescription,{children:e.description})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,c.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[B&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:P,disabled:w,className:`w-full sm:w-auto`,children:H}),L&&(0,c.jsxs)(a.Button,{type:`submit`,form:D,disabled:w,className:`w-full sm:w-auto`,children:[w&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),V]})]})})]})})},V=({schema:e,dataSource:n})=>{let i=(0,o.usePermissions)(),a=(0,t.useMemo)(()=>{if(!i?.isLoaded)return e;let t=t=>t?.name?i.checkField(e.objectName,t.name,`read`)?!i.checkField(e.objectName,t.name,`write`)&&e.mode!==`view`?{...t,readOnly:!0,disabled:!0}:t:null:t,n=e=>Array.isArray(e)?e.map(t).filter(Boolean):e;return{...e,fields:n(e.fields),sections:e.sections?.map(e=>({...e,fields:n(e.fields)}))}},[e,i]),{sectionLabel:s}=(0,r.useSafeFieldLabel)(),l=e=>e?.name?s(a.objectName,e.name,e.label||e.name):e?.label;if(a.formType===`tabbed`&&a.sections?.length)return(0,c.jsx)(_,{schema:{...a,formType:`tabbed`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),defaultTab:a.defaultTab,tabPosition:a.tabPosition},dataSource:n,className:a.className});if(a.formType===`wizard`&&a.sections?.length)return(0,c.jsx)(v,{schema:{...a,formType:`wizard`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),allowSkip:a.allowSkip,showStepIndicator:a.showStepIndicator,nextText:a.nextText,prevText:a.prevText,onStepChange:a.onStepChange},dataSource:n,className:a.className});if(a.formType===`split`&&a.sections?.length)return(0,c.jsx)(y,{schema:{...a,formType:`split`,sections:a.sections.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),splitDirection:a.splitDirection,splitSize:a.splitSize,splitResizable:a.splitResizable},dataSource:n,className:a.className});if(a.formType===`drawer`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(L,{schema:{...t,layout:r,formType:`drawer`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:a.open,onOpenChange:a.onOpenChange,drawerSide:a.drawerSide,drawerWidth:a.drawerWidth},dataSource:n,className:a.className})}if(a.formType===`modal`){let{layout:e,...t}=a,r=a.layout===`vertical`||a.layout===`horizontal`?a.layout:void 0;return(0,c.jsx)(B,{schema:{...t,layout:r,formType:`modal`,sections:a.sections?.map(e=>({name:e.name,label:l(e),description:e.description,columns:e.columns,fields:e.fields})),open:a.open,onOpenChange:a.onOpenChange,modalSize:a.modalSize,modalCloseButton:a.modalCloseButton},dataSource:n,className:a.className})}return(0,c.jsx)(H,{schema:a,dataSource:n})},H=({schema:e,dataSource:n})=>{let{fieldLabel:s,sectionLabel:l}=(0,r.useSafeFieldLabel)(),u=(0,a.useIsMobile)(),d=(0,o.usePermissions)(),f=(0,t.useCallback)(t=>{if(!d?.isLoaded)return t;let n=[];for(let r of t)d.checkField(e.objectName,r.name,`read`)&&(!d.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0,description:r.description??`You do not have edit access to this field.`}):n.push(r));return n},[d,e.objectName,e.mode]),[p,m]=(0,t.useState)(null),[h,_]=(0,t.useState)([]),[y,b]=(0,t.useState)(null),[x,S]=(0,t.useState)(!0),[C,w]=(0,t.useState)(null),T=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{T&&(b(e.initialData||e.initialValues||{}),S(!1))},[T,e.initialData,e.initialValues]),(0,t.useEffect)(()=>{T?m({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}"`);m(t)}catch(e){w(e),S(!1)}})():T||S(!1)},[e.objectName,n,T]),(0,t.useEffect)(()=>{p&&!T&&(async()=>{if(!e.recordId||e.mode===`create`){b(e.initialData||e.initialValues||{}),S(!1);return}if(!T){if(!n){w(Error(`DataSource is required for fetching record data (inline data not provided)`)),S(!1);return}S(!0);try{b(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),w(e)}finally{S(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,n,p,T]);let E=(0,t.useCallback)(e=>{if(!e||typeof e.visible==`function`)return e;let t=e.visibleOn;return typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e},[]);(0,t.useEffect)(()=>{if(T&&e.customFields){_(e.customFields.map(E)),S(!1);return}if(!p)return;let t=[],r=e.fields||Object.keys(p.fields||{});(Array.isArray(r)?r:Object.keys(r)).forEach(n=>{let r=typeof n==`string`?n:n.name;if(!r)return;let a=p.fields?.[r];if(!a&&!T)return;let o=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!o)return;let c=e.customFields?.find(e=>e.name===r);if(c)t.push(E(c));else if(a){let o={name:r,label:s(e.objectName,r,a.label||n),type:(0,i.mapFieldTypeToFormType)(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly||p?.managedBy&&p.managedBy!==`platform`,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`)&&(o.options=a.options||[],o.multiple=a.multiple),(a.type===`number`||a.type===`currency`||a.type===`percent`)&&(o.inputType=`number`,o.min=a.min,o.max=a.max,o.step=a.precision?10**-a.precision:void 0),a.type===`date`&&(o.inputType=`date`),a.type===`datetime`&&(o.inputType=`datetime-local`),(a.type===`text`||a.type===`textarea`||a.type===`markdown`||a.type===`html`)&&(o.maxLength=a.max_length,o.minLength=a.min_length),(a.type===`file`||a.type===`image`)&&(o.inputType=`file`,o.multiple=a.multiple,o.accept=a.accept?a.accept.join(`,`):void 0,a.max_size)){let e=`Max size: ${(0,i.formatFileSize)(a.max_size)}`;o.description=o.description?`${o.description} (${e})`:e}a.type===`email`&&(o.inputType=`email`),a.type===`phone`&&(o.inputType=`tel`),a.type===`url`&&(o.inputType=`url`),a.type===`password`&&(o.inputType=`password`),a.type===`time`&&(o.inputType=`time`),(a.type===`formula`||a.type===`summary`||a.type===`auto_number`)&&(o.disabled=!0),a.visible_on&&(o.visible=e=>(0,i.evaluateCondition)(a.visible_on,e)),t.push(o)}}),_(t),!T&&e.recordId&&e.mode!==`create`&&n||S(!1)},[p,e.fields,e.customFields,e.readOnly,e.mode,T,e.recordId,n]);let D=(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={})),T&&!n)return e.onSuccess&&await e.onSuccess(t),t;if(!n)throw Error(`DataSource is required for form submission (inline mode not configured)`);let i=t;if(d?.isLoaded&&t&&typeof t==`object`){i={};for(let n of Object.keys(t))d.checkField(e.objectName,n,`write`)&&(i[n]=t[n])}try{let t;if(e.mode===`create`)t=await n.create(e.objectName,i);else if(e.mode===`edit`&&e.recordId)t=await n.update(e.objectName,e.recordId,i);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(t),t}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,n,T,d]),O=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),k={...t.default.useMemo(()=>{if(!p?.fields)return{};let e={};return Object.keys(p.fields).forEach(t=>{let n=p.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[p]),...y};if(C)return(0,c.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:C.message})]});if(x)return(0,c.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let A=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,c.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=f(h.filter(e=>i.includes(e.name)));return(0,c.jsx)(g,{label:t.name?l(e.objectName,t.name,t.label||t.name):t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,showBorder:t.showBorder,children:(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,fields:a,layout:A,defaultValues:k,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:D,onCancel:O}})},t.name||t.label||n)})});let j=e.sections?.length,N=f(h),P=j?{fields:N,columns:e.columns}:M(N,p,e.columns,e.mode),F=e.mobile,I=F?.fullscreenLongText?P.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}):P.fields,L=F?.stepper,R=F?.stepperMinFields??8,z=Math.max(1,F?.stepperFieldsPerStep??1);if(!e.formType&&!j&&I.length>=2&&(L===!0||L===`auto`&&u&&I.length>=R)){let t=I,r=[];for(let e=0;e<t.length;e+=z){let n=t.slice(e,e+z);r.push({name:`step-${Math.floor(e/z)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/z)+1}`,fields:n})}return(0,c.jsx)(v,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let B={type:`form`,fields:I,layout:A,columns:P.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:k,onSubmit:D,onCancel:O,className:e.className,mobileStickyActions:!!F?.stickyActions};return(0,c.jsx)(`div`,{className:F?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":F?`true`:void 0,children:(0,c.jsx)(r.SchemaRenderer,{schema:B})})},U={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},W=`_company_website_2`,G=1500;function K(e,t=[]){try{let n=new URL(e,typeof window<`u`?window.location.href:`http://localhost`);return typeof window<`u`&&n.origin===window.location.origin?!0:n.protocol!==`https:`&&n.protocol!==`http:`?!1:t.some(e=>{if(e===n.host)return!0;if(e.startsWith(`*.`)){let t=e.slice(1);return n.host.endsWith(t)&&n.host.length>t.length}return!1})}catch{return!1}}function q(e){return e&&e.map(e=>{let t=U[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var J=({config:e,dataSource:n,prefillParams:r,className:i})=>{let[o,l]=(0,t.useState)(!1),[u,d]=(0,t.useState)(!1),[f,p]=(0,t.useState)(null),[m,h]=(0,t.useState)(!(e.consent?.required??!!e.consent)),[g,_]=(0,t.useState)(null),v=(0,t.useRef)(null),y=(0,t.useRef)(Date.now());(0,t.useEffect)(()=>{o||(y.current=Date.now())},[o]);let b=e.honeypot===!1?null:e.honeypot||W,x=e.minFillTime??G,S=(0,t.useMemo)(()=>q(e.customFields),[e.customFields]),C=(0,t.useMemo)(()=>{if(!n||S&&S.length>0||!e.fields||e.fields.length===0)return;let t=async(e,t)=>t;return{...n,create:t,update:(e,t,n)=>Promise.resolve(n),delete:()=>Promise.reject(Error(`Not permitted on public form`))}},[n,S,e.fields]),w=(0,t.useMemo)(()=>{let t={};if(r)for(let[e,n]of Object.entries(r))t[e]=n;if(typeof window<`u`&&e.allowedPrefillFields?.length){let n=new Set(e.allowedPrefillFields);new URLSearchParams(window.location.search).forEach((e,r)=>{n.has(r)&&!(r in t)&&(t[r]=e)})}return Object.keys(t).length>0?t:void 0},[r,e.allowedPrefillFields]),T=(0,t.useCallback)(async t=>{if(e.consent?.required&&!m){_(e.texts?.consentRequired??`Please accept the privacy policy to continue.`);return}if(_(null),b&&v.current?.value){l(!0);return}if(x>0&&Date.now()-y.current<x){p(e.texts?.rateLimited??`Please take a moment to review your answers before submitting.`);return}let r={...t};b&&delete r[b],e.captchaToken&&(r._captcha=e.captchaToken),d(!0),p(null);try{n&&await n.create(e.objectName,r),l(!0);let t=e.thankYouPage?.redirectUrl;if(t)if(K(t,e.allowedRedirectHosts)){let n=e.thankYouPage?.redirectDelay??3e3;setTimeout(()=>{window.location.href=t},n)}else console.warn(`[EmbeddableForm] Blocked unsafe redirect target:`,t),p(e.texts?.redirectBlocked??null)}catch(e){p(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{d(!1)}},[n,e,m,b,x]),E=(0,t.useCallback)(()=>{l(!1),p(null)},[]),D=(0,t.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(o){let t=e.thankYouPage,n=e.texts??{},r=Math.ceil((t?.redirectDelay??3e3)/1e3),o=(n.redirecting??`Redirecting in {{seconds}} seconds…`).replace(`{{seconds}}`,String(r));return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,c.jsxs)(`div`,{className:`max-w-md w-full bg-card border rounded-xl shadow-sm p-8 text-center space-y-4`,children:[(0,c.jsx)(`div`,{className:`mx-auto inline-flex h-14 w-14 items-center justify-center rounded-full bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400`,children:(0,c.jsx)(s.CheckCircle2,{className:`h-8 w-8`,"aria-hidden":`true`})}),(0,c.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||n.thankYouTitle||`Thank You!`}),(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t?.message||n.thankYouMessage||`Your submission has been received successfully.`}),e.allowMultiple&&(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,onClick:E,className:`mt-2`,children:n.submitAnother??`Submit Another Response`}),t?.redirectUrl&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})})}let O=e.texts??{},k=!!e.consent?.required,A=`${e.formId}-consent`;return(0,c.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 sm:p-6 bg-gradient-to-b from-muted/40 via-background to-background ${i||``}`,style:D,children:(0,c.jsxs)(`div`,{className:`max-w-2xl w-full bg-card border rounded-xl shadow-sm overflow-hidden`,children:[e.branding?.coverImage&&(0,c.jsx)(`div`,{className:`h-28 sm:h-32 w-full bg-cover bg-center`,style:{backgroundImage:`url(${JSON.stringify(e.branding.coverImage)})`},role:`presentation`}),(0,c.jsxs)(`div`,{className:`px-6 sm:px-8 pt-7 pb-5 border-b bg-muted/20`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,c.jsx)(`img`,{src:e.branding.logo,alt:``,className:`h-8 mb-4`}),e.title&&(0,c.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 leading-relaxed`,children:e.description}),(0,c.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 mt-3`,"aria-hidden":`true`,children:O.requiredHint??`* Required field`})]}),(0,c.jsxs)(`div`,{className:`relative px-6 sm:px-8 py-6`,children:[f&&(0,c.jsx)(`div`,{role:`alert`,"aria-live":`assertive`,className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:f}),(0,c.jsx)(V,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:S,initialData:w,onSuccess:T,submitText:u?O.submitting??`Submitting...`:O.submit??`Submit`},dataSource:C}),b&&(0,c.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute left-[-10000px] top-auto h-px w-px overflow-hidden`,children:[(0,c.jsx)(`label`,{htmlFor:`${e.formId}-${b}`,children:`Do not fill this field`}),(0,c.jsx)(`input`,{ref:v,id:`${e.formId}-${b}`,type:`text`,name:b,tabIndex:-1,autoComplete:`off`,defaultValue:``})]}),e.consent&&(0,c.jsxs)(`div`,{className:`mt-4`,children:[(0,c.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-foreground cursor-pointer select-none`,children:[(0,c.jsx)(`input`,{type:`checkbox`,id:A,checked:m,onChange:e=>{h(e.target.checked),e.target.checked&&_(null)},"aria-required":k||void 0,"aria-invalid":g?`true`:void 0,"aria-describedby":g?`${A}-error`:void 0,className:`mt-0.5 h-4 w-4 rounded border-input accent-primary`}),(0,c.jsxs)(`span`,{className:`leading-relaxed`,children:[e.consent.label??O.consentLabelDefault??`I agree to the privacy policy.`,k&&(0,c.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive ml-0.5`,children:`*`}),e.consent.privacyUrl&&(0,c.jsxs)(c.Fragment,{children:[` `,(0,c.jsx)(`a`,{href:e.consent.privacyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`underline text-primary hover:opacity-80`,children:O.consentLink??`Privacy policy`})]})]})]}),g&&(0,c.jsx)(`p`,{id:`${A}-error`,role:`alert`,className:`mt-1.5 text-xs text-destructive`,children:g})]}),u&&(0,c.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,c.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":`true`}),(0,c.jsx)(`span`,{children:O.submitting??`Submitting…`})]})]}),(0,c.jsxs)(`div`,{className:`px-6 sm:px-8 py-4 border-t bg-muted/20 flex flex-col sm:flex-row items-center justify-between gap-2`,children:[(0,c.jsxs)(`p`,{className:`inline-flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,c.jsx)(s.Lock,{className:`h-3 w-3`,"aria-hidden":`true`}),(0,c.jsx)(`span`,{children:O.secureNotice??`Your information is transmitted securely and only used to respond to your request.`})]}),(0,c.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground/80`,children:[e.privacyPolicyUrl&&(0,c.jsxs)(`a`,{href:e.privacyPolicyUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 underline hover:text-foreground`,children:[(0,c.jsx)(s.ShieldCheck,{className:`h-3 w-3`,"aria-hidden":`true`}),O.consentLink??`Privacy policy`]}),(0,c.jsx)(`span`,{children:O.poweredBy??`Powered by ObjectStack`})]})]})]})})};function Y(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 X=({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,c.jsxs)(`div`,{className:`space-y-4 ${i||``}`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:n||`Form Analytics`}),(0,c.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,c.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Total Submissions`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.totalSubmissions.toLocaleString()})]})}),(0,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Fill Rate`}),(0,c.jsxs)(a.CardTitle,{className:`text-2xl`,children:[o,`%`]})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,c.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${o}%`}})})})]}),(0,c.jsx)(a.Card,{children:(0,c.jsxs)(a.CardHeader,{className:`pb-2`,children:[(0,c.jsx)(a.CardDescription,{children:`Avg. Completion Time`}),(0,c.jsx)(a.CardTitle,{className:`text-2xl`,children:r.avgCompletionTime?Y(r.avgCompletionTime):`—`})]})})]}),r.dailySubmissions&&r.dailySubmissions.length>0&&(0,c.jsxs)(a.Card,{children:[(0,c.jsx)(a.CardHeader,{children:(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:r.dailySubmissions.map((e,t)=>(0,c.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,c.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,c.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,c.jsxs)(a.Card,{children:[(0,c.jsxs)(a.CardHeader,{children:[(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,c.jsx)(a.CardDescription,{children:`Percentage of users who completed each field`})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)(`div`,{className:`space-y-3`,children:r.fieldDropOff.map((e,t)=>(0,c.jsxs)(`div`,{className:`space-y-1`,children:[(0,c.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,c.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,c.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,c.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,c.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))})})]})]})},Z=({schema:e})=>(0,c.jsx)(V,{schema:e});n.ComponentRegistry.register(`object-form`,Z,{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`,Z,{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,c.jsx)(J,{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,c.jsx)(X,{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=L,e.EmbeddableForm=J,e.FormAnalytics=X,e.FormSection=g,e.ModalForm=B,e.ObjectForm=V,e.SplitForm=y,e.TabbedForm=_,e.WizardForm=v,e.applyAutoColSpan=E,e.applyAutoLayout=M,e.filterAutoGeneratedFields=A,e.filterCreateModeFields=k,e.filterSystemFields=O,e.inferColumns=T,e.inferModalSize=j,e.isAutoGeneratedFieldType=w,e.isWideFieldType=C});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/plugin-form",
3
- "version": "6.0.3",
3
+ "version": "6.1.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Form plugin for Object UI",
@@ -16,12 +16,12 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "lucide-react": "^1.16.0",
19
- "@object-ui/components": "6.0.3",
20
- "@object-ui/core": "6.0.3",
21
- "@object-ui/fields": "6.0.3",
22
- "@object-ui/permissions": "6.0.3",
23
- "@object-ui/react": "6.0.3",
24
- "@object-ui/types": "6.0.3"
19
+ "@object-ui/components": "6.1.0",
20
+ "@object-ui/core": "6.1.0",
21
+ "@object-ui/fields": "6.1.0",
22
+ "@object-ui/permissions": "6.1.0",
23
+ "@object-ui/react": "6.1.0",
24
+ "@object-ui/types": "6.1.0"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^18.0.0 || ^19.0.0",
@@ -31,9 +31,9 @@
31
31
  "@vitejs/plugin-react": "^6.0.2",
32
32
  "msw": "^2.14.6",
33
33
  "typescript": "^6.0.3",
34
- "vite": "^8.0.13",
35
- "vite-plugin-dts": "^5.0.0",
36
- "@object-ui/data-objectstack": "6.0.3"
34
+ "vite": "^8.0.14",
35
+ "vite-plugin-dts": "^5.0.1",
36
+ "@object-ui/data-objectstack": "6.1.0"
37
37
  },
38
38
  "keywords": [
39
39
  "objectui",