@object-ui/console 3.0.3 → 3.1.1

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.
Files changed (168) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/AdvancedChartImpl-D711bBuO.js +7 -0
  3. package/dist/assets/AppManagementPage-D_71FpIH.js +1 -0
  4. package/dist/assets/AuditLogPage-D3g_VEdE.js +1 -0
  5. package/dist/assets/AuthPageLayout-9l5xWV_-.js +1 -0
  6. package/dist/assets/{ChartImpl-2ivTljUi.js → ChartImpl-B9B4Fnbe.js} +1 -1
  7. package/dist/assets/CreateAppPage-mqt5j4rK.js +1 -0
  8. package/dist/assets/DashboardDesignPage-Cijb3jeF.js +1 -0
  9. package/dist/assets/DashboardView-DjhlMHLV.js +1 -0
  10. package/dist/assets/EditAppPage-BiK_DWcO.js +1 -0
  11. package/dist/assets/ForgotPasswordPage-Bzady8r_.js +1 -0
  12. package/dist/assets/KanbanEnhanced-OvdpYe81.js +1 -0
  13. package/dist/assets/KanbanImpl-EcxwmGw7.js +1 -0
  14. package/dist/assets/LoginPage-valW4Wu1.js +1 -0
  15. package/dist/assets/{MarkdownImpl-BshtTFK2.js → MarkdownImpl-C0wRapHT.js} +2 -2
  16. package/dist/assets/OrgManagementPage-D0d52PdP.js +1 -0
  17. package/dist/assets/PageDesignPage-hpFLdWCR.js +1 -0
  18. package/dist/assets/PageView-DxIAf-SB.js +2 -0
  19. package/dist/assets/PermissionManagementPage-ELCC8HyK.js +1 -0
  20. package/dist/assets/ProfilePage-Dj1N0mY3.js +1 -0
  21. package/dist/assets/RecordDetailView-DS9tEr5f.js +1 -0
  22. package/dist/assets/RegisterPage-DqUU8oW-.js +1 -0
  23. package/dist/assets/ReportView-CNi0A66t.js +1 -0
  24. package/dist/assets/RoleManagementPage-DRvuG53j.js +1 -0
  25. package/dist/assets/SearchResultsPage-nMlMQCb8.js +1 -0
  26. package/dist/assets/SystemHubPage-CAY-YvG2.js +1 -0
  27. package/dist/assets/UserManagementPage-fzvfJxav.js +1 -0
  28. package/dist/assets/data-adapter-rvE3xy2B.js +1 -0
  29. package/dist/assets/framework-BM176iet.js +10 -0
  30. package/dist/assets/index-B6cpm7bF.css +1 -0
  31. package/dist/assets/index-CTBPkbPG.js +9 -0
  32. package/dist/assets/index-Dv78M4Xq.js +1 -0
  33. package/dist/assets/infrastructure-n1j_TN6w.js +1 -0
  34. package/dist/assets/maplibre-gl-DVmJFhI2.js +811 -0
  35. package/dist/assets/plugins-core-qwgXbAqa.js +8 -0
  36. package/dist/assets/plugins-views-CveFN6PV.js +62 -0
  37. package/dist/assets/ui-components-BxvihT61.js +36 -0
  38. package/dist/assets/ui-components-CRV2BvKI.css +1 -0
  39. package/dist/assets/ui-layout-C6KWQtRO.js +1 -0
  40. package/dist/assets/{vendor-charts-CSvoW-yB.js → vendor-charts-BLNOCZWl.js} +2 -2
  41. package/dist/assets/vendor-dndkit-CX1oDZqy.js +5 -0
  42. package/dist/assets/vendor-i18n-E3-WitRV.js +9 -0
  43. package/dist/assets/{vendor-icons-CQ8b-fGy.js → vendor-icons-ndICq8DC.js} +3425 -3535
  44. package/dist/assets/vendor-objectstack-YKtcdalX.js +34 -0
  45. package/dist/assets/{vendor-radix-BbeYj_o4.js → vendor-radix-C6qchjxv.js} +1 -1
  46. package/dist/assets/vendor-react-9M-xu2bR.js +60 -0
  47. package/dist/assets/vendor-ui-utils-3tkeUVaX.js +1 -0
  48. package/dist/assets/vendor-zod-DxQVy2_o.js +39 -0
  49. package/dist/index.html +23 -22
  50. package/package.json +49 -46
  51. package/plugin.d.ts +1 -2
  52. package/plugin.js +1 -2
  53. package/plugin.ts +1 -2
  54. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js +0 -7
  55. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.br +0 -0
  56. package/dist/assets/AdvancedChartImpl-DAS1mU9o.js.gz +0 -0
  57. package/dist/assets/AuditLogPage-CyY7VZJW.js +0 -1
  58. package/dist/assets/AuditLogPage-CyY7VZJW.js.br +0 -0
  59. package/dist/assets/AuditLogPage-CyY7VZJW.js.gz +0 -0
  60. package/dist/assets/ChartImpl-2ivTljUi.js.br +0 -0
  61. package/dist/assets/ChartImpl-2ivTljUi.js.gz +0 -0
  62. package/dist/assets/DashboardView-DSh9LYBb.js +0 -1
  63. package/dist/assets/DashboardView-DSh9LYBb.js.br +0 -0
  64. package/dist/assets/DashboardView-DSh9LYBb.js.gz +0 -0
  65. package/dist/assets/ForgotPasswordPage-DUfjj-wh.js +0 -1
  66. package/dist/assets/KanbanEnhanced-ZOndyXyg.js +0 -1
  67. package/dist/assets/KanbanEnhanced-ZOndyXyg.js.br +0 -0
  68. package/dist/assets/KanbanEnhanced-ZOndyXyg.js.gz +0 -0
  69. package/dist/assets/KanbanImpl-BsMtStI7.js +0 -1
  70. package/dist/assets/KanbanImpl-BsMtStI7.js.br +0 -0
  71. package/dist/assets/KanbanImpl-BsMtStI7.js.gz +0 -0
  72. package/dist/assets/LoginPage-2CoFvwsL.js +0 -1
  73. package/dist/assets/MarkdownImpl-BshtTFK2.js.br +0 -0
  74. package/dist/assets/MarkdownImpl-BshtTFK2.js.gz +0 -0
  75. package/dist/assets/OrgManagementPage-BJt5Iiun.js +0 -1
  76. package/dist/assets/OrgManagementPage-BJt5Iiun.js.br +0 -0
  77. package/dist/assets/OrgManagementPage-BJt5Iiun.js.gz +0 -0
  78. package/dist/assets/PageView-bHvRhycc.js +0 -1
  79. package/dist/assets/PageView-bHvRhycc.js.br +0 -0
  80. package/dist/assets/PageView-bHvRhycc.js.gz +0 -0
  81. package/dist/assets/ProfilePage-MVUfKMrp.js +0 -1
  82. package/dist/assets/ProfilePage-MVUfKMrp.js.br +0 -0
  83. package/dist/assets/ProfilePage-MVUfKMrp.js.gz +0 -0
  84. package/dist/assets/RecordDetailView-Sm8_iQw_.js +0 -1
  85. package/dist/assets/RecordDetailView-Sm8_iQw_.js.br +0 -0
  86. package/dist/assets/RecordDetailView-Sm8_iQw_.js.gz +0 -0
  87. package/dist/assets/RegisterPage-B9itUVYp.js +0 -1
  88. package/dist/assets/ReportView-B0D9jx4v.js +0 -1
  89. package/dist/assets/ReportView-B0D9jx4v.js.br +0 -0
  90. package/dist/assets/ReportView-B0D9jx4v.js.gz +0 -0
  91. package/dist/assets/RoleManagementPage-BRqaeF_L.js +0 -1
  92. package/dist/assets/RoleManagementPage-BRqaeF_L.js.br +0 -0
  93. package/dist/assets/RoleManagementPage-BRqaeF_L.js.gz +0 -0
  94. package/dist/assets/SearchResultsPage-wlC0eLLr.js +0 -1
  95. package/dist/assets/SearchResultsPage-wlC0eLLr.js.br +0 -0
  96. package/dist/assets/SearchResultsPage-wlC0eLLr.js.gz +0 -0
  97. package/dist/assets/UserManagementPage-DOH6ql6-.js +0 -1
  98. package/dist/assets/UserManagementPage-DOH6ql6-.js.br +0 -0
  99. package/dist/assets/UserManagementPage-DOH6ql6-.js.gz +0 -0
  100. package/dist/assets/ViewDesignerPage-TCaXYb43.js +0 -1
  101. package/dist/assets/ViewDesignerPage-TCaXYb43.js.br +0 -0
  102. package/dist/assets/ViewDesignerPage-TCaXYb43.js.gz +0 -0
  103. package/dist/assets/data-adapter-D15yh-pb.js +0 -1
  104. package/dist/assets/data-adapter-D15yh-pb.js.br +0 -0
  105. package/dist/assets/data-adapter-D15yh-pb.js.gz +0 -0
  106. package/dist/assets/framework-mHWN965c.js +0 -10
  107. package/dist/assets/framework-mHWN965c.js.br +0 -0
  108. package/dist/assets/framework-mHWN965c.js.gz +0 -0
  109. package/dist/assets/index-CUnVdETN.css +0 -1
  110. package/dist/assets/index-CUnVdETN.css.br +0 -0
  111. package/dist/assets/index-CUnVdETN.css.gz +0 -0
  112. package/dist/assets/index-RAPqkKVL.js +0 -9
  113. package/dist/assets/index-RAPqkKVL.js.br +0 -0
  114. package/dist/assets/index-RAPqkKVL.js.gz +0 -0
  115. package/dist/assets/infrastructure-Di0WqY4l.js +0 -1
  116. package/dist/assets/infrastructure-Di0WqY4l.js.br +0 -0
  117. package/dist/assets/infrastructure-Di0WqY4l.js.gz +0 -0
  118. package/dist/assets/maplibre-gl-D2AsLM0J.js +0 -811
  119. package/dist/assets/maplibre-gl-D2AsLM0J.js.br +0 -0
  120. package/dist/assets/maplibre-gl-D2AsLM0J.js.gz +0 -0
  121. package/dist/assets/plugins-core-Cv2TPt86.js +0 -4
  122. package/dist/assets/plugins-core-Cv2TPt86.js.br +0 -0
  123. package/dist/assets/plugins-core-Cv2TPt86.js.gz +0 -0
  124. package/dist/assets/plugins-views-P3eB-els.css.br +0 -0
  125. package/dist/assets/plugins-views-P3eB-els.css.gz +0 -0
  126. package/dist/assets/plugins-views-divN-xXs.js +0 -60
  127. package/dist/assets/plugins-views-divN-xXs.js.br +0 -0
  128. package/dist/assets/plugins-views-divN-xXs.js.gz +0 -0
  129. package/dist/assets/systemObjects-DSpePIIy.js.br +0 -2
  130. package/dist/assets/systemObjects-DSpePIIy.js.gz +0 -0
  131. package/dist/assets/ui-components-CseD2Dpn.js +0 -31
  132. package/dist/assets/ui-components-CseD2Dpn.js.br +0 -0
  133. package/dist/assets/ui-components-CseD2Dpn.js.gz +0 -0
  134. package/dist/assets/ui-components-GrNdJOi1.css +0 -1
  135. package/dist/assets/ui-components-GrNdJOi1.css.br +0 -0
  136. package/dist/assets/ui-components-GrNdJOi1.css.gz +0 -0
  137. package/dist/assets/ui-layout-CF_1bNSv.js +0 -1
  138. package/dist/assets/ui-layout-CF_1bNSv.js.br +0 -0
  139. package/dist/assets/ui-layout-CF_1bNSv.js.gz +0 -0
  140. package/dist/assets/vendor-charts-CSvoW-yB.js.br +0 -0
  141. package/dist/assets/vendor-charts-CSvoW-yB.js.gz +0 -0
  142. package/dist/assets/vendor-dndkit-DRGpK6sP.js +0 -5
  143. package/dist/assets/vendor-dndkit-DRGpK6sP.js.br +0 -0
  144. package/dist/assets/vendor-dndkit-DRGpK6sP.js.gz +0 -0
  145. package/dist/assets/vendor-i18n-D5KbMT7w.js +0 -9
  146. package/dist/assets/vendor-i18n-D5KbMT7w.js.br +0 -0
  147. package/dist/assets/vendor-i18n-D5KbMT7w.js.gz +0 -0
  148. package/dist/assets/vendor-icons-CQ8b-fGy.js.br +0 -0
  149. package/dist/assets/vendor-icons-CQ8b-fGy.js.gz +0 -0
  150. package/dist/assets/vendor-objectstack-Bifvxvds.js +0 -1
  151. package/dist/assets/vendor-objectstack-Bifvxvds.js.br +0 -0
  152. package/dist/assets/vendor-objectstack-Bifvxvds.js.gz +0 -0
  153. package/dist/assets/vendor-radix-BbeYj_o4.js.br +0 -0
  154. package/dist/assets/vendor-radix-BbeYj_o4.js.gz +0 -0
  155. package/dist/assets/vendor-react-Dy_xkBQQ.js +0 -60
  156. package/dist/assets/vendor-react-Dy_xkBQQ.js.br +0 -0
  157. package/dist/assets/vendor-react-Dy_xkBQQ.js.gz +0 -0
  158. package/dist/assets/vendor-ui-utils-h6yAcIi9.js +0 -1
  159. package/dist/assets/vendor-ui-utils-h6yAcIi9.js.br +0 -0
  160. package/dist/assets/vendor-ui-utils-h6yAcIi9.js.gz +0 -0
  161. package/dist/assets/vendor-zod-UZPqlszj.js +0 -39
  162. package/dist/assets/vendor-zod-UZPqlszj.js.br +0 -0
  163. package/dist/assets/vendor-zod-UZPqlszj.js.gz +0 -0
  164. package/dist/index.html.br +0 -0
  165. package/dist/index.html.gz +0 -0
  166. package/dist/mockServiceWorker.js.br +0 -0
  167. package/dist/mockServiceWorker.js.gz +0 -0
  168. package/dist/stats.html +0 -4949
@@ -1,4 +0,0 @@
1
- import{r,j as t,R as me,d as Ot}from"./vendor-react-Dy_xkBQQ.js";import{c as _,b as de,m as ce,T as Ue,a as He,d as Ge,e as Et,B as ee,R as kt,f as Qe,g as Dt,S as Vt,h as Tt,i as zt,j as It,k as Mt,D as dt,l as ct,n as ut,o as ft,p as pt,q as At,r as Lt,s as Xe,t as Rt,u as _t,v as $t,w as Ye,N as $e,x as Ve,y as Te,z as ze,A as Ie,C as Se,E as mt,F as bt,G as gt,H as ht,I as yt,L as Pt,P as Wt,J as qt,K as Kt,M as Ce,O as Bt,Q as Ut}from"./ui-components-CseD2Dpn.js";import{S as te,C as re,c as Ht,f as Gt,d as Jt,g as Qt}from"./framework-mHWN965c.js";import{a as ye}from"./vendor-ui-utils-h6yAcIi9.js";import{u as Xt}from"./plugins-views-divN-xXs.js";import{a as Je,C as xt,d as Yt,b as Zt,Y as en,v as tn,l as nn,Z as sn,_ as ln,j as rn,$ as on,a0 as an,a1 as dn,a2 as cn,i as un,m as fn,a3 as Ze,X as pn,a4 as mn,a5 as bn}from"./vendor-icons-CQ8b-fGy.js";const xe=({label:e,description:s,collapsible:n=!1,collapsed:i=!1,columns:l=1,children:o,className:d})=>{const[a,w]=r.useState(i),C={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"},m=()=>{n&&w(!a)};return t.jsxs("div",{className:_("form-section",d),children:[(e||s)&&t.jsxs("div",{className:_("flex items-start gap-2 mb-4",n&&"cursor-pointer select-none"),onClick:m,role:n?"button":void 0,"aria-expanded":n?!a:void 0,children:[n&&t.jsx("span",{className:"mt-0.5 text-muted-foreground",children:a?t.jsx(Je,{className:"h-4 w-4"}):t.jsx(xt,{className:"h-4 w-4"})}),t.jsxs("div",{className:"flex-1",children:[e&&t.jsx("h3",{className:"text-base font-semibold text-foreground",children:e}),s&&t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:s})]})]}),!a&&t.jsx("div",{className:_("grid gap-4",C[l]),children:o})]})},gn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null),[c,g]=r.useState(e.defaultTab||e.sections[0]?.name||e.sections[0]?.label||"tab-0");me.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const u=await s.getObjectSchema(e.objectName);l(u)}catch(u){m(u)}})()},[e.objectName,s]),me.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId||!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const u=await s.findOne(e.objectName,e.recordId);d(u||{})}catch(u){m(u)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const N=r.useCallback(f=>{const u=[];for(const j of f.fields){const v=typeof j=="string"?j:j.name;if(typeof j=="object")u.push(j);else if(i?.fields?.[v]){const S=i.fields[v];u.push({name:v,label:S.label||v,type:ce(S.type),required:S.required||!1,disabled:e.readOnly||e.mode==="view"||S.readonly,placeholder:S.placeholder,description:S.help||S.description,validation:de(S),field:S,options:S.options,multiple:S.multiple})}else u.push({name:v,label:v,type:"input"})}return u},[i,e.readOnly,e.mode]),V=r.useCallback(async f=>{if(!s)return e.onSuccess&&await e.onSuccess(f),f;try{let u;return e.mode==="create"?u=await s.create(e.objectName,f):e.mode==="edit"&&e.recordId&&(u=await s.update(e.objectName,e.recordId,f)),e.onSuccess&&await e.onSuccess(u),u}catch(u){throw e.onError&&e.onError(u),u}},[e,s]),b=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),I=(f,u)=>f.name||f.label||`tab-${u}`;if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const y={type:"form",fields:e.sections.flatMap(f=>N(f)),layout:"vertical",defaultValues:o,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:b},x=e.tabPosition==="left"||e.tabPosition==="right";return t.jsx("div",{className:_("w-full",n,e.className),children:t.jsxs(Ue,{value:c,onValueChange:g,orientation:x?"vertical":"horizontal",className:_(x&&"flex gap-4"),children:[t.jsx(He,{className:_(x?"flex-col h-auto":"",e.tabPosition==="bottom"&&"order-last",e.tabPosition==="right"&&"order-last"),children:e.sections.map((f,u)=>t.jsx(Ge,{value:I(f,u),className:x?"w-full justify-start":"",children:f.label||`Tab ${u+1}`},I(f,u)))}),t.jsx("div",{className:"flex-1",children:e.sections.map((f,u)=>t.jsx(Et,{value:I(f,u),className:"mt-0",children:t.jsx(xe,{description:f.description,columns:f.columns||1,children:t.jsx(te,{schema:{...y,fields:N(f),showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1}})})},I(f,u)))})]})})},hn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null),[c,g]=r.useState(0),[N,V]=r.useState(new Set),[b,I]=r.useState(!1),z=e.sections.length,y=c===0,x=c===z-1;me.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const D=await s.getObjectSchema(e.objectName);l(D)}catch(D){m(D)}})()},[e.objectName,s]),me.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId||!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const D=await s.findOne(e.objectName,e.recordId);d(D||{})}catch(D){m(D)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const f=r.useCallback(O=>{const D=[];for(const R of O.fields){const K=typeof R=="string"?R:R.name;if(typeof R=="object")D.push(R);else if(i?.fields?.[K]){const M=i.fields[K];D.push({name:K,label:M.label||K,type:ce(M.type),required:M.required||!1,disabled:e.readOnly||e.mode==="view"||M.readonly,placeholder:M.placeholder,description:M.help||M.description,validation:de(M),field:M,options:M.options,multiple:M.multiple})}else D.push({name:K,label:K,type:"input"})}return D},[i,e.readOnly,e.mode]),u=r.useMemo(()=>c>=0&&c<z?f(e.sections[c]):[],[c,z,e.sections,f]),j=r.useCallback(async O=>{const D={...o,...O};if(d(D),V(R=>new Set(R).add(c)),x){I(!0);try{if(!s)return e.onSuccess&&await e.onSuccess(D),D;let R;return e.mode==="create"?R=await s.create(e.objectName,D):e.mode==="edit"&&e.recordId&&(R=await s.update(e.objectName,e.recordId,D)),e.onSuccess&&await e.onSuccess(R),R}catch(R){throw e.onError&&e.onError(R),R}finally{I(!1)}}else v(c+1)},[o,c,x,e,s]),v=r.useCallback(O=>{O>=0&&O<z&&(g(O),e.onStepChange&&e.onStepChange(O))},[z,e]),S=r.useCallback(()=>{v(c-1)},[c,v]),p=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),A=r.useCallback(O=>{(e.allowSkip||N.has(O)||O<=c)&&v(O)},[e.allowSkip,N,c,v]);if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const X=e.sections[c];return t.jsxs("div",{className:_("w-full",n,e.className),children:[e.showStepIndicator!==!1&&t.jsx("nav",{"aria-label":"Progress",className:"mb-8",children:t.jsx("ol",{className:"flex items-center",children:e.sections.map((O,D)=>{const R=D===c,K=N.has(D),M=e.allowSkip||K||D<=c;return t.jsxs("li",{className:_("relative flex-1",D!==z-1&&"pr-8 sm:pr-12"),children:[D!==z-1&&t.jsx("div",{className:"absolute top-3 sm:top-4 left-6 -right-4 sm:left-10 sm:-right-2 h-0.5","aria-hidden":"true",children:t.jsx("div",{className:_("h-full",K?"bg-primary":"bg-muted")})}),t.jsxs("button",{type:"button",className:_("group relative flex items-center",M?"cursor-pointer":"cursor-not-allowed"),onClick:()=>A(D),disabled:!M,children:[t.jsx("span",{className:_("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",K&&"bg-primary text-primary-foreground",R&&!K&&"border-2 border-primary bg-background text-primary",!R&&!K&&"border-2 border-muted bg-background text-muted-foreground"),children:K?t.jsx(Yt,{className:"h-3 w-3 sm:h-4 sm:w-4"}):D+1}),t.jsx("span",{className:"ml-2 sm:ml-3 text-xs sm:text-sm font-medium hidden sm:block",children:t.jsx("span",{className:_(R?"text-foreground":"text-muted-foreground"),children:O.label||`Step ${D+1}`})})]})]},D)})})}),t.jsx("div",{className:"min-h-[200px]",children:X&&t.jsx(xe,{label:X.label,description:X.description,columns:X.columns||1,children:u.length>0?t.jsx(te,{schema:{type:"form",fields:u,layout:"vertical",defaultValues:o,showSubmit:!1,showCancel:!1,onSubmit:j}}):t.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No fields configured for this step"})})}),t.jsxs("div",{className:"flex items-center justify-between mt-6 pt-4 border-t",children:[t.jsx("div",{children:e.showCancel!==!1&&t.jsx(ee,{variant:"ghost",onClick:p,children:e.cancelText||"Cancel"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"text-sm text-muted-foreground mr-2",children:["Step ",c+1," of ",z]}),!y&&t.jsxs(ee,{variant:"outline",onClick:S,children:[t.jsx(Zt,{className:"h-4 w-4 mr-1"}),e.prevText||"Back"]}),x?t.jsx(ee,{onClick:()=>j(o),disabled:b||e.mode==="view",children:b?"Submitting...":e.submitText||(e.mode==="create"?"Create":"Update")}):t.jsxs(ee,{onClick:()=>j(o),children:[e.nextText||"Next",t.jsx(Je,{className:"h-4 w-4 ml-1"})]})]})]})]})},yn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState({}),[a,w]=r.useState(!0),[C,m]=r.useState(null);r.useEffect(()=>{(async()=>{if(!s){w(!1);return}try{const u=await s.getObjectSchema(e.objectName);l(u)}catch(u){m(u),w(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){d(e.initialData||e.initialValues||{}),w(!1);return}if(!s){d(e.initialData||e.initialValues||{}),w(!1);return}try{const u=await s.findOne(e.objectName,e.recordId);d(u||{})}catch(u){m(u)}finally{w(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const c=r.useCallback(f=>{const u=[];for(const j of f.fields){const v=typeof j=="string"?j:j.name;if(typeof j=="object")u.push(j);else if(i?.fields?.[v]){const S=i.fields[v];u.push({name:v,label:S.label||v,type:ce(S.type),required:S.required||!1,disabled:e.readOnly||e.mode==="view"||S.readonly,placeholder:S.placeholder,description:S.help||S.description,validation:de(S),field:S,options:S.options,multiple:S.multiple})}else u.push({name:v,label:v,type:"input"})}return u},[i,e.readOnly,e.mode]),g=r.useCallback(async f=>{if(!s)return e.onSuccess&&await e.onSuccess(f),f;try{let u;return e.mode==="create"?u=await s.create(e.objectName,f):e.mode==="edit"&&e.recordId&&(u=await s.update(e.objectName,e.recordId,f)),e.onSuccess&&await e.onSuccess(u),u}catch(u){throw e.onError&&e.onError(u),u}},[e,s]),N=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),V=r.useMemo(()=>e.sections.slice(0,1),[e.sections]),b=r.useMemo(()=>e.sections.slice(1),[e.sections]);r.useMemo(()=>e.sections.flatMap(f=>c(f)),[e.sections,c]);const I=e.splitDirection||"horizontal",z=e.splitSize||50;if(C)return t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:C.message})]});if(a)return t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const y={type:"form",layout:"vertical",defaultValues:o,onSubmit:g,onCancel:N},x=(f,u)=>t.jsx("div",{className:"space-y-4 p-4",children:f.map((j,v)=>t.jsx(xe,{label:j.label,description:j.description,columns:j.columns||1,children:t.jsx(te,{schema:{...y,fields:c(j),showSubmit:u&&e.showSubmit!==!1&&e.mode!=="view",showCancel:u&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText}})},j.name||j.label||v))});return t.jsx("div",{className:_("w-full",n,e.className),children:t.jsxs(kt,{orientation:I,className:"min-h-[300px] rounded-lg border",children:[t.jsx(Qe,{defaultSize:z,minSize:20,children:x(V,b.length===0)}),b.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Dt,{withHandle:e.splitResizable!==!1}),t.jsx(Qe,{defaultSize:100-z,minSize:20,children:x(b,!0)})]})]})})},xn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState([]),[a,w]=r.useState({}),[C,m]=r.useState(!0),[c,g]=r.useState(null),N=e.open!==!1,V=e.drawerSide||"right";r.useEffect(()=>{(async()=>{if(!s){m(!1);return}try{const v=await s.getObjectSchema(e.objectName);l(v)}catch(v){g(v),m(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){w(e.initialData||e.initialValues||{}),m(!1);return}if(!s){w(e.initialData||e.initialValues||{}),m(!1);return}try{const v=await s.findOne(e.objectName,e.recordId);w(v||{})}catch(v){g(v)}finally{m(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const b=r.useCallback(j=>{const v=[];for(const S of j.fields){const p=typeof S=="string"?S:S.name;if(typeof S=="object")v.push(S);else if(i?.fields?.[p]){const A=i.fields[p];v.push({name:p,label:A.label||p,type:ce(A.type),required:A.required||!1,disabled:e.readOnly||e.mode==="view"||A.readonly,placeholder:A.placeholder,description:A.help||A.description,validation:de(A),field:A,options:A.options,multiple:A.multiple})}else v.push({name:p,label:p,type:"input"})}return v},[i,e.readOnly,e.mode]);r.useEffect(()=>{if(!i&&s)return;if(e.customFields?.length){d(e.customFields),m(!1);return}if(e.sections?.length){m(!1);return}if(!i)return;const j=e.fields||Object.keys(i.fields||{}),v=[];for(const S of j){const p=typeof S=="string"?S:S.name;if(!p)continue;const A=i.fields?.[p];A&&v.push({name:p,label:A.label||p,type:ce(A.type),required:A.required||!1,disabled:e.readOnly||e.mode==="view"||A.readonly,placeholder:A.placeholder,description:A.help||A.description,validation:de(A),field:A,options:A.options,multiple:A.multiple})}d(v),m(!1)},[i,e.fields,e.customFields,e.sections,e.readOnly,e.mode,s]);const I=r.useCallback(async j=>{if(!s)return e.onSuccess&&await e.onSuccess(j),e.onOpenChange?.(!1),j;try{let v;return e.mode==="create"?v=await s.create(e.objectName,j):e.mode==="edit"&&e.recordId&&(v=await s.update(e.objectName,e.recordId,j)),e.onSuccess&&await e.onSuccess(v),e.onOpenChange?.(!1),v}catch(v){throw e.onError&&e.onError(v),v}},[e,s]),z=r.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),y=r.useMemo(()=>e.drawerWidth?V==="left"||V==="right"?{width:e.drawerWidth,maxWidth:e.drawerWidth}:{height:e.drawerWidth,maxHeight:e.drawerWidth}:void 0,[e.drawerWidth,V]),f={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:a,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:I,onCancel:z},u=()=>c?t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:c.message})]}):C?t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]}):e.sections?.length?t.jsx("div",{className:"space-y-6",children:e.sections.map((j,v)=>t.jsx(xe,{label:j.label,description:j.description,columns:j.columns||1,children:t.jsx(te,{schema:{...f,fields:b(j),showSubmit:v===e.sections.length-1&&f.showSubmit,showCancel:v===e.sections.length-1&&f.showCancel}})},j.name||j.label||v))}):t.jsx(te,{schema:{...f,fields:o,columns:e.columns}});return t.jsx(Vt,{open:N,onOpenChange:e.onOpenChange,children:t.jsxs(Tt,{side:V,className:_("overflow-y-auto",n,e.className),style:y,children:[(e.title||e.description)&&t.jsxs(zt,{children:[e.title&&t.jsx(It,{children:e.title}),e.description&&t.jsx(Mt,{children:e.description})]}),t.jsx("div",{className:"py-4",children:u()})]})})},et={sm:"max-w-sm",default:"max-w-lg",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-[95vw] w-full"},wn=({schema:e,dataSource:s,className:n})=>{const[i,l]=r.useState(null),[o,d]=r.useState([]),[a,w]=r.useState({}),[C,m]=r.useState(!0),[c,g]=r.useState(null),N=e.open!==!1,V=et[e.modalSize||"default"]||et.default;r.useEffect(()=>{(async()=>{if(!s){m(!1);return}try{const j=await s.getObjectSchema(e.objectName);l(j)}catch(j){g(j),m(!1)}})()},[e.objectName,s]),r.useEffect(()=>{(i||!s)&&(async()=>{if(e.mode==="create"||!e.recordId){w(e.initialData||e.initialValues||{}),m(!1);return}if(!s){w(e.initialData||e.initialValues||{}),m(!1);return}try{const j=await s.findOne(e.objectName,e.recordId);w(j||{})}catch(j){g(j)}finally{m(!1)}})()},[i,e.mode,e.recordId,e.initialData,e.initialValues,s,e.objectName]);const b=r.useCallback(u=>{const j=[];for(const v of u.fields){const S=typeof v=="string"?v:v.name;if(typeof v=="object")j.push(v);else if(i?.fields?.[S]){const p=i.fields[S];j.push({name:S,label:p.label||S,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p,options:p.options,multiple:p.multiple})}else j.push({name:S,label:S,type:"input"})}return j},[i,e.readOnly,e.mode]);r.useEffect(()=>{if(!i&&s)return;if(e.customFields?.length){d(e.customFields),m(!1);return}if(e.sections?.length){m(!1);return}if(!i)return;const u=e.fields||Object.keys(i.fields||{}),j=[];for(const v of u){const S=typeof v=="string"?v:v.name;if(!S)continue;const p=i.fields?.[S];p&&j.push({name:S,label:p.label||S,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p,options:p.options,multiple:p.multiple})}d(j),m(!1)},[i,e.fields,e.customFields,e.sections,e.readOnly,e.mode,s]);const I=r.useCallback(async u=>{if(!s)return e.onSuccess&&await e.onSuccess(u),e.onOpenChange?.(!1),u;try{let j;return e.mode==="create"?j=await s.create(e.objectName,u):e.mode==="edit"&&e.recordId&&(j=await s.update(e.objectName,e.recordId,u)),e.onSuccess&&await e.onSuccess(j),e.onOpenChange?.(!1),j}catch(j){throw e.onError&&e.onError(j),j}},[e,s]),z=r.useCallback(()=>{e.onCancel&&e.onCancel(),e.onOpenChange?.(!1)},[e]),x={type:"form",layout:e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical",defaultValues:a,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,showSubmit:e.showSubmit!==!1&&e.mode!=="view",showCancel:e.showCancel!==!1,onSubmit:I,onCancel:z},f=()=>c?t.jsxs("div",{className:"p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:c.message})]}):C?t.jsxs("div",{className:"p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]}):e.sections?.length?t.jsx("div",{className:"space-y-6",children:e.sections.map((u,j)=>t.jsx(xe,{label:u.label,description:u.description,columns:u.columns||1,children:t.jsx(te,{schema:{...x,fields:b(u),showSubmit:j===e.sections.length-1&&x.showSubmit,showCancel:j===e.sections.length-1&&x.showCancel}})},u.name||u.label||j))}):t.jsx(te,{schema:{...x,fields:o,columns:e.columns}});return t.jsx(dt,{open:N,onOpenChange:e.onOpenChange,children:t.jsxs(ct,{className:_(V,"max-h-[90vh] overflow-y-auto",n,e.className),children:[(e.title||e.description)&&t.jsxs(ut,{children:[e.title&&t.jsx(ft,{children:e.title}),e.description&&t.jsx(pt,{children:e.description})]}),t.jsx("div",{className:"py-2",children:f()})]})})},Be=({schema:e,dataSource:s})=>{if(e.formType==="tabbed"&&e.sections?.length)return t.jsx(gn,{schema:{...e,formType:"tabbed",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),defaultTab:e.defaultTab,tabPosition:e.tabPosition},dataSource:s,className:e.className});if(e.formType==="wizard"&&e.sections?.length)return t.jsx(hn,{schema:{...e,formType:"wizard",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),allowSkip:e.allowSkip,showStepIndicator:e.showStepIndicator,nextText:e.nextText,prevText:e.prevText,onStepChange:e.onStepChange},dataSource:s,className:e.className});if(e.formType==="split"&&e.sections?.length)return t.jsx(yn,{schema:{...e,formType:"split",sections:e.sections.map(n=>({name:n.name,label:n.label,description:n.description,columns:n.columns,fields:n.fields})),splitDirection:e.splitDirection,splitSize:e.splitSize,splitResizable:e.splitResizable},dataSource:s,className:e.className});if(e.formType==="drawer"){const{layout:n,...i}=e,l=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(xn,{schema:{...i,layout:l,formType:"drawer",sections:e.sections?.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),open:e.open,onOpenChange:e.onOpenChange,drawerSide:e.drawerSide,drawerWidth:e.drawerWidth},dataSource:s,className:e.className})}if(e.formType==="modal"){const{layout:n,...i}=e,l=e.layout==="vertical"||e.layout==="horizontal"?e.layout:void 0;return t.jsx(wn,{schema:{...i,layout:l,formType:"modal",sections:e.sections?.map(o=>({name:o.name,label:o.label,description:o.description,columns:o.columns,fields:o.fields})),open:e.open,onOpenChange:e.onOpenChange,modalSize:e.modalSize,modalCloseButton:e.modalCloseButton},dataSource:s,className:e.className})}return t.jsx(jn,{schema:e,dataSource:s})},jn=({schema:e,dataSource:s})=>{const[n,i]=r.useState(null),[l,o]=r.useState([]),[d,a]=r.useState(null),[w,C]=r.useState(!0),[m,c]=r.useState(null),g=e.customFields&&e.customFields.length>0;r.useEffect(()=>{g&&(a(e.initialData||e.initialValues||{}),C(!1))},[g,e.initialData,e.initialValues]),r.useEffect(()=>{const x=async()=>{try{if(!s)throw new Error("DataSource is required when using ObjectQL schema fetching (inline fields not provided)");const f=await s.getObjectSchema(e.objectName);if(!f)throw new Error(`No schema found for object "${e.objectName}"`);i(f)}catch(f){c(f),C(!1)}};g?i({name:e.objectName,fields:{}}):e.objectName&&s?x():g||C(!1)},[e.objectName,s,g]),r.useEffect(()=>{n&&!g&&(async()=>{if(!e.recordId||e.mode==="create"){a(e.initialData||e.initialValues||{}),C(!1);return}if(!g){if(!s){c(new Error("DataSource is required for fetching record data (inline data not provided)")),C(!1);return}C(!0);try{const f=await s.findOne(e.objectName,e.recordId);a(f)}catch(f){console.error("Failed to fetch record:",f),c(f)}finally{C(!1)}}})()},[e.objectName,e.recordId,e.mode,e.initialValues,e.initialData,s,n,g]),r.useEffect(()=>{if(g&&e.customFields){o(e.customFields),C(!1);return}if(!n)return;const x=[],f=e.fields||Object.keys(n.fields||{});(Array.isArray(f)?f:Object.keys(f)).forEach(v=>{const S=typeof v=="string"?v:v.name;if(!S)return;const p=n.fields?.[S];if(!p&&!g)return;const A=!p?.permissions||p?.permissions.write!==!1;if(e.mode!=="view"&&!A)return;const X=e.customFields?.find(O=>O.name===S);if(X)x.push(X);else if(p){const O={name:S,label:p.label||v,type:ce(p.type),required:p.required||!1,disabled:e.readOnly||e.mode==="view"||p.readonly,placeholder:p.placeholder,description:p.help||p.description,validation:de(p),field:p};if((p.type==="select"||p.type==="lookup"||p.type==="master_detail")&&(O.options=p.options||[],O.multiple=p.multiple),(p.type==="number"||p.type==="currency"||p.type==="percent")&&(O.inputType="number",O.min=p.min,O.max=p.max,O.step=p.precision?Math.pow(10,-p.precision):void 0),p.type==="date"&&(O.inputType="date"),p.type==="datetime"&&(O.inputType="datetime-local"),(p.type==="text"||p.type==="textarea"||p.type==="markdown"||p.type==="html")&&(O.maxLength=p.max_length,O.minLength=p.min_length),(p.type==="file"||p.type==="image")&&(O.inputType="file",O.multiple=p.multiple,O.accept=p.accept?p.accept.join(","):void 0,p.max_size)){const D=`Max size: ${At(p.max_size)}`;O.description=O.description?`${O.description} (${D})`:D}p.type==="email"&&(O.inputType="email"),p.type==="phone"&&(O.inputType="tel"),p.type==="url"&&(O.inputType="url"),p.type==="password"&&(O.inputType="password"),p.type==="time"&&(O.inputType="time"),(p.type==="formula"||p.type==="summary"||p.type==="auto_number")&&(O.disabled=!0),p.visible_on&&(O.visible=D=>Lt(p.visible_on,D)),x.push(O)}}),o(x),!g&&e.recordId&&e.mode!=="create"&&s||C(!1)},[n,e.fields,e.customFields,e.readOnly,e.mode,g,e.recordId,s]);const N=r.useCallback(async(x,f)=>{if(x&&(x.nativeEvent||x._reactName==="onSubmit")&&(console.warn("ObjectForm: Received Event instead of data in handleSubmit! This suggests a Form renderer issue."),f===void 0&&(f=x,x={})),g&&!s)return e.onSuccess&&await e.onSuccess(x),x;if(!s)throw new Error("DataSource is required for form submission (inline mode not configured)");try{let u;if(e.mode==="create")u=await s.create(e.objectName,x);else if(e.mode==="edit"&&e.recordId)u=await s.update(e.objectName,e.recordId,x);else throw new Error("Invalid form mode or missing record ID");return e.onSuccess&&await e.onSuccess(u),u}catch(u){throw console.error("Failed to submit form:",u),e.onError&&e.onError(u),u}},[e,s,g]),V=r.useCallback(()=>{e.onCancel&&e.onCancel()},[e]),I={...me.useMemo(()=>{if(!n?.fields)return{};const x={};return Object.keys(n.fields).forEach(f=>{const u=n.fields[f];u.defaultValue!==void 0&&(x[f]=u.defaultValue)}),x},[n]),...d};if(m)return t.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading form"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:m.message})]});if(w)return t.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading form..."})]});const z=e.layout==="vertical"||e.layout==="horizontal"?e.layout:"vertical";if(e.sections?.length&&(!e.formType||e.formType==="simple"))return t.jsx("div",{className:"w-full space-y-6",children:e.sections.map((x,f)=>{const u=x.fields.map(v=>typeof v=="string"?v:v.name),j=l.filter(v=>u.includes(v.name));return t.jsx(xe,{label:x.label,description:x.description,collapsible:x.collapsible,collapsed:x.collapsed,columns:x.columns,children:t.jsx(te,{schema:{type:"form",fields:j,layout:z,defaultValues:I,showSubmit:f===e.sections.length-1&&e.showSubmit!==!1&&e.mode!=="view",showCancel:f===e.sections.length-1&&e.showCancel!==!1,submitLabel:e.submitText||(e.mode==="create"?"Create":"Update"),cancelLabel:e.cancelText,onSubmit:N,onCancel:V}})},x.name||x.label||f)})});const y={type:"form",fields:l,layout:z,columns:e.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:I,onSubmit:N,onCancel:V,className:e.className};return t.jsx("div",{className:"w-full",children:t.jsx(te,{schema:y})})},wt=({schema:e})=>t.jsx(Be,{schema:e});re.register("object-form",wt,{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"]}]});re.register("form",wt,{namespace:"view",skipFallback:!0,label:"Data Form View",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"fields",type:"array",label:"Fields"},{name:"mode",type:"enum",label:"Mode",enum:["create","edit","view"]}]});const vn={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 Cn(e){if(e.startsWith("bg-"))return e;const s=e.toLowerCase().trim();return vn[s]}function Sn(e){return r.useCallback(s=>{if(!e?.field||!e.colors)return;const n=String(s[e.field]??""),i=e.colors[n];if(i)return Cn(i)},[e?.field,e?.colors])}function Nn(e,s){return s.map(n=>String(e[n.field]??"")).join(" / ")}function Fn(e,s){return s.map(n=>{const i=e[n.field];return i!=null&&i!==""?String(i):"(empty)"}).join(" / ")}function On(e,s,n){const i=e.localeCompare(s,void 0,{numeric:!0,sensitivity:"base"});return n==="desc"?-i:i}function En(e,s){const n=e?.fields,i=!!(n&&n.length>0),[l,o]=r.useState({}),d=r.useMemo(()=>n?n.some(C=>C.collapsed):!1,[n]),a=r.useMemo(()=>{if(!i||!n)return[];const C=new Map,m=[];for(const g of s){const N=Nn(g,n);C.has(N)||(C.set(N,{label:Fn(g,n),rows:[]}),m.push(N)),C.get(N).rows.push(g)}const c=n[0]?.order??"asc";return m.sort((g,N)=>On(g,N,c)),m.map(g=>{const N=C.get(g),V=g in l?l[g]:d;return{key:g,label:N.label,rows:N.rows,collapsed:V}})},[s,n,i,l,d]),w=r.useCallback(C=>{o(m=>({...m,[C]:m[C]!==void 0?!m[C]:!d}))},[d]);return{groups:a,isGrouped:i,toggleGroup:w}}function kn(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 tt(e){if(!(!e||e.length===0))return typeof e[0]=="object"&&e[0]!==null,e}const jt=({schema:e,dataSource:s,onEdit:n,onDelete:i,onRowSelect:l,onRowClick:o,onCellChange:d,onRowSave:a,onBatchSave:w,...C})=>{const[m,c]=r.useState([]),[g,N]=r.useState(!0),[V,b]=r.useState(null),[I,z]=r.useState(null),[y,x]=r.useState(!1),[f,u]=r.useState(0),j=r.useCallback(async()=>{u(T=>T+1)},[]),{ref:v,isRefreshing:S,pullDistance:p}=Xt({onRefresh:j,enabled:!!s&&!!e.objectName});r.useEffect(()=>{const T=()=>x(window.innerWidth<480);return T(),window.addEventListener("resize",T),()=>window.removeEventListener("resize",T)},[]);const A=C.data,X=Ht(e.bind),O=kn(e),D=me.useMemo(()=>A&&Array.isArray(A)?{provider:"value",items:A}:X&&Array.isArray(X)?{provider:"value",items:X}:O,[JSON.stringify(O),X,A]),R=D?.provider==="value",K=D?.provider==="object"&&D&&"object"in D?D.object:e.objectName,M=e.fields,U=e.columns,ue=e.filter,oe=e.sort,W=e.pagination,ie=e.pageSize;r.useEffect(()=>{R&&D?.provider==="value"&&(c(T=>{const $=D.items;return JSON.stringify(T)!==JSON.stringify($)?$:T}),N(!1))},[R,D]),r.useEffect(()=>{if(R)return;let T=!1;return(async()=>{N(!0),b(null);try{let G=null;if((tt(U)||M)&&K)G={name:K,fields:{}};else if(K&&s){const k=await s.getObjectSchema(K);if(T)return;G=k}else throw K?new Error("DataSource required"):new Error("Object name required for data fetching");if(T||z(G),s&&K){const J={$select:(()=>{if(M)return M;if(U&&Array.isArray(U))return U.map(H=>typeof H=="string"?H:H.field)})(),$top:W?.pageSize||ie||50};ue&&Array.isArray(ue)?J.$filter=ue:e.defaultFilters&&(J.$filter=e.defaultFilters),oe?typeof oe=="string"?J.$orderby=oe:Array.isArray(oe)&&(J.$orderby=oe.map(H=>`${H.field} ${H.order}`).join(", ")):e.defaultSort&&(J.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);const fe=await s.find(K,J);if(T)return;c(fe.data||[])}}catch(G){T||b(G)}finally{T||N(!1)}})(),()=>{T=!0}},[K,M,U,ue,oe,W,ie,s,R,D,f]);const q=Gt({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:o}),{execute:se}=Jt(),le=Sn(e.rowColor),{groups:Me,isGrouped:we,toggleGroup:Ne}=En(e.grouping,m),je=r.useCallback(()=>{const T=tt(U);if(T){if(T.length>0&&typeof T[0]=="object"&&T[0]!==null){const P=T[0];if("accessorKey"in P)return T;if("field"in P)return T.filter(k=>k?.field&&typeof k.field=="string"&&!k.hidden).map((k,J)=>{const fe=k.label||k.field.charAt(0).toUpperCase()+k.field.slice(1).replace(/_/g," ");let H;const h=k.type?Xe(k.type):null;k.link&&k.action?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:k.field,type:k.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.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",onClick:Q=>{Q.stopPropagation(),q.handleClick(Z)},children:B})}:k.link?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:k.field,type:k.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.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",onClick:Q=>{Q.stopPropagation(),q.handleClick(Z)},children:B})}:k.action?H=(L,Z)=>{const B=h?t.jsx(h,{value:L,field:{name:k.field,type:k.type||"text"}}):L!=null&&L!==""?String(L):t.jsx("span",{className:"text-muted-foreground",children:"-"});return t.jsx("button",{type:"button",className:"text-primary underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit",onClick:Q=>{Q.stopPropagation(),se({type:k.action,params:{record:Z,field:k.field,value:L}})},children:B})}:h?H=L=>t.jsx(h,{value:L,field:{name:k.field,type:k.type||"text"}}):H=L=>L!=null&&L!==""?t.jsx("span",{children:String(L)}):t.jsx("span",{className:"text-muted-foreground",children:"-"});const F=["number","currency","percent"],E=k.align||(k.type&&F.includes(k.type)?"right":void 0),Y=J===0||k.essential===!0;return{header:fe,accessorKey:k.field,...!Y&&{className:"hidden sm:table-cell"},...k.width&&{width:k.width},...E&&{align:E},sortable:k.sortable!==!1,...k.resizable!==void 0&&{resizable:k.resizable},...k.wrap!==void 0&&{wrap:k.wrap},...H&&{cell:H}}})}return T.filter(P=>typeof P=="string"&&P.trim().length>0).map(P=>({header:I?.fields?.[P]?.label||P.charAt(0).toUpperCase()+P.slice(1).replace(/_/g," "),accessorKey:P}))}if(R){const P=D?.provider==="value"?D.items:[];if(P.length>0)return(M||Object.keys(P[0])).map(J=>({header:J.charAt(0).toUpperCase()+J.slice(1).replace(/_/g," "),accessorKey:J}))}if(!I)return[];const $=[];return(M||Object.keys(I.fields||{})).forEach(P=>{const k=I.fields?.[P];if(!k||k.permissions&&k.permissions.read===!1)return;const J=Xe(k.type),fe=["number","currency","percent"];$.push({header:k.label||P,accessorKey:P,...fe.includes(k.type)&&{align:"right"},cell:H=>t.jsx(J,{value:H,field:k}),sortable:k.sortable!==!1})}),$},[I,M,U,D,R,q.handleClick,se]);if(V)return t.jsxs("div",{className:"p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md",children:[t.jsx("h3",{className:"text-red-800 font-semibold",children:"Error loading grid"}),t.jsx("p",{className:"text-red-600 text-sm mt-1",children:V.message})]});if(g&&m.length===0)return t.jsxs("div",{className:"p-4 sm:p-8 text-center",children:[t.jsx("div",{className:"inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),t.jsx("p",{className:"mt-2 text-sm text-gray-600",children:"Loading grid..."})]});const Fe=je(),ae="operations"in e?e.operations:void 0,Oe=ae&&(ae.update||ae.delete),Ae=Oe?[...Fe,{header:"Actions",accessorKey:"_actions",cell:(T,$)=>t.jsxs(Rt,{children:[t.jsx(_t,{asChild:!0,children:t.jsxs(ee,{variant:"ghost",size:"icon",className:"h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0",children:[t.jsx(en,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"Open menu"})]})}),t.jsxs($t,{align:"end",children:[ae?.update&&n&&t.jsxs(Ye,{onClick:()=>n($),children:[t.jsx(tn,{className:"mr-2 h-4 w-4"}),"Edit"]}),ae?.delete&&i&&t.jsxs(Ye,{onClick:()=>i($),children:[t.jsx(nn,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]}),sortable:!1}]:Fe;let be=!1;e.selection?.type?be=e.selection.type==="none"?!1:e.selection.type:e.selectable!==void 0&&(be=e.selectable);const Le=e.pagination!==void 0?!0:e.showPagination!==void 0?e.showPagination:!0,Re=e.pagination?.pageSize||e.pageSize||10,_e=e.searchableFields!==void 0?e.searchableFields.length>0:e.showSearch!==void 0?e.showSearch:!0,Ee={type:"data-table",caption:e.label||e.title,columns:Ae,data:m,pagination:Le,pageSize:Re,searchable:_e,selectable:be,sortable:!0,exportable:ae?.export,rowActions:Oe,resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,className:e.className,cellClassName:"px-2 py-1.5 sm:px-3 sm:py-2 md:px-4 md:py-2.5",rowClassName:e.rowColor?(T,$)=>le(T):void 0,onSelectionChange:l,onRowClick:q.handleClick,onCellChange:d,onRowSave:a,onBatchSave:w},ke=T=>({...Ee,caption:void 0,data:T,pagination:!1,searchable:!1}),ge=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:"Record Detail";if(y&&m.length>0&&!we){const T=je().filter($=>$.accessorKey!=="_actions");return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"space-y-2 p-2",children:m.map(($,G)=>t.jsx("div",{className:"border rounded-lg p-3 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation",onClick:()=>q.handleClick($),children:T.slice(0,4).map(P=>t.jsxs("div",{className:"flex justify-between items-center py-1",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:P.header}),t.jsx("span",{className:"text-sm font-medium truncate ml-2 text-right",children:P.cell?P.cell($[P.accessorKey],$):String($[P.accessorKey]??"—")})]},P.accessorKey))},$.id||$._id||G))}),q.isOverlay&&t.jsx($e,{...q,title:ge,children:$=>t.jsx("div",{className:"space-y-3",children:Object.entries($).map(([G,P])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:G.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(P??"—")})]},G))})})]})}const ve=we?t.jsx("div",{className:"space-y-2",children:Me.map(T=>t.jsxs("div",{className:"border rounded-md",children:[t.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:()=>Ne(T.key),children:[T.collapsed?t.jsx(Je,{className:"h-4 w-4 shrink-0"}):t.jsx(xt,{className:"h-4 w-4 shrink-0"}),t.jsx("span",{children:T.label}),t.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:T.rows.length})]}),!T.collapsed&&t.jsx(te,{schema:ke(T.rows)})]},T.key))}):t.jsx(te,{schema:Ee});return q.isOverlay&&q.mode==="split"?t.jsx($e,{...q,title:ge,mainContent:ve,children:T=>t.jsx("div",{className:"space-y-3",children:Object.entries(T).map(([$,G])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:$.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(G??"—")})]},$))})}):t.jsxs("div",{ref:v,className:"relative h-full",children:[p>0&&t.jsx("div",{className:"flex items-center justify-center text-xs text-muted-foreground",style:{height:p},children:S?"Refreshing…":"Pull to refresh"}),ve,q.isOverlay&&t.jsx($e,{...q,title:ge,children:T=>t.jsx("div",{className:"space-y-3",children:Object.entries(T).map(([$,G])=>t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:$.replace(/_/g," ")}),t.jsx("span",{className:"text-sm",children:String(G??"—")})]},$))})})]})};function he(e,s,n){let i=n.initialDeps??[],l,o=!0;function d(){var a,w,C;let m;n.key&&((a=n.debug)!=null&&a.call(n))&&(m=Date.now());const c=e();if(!(c.length!==i.length||c.some((V,b)=>i[b]!==V)))return l;i=c;let N;if(n.key&&((w=n.debug)!=null&&w.call(n))&&(N=Date.now()),l=s(...c),n.key&&((C=n.debug)!=null&&C.call(n))){const V=Math.round((Date.now()-m)*100)/100,b=Math.round((Date.now()-N)*100)/100,I=b/16,z=(y,x)=>{for(y=String(y);y.length<x;)y=" "+y;return y};console.info(`%c⏱ ${z(b,5)} /${z(V,5)} ms`,`
2
- font-size: .6rem;
3
- font-weight: bold;
4
- color: hsl(${Math.max(0,Math.min(120-120*I,120))}deg 100% 31%);`,n?.key)}return n?.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(l),o=!1,l}return d.updateDeps=a=>{i=a},d}function nt(e,s){if(e===void 0)throw new Error("Unexpected undefined");return e}const Dn=(e,s)=>Math.abs(e-s)<1.01,Vn=(e,s,n)=>{let i;return function(...l){e.clearTimeout(i),i=e.setTimeout(()=>s.apply(this,l),n)}},it=e=>{const{offsetWidth:s,offsetHeight:n}=e;return{width:s,height:n}},Tn=e=>e,zn=e=>{const s=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1),i=[];for(let l=s;l<=n;l++)i.push(l);return i},In=(e,s)=>{const n=e.scrollElement;if(!n)return;const i=e.targetWindow;if(!i)return;const l=d=>{const{width:a,height:w}=d;s({width:Math.round(a),height:Math.round(w)})};if(l(it(n)),!i.ResizeObserver)return()=>{};const o=new i.ResizeObserver(d=>{const a=()=>{const w=d[0];if(w?.borderBoxSize){const C=w.borderBoxSize[0];if(C){l({width:C.inlineSize,height:C.blockSize});return}}l(it(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},st={passive:!0},lt=typeof window>"u"?!0:"onscrollend"in window,Mn=(e,s)=>{const n=e.scrollElement;if(!n)return;const i=e.targetWindow;if(!i)return;let l=0;const o=e.options.useScrollendEvent&&lt?()=>{}:Vn(i,()=>{s(l,!1)},e.options.isScrollingResetDelay),d=m=>()=>{const{horizontal:c,isRtl:g}=e.options;l=c?n.scrollLeft*(g&&-1||1):n.scrollTop,o(),s(l,m)},a=d(!0),w=d(!1);n.addEventListener("scroll",a,st);const C=e.options.useScrollendEvent&&lt;return C&&n.addEventListener("scrollend",w,st),()=>{n.removeEventListener("scroll",a),C&&n.removeEventListener("scrollend",w)}},An=(e,s,n)=>{if(s?.borderBoxSize){const i=s.borderBoxSize[0];if(i)return Math.round(i[n.options.horizontal?"inlineSize":"blockSize"])}return e[n.options.horizontal?"offsetWidth":"offsetHeight"]},Ln=(e,{adjustments:s=0,behavior:n},i)=>{var l,o;const d=e+s;(o=(l=i.scrollElement)==null?void 0:l.scrollTo)==null||o.call(l,{[i.options.horizontal?"left":"top"]:d,behavior:n})};class Rn{constructor(s){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.currentScrollToIndex=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let n=null;const i=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(l=>{l.forEach(o=>{const d=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(d):d()})}));return{disconnect:()=>{var l;(l=i())==null||l.disconnect(),n=null},observe:l=>{var o;return(o=i())==null?void 0:o.observe(l,{box:"border-box"})},unobserve:l=>{var o;return(o=i())==null?void 0:o.unobserve(l)}}})(),this.range=null,this.setOptions=n=>{Object.entries(n).forEach(([i,l])=>{typeof l>"u"&&delete n[i]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Tn,rangeExtractor:zn,onChange:()=>{},measureElement:An,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...n}},this.notify=n=>{var i,l;(l=(i=this.options).onChange)==null||l.call(i,this,n)},this.maybeNotify=he(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i){this.maybeNotify();return}this.scrollElement=i,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(l=>{this.observer.observe(l)}),this.unsubs.push(this.options.observeElementRect(this,l=>{this.scrollRect=l,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(l,o)=>{this.scrollAdjustments=0,this.scrollDirection=o?this.getScrollOffset()<l?"forward":"backward":null,this.scrollOffset=l,this.isScrolling=o,this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(n,i)=>{const l=new Map,o=new Map;for(let d=i-1;d>=0;d--){const a=n[d];if(l.has(a.lane))continue;const w=o.get(a.lane);if(w==null||a.end>w.end?o.set(a.lane,a):a.end<w.end&&l.set(a.lane,!0),l.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((d,a)=>d.end===a.end?d.index-a.index:d.end-a.end)[0]:void 0},this.getMeasurementOptions=he(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes],(n,i,l,o,d,a)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMeasuredCacheIndexes=[],{count:n,paddingStart:i,scrollMargin:l,getItemKey:o,enabled:d,lanes:a}),{key:!1}),this.getMeasurements=he(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:n,paddingStart:i,scrollMargin:l,getItemKey:o,enabled:d,lanes:a},w)=>{if(!d)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(g=>{this.itemSizeCache.set(g.key,g.size)}));const C=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1);const m=this.measurementsCache.slice(0,C),c=new Array(a).fill(void 0);for(let g=0;g<C;g++){const N=m[g];N&&(c[N.lane]=g)}for(let g=C;g<n;g++){const N=o(g),V=this.laneAssignments.get(g);let b,I;if(V!==void 0&&this.options.lanes>1){b=V;const f=c[b],u=f!==void 0?m[f]:void 0;I=u?u.end+this.options.gap:i+l}else{const f=this.options.lanes===1?m[g-1]:this.getFurthestMeasurement(m,g);I=f?f.end+this.options.gap:i+l,b=f?f.lane:g%this.options.lanes,this.options.lanes>1&&this.laneAssignments.set(g,b)}const z=w.get(N),y=typeof z=="number"?z:this.options.estimateSize(g),x=I+y;m[g]={index:g,start:I,size:y,end:x,key:N,lane:b},c[b]=g}return this.measurementsCache=m,m},{key:!1,debug:()=>this.options.debug}),this.calculateRange=he(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,i,l,o)=>this.range=n.length>0&&i>0?_n({measurements:n,outerSize:i,scrollOffset:l,lanes:o}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=he(()=>{let n=null,i=null;const l=this.calculateRange();return l&&(n=l.startIndex,i=l.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,i]},(n,i,l,o,d)=>o===null||d===null?[]:n({startIndex:o,endIndex:d,overscan:i,count:l}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const i=this.options.indexAttribute,l=n.getAttribute(i);return l?parseInt(l,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this._measureElement=(n,i)=>{const l=this.indexFromElement(n),o=this.measurementsCache[l];if(!o)return;const d=o.key,a=this.elementsCache.get(d);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(d,n)),n.isConnected&&this.resizeItem(l,this.options.measureElement(n,i,this))},this.resizeItem=(n,i)=>{const l=this.measurementsCache[n];if(!l)return;const o=this.itemSizeCache.get(l.key)??l.size,d=i-o;d!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(l,d,this):l.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=d,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(l.index),this.itemSizeCache=new Map(this.itemSizeCache.set(l.key,i)),this.notify(!1))},this.measureElement=n=>{if(!n){this.elementsCache.forEach((i,l)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(l))});return}this._measureElement(n,void 0)},this.getVirtualItems=he(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,i)=>{const l=[];for(let o=0,d=n.length;o<d;o++){const a=n[o],w=i[a];l.push(w)}return l},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const i=this.getMeasurements();if(i.length!==0)return nt(i[vt(0,i.length-1,l=>nt(i[l]).start,n)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(n,i,l=0)=>{if(!this.scrollElement)return 0;const o=this.getSize(),d=this.getScrollOffset();i==="auto"&&(i=n>=d+o?"end":"start"),i==="center"?n+=(l-o)/2:i==="end"&&(n-=o);const a=this.getMaxScrollOffset();return Math.max(Math.min(a,n),0)},this.getOffsetForIndex=(n,i="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const l=this.measurementsCache[n];if(!l)return;const o=this.getSize(),d=this.getScrollOffset();if(i==="auto")if(l.end>=d+o-this.options.scrollPaddingEnd)i="end";else if(l.start<=d+this.options.scrollPaddingStart)i="start";else return[d,i];if(i==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),i];const a=i==="end"?l.end+this.options.scrollPaddingEnd:l.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,i,l.size),i]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(n,{align:i="start",behavior:l}={})=>{l==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(n,i),{adjustments:void 0,behavior:l})},this.scrollToIndex=(n,{align:i="auto",behavior:l}={})=>{l==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),n=Math.max(0,Math.min(n,this.options.count-1)),this.currentScrollToIndex=n;let o=0;const d=10,a=C=>{if(!this.targetWindow)return;const m=this.getOffsetForIndex(n,C);if(!m){console.warn("Failed to get offset for index:",n);return}const[c,g]=m;this._scrollToOffset(c,{adjustments:void 0,behavior:l}),this.targetWindow.requestAnimationFrame(()=>{const N=()=>{if(this.currentScrollToIndex!==n)return;const V=this.getScrollOffset(),b=this.getOffsetForIndex(n,g);if(!b){console.warn("Failed to get offset for index:",n);return}Dn(b[0],V)||w(g)};this.isDynamicMode()?this.targetWindow.requestAnimationFrame(N):N()})},w=C=>{this.targetWindow&&this.currentScrollToIndex===n&&(o++,o<d?this.targetWindow.requestAnimationFrame(()=>a(C)):console.warn(`Failed to scroll to index ${n} after ${d} attempts.`))};a(i)},this.scrollBy=(n,{behavior:i}={})=>{i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+n,{adjustments:void 0,behavior:i})},this.getTotalSize=()=>{var n;const i=this.getMeasurements();let l;if(i.length===0)l=this.options.paddingStart;else if(this.options.lanes===1)l=((n=i[i.length-1])==null?void 0:n.end)??0;else{const o=Array(this.options.lanes).fill(null);let d=i.length-1;for(;d>=0&&o.some(a=>a===null);){const a=i[d];o[a.lane]===null&&(o[a.lane]=a.end),d--}l=Math.max(...o.filter(a=>a!==null))}return Math.max(l-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(n,{adjustments:i,behavior:l})=>{this.options.scrollToFn(n,{behavior:l,adjustments:i},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(s)}}const vt=(e,s,n,i)=>{for(;e<=s;){const l=(e+s)/2|0,o=n(l);if(o<i)e=l+1;else if(o>i)s=l-1;else return l}return e>0?e-1:0};function _n({measurements:e,outerSize:s,scrollOffset:n,lanes:i}){const l=e.length-1,o=w=>e[w].start;if(e.length<=i)return{startIndex:0,endIndex:l};let d=vt(0,l,o,n),a=d;if(i===1)for(;a<l&&e[a].end<n+s;)a++;else if(i>1){const w=Array(i).fill(0);for(;a<l&&w.some(m=>m<n+s);){const m=e[a];w[m.lane]=m.end,a++}const C=Array(i).fill(n+s);for(;d>=0&&C.some(m=>m>=n);){const m=e[d];C[m.lane]=m.start,d--}d=Math.max(0,d-d%i),a=Math.min(l,a+(i-1-a%i))}return{startIndex:d,endIndex:a}}const rt=typeof document<"u"?r.useLayoutEffect:r.useEffect;function $n({useFlushSync:e=!0,...s}){const n=r.useReducer(()=>({}),{})[1],i={...s,onChange:(o,d)=>{var a;e&&d?Ot.flushSync(n):n(),(a=s.onChange)==null||a.call(s,o,d)}},[l]=r.useState(()=>new Rn(i));return l.setOptions(i),rt(()=>l._didMount(),[]),rt(()=>l._willUpdate()),l}function ui(e){return $n({observeElementRect:In,observeElementOffset:Mn,scrollToFn:Ln,...e})}const Ct=({schema:e,...s})=>{const{dataSource:n}=Qt()||{};return t.jsx(jt,{schema:e,dataSource:n,...s})};re.register("object-grid",Ct,{namespace:"plugin-grid",label:"Object Grid",category:"plugin",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]});re.register("grid",Ct,{namespace:"view",label:"Data Grid",category:"view",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"columns",type:"array",label:"Columns"},{name:"filters",type:"array",label:"Filters"}]});const Pn={list:"List",detail:"Detail",grid:"Grid",kanban:"Kanban",calendar:"Calendar",timeline:"Timeline",map:"Map"},Wn={list:cn,detail:dn,grid:an,kanban:on,calendar:rn,timeline:ln,map:sn},qn=ye("flex gap-4",{variants:{position:{top:"flex-col",bottom:"flex-col-reverse",left:"flex-row",right:"flex-row-reverse"}},defaultVariants:{position:"top"}}),Kn=ye("w-full",{variants:{orientation:{horizontal:"w-full",vertical:"w-48"}},defaultVariants:{orientation:"horizontal"}}),Bn=ye("flex gap-2",{variants:{orientation:{horizontal:"flex-row flex-wrap",vertical:"flex-col"}},defaultVariants:{orientation:"horizontal"}}),Un=ye("",{variants:{orientation:{horizontal:"",vertical:"flex h-auto flex-col items-stretch"}},defaultVariants:{orientation:"horizontal"}});function Hn(e){return e.split("-").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}const Gn={Home:"House"};function Jn(e){if(!e)return null;const s=Hn(e),n=Gn[s]||s;return un[n]||null}function Pe(e){return e.label?e.label:Pn[e.type]||e.type}function ot(e){return e.icon?Jn(e.icon):Wn[e.type]||null}function Qn(e){return e.activeView?e.activeView:e.defaultView?e.defaultView:e.views?.[0]?.type}const St=({schema:e,className:s,onViewChange:n,...i})=>{const l=r.useMemo(()=>e.storageKey?e.storageKey:`view-switcher${e.id?`-${e.id}`:""}`,[e.id,e.storageKey]),[o,d]=r.useState(()=>Qn(e));r.useEffect(()=>{if(e.activeView){d(e.activeView);return}if(e.persistPreference)try{const y=localStorage.getItem(l);if(y){const x=e.views.find(f=>f.type===y)?.type;x&&d(x)}}catch{}},[e.activeView,e.persistPreference,e.views,l]),r.useEffect(()=>{if(!(!e.persistPreference||!o||e.activeView))try{localStorage.setItem(l,o)}catch{}},[o,e.activeView,e.persistPreference,l]);const a=r.useCallback(y=>{n?.(y),e.onViewChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onViewChange,{detail:{view:y}}))},[n,e.onViewChange]),w=r.useCallback(y=>{d(y),a(y)},[a]),C=o||e.views?.[0]?.type,m=C||"",c=e.views.find(y=>y.type===C)||e.views?.[0],g=e.variant||"tabs",N=e.position||"top",V=N==="left"||N==="right",b=V?"vertical":"horizontal",I=t.jsxs("div",{className:_(Kn({orientation:b})),children:[g==="dropdown"&&t.jsxs(Ve,{value:m,onValueChange:y=>w(y),children:[t.jsx(Te,{className:_("w-full",V?"h-10":"h-9"),children:t.jsx(ze,{placeholder:"Select view"})}),t.jsx(Ie,{children:e.views.map((y,x)=>t.jsx(Se,{value:y.type,children:Pe(y)},`${y.type}-${x}`))})]}),g==="buttons"&&t.jsx("div",{className:_(Bn({orientation:b})),children:e.views.map((y,x)=>{const f=y.type===C,u=ot(y);return t.jsxs(ee,{type:"button",size:"sm",variant:f?"secondary":"ghost",className:_("justify-start gap-2",V?"w-full":""),onClick:()=>w(y.type),children:[u?t.jsx(u,{className:"h-4 w-4"}):null,t.jsx("span",{children:Pe(y)})]},`${y.type}-${x}`)})}),g==="tabs"&&t.jsx(Ue,{value:m,onValueChange:y=>w(y),children:t.jsx(He,{className:_(Un({orientation:b})),children:e.views.map((y,x)=>{const f=ot(y);return t.jsxs(Ge,{value:y.type,className:_("gap-2",V?"justify-start":""),children:[f?t.jsx(f,{className:"h-4 w-4"}):null,t.jsx("span",{children:Pe(y)})]},`${y.type}-${x}`)})})})]}),z=c?.schema?Array.isArray(c.schema)?t.jsx("div",{className:"space-y-4",children:c.schema.map((y,x)=>t.jsx(te,{schema:y,...i},`${c.type}-${x}`))}):t.jsx(te,{schema:c.schema,...i}):null;return t.jsxs("div",{className:_(qn({position:N}),s),children:[t.jsx("div",{className:_("shrink-0",V?"flex flex-col":"flex"),children:I}),t.jsx("div",{className:"flex-1 min-w-0",children:z})]})};let De=null;try{De=require("@object-ui/react").SchemaRenderer||null}catch{}const Xn=({schema:e,dataSource:s,className:n,views:i,activeViewId:l,onViewChange:o,onRowClick:d,onEdit:a,renderListView:w,toolbarAddon:C})=>{const[m,c]=r.useState(null),[g,N]=r.useState(!1),[V,b]=r.useState("create"),[I,z]=r.useState(null),[y,x]=r.useState(0),[f,u]=r.useState([]),[j,v]=r.useState(!1),[S,p]=r.useState({}),[A,X]=r.useState([]),O=e.listViews,D=O!=null&&Object.keys(O).length>0,[R,K]=r.useState(()=>e.defaultListView&&O?.[e.defaultListView]?e.defaultListView:O&&Object.keys(O)[0]||""),M=r.useMemo(()=>!D||!R?null:O[R]||null,[D,R,O]),U=r.useMemo(()=>i&&i.length>0?i:null,[i]),ue=U!=null&&U.length>0,oe=l||U?.[0]?.id,W=U?.find(h=>h.id===oe)||U?.[0],ie=r.useMemo(()=>M?.type?M.type:W?.type?W.type:e.defaultViewType||"grid",[M,W,e.defaultViewType]),q=e.navigation;r.useEffect(()=>{let h=!0;const F=async()=>{try{const E=await s.getObjectSchema(e.objectName);h&&c(E)}catch(E){console.error("Failed to fetch object schema:",E)}};return e.objectName&&s&&F(),()=>{h=!1}},[e.objectName,s]),r.useEffect(()=>{let h=!0;return(async()=>{if(!(ie==="grid"&&!w)&&!(!s||!e.objectName)){v(!0);try{const E=M?.filter||W?.filter||e.table?.defaultFilters||[],Y=Object.entries(S).filter(([,ne])=>ne!==void 0&&ne!==""&&ne!==null).map(([ne,pe])=>[ne,"=",pe]);let L=[];E.length>0&&Y.length>0?L=["and",...E,...Y]:Y.length===1?L=Y[0]:Y.length>1?L=["and",...Y]:L=E;const Z=A.length>0?A.map(ne=>({field:ne.field,order:ne.direction})):M?.sort||W?.sort||e.table?.defaultSort||void 0,B=await s.find(e.objectName,{$filter:L.length>0?L:void 0,$orderby:Z,$top:100});let Q=[];Array.isArray(B)?Q=B:B&&typeof B=="object"&&(Array.isArray(B.data)?Q=B.data:Array.isArray(B.records)&&(Q=B.records)),h&&u(Q)}catch(E){console.error("ObjectView data fetch error:",E)}finally{h&&v(!1)}}})(),()=>{h=!1}},[e.objectName,s,ie,S,A,y,M,W,w]);const se=e.layout||"drawer",le=e.operations||e.table?.operations||{create:!0,read:!0,update:!0,delete:!0},Me=r.useCallback(()=>{se==="page"&&e.onNavigate?e.onNavigate("new","edit"):(b("create"),z(null),N(!0))},[se,e]),we=r.useCallback(h=>{if(a){a(h);return}if(se==="page"&&e.onNavigate){const F=h._id||h.id;e.onNavigate(F,"edit")}else b("edit"),z(h),N(!0)},[se,e,a]),Ne=r.useCallback(h=>{if(se==="page"&&e.onNavigate){const F=h._id||h.id;e.onNavigate(F,"view")}else b("view"),z(h),N(!0)},[se,e]),je=r.useCallback(h=>{if(d){d(h);return}if(q){if(q.mode==="none"||q.preventNavigation)return;if(q.mode==="new_window"||q.openNewTab){const F=h._id||h.id,E=`/${e.objectName}/${F}`;window.open(E,"_blank");return}if(q.mode==="drawer"){b("view"),z(h),N(!0);return}if(q.mode==="modal"){b("view"),z(h),N(!0);return}if(q.mode==="page"){const F=h._id||h.id;e.onNavigate&&e.onNavigate(F,"view");return}}le.read!==!1&&Ne(h)},[d,q,le.read,Ne,e]),Fe=r.useCallback(h=>{x(F=>F+1)},[]),ae=r.useCallback(h=>{x(F=>F+1)},[]),Oe=r.useCallback(()=>{N(!1),z(null),x(h=>h+1)},[]),Ae=r.useCallback(()=>{N(!1),z(null)},[]);r.useCallback(()=>{x(h=>h+1)},[]);const be=r.useMemo(()=>!ue||!U||U.length<=1?null:{type:"view-switcher",variant:"tabs",position:"top",persistPreference:!0,storageKey:`view-pref-${e.objectName}`,defaultView:W?.type||"grid",activeView:W?.type||"grid",views:U.map(h=>{const F={kanban:"kanban",calendar:"calendar",map:"map",gallery:"layout-grid",timeline:"activity",gantt:"gantt-chart",grid:"table",list:"list",detail:"file-text"};return{type:h.type,label:h.label,icon:F[h.type]||"table"}})},[ue,U,W,e.objectName]),Le=r.useCallback(h=>{if(!U)return;const F=U.find(E=>E.type===h);F&&o&&o(F.id)},[U,o]),Re=r.useCallback(h=>{K(h)},[]);r.useMemo(()=>{if(e.showFilters===!1)return null;const h=e.filterableFields,F=m?.fields||{},Y=(h?h.map(L=>[L,F[L]||{label:L}]):Object.entries(F).filter(([,L])=>!L.hidden).slice(0,8)).map(([L,Z])=>{const B=Z.type||"text";let Q="text",ne;return B==="number"||B==="currency"||B==="percent"?Q="number":B==="boolean"||B==="toggle"?Q="boolean":B==="date"||B==="datetime"?Q="date":(B==="select"||Z.options)&&(Q="select",ne=(Z.options||[]).map(pe=>typeof pe=="string"?{label:pe,value:pe}:{label:pe.label,value:pe.value})),{field:L,label:Z.label||L,type:Q,placeholder:`Filter ${Z.label||L}...`,...ne?{options:ne}:{}}});return Y.length===0?null:{type:"filter-ui",layout:"popover",showClear:!0,showApply:!0,filters:Y,values:S}},[e.showFilters,e.filterableFields,m,S]),r.useMemo(()=>{const h=m?.fields||{},F=Object.entries(h).filter(([,E])=>!E.hidden).slice(0,10).map(([E,Y])=>({field:E,label:Y.label||E}));return F.length===0?null:{type:"sort-ui",variant:"dropdown",multiple:!1,fields:F,sort:A}},[m,A]);const _e=r.useCallback(h=>{const F={objectName:e.objectName,fields:M?.columns||W?.columns||e.table?.fields,className:"h-full w-full",showSearch:!1},E=M?.options||W||{};switch(h){case"kanban":return{type:"object-kanban",...F,groupBy:E.kanban?.groupField||"status",groupField:E.kanban?.groupField||"status",titleField:E.kanban?.titleField||"name",cardFields:F.fields||[],...E.kanban||{}};case"calendar":return{type:"object-calendar",...F,startDateField:E.calendar?.startDateField||"start_date",endDateField:E.calendar?.endDateField||"end_date",titleField:E.calendar?.titleField||"name",...E.calendar||{}};case"gallery":return{type:"object-gallery",...F,imageField:E.gallery?.imageField,titleField:E.gallery?.titleField||"name",subtitleField:E.gallery?.subtitleField,...E.gallery||{}};case"timeline":return{type:"object-timeline",...F,dateField:E.timeline?.dateField||"created_at",titleField:E.timeline?.titleField||"name",...E.timeline||{}};case"gantt":return{type:"object-gantt",...F,startDateField:E.gantt?.startDateField||"start_date",endDateField:E.gantt?.endDateField||"end_date",progressField:E.gantt?.progressField||"progress",dependenciesField:E.gantt?.dependenciesField||"dependencies",...E.gantt||{}};case"map":return{type:"object-map",...F,locationField:E.map?.locationField||"location",...E.map||{}};default:return null}},[e.objectName,e.table?.fields,M,W]),Ee=r.useMemo(()=>({type:"object-grid",objectName:e.objectName,title:e.table?.title,description:e.table?.description,fields:M?.columns||W?.columns||e.table?.fields,columns:M?.columns||W?.columns||e.table?.columns,operations:{...le,create:!1},defaultFilters:M?.filter||W?.filter||e.table?.defaultFilters,defaultSort:M?.sort||W?.sort||e.table?.defaultSort,pageSize:e.table?.pageSize,selectable:e.table?.selectable,className:e.table?.className}),[e,le,M,W]),ke=()=>{const h=I?I._id||I.id:void 0;return{type:"object-form",objectName:e.objectName,mode:V,recordId:h,title:e.form?.title,description:e.form?.description,fields:e.form?.fields,customFields:e.form?.customFields,groups:e.form?.groups,layout:e.form?.layout,columns:e.form?.columns,showSubmit:e.form?.showSubmit,submitText:e.form?.submitText,showCancel:e.form?.showCancel,cancelText:e.form?.cancelText,showReset:e.form?.showReset,initialValues:e.form?.initialValues,readOnly:e.form?.readOnly||V==="view",className:e.form?.className,onSuccess:Oe,onCancel:Ae}},ge=()=>{if(e.form?.title)return e.form.title;const h=m?.label||e.objectName;switch(V){case"create":return`Create ${h}`;case"edit":return`Edit ${h}`;case"view":return`View ${h}`;default:return h}},ve=r.useMemo(()=>{const h=q?.width;return h?typeof h=="number"?`max-w-[${h}px]`:`max-w-[${h}]`:""},[q]),T=()=>t.jsx(mt,{open:g,onOpenChange:N,direction:"right",children:t.jsxs(bt,{className:_("w-full sm:max-w-2xl",ve),children:[t.jsxs(gt,{children:[t.jsx(ht,{children:ge()}),e.form?.description&&t.jsx(yt,{children:e.form.description})]}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-4",children:t.jsx(Be,{schema:ke(),dataSource:s})})]})}),$=()=>t.jsx(dt,{open:g,onOpenChange:N,children:t.jsxs(ct,{className:_("max-w-2xl max-h-[90vh] overflow-y-auto",ve),children:[t.jsxs(ut,{children:[t.jsx(ft,{children:ge()}),e.form?.description&&t.jsx(pt,{children:e.form.description})]}),t.jsx(Be,{schema:ke(),dataSource:s})]})}),G=r.useMemo(()=>Object.keys(S).some(F=>S[F]!==void 0&&S[F]!==""&&S[F]!==null)?Object.entries(S).filter(([,F])=>F!==void 0&&F!==""&&F!==null).map(([F,E])=>({field:F,operator:"equals",value:E})):M?.filter||W?.filter||e.table?.defaultFilters,[S,M,W,e.table?.defaultFilters]),P=r.useMemo(()=>A.length>0?A:M?.sort||W?.sort||e.table?.defaultSort,[A,M,W,e.table?.defaultSort]),k=()=>{const h=`${e.objectName}-${R||W?.id||"default"}-${ie}-${y}`;if(w)return w({schema:{type:"list-view",objectName:e.objectName,viewType:ie,fields:M?.columns||W?.columns||e.table?.fields,filters:G,sort:P,options:M?.options||W},dataSource:s,onEdit:we,onRowClick:je,className:"h-full"});if(ie!=="grid"){const F=_e(ie);if(F&&De)return t.jsx(De,{schema:F,dataSource:s,data:f,loading:j},h);if(!De)return t.jsx("div",{className:"flex items-center justify-center h-40 text-muted-foreground",children:t.jsxs("p",{children:["SchemaRenderer not available. Install @object-ui/react to render ",ie," views."]})})}return t.jsx(jt,{schema:Ee,dataSource:s,onRowClick:je,onEdit:le.update!==!1?we:void 0,onDelete:le.delete!==!1?Fe:void 0,onBulkDelete:le.delete!==!1?ae:void 0},h)},J=()=>{if(!D)return null;const h=Object.entries(O);return h.length<=1?null:t.jsx(Ue,{value:R,onValueChange:Re,className:"w-full",children:t.jsx(He,{className:"w-auto",children:h.map(([F,E])=>t.jsx(Ge,{value:F,className:"text-sm",children:E.label||F},F))})})},fe=()=>{const h=e.showCreate!==!1&&le.create!==!1,F=e.showViewSwitcher===!0,E=J();return!E&&!F&&!h&&!C?null:t.jsxs("div",{className:"flex flex-col gap-3",children:[E,(F||h||C)&&t.jsxs("div",{className:"flex items-center justify-between gap-4",children:[t.jsx("div",{className:"flex items-center gap-2",children:F&&be&&t.jsx(St,{schema:be,onViewChange:Le,className:"overflow-x-auto"})}),t.jsxs("div",{className:"flex items-center gap-2",children:[C,h&&t.jsxs(ee,{size:"sm",onClick:Me,children:[t.jsx(fn,{className:"h-4 w-4"}),"Create"]})]})]})]})},H=q?.mode==="modal"?"modal":q?.mode==="drawer"?"drawer":se;return t.jsxs("div",{className:_("flex flex-col h-full",n),children:[(e.title||e.description)&&t.jsxs("div",{className:"mb-4 shrink-0",children:[e.title&&t.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:e.title}),e.description&&t.jsx("p",{className:"text-muted-foreground mt-1",children:e.description})]}),t.jsx("div",{className:"mb-4 shrink-0",children:fe()}),t.jsx("div",{className:"flex-1 min-h-0",children:k()}),H==="drawer"&&T(),H==="modal"&&$()]})},We=ye("flex",{variants:{layout:{inline:"flex-col space-y-4",popover:"items-center",drawer:"items-center"}},defaultVariants:{layout:"inline"}}),Yn=e=>e==null||e===""?!0:Array.isArray(e)?e.length===0:typeof e=="object"?Object.values(e).every(s=>s==null||s===""):!1,Zn=e=>Array.isArray(e)?{start:e[0]||"",end:e[1]||""}:e&&typeof e=="object"?{start:e.start||"",end:e.end||""}:{start:"",end:""},ei=({schema:e,className:s,onChange:n})=>{const[i,l]=r.useState(e.values||{}),[o,d]=r.useState(!1);r.useEffect(()=>{e.values&&l(e.values)},[e.values]);const a=r.useCallback(b=>{n?.(b),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{values:b}}))},[n,e.onChange]),w=r.useCallback((b,I)=>{const z={...i,[b]:I};l(z),e.showApply||a(z)},[a,e.showApply,i]),C=r.useCallback(()=>{const b={};if(l(b),e.showApply){a(b);return}a(b)},[a,e.showApply]),m=r.useCallback(()=>{a(i),d(!1)},[a,i]),c=r.useMemo(()=>Object.values(i).filter(b=>!Yn(b)).length,[i]),g=b=>{const I=b.label||b.field,z=b.placeholder||`Filter by ${I}`;switch(b.type){case"number":return t.jsx(Ce,{type:"number",value:i[b.field]??"",placeholder:z,onChange:y=>{const x=y.target.value,f=x===""?"":Number(x);w(b.field,f)}});case"select":return t.jsxs(Ve,{value:i[b.field]!==void 0?String(i[b.field]):"",onValueChange:y=>{const x=b.options?.find(f=>String(f.value)===y);w(b.field,x?x.value:y)},children:[t.jsx(Te,{children:t.jsx(ze,{placeholder:z})}),t.jsx(Ie,{children:b.options?.map(y=>t.jsx(Se,{value:String(y.value),children:y.label},String(y.value)))})]});case"date":return t.jsx(Ce,{type:"date",value:i[b.field]??"",onChange:y=>w(b.field,y.target.value)});case"date-range":{const y=Zn(i[b.field]);return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ce,{type:"date",value:y.start??"",onChange:x=>{w(b.field,{...y,start:x.target.value})}}),t.jsx(Ce,{type:"date",value:y.end??"",onChange:x=>{w(b.field,{...y,end:x.target.value})}})]})}case"boolean":return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Bt,{checked:!!i[b.field],onCheckedChange:y=>w(b.field,!!y)}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Enabled"})]});case"text":default:return t.jsx(Ce,{value:i[b.field]??"",placeholder:z,onChange:y=>w(b.field,y.target.value)})}},N=t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:e.filters.map(b=>t.jsxs("div",{className:"space-y-2",children:[t.jsx(Pt,{className:"text-xs text-muted-foreground",children:b.label||b.field}),g(b)]},b.field))}),(e.showApply||e.showClear)&&t.jsxs("div",{className:"flex items-center justify-end gap-2 border-t pt-3",children:[e.showClear&&t.jsx(ee,{type:"button",variant:"ghost",size:"sm",onClick:C,children:"Clear"}),e.showApply&&t.jsx(ee,{type:"button",size:"sm",onClick:m,children:"Apply"})]})]}),V=e.layout||"inline";return V==="popover"?t.jsx("div",{className:_(We({layout:V}),s),children:t.jsxs(Wt,{open:o,onOpenChange:d,children:[t.jsx(qt,{asChild:!0,children:t.jsxs(ee,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",children:[t.jsx(Ze,{className:"h-4 w-4"}),"Filters",c>0&&t.jsx("span",{className:"inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary",children:c})]})}),t.jsx(Kt,{align:"start",className:"w-[520px] p-4",children:N})]})}):V==="drawer"?t.jsxs("div",{className:_(We({layout:V}),s),children:[t.jsxs(ee,{type:"button",variant:c>0?"secondary":"outline",size:"sm",className:"gap-2",onClick:()=>d(!0),children:[t.jsx(Ze,{className:"h-4 w-4"}),"Filters",c>0&&t.jsx("span",{className:"inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary/10 px-1 text-xs font-medium text-primary",children:c})]}),t.jsx(mt,{open:o,onOpenChange:d,children:t.jsxs(bt,{children:[t.jsxs(gt,{children:[t.jsx(ht,{children:"Filters"}),t.jsx(yt,{children:"Refine the data with advanced filters."})]}),t.jsx("div",{className:"px-4 pb-6",children:N})]})})]}):t.jsxs("div",{className:_(We({layout:V}),s),children:[N,!e.showApply&&e.showClear&&t.jsxs(ee,{type:"button",variant:"ghost",size:"sm",className:"gap-2",onClick:C,children:[t.jsx(pn,{className:"h-3.5 w-3.5"}),"Clear filters"]})]})},qe=ye("",{variants:{variant:{buttons:"flex flex-wrap gap-2",dropdown:"flex flex-wrap items-center gap-3",builder:"space-y-3"}},defaultVariants:{variant:"dropdown"}}),Ke=e=>e?e.map(s=>({field:s.field,direction:s.direction})):[],at=e=>e.map(s=>({id:`${s.field}-${s.direction}`,field:s.field,order:s.direction})),ti=e=>e.filter(s=>s.field).map(s=>({field:s.field,direction:s.order})),ni=({schema:e,className:s,onChange:n})=>{const[i,l]=r.useState(()=>Ke(e.sort)),[o,d]=r.useState(()=>at(Ke(e.sort)));r.useEffect(()=>{const c=Ke(e.sort);l(c),d(at(c))},[e.sort]);const a=r.useCallback(c=>{l(c),n?.(c),e.onChange&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(e.onChange,{detail:{sort:c}}))},[n,e.onChange]),w=r.useCallback(c=>{const g=i.find(b=>b.field===c),N=!!e.multiple;if(!g){const b=N?[...i,{field:c,direction:"asc"}]:[{field:c,direction:"asc"}];a(b);return}if(g.direction==="asc"){const b=i.map(I=>I.field===c?{...I,direction:"desc"}:I);a(b);return}const V=i.filter(b=>b.field!==c);a(V)},[a,e.multiple,i]);if((e.variant||"dropdown")==="buttons")return t.jsx("div",{className:_(qe({variant:"buttons"}),s),children:e.fields.map(c=>{const g=i.find(V=>V.field===c.field),N=g?.direction==="asc"?mn:bn;return t.jsxs(ee,{type:"button",variant:g?"secondary":"outline",size:"sm",onClick:()=>w(c.field),className:"gap-2",children:[t.jsx("span",{children:c.label||c.field}),g&&t.jsx(N,{className:"h-3.5 w-3.5"})]},c.field)})});if(e.multiple)return t.jsx("div",{className:_(qe({variant:"builder"}),s),children:t.jsx(Ut,{fields:e.fields.map(c=>({value:c.field,label:c.label||c.field})),value:o,onChange:c=>{d(c),a(ti(c))}})});const m=i[0];return t.jsxs("div",{className:_(qe({variant:"dropdown"}),s),children:[t.jsxs(Ve,{value:m?.field||"",onValueChange:c=>{if(!c){a([]);return}a([{field:c,direction:m?.direction||"asc"}])},children:[t.jsx(Te,{className:"w-56",children:t.jsx(ze,{placeholder:"Select field"})}),t.jsx(Ie,{children:e.fields.map(c=>t.jsx(Se,{value:c.field,children:c.label||c.field},c.field))})]}),t.jsxs(Ve,{value:m?.direction||"asc",onValueChange:c=>{m?.field&&a([{field:m.field,direction:c}])},children:[t.jsx(Te,{className:"w-36",children:t.jsx(ze,{})}),t.jsxs(Ie,{children:[t.jsx(Se,{value:"asc",children:"Ascending"}),t.jsx(Se,{value:"desc",children:"Descending"})]})]})]})},ii=me.createContext(null);let Nt=ii;try{const e=require("@object-ui/react");e.SchemaRendererContext&&(Nt=e.SchemaRendererContext)}catch{}const Ft=({schema:e})=>{const n=r.useContext(Nt)?.dataSource??null;return t.jsx(Xn,{schema:e,dataSource:n})};re.register("object-view",Ft,{namespace:"plugin-view",label:"Object View",category:"view",icon:"LayoutDashboard",inputs:[{name:"objectName",type:"string",label:"Object Name",required:!0},{name:"title",type:"string",label:"Title"},{name:"description",type:"string",label:"Description"},{name:"layout",type:"enum",label:"Form Layout",enum:["drawer","modal","page"]},{name:"defaultViewType",type:"enum",label:"Default View Type",enum:["grid","kanban","gallery","calendar","timeline","gantt","map"]},{name:"defaultListView",type:"string",label:"Default Named View"},{name:"showSearch",type:"boolean",label:"Show Search"},{name:"showFilters",type:"boolean",label:"Show Filters"},{name:"showCreate",type:"boolean",label:"Show Create Button"},{name:"showRefresh",type:"boolean",label:"Show Refresh Button"},{name:"showViewSwitcher",type:"boolean",label:"Show View Switcher"},{name:"listViews",type:"object",label:"Named List Views"},{name:"navigation",type:"object",label:"Navigation Config"},{name:"searchableFields",type:"array",label:"Searchable Fields"},{name:"filterableFields",type:"array",label:"Filterable Fields"}],defaultProps:{layout:"drawer",defaultViewType:"grid",showSearch:!0,showFilters:!0,showCreate:!0,showRefresh:!0,showViewSwitcher:!0}});re.register("view",Ft,{namespace:"plugin-view",label:"View",category:"view"});re.register("view-switcher",St,{namespace:"view",label:"View Switcher",category:"view",icon:"LayoutGrid",inputs:[{name:"views",type:"array",label:"Views",required:!0},{name:"defaultView",type:"string",label:"Default View"},{name:"activeView",type:"string",label:"Active View"},{name:"variant",type:"enum",label:"Variant",enum:["tabs","buttons","dropdown"]},{name:"position",type:"enum",label:"Position",enum:["top","bottom","left","right"]},{name:"persistPreference",type:"boolean",label:"Persist Preference"},{name:"storageKey",type:"string",label:"Storage Key"},{name:"onViewChange",type:"string",label:"On View Change Event"}],defaultProps:{variant:"tabs",position:"top",defaultView:"grid",views:[{type:"grid",label:"Grid",schema:{type:"text",content:"Grid view"}},{type:"list",label:"List",schema:{type:"text",content:"List view"}}]}});re.register("filter-ui",ei,{namespace:"view",label:"Filter UI",category:"view",icon:"SlidersHorizontal",inputs:[{name:"filters",type:"array",label:"Filters",required:!0},{name:"values",type:"object",label:"Values"},{name:"onChange",type:"string",label:"On Change Event"},{name:"showClear",type:"boolean",label:"Show Clear Button"},{name:"showApply",type:"boolean",label:"Show Apply Button"},{name:"layout",type:"enum",label:"Layout",enum:["inline","popover","drawer"]}],defaultProps:{layout:"inline",showApply:!1,showClear:!0,filters:[{field:"name",label:"Name",type:"text",placeholder:"Search name"},{field:"status",label:"Status",type:"select",options:[{label:"Open",value:"open"},{label:"Closed",value:"closed"}]},{field:"created_at",label:"Created",type:"date"}]}});re.register("sort-ui",ni,{namespace:"view",label:"Sort UI",category:"view",icon:"ArrowUpDown",inputs:[{name:"fields",type:"array",label:"Fields",required:!0},{name:"sort",type:"array",label:"Sort"},{name:"onChange",type:"string",label:"On Change Event"},{name:"multiple",type:"boolean",label:"Allow Multiple"},{name:"variant",type:"enum",label:"Variant",enum:["dropdown","buttons"]}],defaultProps:{variant:"dropdown",multiple:!0,fields:[{field:"name",label:"Name"},{field:"created_at",label:"Created At"}],sort:[{field:"name",direction:"asc"}]}});const si=({schema:e,className:s,children:n,dataSource:i,...l})=>{const o=e.props?.columns?{display:"grid",gridTemplateColumns:`repeat(${e.props.columns}, 1fr)`,gap:"1rem"}:void 0;return t.jsx("div",{className:s,style:o,...l,children:n})};re.register("view:simple",si,{namespace:"plugin-view",label:"Simple View",category:"view"});export{Xn as O,Be as a,ui as u};