@object-ui/console 4.0.1 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AppManagementPage-Da4DphqI.js → AppManagementPage-ynJLzxVY.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-C2rFxE3n.js +1 -0
- package/dist/assets/DashboardView-x75VLMQW.js +1 -0
- package/dist/assets/MetadataDetailPage-B9EzoQgu.js +1 -0
- package/dist/assets/{MetadataFormDialog-CSuCo9Qt.js → MetadataFormDialog-BebGlAr3.js} +1 -1
- package/dist/assets/{MetadataManagerPage-DJ2ZjoVP.js → MetadataManagerPage-B0xfI-4w.js} +1 -1
- package/dist/assets/{PageView-CJFNRux1.js → PageView-C2GS-SQP.js} +1 -1
- package/dist/assets/{ProfilePage-CK0mmAvw.js → ProfilePage-BO3TRbTV.js} +1 -1
- package/dist/assets/RecordDetailView-Clze41HE.js +1 -0
- package/dist/assets/RecordFormPage-B6mEBKMB.js +1 -0
- package/dist/assets/{ReportView-B6tHCvDV.js → ReportView-B16PsGer.js} +1 -1
- package/dist/assets/{SearchResultsPage-CDUPn8G4.js → SearchResultsPage-932jfRUX.js} +1 -1
- package/dist/assets/{SystemHubPage-CVOYNpyU.js → SystemHubPage-CqrYgpYf.js} +1 -1
- package/dist/assets/{data-adapter-DBWF2sV-.js → data-adapter-BwfAq_h0.js} +1 -1
- package/dist/assets/{getIcon-CWhoWdFA.js → getIcon-DF6zJOtU.js} +1 -1
- package/dist/assets/index-CPatxDwz.js +2 -0
- package/dist/assets/index-vbGrAsEJ.css +2 -0
- package/dist/assets/{plugin-calendar-DBrkXKZq.js → plugin-calendar-D1bCBBwe.js} +1 -1
- package/dist/assets/{plugin-charts-BHH2XtQC.js → plugin-charts-x_9Q2-i_.js} +1 -1
- package/dist/assets/{plugin-chatbot-Cdf-WJAv.js → plugin-chatbot-CgNZnFch.js} +6 -6
- package/dist/assets/{plugin-form-CKcMp4d_.js → plugin-form-DOfn-uRa.js} +1 -1
- package/dist/assets/{plugin-gantt-DwFZiNye.js → plugin-gantt-CHZ4HLjh.js} +1 -1
- package/dist/assets/{plugin-grid-CQS8zk9l.js → plugin-grid-Cn_T_wpz.js} +1 -1
- package/dist/assets/{plugin-kanban-CaM_pxR_.js → plugin-kanban-BsgjJQam.js} +1 -1
- package/dist/assets/{plugin-map-BFlwDcr7.js → plugin-map-DZdVR1tc.js} +1 -1
- package/dist/assets/{plugin-markdown-PR8tBwTD.js → plugin-markdown-BlHuacDq.js} +1 -1
- package/dist/assets/{plugin-timeline-B-vzj0Pe.js → plugin-timeline-OEB0nyvd.js} +1 -1
- package/dist/assets/{plugin-view-djqft75T.js → plugin-view-CJFsgQ9v.js} +1 -1
- package/dist/assets/{plugins-views-BDVYhbx4.js → plugins-views-DqZMtAOw.js} +1 -1
- package/dist/assets/{src-D1MGEpQM.js → src-D5NTzWsi.js} +1 -1
- package/dist/assets/{ui-components-3HVEceOY.js → ui-components-B7mlp0en.js} +1 -1
- package/dist/assets/{ui-layout-_xO4eFwD.js → ui-layout-jqAD528v.js} +1 -1
- package/dist/assets/utils-DMMB8Xfh.js +1 -0
- package/dist/assets/{vendor-charts-DHZsyaJw.js → vendor-charts-D0g2ZI3F.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +30 -30
- package/dist/assets/ConsoleFloatingChatbot-BWbRwcSc.js +0 -1
- package/dist/assets/DashboardView-l8ACItY-.js +0 -1
- package/dist/assets/MetadataDetailPage-D7yDeoSe.js +0 -1
- package/dist/assets/RecordDetailView-BfzfI4-e.js +0 -1
- package/dist/assets/index-BimUnPgZ.js +0 -2
- package/dist/assets/index-DoG5QbE6.css +0 -2
- /package/dist/assets/{maplibre-gl-ChgVR8ni.js → maplibre-gl-CKvz_wTN.js} +0 -0
- /package/dist/assets/{vendor-dndkit-BGB4qgc3.js → vendor-dndkit-BfOuYFuz.js} +0 -0
- /package/dist/assets/{vendor-icons-core-s9WPLoP3.js → vendor-icons-core-BA-_NHij.js} +0 -0
- /package/dist/assets/{vendor-markdown-D-LpQJes.js → vendor-markdown-Cdqza44B.js} +0 -0
- /package/dist/assets/{vendor-ui-utils-AywTz3cM.js → vendor-ui-utils-Dyl9EYZi.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{D as r,H as i}from"./framework-CoXA0nY6.js";import{f as a}from"./infrastructure-Djv3I7gr.js";import{$A as o,$n as s,Cy as c,Gn as l,Gt as u,Jn as d,Jt as f,Kt as p,PL as m,Un as h,Ut as g,Wt as _,Yt as v,ZA as y,_t as b,an as x,er as S,et as C,gt as w,ht as T,in as E,mt as D,n as O,nr as k,o as A,on as j,pj as M,qn as ee,qt as N,rj as P,rr as F,t as I,tr as L,u as R,yr as z}from"./ui-components-3HVEceOY.js";var B=e(t(),1),V=n(),H=({label:e,description:t,collapsible:n=!1,collapsed:r=!1,columns:i=1,children:a,className:o,gridClassName:s})=>{let[c,l]=(0,B.useState)(r);return(0,V.jsxs)(`div`,{className:m(`form-section`,o),children:[(e||t)&&(0,V.jsxs)(`div`,{className:m(`flex items-start gap-2 mb-4`,n&&`cursor-pointer select-none`),onClick:()=>{n&&l(!c)},role:n?`button`:void 0,"aria-expanded":n?!c:void 0,children:[n&&(0,V.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:c?(0,V.jsx)(y,{className:`h-4 w-4`}):(0,V.jsx)(P,{className:`h-4 w-4`})}),(0,V.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,V.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),t&&(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}),!c&&(0,V.jsx)(`div`,{className:m(`grid gap-4`,s||{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`}[i]),children:a})]})},U=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)({}),[u,d]=(0,B.useState)(!0),[f,p]=(0,B.useState)(null),[h,g]=(0,B.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);B.useEffect(()=>{(async()=>{if(!t){d(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){p(e)}})()},[e.objectName,t]),B.useEffect(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){l(e.initialData||e.initialValues||{}),d(!1);return}try{l(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{d(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let _=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]),v=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),y=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x=(e,t)=>e.name||e.label||`tab-${t}`;if(f)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:f.message})]});if(u)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let S={type:`form`,fields:e.sections.flatMap(e=>_(e)),layout:`vertical`,defaultValues:c,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:v,onCancel:y},C=e.tabPosition===`left`||e.tabPosition===`right`;return(0,V.jsx)(`div`,{className:m(`w-full`,n,e.className),children:(0,V.jsxs)(D,{value:h,onValueChange:g,orientation:C?`vertical`:`horizontal`,className:m(C&&`flex gap-4`),children:[(0,V.jsx)(w,{className:m(C?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,V.jsx)(b,{value:x(e,t),className:C?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},x(e,t)))}),(0,V.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,V.jsx)(T,{value:x(t,n),className:`mt-0`,children:(0,V.jsx)(H,{description:t.description,columns:t.columns||1,children:(0,V.jsx)(r,{schema:{...S,fields:_(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},x(t,n)))})]})})},W=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)({}),[d,f]=(0,B.useState)(!0),[p,h]=(0,B.useState)(null),[g,_]=(0,B.useState)(0),[v,b]=(0,B.useState)(new Set),[x,S]=(0,B.useState)(!1),C=e.sections.length,w=g===0,T=g===C-1;B.useEffect(()=>{(async()=>{if(!t){f(!1);return}try{c(await t.getObjectSchema(e.objectName))}catch(e){h(e)}})()},[e.objectName,t]),B.useEffect(()=>{(s||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){u(e.initialData||e.initialValues||{}),f(!1);return}try{u(await t.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{f(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let E=(0,B.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(s?.fields?.[t]){let r=s.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[s,e.readOnly,e.mode]),D=(0,B.useMemo)(()=>g>=0&&g<C?E(e.sections[g]):[],[g,C,e.sections,E]),O=(0,B.useCallback)(async n=>{let r={...l,...n};if(u(r),b(e=>new Set(e).add(g)),T){S(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(r),r;let n;return e.mode===`create`?n=await t.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(n=await t.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(n),n}catch(t){throw e.onError&&e.onError(t),t}finally{S(!1)}}else k(g+1)},[l,g,T,e,t]),k=(0,B.useCallback)(t=>{t>=0&&t<C&&(_(t),e.onStepChange&&e.onStepChange(t))},[C,e]),A=(0,B.useCallback)(()=>{k(g-1)},[g,k]),j=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),ee=(0,B.useCallback)(t=>{(e.allowSkip||v.has(t)||t<=g)&&k(t)},[e.allowSkip,v,g,k]);if(p)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:p.message})]});if(d)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let N=e.sections[g];return(0,V.jsxs)(`div`,{className:m(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,V.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,V.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===g,i=v.has(n),a=e.allowSkip||i||n<=g;return(0,V.jsxs)(`li`,{className:m(`relative flex-1`,n!==C-1&&`pr-8 sm:pr-12`),children:[n!==C-1&&(0,V.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,V.jsx)(`div`,{className:m(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,V.jsxs)(`button`,{type:`button`,className:m(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>ee(n),disabled:!a,children:[(0,V.jsx)(`span`,{className:m(`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,V.jsx)(M,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,V.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,V.jsx)(`span`,{className:m(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,V.jsx)(`div`,{className:`min-h-[200px]`,children:N&&(0,V.jsx)(H,{label:N.label,description:N.description,columns:N.columns||1,children:D.length>0?(0,V.jsx)(r,{schema:{type:`form`,fields:D,layout:`vertical`,defaultValues:l,showSubmit:!1,showCancel:!1,onSubmit:O}}):(0,V.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,V.jsx)(`div`,{children:e.showCancel!==!1&&(0,V.jsx)(z,{variant:`ghost`,onClick:j,children:e.cancelText||`Cancel`})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,g+1,` of `,C]}),!w&&(0,V.jsxs)(z,{variant:`outline`,onClick:A,children:[(0,V.jsx)(o,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),T?(0,V.jsx)(z,{onClick:()=>O(l),disabled:x||e.mode===`view`,children:x?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,V.jsxs)(z,{onClick:()=>O(l),children:[e.nextText||`Next`,(0,V.jsx)(y,{className:`h-4 w-4 ml-1`})]})]})]})]})},G=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)({}),[u,d]=(0,B.useState)(!0),[f,p]=(0,B.useState)(null);(0,B.useEffect)(()=>{(async()=>{if(!t){d(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){p(e),d(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){l(e.initialData||e.initialValues||{}),d(!1);return}if(!t){l(e.initialData||e.initialValues||{}),d(!1);return}try{l(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{d(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]),g=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),_=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(0,B.useMemo)(()=>e.sections.slice(0,1),[e.sections]),y=(0,B.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,B.useMemo)(()=>e.sections.flatMap(e=>h(e)),[e.sections,h]);let b=e.splitDirection||`horizontal`,S=e.splitSize||50;if(f)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:f.message})]});if(u)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let C={type:`form`,layout:`vertical`,defaultValues:c,onSubmit:g,onCancel:_},w=(t,n)=>(0,V.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,V.jsx)(H,{label:t.label,description:t.description,columns:t.columns||1,children:(0,V.jsx)(r,{schema:{...C,fields:h(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,V.jsx)(`div`,{className:m(`w-full`,n,e.className),children:(0,V.jsxs)(j,{orientation:b,className:`min-h-[300px] rounded-lg border`,children:[(0,V.jsx)(x,{defaultSize:S,minSize:20,children:w(v,y.length===0)}),y.length>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{withHandle:e.splitResizable!==!1}),(0,V.jsx)(x,{defaultSize:100-S,minSize:20,children:w(y,!0)})]})]})})},te=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`,`field:master_detail`]),ne=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),re=new Set([`formula`,`summary`,`auto_number`,`autonumber`,`master_detail`,`masterDetail`]);function ie(e){return ne.has(e)}function ae(e){return re.has(e)}function oe(e){return e<=3?1:2}function K(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&ie(e.type)?{...e,colSpan:t}:e)}var se=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function ce(e,t){return e.filter(e=>{if(se.has(e.name)||e.type&&te.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!ae(n.type):!0})}function q(e){return e<=1?`default`:e===2?`xl`:`full`}function J(e,t,n,r){let i=[...e];if(r===`create`&&(i=ce(i,t)),n!==void 0)return i=K(i,n),{fields:i,columns:n};let a=oe(i.length);return i=K(i,a),{fields:i,columns:a}}var le={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`},Y=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)([]),[d,h]=(0,B.useState)({}),[g,_]=(0,B.useState)(!0),[y,b]=(0,B.useState)(null),x=e.open!==!1,S=e.drawerSide||`right`,[C,w]=(0,B.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,B.useEffect)(()=>{(async()=>{if(!t){_(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){b(e),_(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){h(e.initialData||e.initialValues||{}),_(!1);return}if(!t){h(e.initialData||e.initialValues||{}),_(!1);return}try{h(await t.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{_(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let T=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]);(0,B.useEffect)(()=>{if(!o&&t)return;if(e.customFields?.length){l(e.customFields),_(!1);return}if(e.sections?.length){_(!1);return}if(!o)return;let n=e.fields||Object.keys(o.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=o.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(a),field:a,options:a.options,multiple:a.multiple})}l(r),_(!1)},[o,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let E=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),D=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),O=(0,B.useMemo)(()=>{if(e.drawerWidth)return S===`left`||S===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,S]),k={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?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:E,onCancel:D};return(0,V.jsx)(u,{open:x,onOpenChange:e.onOpenChange,children:(0,V.jsxs)(p,{side:S,className:m(`overflow-y-auto`,n,e.className),style:O,children:[(e.title||e.description)&&(0,V.jsxs)(f,{children:[e.title&&(0,V.jsx)(v,{children:e.title}),e.description&&(0,V.jsx)(N,{children:e.description})]}),(0,V.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(y)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(g)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.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,V.jsx)(r,{schema:{...k,fields:t}})}let t=J(c,o,e.columns,e.mode),n=le[t.columns||1];return(0,V.jsx)(r,{schema:{...k,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},X={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`},Q=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[u,f]=(0,B.useState)([]),[p,_]=(0,B.useState)({}),[v,y]=(0,B.useState)(!0),[b,x]=(0,B.useState)(null),[S,w]=(0,B.useState)(!1),T=e.open!==!1,E=(0,B.useId)(),D=(0,B.useMemo)(()=>e.sections?.length||e.customFields?.length?null:J(u,o,e.columns,e.mode),[u,o,e.columns,e.mode,e.sections,e.customFields]),O=X[(0,B.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(D?.columns&&D.columns>1)return q(D.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return q(t)}return`default`},[e.modalSize,D,e.sections])]||X.default;(0,B.useEffect)(()=>{(async()=>{if(!t){y(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){x(e),y(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){_(e.initialData||e.initialValues||{}),y(!1);return}if(!t){_(e.initialData||e.initialValues||{}),y(!1);return}try{_(await t.findOne(e.objectName,e.recordId)||{})}catch(e){x(e)}finally{y(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let k=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]);(0,B.useEffect)(()=>{if(!o&&t)return;if(e.customFields?.length){f(e.customFields),y(!1);return}if(e.sections?.length){y(!1);return}if(!o)return;let n=e.fields||Object.keys(o.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=o.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(a),field:a,options:a.options,multiple:a.multiple})}f(r),y(!1)},[o,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let A=(0,B.useCallback)(async n=>{w(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{w(!1)}},[e,t]),j=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),M=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,N=e.showSubmit!==!1&&e.mode!==`view`,P=e.showCancel!==!1,F=e.submitText||(e.mode===`create`?`Create`:`Update`),L=e.cancelText||`Cancel`,U={type:`form`,layout:M,defaultValues:p,submitLabel:F,cancelLabel:L,showSubmit:N,showCancel:P,onSubmit:A,onCancel:j,showActions:!1,id:E},W=()=>{if(b)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:b.message})]});if(v)return(0,V.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(g,{className:`h-4 w-24`}),(0,V.jsx)(g,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,V.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,V.jsx)(H,{label:e.label,description:e.description,columns:n,gridClassName:Z[n],children:(0,V.jsx)(r,{schema:{...U,fields:k(e)}})},e.name||e.label||t)})});let t=D??J(u,o,e.columns,e.mode),n=Z[t.columns||1];return(0,V.jsx)(r,{schema:{...U,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!v&&!b&&(N||P);return(0,V.jsx)(h,{open:T,onOpenChange:e.onOpenChange,children:(0,V.jsxs)(C,{className:m(O,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,V.jsxs)(ee,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,V.jsx)(d,{children:e.title}),e.description&&(0,V.jsx)(l,{children:e.description})]}),(0,V.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,V.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,V.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[P&&(0,V.jsx)(z,{type:`button`,variant:`outline`,onClick:j,disabled:S,className:`w-full sm:w-auto`,children:L}),N&&(0,V.jsxs)(z,{type:`submit`,form:E,disabled:S,className:`w-full sm:w-auto`,children:[S&&(0,V.jsx)(c,{className:`mr-2 h-4 w-4 animate-spin`}),F]})]})})]})})},$=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,V.jsx)(U,{schema:{...e,formType:`tabbed`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:t,className:e.className});if(e.formType===`wizard`&&e.sections?.length)return(0,V.jsx)(W,{schema:{...e,formType:`wizard`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:t,className:e.className});if(e.formType===`split`&&e.sections?.length)return(0,V.jsx)(G,{schema:{...e,formType:`split`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:t,className:e.className});if(e.formType===`drawer`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,V.jsx)(Y,{schema:{...r,layout:i,formType:`drawer`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:t,className:e.className})}if(e.formType===`modal`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,V.jsx)(Q,{schema:{...r,layout:i,formType:`modal`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:t,className:e.className})}return(0,V.jsx)(ue,{schema:e,dataSource:t})},ue=({schema:e,dataSource:t})=>{let{fieldLabel:n}=a(),i=_(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)([]),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(!0),[m,h]=(0,B.useState)(null),g=e.customFields&&e.customFields.length>0;(0,B.useEffect)(()=>{g&&(d(e.initialData||e.initialValues||{}),p(!1))},[g,e.initialData,e.initialValues]),(0,B.useEffect)(()=>{g?s({name:e.objectName,fields:{}}):e.objectName&&t?(async()=>{try{if(!t)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let n=await t.getObjectSchema(e.objectName);if(!n)throw Error(`No schema found for object "${e.objectName}"`);s(n)}catch(e){h(e),p(!1)}})():g||p(!1)},[e.objectName,t,g]),(0,B.useEffect)(()=>{o&&!g&&(async()=>{if(!e.recordId||e.mode===`create`){d(e.initialData||e.initialValues||{}),p(!1);return}if(!g){if(!t){h(Error(`DataSource is required for fetching record data (inline data not provided)`)),p(!1);return}p(!0);try{d(await t.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),h(e)}finally{p(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,o,g]),(0,B.useEffect)(()=>{if(g&&e.customFields){l(e.customFields),p(!1);return}if(!o)return;let r=[],i=e.fields||Object.keys(o.fields||{});(Array.isArray(i)?i:Object.keys(i)).forEach(t=>{let i=typeof t==`string`?t:t.name;if(!i)return;let a=o.fields?.[i];if(!a&&!g)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===i);if(c)r.push(c);else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(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: ${A(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=>O(a.visible_on,e)),r.push(o)}}),l(r),!g&&e.recordId&&e.mode!==`create`&&t||p(!1)},[o,e.fields,e.customFields,e.readOnly,e.mode,g,e.recordId,t]);let v=(0,B.useCallback)(async(n,r)=>{if(n&&(n.nativeEvent||n._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=n,n={})),g&&!t)return e.onSuccess&&await e.onSuccess(n),n;if(!t)throw Error(`DataSource is required for form submission (inline mode not configured)`);try{let r;if(e.mode===`create`)r=await t.create(e.objectName,n);else if(e.mode===`edit`&&e.recordId)r=await t.update(e.objectName,e.recordId,n);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,t,g]),y=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),b={...B.useMemo(()=>{if(!o?.fields)return{};let e={};return Object.keys(o.fields).forEach(t=>{let n=o.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[o]),...u};if(m)return(0,V.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:m.message})]});if(f)return(0,V.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let x=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,V.jsx)(`div`,{className:`w-full space-y-6`,children:e.sections.map((t,n)=>{let i=t.fields.map(e=>typeof e==`string`?e:e.name),a=c.filter(e=>i.includes(e.name));return(0,V.jsx)(H,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,V.jsx)(r,{schema:{type:`form`,fields:a,layout:x,defaultValues:b,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:v,onCancel:y}})},t.name||t.label||n)})});let S=e.sections?.length,C=S?{fields:c,columns:e.columns}:J(c,o,e.columns,e.mode),w=e.mobile,T=w?.fullscreenLongText?C.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}):C.fields,E=w?.stepper,D=w?.stepperMinFields??8,k=Math.max(1,w?.stepperFieldsPerStep??1);if(!e.formType&&!S&&T.length>=2&&(E===!0||E===`auto`&&i&&T.length>=D)){let n=T,r=[];for(let e=0;e<n.length;e+=k){let t=n.slice(e,e+k);r.push({name:`step-${Math.floor(e/k)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/k)+1}`,fields:t})}return(0,V.jsx)(W,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let j={type:`form`,fields:T,layout:x,columns:C.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:b,onSubmit:v,onCancel:y,className:e.className,mobileStickyActions:!!w?.stickyActions};return(0,V.jsx)(`div`,{className:w?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":w?`true`:void 0,children:(0,V.jsx)(r,{schema:j})})},de=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),u=(0,B.useMemo)(()=>{let e={};if(n)for(let[t,r]of Object.entries(n))e[t]=r;return typeof window<`u`&&new URLSearchParams(window.location.search).forEach((t,n)=>{n in e||(e[n]=t)}),Object.keys(e).length>0?e:void 0},[n]),d=(0,B.useCallback)(async n=>{s(!0),l(null);try{if(t&&await t.create(e.objectName,n),a(!0),e.thankYouPage?.redirectUrl){let t=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},t)}}catch(e){l(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{s(!1)}},[t,e]),f=(0,B.useCallback)(()=>{a(!1),l(null)},[]),p=(0,B.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(i){let t=e.thankYouPage;return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${r||``}`,style:p,children:(0,V.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,V.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,V.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,V.jsx)(`button`,{onClick:f,className:`mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors`,children:`Submit Another Response`}),t?.redirectUrl&&(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${r||``}`,style:p,children:(0,V.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,V.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,V.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,V.jsxs)(`div`,{className:`p-6`,children:[c&&(0,V.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:c}),(0,V.jsx)($,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:u,onSuccess:d,submitLabel:o?`Submitting...`:`Submit`},dataSource:t})]}),(0,V.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function fe(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:t,metrics:n,className:r})=>{let i=(0,B.useMemo)(()=>{if(!n.abandonedSubmissions)return 100;let e=n.totalSubmissions+n.abandonedSubmissions;return e===0?0:Math.round(n.totalSubmissions/e*100)},[n.totalSubmissions,n.abandonedSubmissions]),a=(0,B.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,V.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,V.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,V.jsx)(s,{children:(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Total Submissions`}),(0,V.jsx)(F,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,V.jsxs)(s,{children:[(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Fill Rate`}),(0,V.jsxs)(F,{className:`text-2xl`,children:[i,`%`]})]}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,V.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,V.jsx)(s,{children:(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Avg. Completion Time`}),(0,V.jsx)(F,{className:`text-2xl`,children:n.avgCompletionTime?fe(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,V.jsxs)(s,{children:[(0,V.jsx)(k,{children:(0,V.jsx)(F,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,V.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,V.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/a*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),n.fieldDropOff&&n.fieldDropOff.length>0&&(0,V.jsxs)(s,{children:[(0,V.jsxs)(k,{children:[(0,V.jsx)(F,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,V.jsx)(L,{children:`Percentage of users who completed each field`})]}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,V.jsxs)(`div`,{className:`space-y-1`,children:[(0,V.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,V.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,V.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,V.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))})})]})]})},me=({schema:e})=>(0,V.jsx)($,{schema:e});i.register(`object-form`,me,{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`]}]}),i.register(`form`,me,{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`]}]}),i.register(`embeddable-form`,({schema:e})=>(0,V.jsx)(de,{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`}]}),i.register(`form-analytics`,({schema:e})=>(0,V.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`}]});export{Q as n,Y as r,$ as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{D as r,H as i}from"./framework-CoXA0nY6.js";import{f as a}from"./infrastructure-Djv3I7gr.js";import{$A as o,$n as s,Cy as c,Gn as l,Gt as u,Jn as d,Jt as f,Kt as p,PL as m,Un as h,Ut as g,Wt as _,Yt as v,ZA as y,_t as b,an as x,er as S,et as C,gt as w,ht as T,in as E,mt as D,n as O,nr as k,o as A,on as j,pj as M,qn as ee,qt as N,rj as P,rr as F,t as I,tr as L,u as R,yr as z}from"./ui-components-B7mlp0en.js";var B=e(t(),1),V=n(),H=({label:e,description:t,collapsible:n=!1,collapsed:r=!1,columns:i=1,children:a,className:o,gridClassName:s})=>{let[c,l]=(0,B.useState)(r);return(0,V.jsxs)(`div`,{className:m(`form-section`,o),children:[(e||t)&&(0,V.jsxs)(`div`,{className:m(`flex items-start gap-2 mb-4`,n&&`cursor-pointer select-none`),onClick:()=>{n&&l(!c)},role:n?`button`:void 0,"aria-expanded":n?!c:void 0,children:[n&&(0,V.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:c?(0,V.jsx)(y,{className:`h-4 w-4`}):(0,V.jsx)(P,{className:`h-4 w-4`})}),(0,V.jsxs)(`div`,{className:`flex-1`,children:[e&&(0,V.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e}),t&&(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:t})]})]}),!c&&(0,V.jsx)(`div`,{className:m(`grid gap-4`,s||{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`}[i]),children:a})]})},U=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)({}),[u,d]=(0,B.useState)(!0),[f,p]=(0,B.useState)(null),[h,g]=(0,B.useState)(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||`tab-0`);B.useEffect(()=>{(async()=>{if(!t){d(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){p(e)}})()},[e.objectName,t]),B.useEffect(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){l(e.initialData||e.initialValues||{}),d(!1);return}try{l(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{d(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let _=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]),v=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),y=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),x=(e,t)=>e.name||e.label||`tab-${t}`;if(f)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:f.message})]});if(u)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let S={type:`form`,fields:e.sections.flatMap(e=>_(e)),layout:`vertical`,defaultValues:c,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,onSubmit:v,onCancel:y},C=e.tabPosition===`left`||e.tabPosition===`right`;return(0,V.jsx)(`div`,{className:m(`w-full`,n,e.className),children:(0,V.jsxs)(D,{value:h,onValueChange:g,orientation:C?`vertical`:`horizontal`,className:m(C&&`flex gap-4`),children:[(0,V.jsx)(w,{className:m(C?`flex-col h-auto`:``,e.tabPosition===`bottom`&&`order-last`,e.tabPosition===`right`&&`order-last`),children:e.sections.map((e,t)=>(0,V.jsx)(b,{value:x(e,t),className:C?`w-full justify-start`:``,children:e.label||`Tab ${t+1}`},x(e,t)))}),(0,V.jsx)(`div`,{className:`flex-1`,children:e.sections.map((t,n)=>(0,V.jsx)(T,{value:x(t,n),className:`mt-0`,children:(0,V.jsx)(H,{description:t.description,columns:t.columns||1,children:(0,V.jsx)(r,{schema:{...S,fields:_(t),showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1}})})},x(t,n)))})]})})},W=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)({}),[d,f]=(0,B.useState)(!0),[p,h]=(0,B.useState)(null),[g,_]=(0,B.useState)(0),[v,b]=(0,B.useState)(new Set),[x,S]=(0,B.useState)(!1),C=e.sections.length,w=g===0,T=g===C-1;B.useEffect(()=>{(async()=>{if(!t){f(!1);return}try{c(await t.getObjectSchema(e.objectName))}catch(e){h(e)}})()},[e.objectName,t]),B.useEffect(()=>{(s||!t)&&(async()=>{if(e.mode===`create`||!e.recordId||!t){u(e.initialData||e.initialValues||{}),f(!1);return}try{u(await t.findOne(e.objectName,e.recordId)||{})}catch(e){h(e)}finally{f(!1)}})()},[s,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let E=(0,B.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(s?.fields?.[t]){let r=s.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[s,e.readOnly,e.mode]),D=(0,B.useMemo)(()=>g>=0&&g<C?E(e.sections[g]):[],[g,C,e.sections,E]),O=(0,B.useCallback)(async n=>{let r={...l,...n};if(u(r),b(e=>new Set(e).add(g)),T){S(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(r),r;let n;return e.mode===`create`?n=await t.create(e.objectName,r):e.mode===`edit`&&e.recordId&&(n=await t.update(e.objectName,e.recordId,r)),e.onSuccess&&await e.onSuccess(n),n}catch(t){throw e.onError&&e.onError(t),t}finally{S(!1)}}else k(g+1)},[l,g,T,e,t]),k=(0,B.useCallback)(t=>{t>=0&&t<C&&(_(t),e.onStepChange&&e.onStepChange(t))},[C,e]),A=(0,B.useCallback)(()=>{k(g-1)},[g,k]),j=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),ee=(0,B.useCallback)(t=>{(e.allowSkip||v.has(t)||t<=g)&&k(t)},[e.allowSkip,v,g,k]);if(p)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:p.message})]});if(d)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let N=e.sections[g];return(0,V.jsxs)(`div`,{className:m(`w-full`,n,e.className),children:[e.showStepIndicator!==!1&&(0,V.jsx)(`nav`,{"aria-label":`Progress`,className:`mb-8`,children:(0,V.jsx)(`ol`,{className:`flex items-center`,children:e.sections.map((t,n)=>{let r=n===g,i=v.has(n),a=e.allowSkip||i||n<=g;return(0,V.jsxs)(`li`,{className:m(`relative flex-1`,n!==C-1&&`pr-8 sm:pr-12`),children:[n!==C-1&&(0,V.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,V.jsx)(`div`,{className:m(`h-full`,i?`bg-primary`:`bg-muted`)})}),(0,V.jsxs)(`button`,{type:`button`,className:m(`group relative flex items-center`,a?`cursor-pointer`:`cursor-not-allowed`),onClick:()=>ee(n),disabled:!a,children:[(0,V.jsx)(`span`,{className:m(`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,V.jsx)(M,{className:`h-3 w-3 sm:h-4 sm:w-4`}):n+1}),(0,V.jsx)(`span`,{className:`ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block`,children:(0,V.jsx)(`span`,{className:m(r?`text-foreground`:`text-muted-foreground`),children:t.label||`Step ${n+1}`})})]})]},n)})})}),(0,V.jsx)(`div`,{className:`min-h-[200px]`,children:N&&(0,V.jsx)(H,{label:N.label,description:N.description,columns:N.columns||1,children:D.length>0?(0,V.jsx)(r,{schema:{type:`form`,fields:D,layout:`vertical`,defaultValues:l,showSubmit:!1,showCancel:!1,onSubmit:O}}):(0,V.jsx)(`div`,{className:`text-center py-8 text-muted-foreground`,children:`No fields configured for this step`})})}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between mt-6 pt-4 border-t`,children:[(0,V.jsx)(`div`,{children:e.showCancel!==!1&&(0,V.jsx)(z,{variant:`ghost`,onClick:j,children:e.cancelText||`Cancel`})}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`span`,{className:`text-sm text-muted-foreground mr-2`,children:[`Step `,g+1,` of `,C]}),!w&&(0,V.jsxs)(z,{variant:`outline`,onClick:A,children:[(0,V.jsx)(o,{className:`h-4 w-4 mr-1`}),e.prevText||`Back`]}),T?(0,V.jsx)(z,{onClick:()=>O(l),disabled:x||e.mode===`view`,children:x?`Submitting...`:e.submitText||(e.mode===`create`?`Create`:`Update`)}):(0,V.jsxs)(z,{onClick:()=>O(l),children:[e.nextText||`Next`,(0,V.jsx)(y,{className:`h-4 w-4 ml-1`})]})]})]})]})},G=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)({}),[u,d]=(0,B.useState)(!0),[f,p]=(0,B.useState)(null);(0,B.useEffect)(()=>{(async()=>{if(!t){d(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){p(e),d(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){l(e.initialData||e.initialValues||{}),d(!1);return}if(!t){l(e.initialData||e.initialValues||{}),d(!1);return}try{l(await t.findOne(e.objectName,e.recordId)||{})}catch(e){p(e)}finally{d(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let h=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]),g=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),_=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),v=(0,B.useMemo)(()=>e.sections.slice(0,1),[e.sections]),y=(0,B.useMemo)(()=>e.sections.slice(1),[e.sections]);(0,B.useMemo)(()=>e.sections.flatMap(e=>h(e)),[e.sections,h]);let b=e.splitDirection||`horizontal`,S=e.splitSize||50;if(f)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:f.message})]});if(u)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let C={type:`form`,layout:`vertical`,defaultValues:c,onSubmit:g,onCancel:_},w=(t,n)=>(0,V.jsx)(`div`,{className:`space-y-4 p-4`,children:t.map((t,i)=>(0,V.jsx)(H,{label:t.label,description:t.description,columns:t.columns||1,children:(0,V.jsx)(r,{schema:{...C,fields:h(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,V.jsx)(`div`,{className:m(`w-full`,n,e.className),children:(0,V.jsxs)(j,{orientation:b,className:`min-h-[300px] rounded-lg border`,children:[(0,V.jsx)(x,{defaultSize:S,minSize:20,children:w(v,y.length===0)}),y.length>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{withHandle:e.splitResizable!==!1}),(0,V.jsx)(x,{defaultSize:100-S,minSize:20,children:w(y,!0)})]})]})})},te=new Set([`field:formula`,`field:summary`,`field:auto_number`,`field:autonumber`,`field:master_detail`]),ne=new Set([`field:textarea`,`field:markdown`,`field:html`,`field:grid`,`field:rich-text`,`textarea`,`markdown`,`html`,`grid`,`rich-text`]),re=new Set([`formula`,`summary`,`auto_number`,`autonumber`,`master_detail`,`masterDetail`]);function ie(e){return ne.has(e)}function ae(e){return re.has(e)}function oe(e){return e<=3?1:2}function K(e,t){return t<=1?e:e.map(e=>e.colSpan===void 0&&e.type&&ie(e.type)?{...e,colSpan:t}:e)}var se=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`owner`,`owner_id`,`_version`,`_rev`]);function ce(e,t){return e.filter(e=>{if(se.has(e.name)||e.type&&te.has(e.type))return!1;if(!t?.fields)return!0;let n=t.fields[e.name];return n?n.readonly===!0?!1:!ae(n.type):!0})}function q(e){return e<=1?`default`:e===2?`xl`:`full`}function J(e,t,n,r){let i=[...e];if(r===`create`&&(i=ce(i,t)),n!==void 0)return i=K(i,n),{fields:i,columns:n};let a=oe(i.length);return i=K(i,a),{fields:i,columns:a}}var le={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`},Y=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)([]),[d,h]=(0,B.useState)({}),[g,_]=(0,B.useState)(!0),[y,b]=(0,B.useState)(null),x=e.open!==!1,S=e.drawerSide||`right`,[C,w]=(0,B.useState)(()=>{let t={};return e.sections?.forEach((e,n)=>{let r=e.name||String(n);e.collapsed&&(t[r]=!0)}),t});(0,B.useEffect)(()=>{(async()=>{if(!t){_(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){b(e),_(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){h(e.initialData||e.initialValues||{}),_(!1);return}if(!t){h(e.initialData||e.initialValues||{}),_(!1);return}try{h(await t.findOne(e.objectName,e.recordId)||{})}catch(e){b(e)}finally{_(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let T=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]);(0,B.useEffect)(()=>{if(!o&&t)return;if(e.customFields?.length){l(e.customFields),_(!1);return}if(e.sections?.length){_(!1);return}if(!o)return;let n=e.fields||Object.keys(o.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=o.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(a),field:a,options:a.options,multiple:a.multiple})}l(r),_(!1)},[o,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let E=(0,B.useCallback)(async n=>{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;try{let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}},[e,t]),D=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),O=(0,B.useMemo)(()=>{if(e.drawerWidth)return S===`left`||S===`right`?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}},[e.drawerWidth,S]),k={type:`form`,layout:e.layout===`vertical`||e.layout===`horizontal`?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:E,onCancel:D};return(0,V.jsx)(u,{open:x,onOpenChange:e.onOpenChange,children:(0,V.jsxs)(p,{side:S,className:m(`overflow-y-auto`,n,e.className),style:O,children:[(e.title||e.description)&&(0,V.jsxs)(f,{children:[e.title&&(0,V.jsx)(v,{children:e.title}),e.description&&(0,V.jsx)(N,{children:e.description})]}),(0,V.jsx)(`div`,{className:`@container py-4`,children:(()=>{if(y)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:y.message})]});if(g)return(0,V.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.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,V.jsx)(r,{schema:{...k,fields:t}})}let t=J(c,o,e.columns,e.mode),n=le[t.columns||1];return(0,V.jsx)(r,{schema:{...k,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})})()})]})})},X={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`},Q=({schema:e,dataSource:t,className:n})=>{let{fieldLabel:i}=a(),[o,s]=(0,B.useState)(null),[u,f]=(0,B.useState)([]),[p,_]=(0,B.useState)({}),[v,y]=(0,B.useState)(!0),[b,x]=(0,B.useState)(null),[S,w]=(0,B.useState)(!1),T=e.open!==!1,E=(0,B.useId)(),D=(0,B.useMemo)(()=>e.sections?.length||e.customFields?.length?null:J(u,o,e.columns,e.mode),[u,o,e.columns,e.mode,e.sections,e.customFields]),O=X[(0,B.useMemo)(()=>{if(e.modalSize)return e.modalSize;if(D?.columns&&D.columns>1)return q(D.columns);if(e.sections?.length){let t=Math.max(...e.sections.map(e=>Number(e.columns)||1));if(t>1)return q(t)}return`default`},[e.modalSize,D,e.sections])]||X.default;(0,B.useEffect)(()=>{(async()=>{if(!t){y(!1);return}try{s(await t.getObjectSchema(e.objectName))}catch(e){x(e),y(!1)}})()},[e.objectName,t]),(0,B.useEffect)(()=>{(o||!t)&&(async()=>{if(e.mode===`create`||!e.recordId){_(e.initialData||e.initialValues||{}),y(!1);return}if(!t){_(e.initialData||e.initialValues||{}),y(!1);return}try{_(await t.findOne(e.objectName,e.recordId)||{})}catch(e){x(e)}finally{y(!1)}})()},[o,e.mode,e.recordId,e.initialData,e.initialValues,t,e.objectName]);let k=(0,B.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(o?.fields?.[t]){let r=o.fields[t];n.push({name:t,label:i(e.objectName,t,r.label||t),type:R(r.type),required:r.required||!1,disabled:e.readOnly||e.mode===`view`||r.readonly,placeholder:r.placeholder,description:r.help||r.description,validation:I(r),field:r,options:r.options,multiple:r.multiple})}else n.push({name:t,label:t,type:`input`})}return n},[o,e.readOnly,e.mode]);(0,B.useEffect)(()=>{if(!o&&t)return;if(e.customFields?.length){f(e.customFields),y(!1);return}if(e.sections?.length){y(!1);return}if(!o)return;let n=e.fields||Object.keys(o.fields||{}),r=[];for(let t of n){let n=typeof t==`string`?t:t.name;if(!n)continue;let a=o.fields?.[n];a&&r.push({name:n,label:i(e.objectName,n,a.label||n),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(a),field:a,options:a.options,multiple:a.multiple})}f(r),y(!1)},[o,e.fields,e.customFields,e.sections,e.readOnly,e.mode,t]);let A=(0,B.useCallback)(async n=>{w(!0);try{if(!t)return e.onSuccess&&await e.onSuccess(n),e.onOpenChange?.(!1),n;let r;return e.mode===`create`?r=await t.create(e.objectName,n):e.mode===`edit`&&e.recordId&&(r=await t.update(e.objectName,e.recordId,n)),e.onSuccess&&await e.onSuccess(r),e.onOpenChange?.(!1),r}catch(t){throw e.onError&&e.onError(t),t}finally{w(!1)}},[e,t]),j=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),M=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`,N=e.showSubmit!==!1&&e.mode!==`view`,P=e.showCancel!==!1,F=e.submitText||(e.mode===`create`?`Create`:`Update`),L=e.cancelText||`Cancel`,U={type:`form`,layout:M,defaultValues:p,submitLabel:F,cancelLabel:L,showSubmit:N,showCancel:P,onSubmit:A,onCancel:j,showActions:!1,id:E},W=()=>{if(b)return(0,V.jsxs)(`div`,{className:`p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:b.message})]});if(v)return(0,V.jsx)(`div`,{className:`space-y-4`,"data-testid":`modal-form-skeleton`,children:[1,2,3].map(e=>(0,V.jsxs)(`div`,{className:`space-y-2`,children:[(0,V.jsx)(g,{className:`h-4 w-24`}),(0,V.jsx)(g,{className:`h-10 w-full`})]},e))});if(e.sections?.length)return(0,V.jsx)(`div`,{className:`space-y-6`,children:e.sections.map((e,t)=>{let n=e.columns||1;return(0,V.jsx)(H,{label:e.label,description:e.description,columns:n,gridClassName:Z[n],children:(0,V.jsx)(r,{schema:{...U,fields:k(e)}})},e.name||e.label||t)})});let t=D??J(u,o,e.columns,e.mode),n=Z[t.columns||1];return(0,V.jsx)(r,{schema:{...U,fields:t.fields,columns:t.columns,...n?{fieldContainerClass:n}:{}}})},G=!v&&!b&&(N||P);return(0,V.jsx)(h,{open:T,onOpenChange:e.onOpenChange,children:(0,V.jsxs)(C,{className:m(O,`flex flex-col h-[100dvh] sm:h-auto sm:max-h-[90vh] overflow-hidden p-0`,n,e.className),children:[(e.title||e.description)&&(0,V.jsxs)(ee,{className:`shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 pb-2 border-b`,children:[e.title&&(0,V.jsx)(d,{children:e.title}),e.description&&(0,V.jsx)(l,{children:e.description})]}),(0,V.jsx)(`div`,{className:`@container flex-1 overflow-y-auto px-4 sm:px-6 py-4`,children:W()}),G&&(0,V.jsx)(`div`,{className:`shrink-0 border-t px-4 sm:px-6 py-3 bg-background`,"data-testid":`modal-form-footer`,children:(0,V.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 sm:justify-end`,children:[P&&(0,V.jsx)(z,{type:`button`,variant:`outline`,onClick:j,disabled:S,className:`w-full sm:w-auto`,children:L}),N&&(0,V.jsxs)(z,{type:`submit`,form:E,disabled:S,className:`w-full sm:w-auto`,children:[S&&(0,V.jsx)(c,{className:`mr-2 h-4 w-4 animate-spin`}),F]})]})})]})})},$=({schema:e,dataSource:t})=>{if(e.formType===`tabbed`&&e.sections?.length)return(0,V.jsx)(U,{schema:{...e,formType:`tabbed`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:t,className:e.className});if(e.formType===`wizard`&&e.sections?.length)return(0,V.jsx)(W,{schema:{...e,formType:`wizard`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:t,className:e.className});if(e.formType===`split`&&e.sections?.length)return(0,V.jsx)(G,{schema:{...e,formType:`split`,sections:e.sections.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:t,className:e.className});if(e.formType===`drawer`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,V.jsx)(Y,{schema:{...r,layout:i,formType:`drawer`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields,collapsible:e.collapsible,collapsed:e.collapsed})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:t,className:e.className})}if(e.formType===`modal`){let{layout:n,...r}=e,i=e.layout===`vertical`||e.layout===`horizontal`?e.layout:void 0;return(0,V.jsx)(Q,{schema:{...r,layout:i,formType:`modal`,sections:e.sections?.map(e=>({name:e.name,label:e.label,description:e.description,columns:e.columns,fields:e.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:t,className:e.className})}return(0,V.jsx)(ue,{schema:e,dataSource:t})},ue=({schema:e,dataSource:t})=>{let{fieldLabel:n}=a(),i=_(),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)([]),[u,d]=(0,B.useState)(null),[f,p]=(0,B.useState)(!0),[m,h]=(0,B.useState)(null),g=e.customFields&&e.customFields.length>0;(0,B.useEffect)(()=>{g&&(d(e.initialData||e.initialValues||{}),p(!1))},[g,e.initialData,e.initialValues]),(0,B.useEffect)(()=>{g?s({name:e.objectName,fields:{}}):e.objectName&&t?(async()=>{try{if(!t)throw Error(`DataSource is required when using ObjectQL schema fetching (inline fields not provided)`);let n=await t.getObjectSchema(e.objectName);if(!n)throw Error(`No schema found for object "${e.objectName}"`);s(n)}catch(e){h(e),p(!1)}})():g||p(!1)},[e.objectName,t,g]),(0,B.useEffect)(()=>{o&&!g&&(async()=>{if(!e.recordId||e.mode===`create`){d(e.initialData||e.initialValues||{}),p(!1);return}if(!g){if(!t){h(Error(`DataSource is required for fetching record data (inline data not provided)`)),p(!1);return}p(!0);try{d(await t.findOne(e.objectName,e.recordId))}catch(e){console.error(`Failed to fetch record:`,e),h(e)}finally{p(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,t,o,g]),(0,B.useEffect)(()=>{if(g&&e.customFields){l(e.customFields),p(!1);return}if(!o)return;let r=[],i=e.fields||Object.keys(o.fields||{});(Array.isArray(i)?i:Object.keys(i)).forEach(t=>{let i=typeof t==`string`?t:t.name;if(!i)return;let a=o.fields?.[i];if(!a&&!g)return;let s=!a?.permissions||a?.permissions.write!==!1;if(e.mode!==`view`&&!s)return;let c=e.customFields?.find(e=>e.name===i);if(c)r.push(c);else if(a){let o={name:i,label:n(e.objectName,i,a.label||t),type:R(a.type),required:a.required||!1,disabled:e.readOnly||e.mode===`view`||a.readonly,placeholder:a.placeholder,description:a.help||a.description,validation:I(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: ${A(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=>O(a.visible_on,e)),r.push(o)}}),l(r),!g&&e.recordId&&e.mode!==`create`&&t||p(!1)},[o,e.fields,e.customFields,e.readOnly,e.mode,g,e.recordId,t]);let v=(0,B.useCallback)(async(n,r)=>{if(n&&(n.nativeEvent||n._reactName===`onSubmit`)&&(console.warn(`ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue.`),r===void 0&&(r=n,n={})),g&&!t)return e.onSuccess&&await e.onSuccess(n),n;if(!t)throw Error(`DataSource is required for form submission (inline mode not configured)`);try{let r;if(e.mode===`create`)r=await t.create(e.objectName,n);else if(e.mode===`edit`&&e.recordId)r=await t.update(e.objectName,e.recordId,n);else throw Error(`Invalid form mode or missing record ID`);return e.onSuccess&&await e.onSuccess(r),r}catch(t){throw console.error(`Failed to submit form:`,t),e.onError&&e.onError(t),t}},[e,t,g]),y=(0,B.useCallback)(()=>{e.onCancel&&e.onCancel()},[e]),b={...B.useMemo(()=>{if(!o?.fields)return{};let e={};return Object.keys(o.fields).forEach(t=>{let n=o.fields[t];n.defaultValue!==void 0&&(e[t]=n.defaultValue)}),e},[o]),...u};if(m)return(0,V.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,V.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:`Error loading form`}),(0,V.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:m.message})]});if(f)return(0,V.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,V.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900`}),(0,V.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:`Loading form...`})]});let x=e.layout===`vertical`||e.layout===`horizontal`?e.layout:`vertical`;if(e.sections?.length&&(!e.formType||e.formType===`simple`))return(0,V.jsx)(`div`,{className:`w-full space-y-6`,children:e.sections.map((t,n)=>{let i=t.fields.map(e=>typeof e==`string`?e:e.name),a=c.filter(e=>i.includes(e.name));return(0,V.jsx)(H,{label:t.label,description:t.description,collapsible:t.collapsible,collapsed:t.collapsed,columns:t.columns,children:(0,V.jsx)(r,{schema:{type:`form`,fields:a,layout:x,defaultValues:b,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:v,onCancel:y}})},t.name||t.label||n)})});let S=e.sections?.length,C=S?{fields:c,columns:e.columns}:J(c,o,e.columns,e.mode),w=e.mobile,T=w?.fullscreenLongText?C.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}):C.fields,E=w?.stepper,D=w?.stepperMinFields??8,k=Math.max(1,w?.stepperFieldsPerStep??1);if(!e.formType&&!S&&T.length>=2&&(E===!0||E===`auto`&&i&&T.length>=D)){let n=T,r=[];for(let e=0;e<n.length;e+=k){let t=n.slice(e,e+k);r.push({name:`step-${Math.floor(e/k)+1}`,label:t[0]?.label||t[0]?.name||`Step ${Math.floor(e/k)+1}`,fields:t})}return(0,V.jsx)(W,{schema:{...e,formType:`wizard`,sections:r,showStepIndicator:!0},dataSource:t,className:e.className})}let j={type:`form`,fields:T,layout:x,columns:C.columns,submitLabel:e.submitText||(e.mode===`create`?`Create`:`Update`),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!==`view`,showCancel:e.showCancel!==!1,resetOnSubmit:e.showReset,defaultValues:b,onSubmit:v,onCancel:y,className:e.className,mobileStickyActions:!!w?.stickyActions};return(0,V.jsx)(`div`,{className:w?.stickyActions?`w-full pb-20 md:pb-0`:`w-full`,"data-mobile-form":w?`true`:void 0,children:(0,V.jsx)(r,{schema:j})})},de=({config:e,dataSource:t,prefillParams:n,className:r})=>{let[i,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),u=(0,B.useMemo)(()=>{let e={};if(n)for(let[t,r]of Object.entries(n))e[t]=r;return typeof window<`u`&&new URLSearchParams(window.location.search).forEach((t,n)=>{n in e||(e[n]=t)}),Object.keys(e).length>0?e:void 0},[n]),d=(0,B.useCallback)(async n=>{s(!0),l(null);try{if(t&&await t.create(e.objectName,n),a(!0),e.thankYouPage?.redirectUrl){let t=e.thankYouPage.redirectDelay??3e3;setTimeout(()=>{window.location.href=e.thankYouPage.redirectUrl},t)}}catch(e){l(e instanceof Error?e.message:`Failed to submit form. Please try again.`)}finally{s(!1)}},[t,e]),f=(0,B.useCallback)(()=>{a(!1),l(null)},[]),p=(0,B.useMemo)(()=>{let t={};return e.branding?.backgroundColor&&(t.backgroundColor=e.branding.backgroundColor),t},[e.branding]);if(i){let t=e.thankYouPage;return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${r||``}`,style:p,children:(0,V.jsxs)(`div`,{className:`max-w-md w-full bg-card rounded-lg shadow-lg p-8 text-center space-y-4`,children:[(0,V.jsx)(`div`,{className:`text-4xl`,children:`✓`}),(0,V.jsx)(`h2`,{className:`text-xl font-semibold text-foreground`,children:t?.title||`Thank You!`}),(0,V.jsx)(`p`,{className:`text-muted-foreground`,children:t?.message||`Your submission has been received successfully.`}),e.allowMultiple&&(0,V.jsx)(`button`,{onClick:f,className:`mt-4 px-4 py-2 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors`,children:`Submit Another Response`}),t?.redirectUrl&&(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Redirecting in `,Math.ceil((t.redirectDelay??3e3)/1e3),` seconds...`]})]})})}return(0,V.jsx)(`div`,{className:`min-h-screen flex items-center justify-center p-4 ${r||``}`,style:p,children:(0,V.jsxs)(`div`,{className:`max-w-2xl w-full bg-card rounded-lg shadow-lg overflow-hidden`,children:[(0,V.jsxs)(`div`,{className:`p-6 border-b`,style:e.branding?.primaryColor?{borderBottomColor:e.branding.primaryColor}:void 0,children:[e.branding?.logo&&(0,V.jsx)(`img`,{src:e.branding.logo,alt:`Logo`,className:`h-8 mb-4`}),e.title&&(0,V.jsx)(`h1`,{className:`text-xl font-semibold text-foreground`,children:e.title}),e.description&&(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e.description})]}),(0,V.jsxs)(`div`,{className:`p-6`,children:[c&&(0,V.jsx)(`div`,{className:`mb-4 p-3 bg-destructive/10 border border-destructive/30 rounded-md text-sm text-destructive`,children:c}),(0,V.jsx)($,{schema:{type:`object-form`,objectName:e.objectName,mode:`create`,fields:e.fields,customFields:e.customFields,initialData:u,onSuccess:d,submitLabel:o?`Submitting...`:`Submit`},dataSource:t})]}),(0,V.jsx)(`div`,{className:`px-6 py-3 border-t bg-muted/20 text-center`,children:(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Powered by ObjectStack`})})]})})};function fe(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:t,metrics:n,className:r})=>{let i=(0,B.useMemo)(()=>{if(!n.abandonedSubmissions)return 100;let e=n.totalSubmissions+n.abandonedSubmissions;return e===0?0:Math.round(n.totalSubmissions/e*100)},[n.totalSubmissions,n.abandonedSubmissions]),a=(0,B.useMemo)(()=>n.dailySubmissions?.length?Math.max(...n.dailySubmissions.map(e=>e.count),1):1,[n.dailySubmissions]);return(0,V.jsxs)(`div`,{className:`space-y-4 ${r||``}`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:t||`Form Analytics`}),(0,V.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Form ID: `,e]})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,V.jsx)(s,{children:(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Total Submissions`}),(0,V.jsx)(F,{className:`text-2xl`,children:n.totalSubmissions.toLocaleString()})]})}),(0,V.jsxs)(s,{children:[(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Fill Rate`}),(0,V.jsxs)(F,{className:`text-2xl`,children:[i,`%`]})]}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`w-full bg-muted rounded-full h-2`,children:(0,V.jsx)(`div`,{className:`bg-primary rounded-full h-2 transition-all`,style:{width:`${i}%`}})})})]}),(0,V.jsx)(s,{children:(0,V.jsxs)(k,{className:`pb-2`,children:[(0,V.jsx)(L,{children:`Avg. Completion Time`}),(0,V.jsx)(F,{className:`text-2xl`,children:n.avgCompletionTime?fe(n.avgCompletionTime):`—`})]})})]}),n.dailySubmissions&&n.dailySubmissions.length>0&&(0,V.jsxs)(s,{children:[(0,V.jsx)(k,{children:(0,V.jsx)(F,{className:`text-sm font-medium`,children:`Daily Submissions`})}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`flex items-end gap-1 h-32`,children:n.dailySubmissions.map((e,t)=>(0,V.jsxs)(`div`,{className:`flex-1 flex flex-col items-center gap-1`,children:[(0,V.jsx)(`div`,{className:`w-full bg-primary/80 rounded-t transition-all hover:bg-primary`,style:{height:`${e.count/a*100}%`,minHeight:e.count>0?`4px`:`0`},title:`${e.date}: ${e.count} submissions`}),(0,V.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate w-full text-center`,children:e.date.slice(-5)})]},t))})})]}),n.fieldDropOff&&n.fieldDropOff.length>0&&(0,V.jsxs)(s,{children:[(0,V.jsxs)(k,{children:[(0,V.jsx)(F,{className:`text-sm font-medium`,children:`Field Completion Rates`}),(0,V.jsx)(L,{children:`Percentage of users who completed each field`})]}),(0,V.jsx)(S,{children:(0,V.jsx)(`div`,{className:`space-y-3`,children:n.fieldDropOff.map((e,t)=>(0,V.jsxs)(`div`,{className:`space-y-1`,children:[(0,V.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,V.jsx)(`span`,{className:`text-foreground`,children:e.label}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completionRate,`%`]})]}),(0,V.jsx)(`div`,{className:`w-full bg-muted rounded-full h-1.5`,children:(0,V.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))})})]})]})},me=({schema:e})=>(0,V.jsx)($,{schema:e});i.register(`object-form`,me,{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`]}]}),i.register(`form`,me,{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`]}]}),i.register(`embeddable-form`,({schema:e})=>(0,V.jsx)(de,{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`}]}),i.register(`form-analytics`,({schema:e})=>(0,V.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`}]});export{Q as n,Y as r,$ as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,t as r}from"./vendor-react-B1k2FF9f.js";import{H as i,L as a,M as o,R as s,w as c}from"./framework-CoXA0nY6.js";import{t as l}from"./vendor-objectstack-CBpPY_xk.js";import{$A as u,$t as d,Cr as f,Mh as p,PL as m,Qt as h,Y as g,ZA as _,en as v,kM as y,kh as b,nn as x,rt as S,tn as C,um as w,xr as ee,yr as T}from"./ui-components-3HVEceOY.js";var E=t(n(),1),D=r();function O(e){return e<640?35:e<1024?50:60}function k(e){return e<640?120:e<1024?200:300}function te(e){return e<640?32:40}function A({tasks:e,viewMode:t=`month`,startDate:n,endDate:r,onTaskClick:i,onTaskUpdate:a,onViewChange:o,onAddClick:s,className:c,inlineEdit:l=!1}){let[S,A]=E.useState(new Date),j=E.useRef(null),{width:M}=g(j),N=M||(typeof window<`u`?window.innerWidth:1024),P=N<640,F=te(N),I=O(N),[ne,L]=E.useState(null),R=ne??I,[z,B]=E.useState(!1),V=E.useRef(!1);E.useEffect(()=>{!V.current&&P&&(B(!0),V.current=!0)},[P]);let H=z?0:k(N),[U,W]=E.useState(null),[G,K]=E.useState({}),q=E.useMemo(()=>{let t=n?new Date(n):new Date,i=r?new Date(r):new Date;return!n&&e.length>0&&(t=new Date(Math.min(...e.map(e=>e.start.getTime()))),t.setDate(t.getDate()-7)),!r&&e.length>0&&(i=new Date(Math.max(...e.map(e=>e.end.getTime()))),i.setDate(i.getDate()+14)),t.setHours(0,0,0,0),i.setHours(23,59,59,999),{start:t,end:i}},[n,r,e]),J=E.useMemo(()=>{let e=[],t=new Date(q.start);for(;t<=q.end;)e.push({date:new Date(t),label:t.getDate().toString(),isWeekend:t.getDay()===0||t.getDay()===6}),t.setDate(t.getDate()+1);return e},[q]),Y=E.useRef(null),X=E.useRef(null),re=E.useRef(null),Z=E.useRef(null),Q=E.useRef(null),ie=E.useCallback(e=>{if(e.touches.length===2){let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY;Q.current={baseDistance:Math.max(1,Math.sqrt(t*t+n*n)),baseColumn:R}}},[R]),ae=E.useCallback(e=>{if(e.touches.length!==2||!Q.current)return;let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY,r=Math.max(1,Math.sqrt(t*t+n*n))/Q.current.baseDistance;L(Math.max(15,Math.min(120,Math.round(Q.current.baseColumn*r))))},[]),oe=E.useCallback(()=>{Q.current=null},[]),$=E.useMemo(()=>{let e=new Date;if(e<q.start||e>q.end)return null;let t=(e.getTime()-q.start.getTime())/(1440*60*1e3);return Math.round(t*R)},[q,R]),se=E.useCallback(()=>{if($==null||!Z.current)return;let e=Math.max(0,$-Z.current.clientWidth/2);Z.current.scrollTo({left:e,behavior:`smooth`})},[$]),ce=e=>{Y.current&&(Y.current.scrollLeft=e.currentTarget.scrollLeft),X.current&&(X.current.scrollTop=e.currentTarget.scrollTop)},le=e=>{q.end.getTime()-q.start.getTime();let t=R,n=1e3*60*60*24,r=e.start.getTime()-q.start.getTime(),i=e.end.getTime()-e.start.getTime();return{left:r/n*t,width:Math.max(i/n*t,t)}};return(0,D.jsxs)(`div`,{ref:j,className:m(`flex flex-col h-full bg-background border rounded-lg overflow-hidden min-w-0`,c),children:[(0,D.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 p-2 border-b bg-card`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(T,{variant:`outline`,size:`sm`,onClick:()=>s?.(),"aria-label":`Create new task`,children:[(0,D.jsx)(w,{className:`h-4 w-4 mr-1 sm:mr-2`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`New Task`}),(0,D.jsx)(`span`,{className:`sm:hidden`,children:`New`})]}),(0,D.jsx)(`div`,{className:`h-4 w-px bg-border mx-1 sm:mx-2`}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":`Previous period`,children:(0,D.jsx)(u,{className:`h-4 w-4`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":`Next period`,children:(0,D.jsx)(_,{className:`h-4 w-4`})}),(0,D.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:q.start.toLocaleDateString(void 0,{month:`long`,year:`numeric`})})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(h,{value:t,onValueChange:e=>o?.(e),children:[(0,D.jsx)(C,{className:`w-[100px] sm:w-[120px] h-8`,children:(0,D.jsx)(x,{})}),(0,D.jsxs)(d,{children:[(0,D.jsx)(v,{value:`day`,children:`Day View`}),(0,D.jsx)(v,{value:`week`,children:`Week View`}),(0,D.jsx)(v,{value:`month`,children:`Month View`}),(0,D.jsx)(v,{value:`quarter`,children:`Quarter View`})]})]}),(0,D.jsxs)(`div`,{className:`flex bg-muted rounded-md p-1`,children:[(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>L(Math.max(15,R-10)),"aria-label":`Zoom out`,children:(0,D.jsx)(ee,{className:`h-3 w-3`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>L(Math.min(120,R+10)),"aria-label":`Zoom in`,children:(0,D.jsx)(f,{className:`h-3 w-3`})})]}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>B(e=>!e),"aria-label":z?`Show task list`:`Hide task list`,"aria-pressed":z,"data-testid":`gantt-toggle-task-list`,children:z?(0,D.jsx)(b,{className:`h-4 w-4`}):(0,D.jsx)(p,{className:`h-4 w-4`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:se,disabled:$==null,"aria-label":`Jump to today`,"data-testid":`gantt-jump-today`,children:(0,D.jsx)(y,{className:`h-4 w-4`})})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`flex border-b bg-muted/30 shrink-0 h-10 sm:h-[50px]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center font-medium text-xs text-muted-foreground px-2 sm:px-4 border-r bg-card z-20 shadow-sm`,style:{width:H,minWidth:H},children:[(0,D.jsx)(`div`,{className:`flex-1`,children:`Task Name`}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right hidden sm:block`,children:`Start`}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right hidden sm:block`,children:`End`})]}),(0,D.jsx)(`div`,{className:`flex-1 overflow-hidden`,ref:Y,children:(0,D.jsx)(`div`,{className:`flex h-full`,style:{width:J.length*R},children:J.map((e,t)=>(0,D.jsxs)(`div`,{className:m(`flex flex-col items-center justify-center border-r text-xs text-muted-foreground h-full`,e.isWeekend&&`bg-muted/50`),style:{width:R,minWidth:R},children:[(0,D.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,D.jsx)(`span`,{className:`text-[10px] opacity-70`,children:e.date.toLocaleDateString(void 0,{weekday:`narrow`})})]},t))})})]}),(0,D.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,D.jsx)(`div`,{className:`overflow-hidden border-r bg-card z-10 shadow-sm`,ref:X,style:{width:H,minWidth:H},children:e.map(e=>{let t=l&&U===e.id;return(0,D.jsxs)(`div`,{className:`flex items-center border-b px-2 sm:px-4 hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,style:{height:F},onClick:()=>!t&&i?.(e),onDoubleClick:()=>{l&&a&&(W(e.id),K({title:e.title,start:e.start.toLocaleDateString(`en-CA`),end:e.end.toLocaleDateString(`en-CA`),progress:String(e.progress)}))},children:[(0,D.jsxs)(`div`,{className:`flex-1 truncate font-medium text-xs sm:text-sm flex items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0`,style:{backgroundColor:e.color||`#3b82f6`}}),t?(0,D.jsx)(`input`,{className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.title||``,onChange:e=>K(t=>({...t,title:e.target.value})),onKeyDown:t=>{t.key===`Enter`?(a?.(e,{title:G.title,start:new Date(G.start),end:new Date(G.end),progress:Number(G.progress)||0}),W(null)):t.key===`Escape`&&W(null)},onClick:e=>e.stopPropagation(),autoFocus:!0}):(0,D.jsxs)(`span`,{className:`flex flex-col min-w-0`,children:[(0,D.jsx)(`span`,{className:`truncate`,children:e.title}),(0,D.jsxs)(`span`,{className:`text-[10px] text-muted-foreground sm:hidden`,children:[e.start.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`}),` → `,e.end.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})]})]})]}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right text-xs text-muted-foreground hidden sm:block`,children:t?(0,D.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.start||``,onChange:e=>K(t=>({...t,start:e.target.value})),onClick:e=>e.stopPropagation()}):e.start.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right text-xs text-muted-foreground hidden sm:block`,children:t?(0,D.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.end||``,onChange:e=>K(t=>({...t,end:e.target.value})),onClick:e=>e.stopPropagation()}):e.end.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})})]},e.id)})}),(0,D.jsx)(`div`,{className:`flex-1 overflow-auto bg-background/50 relative [-webkit-overflow-scrolling:touch]`,ref:e=>{re.current=e,Z.current=e},onScroll:ce,onTouchStart:ie,onTouchMove:ae,onTouchEnd:oe,"data-testid":`gantt-timeline`,children:(0,D.jsxs)(`div`,{className:`relative`,style:{width:J.length*R},children:[$!=null&&(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-red-500/80 z-20 pointer-events-none`,style:{left:$},"data-testid":`gantt-today-marker`,"aria-label":`Today`,children:(0,D.jsx)(`div`,{className:`absolute -top-2 -translate-x-1/2 left-0 text-[10px] font-semibold text-white bg-red-500 rounded-sm px-1 py-0.5 whitespace-nowrap`,children:`Today`})}),(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 flex pointer-events-none z-0`,children:J.map((e,t)=>(0,D.jsx)(`div`,{className:m(`border-r h-full`,e.isWeekend&&`bg-muted/20`),style:{width:R,minWidth:R}},t))}),e.map(e=>{let t=le(e);return(0,D.jsx)(`div`,{className:`relative border-b hover:bg-black/5`,style:{height:F},children:(0,D.jsxs)(`div`,{className:`absolute top-1 sm:top-2 h-[calc(100%-8px)] sm:h-[calc(100%-16px)] rounded-sm bg-primary border border-primary-foreground/20 shadow-sm cursor-pointer hover:brightness-110 flex items-center px-2 group`,style:{left:t.left,width:t.width,backgroundColor:e.color||`#3b82f6`},onClick:()=>i?.(e),children:[e.progress>0&&(0,D.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 bg-black/20 rounded-l-sm`,style:{width:`${e.progress}%`}}),(0,D.jsxs)(`span`,{className:`text-[10px] text-white font-medium truncate opacity-0 group-hover:opacity-100 transition-opacity`,children:[Math.round(e.progress),`%`]})]})},e.id)}),(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-red-500 z-20 pointer-events-none`,style:{left:(new Date().getTime()-q.start.getTime())/(1e3*60*60*24)*R},children:(0,D.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-red-500 -ml-[3px]`})})]})]})})]})]})]})}function j(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function M(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function N(e){let t=null;if(e.startDateField&&e.endDateField)return t={startDateField:e.startDateField,endDateField:e.endDateField,titleField:e.titleField||`name`,progressField:e.progressField,dependenciesField:e.dependenciesField||e.dependencyField,colorField:e.colorField},t;if(e.gantt&&(t=e.gantt),t){let e=l.safeParse(t);return e.success||console.warn(`[ObjectGantt] Invalid gantt configuration:`,e.error.format()),t}return null}var P=({schema:e,dataSource:t,className:n,onTaskClick:r,onRowClick:i,...o})=>{let[l,u]=(0,E.useState)([]),[d,f]=(0,E.useState)(!0),[p,m]=(0,E.useState)(null),[h,g]=(0,E.useState)(null),_=j(e),v=(0,E.useMemo)(()=>_,[JSON.stringify(_)]),y=N(e),b=v?.provider===`value`;(0,E.useEffect)(()=>{(async()=>{try{if(f(!0),o.data&&Array.isArray(o.data)){u(o.data),f(!1);return}if(b&&v?.provider===`value`){u(v.items),f(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(v?.provider===`object`){let n=v.object,r=a(h?.fields);u(s(await t.find(n,{$filter:e.filter,$orderby:M(e.sort),...r.length>0?{$expand:r}:{}})))}else v?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectGantt`),u([]));f(!1)}catch(e){m(e),f(!1)}})()},[v,t,b,e.filter,e.sort,h]),(0,E.useEffect)(()=>{!b&&t&&(async()=>{try{if(!t)return;let n=v?.provider===`object`?v.object:e.objectName;if(!n)return;g(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,b,v]);let x=(0,E.useMemo)(()=>{if(!y||!l.length)return[];let{startDateField:e,endDateField:t,titleField:n,progressField:r,dependenciesField:i,colorField:a}=y;return l.map((o,s)=>{let c=o[e],l=o[t],u=o[n]||`Untitled Task`,d=r?o[r]:0,f=i?o[i]:[],p=a?o[a]:void 0;return{id:o.id||o._id||`task-${s}`,title:u,start:c?new Date(c):new Date,end:l?new Date(l):new Date,progress:Math.min(100,Math.max(0,d||0)),dependencies:Array.isArray(f)?f:[],color:p,data:o}}).filter(e=>!isNaN(e.start.getTime())&&!isNaN(e.end.getTime()))},[l,y]),C=c({navigation:e.navigation,objectName:e.objectName,onRowClick:i});return d?(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading Gantt chart...`})})}):p?(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,p.message]})})}):y?(0,D.jsxs)(`div`,{className:n,children:[(0,D.jsx)(`div`,{className:`h-[calc(100vh-200px)] min-h-[600px]`,children:(0,D.jsx)(A,{tasks:x,onTaskClick:e=>{C.handleClick(e.data),r?.(e.data)},onAddClick:()=>{}})}),C.isOverlay&&(0,D.jsx)(S,{...C,title:`Task Details`,children:e=>(0,D.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,D.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]}):(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsx)(`div`,{className:`text-muted-foreground`,children:`Gantt configuration required. Please specify startDateField, endDateField, and titleField.`})})})},F=e({GanttView:()=>A,ObjectGantt:()=>P,ObjectGanttRenderer:()=>I}),I=({schema:e})=>{let{dataSource:t}=o()||{};return(0,D.jsx)(P,{schema:e,dataSource:t})};i.register(`object-gantt`,I,{namespace:`plugin-gantt`,label:`Object Gantt`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]}),i.register(`gantt`,I,{namespace:`view`,label:`Gantt View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]});export{F as t};
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,t as r}from"./vendor-react-B1k2FF9f.js";import{H as i,L as a,M as o,R as s,w as c}from"./framework-CoXA0nY6.js";import{t as l}from"./vendor-objectstack-CBpPY_xk.js";import{$A as u,$t as d,Cr as f,Mh as p,PL as m,Qt as h,Y as g,ZA as _,en as v,kM as y,kh as b,nn as x,rt as S,tn as C,um as w,xr as ee,yr as T}from"./ui-components-B7mlp0en.js";var E=t(n(),1),D=r();function O(e){return e<640?35:e<1024?50:60}function k(e){return e<640?120:e<1024?200:300}function te(e){return e<640?32:40}function A({tasks:e,viewMode:t=`month`,startDate:n,endDate:r,onTaskClick:i,onTaskUpdate:a,onViewChange:o,onAddClick:s,className:c,inlineEdit:l=!1}){let[S,A]=E.useState(new Date),j=E.useRef(null),{width:M}=g(j),N=M||(typeof window<`u`?window.innerWidth:1024),P=N<640,F=te(N),I=O(N),[ne,L]=E.useState(null),R=ne??I,[z,B]=E.useState(!1),V=E.useRef(!1);E.useEffect(()=>{!V.current&&P&&(B(!0),V.current=!0)},[P]);let H=z?0:k(N),[U,W]=E.useState(null),[G,K]=E.useState({}),q=E.useMemo(()=>{let t=n?new Date(n):new Date,i=r?new Date(r):new Date;return!n&&e.length>0&&(t=new Date(Math.min(...e.map(e=>e.start.getTime()))),t.setDate(t.getDate()-7)),!r&&e.length>0&&(i=new Date(Math.max(...e.map(e=>e.end.getTime()))),i.setDate(i.getDate()+14)),t.setHours(0,0,0,0),i.setHours(23,59,59,999),{start:t,end:i}},[n,r,e]),J=E.useMemo(()=>{let e=[],t=new Date(q.start);for(;t<=q.end;)e.push({date:new Date(t),label:t.getDate().toString(),isWeekend:t.getDay()===0||t.getDay()===6}),t.setDate(t.getDate()+1);return e},[q]),Y=E.useRef(null),X=E.useRef(null),re=E.useRef(null),Z=E.useRef(null),Q=E.useRef(null),ie=E.useCallback(e=>{if(e.touches.length===2){let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY;Q.current={baseDistance:Math.max(1,Math.sqrt(t*t+n*n)),baseColumn:R}}},[R]),ae=E.useCallback(e=>{if(e.touches.length!==2||!Q.current)return;let t=e.touches[0].clientX-e.touches[1].clientX,n=e.touches[0].clientY-e.touches[1].clientY,r=Math.max(1,Math.sqrt(t*t+n*n))/Q.current.baseDistance;L(Math.max(15,Math.min(120,Math.round(Q.current.baseColumn*r))))},[]),oe=E.useCallback(()=>{Q.current=null},[]),$=E.useMemo(()=>{let e=new Date;if(e<q.start||e>q.end)return null;let t=(e.getTime()-q.start.getTime())/(1440*60*1e3);return Math.round(t*R)},[q,R]),se=E.useCallback(()=>{if($==null||!Z.current)return;let e=Math.max(0,$-Z.current.clientWidth/2);Z.current.scrollTo({left:e,behavior:`smooth`})},[$]),ce=e=>{Y.current&&(Y.current.scrollLeft=e.currentTarget.scrollLeft),X.current&&(X.current.scrollTop=e.currentTarget.scrollTop)},le=e=>{q.end.getTime()-q.start.getTime();let t=R,n=1e3*60*60*24,r=e.start.getTime()-q.start.getTime(),i=e.end.getTime()-e.start.getTime();return{left:r/n*t,width:Math.max(i/n*t,t)}};return(0,D.jsxs)(`div`,{ref:j,className:m(`flex flex-col h-full bg-background border rounded-lg overflow-hidden min-w-0`,c),children:[(0,D.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-2 p-2 border-b bg-card`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(T,{variant:`outline`,size:`sm`,onClick:()=>s?.(),"aria-label":`Create new task`,children:[(0,D.jsx)(w,{className:`h-4 w-4 mr-1 sm:mr-2`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`New Task`}),(0,D.jsx)(`span`,{className:`sm:hidden`,children:`New`})]}),(0,D.jsx)(`div`,{className:`h-4 w-px bg-border mx-1 sm:mx-2`}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":`Previous period`,children:(0,D.jsx)(u,{className:`h-4 w-4`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,"aria-label":`Next period`,children:(0,D.jsx)(_,{className:`h-4 w-4`})}),(0,D.jsx)(`span`,{className:`font-semibold text-xs sm:text-sm`,children:q.start.toLocaleDateString(void 0,{month:`long`,year:`numeric`})})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(h,{value:t,onValueChange:e=>o?.(e),children:[(0,D.jsx)(C,{className:`w-[100px] sm:w-[120px] h-8`,children:(0,D.jsx)(x,{})}),(0,D.jsxs)(d,{children:[(0,D.jsx)(v,{value:`day`,children:`Day View`}),(0,D.jsx)(v,{value:`week`,children:`Week View`}),(0,D.jsx)(v,{value:`month`,children:`Month View`}),(0,D.jsx)(v,{value:`quarter`,children:`Quarter View`})]})]}),(0,D.jsxs)(`div`,{className:`flex bg-muted rounded-md p-1`,children:[(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>L(Math.max(15,R-10)),"aria-label":`Zoom out`,children:(0,D.jsx)(ee,{className:`h-3 w-3`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>L(Math.min(120,R+10)),"aria-label":`Zoom in`,children:(0,D.jsx)(f,{className:`h-3 w-3`})})]}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>B(e=>!e),"aria-label":z?`Show task list`:`Hide task list`,"aria-pressed":z,"data-testid":`gantt-toggle-task-list`,children:z?(0,D.jsx)(b,{className:`h-4 w-4`}):(0,D.jsx)(p,{className:`h-4 w-4`})}),(0,D.jsx)(T,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:se,disabled:$==null,"aria-label":`Jump to today`,"data-testid":`gantt-jump-today`,children:(0,D.jsx)(y,{className:`h-4 w-4`})})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,D.jsxs)(`div`,{className:`flex border-b bg-muted/30 shrink-0 h-10 sm:h-[50px]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center font-medium text-xs text-muted-foreground px-2 sm:px-4 border-r bg-card z-20 shadow-sm`,style:{width:H,minWidth:H},children:[(0,D.jsx)(`div`,{className:`flex-1`,children:`Task Name`}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right hidden sm:block`,children:`Start`}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right hidden sm:block`,children:`End`})]}),(0,D.jsx)(`div`,{className:`flex-1 overflow-hidden`,ref:Y,children:(0,D.jsx)(`div`,{className:`flex h-full`,style:{width:J.length*R},children:J.map((e,t)=>(0,D.jsxs)(`div`,{className:m(`flex flex-col items-center justify-center border-r text-xs text-muted-foreground h-full`,e.isWeekend&&`bg-muted/50`),style:{width:R,minWidth:R},children:[(0,D.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),(0,D.jsx)(`span`,{className:`text-[10px] opacity-70`,children:e.date.toLocaleDateString(void 0,{weekday:`narrow`})})]},t))})})]}),(0,D.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,D.jsx)(`div`,{className:`overflow-hidden border-r bg-card z-10 shadow-sm`,ref:X,style:{width:H,minWidth:H},children:e.map(e=>{let t=l&&U===e.id;return(0,D.jsxs)(`div`,{className:`flex items-center border-b px-2 sm:px-4 hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,style:{height:F},onClick:()=>!t&&i?.(e),onDoubleClick:()=>{l&&a&&(W(e.id),K({title:e.title,start:e.start.toLocaleDateString(`en-CA`),end:e.end.toLocaleDateString(`en-CA`),progress:String(e.progress)}))},children:[(0,D.jsxs)(`div`,{className:`flex-1 truncate font-medium text-xs sm:text-sm flex items-center gap-2`,children:[(0,D.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0`,style:{backgroundColor:e.color||`#3b82f6`}}),t?(0,D.jsx)(`input`,{className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.title||``,onChange:e=>K(t=>({...t,title:e.target.value})),onKeyDown:t=>{t.key===`Enter`?(a?.(e,{title:G.title,start:new Date(G.start),end:new Date(G.end),progress:Number(G.progress)||0}),W(null)):t.key===`Escape`&&W(null)},onClick:e=>e.stopPropagation(),autoFocus:!0}):(0,D.jsxs)(`span`,{className:`flex flex-col min-w-0`,children:[(0,D.jsx)(`span`,{className:`truncate`,children:e.title}),(0,D.jsxs)(`span`,{className:`text-[10px] text-muted-foreground sm:hidden`,children:[e.start.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`}),` → `,e.end.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})]})]})]}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right text-xs text-muted-foreground hidden sm:block`,children:t?(0,D.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.start||``,onChange:e=>K(t=>({...t,start:e.target.value})),onClick:e=>e.stopPropagation()}):e.start.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})}),(0,D.jsx)(`div`,{className:`w-16 sm:w-20 text-right text-xs text-muted-foreground hidden sm:block`,children:t?(0,D.jsx)(`input`,{type:`date`,className:`border rounded px-1 py-0.5 text-xs w-full bg-background`,value:G.end||``,onChange:e=>K(t=>({...t,end:e.target.value})),onClick:e=>e.stopPropagation()}):e.end.toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})})]},e.id)})}),(0,D.jsx)(`div`,{className:`flex-1 overflow-auto bg-background/50 relative [-webkit-overflow-scrolling:touch]`,ref:e=>{re.current=e,Z.current=e},onScroll:ce,onTouchStart:ie,onTouchMove:ae,onTouchEnd:oe,"data-testid":`gantt-timeline`,children:(0,D.jsxs)(`div`,{className:`relative`,style:{width:J.length*R},children:[$!=null&&(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-red-500/80 z-20 pointer-events-none`,style:{left:$},"data-testid":`gantt-today-marker`,"aria-label":`Today`,children:(0,D.jsx)(`div`,{className:`absolute -top-2 -translate-x-1/2 left-0 text-[10px] font-semibold text-white bg-red-500 rounded-sm px-1 py-0.5 whitespace-nowrap`,children:`Today`})}),(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 flex pointer-events-none z-0`,children:J.map((e,t)=>(0,D.jsx)(`div`,{className:m(`border-r h-full`,e.isWeekend&&`bg-muted/20`),style:{width:R,minWidth:R}},t))}),e.map(e=>{let t=le(e);return(0,D.jsx)(`div`,{className:`relative border-b hover:bg-black/5`,style:{height:F},children:(0,D.jsxs)(`div`,{className:`absolute top-1 sm:top-2 h-[calc(100%-8px)] sm:h-[calc(100%-16px)] rounded-sm bg-primary border border-primary-foreground/20 shadow-sm cursor-pointer hover:brightness-110 flex items-center px-2 group`,style:{left:t.left,width:t.width,backgroundColor:e.color||`#3b82f6`},onClick:()=>i?.(e),children:[e.progress>0&&(0,D.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 bg-black/20 rounded-l-sm`,style:{width:`${e.progress}%`}}),(0,D.jsxs)(`span`,{className:`text-[10px] text-white font-medium truncate opacity-0 group-hover:opacity-100 transition-opacity`,children:[Math.round(e.progress),`%`]})]})},e.id)}),(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-red-500 z-20 pointer-events-none`,style:{left:(new Date().getTime()-q.start.getTime())/(1e3*60*60*24)*R},children:(0,D.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-red-500 -ml-[3px]`})})]})]})})]})]})]})}function j(e){return e.data?e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function M(e){if(e){if(typeof e==`string`){let t=e.split(` `),n=t[0],r=t[1]?.toLowerCase()===`desc`?`desc`:`asc`;return{[n]:r}}if(Array.isArray(e))return e.reduce((e,t)=>(t.field&&t.order&&(e[t.field]=t.order),e),{})}}function N(e){let t=null;if(e.startDateField&&e.endDateField)return t={startDateField:e.startDateField,endDateField:e.endDateField,titleField:e.titleField||`name`,progressField:e.progressField,dependenciesField:e.dependenciesField||e.dependencyField,colorField:e.colorField},t;if(e.gantt&&(t=e.gantt),t){let e=l.safeParse(t);return e.success||console.warn(`[ObjectGantt] Invalid gantt configuration:`,e.error.format()),t}return null}var P=({schema:e,dataSource:t,className:n,onTaskClick:r,onRowClick:i,...o})=>{let[l,u]=(0,E.useState)([]),[d,f]=(0,E.useState)(!0),[p,m]=(0,E.useState)(null),[h,g]=(0,E.useState)(null),_=j(e),v=(0,E.useMemo)(()=>_,[JSON.stringify(_)]),y=N(e),b=v?.provider===`value`;(0,E.useEffect)(()=>{(async()=>{try{if(f(!0),o.data&&Array.isArray(o.data)){u(o.data),f(!1);return}if(b&&v?.provider===`value`){u(v.items),f(!1);return}if(!t||typeof t.find!=`function`)throw Error(`DataSource required for object/api providers`);if(v?.provider===`object`){let n=v.object,r=a(h?.fields);u(s(await t.find(n,{$filter:e.filter,$orderby:M(e.sort),...r.length>0?{$expand:r}:{}})))}else v?.provider===`api`&&(console.warn(`API provider not yet implemented for ObjectGantt`),u([]));f(!1)}catch(e){m(e),f(!1)}})()},[v,t,b,e.filter,e.sort,h]),(0,E.useEffect)(()=>{!b&&t&&(async()=>{try{if(!t)return;let n=v?.provider===`object`?v.object:e.objectName;if(!n)return;g(await t.getObjectSchema(n))}catch(e){console.error(`Failed to fetch object schema:`,e)}})()},[e.objectName,t,b,v]);let x=(0,E.useMemo)(()=>{if(!y||!l.length)return[];let{startDateField:e,endDateField:t,titleField:n,progressField:r,dependenciesField:i,colorField:a}=y;return l.map((o,s)=>{let c=o[e],l=o[t],u=o[n]||`Untitled Task`,d=r?o[r]:0,f=i?o[i]:[],p=a?o[a]:void 0;return{id:o.id||o._id||`task-${s}`,title:u,start:c?new Date(c):new Date,end:l?new Date(l):new Date,progress:Math.min(100,Math.max(0,d||0)),dependencies:Array.isArray(f)?f:[],color:p,data:o}}).filter(e=>!isNaN(e.start.getTime())&&!isNaN(e.end.getTime()))},[l,y]),C=c({navigation:e.navigation,objectName:e.objectName,onRowClick:i});return d?(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsx)(`div`,{className:`text-muted-foreground`,children:`Loading Gantt chart...`})})}):p?(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsxs)(`div`,{className:`text-destructive`,children:[`Error: `,p.message]})})}):y?(0,D.jsxs)(`div`,{className:n,children:[(0,D.jsx)(`div`,{className:`h-[calc(100vh-200px)] min-h-[600px]`,children:(0,D.jsx)(A,{tasks:x,onTaskClick:e=>{C.handleClick(e.data),r?.(e.data)},onAddClick:()=>{}})}),C.isOverlay&&(0,D.jsx)(S,{...C,title:`Task Details`,children:e=>(0,D.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,D.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]}):(0,D.jsx)(`div`,{className:n,children:(0,D.jsx)(`div`,{className:`flex items-center justify-center h-96`,children:(0,D.jsx)(`div`,{className:`text-muted-foreground`,children:`Gantt configuration required. Please specify startDateField, endDateField, and titleField.`})})})},F=e({GanttView:()=>A,ObjectGantt:()=>P,ObjectGanttRenderer:()=>I}),I=({schema:e})=>{let{dataSource:t}=o()||{};return(0,D.jsx)(P,{schema:e,dataSource:t})};i.register(`object-gantt`,I,{namespace:`plugin-gantt`,label:`Object Gantt`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]}),i.register(`gantt`,I,{namespace:`view`,label:`Gantt View`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`gantt`,type:`object`,label:`Gantt Config`,description:`startDateField, endDateField, titleField, progressField, percentageField, colorField, dependenciesField`}]});export{F as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,g as n,t as r}from"./vendor-react-B1k2FF9f.js";import{D as i,H as a,I as o,L as s,M as c,_ as l,a as u,j as d,w as f}from"./framework-CoXA0nY6.js";import{f as p}from"./infrastructure-Djv3I7gr.js";import{$ as m,$t as h,Af as ee,Ct as g,Ef as _,El as v,Gn as te,IA as ne,J as re,Jn as y,Kn as ie,Of as ae,PL as b,Qt as x,Sn as oe,St as S,TA as C,TE as w,Ta as T,Un as E,Va as D,Vr as se,Wn as ce,ZA as O,Zc as k,a as A,ar as j,bt as M,c as N,cI as le,cn as ue,dn as P,en as de,fS as fe,ff as pe,gn as F,i as me,ks as he,l as I,ln as ge,ls as _e,mM as ve,mT as L,mn as ye,mo as be,nn as xe,pn as Se,qE as Ce,qn as R,r as we,ra as Te,rj as Ee,rk as De,rt as Oe,s as ke,sn as Ae,st as je,tI as Me,tn as Ne,un as Pe,vt as Fe,xt as z,yr as B,yt as V}from"./ui-components-3HVEceOY.js";var H=e(t(),1),Ie={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},U=[`xs`,`sm`,`md`,`lg`,`xl`,`2xl`];function W(e){for(let t=U.length-1;t>=0;t--){let n=U[t];if(e>=Ie[n])return n}return`xs`}function G(){let[e,t]=(0,H.useState)(()=>typeof window<`u`?window.innerWidth:1024);(0,H.useEffect)(()=>{if(typeof window>`u`)return;let e,n=()=>{clearTimeout(e),e=setTimeout(()=>{t(window.innerWidth)},100)};return window.addEventListener(`resize`,n),()=>{clearTimeout(e),window.removeEventListener(`resize`,n)}},[]);let n=W(e),r=U.indexOf(n);return{breakpoint:n,width:e,isMobile:r<U.indexOf(`md`),isTablet:r>=U.indexOf(`md`)&&r<U.indexOf(`lg`),isDesktop:r>=U.indexOf(`lg`),isAbove:t=>e>=Ie[t],isBelow:t=>e<Ie[t]}}function Le(e){let{onRefresh:t,threshold:n=80,enabled:r=!0}=e,i=(0,H.useRef)(null),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(0),l=(0,H.useRef)(0),u=(0,H.useCallback)(e=>{if(!r||a)return;let t=i.current;t&&t.scrollTop===0&&(l.current=e.touches[0].clientY)},[r,a]),d=(0,H.useCallback)(e=>{if(!r||a||!l.current)return;let t=e.touches[0].clientY-l.current;t>0&&c(Math.min(t,n*1.5))},[r,a,n]),f=(0,H.useCallback)(async()=>{if(!r||a)return;let e=s;if(c(0),l.current=0,e>=n){o(!0);try{await t()}finally{o(!1)}}},[r,a,s,n,t]);return(0,H.useEffect)(()=>{let e=i.current;if(!(!e||!r))return e.addEventListener(`touchstart`,u,{passive:!0}),e.addEventListener(`touchmove`,d,{passive:!0}),e.addEventListener(`touchend`,f,{passive:!0}),()=>{e.removeEventListener(`touchstart`,u),e.removeEventListener(`touchmove`,d),e.removeEventListener(`touchend`,f)}},[u,d,f,r]),{ref:i,isRefreshing:a,pullDistance:s}}var K=r(),q=(0,H.createContext)(null);q.displayName=`MobileContext`;function J({pwa:e,offline:t,children:n}){let r=G(),i=(0,H.useMemo)(()=>({...r,pwa:e,offline:t}),[r,e,t]);return(0,K.jsx)(q.Provider,{value:i,children:n})}var Re={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function Y(e){return e.startsWith(`bg-`)?e:Re[e.toLowerCase().trim()]}function ze(e){return(0,H.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return Y(r)},[e?.field,e?.colors])}function Be(e){if(e==null||e===``)return``;if(Array.isArray(e))return e.map(e=>Be(e)).join(`|`);if(typeof e==`object`){let t=e.id??e._id??e.pk??e.value;if(t!=null&&t!==``)return String(t);let n=e.name??e.label??e.title;if(n!=null&&n!==``)return String(n);try{return JSON.stringify(e)}catch{return``}}return String(e)}function Ve(e,t){return Be(e[t])}function X(e,t,n){if(e==null||e===``)return`(empty)`;if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}if(Array.isArray(e))return e.map(e=>{if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}return X(e,t)}).join(`, `)||`(empty)`;if(typeof e==`object`){let t=e.name??e.label??e.title??e.display_name??e.displayName??e.fullName??e.full_name;if(t!=null&&t!==``)return String(t);let n=e.id??e._id??e.pk;return n!=null&&n!==``?String(n):`(empty)`}return String(e)}function He(e,t){return t.map(({field:t,type:n})=>{let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`count`:i=r.length;break;case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function Ue(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function We(e,t,n,r){let i=e?.fields,a=!!(i&&i.length>0),[o,s]=(0,H.useState)({});return{groups:(0,H.useMemo)(()=>{if(!a||!i)return[];let e=(t,a,s)=>{if(a>=i.length)return[];let c=i[a],l=new Map,u=[];for(let e of t){let t=Ve(e,c.field);l.has(t)||(l.set(t,{label:X(e[c.field],c.field,r),rows:[]}),u.push(t)),l.get(t).rows.push(e)}let d=c.order??`asc`;return u.sort((e,t)=>Ue(l.get(e)?.label??e,l.get(t)?.label??t,d)),u.map(t=>{let r=l.get(t),u=s?`${s}__${a}:${t}`:`${a}:${t}`,d=!!c.collapsed,f=u in o?o[u]:d,p=n&&n.length>0?He(r.rows,n):[],m=a+1<i.length?e(r.rows,a+1,u):[];return{key:u,label:r.label,field:c.field,depth:a,rows:r.rows,collapsed:f,aggregations:p,subgroups:m}})};return e(t,0,``)},[t,i,a,o,n,r]),isGrouped:a,toggleGroup:(0,H.useCallback)(e=>{s(t=>{let n=e.split(`__`).pop()||``,r=/^(\d+):/.exec(n),a=r?Number(r[1]):0,o=!!i?.[a]?.collapsed;return{...t,[e]:t[e]===void 0?!o:!t[e]}})},[i])}}var Ge=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,onToggle:a,children:o})=>(0,K.jsxs)(`div`,{className:`border rounded-md`,"data-testid":`group-row-${e}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors`,onClick:()=>a(e),"aria-expanded":!r,children:[r?(0,K.jsx)(O,{className:`h-4 w-4 shrink-0`}):(0,K.jsx)(Ee,{className:`h-4 w-4 shrink-0`}),(0,K.jsx)(`span`,{className:`group-label`,children:t}),i&&i.length>0&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,K.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))}),(0,K.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground group-count`,children:[`(`,n,`)`]})]}),!r&&o]});function Ke(e){return typeof e==`string`?{type:e}:e}function qe(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function Je(e,t){return t===null?``:`${{count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e}: ${e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString()}`}function Ye(e,t){return(0,H.useMemo)(()=>{let n=new Map;if(!e||e.length===0||t.length===0)return{summaries:n,hasSummary:!1};for(let r of e){if(!r.summary)continue;let e=Ke(r.summary),i=e.field||r.field,a=[];for(let e of t){let t=e[i];if(t!=null&&typeof t==`number`&&!isNaN(t))a.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||a.push(e)}}let o;if(e.type===`count`){let e=t.filter(e=>e[i]!=null&&e[i]!==``).length;o=e>0?e:null}else o=qe(e.type,a);n.set(r.field,{field:r.field,value:o,label:Je(e.type,o)})}return{summaries:n,hasSummary:n.size>0}},[e,t])}function Xe(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var Ze=({row:e,rowActions:t,canEdit:n,canDelete:r,onEdit:i,onDelete:a,onAction:o})=>(0,K.jsxs)(Se,{children:[(0,K.jsx)(oe,{asChild:!0,children:(0,K.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,K.jsx)(w,{className:`h-4 w-4`}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Open menu`})]})}),(0,K.jsxs)(ye,{align:`end`,children:[n&&i&&(0,K.jsxs)(F,{onClick:()=>i(e),children:[(0,K.jsx)(k,{className:`mr-2 h-4 w-4`}),`Edit`]}),r&&a&&(0,K.jsxs)(F,{onClick:()=>a(e),children:[(0,K.jsx)(be,{className:`mr-2 h-4 w-4`}),`Delete`]}),t?.map(t=>(0,K.jsx)(F,{onClick:()=>o?.(t,e),"data-testid":`row-action-${t}`,children:Xe(t)},t))]})]}),Qe=({selectedRows:e,actions:t,onAction:n,onClearSelection:r})=>!t||t.length===0||e.length===0?null:(0,K.jsxs)(`div`,{className:`border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0`,"data-testid":`bulk-actions-bar`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground font-medium`,children:[e.length,` selected`]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 ml-2`,children:t.map(t=>(0,K.jsx)(B,{variant:`outline`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>n?.(t,e),"data-testid":`bulk-action-${t}`,children:Xe(t)},t))}),(0,K.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs ml-auto`,onClick:r,children:`Clear`})]}),$e={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`};function et(){try{let e=u();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=$e[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=$e[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function tt(e){if(e!=null)return typeof e==`string`?e:void 0}function nt(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function rt(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var it=({schema:e,dataSource:t,onEdit:n,onDelete:r,onRowSelect:a,onRowClick:c,onCellChange:u,onRowSave:h,onBatchSave:g,onAddRecord:te,...ne})=>{let[y,ie]=(0,H.useState)([]),[b,x]=(0,H.useState)(!0),[oe,S]=(0,H.useState)(null),{t:C}=et(),{fieldLabel:w,translateOptions:T}=p(),[E,se]=(0,H.useState)(null),[ce,O]=(0,H.useState)(!1),[k,M]=(0,H.useState)(0),[le,P]=(0,H.useState)(!1),[de,pe]=(0,H.useState)(!1),F=re({dataSource:t}),[L,ye]=(0,H.useState)(e.rowHeight??`compact`),[be,xe]=(0,H.useState)([]),Se=H.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[R,Ee]=(0,H.useState)(()=>{try{let e=localStorage.getItem(Se);return e?JSON.parse(e):{}}catch{return{}}}),Ae=(0,H.useCallback)(e=>{Ee(e);try{localStorage.setItem(Se,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}},[Se]),{ref:Me,isRefreshing:Ne,pullDistance:Fe}=Le({onRefresh:(0,H.useCallback)(async()=>{M(e=>e+1)},[]),enabled:!!t&&!!e.objectName});(0,H.useEffect)(()=>{let e=()=>O(window.innerWidth<480);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let z=ne.data,V=d(e.bind),Ie=nt(e),U=H.useMemo(()=>z&&Array.isArray(z)?{provider:`value`,items:z}:V&&Array.isArray(V)?{provider:`value`,items:V}:Ie,[JSON.stringify(Ie),V,z]),W=U?.provider===`value`,G=U?.provider===`object`&&U&&`object`in U?U.object:e.objectName,q=e.fields,J=e.columns,Re=e.filter,Y=e.sort,Be=e.pagination,Ve=e.pageSize;(0,H.useEffect)(()=>{W&&U?.provider===`value`&&(ie(e=>{let t=U.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),x(!1))},[W,U]),(0,H.useEffect)(()=>{if(!W||!G||!t)return;let e=!1;return(async()=>{try{if(typeof t.getObjectSchema!=`function`)return;let n=await t.getObjectSchema(G);e||se(n)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${G}):`,e)}})(),()=>{e=!0}},[W,G,t]),(0,H.useEffect)(()=>{if(W)return;let n=!1;return(async()=>{x(!0),S(null);try{let r=null,i=rt(J)||q;if(G&&t)if(typeof t.getObjectSchema==`function`){let e=await t.getObjectSchema(G);if(n)return;r=e}else r={name:G,fields:{}};else if(i&&G)r={name:G,fields:{}};else if(G)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(n||se(r),t&&G){let i={$select:(()=>{if(q)return q;if(J&&Array.isArray(J))return J.map(e=>typeof e==`string`?e:e.field)})(),$top:Be?.pageSize||Ve||50};Re&&Array.isArray(Re)?i.$filter=Re:e.defaultFilters&&(i.$filter=e.defaultFilters),Y?typeof Y==`string`?i.$orderby=Y:Array.isArray(Y)&&(i.$orderby=Y.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=s(r?.fields,J??q);a.length>0&&(i.$expand=a);let o=await t.find(G,i);if(n)return;ie(o.data||[])}}catch(e){n||S(e)}finally{n||x(!1)}})(),()=>{n=!0}},[G,q,J,Re,Y,Be,Ve,t,W,U,k]);let X=f({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:c}),{execute:He}=l(),Ue=ze(e.rowColor),Ke=(0,H.useCallback)(t=>{let n=e.conditionalFormatting;if(!(!n||n.length===0))for(let e of n){let n=!1,r=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(r)n=o(r,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let r=e,i=t[r.field];switch(r.operator){case`equals`:n=i===r.value;break;case`not_equals`:n=i!==r.value;break;case`contains`:n=typeof i==`string`&&typeof r.value==`string`&&i.includes(r.value);break;case`greater_than`:n=typeof i==`number`&&typeof r.value==`number`&&i>r.value;break;case`less_than`:n=typeof i==`number`&&typeof r.value==`number`&&i<r.value;break;case`in`:n=Array.isArray(r.value)&&r.value.includes(i);break}}if(n){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),qe=H.useMemo(()=>{let t=e.grouping;if(!t?.fields?.length)return;let n=new Map;for(let r of t.fields){let t=r.field,i=E?.fields?.[t],a=rt(e.columns)?.find?.(e=>typeof e==`object`&&e?.field===t),o=a?.type||i?.type,s=a?.options||i?.options,c=new Map;if(Array.isArray(s)&&s.length>0){let n=e.objectName?T(e.objectName,t,s):s;for(let e of n)if(e&&e.value!==void 0&&e.value!==null){let t=e.label;c.set(String(e.value),String(t??e.value))}}n.set(t,{type:o||void 0,options:c.size>0?c:void 0})}return(e,t)=>{let r=n.get(e);if(r){if(r.options){let e=r.options.get(String(t));if(e!==void 0)return e}if(r.type===`boolean`||typeof t==`boolean`){if(t===!0||t===`true`)return C(`grid.booleanTrue`,`Yes`);if(t===!1||t===`false`)return C(`grid.booleanFalse`,`No`)}}}},[e.grouping,e.columns,e.objectName,E,T,C]),{groups:Je,isGrouped:$e,toggleGroup:it}=We(e.grouping,y,void 0,qe),{summaries:at,hasSummary:Z}=Ye(H.useMemo(()=>{let t=rt(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),y),Q=(0,H.useCallback)(()=>{let t=e=>e&&{text:(0,K.jsx)(D,{className:`h-3.5 w-3.5`}),number:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),currency:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),percent:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),date:(0,K.jsx)(ve,{className:`h-3.5 w-3.5`}),datetime:(0,K.jsx)(De,{className:`h-3.5 w-3.5`}),boolean:(0,K.jsx)(v,{className:`h-3.5 w-3.5`}),user:(0,K.jsx)(Te,{className:`h-3.5 w-3.5`}),select:(0,K.jsx)(he,{className:`h-3.5 w-3.5`})}[e]||(0,K.jsx)(D,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(y.length>0){let t=y.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&y.length>0&&typeof y.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&y.length>0){let t=new Set(y.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&y.length>0&&typeof y.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(y.length>0){let t=y.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=rt(J);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let i=r[0];if(`accessorKey`in i)return r.map(r=>{if(r.cell)return r;let i=n({field:r.accessorKey,label:r.header,type:r.type});if(!i)return r;let a=N(i),o={name:r.accessorKey,type:i};return i===`select`&&(o.options=Array.from(new Set(y.map(e=>e[r.accessorKey]).filter(Boolean))).map(e=>({value:e,label:I(String(e))}))),{...r,...e.showColumnTypeIcons&&{headerIcon:t(i)},cell:e=>(0,K.jsx)(a,{value:e,field:o})}});if(`field`in i)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,i)=>{let a=tt(r.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),o=e.objectName?w(e.objectName,r.field,a):a,s,c=E?.fields?.[r.field],l=r.type||c?.type||n({field:r.field})||null,u=l?N(l):null,d={name:r.field,type:l||`text`};c&&(c.label&&(d.label=c.label),c.currency&&(d.currency=c.currency),c.precision!==void 0&&(d.precision=c.precision),c.format&&(d.format=c.format),c.options&&(d.options=T(e.objectName,r.field,c.options))),l===`select`&&!d.options&&(d.options=Array.from(new Set(y.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:I(String(e))}))),r.options&&(d.options=T(e.objectName,r.field,r.options));let f=i===0&&!r.link&&!r.action,p=r.link||f;s=r.link&&r.action||f&&r.action||p?(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":f?`primary-field-link`:`link-cell`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:u?(0,K.jsx)(u,{value:e,field:d}):e!=null&&e!==``?String(e):(0,K.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):r.action?(e,t)=>(0,K.jsx)(B,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),He({type:r.action,params:{record:t,field:r.field,value:e}})},children:Xe(r.action)}):u?e=>(0,K.jsx)(u,{value:e,field:d}):e=>e!=null&&e!==``?(0,K.jsx)(`span`,{children:String(e)}):(0,K.jsx)(je,{});let m=r.prefix;if(m?.field){let e=s,t=m.type===`badge`?N(`select`):null;s=(n,r)=>{let i=r[m.field];return(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,K.jsx)(t,{value:i,field:{name:m.field,type:`select`}}):(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let h=[`number`,`currency`,`percent`],ee=l||r.type,g=r.align||(ee&&h.includes(ee)?`right`:void 0),_=i===0||r.essential===!0;return{header:o,accessorKey:r.field,...e.showColumnTypeIcons&&{headerIcon:t(l)},...!_&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...g&&{align:g},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...s&&{cell:s},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,i)=>{let a=E?.fields?.[r],o=a?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),s=e.objectName?w(e.objectName,r,o):o,c=a?.type||n({field:r})||null,l=c?N(c):null,u={name:r,type:c||`text`};a&&(a.label&&(u.label=a.label),a.currency&&(u.currency=a.currency),a.precision!==void 0&&(u.precision=a.precision),a.format&&(u.format=a.format),a.options&&(u.options=T(e.objectName,r,a.options))),c===`select`&&!u.options&&(u.options=Array.from(new Set(y.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:I(String(e))})));let d=c&&[`number`,`currency`,`percent`].includes(c)?`right`:void 0,f=i===0,p;return f&&l?p=(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:(0,K.jsx)(l,{value:e,field:u})}):f?p=(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:e!=null&&e!==``?String(e):(0,K.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):l&&(p=e=>(0,K.jsx)(l,{value:e,field:u})),{header:s,accessorKey:r,...e.showColumnTypeIcons&&c&&{headerIcon:t(c)},...d&&{align:d},...p&&{cell:p},sortable:a?.sortable!==!1}})}if(W){let r=U?.provider===`value`?U.items:[];if(r.length>0)return(q||Object.keys(r[0])).map(r=>{let i=E?.fields?.[r],a=i?.type||n({field:r})||null,o=a?N(a):null,s=i?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),c={name:r,type:a||`text`};i&&(i.label&&(c.label=i.label),i.currency&&(c.currency=i.currency),i.precision!==void 0&&(c.precision=i.precision),i.format&&(c.format=i.format),i.options&&(c.options=T(e.objectName,r,i.options))),a===`select`&&!c.options&&(c.options=Array.from(new Set(y.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:I(String(e))})));let l=a&&[`number`,`currency`,`percent`].includes(a)?`right`:void 0;return{header:s,accessorKey:r,...e.showColumnTypeIcons&&a&&{headerIcon:t(a)},...l&&{align:l},...o&&{cell:e=>(0,K.jsx)(o,{value:e,field:c})},sortable:i?.sortable!==!1}})}if(!E)return[];let i=[],a=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),o=E?.compactLayout,s=Object.keys(E.fields||{}),c;if(q)c=q;else if(o?.length)c=o.filter(e=>E.fields?.[e]);else{let e=s.filter(e=>{let t=E.fields?.[e];return!(!t||t.hidden||t.readonly&&a.has(e))});c=[...e.filter(e=>!a.has(e)),...e.filter(e=>a.has(e))]}return c.forEach(t=>{let n=E.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=N(n.type),a=[`number`,`currency`,`percent`],o=n.options?{...n,options:T(e.objectName,t,n.options)}:n;i.push({header:e.objectName?w(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...a.includes(n.type)&&{align:`right`},cell:e=>(0,K.jsx)(r,{value:e,field:o}),sortable:n.sortable!==!1})}),i},[E,q,J,U,W,X.handleClick,He,y,w,T,e.objectName]),ot=(0,H.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`;if((t===`csv`||t===`xlsx`||t===`json`)&&F.isSupported&&e.objectName&&!W&&n?.streaming!==!1){let n=Q().filter(e=>e.accessorKey!==`_actions`).map(e=>e.accessorKey).filter(Boolean);P(!1),pe(!0),F.start(e.objectName,{format:t===`json`?`json`:t,fields:n.length?n:void 0,includeHeaders:i,limit:r>0?r:void 0});return}let o=r>0?y.slice(0,r):y,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,g as n,t as r}from"./vendor-react-B1k2FF9f.js";import{D as i,H as a,I as o,L as s,M as c,_ as l,a as u,j as d,w as f}from"./framework-CoXA0nY6.js";import{f as p}from"./infrastructure-Djv3I7gr.js";import{$ as m,$t as h,Af as ee,Ct as g,Ef as _,El as v,Gn as te,IA as ne,J as re,Jn as y,Kn as ie,Of as ae,PL as b,Qt as x,Sn as oe,St as S,TA as C,TE as w,Ta as T,Un as E,Va as D,Vr as se,Wn as ce,ZA as O,Zc as k,a as A,ar as j,bt as M,c as N,cI as le,cn as ue,dn as P,en as de,fS as fe,ff as pe,gn as F,i as me,ks as he,l as I,ln as ge,ls as _e,mM as ve,mT as L,mn as ye,mo as be,nn as xe,pn as Se,qE as Ce,qn as R,r as we,ra as Te,rj as Ee,rk as De,rt as Oe,s as ke,sn as Ae,st as je,tI as Me,tn as Ne,un as Pe,vt as Fe,xt as z,yr as B,yt as V}from"./ui-components-B7mlp0en.js";var H=e(t(),1),Ie={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},U=[`xs`,`sm`,`md`,`lg`,`xl`,`2xl`];function W(e){for(let t=U.length-1;t>=0;t--){let n=U[t];if(e>=Ie[n])return n}return`xs`}function G(){let[e,t]=(0,H.useState)(()=>typeof window<`u`?window.innerWidth:1024);(0,H.useEffect)(()=>{if(typeof window>`u`)return;let e,n=()=>{clearTimeout(e),e=setTimeout(()=>{t(window.innerWidth)},100)};return window.addEventListener(`resize`,n),()=>{clearTimeout(e),window.removeEventListener(`resize`,n)}},[]);let n=W(e),r=U.indexOf(n);return{breakpoint:n,width:e,isMobile:r<U.indexOf(`md`),isTablet:r>=U.indexOf(`md`)&&r<U.indexOf(`lg`),isDesktop:r>=U.indexOf(`lg`),isAbove:t=>e>=Ie[t],isBelow:t=>e<Ie[t]}}function Le(e){let{onRefresh:t,threshold:n=80,enabled:r=!0}=e,i=(0,H.useRef)(null),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(0),l=(0,H.useRef)(0),u=(0,H.useCallback)(e=>{if(!r||a)return;let t=i.current;t&&t.scrollTop===0&&(l.current=e.touches[0].clientY)},[r,a]),d=(0,H.useCallback)(e=>{if(!r||a||!l.current)return;let t=e.touches[0].clientY-l.current;t>0&&c(Math.min(t,n*1.5))},[r,a,n]),f=(0,H.useCallback)(async()=>{if(!r||a)return;let e=s;if(c(0),l.current=0,e>=n){o(!0);try{await t()}finally{o(!1)}}},[r,a,s,n,t]);return(0,H.useEffect)(()=>{let e=i.current;if(!(!e||!r))return e.addEventListener(`touchstart`,u,{passive:!0}),e.addEventListener(`touchmove`,d,{passive:!0}),e.addEventListener(`touchend`,f,{passive:!0}),()=>{e.removeEventListener(`touchstart`,u),e.removeEventListener(`touchmove`,d),e.removeEventListener(`touchend`,f)}},[u,d,f,r]),{ref:i,isRefreshing:a,pullDistance:s}}var K=r(),q=(0,H.createContext)(null);q.displayName=`MobileContext`;function J({pwa:e,offline:t,children:n}){let r=G(),i=(0,H.useMemo)(()=>({...r,pwa:e,offline:t}),[r,e,t]);return(0,K.jsx)(q.Provider,{value:i,children:n})}var Re={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function Y(e){return e.startsWith(`bg-`)?e:Re[e.toLowerCase().trim()]}function ze(e){return(0,H.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return Y(r)},[e?.field,e?.colors])}function Be(e){if(e==null||e===``)return``;if(Array.isArray(e))return e.map(e=>Be(e)).join(`|`);if(typeof e==`object`){let t=e.id??e._id??e.pk??e.value;if(t!=null&&t!==``)return String(t);let n=e.name??e.label??e.title;if(n!=null&&n!==``)return String(n);try{return JSON.stringify(e)}catch{return``}}return String(e)}function Ve(e,t){return Be(e[t])}function X(e,t,n){if(e==null||e===``)return`(empty)`;if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}if(Array.isArray(e))return e.map(e=>{if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}return X(e,t)}).join(`, `)||`(empty)`;if(typeof e==`object`){let t=e.name??e.label??e.title??e.display_name??e.displayName??e.fullName??e.full_name;if(t!=null&&t!==``)return String(t);let n=e.id??e._id??e.pk;return n!=null&&n!==``?String(n):`(empty)`}return String(e)}function He(e,t){return t.map(({field:t,type:n})=>{let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`count`:i=r.length;break;case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function Ue(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function We(e,t,n,r){let i=e?.fields,a=!!(i&&i.length>0),[o,s]=(0,H.useState)({});return{groups:(0,H.useMemo)(()=>{if(!a||!i)return[];let e=(t,a,s)=>{if(a>=i.length)return[];let c=i[a],l=new Map,u=[];for(let e of t){let t=Ve(e,c.field);l.has(t)||(l.set(t,{label:X(e[c.field],c.field,r),rows:[]}),u.push(t)),l.get(t).rows.push(e)}let d=c.order??`asc`;return u.sort((e,t)=>Ue(l.get(e)?.label??e,l.get(t)?.label??t,d)),u.map(t=>{let r=l.get(t),u=s?`${s}__${a}:${t}`:`${a}:${t}`,d=!!c.collapsed,f=u in o?o[u]:d,p=n&&n.length>0?He(r.rows,n):[],m=a+1<i.length?e(r.rows,a+1,u):[];return{key:u,label:r.label,field:c.field,depth:a,rows:r.rows,collapsed:f,aggregations:p,subgroups:m}})};return e(t,0,``)},[t,i,a,o,n,r]),isGrouped:a,toggleGroup:(0,H.useCallback)(e=>{s(t=>{let n=e.split(`__`).pop()||``,r=/^(\d+):/.exec(n),a=r?Number(r[1]):0,o=!!i?.[a]?.collapsed;return{...t,[e]:t[e]===void 0?!o:!t[e]}})},[i])}}var Ge=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,onToggle:a,children:o})=>(0,K.jsxs)(`div`,{className:`border rounded-md`,"data-testid":`group-row-${e}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors`,onClick:()=>a(e),"aria-expanded":!r,children:[r?(0,K.jsx)(O,{className:`h-4 w-4 shrink-0`}):(0,K.jsx)(Ee,{className:`h-4 w-4 shrink-0`}),(0,K.jsx)(`span`,{className:`group-label`,children:t}),i&&i.length>0&&(0,K.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,K.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))}),(0,K.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground group-count`,children:[`(`,n,`)`]})]}),!r&&o]});function Ke(e){return typeof e==`string`?{type:e}:e}function qe(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function Je(e,t){return t===null?``:`${{count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e}: ${e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString()}`}function Ye(e,t){return(0,H.useMemo)(()=>{let n=new Map;if(!e||e.length===0||t.length===0)return{summaries:n,hasSummary:!1};for(let r of e){if(!r.summary)continue;let e=Ke(r.summary),i=e.field||r.field,a=[];for(let e of t){let t=e[i];if(t!=null&&typeof t==`number`&&!isNaN(t))a.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||a.push(e)}}let o;if(e.type===`count`){let e=t.filter(e=>e[i]!=null&&e[i]!==``).length;o=e>0?e:null}else o=qe(e.type,a);n.set(r.field,{field:r.field,value:o,label:Je(e.type,o)})}return{summaries:n,hasSummary:n.size>0}},[e,t])}function Xe(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var Ze=({row:e,rowActions:t,canEdit:n,canDelete:r,onEdit:i,onDelete:a,onAction:o})=>(0,K.jsxs)(Se,{children:[(0,K.jsx)(oe,{asChild:!0,children:(0,K.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,K.jsx)(w,{className:`h-4 w-4`}),(0,K.jsx)(`span`,{className:`sr-only`,children:`Open menu`})]})}),(0,K.jsxs)(ye,{align:`end`,children:[n&&i&&(0,K.jsxs)(F,{onClick:()=>i(e),children:[(0,K.jsx)(k,{className:`mr-2 h-4 w-4`}),`Edit`]}),r&&a&&(0,K.jsxs)(F,{onClick:()=>a(e),children:[(0,K.jsx)(be,{className:`mr-2 h-4 w-4`}),`Delete`]}),t?.map(t=>(0,K.jsx)(F,{onClick:()=>o?.(t,e),"data-testid":`row-action-${t}`,children:Xe(t)},t))]})]}),Qe=({selectedRows:e,actions:t,onAction:n,onClearSelection:r})=>!t||t.length===0||e.length===0?null:(0,K.jsxs)(`div`,{className:`border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0`,"data-testid":`bulk-actions-bar`,children:[(0,K.jsxs)(`span`,{className:`text-muted-foreground font-medium`,children:[e.length,` selected`]}),(0,K.jsx)(`div`,{className:`flex items-center gap-1 ml-2`,children:t.map(t=>(0,K.jsx)(B,{variant:`outline`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>n?.(t,e),"data-testid":`bulk-action-${t}`,children:Xe(t)},t))}),(0,K.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs ml-auto`,onClick:r,children:`Clear`})]}),$e={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`};function et(){try{let e=u();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=$e[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=$e[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function tt(e){if(e!=null)return typeof e==`string`?e:void 0}function nt(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function rt(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var it=({schema:e,dataSource:t,onEdit:n,onDelete:r,onRowSelect:a,onRowClick:c,onCellChange:u,onRowSave:h,onBatchSave:g,onAddRecord:te,...ne})=>{let[y,ie]=(0,H.useState)([]),[b,x]=(0,H.useState)(!0),[oe,S]=(0,H.useState)(null),{t:C}=et(),{fieldLabel:w,translateOptions:T}=p(),[E,se]=(0,H.useState)(null),[ce,O]=(0,H.useState)(!1),[k,M]=(0,H.useState)(0),[le,P]=(0,H.useState)(!1),[de,pe]=(0,H.useState)(!1),F=re({dataSource:t}),[L,ye]=(0,H.useState)(e.rowHeight??`compact`),[be,xe]=(0,H.useState)([]),Se=H.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[R,Ee]=(0,H.useState)(()=>{try{let e=localStorage.getItem(Se);return e?JSON.parse(e):{}}catch{return{}}}),Ae=(0,H.useCallback)(e=>{Ee(e);try{localStorage.setItem(Se,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}},[Se]),{ref:Me,isRefreshing:Ne,pullDistance:Fe}=Le({onRefresh:(0,H.useCallback)(async()=>{M(e=>e+1)},[]),enabled:!!t&&!!e.objectName});(0,H.useEffect)(()=>{let e=()=>O(window.innerWidth<480);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let z=ne.data,V=d(e.bind),Ie=nt(e),U=H.useMemo(()=>z&&Array.isArray(z)?{provider:`value`,items:z}:V&&Array.isArray(V)?{provider:`value`,items:V}:Ie,[JSON.stringify(Ie),V,z]),W=U?.provider===`value`,G=U?.provider===`object`&&U&&`object`in U?U.object:e.objectName,q=e.fields,J=e.columns,Re=e.filter,Y=e.sort,Be=e.pagination,Ve=e.pageSize;(0,H.useEffect)(()=>{W&&U?.provider===`value`&&(ie(e=>{let t=U.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),x(!1))},[W,U]),(0,H.useEffect)(()=>{if(!W||!G||!t)return;let e=!1;return(async()=>{try{if(typeof t.getObjectSchema!=`function`)return;let n=await t.getObjectSchema(G);e||se(n)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${G}):`,e)}})(),()=>{e=!0}},[W,G,t]),(0,H.useEffect)(()=>{if(W)return;let n=!1;return(async()=>{x(!0),S(null);try{let r=null,i=rt(J)||q;if(G&&t)if(typeof t.getObjectSchema==`function`){let e=await t.getObjectSchema(G);if(n)return;r=e}else r={name:G,fields:{}};else if(i&&G)r={name:G,fields:{}};else if(G)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(n||se(r),t&&G){let i={$select:(()=>{if(q)return q;if(J&&Array.isArray(J))return J.map(e=>typeof e==`string`?e:e.field)})(),$top:Be?.pageSize||Ve||50};Re&&Array.isArray(Re)?i.$filter=Re:e.defaultFilters&&(i.$filter=e.defaultFilters),Y?typeof Y==`string`?i.$orderby=Y:Array.isArray(Y)&&(i.$orderby=Y.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=s(r?.fields,J??q);a.length>0&&(i.$expand=a);let o=await t.find(G,i);if(n)return;ie(o.data||[])}}catch(e){n||S(e)}finally{n||x(!1)}})(),()=>{n=!0}},[G,q,J,Re,Y,Be,Ve,t,W,U,k]);let X=f({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:c}),{execute:He}=l(),Ue=ze(e.rowColor),Ke=(0,H.useCallback)(t=>{let n=e.conditionalFormatting;if(!(!n||n.length===0))for(let e of n){let n=!1,r=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(r)n=o(r,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let r=e,i=t[r.field];switch(r.operator){case`equals`:n=i===r.value;break;case`not_equals`:n=i!==r.value;break;case`contains`:n=typeof i==`string`&&typeof r.value==`string`&&i.includes(r.value);break;case`greater_than`:n=typeof i==`number`&&typeof r.value==`number`&&i>r.value;break;case`less_than`:n=typeof i==`number`&&typeof r.value==`number`&&i<r.value;break;case`in`:n=Array.isArray(r.value)&&r.value.includes(i);break}}if(n){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),qe=H.useMemo(()=>{let t=e.grouping;if(!t?.fields?.length)return;let n=new Map;for(let r of t.fields){let t=r.field,i=E?.fields?.[t],a=rt(e.columns)?.find?.(e=>typeof e==`object`&&e?.field===t),o=a?.type||i?.type,s=a?.options||i?.options,c=new Map;if(Array.isArray(s)&&s.length>0){let n=e.objectName?T(e.objectName,t,s):s;for(let e of n)if(e&&e.value!==void 0&&e.value!==null){let t=e.label;c.set(String(e.value),String(t??e.value))}}n.set(t,{type:o||void 0,options:c.size>0?c:void 0})}return(e,t)=>{let r=n.get(e);if(r){if(r.options){let e=r.options.get(String(t));if(e!==void 0)return e}if(r.type===`boolean`||typeof t==`boolean`){if(t===!0||t===`true`)return C(`grid.booleanTrue`,`Yes`);if(t===!1||t===`false`)return C(`grid.booleanFalse`,`No`)}}}},[e.grouping,e.columns,e.objectName,E,T,C]),{groups:Je,isGrouped:$e,toggleGroup:it}=We(e.grouping,y,void 0,qe),{summaries:at,hasSummary:Z}=Ye(H.useMemo(()=>{let t=rt(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),y),Q=(0,H.useCallback)(()=>{let t=e=>e&&{text:(0,K.jsx)(D,{className:`h-3.5 w-3.5`}),number:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),currency:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),percent:(0,K.jsx)(fe,{className:`h-3.5 w-3.5`}),date:(0,K.jsx)(ve,{className:`h-3.5 w-3.5`}),datetime:(0,K.jsx)(De,{className:`h-3.5 w-3.5`}),boolean:(0,K.jsx)(v,{className:`h-3.5 w-3.5`}),user:(0,K.jsx)(Te,{className:`h-3.5 w-3.5`}),select:(0,K.jsx)(he,{className:`h-3.5 w-3.5`})}[e]||(0,K.jsx)(D,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(y.length>0){let t=y.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&y.length>0&&typeof y.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&y.length>0){let t=new Set(y.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&y.length>0&&typeof y.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(y.length>0){let t=y.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=rt(J);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let i=r[0];if(`accessorKey`in i)return r.map(r=>{if(r.cell)return r;let i=n({field:r.accessorKey,label:r.header,type:r.type});if(!i)return r;let a=N(i),o={name:r.accessorKey,type:i};return i===`select`&&(o.options=Array.from(new Set(y.map(e=>e[r.accessorKey]).filter(Boolean))).map(e=>({value:e,label:I(String(e))}))),{...r,...e.showColumnTypeIcons&&{headerIcon:t(i)},cell:e=>(0,K.jsx)(a,{value:e,field:o})}});if(`field`in i)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,i)=>{let a=tt(r.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),o=e.objectName?w(e.objectName,r.field,a):a,s,c=E?.fields?.[r.field],l=r.type||c?.type||n({field:r.field})||null,u=l?N(l):null,d={name:r.field,type:l||`text`};c&&(c.label&&(d.label=c.label),c.currency&&(d.currency=c.currency),c.precision!==void 0&&(d.precision=c.precision),c.format&&(d.format=c.format),c.options&&(d.options=T(e.objectName,r.field,c.options))),l===`select`&&!d.options&&(d.options=Array.from(new Set(y.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:I(String(e))}))),r.options&&(d.options=T(e.objectName,r.field,r.options));let f=i===0&&!r.link&&!r.action,p=r.link||f;s=r.link&&r.action||f&&r.action||p?(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":f?`primary-field-link`:`link-cell`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:u?(0,K.jsx)(u,{value:e,field:d}):e!=null&&e!==``?String(e):(0,K.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):r.action?(e,t)=>(0,K.jsx)(B,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),He({type:r.action,params:{record:t,field:r.field,value:e}})},children:Xe(r.action)}):u?e=>(0,K.jsx)(u,{value:e,field:d}):e=>e!=null&&e!==``?(0,K.jsx)(`span`,{children:String(e)}):(0,K.jsx)(je,{});let m=r.prefix;if(m?.field){let e=s,t=m.type===`badge`?N(`select`):null;s=(n,r)=>{let i=r[m.field];return(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,K.jsx)(t,{value:i,field:{name:m.field,type:`select`}}):(0,K.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let h=[`number`,`currency`,`percent`],ee=l||r.type,g=r.align||(ee&&h.includes(ee)?`right`:void 0),_=i===0||r.essential===!0;return{header:o,accessorKey:r.field,...e.showColumnTypeIcons&&{headerIcon:t(l)},...!_&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...g&&{align:g},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...s&&{cell:s},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,i)=>{let a=E?.fields?.[r],o=a?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),s=e.objectName?w(e.objectName,r,o):o,c=a?.type||n({field:r})||null,l=c?N(c):null,u={name:r,type:c||`text`};a&&(a.label&&(u.label=a.label),a.currency&&(u.currency=a.currency),a.precision!==void 0&&(u.precision=a.precision),a.format&&(u.format=a.format),a.options&&(u.options=T(e.objectName,r,a.options))),c===`select`&&!u.options&&(u.options=Array.from(new Set(y.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:I(String(e))})));let d=c&&[`number`,`currency`,`percent`].includes(c)?`right`:void 0,f=i===0,p;return f&&l?p=(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:(0,K.jsx)(l,{value:e,field:u})}):f?p=(e,t)=>(0,K.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),X.handleClick(t)},children:e!=null&&e!==``?String(e):(0,K.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):l&&(p=e=>(0,K.jsx)(l,{value:e,field:u})),{header:s,accessorKey:r,...e.showColumnTypeIcons&&c&&{headerIcon:t(c)},...d&&{align:d},...p&&{cell:p},sortable:a?.sortable!==!1}})}if(W){let r=U?.provider===`value`?U.items:[];if(r.length>0)return(q||Object.keys(r[0])).map(r=>{let i=E?.fields?.[r],a=i?.type||n({field:r})||null,o=a?N(a):null,s=i?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),c={name:r,type:a||`text`};i&&(i.label&&(c.label=i.label),i.currency&&(c.currency=i.currency),i.precision!==void 0&&(c.precision=i.precision),i.format&&(c.format=i.format),i.options&&(c.options=T(e.objectName,r,i.options))),a===`select`&&!c.options&&(c.options=Array.from(new Set(y.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:I(String(e))})));let l=a&&[`number`,`currency`,`percent`].includes(a)?`right`:void 0;return{header:s,accessorKey:r,...e.showColumnTypeIcons&&a&&{headerIcon:t(a)},...l&&{align:l},...o&&{cell:e=>(0,K.jsx)(o,{value:e,field:c})},sortable:i?.sortable!==!1}})}if(!E)return[];let i=[],a=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),o=E?.compactLayout,s=Object.keys(E.fields||{}),c;if(q)c=q;else if(o?.length)c=o.filter(e=>E.fields?.[e]);else{let e=s.filter(e=>{let t=E.fields?.[e];return!(!t||t.hidden||t.readonly&&a.has(e))});c=[...e.filter(e=>!a.has(e)),...e.filter(e=>a.has(e))]}return c.forEach(t=>{let n=E.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=N(n.type),a=[`number`,`currency`,`percent`],o=n.options?{...n,options:T(e.objectName,t,n.options)}:n;i.push({header:e.objectName?w(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...a.includes(n.type)&&{align:`right`},cell:e=>(0,K.jsx)(r,{value:e,field:o}),sortable:n.sortable!==!1})}),i},[E,q,J,U,W,X.handleClick,He,y,w,T,e.objectName]),ot=(0,H.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`;if((t===`csv`||t===`xlsx`||t===`json`)&&F.isSupported&&e.objectName&&!W&&n?.streaming!==!1){let n=Q().filter(e=>e.accessorKey!==`_actions`).map(e=>e.accessorKey).filter(Boolean);P(!1),pe(!0),F.start(e.objectName,{format:t===`json`?`json`:t,fields:n.length?n:void 0,includeHeaders:i,limit:r>0?r:void 0});return}let o=r>0?y.slice(0,r):y,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
2
2
|
`)||t.includes(`\r`)?`"${t.replace(/"/g,`""`)}"`:t};if(t===`csv`){let e=Q().filter(e=>e.accessorKey!==`_actions`),t=e.map(e=>e.accessorKey),n=e.map(e=>e.header),r=[];i&&r.push(n.join(`,`)),o.forEach(e=>{r.push(t.map(t=>c(e[t])).join(`,`))}),s(new Blob([r.join(`
|
|
3
3
|
`)],{type:`text/csv;charset=utf-8;`}),`${a}.csv`)}else t===`json`&&s(new Blob([JSON.stringify(o,null,2)],{type:`application/json`}),`${a}.json`);P(!1)},[y,e.exportOptions,e.objectName,Q,F,W]);if(oe)return(0,K.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,K.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:C(`grid.errorLoading`)}),(0,K.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:oe.message})]});if(b&&y.length===0)return ce?(0,K.jsx)(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>(0,K.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card animate-pulse`,children:[(0,K.jsx)(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-3`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`div`,{className:`h-4 bg-muted rounded w-1/4`}),(0,K.jsx)(`div`,{className:`h-5 bg-muted rounded-full w-20`})]}),(0,K.jsx)(`div`,{className:`h-3 bg-muted rounded w-1/3`})]},e))}):(0,K.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,K.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-foreground`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:C(`grid.loading`)})]});let st=[...Q()];if(R.widths&&(st=st.map(e=>{let t=R.widths?.[e.accessorKey];return t?{...e,size:t}:e})),R.order&&R.order.length>0){let e=new Map(R.order.map((e,t)=>[e,t]));st.sort((t,n)=>(e.get(t.accessorKey)??1/0)-(e.get(n.accessorKey)??1/0))}let $=`operations`in e?e.operations:void 0,ct=$&&($.update||$.delete),lt=e.rowActions&&e.rowActions.length>0,ut=ct||lt?[...st,{header:C(`grid.actions`),accessorKey:`_actions`,cell:(t,i)=>(0,K.jsx)(Ze,{row:i,rowActions:e.rowActions,canEdit:!!($?.update&&n),canDelete:!!($?.delete&&r),onEdit:n,onDelete:r,onAction:(e,t)=>He({type:e,params:{record:t}})}),sortable:!1}]:st,dt=ut.filter(e=>e.pinned===`left`),ft=ut.filter(e=>e.pinned===`right`),pt=ut.filter(e=>!e.pinned),mt=dt.length>0||ft.length>0,ht=`sticky right-0 z-10 bg-background border-l border-border`,gt=mt?[...dt,...pt,...ft.map(e=>({...e,className:[e.className,ht].filter(Boolean).join(` `),cellClassName:[e.cellClassName,ht].filter(Boolean).join(` `)}))]:ut,_t=mt?dt.length:e.frozenColumns??1,vt=e.batchActions??e.bulkActions,yt=vt&&vt.length>0,bt=!1;e.selection?.type?bt=e.selection.type===`none`?!1:e.selection.type:e.selectable===void 0?yt&&(bt=`multiple`):bt=e.selectable;let xt=e.pagination===void 0?e.showPagination===void 0?!0:e.showPagination:!0,St=e.pagination?.pageSize||e.pageSize||10,Ct=e.searchableFields===void 0?e.showSearch===void 0?!0:e.showSearch:e.searchableFields.length>0,wt={type:`data-table`,caption:e.label||e.title,columns:gt,data:y,pagination:xt,pageSize:St,searchable:Ct,selectable:bt,sortable:!0,exportable:$?.export,rowActions:!!(e.editable&&ct),resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:L===`compact`?`px-3 py-1 text-[13px] leading-tight`:L===`short`?`px-3 py-1 text-[13px] leading-normal`:L===`tall`?`px-3 py-2.5 text-sm`:L===`extra_tall`?`px-3 py-3.5 text-sm leading-relaxed`:`px-3 py-1.5 text-[13px] leading-normal`,showRowNumbers:!0,showAddRow:!!$?.create,onAddRecord:te,rowClassName:e.rowColor?(e,t)=>Ue(e):void 0,rowStyle:e.conditionalFormatting?.length?(e,t)=>Ke(e):void 0,frozenColumns:_t,onSelectionChange:e=>{xe(e),a?.(e)},onRowClick:X.handleClick,onCellChange:u,onRowSave:h,onBatchSave:g,onColumnResize:(e,t)=>{Ae({...R,widths:{...R.widths,[e]:t}})},onColumnReorder:e=>{Ae({...R,order:e})}},Tt=e=>({...wt,caption:void 0,data:e,pagination:!1,searchable:!1}),Et=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:`Record Detail`;if(ce&&y.length>0&&!$e){let e=Q().filter(e=>e.accessorKey!==`_actions`),t=new Map;e.forEach(e=>t.set(e.accessorKey,e));let n=e[0],r=[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`],i=[`stage`,`status`,`priority`,`category`,`severity`,`level`],a=[`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`],o=[`probability`,`percent`,`rate`,`ratio`,`confidence`,`score`],s=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`||t===`success`||t===`approved`||t===`paid`?`bg-green-50 text-green-700 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900/60`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t.includes(`closed lost`)||t===`expired`||t===`terminated`||t===`failed`||t===`overdue`?`bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-300 dark:border-red-900/60`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)||t===`in_approval`||t===`pending_approval`?`bg-yellow-50 text-yellow-800 border-yellow-200 dark:bg-yellow-950/40 dark:text-yellow-300 dark:border-yellow-900/60`:t.includes(`proposal`)||t.includes(`pending`)?`bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900/60`:t.includes(`qualification`)||t.includes(`qualified`)?`bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900/60`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-950/40 dark:text-purple-300 dark:border-purple-900/60`:t===`draft`||t.includes(`draft`)?`bg-slate-50 text-slate-700 border-slate-200 dark:bg-slate-950/40 dark:text-slate-300 dark:border-slate-900/60`:`bg-muted text-muted-foreground border-border`},c=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`?`border-l-green-500`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t===`expired`||t===`terminated`?`border-l-red-500`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)?`border-l-yellow-500`:t.includes(`proposal`)||t.includes(`pending`)?`border-l-blue-500`:t.includes(`qualification`)||t.includes(`qualified`)?`border-l-indigo-500`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`border-l-purple-500`:t===`draft`||t.includes(`draft`)?`border-l-slate-400`:`border-l-gray-300`},l=e=>{let t=e.toLowerCase();return r.some(e=>t.includes(e))?`amount`:i.some(e=>t.includes(e))?`stage`:a.some(e=>t.includes(e))?`date`:o.some(e=>t.includes(e))?`percent`:`other`};return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`space-y-2 p-2`,children:y.map((t,r)=>{let i=e.slice(1,5),a=i.find(e=>l(e.accessorKey)===`amount`),o=i.find(e=>l(e.accessorKey)===`stage`),u=i.filter(e=>l(e.accessorKey)===`date`),d=i.filter(e=>l(e.accessorKey)===`percent`),f=i.filter(e=>e!==a&&e!==o&&!u.includes(e)&&!d.includes(e)),p=o?String(t[o.accessorKey]??``):``,m=p?c(p):``;return(0,K.jsxs)(`div`,{className:[`border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,m?`border-l-[3px] ${m}`:``].filter(Boolean).join(` `),onClick:()=>X.handleClick(t),children:[n&&(0,K.jsx)(`div`,{className:`font-semibold text-sm truncate mb-1`,children:t[n.accessorKey]!=null&&typeof t[n.accessorKey]==`object`?String(t[n.accessorKey]):t[n.accessorKey]??`—`}),(a||o)&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[a&&(0,K.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:typeof t[a.accessorKey]==`number`?we(t[a.accessorKey]):t[a.accessorKey]!=null&&typeof t[a.accessorKey]==`object`?String(t[a.accessorKey]):t[a.accessorKey]??`—`}),o&&t[o.accessorKey]&&(0,K.jsx)(j,{variant:`outline`,className:`text-xs shrink-0 max-w-[140px] truncate ${s(String(t[o.accessorKey]))}`,children:String(t[o.accessorKey])})]}),(u.length>0||d.length>0)&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between py-0.5 text-xs text-muted-foreground`,children:[u[0]&&(0,K.jsx)(`span`,{className:`tabular-nums`,children:t[u[0].accessorKey]?A(t[u[0].accessorKey],`short`):`—`}),d[0]&&t[d[0].accessorKey]!=null&&(0,K.jsx)(`span`,{className:`tabular-nums`,children:ke(Number(t[d[0].accessorKey]))})]}),u.slice(1).map(e=>(0,K.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:t[e.accessorKey]?A(t[e.accessorKey],`short`):`—`})]},e.accessorKey)),f.map(e=>{let n=t[e.accessorKey];return n==null||n===``?null:(0,K.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,K.jsx)(`span`,{className:`text-xs font-medium truncate ml-2 text-right`,children:e.cell?e.cell(n,t):String(n)})]},e.accessorKey)})]},t.id||t._id||r)})}),X.isOverlay&&(0,K.jsx)(Oe,{...X,title:Et,children:e=>(0,K.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,K.jsxs)(`div`,{className:`flex flex-col`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,K.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})}let Dt=()=>{ye(e=>e===`compact`?`short`:e===`short`?`medium`:e===`medium`?`tall`:e===`tall`?`extra_tall`:`compact`)},Ot={compact:_,short:ae,medium:ee,tall:_e,extra_tall:_e}[L],kt=e.rowHeight!==void 0,At=e.exportOptions||kt?(0,K.jsxs)(`div`,{className:`flex items-center justify-end gap-1 px-2 py-1`,children:[kt&&(0,K.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,onClick:Dt,title:`Row height: ${L}`,children:[(0,K.jsx)(Ot,{className:`h-3.5 w-3.5 mr-1.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline capitalize`,children:L})]}),e.exportOptions&&(0,K.jsxs)(ue,{open:le,onOpenChange:P,children:[(0,K.jsx)(Pe,{asChild:!0,children:(0,K.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,children:[(0,K.jsx)(Ce,{className:`h-3.5 w-3.5 mr-1.5`}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:C(`grid.export`)})]})}),(0,K.jsx)(ge,{align:`end`,className:`w-48 p-2`,children:(0,K.jsx)(`div`,{className:`space-y-1`,children:(e.exportOptions.formats||[`csv`,`json`]).map(e=>(0,K.jsxs)(B,{variant:`ghost`,size:`sm`,className:`w-full justify-start h-8 text-xs`,onClick:()=>ot(e),children:[(0,K.jsx)(Ce,{className:`h-3.5 w-3.5 mr-2`}),C(`grid.exportAs`,{format:e.toUpperCase()})]},e))})})]})]}):null,jt=e=>{let t=[`_id`,`id`,`created_at`,`updated_at`,`created_by`,`updated_by`],n=Object.entries(e),r=n.filter(([e])=>!t.includes(e)),i=n.filter(([e])=>t.includes(e)&&e!==`_id`&&e!==`id`),a=e=>e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `),o=(e,t)=>{if(t==null||t===``)return(0,K.jsx)(`span`,{className:`text-muted-foreground/50 text-sm italic`,children:`Empty`});let n=E?.fields?.[e];if(n?.type){let e=N(n.type);if(e)return(0,K.jsx)(e,{value:t,field:n})}return typeof t==`boolean`?(0,K.jsx)(j,{variant:t?`default`:`outline`,children:t?`Yes`:`No`}):typeof t==`string`&&!isNaN(Date.parse(t))&&(e.includes(`date`)||e.includes(`_at`)||e.includes(`time`))?(0,K.jsx)(`span`,{className:`text-sm tabular-nums`,children:A(t)}):typeof t==`number`&&[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`].some(t=>e.toLowerCase().includes(t))?(0,K.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:me(t)}):(0,K.jsx)(`span`,{className:`text-sm break-words`,children:String(t)})};return(0,K.jsxs)(`div`,{className:`space-y-4`,"data-testid":`record-detail-panel`,children:[(0,K.jsx)(`div`,{className:`rounded-lg border bg-card`,children:(0,K.jsx)(`div`,{className:`divide-y`,children:r.map(([e,t])=>(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0`,children:a(e)}),(0,K.jsx)(`div`,{className:`flex-1 min-w-0`,children:o(e,t)})]},e))})}),i.length>0&&(0,K.jsxs)(`div`,{className:`rounded-lg border bg-muted/30`,children:[(0,K.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,K.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`System`})}),(0,K.jsx)(`div`,{className:`divide-y divide-border/50`,children:i.map(([e,t])=>(0,K.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground w-1/3 text-right shrink-0`,children:a(e)}),(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1 min-w-0 break-words`,children:String(t??``)})]},e))})]})]})},Mt=Z?(0,K.jsx)(`div`,{className:`border-t bg-muted/30 px-2 py-1.5`,"data-testid":`column-summary-footer`,children:(0,K.jsx)(`div`,{className:`flex gap-4 text-xs text-muted-foreground font-medium`,children:gt.filter(e=>at.has(e.accessorKey)).map(e=>{let t=at.get(e.accessorKey);return(0,K.jsxs)(`span`,{"data-testid":`summary-${e.accessorKey}`,children:[e.header,`: `,t.label]},e.accessorKey)})})}):null,Nt=e=>(0,K.jsx)(`div`,{style:e.depth>0?{marginLeft:e.depth*16}:void 0,children:(0,K.jsx)(Ge,{groupKey:e.key,label:e.label,count:e.rows.length,collapsed:e.collapsed,aggregations:e.aggregations,onToggle:it,children:e.subgroups.length>0?(0,K.jsx)(`div`,{className:`space-y-2 p-2`,children:e.subgroups.map(Nt)}):(0,K.jsx)(i,{schema:Tt(e.rows)})})},e.key),Pt=$e?(0,K.jsx)(`div`,{className:`space-y-2`,children:Je.map(Nt)}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(i,{schema:wt}),Mt]}),Ft=(0,K.jsx)(m,{open:de,onOpenChange:pe,job:F,filename:`${e.exportOptions?.fileNamePrefix||e.objectName||`export`}.${F.progress?.format||`csv`}`,closeAfterDownloadMs:400});return X.isOverlay&&X.mode===`split`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Oe,{...X,title:Et,mainContent:(0,K.jsxs)(K.Fragment,{children:[At,Pt,(0,K.jsx)(Qe,{selectedRows:be,actions:vt??[],onAction:(e,t)=>He({type:e,params:{records:t}}),onClearSelection:()=>xe([])})]}),children:e=>jt(e)}),Ft]}):(0,K.jsxs)(`div`,{ref:Me,className:`relative h-full`,children:[Fe>0&&(0,K.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:Fe},children:C(Ne?`grid.refreshing`:`grid.pullToRefresh`)}),At,Pt,(0,K.jsx)(Qe,{selectedRows:be,actions:vt??[],onAction:(e,t)=>He({type:e,params:{records:t}}),onClearSelection:()=>xe([])}),X.isOverlay&&(0,K.jsx)(Oe,{...X,title:Et,children:e=>jt(e)}),Ft]})},at=e(n(),1);function Z(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o;n.key&&n.debug?.call(n)&&(o=Date.now());let s=e();if(!(s.length!==r.length||s.some((e,t)=>r[t]!==e)))return i;r=s;let c;if(n.key&&n.debug?.call(n)&&(c=Date.now()),i=t(...s),n.key&&n.debug?.call(n)){let e=Math.round((Date.now()-o)*100)/100,t=Math.round((Date.now()-c)*100)/100,r=t/16,i=(e,t)=>{for(e=String(e);e.length<t;)e=` `+e;return e};console.info(`%c⏱ ${i(t,5)} /${i(e,5)} ms`,`
|
|
4
4
|
font-size: .6rem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,m as r,t as i}from"./vendor-react-B1k2FF9f.js";import{H as a,L as o,M as s,R as c,h as l,j as u,m as d,w as f}from"./framework-CoXA0nY6.js";import{$n as p,Ut as m,Vr as h,Y as g,ZA as _,ar as v,cT as y,dn as b,er as x,no as S,nr as C,pj as w,rj as T,rn as E,rr as D,rt as O,tr as k,um as A,yr as j}from"./ui-components-3HVEceOY.js";import{a as M,c as N,d as ee,g as P,h as F,m as I,n as te,o as L,p as R,s as z,t as B,u as V}from"./vendor-dndkit-BGB4qgc3.js";import{t as ne}from"./plugin-grid-CQS8zk9l.js";var re=e({KanbanEnhanced:()=>K,default:()=>K}),H=t(n(),1),U=i(),W=(...e)=>e.filter(Boolean).join(` `);function ie(e,t){if(!t||t.length===0)return{};for(let n of t){let t=e[n.field];if(t==null)continue;let r=!1,i=String(t);switch(n.operator){case`equals`:r=i===String(n.value);break;case`not_equals`:r=i!==String(n.value);break;case`contains`:r=i.toLowerCase().includes(String(n.value).toLowerCase());break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}if(r)return{...n.backgroundColor?{backgroundColor:n.backgroundColor}:{},...n.borderColor?{borderColor:n.borderColor}:{}}}return{}}function G({card:e,conditionalFormatting:t}){let{attributes:n,listeners:r,setNodeRef:i,transform:a,transition:o,isDragging:s}=M({id:e.id}),c={transform:P.Transform.toString(a),transition:o,opacity:s?.5:void 0},l=ie(e,t);return(0,U.jsx)(`div`,{ref:i,style:c,...n,...r,children:(0,U.jsxs)(p,{className:`mb-2 cursor-grab active:cursor-grabbing border-border bg-card/60 hover:border-primary/40 hover:shadow-lg hover:shadow-primary/10 transition-all duration-300 group`,style:l,children:[e.coverImage&&(0,U.jsx)(`div`,{className:`w-full h-32 overflow-hidden rounded-t-lg`,children:(0,U.jsx)(`img`,{src:e.coverImage,alt:``,className:`w-full h-full object-cover`,loading:`lazy`})}),(0,U.jsxs)(C,{className:`p-4`,children:[(0,U.jsx)(D,{className:`text-sm font-medium tracking-tight text-foreground group-hover:text-primary transition-colors`,children:e.title}),e.description&&(0,U.jsx)(k,{className:`text-xs text-muted-foreground`,children:e.description})]}),e.badges&&e.badges.length>0&&(0,U.jsx)(x,{className:`p-4 pt-0`,children:(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.badges.map((e,t)=>(0,U.jsx)(v,{variant:e.variant||`default`,className:`text-xs`,children:e.label},t))})})]})})}function ae({cards:e,parentRef:t,conditionalFormatting:n}){let r=ne({count:e.length,getScrollElement:()=>t.current,estimateSize:()=>120,overscan:5});return(0,U.jsx)(`div`,{style:{height:`${r.getTotalSize()}px`,width:`100%`,position:`relative`},children:r.getVirtualItems().map(t=>{let r=e[t.index];return(0,U.jsx)(`div`,{style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${t.start}px)`},children:(0,U.jsx)(G,{card:r,conditionalFormatting:n})},r.id)})})}function oe({columnId:e,onAdd:t}){let[n,r]=H.useState(!1),[i,a]=H.useState(``),o=H.useRef(null),s=()=>{let n=i.trim();n&&(t(e,n),a(``)),r(!1)};return n?(0,U.jsx)(`div`,{className:`mt-2 space-y-2`,children:(0,U.jsx)(b,{ref:o,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(a(``),r(!1))},onBlur:s,placeholder:`Enter card title...`,className:`text-sm`,autoFocus:!0})}):(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground`,onClick:()=>{r(!0),setTimeout(()=>o.current?.focus(),0)},children:[(0,U.jsx)(A,{className:`h-4 w-4 mr-1`}),`Add Card`]})}function se({column:e,cards:t,onToggle:n,enableVirtual:r,quickAdd:i,onQuickAdd:a,conditionalFormatting:o}){let s=t||[],c=H.useRef(null),{setNodeRef:l}=M({id:e.id,data:{type:`column`}}),u=e.limit&&s.length>=e.limit,d=e.limit&&s.length>=e.limit*.8;return(0,U.jsxs)(`div`,{ref:l,className:W(`flex flex-col flex-shrink-0 rounded-lg border border-border bg-card/20 backdrop-blur-sm shadow-xl transition-all`,e.collapsed?`w-16`:`w-80`,e.className),children:[(0,U.jsxs)(`div`,{className:`p-4 border-b border-border/50 bg-muted/20 flex items-center justify-between`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0`,children:[(0,U.jsx)(j,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>n(!e.collapsed),children:e.collapsed?(0,U.jsx)(_,{className:`h-4 w-4`}):(0,U.jsx)(T,{className:`h-4 w-4`})}),!e.collapsed&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`h3`,{className:` text-sm font-semibold tracking-wider text-primary/90 uppercase truncate`,children:e.title}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsxs)(`span`,{className:W(` text-xs`,u?`text-destructive`:d?`text-yellow-500`:`text-muted-foreground`),children:[s.length,e.limit&&` / ${e.limit}`]}),u&&(0,U.jsx)(v,{variant:`destructive`,className:`text-xs`,children:`Full`}),d&&!u&&(0,U.jsx)(S,{className:`h-3 w-3 text-yellow-500`})]})]})]}),e.collapsed&&(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,U.jsx)(`span`,{className:` text-xs font-bold text-primary/90 [writing-mode:vertical-rl] rotate-180`,children:e.title}),(0,U.jsx)(v,{variant:`secondary`,className:`text-xs`,children:s.length})]})]}),!e.collapsed&&(0,U.jsxs)(`div`,{ref:c,className:`flex-1 p-4 overflow-y-auto`,style:{maxHeight:`600px`},children:[(0,U.jsx)(B,{items:s.map(e=>e.id),strategy:L,children:r?(0,U.jsx)(ae,{cards:s,parentRef:c,conditionalFormatting:o}):(0,U.jsx)(`div`,{className:`space-y-2`,children:s.map(e=>(0,U.jsx)(G,{card:e,conditionalFormatting:o},e.id))})}),i&&a&&(0,U.jsx)(oe,{columnId:e.id,onAdd:a})]})]})}function K({columns:e,onCardMove:t,onColumnToggle:n,enableVirtualScrolling:r=!1,virtualScrollThreshold:i=50,className:a,quickAdd:o,onQuickAdd:s,conditionalFormatting:c}){let[l,u]=H.useState(null),d=H.useMemo(()=>(e||[]).map(e=>({...e,cards:e.cards||[]})),[e]),[f,p]=H.useState(d);H.useEffect(()=>{p(d)},[d]);let m=F(I(V,{activationConstraint:{distance:8}})),h=e=>{let{active:t}=e;u(_(t.id))},g=e=>{let{active:n,over:r}=e;if(u(null),!r)return;let i=n.id,a=r.id;if(i===a)return;let o=v(i),s=v(a)||y(a);if(!(!o||!s))if(o.id===s.id){let e=[...o.cards],t=te(e,e.findIndex(e=>e.id===i),e.findIndex(e=>e.id===a));p(e=>e.map(e=>e.id===o.id?{...e,cards:t}:e))}else{let e=[...o.cards],n=[...s.cards],r=e.findIndex(e=>e.id===i),c=a===s.id?n.length:n.findIndex(e=>e.id===a),[l]=e.splice(r,1);n.splice(c,0,l),p(t=>t.map(t=>t.id===o.id?{...t,cards:e}:t.id===s.id?{...t,cards:n}:t)),t&&t(i,o.id,s.id,c)}},_=H.useCallback(e=>{for(let t of f){let n=t.cards.find(t=>t.id===e);if(n)return n}return null},[f]),v=H.useCallback(e=>f.find(t=>t.cards.some(t=>t.id===e))||null,[f]),y=H.useCallback(e=>f.find(t=>t.id===e)||null,[f]),b=H.useCallback((e,t)=>{p(n=>n.map(n=>n.id===e?{...n,collapsed:t}:n)),n?.(e,t)},[n]);return(0,U.jsxs)(z,{sensors:m,collisionDetection:R,onDragStart:h,onDragEnd:g,children:[(0,U.jsx)(`div`,{className:W(`flex gap-4 overflow-x-auto p-4`,a),children:f.map(e=>{let t=r&&e.cards.length>i;return(0,U.jsx)(se,{column:e,cards:e.cards,onToggle:t=>b(e.id,t),enableVirtual:t,quickAdd:o,onQuickAdd:s,conditionalFormatting:c},e.id)})}),(0,U.jsx)(N,{children:l?(0,U.jsx)(G,{card:l,conditionalFormatting:c}):null})]})}var q=e({default:()=>fe}),J=(...e)=>e.filter(Boolean).join(` `),Y=`Uncategorized`;function ce(e,t){if(!t||t.length===0)return{};for(let n of t){let t=e[n.field];if(t==null)continue;let r=!1,i=String(t);switch(n.operator){case`equals`:r=i===String(n.value);break;case`not_equals`:r=i!==String(n.value);break;case`contains`:r=i.toLowerCase().includes(String(n.value).toLowerCase());break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}if(r)return{...n.backgroundColor?{backgroundColor:n.backgroundColor}:{},...n.borderColor?{borderColor:n.borderColor}:{}}}return{}}function X({card:e,onCardClick:t,conditionalFormatting:n}){let{attributes:r,listeners:i,setNodeRef:a,transform:o,transition:s,isDragging:c}=M({id:e.id}),l={transform:P.Transform.toString(o),transition:s,opacity:c?.5:void 0},u=ce(e,n);return(0,U.jsx)(`div`,{ref:a,style:l,...r,...i,role:`listitem`,"aria-label":e.title,onClick:()=>t?.(e),children:(0,U.jsxs)(p,{className:`mb-2 cursor-grab active:cursor-grabbing border-border border-l-4 border-l-primary/40 bg-card/60 hover:border-primary/40 hover:shadow-lg hover:shadow-primary/10 transition-all duration-300 group touch-manipulation`,style:u,children:[e.coverImage&&(0,U.jsx)(`div`,{className:`w-full h-32 overflow-hidden rounded-t-lg`,children:(0,U.jsx)(`img`,{src:e.coverImage,alt:``,className:`w-full h-full object-cover`,loading:`lazy`})}),(0,U.jsxs)(C,{className:`p-2 sm:p-4`,children:[(0,U.jsx)(D,{className:`text-xs sm:text-sm font-medium tracking-tight text-foreground group-hover:text-primary transition-colors`,children:e.title}),e.description&&(0,U.jsx)(k,{className:`text-xs text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description})]}),e.badges&&e.badges.length>0&&(0,U.jsx)(x,{className:`p-2 sm:p-4 pt-0`,children:(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.badges.map((e,t)=>(0,U.jsx)(v,{variant:e.variant||`default`,className:`text-xs`,children:e.label},t))})})]})})}function le({columnId:e,onAdd:t}){let[n,r]=H.useState(!1),[i,a]=H.useState(``),o=H.useRef(null),s=()=>{let n=i.trim();n&&(t(e,n),a(``)),r(!1)};return n?(0,U.jsx)(`div`,{className:`mt-2 space-y-2`,children:(0,U.jsx)(b,{ref:o,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(a(``),r(!1))},onBlur:s,placeholder:`Enter card title...`,className:`text-sm`,autoFocus:!0})}):(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground`,onClick:()=>{r(!0),setTimeout(()=>o.current?.focus(),0)},children:[(0,U.jsx)(A,{className:`h-4 w-4 mr-1`}),`Add Card`]})}function ue({column:e,cards:t,onCardClick:n,quickAdd:r,onQuickAdd:i,conditionalFormatting:a,columnStyle:o}){let s=t||[],{setNodeRef:c}=M({id:e.id,data:{type:`column`}}),l=e.limit&&s.length>=e.limit,u=o&&o.width!=null?`flex-shrink-0`:`w-[85vw] sm:w-80 flex-shrink-0`;return(0,U.jsxs)(`div`,{ref:c,role:`group`,"aria-label":e.title,style:o,className:J(`flex flex-col rounded-lg border border-border bg-card/20 backdrop-blur-sm shadow-xl snap-start max-h-full min-h-0`,u,e.className),children:[(0,U.jsx)(`div`,{className:`p-3 sm:p-4 border-b border-border/50 bg-muted/30 rounded-t-lg`,children:(0,U.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,U.jsx)(`h3`,{id:`kanban-col-${e.id}`,className:` text-xs sm:text-sm font-semibold tracking-wider text-primary/90 uppercase truncate`,children:e.title}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsxs)(v,{variant:`secondary`,className:`text-xs tabular-nums`,children:[s.length,e.limit&&` / ${e.limit}`]}),l&&(0,U.jsx)(v,{variant:`destructive`,className:`text-xs`,children:`Full`})]})]})}),(0,U.jsxs)(E,{className:`flex-1 p-4`,children:[(0,U.jsx)(B,{items:s.map(e=>e.id),strategy:L,children:(0,U.jsxs)(`div`,{className:`space-y-2`,role:`list`,"aria-label":`${e.title} cards`,children:[s.length===0&&(0,U.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground/50`,children:(0,U.jsx)(`span`,{className:`text-xs`,children:`No cards`})}),s.map(e=>(0,U.jsx)(X,{card:e,onCardClick:n,conditionalFormatting:a},e.id))]})}),r&&i&&(0,U.jsx)(le,{columnId:e.id,onAdd:i})]})]})}function de({children:e}){return(0,U.jsx)(U.Fragment,{children:e(d())})}function fe({columns:e,onCardMove:t,onCardClick:n,className:r,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c}){return l()?(0,U.jsx)(de,{children:l=>(0,U.jsx)(pe,{columns:e,onCardMove:t,onCardClick:n,className:r,dnd:l,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c})}):(0,U.jsx)(pe,{columns:e,onCardMove:t,onCardClick:n,className:r,dnd:null,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c})}function pe({columns:e,onCardMove:t,onCardClick:n,className:r,dnd:i,quickAdd:a,onQuickAdd:o,coverImageField:s,conditionalFormatting:c,swimlaneField:l}){let[u,d]=H.useState(null),f=H.useRef(null),{width:p}=g(f),m=H.useMemo(()=>p?p<480?{width:Math.max(p-32,220)}:p<720?{width:280}:{width:320}:{},[p]),h=l?`objectui:kanban-collapsed:${l}`:null,[_,v]=H.useState(()=>{if(!h)return new Set;try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>typeof e==`string`))}}catch{}return new Set}),y=H.useMemo(()=>(e||[]).map(e=>({...e,cards:e.cards||[]})),[e]),[b,x]=H.useState(y);H.useEffect(()=>{x(y)},[y]);let S=H.useMemo(()=>{if(!l)return null;let e=b.flatMap(e=>e.cards),t=new Set;return e.forEach(e=>{let n=e[l];t.add(n==null?Y:String(n))}),Array.from(t).sort()},[b,l]),C=H.useCallback(e=>{v(t=>{let n=new Set(t);if(n.has(e)?n.delete(e):n.add(e),h)try{localStorage.setItem(h,JSON.stringify([...n]))}catch{}return n})},[h]),w=F(I(V,{activationConstraint:{distance:5}}),I(ee,{activationConstraint:{delay:200,tolerance:5}})),T=e=>{let{active:t}=e,n=D(t.id);if(d(n),i&&n){let e=O(n.id);e&&i.startDrag({id:n.id,type:`kanban-card`,data:n,sourceId:e.id})}},E=e=>{let{active:n,over:r}=e;if(d(null),!r){i&&i.endDrag();return}let a=n.id,o=r.id;if(a===o){i&&i.endDrag();return}let s=O(a),c=O(o)||k(o);if(!s||!c){i&&i.endDrag();return}if(s.id===c.id){let e=[...s.cards],t=te(e,e.findIndex(e=>e.id===a),e.findIndex(e=>e.id===o));x(e=>e.map(e=>e.id===s.id?{...e,cards:t}:e))}else{let e=[...s.cards],n=[...c.cards],r=e.findIndex(e=>e.id===a),i=o===c.id?n.length:n.findIndex(e=>e.id===o),[l]=e.splice(r,1);n.splice(i,0,l),x(t=>t.map(t=>t.id===s.id?{...t,cards:e}:t.id===c.id?{...t,cards:n}:t)),t&&t(a,s.id,c.id,i)}i&&i.endDrag(c.id)},D=H.useCallback(e=>{for(let t of b){let n=t.cards.find(t=>t.id===e);if(n)return n}return null},[b]),O=H.useCallback(e=>b.find(t=>t.cards.some(t=>t.id===e))||null,[b]),k=H.useCallback(e=>b.find(t=>t.id===e)||null,[b]);return(0,U.jsxs)(z,{sensors:w,collisionDetection:R,onDragStart:T,onDragEnd:E,children:[(0,U.jsxs)(`div`,{ref:f,className:`flex flex-col min-w-0 min-h-0 h-full`,children:[(0,U.jsxs)(`div`,{className:`flex sm:hidden items-center justify-between px-3 pb-2 text-xs text-muted-foreground`,children:[(0,U.jsxs)(`span`,{children:[b.length,` columns`]}),(0,U.jsx)(`span`,{children:`← Swipe to navigate →`})]}),S?(0,U.jsxs)(`div`,{className:J(`flex flex-col gap-1 p-2 sm:p-4 min-w-0 overflow-hidden`,r),role:`region`,"aria-label":`Kanban board with swimlanes`,children:[(0,U.jsx)(`div`,{className:`flex gap-3 sm:gap-4 pl-36 sm:pl-44 overflow-x-auto`,children:b.map(e=>(0,U.jsxs)(`div`,{className:`w-[85vw] sm:w-80 flex-shrink-0 text-center`,children:[(0,U.jsx)(`span`,{className:` text-xs sm:text-sm font-semibold tracking-wider text-primary/90 uppercase`,children:e.title}),(0,U.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,e.cards.length,`)`]})]},e.id))}),S.map(e=>{let t=_.has(e),r=b.reduce((t,n)=>t+n.cards.filter(t=>(t[l]==null?Y:String(t[l]))===e).length,0);return(0,U.jsxs)(`div`,{className:`border rounded-lg bg-muted/10`,children:[(0,U.jsxs)(`button`,{className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-muted/30 transition-colors`,onClick:()=>C(e),"aria-expanded":!t,children:[(0,U.jsx)(`span`,{className:J(`transition-transform text-xs`,t?``:`rotate-90`),children:`▶`}),(0,U.jsx)(`span`,{className:` text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e}),(0,U.jsxs)(`span`,{className:` text-xs text-muted-foreground`,children:[`(`,r,`)`]})]}),!t&&(0,U.jsx)(`div`,{className:`flex gap-3 sm:gap-4 overflow-x-auto px-2 pb-3 pl-36 sm:pl-44`,children:b.map(t=>{let r=t.cards.filter(t=>(t[l]==null?Y:String(t[l]))===e);return(0,U.jsx)(`div`,{className:`w-[85vw] sm:w-80 flex-shrink-0 min-h-[60px] rounded-md bg-card/20 p-2`,children:(0,U.jsx)(B,{items:r.map(e=>e.id),strategy:L,children:(0,U.jsx)(`div`,{className:`space-y-2`,role:`list`,"aria-label":`${t.title} - ${e} cards`,children:r.map(e=>(0,U.jsx)(X,{card:e,onCardClick:n,conditionalFormatting:c},e.id))})})},t.id)})})]},e)})]}):(0,U.jsx)(`div`,{className:J(`flex gap-3 sm:gap-4 overflow-x-auto snap-x snap-mandatory p-2 sm:p-4 bg-muted/10 rounded-lg [-webkit-overflow-scrolling:touch] min-w-0 min-h-0 h-full`,r),role:`region`,"aria-label":`Kanban board`,children:b.map(e=>(0,U.jsx)(ue,{column:e,cards:e.cards,onCardClick:n,quickAdd:a,onQuickAdd:o,conditionalFormatting:c,columnStyle:m},e.id))})]}),(0,U.jsx)(N,{children:(0,U.jsx)(`div`,{"aria-live":`assertive`,"aria-label":u?`Dragging ${u.title}`:void 0,children:u?(0,U.jsx)(X,{card:u,conditionalFormatting:c}):null})})]})}var Z=({schema:e,dataSource:t,className:n,data:r,loading:i,onRowClick:a,onCardClick:s,...l})=>{let d=Array.isArray(r),[p,m]=(0,H.useState)([]),[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(d?i??!1:!1),[y,b]=(0,H.useState)(null),[x,S]=(0,H.useState)(0),C=u(e.bind);(0,H.useEffect)(()=>{if(!d&&!(!t?.onMutation||!e.objectName))return t.onMutation(t=>{t.resource===e.objectName&&S(e=>e+1)})},[t,e.objectName,d]),(0,H.useEffect)(()=>{d&&i!==void 0&&v(i)},[i,d]),(0,H.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&g(r)}catch(e){console.warn(`Failed to fetch object def`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,H.useEffect)(()=>{if(d)return;let n=!0;return e.objectName&&!C&&!e.data&&(async()=>{if(!(!t||typeof t.find!=`function`||!e.objectName)){n&&v(!0);try{let r=o(h?.fields),i=c(await t.find(e.objectName,{options:{$top:100},$filter:e.filter,...r.length>0?{$expand:r}:{}}));n&&m(i)}catch(e){console.error(`[ObjectKanban] Fetch error:`,e),n&&b(e)}finally{n&&v(!1)}}})(),()=>{n=!1}},[e.objectName,t,C,e.data,e.filter,d,h,x]);let w=(d?r:void 0)||C||e.data||p,T=(0,H.useMemo)(()=>{if(!Array.isArray(w))return[];let t=e.cardTitle||e.titleField,n=[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`],r=h?.titleFormat,i=h?.NAME_FIELD_KEY,a=(e,t)=>{let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=e.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=t[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r?i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim():``};return w.map(e=>{let o;if(t&&(o=e[t],typeof o==`string`&&(o=o.trim())),!o&&r){let t=a(r,e);t&&(o=t)}if(!o&&i){let t=e[i];typeof t==`string`?o=t.trim():t&&(o=t)}if(!o)for(let t of n){let n=e[t],r=typeof n==`string`?n.trim():n;if(r){o=r;break}}let s=e=>e>=1e6?`$${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`$${Math.round(e/1e3)}K`:`$${e}`,c=[],l=[`amount`,`value`,`deal_value`,`expected_value`,`opportunity_value`].find(t=>typeof e[t]==`number`);l&&c.push(s(e[l]));let u=[`company`,`company_name`,`account`,`account_name`,`organization`].find(t=>typeof e[t]==`string`&&e[t]);u&&(!o||!String(o).includes(e[u]))&&c.push(e[u]);let d=[`owner`,`owner_name`,`assignee`,`assignee_name`].find(t=>typeof e[t]==`string`&&e[t]);d&&c.push(`@${e[d]}`);let f=[`priority`,`severity`,`industry`,`rating`],p=[];for(let t of f){let n=e[t];if(n!=null&&n!==``&&(p.push({label:String(n),variant:`secondary`}),p.length>=2))break}return{...e,id:e.id||e._id,title:o||`Untitled`,...e.description==null&&c.length>0?{description:c.join(` · `)}:{},...!Array.isArray(e.badges)&&p.length>0?{badges:p}:{}}})},[w,e,h]),E=(0,H.useMemo)(()=>{if(e.columns&&e.columns.length>0)if(typeof e.columns[0]==`string`){if(!e.groupBy)return e.columns.map(e=>({id:e,title:e}))}else return e.columns;if(e.groupBy&&h?.fields?.[e.groupBy]?.options)return h.fields[e.groupBy].options.map(e=>({id:e.value,title:e.label}));if(e.groupBy&&T.length>0){let t=new Set(T.map(t=>t[e.groupBy]));return Array.from(t).map(e=>({id:String(e),title:String(e)}))}return[]},[e.columns,e.groupBy,T,h]),D=e.swimlaneField||e.grouping?.fields?.[0]?.field,k={...e,data:T,columns:E,className:n||e.className,...D?{swimlaneField:D}:{}},A=f({navigation:e.navigation,objectName:e.objectName,onRowClick:a??s});if(y)return(0,U.jsxs)(`div`,{className:`p-4 border border-destructive/50 rounded bg-destructive/10 text-destructive`,children:[`Error loading kanban data: `,y.message]});let j=e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1).replace(/_/g,` `)} Detail`:`Card Details`;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Q,{schema:{...k,onCardClick:e=>{A.handleClick(e),s?.(e)}}}),A.isOverlay&&(0,U.jsx)(O,{...A,title:j,children:e=>(0,U.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,U.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},me=(...e)=>e.filter(Boolean).join(` `),he=({columnId:e,fields:t,onSubmit:n,onCancel:r,defaultValues:i})=>{let[a,o]=H.useState(()=>{let e={};for(let n of t)e[n.name]=i?.[n.name]??n.defaultValue??``;return e}),s=H.useRef(null);H.useEffect(()=>{let e=setTimeout(()=>s.current?.focus(),0);return()=>clearTimeout(e)},[]);let c=H.useCallback((e,t)=>{o(n=>({...n,[e]:t}))},[]),l=H.useCallback(()=>{Object.values(a).some(e=>typeof e==`string`?e.trim().length>0:e!=null)&&n(e,a)},[e,a,n]);return(0,U.jsxs)(`div`,{className:`mt-2 rounded-lg border border-primary/30 bg-card p-3 space-y-2 shadow-sm`,onKeyDown:H.useCallback(e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),r())},[l,r]),role:`form`,"aria-label":`Quick add card`,children:[t.map((t,n)=>(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`qa-${e}-${t.name}`,className:`text-xs text-muted-foreground`,children:t.label??t.name}),ge(t,a[t.name],c,n===0?s:void 0,`qa-${e}-${t.name}`)]},t.name)),(0,U.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,U.jsxs)(j,{type:`button`,size:`sm`,className:`h-7 text-xs gap-1`,onClick:l,children:[(0,U.jsx)(w,{className:`h-3 w-3`}),`Save`]}),(0,U.jsxs)(j,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs gap-1`,onClick:r,children:[(0,U.jsx)(h,{className:`h-3 w-3`}),`Cancel`]})]})]})};function ge(e,t,n,r,i){let a=`text-sm h-8`;switch(e.type){case`select`:return(0,U.jsxs)(`select`,{ref:r,id:i,value:t??``,onChange:t=>n(e.name,t.target.value),className:me(a,`w-full rounded-md border border-input bg-background px-2 py-1 text-sm ring-offset-background`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`),children:[(0,U.jsx)(`option`,{value:``,children:e.placeholder??`Select ${e.label??e.name}...`}),(e.options??[]).map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))]});case`number`:return(0,U.jsx)(b,{ref:r,id:i,type:`number`,value:t??``,onChange:t=>n(e.name,t.target.value===``?``:Number(t.target.value)),placeholder:e.placeholder??`Enter ${e.label??e.name}...`,className:a});default:return(0,U.jsx)(b,{ref:r,id:i,type:`text`,value:t??``,onChange:t=>n(e.name,t.target.value),placeholder:e.placeholder??`Enter ${e.label??e.name}...`,className:a})}}var _e=(...e)=>e.filter(Boolean).join(` `),ve=({templates:e,onSelect:t,columnId:n})=>{let[r,i]=H.useState(!1),a=H.useRef(null);return H.useEffect(()=>{if(!r)return;let e=e=>{a.current&&!a.current.contains(e.target)&&i(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]),(0,U.jsxs)(`div`,{ref:a,className:`relative`,onKeyDown:H.useCallback(e=>{e.key===`Escape`&&i(!1)},[]),children:[(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground gap-1`,onClick:()=>i(e=>!e),"aria-haspopup":`listbox`,"aria-expanded":r,"aria-label":`Add card to ${n}`,children:[(0,U.jsx)(A,{className:`h-4 w-4`}),`Add Card`,(0,U.jsx)(T,{className:_e(`h-3 w-3 transition-transform`,r?`rotate-180`:``)})]}),r&&(0,U.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full rounded-md border border-border bg-popover p-1 shadow-md`,role:`listbox`,"aria-label":`Card templates`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground transition-colors`,role:`option`,"aria-selected":!1,onClick:()=>{t(null),i(!1)},children:[(0,U.jsx)(A,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{className:`font-mono text-xs`,children:`Custom`})]}),e.length>0&&(0,U.jsx)(`div`,{className:`my-1 h-px bg-border`,role:`separator`}),e.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground transition-colors`,role:`option`,"aria-selected":!1,onClick:()=>{t(e),i(!1)},children:[(0,U.jsx)(y,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{className:`font-mono text-xs truncate`,children:e.name})]},e.id))]})]})},ye=`objectui:kanban-column-widths`;function be(e){try{let t=localStorage.getItem(e);if(t){let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return e}}catch{}return{}}function xe(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}function Se({columns:e,defaultWidth:t=320,minWidth:n=200,maxWidth:r=600,storageKey:i}){let a=i?`${ye}:${i}`:ye,[o,s]=(0,H.useState)(()=>be(a)),c=(0,H.useCallback)(e=>Math.max(n,Math.min(r,e)),[n,r]);return{getColumnWidth:(0,H.useCallback)(e=>{let n=o[e];return n==null?t:c(n)},[o,t,c]),setColumnWidth:(0,H.useCallback)((e,t)=>{let n=c(t);s(t=>{let r={...t,[e]:n};return xe(a,r),r})},[c,a]),resetWidths:(0,H.useCallback)(()=>{s({});try{localStorage.removeItem(a)}catch{}},[a]),config:(0,H.useMemo)(()=>({defaultWidth:t,minWidth:n,maxWidth:r,overrides:{...o}}),[t,n,r,o])}}function Ce({swimlanes:e,onCardMove:t}){let[n,r]=(0,H.useState)(null),i=(0,H.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.id,n);return t},[e]),a=(0,H.useCallback)((e,t)=>{if(e===t)return!0;let n=i.get(t);return n?n.acceptFrom?n.acceptFrom.includes(e):!0:!1},[i]),o=(0,H.useCallback)((e,n,i,o)=>a(n,i)?(t?.({cardId:e,fromSwimlane:n,toSwimlane:i,columnId:o}),r(null),!0):!1,[a,t]),s=(0,H.useCallback)(e=>{r(e)},[]),c=(0,H.useCallback)(()=>{r(null)},[]);return{handleCrossSwimlaneMove:o,isDraggingAcrossSwimlanes:n!==null,startCrossSwimlaneDrag:s,endCrossSwimlaneDrag:c,canMoveTo:a}}function we({cards:e,onReorderComplete:t}){let[n,r]=(0,H.useState)(e),[i,a]=(0,H.useState)(!1);!Te(n,e)&&!i&&r(e);let o=(0,H.useCallback)(()=>{r(e),a(!1)},[e]);return{reorderedCards:n,onReorder:(0,H.useCallback)((e,t)=>{r(n=>{if(e<0||t<0||e>=n.length||t>=n.length)return n;let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},[]),isDragging:i,startDrag:(0,H.useCallback)(()=>{a(!0)},[]),endDrag:(0,H.useCallback)(()=>{a(!1),r(e=>(t?.(e),e))},[t]),reset:o}}function Te(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].id!==t[n].id)return!1;return!0}var Ee=e({CardTemplates:()=>ve,InlineQuickAdd:()=>he,KanbanRenderer:()=>Q,ObjectKanban:()=>Z,ObjectKanbanRenderer:()=>$,kanbanComponents:()=>ke,useColumnWidths:()=>Se,useCrossSwimlaneMove:()=>Ce,useQuickAddReorder:()=>we}),De=H.lazy(()=>r(()=>Promise.resolve().then(()=>q),void 0)),Oe=H.lazy(()=>r(()=>Promise.resolve().then(()=>re),void 0)),Q=({schema:e})=>{let t=H.useMemo(()=>{let{columns:t=[],data:n,groupBy:r,coverImageField:i}=e,a=e=>{if(!i)return e;let t=e[i];if(!t)return e;let n=typeof t==`string`?t:t?.url;return n?{...e,coverImage:n}:e};if(n&&r&&Array.isArray(n)){let e={};t.forEach(t=>{t.id&&(e[String(t.id).toLowerCase()]=t.id),t.title&&(e[String(t.title).toLowerCase()]=t.id)});let i=n.reduce((t,n)=>{let i=String(n[r]??``),o=e[i.toLowerCase()]??i;return t[o]||(t[o]=[]),t[o].push(a(n)),t},{});return t.map(e=>({...e,cards:[...(e.cards||[]).map(a),...i[e.id]||[]]}))}return t.map(e=>({...e,cards:(e.cards||[]).map(a)}))},[e]);return(0,U.jsx)(H.Suspense,{fallback:(0,U.jsx)(m,{className:`w-full h-[600px]`}),children:(0,U.jsx)(De,{columns:t,onCardMove:e.onCardMove,onCardClick:e.onCardClick,className:e.className,quickAdd:e.quickAdd,onQuickAdd:e.onQuickAdd,coverImageField:e.coverImageField,conditionalFormatting:e.conditionalFormatting,swimlaneField:e.swimlaneField})})};a.register(`kanban-ui`,Q,{namespace:`plugin-kanban`,label:`Kanban Board`,icon:`LayoutDashboard`,category:`plugin`,inputs:[{name:`columns`,type:`array`,label:`Columns`,description:`Array of { id, title, cards, limit, className }`,required:!0},{name:`onCardMove`,type:`code`,label:`On Card Move`,description:`Callback when a card is moved`,advanced:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:[{id:`todo`,title:`To Do`,cards:[{id:`card-1`,title:`Task 1`,description:`This is the first task`,badges:[{label:`High Priority`,variant:`destructive`},{label:`Feature`,variant:`default`}]},{id:`card-2`,title:`Task 2`,description:`This is the second task`,badges:[{label:`Bug`,variant:`destructive`}]}]},{id:`in-progress`,title:`In Progress`,limit:3,cards:[{id:`card-3`,title:`Task 3`,description:`Currently working on this`,badges:[{label:`In Progress`,variant:`default`}]}]},{id:`done`,title:`Done`,cards:[{id:`card-4`,title:`Task 4`,description:`This task is completed`,badges:[{label:`Completed`,variant:`outline`}]},{id:`card-5`,title:`Task 5`,description:`Another completed task`,badges:[{label:`Completed`,variant:`outline`}]}]}],className:`w-full`}});var ke={kanban:Q,"kanban-enhanced":Oe,"object-kanban":Z};a.register(`kanban-enhanced`,({schema:e})=>{let t=H.useMemo(()=>{let{columns:t=[],data:n,groupBy:r}=e;if(n&&r&&Array.isArray(n)){let e=n.reduce((e,t)=>{let n=t[r];return e[n]||(e[n]=[]),e[n].push(t),e},{});return t.map(t=>({...t,cards:[...t.cards||[],...e[t.id]||[]]}))}return t},[e]);return(0,U.jsx)(H.Suspense,{fallback:(0,U.jsx)(m,{className:`w-full h-[600px]`}),children:(0,U.jsx)(Oe,{columns:t,onCardMove:e.onCardMove,onColumnToggle:e.onColumnToggle,enableVirtualScrolling:e.enableVirtualScrolling,virtualScrollThreshold:e.virtualScrollThreshold,className:e.className,quickAdd:e.quickAdd,onQuickAdd:e.onQuickAdd,conditionalFormatting:e.conditionalFormatting})})},{namespace:`plugin-kanban`,label:`Kanban Board (Enhanced)`,icon:`LayoutGrid`,category:`plugin`,inputs:[{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`enableVirtualScrolling`,type:`boolean`,label:`Virtual Scrolling`,defaultValue:!1},{name:`virtualScrollThreshold`,type:`number`,label:`Virtual Scroll Threshold`,defaultValue:50},{name:`onCardMove`,type:`code`,label:`On Card Move`,advanced:!0},{name:`onColumnToggle`,type:`code`,label:`On Column Toggle`,advanced:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:[],enableVirtualScrolling:!1,virtualScrollThreshold:50,className:`w-full`}});var $=({schema:e,...t})=>{let{dataSource:n}=s()||{};return(0,U.jsx)(Z,{schema:e,dataSource:n,...t})};a.register(`object-kanban`,$,{namespace:`plugin-kanban`,label:`Object Kanban`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`}]}),a.register(`kanban`,$,{namespace:`view`,label:`Kanban Board`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`}]});export{q as n,re as r,Ee as t};
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,m as r,t as i}from"./vendor-react-B1k2FF9f.js";import{H as a,L as o,M as s,R as c,h as l,j as u,m as d,w as f}from"./framework-CoXA0nY6.js";import{$n as p,Ut as m,Vr as h,Y as g,ZA as _,ar as v,cT as y,dn as b,er as x,no as S,nr as C,pj as w,rj as T,rn as E,rr as D,rt as O,tr as k,um as A,yr as j}from"./ui-components-B7mlp0en.js";import{a as M,c as N,d as ee,g as P,h as F,m as I,n as te,o as L,p as R,s as z,t as B,u as V}from"./vendor-dndkit-BfOuYFuz.js";import{t as ne}from"./plugin-grid-Cn_T_wpz.js";var re=e({KanbanEnhanced:()=>K,default:()=>K}),H=t(n(),1),U=i(),W=(...e)=>e.filter(Boolean).join(` `);function ie(e,t){if(!t||t.length===0)return{};for(let n of t){let t=e[n.field];if(t==null)continue;let r=!1,i=String(t);switch(n.operator){case`equals`:r=i===String(n.value);break;case`not_equals`:r=i!==String(n.value);break;case`contains`:r=i.toLowerCase().includes(String(n.value).toLowerCase());break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}if(r)return{...n.backgroundColor?{backgroundColor:n.backgroundColor}:{},...n.borderColor?{borderColor:n.borderColor}:{}}}return{}}function G({card:e,conditionalFormatting:t}){let{attributes:n,listeners:r,setNodeRef:i,transform:a,transition:o,isDragging:s}=M({id:e.id}),c={transform:P.Transform.toString(a),transition:o,opacity:s?.5:void 0},l=ie(e,t);return(0,U.jsx)(`div`,{ref:i,style:c,...n,...r,children:(0,U.jsxs)(p,{className:`mb-2 cursor-grab active:cursor-grabbing border-border bg-card/60 hover:border-primary/40 hover:shadow-lg hover:shadow-primary/10 transition-all duration-300 group`,style:l,children:[e.coverImage&&(0,U.jsx)(`div`,{className:`w-full h-32 overflow-hidden rounded-t-lg`,children:(0,U.jsx)(`img`,{src:e.coverImage,alt:``,className:`w-full h-full object-cover`,loading:`lazy`})}),(0,U.jsxs)(C,{className:`p-4`,children:[(0,U.jsx)(D,{className:`text-sm font-medium tracking-tight text-foreground group-hover:text-primary transition-colors`,children:e.title}),e.description&&(0,U.jsx)(k,{className:`text-xs text-muted-foreground`,children:e.description})]}),e.badges&&e.badges.length>0&&(0,U.jsx)(x,{className:`p-4 pt-0`,children:(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.badges.map((e,t)=>(0,U.jsx)(v,{variant:e.variant||`default`,className:`text-xs`,children:e.label},t))})})]})})}function ae({cards:e,parentRef:t,conditionalFormatting:n}){let r=ne({count:e.length,getScrollElement:()=>t.current,estimateSize:()=>120,overscan:5});return(0,U.jsx)(`div`,{style:{height:`${r.getTotalSize()}px`,width:`100%`,position:`relative`},children:r.getVirtualItems().map(t=>{let r=e[t.index];return(0,U.jsx)(`div`,{style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${t.start}px)`},children:(0,U.jsx)(G,{card:r,conditionalFormatting:n})},r.id)})})}function oe({columnId:e,onAdd:t}){let[n,r]=H.useState(!1),[i,a]=H.useState(``),o=H.useRef(null),s=()=>{let n=i.trim();n&&(t(e,n),a(``)),r(!1)};return n?(0,U.jsx)(`div`,{className:`mt-2 space-y-2`,children:(0,U.jsx)(b,{ref:o,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(a(``),r(!1))},onBlur:s,placeholder:`Enter card title...`,className:`text-sm`,autoFocus:!0})}):(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground`,onClick:()=>{r(!0),setTimeout(()=>o.current?.focus(),0)},children:[(0,U.jsx)(A,{className:`h-4 w-4 mr-1`}),`Add Card`]})}function se({column:e,cards:t,onToggle:n,enableVirtual:r,quickAdd:i,onQuickAdd:a,conditionalFormatting:o}){let s=t||[],c=H.useRef(null),{setNodeRef:l}=M({id:e.id,data:{type:`column`}}),u=e.limit&&s.length>=e.limit,d=e.limit&&s.length>=e.limit*.8;return(0,U.jsxs)(`div`,{ref:l,className:W(`flex flex-col flex-shrink-0 rounded-lg border border-border bg-card/20 backdrop-blur-sm shadow-xl transition-all`,e.collapsed?`w-16`:`w-80`,e.className),children:[(0,U.jsxs)(`div`,{className:`p-4 border-b border-border/50 bg-muted/20 flex items-center justify-between`,children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 min-w-0`,children:[(0,U.jsx)(j,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>n(!e.collapsed),children:e.collapsed?(0,U.jsx)(_,{className:`h-4 w-4`}):(0,U.jsx)(T,{className:`h-4 w-4`})}),!e.collapsed&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`h3`,{className:` text-sm font-semibold tracking-wider text-primary/90 uppercase truncate`,children:e.title}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsxs)(`span`,{className:W(` text-xs`,u?`text-destructive`:d?`text-yellow-500`:`text-muted-foreground`),children:[s.length,e.limit&&` / ${e.limit}`]}),u&&(0,U.jsx)(v,{variant:`destructive`,className:`text-xs`,children:`Full`}),d&&!u&&(0,U.jsx)(S,{className:`h-3 w-3 text-yellow-500`})]})]})]}),e.collapsed&&(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,U.jsx)(`span`,{className:` text-xs font-bold text-primary/90 [writing-mode:vertical-rl] rotate-180`,children:e.title}),(0,U.jsx)(v,{variant:`secondary`,className:`text-xs`,children:s.length})]})]}),!e.collapsed&&(0,U.jsxs)(`div`,{ref:c,className:`flex-1 p-4 overflow-y-auto`,style:{maxHeight:`600px`},children:[(0,U.jsx)(B,{items:s.map(e=>e.id),strategy:L,children:r?(0,U.jsx)(ae,{cards:s,parentRef:c,conditionalFormatting:o}):(0,U.jsx)(`div`,{className:`space-y-2`,children:s.map(e=>(0,U.jsx)(G,{card:e,conditionalFormatting:o},e.id))})}),i&&a&&(0,U.jsx)(oe,{columnId:e.id,onAdd:a})]})]})}function K({columns:e,onCardMove:t,onColumnToggle:n,enableVirtualScrolling:r=!1,virtualScrollThreshold:i=50,className:a,quickAdd:o,onQuickAdd:s,conditionalFormatting:c}){let[l,u]=H.useState(null),d=H.useMemo(()=>(e||[]).map(e=>({...e,cards:e.cards||[]})),[e]),[f,p]=H.useState(d);H.useEffect(()=>{p(d)},[d]);let m=F(I(V,{activationConstraint:{distance:8}})),h=e=>{let{active:t}=e;u(_(t.id))},g=e=>{let{active:n,over:r}=e;if(u(null),!r)return;let i=n.id,a=r.id;if(i===a)return;let o=v(i),s=v(a)||y(a);if(!(!o||!s))if(o.id===s.id){let e=[...o.cards],t=te(e,e.findIndex(e=>e.id===i),e.findIndex(e=>e.id===a));p(e=>e.map(e=>e.id===o.id?{...e,cards:t}:e))}else{let e=[...o.cards],n=[...s.cards],r=e.findIndex(e=>e.id===i),c=a===s.id?n.length:n.findIndex(e=>e.id===a),[l]=e.splice(r,1);n.splice(c,0,l),p(t=>t.map(t=>t.id===o.id?{...t,cards:e}:t.id===s.id?{...t,cards:n}:t)),t&&t(i,o.id,s.id,c)}},_=H.useCallback(e=>{for(let t of f){let n=t.cards.find(t=>t.id===e);if(n)return n}return null},[f]),v=H.useCallback(e=>f.find(t=>t.cards.some(t=>t.id===e))||null,[f]),y=H.useCallback(e=>f.find(t=>t.id===e)||null,[f]),b=H.useCallback((e,t)=>{p(n=>n.map(n=>n.id===e?{...n,collapsed:t}:n)),n?.(e,t)},[n]);return(0,U.jsxs)(z,{sensors:m,collisionDetection:R,onDragStart:h,onDragEnd:g,children:[(0,U.jsx)(`div`,{className:W(`flex gap-4 overflow-x-auto p-4`,a),children:f.map(e=>{let t=r&&e.cards.length>i;return(0,U.jsx)(se,{column:e,cards:e.cards,onToggle:t=>b(e.id,t),enableVirtual:t,quickAdd:o,onQuickAdd:s,conditionalFormatting:c},e.id)})}),(0,U.jsx)(N,{children:l?(0,U.jsx)(G,{card:l,conditionalFormatting:c}):null})]})}var q=e({default:()=>fe}),J=(...e)=>e.filter(Boolean).join(` `),Y=`Uncategorized`;function ce(e,t){if(!t||t.length===0)return{};for(let n of t){let t=e[n.field];if(t==null)continue;let r=!1,i=String(t);switch(n.operator){case`equals`:r=i===String(n.value);break;case`not_equals`:r=i!==String(n.value);break;case`contains`:r=i.toLowerCase().includes(String(n.value).toLowerCase());break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}if(r)return{...n.backgroundColor?{backgroundColor:n.backgroundColor}:{},...n.borderColor?{borderColor:n.borderColor}:{}}}return{}}function X({card:e,onCardClick:t,conditionalFormatting:n}){let{attributes:r,listeners:i,setNodeRef:a,transform:o,transition:s,isDragging:c}=M({id:e.id}),l={transform:P.Transform.toString(o),transition:s,opacity:c?.5:void 0},u=ce(e,n);return(0,U.jsx)(`div`,{ref:a,style:l,...r,...i,role:`listitem`,"aria-label":e.title,onClick:()=>t?.(e),children:(0,U.jsxs)(p,{className:`mb-2 cursor-grab active:cursor-grabbing border-border border-l-4 border-l-primary/40 bg-card/60 hover:border-primary/40 hover:shadow-lg hover:shadow-primary/10 transition-all duration-300 group touch-manipulation`,style:u,children:[e.coverImage&&(0,U.jsx)(`div`,{className:`w-full h-32 overflow-hidden rounded-t-lg`,children:(0,U.jsx)(`img`,{src:e.coverImage,alt:``,className:`w-full h-full object-cover`,loading:`lazy`})}),(0,U.jsxs)(C,{className:`p-2 sm:p-4`,children:[(0,U.jsx)(D,{className:`text-xs sm:text-sm font-medium tracking-tight text-foreground group-hover:text-primary transition-colors`,children:e.title}),e.description&&(0,U.jsx)(k,{className:`text-xs text-muted-foreground line-clamp-2 sm:line-clamp-none`,children:e.description})]}),e.badges&&e.badges.length>0&&(0,U.jsx)(x,{className:`p-2 sm:p-4 pt-0`,children:(0,U.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.badges.map((e,t)=>(0,U.jsx)(v,{variant:e.variant||`default`,className:`text-xs`,children:e.label},t))})})]})})}function le({columnId:e,onAdd:t}){let[n,r]=H.useState(!1),[i,a]=H.useState(``),o=H.useRef(null),s=()=>{let n=i.trim();n&&(t(e,n),a(``)),r(!1)};return n?(0,U.jsx)(`div`,{className:`mt-2 space-y-2`,children:(0,U.jsx)(b,{ref:o,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(a(``),r(!1))},onBlur:s,placeholder:`Enter card title...`,className:`text-sm`,autoFocus:!0})}):(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground`,onClick:()=>{r(!0),setTimeout(()=>o.current?.focus(),0)},children:[(0,U.jsx)(A,{className:`h-4 w-4 mr-1`}),`Add Card`]})}function ue({column:e,cards:t,onCardClick:n,quickAdd:r,onQuickAdd:i,conditionalFormatting:a,columnStyle:o}){let s=t||[],{setNodeRef:c}=M({id:e.id,data:{type:`column`}}),l=e.limit&&s.length>=e.limit,u=o&&o.width!=null?`flex-shrink-0`:`w-[85vw] sm:w-80 flex-shrink-0`;return(0,U.jsxs)(`div`,{ref:c,role:`group`,"aria-label":e.title,style:o,className:J(`flex flex-col rounded-lg border border-border bg-card/20 backdrop-blur-sm shadow-xl snap-start max-h-full min-h-0`,u,e.className),children:[(0,U.jsx)(`div`,{className:`p-3 sm:p-4 border-b border-border/50 bg-muted/30 rounded-t-lg`,children:(0,U.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,U.jsx)(`h3`,{id:`kanban-col-${e.id}`,className:` text-xs sm:text-sm font-semibold tracking-wider text-primary/90 uppercase truncate`,children:e.title}),(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsxs)(v,{variant:`secondary`,className:`text-xs tabular-nums`,children:[s.length,e.limit&&` / ${e.limit}`]}),l&&(0,U.jsx)(v,{variant:`destructive`,className:`text-xs`,children:`Full`})]})]})}),(0,U.jsxs)(E,{className:`flex-1 p-4`,children:[(0,U.jsx)(B,{items:s.map(e=>e.id),strategy:L,children:(0,U.jsxs)(`div`,{className:`space-y-2`,role:`list`,"aria-label":`${e.title} cards`,children:[s.length===0&&(0,U.jsx)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground/50`,children:(0,U.jsx)(`span`,{className:`text-xs`,children:`No cards`})}),s.map(e=>(0,U.jsx)(X,{card:e,onCardClick:n,conditionalFormatting:a},e.id))]})}),r&&i&&(0,U.jsx)(le,{columnId:e.id,onAdd:i})]})]})}function de({children:e}){return(0,U.jsx)(U.Fragment,{children:e(d())})}function fe({columns:e,onCardMove:t,onCardClick:n,className:r,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c}){return l()?(0,U.jsx)(de,{children:l=>(0,U.jsx)(pe,{columns:e,onCardMove:t,onCardClick:n,className:r,dnd:l,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c})}):(0,U.jsx)(pe,{columns:e,onCardMove:t,onCardClick:n,className:r,dnd:null,quickAdd:i,onQuickAdd:a,coverImageField:o,conditionalFormatting:s,swimlaneField:c})}function pe({columns:e,onCardMove:t,onCardClick:n,className:r,dnd:i,quickAdd:a,onQuickAdd:o,coverImageField:s,conditionalFormatting:c,swimlaneField:l}){let[u,d]=H.useState(null),f=H.useRef(null),{width:p}=g(f),m=H.useMemo(()=>p?p<480?{width:Math.max(p-32,220)}:p<720?{width:280}:{width:320}:{},[p]),h=l?`objectui:kanban-collapsed:${l}`:null,[_,v]=H.useState(()=>{if(!h)return new Set;try{let e=localStorage.getItem(h);if(e){let t=JSON.parse(e);if(Array.isArray(t))return new Set(t.filter(e=>typeof e==`string`))}}catch{}return new Set}),y=H.useMemo(()=>(e||[]).map(e=>({...e,cards:e.cards||[]})),[e]),[b,x]=H.useState(y);H.useEffect(()=>{x(y)},[y]);let S=H.useMemo(()=>{if(!l)return null;let e=b.flatMap(e=>e.cards),t=new Set;return e.forEach(e=>{let n=e[l];t.add(n==null?Y:String(n))}),Array.from(t).sort()},[b,l]),C=H.useCallback(e=>{v(t=>{let n=new Set(t);if(n.has(e)?n.delete(e):n.add(e),h)try{localStorage.setItem(h,JSON.stringify([...n]))}catch{}return n})},[h]),w=F(I(V,{activationConstraint:{distance:5}}),I(ee,{activationConstraint:{delay:200,tolerance:5}})),T=e=>{let{active:t}=e,n=D(t.id);if(d(n),i&&n){let e=O(n.id);e&&i.startDrag({id:n.id,type:`kanban-card`,data:n,sourceId:e.id})}},E=e=>{let{active:n,over:r}=e;if(d(null),!r){i&&i.endDrag();return}let a=n.id,o=r.id;if(a===o){i&&i.endDrag();return}let s=O(a),c=O(o)||k(o);if(!s||!c){i&&i.endDrag();return}if(s.id===c.id){let e=[...s.cards],t=te(e,e.findIndex(e=>e.id===a),e.findIndex(e=>e.id===o));x(e=>e.map(e=>e.id===s.id?{...e,cards:t}:e))}else{let e=[...s.cards],n=[...c.cards],r=e.findIndex(e=>e.id===a),i=o===c.id?n.length:n.findIndex(e=>e.id===o),[l]=e.splice(r,1);n.splice(i,0,l),x(t=>t.map(t=>t.id===s.id?{...t,cards:e}:t.id===c.id?{...t,cards:n}:t)),t&&t(a,s.id,c.id,i)}i&&i.endDrag(c.id)},D=H.useCallback(e=>{for(let t of b){let n=t.cards.find(t=>t.id===e);if(n)return n}return null},[b]),O=H.useCallback(e=>b.find(t=>t.cards.some(t=>t.id===e))||null,[b]),k=H.useCallback(e=>b.find(t=>t.id===e)||null,[b]);return(0,U.jsxs)(z,{sensors:w,collisionDetection:R,onDragStart:T,onDragEnd:E,children:[(0,U.jsxs)(`div`,{ref:f,className:`flex flex-col min-w-0 min-h-0 h-full`,children:[(0,U.jsxs)(`div`,{className:`flex sm:hidden items-center justify-between px-3 pb-2 text-xs text-muted-foreground`,children:[(0,U.jsxs)(`span`,{children:[b.length,` columns`]}),(0,U.jsx)(`span`,{children:`← Swipe to navigate →`})]}),S?(0,U.jsxs)(`div`,{className:J(`flex flex-col gap-1 p-2 sm:p-4 min-w-0 overflow-hidden`,r),role:`region`,"aria-label":`Kanban board with swimlanes`,children:[(0,U.jsx)(`div`,{className:`flex gap-3 sm:gap-4 pl-36 sm:pl-44 overflow-x-auto`,children:b.map(e=>(0,U.jsxs)(`div`,{className:`w-[85vw] sm:w-80 flex-shrink-0 text-center`,children:[(0,U.jsx)(`span`,{className:` text-xs sm:text-sm font-semibold tracking-wider text-primary/90 uppercase`,children:e.title}),(0,U.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,e.cards.length,`)`]})]},e.id))}),S.map(e=>{let t=_.has(e),r=b.reduce((t,n)=>t+n.cards.filter(t=>(t[l]==null?Y:String(t[l]))===e).length,0);return(0,U.jsxs)(`div`,{className:`border rounded-lg bg-muted/10`,children:[(0,U.jsxs)(`button`,{className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-muted/30 transition-colors`,onClick:()=>C(e),"aria-expanded":!t,children:[(0,U.jsx)(`span`,{className:J(`transition-transform text-xs`,t?``:`rotate-90`),children:`▶`}),(0,U.jsx)(`span`,{className:` text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:e}),(0,U.jsxs)(`span`,{className:` text-xs text-muted-foreground`,children:[`(`,r,`)`]})]}),!t&&(0,U.jsx)(`div`,{className:`flex gap-3 sm:gap-4 overflow-x-auto px-2 pb-3 pl-36 sm:pl-44`,children:b.map(t=>{let r=t.cards.filter(t=>(t[l]==null?Y:String(t[l]))===e);return(0,U.jsx)(`div`,{className:`w-[85vw] sm:w-80 flex-shrink-0 min-h-[60px] rounded-md bg-card/20 p-2`,children:(0,U.jsx)(B,{items:r.map(e=>e.id),strategy:L,children:(0,U.jsx)(`div`,{className:`space-y-2`,role:`list`,"aria-label":`${t.title} - ${e} cards`,children:r.map(e=>(0,U.jsx)(X,{card:e,onCardClick:n,conditionalFormatting:c},e.id))})})},t.id)})})]},e)})]}):(0,U.jsx)(`div`,{className:J(`flex gap-3 sm:gap-4 overflow-x-auto snap-x snap-mandatory p-2 sm:p-4 bg-muted/10 rounded-lg [-webkit-overflow-scrolling:touch] min-w-0 min-h-0 h-full`,r),role:`region`,"aria-label":`Kanban board`,children:b.map(e=>(0,U.jsx)(ue,{column:e,cards:e.cards,onCardClick:n,quickAdd:a,onQuickAdd:o,conditionalFormatting:c,columnStyle:m},e.id))})]}),(0,U.jsx)(N,{children:(0,U.jsx)(`div`,{"aria-live":`assertive`,"aria-label":u?`Dragging ${u.title}`:void 0,children:u?(0,U.jsx)(X,{card:u,conditionalFormatting:c}):null})})]})}var Z=({schema:e,dataSource:t,className:n,data:r,loading:i,onRowClick:a,onCardClick:s,...l})=>{let d=Array.isArray(r),[p,m]=(0,H.useState)([]),[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(d?i??!1:!1),[y,b]=(0,H.useState)(null),[x,S]=(0,H.useState)(0),C=u(e.bind);(0,H.useEffect)(()=>{if(!d&&!(!t?.onMutation||!e.objectName))return t.onMutation(t=>{t.resource===e.objectName&&S(e=>e+1)})},[t,e.objectName,d]),(0,H.useEffect)(()=>{d&&i!==void 0&&v(i)},[i,d]),(0,H.useEffect)(()=>{let n=!0;return(async()=>{if(!(!t||!e.objectName))try{let r=await t.getObjectSchema(e.objectName);n&&g(r)}catch(e){console.warn(`Failed to fetch object def`,e)}})(),()=>{n=!1}},[e.objectName,t]),(0,H.useEffect)(()=>{if(d)return;let n=!0;return e.objectName&&!C&&!e.data&&(async()=>{if(!(!t||typeof t.find!=`function`||!e.objectName)){n&&v(!0);try{let r=o(h?.fields),i=c(await t.find(e.objectName,{options:{$top:100},$filter:e.filter,...r.length>0?{$expand:r}:{}}));n&&m(i)}catch(e){console.error(`[ObjectKanban] Fetch error:`,e),n&&b(e)}finally{n&&v(!1)}}})(),()=>{n=!1}},[e.objectName,t,C,e.data,e.filter,d,h,x]);let w=(d?r:void 0)||C||e.data||p,T=(0,H.useMemo)(()=>{if(!Array.isArray(w))return[];let t=e.cardTitle||e.titleField,n=[`name`,`full_name`,`fullName`,`title`,`subject`,`label`,`display_name`,`displayName`],r=h?.titleFormat,i=h?.NAME_FIELD_KEY,a=(e,t)=>{let n=`[-\\u2013\\u2014|/·,:]`,r=!1,i=e.replace(/\{([^{}]+)\}/g,(e,n)=>{let i=t[n.trim()];return i!=null&&i!==``?(r=!0,String(i)):`\0`});return r?i.replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\\s*${n}\\s*`,`g`),``).replace(RegExp(`\0`,`g`),``).replace(/\s+/g,` `).trim():``};return w.map(e=>{let o;if(t&&(o=e[t],typeof o==`string`&&(o=o.trim())),!o&&r){let t=a(r,e);t&&(o=t)}if(!o&&i){let t=e[i];typeof t==`string`?o=t.trim():t&&(o=t)}if(!o)for(let t of n){let n=e[t],r=typeof n==`string`?n.trim():n;if(r){o=r;break}}let s=e=>e>=1e6?`$${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`:e>=1e3?`$${Math.round(e/1e3)}K`:`$${e}`,c=[],l=[`amount`,`value`,`deal_value`,`expected_value`,`opportunity_value`].find(t=>typeof e[t]==`number`);l&&c.push(s(e[l]));let u=[`company`,`company_name`,`account`,`account_name`,`organization`].find(t=>typeof e[t]==`string`&&e[t]);u&&(!o||!String(o).includes(e[u]))&&c.push(e[u]);let d=[`owner`,`owner_name`,`assignee`,`assignee_name`].find(t=>typeof e[t]==`string`&&e[t]);d&&c.push(`@${e[d]}`);let f=[`priority`,`severity`,`industry`,`rating`],p=[];for(let t of f){let n=e[t];if(n!=null&&n!==``&&(p.push({label:String(n),variant:`secondary`}),p.length>=2))break}return{...e,id:e.id||e._id,title:o||`Untitled`,...e.description==null&&c.length>0?{description:c.join(` · `)}:{},...!Array.isArray(e.badges)&&p.length>0?{badges:p}:{}}})},[w,e,h]),E=(0,H.useMemo)(()=>{if(e.columns&&e.columns.length>0)if(typeof e.columns[0]==`string`){if(!e.groupBy)return e.columns.map(e=>({id:e,title:e}))}else return e.columns;if(e.groupBy&&h?.fields?.[e.groupBy]?.options)return h.fields[e.groupBy].options.map(e=>({id:e.value,title:e.label}));if(e.groupBy&&T.length>0){let t=new Set(T.map(t=>t[e.groupBy]));return Array.from(t).map(e=>({id:String(e),title:String(e)}))}return[]},[e.columns,e.groupBy,T,h]),D=e.swimlaneField||e.grouping?.fields?.[0]?.field,k={...e,data:T,columns:E,className:n||e.className,...D?{swimlaneField:D}:{}},A=f({navigation:e.navigation,objectName:e.objectName,onRowClick:a??s});if(y)return(0,U.jsxs)(`div`,{className:`p-4 border border-destructive/50 rounded bg-destructive/10 text-destructive`,children:[`Error loading kanban data: `,y.message]});let j=e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1).replace(/_/g,` `)} Detail`:`Card Details`;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Q,{schema:{...k,onCardClick:e=>{A.handleClick(e),s?.(e)}}}),A.isOverlay&&(0,U.jsx)(O,{...A,title:j,children:e=>(0,U.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,U.jsxs)(`div`,{className:`flex flex-col`,children:[(0,U.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,U.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})},me=(...e)=>e.filter(Boolean).join(` `),he=({columnId:e,fields:t,onSubmit:n,onCancel:r,defaultValues:i})=>{let[a,o]=H.useState(()=>{let e={};for(let n of t)e[n.name]=i?.[n.name]??n.defaultValue??``;return e}),s=H.useRef(null);H.useEffect(()=>{let e=setTimeout(()=>s.current?.focus(),0);return()=>clearTimeout(e)},[]);let c=H.useCallback((e,t)=>{o(n=>({...n,[e]:t}))},[]),l=H.useCallback(()=>{Object.values(a).some(e=>typeof e==`string`?e.trim().length>0:e!=null)&&n(e,a)},[e,a,n]);return(0,U.jsxs)(`div`,{className:`mt-2 rounded-lg border border-primary/30 bg-card p-3 space-y-2 shadow-sm`,onKeyDown:H.useCallback(e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),r())},[l,r]),role:`form`,"aria-label":`Quick add card`,children:[t.map((t,n)=>(0,U.jsxs)(`div`,{className:`space-y-1`,children:[(0,U.jsx)(`label`,{htmlFor:`qa-${e}-${t.name}`,className:`text-xs text-muted-foreground`,children:t.label??t.name}),ge(t,a[t.name],c,n===0?s:void 0,`qa-${e}-${t.name}`)]},t.name)),(0,U.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,U.jsxs)(j,{type:`button`,size:`sm`,className:`h-7 text-xs gap-1`,onClick:l,children:[(0,U.jsx)(w,{className:`h-3 w-3`}),`Save`]}),(0,U.jsxs)(j,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 text-xs gap-1`,onClick:r,children:[(0,U.jsx)(h,{className:`h-3 w-3`}),`Cancel`]})]})]})};function ge(e,t,n,r,i){let a=`text-sm h-8`;switch(e.type){case`select`:return(0,U.jsxs)(`select`,{ref:r,id:i,value:t??``,onChange:t=>n(e.name,t.target.value),className:me(a,`w-full rounded-md border border-input bg-background px-2 py-1 text-sm ring-offset-background`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`),children:[(0,U.jsx)(`option`,{value:``,children:e.placeholder??`Select ${e.label??e.name}...`}),(e.options??[]).map(e=>(0,U.jsx)(`option`,{value:e.value,children:e.label},e.value))]});case`number`:return(0,U.jsx)(b,{ref:r,id:i,type:`number`,value:t??``,onChange:t=>n(e.name,t.target.value===``?``:Number(t.target.value)),placeholder:e.placeholder??`Enter ${e.label??e.name}...`,className:a});default:return(0,U.jsx)(b,{ref:r,id:i,type:`text`,value:t??``,onChange:t=>n(e.name,t.target.value),placeholder:e.placeholder??`Enter ${e.label??e.name}...`,className:a})}}var _e=(...e)=>e.filter(Boolean).join(` `),ve=({templates:e,onSelect:t,columnId:n})=>{let[r,i]=H.useState(!1),a=H.useRef(null);return H.useEffect(()=>{if(!r)return;let e=e=>{a.current&&!a.current.contains(e.target)&&i(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[r]),(0,U.jsxs)(`div`,{ref:a,className:`relative`,onKeyDown:H.useCallback(e=>{e.key===`Escape`&&i(!1)},[]),children:[(0,U.jsxs)(j,{variant:`ghost`,size:`sm`,className:`w-full mt-2 text-muted-foreground hover:text-foreground gap-1`,onClick:()=>i(e=>!e),"aria-haspopup":`listbox`,"aria-expanded":r,"aria-label":`Add card to ${n}`,children:[(0,U.jsx)(A,{className:`h-4 w-4`}),`Add Card`,(0,U.jsx)(T,{className:_e(`h-3 w-3 transition-transform`,r?`rotate-180`:``)})]}),r&&(0,U.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full rounded-md border border-border bg-popover p-1 shadow-md`,role:`listbox`,"aria-label":`Card templates`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground transition-colors`,role:`option`,"aria-selected":!1,onClick:()=>{t(null),i(!1)},children:[(0,U.jsx)(A,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{className:`font-mono text-xs`,children:`Custom`})]}),e.length>0&&(0,U.jsx)(`div`,{className:`my-1 h-px bg-border`,role:`separator`}),e.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground transition-colors`,role:`option`,"aria-selected":!1,onClick:()=>{t(e),i(!1)},children:[(0,U.jsx)(y,{className:`h-4 w-4 text-muted-foreground`}),(0,U.jsx)(`span`,{className:`font-mono text-xs truncate`,children:e.name})]},e.id))]})]})},ye=`objectui:kanban-column-widths`;function be(e){try{let t=localStorage.getItem(e);if(t){let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return e}}catch{}return{}}function xe(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}function Se({columns:e,defaultWidth:t=320,minWidth:n=200,maxWidth:r=600,storageKey:i}){let a=i?`${ye}:${i}`:ye,[o,s]=(0,H.useState)(()=>be(a)),c=(0,H.useCallback)(e=>Math.max(n,Math.min(r,e)),[n,r]);return{getColumnWidth:(0,H.useCallback)(e=>{let n=o[e];return n==null?t:c(n)},[o,t,c]),setColumnWidth:(0,H.useCallback)((e,t)=>{let n=c(t);s(t=>{let r={...t,[e]:n};return xe(a,r),r})},[c,a]),resetWidths:(0,H.useCallback)(()=>{s({});try{localStorage.removeItem(a)}catch{}},[a]),config:(0,H.useMemo)(()=>({defaultWidth:t,minWidth:n,maxWidth:r,overrides:{...o}}),[t,n,r,o])}}function Ce({swimlanes:e,onCardMove:t}){let[n,r]=(0,H.useState)(null),i=(0,H.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.id,n);return t},[e]),a=(0,H.useCallback)((e,t)=>{if(e===t)return!0;let n=i.get(t);return n?n.acceptFrom?n.acceptFrom.includes(e):!0:!1},[i]),o=(0,H.useCallback)((e,n,i,o)=>a(n,i)?(t?.({cardId:e,fromSwimlane:n,toSwimlane:i,columnId:o}),r(null),!0):!1,[a,t]),s=(0,H.useCallback)(e=>{r(e)},[]),c=(0,H.useCallback)(()=>{r(null)},[]);return{handleCrossSwimlaneMove:o,isDraggingAcrossSwimlanes:n!==null,startCrossSwimlaneDrag:s,endCrossSwimlaneDrag:c,canMoveTo:a}}function we({cards:e,onReorderComplete:t}){let[n,r]=(0,H.useState)(e),[i,a]=(0,H.useState)(!1);!Te(n,e)&&!i&&r(e);let o=(0,H.useCallback)(()=>{r(e),a(!1)},[e]);return{reorderedCards:n,onReorder:(0,H.useCallback)((e,t)=>{r(n=>{if(e<0||t<0||e>=n.length||t>=n.length)return n;let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},[]),isDragging:i,startDrag:(0,H.useCallback)(()=>{a(!0)},[]),endDrag:(0,H.useCallback)(()=>{a(!1),r(e=>(t?.(e),e))},[t]),reset:o}}function Te(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n].id!==t[n].id)return!1;return!0}var Ee=e({CardTemplates:()=>ve,InlineQuickAdd:()=>he,KanbanRenderer:()=>Q,ObjectKanban:()=>Z,ObjectKanbanRenderer:()=>$,kanbanComponents:()=>ke,useColumnWidths:()=>Se,useCrossSwimlaneMove:()=>Ce,useQuickAddReorder:()=>we}),De=H.lazy(()=>r(()=>Promise.resolve().then(()=>q),void 0)),Oe=H.lazy(()=>r(()=>Promise.resolve().then(()=>re),void 0)),Q=({schema:e})=>{let t=H.useMemo(()=>{let{columns:t=[],data:n,groupBy:r,coverImageField:i}=e,a=e=>{if(!i)return e;let t=e[i];if(!t)return e;let n=typeof t==`string`?t:t?.url;return n?{...e,coverImage:n}:e};if(n&&r&&Array.isArray(n)){let e={};t.forEach(t=>{t.id&&(e[String(t.id).toLowerCase()]=t.id),t.title&&(e[String(t.title).toLowerCase()]=t.id)});let i=n.reduce((t,n)=>{let i=String(n[r]??``),o=e[i.toLowerCase()]??i;return t[o]||(t[o]=[]),t[o].push(a(n)),t},{});return t.map(e=>({...e,cards:[...(e.cards||[]).map(a),...i[e.id]||[]]}))}return t.map(e=>({...e,cards:(e.cards||[]).map(a)}))},[e]);return(0,U.jsx)(H.Suspense,{fallback:(0,U.jsx)(m,{className:`w-full h-[600px]`}),children:(0,U.jsx)(De,{columns:t,onCardMove:e.onCardMove,onCardClick:e.onCardClick,className:e.className,quickAdd:e.quickAdd,onQuickAdd:e.onQuickAdd,coverImageField:e.coverImageField,conditionalFormatting:e.conditionalFormatting,swimlaneField:e.swimlaneField})})};a.register(`kanban-ui`,Q,{namespace:`plugin-kanban`,label:`Kanban Board`,icon:`LayoutDashboard`,category:`plugin`,inputs:[{name:`columns`,type:`array`,label:`Columns`,description:`Array of { id, title, cards, limit, className }`,required:!0},{name:`onCardMove`,type:`code`,label:`On Card Move`,description:`Callback when a card is moved`,advanced:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:[{id:`todo`,title:`To Do`,cards:[{id:`card-1`,title:`Task 1`,description:`This is the first task`,badges:[{label:`High Priority`,variant:`destructive`},{label:`Feature`,variant:`default`}]},{id:`card-2`,title:`Task 2`,description:`This is the second task`,badges:[{label:`Bug`,variant:`destructive`}]}]},{id:`in-progress`,title:`In Progress`,limit:3,cards:[{id:`card-3`,title:`Task 3`,description:`Currently working on this`,badges:[{label:`In Progress`,variant:`default`}]}]},{id:`done`,title:`Done`,cards:[{id:`card-4`,title:`Task 4`,description:`This task is completed`,badges:[{label:`Completed`,variant:`outline`}]},{id:`card-5`,title:`Task 5`,description:`Another completed task`,badges:[{label:`Completed`,variant:`outline`}]}]}],className:`w-full`}});var ke={kanban:Q,"kanban-enhanced":Oe,"object-kanban":Z};a.register(`kanban-enhanced`,({schema:e})=>{let t=H.useMemo(()=>{let{columns:t=[],data:n,groupBy:r}=e;if(n&&r&&Array.isArray(n)){let e=n.reduce((e,t)=>{let n=t[r];return e[n]||(e[n]=[]),e[n].push(t),e},{});return t.map(t=>({...t,cards:[...t.cards||[],...e[t.id]||[]]}))}return t},[e]);return(0,U.jsx)(H.Suspense,{fallback:(0,U.jsx)(m,{className:`w-full h-[600px]`}),children:(0,U.jsx)(Oe,{columns:t,onCardMove:e.onCardMove,onColumnToggle:e.onColumnToggle,enableVirtualScrolling:e.enableVirtualScrolling,virtualScrollThreshold:e.virtualScrollThreshold,className:e.className,quickAdd:e.quickAdd,onQuickAdd:e.onQuickAdd,conditionalFormatting:e.conditionalFormatting})})},{namespace:`plugin-kanban`,label:`Kanban Board (Enhanced)`,icon:`LayoutGrid`,category:`plugin`,inputs:[{name:`columns`,type:`array`,label:`Columns`,required:!0},{name:`enableVirtualScrolling`,type:`boolean`,label:`Virtual Scrolling`,defaultValue:!1},{name:`virtualScrollThreshold`,type:`number`,label:`Virtual Scroll Threshold`,defaultValue:50},{name:`onCardMove`,type:`code`,label:`On Card Move`,advanced:!0},{name:`onColumnToggle`,type:`code`,label:`On Column Toggle`,advanced:!0},{name:`className`,type:`string`,label:`CSS Class`}],defaultProps:{columns:[],enableVirtualScrolling:!1,virtualScrollThreshold:50,className:`w-full`}});var $=({schema:e,...t})=>{let{dataSource:n}=s()||{};return(0,U.jsx)(Z,{schema:e,dataSource:n,...t})};a.register(`object-kanban`,$,{namespace:`plugin-kanban`,label:`Object Kanban`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`}]}),a.register(`kanban`,$,{namespace:`view`,label:`Kanban Board`,category:`view`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`,required:!0},{name:`columns`,type:`array`,label:`Columns`}]});export{q as n,re as r,Ee as t};
|