@object-ui/plugin-form 6.2.2 → 7.0.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 +323 -0
- package/dist/{packages/plugin-form/src/DrawerForm.d.ts → DrawerForm.d.ts} +14 -1
- package/dist/{packages/plugin-form/src/EmbeddableForm.d.ts → EmbeddableForm.d.ts} +1 -1
- package/dist/LineItemsPanel.d.ts +20 -0
- package/dist/MasterDetailForm.d.ts +67 -0
- package/dist/{packages/plugin-form/src/ModalForm.d.ts → ModalForm.d.ts} +17 -1
- package/dist/{packages/plugin-form/src/ObjectForm.d.ts → ObjectForm.d.ts} +1 -1
- package/dist/{packages/plugin-form/src/SplitForm.d.ts → SplitForm.d.ts} +1 -1
- package/dist/{packages/plugin-form/src/TabbedForm.d.ts → TabbedForm.d.ts} +1 -1
- package/dist/{packages/plugin-form/src/WizardForm.d.ts → WizardForm.d.ts} +13 -1
- package/dist/{packages/plugin-form/src/autoLayout.d.ts → autoLayout.d.ts} +1 -1
- package/dist/deriveMasterDetail.d.ts +86 -0
- package/dist/fieldGroups.d.ts +27 -0
- package/dist/index.d.ts +26 -2
- package/dist/index.js +1964 -875
- package/dist/index.umd.cjs +1 -1
- package/dist/masterDetailTx.d.ts +80 -0
- package/dist/sectionFields.d.ts +22 -0
- package/dist/successBehavior.d.ts +21 -0
- package/package.json +11 -11
- package/dist/packages/plugin-form/src/index.d.ts +0 -20
- /package/dist/{packages/plugin-form/src/FormAnalytics.d.ts → FormAnalytics.d.ts} +0 -0
- /package/dist/{packages/plugin-form/src/FormSection.d.ts → FormSection.d.ts} +0 -0
- /package/dist/{packages/plugin-form/src/sanitize.d.ts → sanitize.d.ts} +0 -0
package/dist/index.umd.cjs
CHANGED
|
@@ -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);function g(e){try{return typeof window>`u`?!1:new URL(e,window.location.href).origin===window.location.origin}catch{return!1}}function _(e,t){if(!e)return null;let n=t?.id??t?.recordId??t?._id;if(n==null||n===``)return null;let r=e.replace(/\{(?:id|recordId)\}/g,String(n));return g(r)?r:null}var v=({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]})};function y(e,t){return typeof t==`string`&&t.trim()?{...e,visible:e=>(0,i.evaluateCondition)(t,e)}:e}function b(e,t){let n=t.objectSchema?.fields?.[e];return n?{name:e,label:t.fieldLabel(t.objectName,e,n.label||e),type:(0,i.mapFieldTypeToFormType)(n.type),required:n.required||!1,disabled:t.readOnly||t.mode===`view`||n.readonly,placeholder:n.placeholder,description:n.help||n.description,validation:(0,i.buildValidationRules)(n),field:n,options:n.options,multiple:n.multiple}:{name:e,label:e,type:`input`}}function x(e,t){if(typeof e==`string`){let n=t.objectSchema?.fields?.[e];return y(b(e,t),n?.visible_on??n?.visibleOn)}let n=e;if(typeof n.field!=`string`)return y(n,n.visibleOn);let r=n.field,a=b(r,t);return n.type!=null&&(a.type=(0,i.mapFieldTypeToFormType)(n.type)),n.widget!=null&&(a.widget=n.widget),n.label!=null&&(a.label=n.label),n.placeholder!=null&&(a.placeholder=n.placeholder),n.helpText!=null&&(a.description=n.helpText),n.required!=null&&(a.required=n.required),n.readonly!=null&&(a.disabled=n.readonly||a.disabled),n.immutable!=null&&(a.immutable=n.immutable),n.hidden!=null&&(a.hidden=n.hidden),n.colSpan!=null&&(a.colSpan=n.colSpan),n.options!=null&&(a.options=n.options),n.multiple!=null&&(a.multiple=n.multiple),n.reference!=null&&(a.reference=n.reference),n.maxLength!=null&&(a.maxLength=n.maxLength),n.minLength!=null&&(a.minLength=n.minLength),n.min!=null&&(a.min=n.min),n.max!=null&&(a.max=n.max),n.precision!=null&&(a.precision=n.precision),n.scale!=null&&(a.scale=n.scale),n.language!=null&&(a.language=n.language),Array.isArray(n.fields)&&(a.fields=n.fields),y(a,n.visibleOn)}function S(e,t){return(e.fields??[]).map(e=>x(e,t))}var C=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),[s,l]=(0,t.useState)(null),[u,d]=(0,t.useState)({}),[f,p]=(0,t.useState)(!0),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);t.default.useEffect(()=>{(async()=>{if(!n){p(!1);return}try{l(await n.getObjectSchema(e.objectName))}catch(e){h(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(s||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){d(e.initialData||e.initialValues||{}),p(!1);return}try{d(await n.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{p(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let y=(0,t.useCallback)(t=>S(t,{objectSchema:s,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:o}),[s,e.readOnly,e.mode,e.objectName,o]),b=(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]),x=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),C=(e,t)=>e.name||e.label||`tab-${t}`;if(m)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:m.message})]});if(f)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=>y(e)),layout:`vertical`,defaultValues:u,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:b,onCancel:x},T=e.tabPosition===`left`||e.tabPosition===`right`;return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,i,e.className),children:(0,c.jsxs)(a.Tabs,{value:g,onValueChange:_,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)(v,{description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...w,fields:y(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},C(t,n)))})]})})},w=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),[l,u]=(0,t.useState)(null),[d,f]=(0,t.useState)({}),[p,m]=(0,t.useState)(!0),[h,g]=(0,t.useState)(null),[y,b]=(0,t.useState)(0),[x,C]=(0,t.useState)(new Set),[w,T]=(0,t.useState)(!1),E=t.default.useId(),[D,O]=(0,t.useState)(0),k=t.default.useRef(!1),A=e.sections.length,j=y===0,M=y===A-1;t.default.useEffect(()=>{(async()=>{if(!n){m(!1);return}try{u(await n.getObjectSchema(e.objectName))}catch(e){g(e)}})()},[e.objectName,n]),t.default.useEffect(()=>{(l||!n)&&(async()=>{if(e.mode===`create`||!e.recordId||!n){k.current||=(f(e.initialData||e.initialValues||{}),!0),m(!1);return}try{f(await n.findOne(e.objectName,e.recordId)||{})}catch(e){g(e)}finally{m(!1)}})()},[l,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let N=(0,t.useCallback)(t=>S(t,{objectSchema:l,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:o}),[l,e.readOnly,e.mode,e.objectName,o]),P=(0,t.useMemo)(()=>y>=0&&y<A?N(e.sections[y]):[],[y,A,e.sections,N]),F=(0,t.useCallback)(async t=>{let r={...d,...t};if(f(r),C(e=>new Set(e).add(y)),M){T(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(r),r;let t;if(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);else{let n=_(e.navigateOnSuccess,t);if(n)return window.location.assign(n),t;a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`)),e.resetOnSuccess&&e.mode===`create`&&(f({}),C(new Set),b(0),O(e=>e+1))}return t}catch(t){throw e.onError&&e.onError(t),t}finally{T(!1)}}else I(y+1)},[d,y,M,e,n]),I=(0,t.useCallback)(t=>{t>=0&&t<A&&(b(t),e.onStepChange&&e.onStepChange(t))},[A,e]),L=(0,t.useCallback)(()=>{I(y-1)},[y,I]),R=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),z=(0,t.useCallback)(t=>{(e.allowSkip||x.has(t)||t<=y)&&I(t)},[e.allowSkip,x,y,I]);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 B=e.sections[y];return(0,c.jsxs)(`div`,{className:(0,a.cn)(`w-full`,i,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!==A-1&&`pr-8 sm:pr-12`),children:[n!==A-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:()=>z(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:B&&(0,c.jsx)(v,{label:B.label,description:B.description,columns:B.columns||1,children:P.length>0?(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,id:E,fields:P,layout:`vertical`,defaultValues:d,showSubmit:!1,showCancel:!1,onSubmit:F}},D):(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:R,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 `,A]}),!j&&(0,c.jsxs)(a.Button,{variant:`outline`,onClick:L,children:[(0,c.jsx)(s.ChevronLeft,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),M?(0,c.jsxs)(a.Button,{type:`submit`,form:E,disabled:w||e.mode===`view`,children:[w&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":!0}),w?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)]}):(0,c.jsxs)(a.Button,{type:`submit`,form:E,children:[e.nextText||`Next`,(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 ml-1`})]})]})]})]})},T=({schema:e,dataSource:n,className:i})=>{let{fieldLabel:o}=(0,r.useSafeFieldLabel)(),[s,l]=(0,t.useState)(null),[u,d]=(0,t.useState)({}),[f,p]=(0,t.useState)(!0),[m,h]=(0,t.useState)(null);(0,t.useEffect)(()=>{(async()=>{if(!n){p(!1);return}try{l(await n.getObjectSchema(e.objectName))}catch(e){h(e),p(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(s||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){d(e.initialData||e.initialValues||{}),p(!1);return}if(!n){d(e.initialData||e.initialValues||{}),p(!1);return}try{d(await n.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{p(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let g=(0,t.useCallback)(t=>S(t,{objectSchema:s,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:o}),[s,e.readOnly,e.mode,e.objectName,o]),_=(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]),y=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),b=(0,t.useMemo)(()=>e.sections.slice(0,1),[e.sections]),x=(0,t.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,t.useMemo)(()=>e.sections.flatMap(e=>g(e)),[e.sections,g]);let C=e.splitDirection||`horizontal`,w=e.splitSize||50;if(m)return(0,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:m.message})]});if(f)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`,objectName:e.objectName,layout:`vertical`,defaultValues:u,onSubmit:_,onCancel:y},E=(t,n)=>(0,c.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,c.jsx)(v,{label:t.label,description:t.description,columns:t.columns||1,children:(0,c.jsx)(r.SchemaRenderer,{schema:{...T,fields:g(t),showSubmit:n&&e.showSubmit!==!1&&e.mode!==`view`,showCancel:n&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText}})},t.name||t.label||i))});return(0,c.jsx)(`div`,{className:(0,a.cn)(`w-full`,i,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(b,x.length===0)}),x.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(x,!0)})]})]})})},E=e=>e==null?void 0:e.id??e._id??e.recordId,D=new Set([`id`,`_id`,`recordId`]);function O(e,t){return e?Object.entries(e).every(([e,n])=>e===t||D.has(e)?!0:n==null||n===``):!0}function k(e,t,n){let r=[{object:e,action:`create`,data:t}];for(let e of n)for(let t of e.rows)O(t,e.relationshipField)||r.push({object:e.childObject,action:`create`,data:{...t,[e.relationshipField]:{$ref:0}}});return r}function A(e,t,n,r){let i=[{object:e,action:`update`,id:t,data:n}];for(let e of r){let n=(e.rows||[]).map(n=>({...n,[e.relationshipField]:t})),{toCreate:r,toUpdate:a,toDelete:o}=j(e.original||[],n);for(let t of r){if(O(t,e.relationshipField))continue;let{id:n,_id:r,recordId:a,...o}=t;i.push({object:e.childObject,action:`create`,data:o})}for(let t of a)i.push({object:e.childObject,action:`update`,id:E(t),data:t});for(let t of o)i.push({object:e.childObject,action:`delete`,id:t})}return i}function j(e,t){let n=new Set(t.map(E).filter(Boolean));return{toCreate:t.filter(e=>!E(e)),toUpdate:t.filter(e=>E(e)),toDelete:(e||[]).map(E).filter(e=>!!e&&!n.has(e))}}function M(e,t){return Array.isArray(e)?e.reduce((e,n)=>{let r=Number(n?.[t]);return e+(Number.isFinite(r)?r:0)},0):0}function N(e){return Array.isArray(e)?e:e&&Array.isArray(e.records)?e.records:e&&Array.isArray(e.data)?e.data:e&&(e.id||e._id)?[e]:[]}async function P(e,t,n){return n.length===0?[]:typeof e.bulk==`function`?N(await e.bulk(t,`create`,n)):N(await Promise.all(n.map(n=>e.create(t,n))))}async function F(e,t,n,r){let i=[],a=r.rows.filter(e=>E(e)||!O(e,r.relationshipField)).map(e=>({...e,[r.relationshipField]:n}));if(r.original!==void 0){let{toCreate:t,toUpdate:n,toDelete:o}=j(r.original,a),s=await P(e,r.childObject,t);for(let e of s){let t=E(e);t&&i.push({object:r.childObject,id:t})}await Promise.all(n.map(t=>e.update(r.childObject,E(t),t))),await Promise.all(o.map(t=>e.delete(r.childObject,t)))}else{let t=await P(e,r.childObject,a);for(let e of t){let t=E(e);t&&i.push({object:r.childObject,id:t})}}if(r.totalField){let i=M(r.rows,r.amountField||`amount`);await e.update(t,n,{[r.totalField]:i})}return{created:i}}var I=new Set([`id`,`_id`,`recordId`,`created_at`,`updated_at`,`created_by`,`updated_by`,`createdAt`,`updatedAt`,`createdBy`,`updatedBy`,`organization_id`,`tenant_id`,`space`,`owner`]),L=new Set([`position`,`sort_order`,`sequence`,`line_no`,`line_number`,`sort`]),R=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`,`file`,`image`,`avatar`,`json`,`object`,`grid`,`table`,`location`,`vector`,`html`,`markdown`,`richtext`]);function z(e){switch(e){case`number`:case`percent`:case`rating`:case`slider`:return`number`;case`currency`:return`currency`;case`date`:case`datetime`:case`time`:return`date`;case`select`:case`picklist`:case`radio`:case`boolean`:case`toggle`:return`select`;case`lookup`:case`master_detail`:return`lookup`;default:return`text`}}function B(e){if(e?.type===`boolean`||e?.type===`toggle`)return[{label:`Yes`,value:`true`},{label:`No`,value:`false`}];let t=e?.options;if(Array.isArray(t))return t.map(e=>typeof e==`object`&&e?{label:String(e.label??e.value),value:String(e.value)}:{label:String(e),value:String(e)})}function V(e,t){let n=e?.fields;if(!n||typeof n!=`object`)return;let r;for(let[e,i]of Object.entries(n)){let n=i;if(n?.reference===t){if(n?.type===`master_detail`)return e;n?.type===`lookup`&&!r&&(r=e)}}return r}var H=[`name`,`title`,`subject`,`label`,`full_name`,`display_name`,`code`],U={select:0,currency:1,number:1,lookup:2,date:3,text:4};function ee(e,t){if(t<=0||e.length<=t)return e;let n=new Set,r=e.find(e=>H.includes(e.field))??e[0];r&&n.add(r.field);for(let t of e)t.required&&n.add(t.field);let i=e.map((e,t)=>({c:e,i:t})).filter(({c:e})=>!n.has(e.field)).sort((e,t)=>(U[e.c.type]??5)-(U[t.c.type]??5)||e.i-t.i);for(let{c:e}of i){if(n.size>=t)break;n.add(e.field)}return e.map(e=>n.has(e.field)?e:{...e,defaultHidden:!0})}function W(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;if(I.has(e)||r.has(e)||L.has(e)||n?.system||n?.readonly||n?.hidden||R.has(n?.type))continue;let a={field:e,label:n?.label||e,type:z(n?.type),required:!!n?.required},o=B(n);a.type===`select`&&o&&(a.options=o),a.type===`lookup`&&(a.reference=n?.reference,a.displayField=n?.display_field||n?.reference_field),n?.readonlyWhen&&(a.readonlyWhen=n.readonlyWhen),(n?.requiredWhen??n?.conditionalRequired)&&(a.requiredWhen=n.requiredWhen??n.conditionalRequired);let s=typeof n?.expression==`string`?n.expression:n?.expression?.source;s&&typeof s==`string`&&(a.computed=!0,a.expr=s,a.required=!1,typeof n?.scale==`number`&&(a.scale=n.scale)),i.push(a)}return ee(i,t.maxColumns??6)}var te=new Set([`formula`,`summary`,`rollup`,`autonumber`,`auto_number`]);function G(e,t={}){let n=e?.fields;if(!n||typeof n!=`object`)return[];let r=new Set([...t.exclude??[],...t.relationshipField?[t.relationshipField]:[]]),i=[];for(let[e,t]of Object.entries(n)){let n=t;I.has(e)||r.has(e)||L.has(e)||n?.system||n?.hidden||te.has(n?.type)||i.push(e)}return i}var ne=new Set([`textarea`,`richtext`,`html`,`markdown`,`rich-text`,`file`,`image`,`avatar`,`attachment`,`json`,`location`,`address`]);function re(e,t,n={}){if(t===`grid`||t===`form`)return t;let r=e?.fields??{},i=G(e,{relationshipField:n.relationshipField});return i.some(e=>ne.has(r[e]?.type))||i.length>8?`form`:`grid`}var ie=[`amount`,`total`,`subtotal`,`line_total`,`line_amount`,`net_amount`];function ae(e){let t=e.filter(e=>e.type===`number`||e.type===`currency`);if(t.length===0)return;let n=t.find(e=>e.computed);if(n)return n.field;let r=t.find(e=>ie.includes(e.field));if(r)return r.field;let i=[...t].reverse().find(e=>e.type===`currency`);return i?i.field:t[t.length-1].field}function oe(e,t,n,r={}){let i=r.relationshipField||V(t,n);if(!i)throw Error(`MasterDetailForm: could not find a lookup/master_detail field on "${e}" referencing "${n}". Set relationshipField explicitly.`);let a=r.columns?.length?r.columns:W(t,{relationshipField:i}),o=r.amountField||ae(a);return{childObject:e,relationshipField:i,columns:a,formFields:G(t,{relationshipField:i}),mode:re(t,r.inlineEdit??(t?.fields)?.[i]?.inlineEdit,{relationshipField:i}),amountField:o,sortField:Object.keys(t?.fields??{}).find(e=>L.has(e))}}function se(e){if(!e)return{};let t={};return e.querySelectorAll(`[name]`).forEach(e=>{let n=e.getAttribute(`name`);if(n){if(e.tagName===`INPUT`){let r=e;if(r.type===`checkbox`){t[n]=r.checked;return}if(r.type===`radio`){r.checked&&(t[n]=r.value);return}if(r.type===`number`||r.type===`range`){if(r.value===``){t[n]=null;return}let e=Number(r.value);t[n]=Number.isFinite(e)?e:r.value;return}t[n]=r.value;return}t[n]=e.value}}),t}var ce=({details:e,state:n,setRows:r,formHostRef:a,taxRateField:o,formKey:s,onRowExpand:l,onAddViaForm:u})=>{let[d,f]=(0,t.useState)({}),p=(0,t.useRef)(``);(0,t.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{let t=se(e),n;try{n=JSON.stringify(t)}catch{n=String(Math.random())}n!==p.current&&(p.current=n,f(t))};t();let n=()=>t();e.addEventListener(`input`,n),e.addEventListener(`change`,n);let r=[120,360,800].map(e=>setTimeout(t,e));return()=>{e.removeEventListener(`input`,n),e.removeEventListener(`change`,n),r.forEach(clearTimeout)}},[a,s,e.length]);let m=d[o],h=m===void 0?null:Number.isFinite(Number(m))?Number(m):0,g=e.reduce((e,t,r)=>e+M(n[r]?.rows??[],t.amountField||`amount`),0),_=h!==null&&e.some(e=>!!e.amountField),v=h??0,y=v/100*g,b=g+y,x=e=>`¥${e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return(0,c.jsxs)(c.Fragment,{children:[e.map((e,t)=>(0,c.jsxs)(`section`,{className:`space-y-2`,children:[(0,c.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:e.title||`Line Items`}),e.columns?.length?(0,c.jsx)(i.LineItemsField,{value:n[t]?.rows??[],onChange:e=>r(t,e),contextRecord:d,...e.inlineMode===`form`||(e.formFields?.length??0)>(e.columns?.length??0)?{onRowExpand:e=>l(t,e)}:{},displayMode:e.inlineMode===`form`?`list`:`grid`,...e.inlineMode===`form`?{onAdd:()=>u(t)}:{},field:{columns:e.columns,total_field:_?void 0:e.amountField||(e.totalField?`amount`:void 0),sort_field:e.sortField,min_rows:e.minRows,max_rows:e.maxRows,add_label:e.inlineMode===`form`?e.addLabel||`Add`:e.addLabel}}):(0,c.jsx)(`p`,{className:`py-4 text-sm text-muted-foreground`,children:`Loading columns…`})]},`${e.childObject}-${t}`)),_&&(0,c.jsx)(`div`,{className:`flex justify-end`,children:(0,c.jsxs)(`dl`,{className:`w-64 space-y-1.5 text-sm`,"data-testid":`md-totals`,children:[(0,c.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,c.jsx)(`dt`,{className:`text-muted-foreground`,children:`Subtotal`}),(0,c.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-subtotal`,children:x(g)})]}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,c.jsxs)(`dt`,{className:`text-muted-foreground`,children:[`Tax (`,v,`%)`]}),(0,c.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-tax`,children:x(y)})]}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border pt-1.5 text-base font-semibold`,children:[(0,c.jsx)(`dt`,{children:`Total`}),(0,c.jsx)(`dd`,{className:`tabular-nums`,"data-testid":`md-grand-total`,children:x(b)})]})]})})]})},K=({schema:e,dataSource:n,className:r})=>{let i=e.details||[],o=e.mode===`edit`&&!!e.recordId,s=i.some(e=>!e.relationshipField||!e.columns?.length),[l,u]=(0,t.useState)(s?null:i),d=l??i;(0,t.useEffect)(()=>{if(!s){u(i);return}if(!n||typeof n.getObjectSchema!=`function`)return;let t=!1;return(async()=>{let r=await Promise.all(i.map(async t=>{if(t.relationshipField&&t.columns?.length)return t;try{let r=await n.getObjectSchema(t.childObject),i=oe(t.childObject,r,e.objectName,{relationshipField:t.relationshipField,columns:t.columns,amountField:t.amountField});return{...t,relationshipField:i.relationshipField,columns:i.columns,formFields:t.formFields??i.formFields,inlineMode:t.inlineMode??i.mode,amountField:t.amountField??i.amountField,sortField:t.sortField??i.sortField}}catch{return t}}));t||u(r)})(),()=>{t=!0}},[n,e.objectName,e.details]);let[f,p]=(0,t.useState)(()=>i.map(()=>({rows:[],original:[]}))),m=(0,t.useRef)(f);m.current=f;let[h,g]=(0,t.useState)(0),[_,v]=(0,t.useState)(!1),y=(0,t.useRef)(!1),b=(0,t.useRef)(null),x=(0,t.useCallback)(()=>{y.current=!1,v(!1),b.current&&=(clearTimeout(b.current),null)},[]);(0,t.useEffect)(()=>{let t=!1;if(!(!o||!n))return(async()=>{let r=await Promise.all(d.map(async t=>{if(!t.relationshipField)return{rows:[],original:[]};try{let r=(await n.find(t.childObject,{$filter:{[t.relationshipField]:e.recordId},$top:500}))?.data??[];return{rows:r.map(e=>({...e})),original:r.map(e=>({...e}))}}catch{return{rows:[],original:[]}}}));t||p(r)})(),()=>{t=!0}},[o,n,e.recordId,l]);let S=(0,t.useCallback)((e,t)=>{p(n=>n.map((n,r)=>r===e?{...n,rows:t}:n))},[]),C=e.taxRateField||`tax_rate`,[w,T]=(0,t.useState)(null),D=w?f[w.detailIdx]?.rows?.[w.rowIdx]:void 0,O=w?d[w.detailIdx]:void 0,j=(0,t.useCallback)((e,t,n)=>{p(r=>r.map((r,i)=>i===e?{...r,rows:r.rows.map((e,r)=>r===t?{...e,...n}:e)}:r))},[]),N=(0,t.useCallback)(e=>{p(t=>{let n=t.map((t,n)=>n===e?{...t,rows:[...t.rows,{}]}:t);return T({detailIdx:e,rowIdx:n[e].rows.length-1,isNew:!0}),n})},[]),P=(0,t.useCallback)(()=>{T(e=>(e?.isNew&&p(t=>t.map((t,n)=>n===e.detailIdx?{...t,rows:t.rows.filter((t,n)=>n!==e.rowIdx)}:t)),null))},[]),I=(0,t.useCallback)(async t=>{x(),a.toast.success(o?e.title?`${e.title} saved`:`Saved`:`Created`),o||(p(d.map(()=>({rows:[],original:[]}))),g(e=>e+1)),await e.onSuccess?.(t)},[o,e.onSuccess,e.title,d.length,x]),L=(0,t.useCallback)(t=>{x(),a.toast.error(t?.message||`Save failed`),e.onError?.(t)},[e,x]),R=(0,t.useCallback)(async t=>{let r=[];for(let i=0;i<d.length;i++){let a=d[i],{rows:s,original:c}=m.current[i];if(!a.relationshipField)continue;let{created:l}=await F(n,e.objectName,t,{childObject:a.childObject,relationshipField:a.relationshipField,rows:s,original:o?c:void 0,amountField:a.amountField,totalField:a.totalField});r.push(...l)}return r},[d,o,n,e.objectName]),z=(0,t.useCallback)(async t=>{let r=E(t)??e.recordId;if(!r)throw Error(`MasterDetailForm: parent record has no id after save`);if(!n)throw Error(`MasterDetailForm: dataSource is required`);let i=[];try{i=await R(r)}catch(t){throw o||await Promise.allSettled([...i.map(e=>n.delete(e.object,e.id)),n.delete(e.objectName,r)]),t}await I(t)},[n,o,R,e,I]),B=typeof n?.batchTransaction==`function`,V=(0,t.useCallback)(async t=>{let r=n,i={...t};d.forEach((e,t)=>{e.totalField&&(i[e.totalField]=M(m.current[t]?.rows??[],e.amountField||`amount`))});let a=o?A(e.objectName,e.recordId,i,d.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:m.current[t]?.rows??[],original:m.current[t]?.original??[]}))):k(e.objectName,i,d.filter(e=>e.relationshipField).map((e,t)=>({childObject:e.childObject,relationshipField:e.relationshipField,rows:m.current[t]?.rows??[]})));return(await r.batchTransaction(a))?.results?.[0]??{...i,id:e.recordId}},[n,d,e.objectName,e.recordId,o]),H=(0,t.useMemo)(()=>({type:`object-form`,objectName:e.objectName,mode:e.mode??`create`,recordId:e.recordId,initialValues:e.initialValues,initialData:e.initialData,formType:e.formType,sections:e.sections,fields:e.fields,title:e.title,showSubmit:!1,showCancel:!1,...B?{submitHandler:V,onSuccess:I}:{onSuccess:z},onError:L}),[e,z,B,V,I,L]),U=(0,t.useRef)(null),ee=e.submitText??(o?`Save`:`Create`),W=(0,t.useCallback)(()=>{y.current||U.current?.querySelector(`form`)&&(y.current=!0,v(!0),setTimeout(()=>{(U.current?.querySelector(`form`))?.requestSubmit()},0),b.current=setTimeout(()=>x(),1500))},[x]);return(0,t.useEffect)(()=>()=>{b.current&&clearTimeout(b.current)},[]),(0,c.jsxs)(`div`,{className:(0,a.cn)(`space-y-6`,r,e.className),children:[(0,c.jsx)(`div`,{ref:U,children:(0,c.jsx)($,{schema:H,dataSource:n},h)}),(0,c.jsx)(ce,{details:d,state:f,setRows:S,formHostRef:U,taxRateField:C,formKey:h,onRowExpand:(e,t)=>T({detailIdx:e,rowIdx:t}),onAddViaForm:N}),w&&O&&(0,c.jsxs)(a.Card,{className:`border-primary/40 shadow-none ring-1 ring-primary/10`,"data-testid":`md-row-form`,children:[(0,c.jsxs)(a.CardHeader,{className:`pb-2 flex flex-row items-center justify-between gap-2 space-y-0`,children:[(0,c.jsxs)(a.CardTitle,{className:`text-sm font-medium`,children:[O.title||`Line item`,` — row `,w.rowIdx+1]}),(0,c.jsx)(a.Button,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs text-muted-foreground`,onClick:P,children:`Close`})]}),(0,c.jsx)(a.CardContent,{children:(0,c.jsx)($,{schema:{type:`object-form`,objectName:O.childObject,mode:`edit`,initialData:D??{},...O.formFields?.length?{fields:O.formFields}:{},submitText:`Apply`,submitHandler:async e=>e,onSuccess:e=>{j(w.detailIdx,w.rowIdx,e),T(null)},onCancel:P},dataSource:n},`row-${w.detailIdx}-${w.rowIdx}`)})]}),(0,c.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-border pt-4`,children:[e.onCancel&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:e.onCancel,disabled:_,"data-testid":`md-form-cancel`,children:`Cancel`}),(0,c.jsx)(a.Button,{type:`button`,onClick:W,disabled:_||s&&!l,"data-testid":`md-form-submit`,children:_?`Saving…`:ee})]})]})},le=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`]),ue=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),de=new Set([`formula`,`summary`,`auto_number`,`autonumber`]);function fe(e){return ue.has(e)}function q(e){return de.has(e)}function pe(e){return e<=3?1:2}function J(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&fe(e.type)?{...e,colSpan:t}:e)}var me=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 he(e,t){return e.filter(e=>{if(me.has(e.name))return!1;let n=t?.fields?.[e.name];return!(n?.hidden===!0||n?.readonly===!0)})}function ge(e,t){return e.filter(e=>{if(me.has(e.name)||e.type&&le.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!q(n.type):!0})}function _e(e,t){return e.filter(e=>{if(e.type&&le.has(e.type))return!1;let n=t?.fields?.[e.name];return n?!q(n.type):!0})}function Y(e){return e<=1?`default`:e===2?`xl`:`full`}function X(e,t,n,r){let i=[...e];if(i=he(i,t),r===`create`&&(i=_e(i,t)),n!==void 0)return i=J(i,n),{fields:i,columns:n};let a=pe(i.length);return i=J(i,a),{fields:i,columns:a}}var ve=new Set([`id`,`_id`,`created_at`,`updated_at`,`createdAt`,`updatedAt`,`organization_id`,`organizationId`]),ye=new Set([`formula`,`rollup`,`lookup_value`,`auto_number`,`autonumber`,`computed`]);function be(e,t){if(!e||typeof e!=`object`)return e;let n={},r=t?.fields;for(let[t,i]of Object.entries(e))if(!ve.has(t)){if(r){let e=r[t];if(!e)continue;let n=String(e.type||``).toLowerCase();if(ye.has(n)||e.computed===!0||e.formula||e.readOnly===!0||e.readonly===!0)continue}n[t]=i}return n}var xe={1:void 0,2:`grid gap-4 grid-cols-1 @md:grid-cols-2`,3:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid gap-4 grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3 @4xl:grid-cols-4`},Se=({schema:e,dataSource:n,className:o})=>{let{fieldLabel:s}=(0,r.useSafeFieldLabel)(),l=(0,r.usePreviewMode)(),[u,d]=(0,t.useState)(null),[f,p]=(0,t.useState)([]),[m,h]=(0,t.useState)({}),[g,_]=(0,t.useState)(!0),[v,y]=(0,t.useState)(null),b=e.open!==!1,x=e.drawerSide||`right`,[C,w]=(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){_(!1);return}try{d(await n.getObjectSchema(e.objectName))}catch(e){y(e),_(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(u||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){h(e.initialData||e.initialValues||{}),_(!1);return}if(!n){h(e.initialData||e.initialValues||{}),_(!1);return}try{h(await n.findOne(e.objectName,e.recordId)||{})}catch(e){y(e)}finally{_(!1)}})()},[u,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let T=(0,t.useCallback)(t=>S(t,{objectSchema:u,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:s}),[u,e.readOnly,e.mode,e.objectName,s]);(0,t.useEffect)(()=>{if(!u&&n)return;if(e.customFields?.length){p(e.customFields),_(!1);return}if(e.sections?.length){_(!1);return}if(!u)return;let t=e.fields||Object.keys(u.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=u.fields?.[t];a&&r.push({name:t,label: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})}p(r),_(!1)},[u,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let E=(0,t.useCallback)(async t=>{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;try{let r,i=be(t,u);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,u]),D=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),O=(0,t.useMemo)(()=>{if(e.drawerWidth)return x===`left`||x===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,x]),k=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,A={type:`form`,objectName:e.objectName,layout:k,defaultValues:m,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:E,onCancel:D},j=()=>{if(v)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:v.message})]});if(g)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=C[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?()=>w(e=>({...e,[r]:!i})):void 0});let a=T(e);i?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,c.jsx)(r.SchemaRenderer,{schema:{...A,fields:t}})}let t=X(f,u,e.columns,e.mode),n=xe[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...A,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},M=e.subforms,N=M?.length&&e.mode!==`view`?(0,c.jsx)(K,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:e.submitText,details:M,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n}):j();return l?(0,c.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,c.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,c.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),N]}):(0,c.jsx)(a.Sheet,{open:b,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.SheetContent,{side:x,className:(0,a.cn)(`overflow-y-auto`,o,e.className),style:O,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)(a.SheetDescription,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,c.jsx)(`div`,{className:`@container py-4`,children:N})]})})},Z={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`},Q={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`},Ce=({schema:e,dataSource:n,className:l})=>{let{fieldLabel:u}=(0,r.useSafeFieldLabel)(),d=(0,r.usePreviewMode)(),f=(0,o.usePermissions)(),p=(0,t.useCallback)(t=>{if(!f?.isLoaded)return t;let n=[];for(let r of t){if(!r?.name){n.push(r);continue}f.checkField(e.objectName,r.name,`read`)&&(!f.checkField(e.objectName,r.name,`write`)&&e.mode!==`view`?n.push({...r,readOnly:!0,disabled:!0}):n.push(r))}return n},[f,e.objectName,e.mode]),[m,h]=(0,t.useState)(null),[g,_]=(0,t.useState)([]),[y,b]=(0,t.useState)({}),[x,C]=(0,t.useState)(!0),[w,T]=(0,t.useState)(null),[E,D]=(0,t.useState)(!1),O=e.open!==!1,k=(0,t.useId)(),A=(0,t.useMemo)(()=>e.sections?.length||e.customFields?.length?null:X(g,m,e.columns,e.mode),[g,m,e.columns,e.mode,e.sections,e.customFields]),j=Z[(0,t.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(A?.columns&&A.columns>1)return Y(A.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return Y(t)}return`default`},[e.modalSize,A,e.sections])]||Z.default;(0,t.useEffect)(()=>{(async()=>{if(!n){C(!1);return}try{h(await n.getObjectSchema(e.objectName))}catch(e){T(e),C(!1)}})()},[e.objectName,n]),(0,t.useEffect)(()=>{(m||!n)&&(async()=>{if(e.mode===`create`||!e.recordId){b(e.initialData||e.initialValues||{}),C(!1);return}if(!n){b(e.initialData||e.initialValues||{}),C(!1);return}try{b(await n.findOne(e.objectName,e.recordId)||{})}catch(e){T(e)}finally{C(!1)}})()},[m,e.mode,e.recordId,e.initialData,e.initialValues,n,e.objectName]);let M=(0,t.useCallback)(t=>S(t,{objectSchema:m,objectName:e.objectName,readOnly:e.readOnly,mode:e.mode,fieldLabel:u}),[m,e.readOnly,e.mode,e.objectName,u]);(0,t.useEffect)(()=>{if(!m&&n)return;if(e.customFields?.length){_(e.customFields),C(!1);return}if(e.sections?.length){C(!1);return}if(!m)return;let t=e.fields||Object.keys(m.fields||{}),r=[];for(let n of t){let t=typeof n==`string`?n:n.name;if(!t)continue;let a=m.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),C(!1)},[m,e.fields,e.customFields,e.sections,e.readOnly,e.mode,n]);let N=(0,t.useCallback)(async t=>{D(!0);try{if(!n)return e.onSuccess&&await e.onSuccess(t),e.onOpenChange?.(!1),t;let r,i=be(t,m);if(f?.isLoaded){let t={};for(let n of Object.keys(i))f.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{D(!1)}},[e,n,m,f]),P=(0,t.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),F=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,I=e.showSubmit!==!1&&e.mode!==`view`,L=e.showCancel!==!1,R=e.submitText||(e.mode===`create`?`Create`:`Update`),z=e.cancelText||`Cancel`,B={type:`form`,objectName:e.objectName,layout:F,defaultValues:y,submitLabel:R,cancelLabel:z,showSubmit:I,showCancel:L,onSubmit:N,onCancel:P,showActions:!1,id:k},V=()=>{if(w)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:w.message})]});if(x)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){let t=e.sections,n=(e,t)=>e.name||e.label||String(t),i=e=>(0,c.jsx)(r.SchemaRenderer,{schema:{...B,fields:p(M(e))}});return e.contentLayout===`tabbed`&&t.length>1?(0,c.jsxs)(a.Tabs,{defaultValue:n(t[0],0),className:`w-full`,children:[(0,c.jsx)(a.TabsList,{className:`mb-4`,children:t.map((e,t)=>(0,c.jsx)(a.TabsTrigger,{value:n(e,t),children:e.label||`Section ${t+1}`},n(e,t)))}),t.map((e,t)=>(0,c.jsx)(a.TabsContent,{value:n(e,t),children:(0,c.jsx)(v,{description:e.description,columns:e.columns||1,gridClassName:Q[e.columns||1],children:i(e)})},n(e,t)))]}):(0,c.jsx)(`div`,{className:`space-y-6`,children:t.map((e,t)=>(0,c.jsx)(v,{label:e.label,description:e.description,columns:e.columns||1,gridClassName:Q[e.columns||1],children:i(e)},n(e,t)))})}let t=A??X(g,m,e.columns,e.mode),n=Q[t.columns||1];return(0,c.jsx)(r.SchemaRenderer,{schema:{...B,fields:p(t.fields),columns:t.columns,...n?{fieldContainerClass:n}:{}}})},H=e.subforms;if(d)return(0,c.jsxs)(`div`,{className:`@container rounded-md border bg-card p-4`,children:[(e.title||e.description)&&(0,c.jsxs)(`div`,{className:`mb-3 space-y-0.5`,children:[e.title&&(0,c.jsx)(`div`,{className:`text-sm font-semibold`,children:e.title}),e.description&&(0,c.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description})]}),V()]});if(H?.length&&e.mode!==`view`)return(0,c.jsx)(a.Dialog,{open:O,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(j,`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)(a.DialogDescription,{className:`sr-only`,children:`Enter the record and its line items, then save.`})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:(0,c.jsx)(K,{schema:{type:`object-master-detail-form`,objectName:e.objectName,mode:e.mode===`edit`?`edit`:`create`,recordId:e.recordId,fields:e.fields,sections:e.sections,submitText:R,details:H,onSuccess:async t=>{await e.onSuccess?.(t),e.onOpenChange?.(!1)},onError:e.onError,onCancel:()=>e.onOpenChange?.(!1)},dataSource:n})})]})});let U=!x&&!w&&(I||L);return(0,c.jsx)(a.Dialog,{open:O,onOpenChange:e.onOpenChange,children:(0,c.jsxs)(a.MobileDialogContent,{className:(0,a.cn)(j,`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)(a.DialogDescription,{className:`sr-only`,children:`Complete the form fields, then submit or cancel.`})]}),(0,c.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:V()}),U&&(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:[L&&(0,c.jsx)(a.Button,{type:`button`,variant:`outline`,onClick:P,disabled:E,className:`w-full sm:w-auto`,children:z}),I&&(0,c.jsxs)(a.Button,{type:`submit`,form:k,disabled:E,className:`w-full sm:w-auto`,children:[E&&(0,c.jsx)(s.Loader2,{className:`mr-2 h-4 w-4 animate-spin`}),R]})]})})]})})};function we(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`).map(e=>({key:typeof e.key==`string`?e.key:``,label:typeof e.label==`string`?e.label:void 0,collapsible:typeof e.collapsible==`boolean`?e.collapsible:void 0,collapsed:typeof e.collapsed==`boolean`?e.collapsed:void 0})).filter(e=>e.key):[]}function Te(e,t){let n=we(t);if(n.length===0)return null;let r=new Set(n.map(e=>e.key)),i=e=>{let t=e.group;return typeof t==`string`&&r.has(t)?t:null};if(!e.some(e=>i(e)!==null))return null;let a=new Map;for(let e of n)a.set(e.key,[]);let o=[];for(let t of e){let e=i(t);e?a.get(e).push(t):o.push(t)}let s=[];for(let e of n){let t=a.get(e.key);t.length!==0&&s.push({name:e.key,label:e.label??e.key,fields:t.map(e=>e.name),...e.collapsible===void 0?{}:{collapsible:e.collapsible},...e.collapsed===void 0?{}:{collapsed:e.collapsed}})}return o.length>0&&s.push({fields:o.map(e=>e.name)}),s}var $=({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.subforms?.length&&a.mode!==`view`&&a.formType!==`drawer`&&a.formType!==`modal`)return(0,c.jsx)(K,{schema:{type:`object-master-detail-form`,objectName:a.objectName,mode:a.mode===`edit`?`edit`:`create`,recordId:a.recordId,initialValues:a.initialValues,initialData:a.initialData,formType:a.formType===`tabbed`?`tabbed`:`simple`,sections:a.sections,fields:a.fields,title:a.title,submitText:a.submitText,details:a.subforms,onSuccess:a.onSuccess,onError:a.onError,onCancel:a.onCancel,className:a.className},dataSource:n});if(a.formType===`tabbed`&&a.sections?.length)return(0,c.jsx)(C,{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)(w,{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)(T,{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)(Se,{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)(Ce,{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)(Ee,{schema:a,dataSource:n})},Ee=({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,g]=(0,t.useState)([]),[v,y]=(0,t.useState)(null),[b,x]=(0,t.useState)(!0),[S,C]=(0,t.useState)(null),T=e.customFields&&e.customFields.length>0;(0,t.useEffect)(()=>{T&&(y(e.initialData||e.initialValues||{}),x(!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){C(e),x(!1)}})():T||x(!1)},[e.objectName,n,T]),(0,t.useEffect)(()=>{p&&!T&&(async()=>{if(!e.recordId||e.mode===`create`){y(e.initialData||e.initialValues||{}),x(!1);return}if(!T){if(!n){C(Error(`DataSource is required for fetching record data (inline data not provided)`)),x(!1);return}x(!0);try{y(await n.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),C(e)}finally{x(!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){g(e.customFields.map(E)),x(!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),visibleWhen:a.visibleWhen,readonlyWhen:a.readonlyWhen,requiredWhen:a.requiredWhen??a.conditionalRequired,group:a.group,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)}}),g(t),!T&&e.recordId&&e.mode!==`create`&&n||x(!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.submitHandler)t=await e.submitHandler(i);else 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`);if(e.onSuccess)await e.onSuccess(t);else if(!e.submitHandler){let n=_(e.navigateOnSuccess,t);if(n)return window.location.assign(n),t;a.toast.success(e.successMessage||(e.mode===`create`?`Created`:`Saved`))}return 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]),...v},A=t.default.useMemo(()=>e.sections?.length?null:Te(h,p?.fieldGroups),[e.sections,h,p]),j=e.sections?.length?e.sections:A,[M,N]=(0,t.useState)({});if(S)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:S.message})]});if(b)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 P=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(j?.length&&(!e.formType||e.formType===`simple`)){let t=[];return j.forEach((n,r)=>{let i=n.fields.map(e=>typeof e==`string`?e:e.field??e.name),a=f(h.filter(e=>i.includes(e.name)));if(a.length===0)return;let o=n.name||n.label||String(r),s=n.name?l(e.objectName,n.name,n.label||n.name):n.label,c=M[o]??n.collapsed??!1;s&&t.push({name:`__section_${o}`,label:s,type:`section-divider`,colSpan:4,collapsible:n.collapsible,collapsed:c,onToggle:n.collapsible?()=>N(e=>({...e,[o]:!c})):void 0}),s&&c?t.push(...a.map(e=>({...e,hidden:!0}))):t.push(...a)}),(0,c.jsx)(`div`,{className:`w-full`,children:(0,c.jsx)(r.SchemaRenderer,{schema:{type:`form`,objectName:e.objectName,fields:t,layout:P,defaultValues:k,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,onSubmit:D,onCancel:O}})})}let F=e.sections?.length,I=f(h),L=F?{fields:I,columns:e.columns}:X(I,p,e.columns,e.mode),R=e.mobile,z=R?.fullscreenLongText?L.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}):L.fields,B=R?.stepper,V=R?.stepperMinFields??8,H=Math.max(1,R?.stepperFieldsPerStep??1);if(!e.formType&&!F&&z.length>=2&&(B===!0||B===`auto`&&u&&z.length>=V)){let t=z,r=[];for(let e=0;e<t.length;e+=H){let n=t.slice(e,e+H);r.push({name:`step-${Math.floor(e/H)+1}`,label:n[0]?.label||n[0]?.name||`Step ${Math.floor(e/H)+1}`,fields:n})}return(0,c.jsx)(w,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:n,className:e.className})}let U={type:`form`,objectName:e.objectName,fields:z,layout:P,columns:L.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||e.resetOnSuccess&&e.mode===`create`,defaultValues:k,onSubmit:D,onCancel:O,className:e.className,mobileStickyActions:!!R?.stickyActions};return(0,c.jsx)(`div`,{className:R?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":R?`true`:void 0,children:(0,c.jsx)(r.SchemaRenderer,{schema:U})})},De={text:200,email:254,url:2048,phone:32,textarea:5e3,markdown:5e3,html:5e3},Oe=`_company_website_2`,ke=1500;function Ae(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 je(e){return e&&e.map(e=>{let t=De[String(e.type||``).toLowerCase()];return!t||(e.maxLength??e.max_length)?e:{...e,maxLength:t}})}var Me=({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||Oe,x=e.minFillTime??ke,S=(0,t.useMemo)(()=>je(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(Ae(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)($,{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 Ne(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 Pe=({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?Ne(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))})})]})]})},Fe=({schema:e})=>{let n=(0,r.useSchemaContext)()?.dataSource,o;try{o=(0,r.useRecordContext)()}catch{o=void 0}let s=e.parentObject||o?.objectName,l=e.parentId||e.recordId||o?.recordId,[u,d]=(0,t.useState)([]),[f,p]=(0,t.useState)([]),[m,h]=(0,t.useState)(!0),[g,_]=(0,t.useState)(!1),[v,y]=(0,t.useState)(!1),[b,x]=(0,t.useState)(null),S=(0,t.useCallback)(async()=>{if(!n||!l){h(!1);return}h(!0);try{let t=(await n.find(e.childObject,{$filter:{[e.relationshipField]:l},$top:500}))?.data??[];d(t.map(e=>({...e}))),p(t.map(e=>({...e}))),y(!1)}catch(e){x(e?.message||`Failed to load line items`)}finally{h(!1)}},[n,l,e.childObject,e.relationshipField]);(0,t.useEffect)(()=>{S()},[S]);let C=(0,t.useCallback)(e=>{d(e),y(!0)},[]),w=(0,t.useCallback)(async()=>{if(!(!n||!l)){_(!0),x(null);try{await F(n,s||e.childObject,l,{childObject:e.childObject,relationshipField:e.relationshipField,rows:u,original:f,amountField:e.amountField,totalField:s?e.totalField:void 0}),await S()}catch(e){x(e?.message||`Failed to save line items`)}finally{_(!1)}}},[n,l,u,f,e,s,S]),T=(0,t.useMemo)(()=>({columns:e.columns,total_field:e.totalField?e.amountField||`amount`:void 0,min_rows:e.minRows,max_rows:e.maxRows,allow_add:!e.readonly,allow_delete:!e.readonly}),[e]);return(0,c.jsxs)(a.Card,{className:(0,a.cn)(`shadow-none`),children:[(0,c.jsxs)(a.CardHeader,{className:`flex-row items-center justify-between gap-2 pb-2`,children:[(0,c.jsx)(a.CardTitle,{className:`text-sm font-medium`,children:e.title||`Line Items`}),!e.readonly&&(0,c.jsx)(a.Button,{type:`button`,size:`sm`,onClick:w,disabled:g||m||!v||!l,children:g?`Saving…`:`Save`})]}),(0,c.jsxs)(a.CardContent,{children:[b&&(0,c.jsx)(`p`,{className:`mb-2 text-sm text-destructive`,children:b}),m?(0,c.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Loading…`}):l?(0,c.jsx)(i.LineItemsField,{value:u,onChange:C,field:T,readonly:e.readonly}):(0,c.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`Save the record first to add line items.`})]})]})},Ie=({schema:e})=>(0,c.jsx)($,{schema:e,dataSource:(0,t.useContext)(r.SchemaRendererContext)?.dataSource??void 0});n.ComponentRegistry.register(`object-form`,Ie,{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`,Ie,{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)(Me,{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)(Pe,{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`}]}),n.ComponentRegistry.register(`object-master-detail-form`,({schema:e})=>(0,c.jsx)(K,{schema:e,dataSource:(0,t.useContext)(r.SchemaRendererContext)?.dataSource??void 0}),{namespace:`plugin-form`,label:`Master-Detail Form`,category:`plugin`,inputs:[{name:`objectName`,type:`string`,label:`Parent Object`,required:!0},{name:`mode`,type:`enum`,label:`Mode`,enum:[`create`,`edit`]},{name:`sections`,type:`array`,label:`Parent Sections`},{name:`details`,type:`array`,label:`Detail Collections`,required:!0}]}),n.ComponentRegistry.register(`line_items`,({schema:e})=>(0,c.jsx)(Fe,{schema:e}),{namespace:`record`,skipFallback:!0,label:`Line Items`,category:`record`,inputs:[{name:`childObject`,type:`string`,label:`Child Object`,required:!0},{name:`relationshipField`,type:`string`,label:`Relationship Field`,required:!0},{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`totalField`,type:`string`,label:`Parent Total Field`},{name:`amountField`,type:`string`,label:`Amount Column`}]}),e.DrawerForm=Se,e.EmbeddableForm=Me,e.FormAnalytics=Pe,e.FormSection=v,e.LineItemsPanel=Fe,e.MasterDetailForm=K,e.ModalForm=Ce,e.ObjectForm=$,e.SplitForm=T,e.TabbedForm=C,e.WizardForm=w,e.applyAutoColSpan=J,e.applyAutoLayout=X,e.deriveColumns=W,e.deriveDetail=oe,e.deriveFormFields=G,e.filterAutoGeneratedFields=_e,e.filterCreateModeFields=ge,e.filterSystemFields=he,e.findRelationshipField=V,e.inferColumns=pe,e.inferModalSize=Y,e.isAutoGeneratedFieldType=q,e.isWideFieldType=fe,e.resolveInlineMode=re});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DataSource } from '@object-ui/types';
|
|
2
|
+
export declare const idOf: (rec: any) => string | undefined;
|
|
3
|
+
export interface RowDiff {
|
|
4
|
+
toCreate: Record<string, any>[];
|
|
5
|
+
toUpdate: Record<string, any>[];
|
|
6
|
+
toDelete: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Diff the current rows against a loaded snapshot. Rows without an id are
|
|
10
|
+
* creates; rows with an id are updates; snapshot ids no longer present are
|
|
11
|
+
* deletes.
|
|
12
|
+
*/
|
|
13
|
+
export interface BatchDetailInput {
|
|
14
|
+
childObject: string;
|
|
15
|
+
relationshipField: string;
|
|
16
|
+
rows: Record<string, any>[];
|
|
17
|
+
}
|
|
18
|
+
/** Edit-mode detail input: current rows + the loaded snapshot to diff against. */
|
|
19
|
+
export interface BatchEditDetailInput extends BatchDetailInput {
|
|
20
|
+
original: Record<string, any>[];
|
|
21
|
+
}
|
|
22
|
+
export interface BatchOp {
|
|
23
|
+
object: string;
|
|
24
|
+
action: 'create' | 'update' | 'delete';
|
|
25
|
+
/** Present for create/update. */
|
|
26
|
+
data?: Record<string, any>;
|
|
27
|
+
/** Present for update/delete. */
|
|
28
|
+
id?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A row that carries no user input — every field is blank once the back-
|
|
32
|
+
* reference FK and id keys are set aside. Computed cells (e.g. amount) read
|
|
33
|
+
* null while their inputs are blank, so they don't count as input. Used to
|
|
34
|
+
* drop the always-present trailing "ghost" line (and any row the user cleared)
|
|
35
|
+
* so it never persists as an empty child record.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isBlankRow(row: Record<string, any>, relationshipField?: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Build cross-object batch operations for an ATOMIC master-detail create:
|
|
40
|
+
* the parent at index 0, then each child with its relationship FK set to
|
|
41
|
+
* `{ $ref: 0 }` so the server resolves it to the parent's generated id inside
|
|
42
|
+
* one transaction (commit all or roll back all).
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildMasterDetailBatch(parentObject: string, parentData: Record<string, any>, details: BatchDetailInput[]): BatchOp[];
|
|
45
|
+
/**
|
|
46
|
+
* Build cross-object batch operations for an ATOMIC master-detail EDIT: update
|
|
47
|
+
* the existing parent (index 0), then per child collection diff the current
|
|
48
|
+
* rows against the loaded snapshot into create / update / delete ops. The
|
|
49
|
+
* parent id is already known, so children reference it directly (no `$ref`).
|
|
50
|
+
* The whole set commits or rolls back as one transaction.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildMasterDetailEditBatch(parentObject: string, parentId: string, parentData: Record<string, any>, details: BatchEditDetailInput[]): BatchOp[];
|
|
53
|
+
export declare function diffRows(original: Record<string, any>[], current: Record<string, any>[]): RowDiff;
|
|
54
|
+
/** Sum a numeric column across rows (blanks/NaN ignored). */
|
|
55
|
+
export declare function sumRows(rows: Record<string, any>[], field: string): number;
|
|
56
|
+
export interface ApplyDetailOptions {
|
|
57
|
+
childObject: string;
|
|
58
|
+
relationshipField: string;
|
|
59
|
+
rows: Record<string, any>[];
|
|
60
|
+
/** Loaded snapshot — when present we diff (edit mode); otherwise create-all. */
|
|
61
|
+
original?: Record<string, any>[];
|
|
62
|
+
/** Numeric child column to sum. */
|
|
63
|
+
amountField?: string;
|
|
64
|
+
/** Parent field to receive the rolled-up sum. */
|
|
65
|
+
totalField?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ApplyDetailResult {
|
|
68
|
+
/** Child object + id pairs created in this call (for cleanup on failure). */
|
|
69
|
+
created: Array<{
|
|
70
|
+
object: string;
|
|
71
|
+
id: string;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Persist one child collection for a known parent id. Sets the relationship FK
|
|
76
|
+
* on every row, then creates / updates / deletes, then (optionally) rolls the
|
|
77
|
+
* line total up onto the parent. Hooks can't do nested writes, so the rollup
|
|
78
|
+
* happens here on the client.
|
|
79
|
+
*/
|
|
80
|
+
export declare function applyDetail(dataSource: DataSource, parentObject: string, parentId: string, opts: ApplyDetailOptions): Promise<ApplyDetailResult>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormField } from '@object-ui/types';
|
|
2
|
+
export interface SectionFieldsContext {
|
|
3
|
+
/** Resolved object schema (`{ fields: { [name]: fieldDef } }`) or null. */
|
|
4
|
+
objectSchema: any;
|
|
5
|
+
/** Object name, for label translation. */
|
|
6
|
+
objectName: string;
|
|
7
|
+
/** Whole-form read-only flag. */
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
/** Form mode — `view` forces every field disabled. */
|
|
10
|
+
mode?: 'create' | 'edit' | 'view';
|
|
11
|
+
/** Translation-aware label resolver (from `useSafeFieldLabel`). */
|
|
12
|
+
fieldLabel: (objectName: string, fieldName: string, fallback?: string) => string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Normalize one section field definition (string | spec object | runtime
|
|
16
|
+
* FormField) into a runtime FormField with a guaranteed `name`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function normalizeSectionField(fieldDef: string | Record<string, any>, ctx: SectionFieldsContext): FormField;
|
|
19
|
+
/** Normalize every field def in a section. */
|
|
20
|
+
export declare function buildSectionFields(section: {
|
|
21
|
+
fields: Array<string | Record<string, any>>;
|
|
22
|
+
}, ctx: SectionFieldsContext): FormField[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* Declarative post-success behaviors shared by ObjectForm + WizardForm. A
|
|
6
|
+
* metadata-only form (authored as JSON) cannot pass an `onSuccess` function, so
|
|
7
|
+
* these let it declare what happens after a create/update: a custom toast
|
|
8
|
+
* (`successMessage`), navigate to the new record (`navigateOnSuccess`), or reset
|
|
9
|
+
* for another entry (`resetOnSuccess`).
|
|
10
|
+
*
|
|
11
|
+
* Kept dependency-free on purpose: importing the redirect guard from
|
|
12
|
+
* EmbeddableForm would create a cycle (EmbeddableForm → ObjectForm → WizardForm
|
|
13
|
+
* → here), so the same-origin check is inlined.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Resolve a `navigateOnSuccess` template into a safe URL: interpolate
|
|
17
|
+
* `{id}` / `{recordId}` from the created/updated record and same-origin-guard it.
|
|
18
|
+
* Returns null when there's no template, no usable id, or the URL fails the
|
|
19
|
+
* guard — callers then fall back to a toast.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveSuccessNavigate(template: string | undefined, record: any): string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Form plugin for Object UI",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"lucide-react": "^1.
|
|
19
|
-
"@object-ui/components": "
|
|
20
|
-
"@object-ui/core": "
|
|
21
|
-
"@object-ui/fields": "
|
|
22
|
-
"@object-ui/permissions": "
|
|
23
|
-
"@object-ui/react": "
|
|
24
|
-
"@object-ui/types": "
|
|
18
|
+
"lucide-react": "^1.21.0",
|
|
19
|
+
"@object-ui/components": "7.0.0",
|
|
20
|
+
"@object-ui/core": "7.0.0",
|
|
21
|
+
"@object-ui/fields": "7.0.0",
|
|
22
|
+
"@object-ui/permissions": "7.0.0",
|
|
23
|
+
"@object-ui/react": "7.0.0",
|
|
24
|
+
"@object-ui/types": "7.0.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.
|
|
35
|
-
"vite-plugin-dts": "^5.0.
|
|
36
|
-
"@object-ui/data-objectstack": "
|
|
34
|
+
"vite": "^8.0.16",
|
|
35
|
+
"vite-plugin-dts": "^5.0.2",
|
|
36
|
+
"@object-ui/data-objectstack": "7.0.0"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"objectui",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ObjectForm } from './ObjectForm';
|
|
2
|
-
export { ObjectForm };
|
|
3
|
-
export type { ObjectFormProps } from './ObjectForm';
|
|
4
|
-
export { FormSection } from './FormSection';
|
|
5
|
-
export type { FormSectionProps } from './FormSection';
|
|
6
|
-
export { applyAutoLayout, inferColumns, inferModalSize, isWideFieldType, isAutoGeneratedFieldType, applyAutoColSpan, filterCreateModeFields, filterSystemFields, filterAutoGeneratedFields, } from './autoLayout';
|
|
7
|
-
export { TabbedForm } from './TabbedForm';
|
|
8
|
-
export type { TabbedFormProps, TabbedFormSchema, FormSectionConfig } from './TabbedForm';
|
|
9
|
-
export { WizardForm } from './WizardForm';
|
|
10
|
-
export type { WizardFormProps, WizardFormSchema } from './WizardForm';
|
|
11
|
-
export { SplitForm } from './SplitForm';
|
|
12
|
-
export type { SplitFormProps, SplitFormSchema } from './SplitForm';
|
|
13
|
-
export { DrawerForm } from './DrawerForm';
|
|
14
|
-
export type { DrawerFormProps, DrawerFormSchema } from './DrawerForm';
|
|
15
|
-
export { ModalForm } from './ModalForm';
|
|
16
|
-
export type { ModalFormProps, ModalFormSchema } from './ModalForm';
|
|
17
|
-
export { EmbeddableForm } from './EmbeddableForm';
|
|
18
|
-
export type { EmbeddableFormProps, EmbeddableFormConfig, EmbeddableFormTexts } from './EmbeddableForm';
|
|
19
|
-
export { FormAnalytics } from './FormAnalytics';
|
|
20
|
-
export type { FormAnalyticsProps, FormSubmissionMetric } from './FormAnalytics';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|