@object-ui/console 4.0.5 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/assets/{AppManagementPage-ynJLzxVY.js → AppManagementPage-DvZRhEu3.js} +1 -1
  2. package/dist/assets/{ConsoleFloatingChatbot-C2rFxE3n.js → ConsoleFloatingChatbot-DSk3VUa6.js} +1 -1
  3. package/dist/assets/DashboardView-ClGhVUz7.js +1 -0
  4. package/dist/assets/{MetadataDetailPage-B9EzoQgu.js → MetadataDetailPage-Dn8QJ3Hw.js} +1 -1
  5. package/dist/assets/{MetadataFormDialog-BebGlAr3.js → MetadataFormDialog-Bf5wwigQ.js} +1 -1
  6. package/dist/assets/MetadataManagerPage-CLb0l4Pw.js +1 -0
  7. package/dist/assets/{PageView-C2GS-SQP.js → PageView-_R84mPfp.js} +2 -2
  8. package/dist/assets/ProfilePage-BFhufxnO.js +1 -0
  9. package/dist/assets/RecordDetailView-DROfHlhL.js +1 -0
  10. package/dist/assets/{RecordFormPage-B6mEBKMB.js → RecordFormPage-BqCa2Cez.js} +1 -1
  11. package/dist/assets/{ReportView-B16PsGer.js → ReportView-bv8vOOKb.js} +2 -2
  12. package/dist/assets/{SearchResultsPage-932jfRUX.js → SearchResultsPage-KJr5yhgC.js} +1 -1
  13. package/dist/assets/{SystemHubPage-CqrYgpYf.js → SystemHubPage-LGgCwgTn.js} +1 -1
  14. package/dist/assets/{data-adapter-BwfAq_h0.js → data-adapter-ChK5QXoY.js} +1 -1
  15. package/dist/assets/{getIcon-DF6zJOtU.js → getIcon-BKYKFGnN.js} +1 -1
  16. package/dist/assets/index-C_jWdyY_.css +2 -0
  17. package/dist/assets/index-DTdi5Ufa.js +2 -0
  18. package/dist/assets/{plugin-calendar-D1bCBBwe.js → plugin-calendar-CQkP8bUI.js} +1 -1
  19. package/dist/assets/{plugin-charts-x_9Q2-i_.js → plugin-charts-CJxtgGBd.js} +1 -1
  20. package/dist/assets/{plugin-chatbot-CgNZnFch.js → plugin-chatbot-CgD9fZFI.js} +14 -14
  21. package/dist/assets/plugin-form-BFt_k4to.js +1 -0
  22. package/dist/assets/plugin-gantt-BKC7uDlF.js +1 -0
  23. package/dist/assets/plugin-grid-C9RnYppl.js +8 -0
  24. package/dist/assets/plugin-kanban-Bi-sR7AW.js +1 -0
  25. package/dist/assets/{plugin-map-DZdVR1tc.js → plugin-map-zYnfrqC_.js} +1 -1
  26. package/dist/assets/{plugin-markdown-BlHuacDq.js → plugin-markdown-D1ozhgoT.js} +1 -1
  27. package/dist/assets/{plugin-timeline-OEB0nyvd.js → plugin-timeline-B93E4n2x.js} +1 -1
  28. package/dist/assets/plugin-view-B94g0Ssh.js +1 -0
  29. package/dist/assets/plugins-views-Bi5okDge.js +63 -0
  30. package/dist/assets/src-DwuebCF9.js +1 -0
  31. package/dist/assets/ui-components-BL3SEdAz.css +1 -0
  32. package/dist/assets/ui-components-DSSaN2w_.js +36 -0
  33. package/dist/assets/{ui-layout-jqAD528v.js → ui-layout-iDLUMX7R.js} +1 -1
  34. package/dist/index.html +4 -4
  35. package/package.json +30 -30
  36. package/dist/assets/DashboardView-x75VLMQW.js +0 -1
  37. package/dist/assets/MetadataManagerPage-B0xfI-4w.js +0 -1
  38. package/dist/assets/ProfilePage-BO3TRbTV.js +0 -1
  39. package/dist/assets/RecordDetailView-Clze41HE.js +0 -1
  40. package/dist/assets/index-CPatxDwz.js +0 -2
  41. package/dist/assets/index-vbGrAsEJ.css +0 -2
  42. package/dist/assets/plugin-form-DOfn-uRa.js +0 -1
  43. package/dist/assets/plugin-gantt-CHZ4HLjh.js +0 -1
  44. package/dist/assets/plugin-grid-Cn_T_wpz.js +0 -8
  45. package/dist/assets/plugin-kanban-BsgjJQam.js +0 -1
  46. package/dist/assets/plugin-view-CJFsgQ9v.js +0 -1
  47. package/dist/assets/plugins-views-DqZMtAOw.js +0 -63
  48. package/dist/assets/src-D5NTzWsi.js +0 -1
  49. package/dist/assets/ui-components-B5ROGaJH.css +0 -1
  50. package/dist/assets/ui-components-B7mlp0en.js +0 -36
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{o}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as s,Fo as c,Jm as l,No as u,Qn as d,Rd as f,ar as p,dn as m,er as h,hc as g,mo as _,pE as v,um as y,yb as b,yr as x}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";var S=e(t(),1);function C(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}var w=r();function T(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,{apps:T,refresh:E}=a(),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(new Set),[j,M]=(0,S.useState)(null),[N,P]=(0,S.useState)(!1),F=(T||[]).filter(e=>{if(!D)return!0;let t=D.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),I=(0,S.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,S.useCallback)(()=>{k.size===F.length?A(new Set):A(new Set(F.map(e=>e.name)))},[k.size,F]),R=(0,S.useCallback)(async e=>{P(!0);try{let t=e.active===!1;o.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await E()}catch{o.error(`Failed to toggle app status`)}finally{P(!1)}},[E]),z=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${e.label||e.name} set as default`),await E()}catch{o.error(`Failed to set default app`)}finally{P(!1)}},[E]),B=(0,S.useCallback)(async e=>{if(j!==e.name){M(e.name);return}P(!0);try{o.success(`${e.label||e.name} deleted`),M(null),await E()}catch{o.error(`Failed to delete app`)}finally{P(!1)}},[j,E]),V=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${k.size} apps ${e?`enabled`:`disabled`}`),A(new Set),await E()}catch{o.error(`Bulk operation failed`)}finally{P(!1)}},[k,E]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,w.jsxs)(x,{onClick:()=>e(`${r}/create-app`),"data-testid":`create-app-btn`,children:[(0,w.jsx)(y,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,w.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,w.jsx)(f,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(m,{id:`app-search`,placeholder:`Search apps...`,value:D,onChange:e=>O(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),k.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(p,{variant:`secondary`,children:[k.size,` selected`]}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!0),disabled:N,children:`Enable`}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!1),disabled:N,children:`Disable`})]})]}),F.length>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,w.jsx)(d,{id:`select-all-apps`,checked:k.size===F.length&&F.length>0,onCheckedChange:()=>L()}),(0,w.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,F.length,`)`]})]}),F.length===0?(0,w.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,w.jsx)(b,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,w.jsx)(`p`,{children:`No apps found.`})]}):(0,w.jsx)(`div`,{className:`grid gap-3`,children:F.map(t=>{let n=t.active!==!1,i=t.isDefault===!0,a=j===t.name;return(0,w.jsx)(s,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,w.jsxs)(h,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,w.jsx)(d,{id:`select-app-${t.name}`,checked:k.has(t.name),onCheckedChange:()=>I(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,w.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,w.jsx)(b,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`span`,{className:`font-medium truncate`,children:C(t.label)||t.name}),i&&(0,w.jsx)(p,{variant:`default`,className:`text-xs`,children:`Default`}),(0,w.jsx)(p,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:C(t.description)})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t.name}`),children:(0,w.jsx)(v,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${r}/edit-app/${t.name}`),children:(0,w.jsx)(l,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>R(t),disabled:N,children:n?(0,w.jsx)(u,{className:`h-4 w-4`}):(0,w.jsx)(c,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>z(t),disabled:N||i,children:(0,w.jsx)(g,{className:`h-4 w-4 ${i?`fill-current text-yellow-500`:``}`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>B(t),disabled:N,className:a?`text-destructive`:``,children:(0,w.jsx)(_,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{T as AppManagementPage};
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{o}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as s,Ld as c,Mo as l,Po as u,Qn as d,Zn as f,fE as p,ir as m,lm as h,mc as g,po as _,qm as v,un as y,vb as b,vr as x}from"./ui-components-DSSaN2w_.js";import"./index-DTdi5Ufa.js";var S=e(t(),1);function C(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}var w=r();function T(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,{apps:T,refresh:E}=a(),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(new Set),[j,M]=(0,S.useState)(null),[N,P]=(0,S.useState)(!1),F=(T||[]).filter(e=>{if(!D)return!0;let t=D.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),I=(0,S.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,S.useCallback)(()=>{k.size===F.length?A(new Set):A(new Set(F.map(e=>e.name)))},[k.size,F]),R=(0,S.useCallback)(async e=>{P(!0);try{let t=e.active===!1;o.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await E()}catch{o.error(`Failed to toggle app status`)}finally{P(!1)}},[E]),z=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${e.label||e.name} set as default`),await E()}catch{o.error(`Failed to set default app`)}finally{P(!1)}},[E]),B=(0,S.useCallback)(async e=>{if(j!==e.name){M(e.name);return}P(!0);try{o.success(`${e.label||e.name} deleted`),M(null),await E()}catch{o.error(`Failed to delete app`)}finally{P(!1)}},[j,E]),V=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${k.size} apps ${e?`enabled`:`disabled`}`),A(new Set),await E()}catch{o.error(`Bulk operation failed`)}finally{P(!1)}},[k,E]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,w.jsxs)(x,{onClick:()=>e(`${r}/create-app`),"data-testid":`create-app-btn`,children:[(0,w.jsx)(h,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,w.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,w.jsx)(c,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(y,{id:`app-search`,placeholder:`Search apps...`,value:D,onChange:e=>O(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),k.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(m,{variant:`secondary`,children:[k.size,` selected`]}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!0),disabled:N,children:`Enable`}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!1),disabled:N,children:`Disable`})]})]}),F.length>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,w.jsx)(f,{id:`select-all-apps`,checked:k.size===F.length&&F.length>0,onCheckedChange:()=>L()}),(0,w.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,F.length,`)`]})]}),F.length===0?(0,w.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,w.jsx)(b,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,w.jsx)(`p`,{children:`No apps found.`})]}):(0,w.jsx)(`div`,{className:`grid gap-3`,children:F.map(t=>{let n=t.active!==!1,i=t.isDefault===!0,a=j===t.name;return(0,w.jsx)(d,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,w.jsxs)(s,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,w.jsx)(f,{id:`select-app-${t.name}`,checked:k.has(t.name),onCheckedChange:()=>I(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,w.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,w.jsx)(b,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`span`,{className:`font-medium truncate`,children:C(t.label)||t.name}),i&&(0,w.jsx)(m,{variant:`default`,className:`text-xs`,children:`Default`}),(0,w.jsx)(m,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:C(t.description)})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t.name}`),children:(0,w.jsx)(p,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${r}/edit-app/${t.name}`),children:(0,w.jsx)(v,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>R(t),disabled:N,children:n?(0,w.jsx)(l,{className:`h-4 w-4`}):(0,w.jsx)(u,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>z(t),disabled:N||i,children:(0,w.jsx)(g,{className:`h-4 w-4 ${i?`fill-current text-yellow-500`:``}`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>B(t),disabled:N,className:a?`text-destructive`:``,children:(0,w.jsx)(_,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{T as AppManagementPage};
@@ -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{$t as r,Qt as i,en as a,nn as o,tn as s}from"./ui-components-B7mlp0en.js";import{n as c,r as l,t as u}from"./plugin-chatbot-CgNZnFch.js";var d=e(t(),1),f=n(),p=`/api/v1/ai`;function m(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${p}`}function h({appLabel:e,objects:t,agents:n,agentsLoading:c,agentsError:p,activeAgent:m,onAgentChange:h,chatApi:g}){let _=t.map(e=>e.label||e.name).join(`, `),v=d.useMemo(()=>n.find(e=>e.name===m)?.label??m??e,[n,m,e]),y=m?`Hello! I'm **${v}**, your ${e} assistant. How can I help you today?`:`Hello! I'm your **${e}** assistant. ${p?`(Backend unreachable — running in offline demo mode.)`:``}`,{messages:b,isLoading:x,error:S,sendMessage:C,stop:w,reload:T,clear:E}=l({api:g,conversationId:m?`${e}:${m}`:void 0,body:{context:{activeApp:e,objects:t.map(e=>({name:e.name,label:e.label})),agentName:m}},initialMessages:[{id:`welcome`,role:`assistant`,content:y}],autoResponse:!g,autoResponseText:_?`I can help you work with ${_}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600}),D=n.length>0?(0,f.jsxs)(i,{value:m,onValueChange:h,disabled:c,children:[(0,f.jsx)(s,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,f.jsx)(o,{placeholder:`Choose agent...`})}),(0,f.jsx)(r,{align:`end`,children:n.map(e=>(0,f.jsxs)(a,{value:e.name,className:`text-xs`,children:[(0,f.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,f.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null;return(0,f.jsx)(u,{floatingConfig:{position:`bottom-right`,defaultOpen:!1,panelWidth:420,panelHeight:560,title:`${e} Assistant`,triggerSize:56},headerExtra:D,messages:b,placeholder:m?`Ask ${v}...`:c?`Loading agents...`:`Ask anything...`,onSendMessage:e=>C(e),onClear:E,onStop:x?w:void 0,onReload:T,isLoading:x,error:S,enableMarkdown:!0})}function g({appLabel:e,objects:t,apiBase:n,defaultAgent:r}){let i=d.useMemo(()=>m(n),[n]),a={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:o,isLoading:s,error:l}=c({apiBase:i}),[u,p]=d.useState(void 0);d.useEffect(()=>{if(!u&&o.length>0){let e=r??a;p(((e?o.find(t=>t.name===e):void 0)??o[0]).name)}},[o,u,r,a]);let g=u?`${i}/agents/${encodeURIComponent(u)}/chat`:void 0;return(0,f.jsx)(h,{appLabel:e,objects:t,agents:o,agentsLoading:s,agentsError:l,activeAgent:u,onAgentChange:p,chatApi:g},g??`local`)}export{g as default};
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{$t as r,Qt as i,Zt as a,en as o,tn as s}from"./ui-components-DSSaN2w_.js";import{n as c,r as l,t as u}from"./plugin-chatbot-CgD9fZFI.js";var d=e(t(),1),f=n(),p=`/api/v1/ai`;function m(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${p}`}function h({appLabel:e,objects:t,agents:n,agentsLoading:c,agentsError:p,activeAgent:m,onAgentChange:h,chatApi:g}){let _=t.map(e=>e.label||e.name).join(`, `),v=d.useMemo(()=>n.find(e=>e.name===m)?.label??m??e,[n,m,e]),y=m?`Hello! I'm **${v}**, your ${e} assistant. How can I help you today?`:`Hello! I'm your **${e}** assistant. ${p?`(Backend unreachable — running in offline demo mode.)`:``}`,{messages:b,isLoading:x,error:S,sendMessage:C,stop:w,reload:T,clear:E}=l({api:g,conversationId:m?`${e}:${m}`:void 0,body:{context:{activeApp:e,objects:t.map(e=>({name:e.name,label:e.label})),agentName:m}},initialMessages:[{id:`welcome`,role:`assistant`,content:y}],autoResponse:!g,autoResponseText:_?`I can help you work with ${_}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600}),D=n.length>0?(0,f.jsxs)(a,{value:m,onValueChange:h,disabled:c,children:[(0,f.jsx)(o,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,f.jsx)(s,{placeholder:`Choose agent...`})}),(0,f.jsx)(i,{align:`end`,children:n.map(e=>(0,f.jsxs)(r,{value:e.name,className:`text-xs`,children:[(0,f.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,f.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null;return(0,f.jsx)(u,{floatingConfig:{position:`bottom-right`,defaultOpen:!1,panelWidth:420,panelHeight:560,title:`${e} Assistant`,triggerSize:56},headerExtra:D,messages:b,placeholder:m?`Ask ${v}...`:c?`Loading agents...`:`Ask anything...`,onSendMessage:e=>C(e),onClear:E,onStop:x?w:void 0,onReload:T,isLoading:x,error:S,enableMarkdown:!0})}function g({appLabel:e,objects:t,apiBase:n,defaultAgent:r}){let i=d.useMemo(()=>m(n),[n]),a={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:o,isLoading:s,error:l}=c({apiBase:i}),[u,p]=d.useState(void 0);d.useEffect(()=>{if(!u&&o.length>0){let e=r??a;p(((e?o.find(t=>t.name===e):void 0)??o[0]).name)}},[o,u,r,a]);let g=u?`${i}/agents/${encodeURIComponent(u)}/chat`:void 0;return(0,f.jsx)(h,{appLabel:e,objects:t,agents:o,agentsLoading:s,agentsError:l,activeAgent:u,onAgentChange:p,chatApi:g},g??`local`)}export{g as default};
@@ -0,0 +1 @@
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,t as i}from"./vendor-react-B1k2FF9f.js";import{a,f as ee,p as te}from"./framework-CoXA0nY6.js";import{d as o}from"./infrastructure-Djv3I7gr.js";import{o as s}from"./vendor-ui-utils-Dyl9EYZi.js";import{Aj as c,Bs as l,Dj as u,Gn as d,Hn as f,Kn as p,Un as m,Wn as h,_j as g,at as ne,bb as re,io as _,it as ie,lm as ae,po as oe,qm as v,qn as se,rt as ce,vb as y,vr as b}from"./ui-components-DSSaN2w_.js";import{r as x}from"./utils-DMMB8Xfh.js";import{i as S,n as C,r as w}from"./plugins-views-Bi5okDge.js";import{n as T}from"./plugin-form-BFt_k4to.js";import{a as E,o as D,s as le}from"./index-DTdi5Ufa.js";var O=e({DashboardView:()=>z}),k=t(n(),1),A=i(),j=[{type:`metric`,label:`KPI Metric`,Icon:_},{type:`bar`,label:`Bar Chart`,Icon:c},{type:`line`,label:`Line Chart`,Icon:u},{type:`pie`,label:`Pie Chart`,Icon:g},{type:`table`,label:`Table`,Icon:l},{type:`grid`,label:`Grid`,Icon:y}],M=0;function N(){return M+=1,`widget_${Date.now()}_${M}`}function P(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:N()})}}function F(e){let t=j.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function I(e){return{title:e.title??``,description:e.description??``,type:e.type??`metric`,object:e.object??``,categoryField:e.categoryField??``,valueField:e.valueField??``,aggregate:e.aggregate??`count`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1,colorVariant:e.colorVariant??`default`,actionUrl:e.actionUrl??``}}function L(e,t){return{title:e.title,description:e.description,type:e.type,object:e.object,categoryField:e.categoryField,valueField:e.valueField,aggregate:e.aggregate,layout:{...t.layout||{},w:e.layoutW,h:e.layoutH},colorVariant:e.colorVariant,actionUrl:e.actionUrl}}function R(e){return{columns:e.columns??3,gap:e.gap??4,rowHeight:String(e.rowHeight??`120`),refreshInterval:String(e.refreshInterval??`0`),title:e.title??``,showDescription:e.showDescription??!0,theme:e.theme??`auto`}}function z({dataSource:e}){let{dashboardName:t}=r(),{showDebug:n}=le(),i=ee(),{t:c}=a(),{dashboardLabel:l,dashboardDescription:u}=o(),[g,_]=(0,k.useState)(!0),[y,O]=(0,k.useState)(!1),[M,z]=(0,k.useState)(null),[B,V]=(0,k.useState)(0),[H,U]=(0,k.useState)(null),W=(0,k.useCallback)(e=>{U(t=>(t&&t.resolve(e),null))},[]),ue=(0,k.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;U({schema:n,resolve:t})}),[]),de=(0,k.useMemo)(()=>({export_dashboard_pdf:async()=>{s.info(`Preparing PDF export…`);try{return window.print(),{success:!0}}catch(e){return s.error(`Export failed: ${e?.message||String(e)}`),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(s.info(`Forecast view coming soon`),{success:!0})}),[]);(0,k.useEffect)(()=>{_(!0),Y(null),O(!1),z(null),queueMicrotask(()=>_(!1))},[t]);let{dashboards:fe,objects:G,refresh:K}=te(),q=fe?.find(e=>e.name===t),[J,Y]=(0,k.useState)(null);(0,k.useEffect)(()=>{y||Y(null)},[q]);let X=(0,k.useCallback)(async e=>{try{i&&(await i.update(`sys_dashboard`,t,e),K().catch(()=>{}))}catch(e){console.warn(`[DashboardView] Auto-save failed:`,e)}},[i,t,K]),pe=(0,k.useCallback)(()=>{Y(P(q)),O(!0),V(e=>e+1)},[q]),Z=(0,k.useCallback)(()=>{O(!1),z(null)},[]),me=(0,k.useCallback)(e=>{if(!J)return;let t=N(),n={id:t,title:F(e),type:e,layout:{x:0,y:J.widgets?.length??0,w:J.columns??2,h:1}},r={...J,widgets:[...J.widgets||[],n]};Y(r),X(r),z(t),V(e=>e+1)},[J,X]),he=(0,k.useCallback)(e=>{if(!J)return;let t={...J,widgets:J.widgets.filter(t=>t.id!==e)};Y(t),X(t),M===e&&z(null)},[J,M,X]),ge=(0,k.useMemo)(()=>R(J||q),[B]),_e=(0,k.useCallback)(e=>{if(!J)return;let t={...J,columns:e.columns,gap:e.gap,rowHeight:e.rowHeight,refreshInterval:Number(e.refreshInterval)||0,title:e.title,showDescription:e.showDescription,theme:e.theme};Y(t),X(t),V(e=>e+1)},[J,X]),ve=(0,k.useCallback)((e,t)=>{J&&Y(n=>n&&(e===`refreshInterval`?{...n,refreshInterval:Number(t)||0}:{...n,[e]:t}))},[J]),Q=J?.widgets?.find(e=>e.id===M),ye=(0,k.useMemo)(()=>Q?I(Q):{},[M,B]),be=(0,k.useCallback)(e=>{if(!J||!M||!Q)return;let t=L(e,Q),n={...J,widgets:J.widgets.map(e=>e.id===M?{...e,...t}:e)};Y(n),X(n),V(e=>e+1)},[J,M,Q,X]),xe=(0,k.useCallback)((e,t)=>{M&&Y(n=>{if(!n)return n;let r=n.widgets?.find(e=>e.id===M);if(!r)return n;let i=I(r);i[e]=t;let a=L(i,r);return{...n,widgets:n.widgets.map(e=>e.id===M?{...e,...a}:e)}})},[M]),Se=(0,k.useMemo)(()=>{if(G?.length)return G.map(e=>({value:e.name,label:e.label||e.name}))},[G]),Ce=(0,k.useMemo)(()=>{let e=Q?.object;if(!e||!G?.length)return;let t=G.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.filter(e=>e.name).map(e=>({value:e.name,label:e.label||e.name})):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e}))},[Q?.object,G]);if(g)return(0,A.jsx)(E,{});if(!q)return(0,A.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,A.jsxs)(ce,{children:[(0,A.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,A.jsx)(re,{className:`h-6 w-6 text-muted-foreground`})}),(0,A.jsx)(ne,{children:`Dashboard Not Found`}),(0,A.jsxs)(ie,{children:[`The dashboard "`,t,`" could not be found. It may have been removed or renamed.`]})]})});let $=J||q;return(0,A.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,A.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,A.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,A.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:l({name:q.name,label:x(q.label,c)})||q.name}),(()=>{let e=u({name:q.name,description:x(q.description,c)});return e?(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e}):null})()]}),(0,A.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[y&&(0,A.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:j.map(({type:e,label:t,Icon:n})=>(0,A.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>me(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,A.jsx)(ae,{className:`h-3 w-3`}),(0,A.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,A.jsxs)(`button`,{type:`button`,onClick:pe,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,A.jsx)(v,{className:`h-3.5 w-3.5`}),c(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,A.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,A.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,A.jsx)(S,{schema:$,dataSource:e,designMode:y,selectedWidgetId:M,onWidgetClick:z,modalHandler:ue,scriptHandlers:de})}),Q?(0,A.jsx)(C,{open:y,onClose:Z,config:ye,onSave:be,onFieldChange:xe,availableObjects:Se,availableFields:Ce,headerExtra:(0,A.jsx)(b,{size:`sm`,variant:`ghost`,onClick:()=>he(M),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"data-testid":`widget-delete-button`,title:`Delete widget`,children:(0,A.jsx)(oe,{className:`h-3.5 w-3.5`})})},M):(0,A.jsx)(w,{open:y,onClose:Z,config:ge,onSave:_e,onFieldChange:ve}),(0,A.jsx)(D,{open:n,sections:[{title:`Dashboard Configuration`,data:$}]})]}),H&&H.schema?.objectName?(0,A.jsx)(T,{schema:{type:`object-form`,formType:`modal`,objectName:H.schema.objectName,mode:H.schema.mode||`create`,recordId:H.schema.recordId,title:H.schema.title,description:H.schema.description,fields:H.schema.fields,open:!0,onOpenChange:e=>{e||W({success:!1})},onSuccess:e=>{W({success:!0,reload:!0,data:e})},onCancel:()=>{W({success:!1})},showSubmit:!0,showCancel:!0},dataSource:i}):H?(0,A.jsx)(f,{open:!0,onOpenChange:e=>{e||W({success:!1})},children:(0,A.jsxs)(m,{children:[(0,A.jsxs)(p,{children:[(0,A.jsx)(se,{children:H.schema?.title||`Action`}),H.schema?.description&&(0,A.jsx)(h,{children:H.schema.description})]}),(0,A.jsxs)(d,{children:[(0,A.jsx)(b,{variant:`outline`,onClick:()=>W({success:!1}),children:`Cancel`}),(0,A.jsx)(b,{onClick:()=>W({success:!0}),children:`OK`})]})]})}):null]})}export{O as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{D as a,p as o}from"./framework-CoXA0nY6.js";import{c as s}from"./infrastructure-Djv3I7gr.js";import{o as c}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as l,Cy as u,Jm as d,ar as f,cI as p,er as m,no as h,nr as g,rr as _,yr as v}from"./ui-components-B7mlp0en.js";import{r as y}from"./index-CPatxDwz.js";import{i as b,n as x,t as S}from"./getIcon-DF6zJOtU.js";import{t as C}from"./MetadataFormDialog-BebGlAr3.js";var w=e(t(),1),T=r(),E=class extends w.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[MetadataDetailPage] Schema rendering error:`,e,t.componentStack)}render(){return this.state.hasError?(0,T.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/5 p-6 text-center`,"data-testid":`schema-render-error`,children:[(0,T.jsx)(h,{className:`h-8 w-8 mx-auto mb-3 text-destructive`}),(0,T.jsxs)(`p`,{className:`text-sm font-medium text-destructive`,children:[`Failed to render `,this.props.fallbackLabel||`detail`,` page`]}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:this.state.error?.message||`An unexpected error occurred.`})]}):this.props.children}};function D({schema:e}){let t=e.body||[];return t.length===0?null:(0,T.jsx)(`div`,{className:`flex flex-col gap-6`,"data-testid":`schema-detail-content`,children:t.map((e,t)=>(0,T.jsx)(a,{schema:e},e?.id||t))})}function O(){let e=i(),{appName:t,metadataType:r,itemName:a}=n(),h=t?`/apps/${t}`:``,O=y(),{refresh:k}=o(),{user:A}=s(),j=A?.role===`admin`,M=r?b(r):void 0,[N,P]=(0,w.useState)(null),[F,I]=(0,w.useState)(!0),[L,R]=(0,w.useState)(!1),[z,B]=(0,w.useState)(!1),V=(0,w.useRef)(O);V.current=O;let H=(0,w.useRef)(M?.label);H.current=M?.label;let U=(0,w.useCallback)(async()=>{let e=V.current;if(!(!e||!r||!a)){I(!0);try{P((await e.getItems(r)).find(e=>String(e.name)===a&&!e._deleted)??null)}catch{c.error(`Failed to load ${H.current??r}`)}finally{I(!1)}}},[r,a]);(0,w.useEffect)(()=>{U()},[U]);let W=(0,w.useCallback)(async e=>{let t=V.current;if(!(!t||!r||!a)){B(!0);try{let n={...N,...e};await t.saveMetadataItem(r,a,n),await k(),await U(),c.success(`${H.current??`Item`} "${a}" updated`)}catch{throw c.error(`Failed to update "${a}"`),Error(`Failed to save ${H.current??`item`} "${a}"`)}finally{B(!1)}}},[r,a,N,k,U]),G=M?.customRoute?`${h}${M.customRoute}`:`${h}/system/metadata/${r??``}`;if(!M)return(0,T.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,T.jsx)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${h}/system`),children:`Back to System Settings`})]})});if(M.pageSchemaFactory){let t=M.pageSchemaFactory(a,N),n=S(M.icon);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(n,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:t.title||a}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` · `,(0,T.jsx)(`span`,{className:`font-mono text-xs`,children:a})]})]})]})}),(0,T.jsx)(E,{fallbackLabel:M.label,children:(0,T.jsx)(D,{schema:t})})]})}let K=S(M.icon),q=M.editable!==!1&&j,J=M.formFields??x,Y=M.detailComponent;return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(K,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:F?`Loading...`:String(N?.label??N?.name??a)}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` Details`]})]})]}),q&&!F&&N&&(0,T.jsxs)(v,{variant:`outline`,onClick:()=>R(!0),disabled:z,"data-testid":`detail-edit-btn`,children:[(0,T.jsx)(d,{className:`mr-2 h-4 w-4`}),`Edit`]})]}),F&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`detail-loading`,children:[(0,T.jsx)(u,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading...`]}),!F&&!N&&(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`detail-not-found`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[M.label,` "`,a,`" not found.`]}),(0,T.jsxs)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(G),children:[`Back to `,M.pluralLabel]})]}),!F&&N&&(0,T.jsx)(T.Fragment,{children:Y?(0,T.jsx)(Y,{item:N}):(0,T.jsxs)(l,{"data-testid":`detail-card`,children:[(0,T.jsx)(g,{children:(0,T.jsxs)(_,{className:`flex items-center gap-2`,children:[(0,T.jsx)(f,{variant:`secondary`,children:M.label}),String(N.name??``)]})}),(0,T.jsx)(m,{children:(0,T.jsx)(`dl`,{className:`grid gap-3 sm:grid-cols-2`,children:J.map(e=>(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{className:`text-sm font-medium text-muted-foreground`,children:e.label}),(0,T.jsx)(`dd`,{className:`mt-1 text-sm`,children:String(N[e.key]??`—`)})]},e.key))})})]})}),q&&N&&(0,T.jsx)(C,{open:L,onOpenChange:R,mode:`edit`,typeLabel:M.label,formFields:M.formFields,initialValues:N,onSubmit:W})]})}export{O as MetadataDetailPage};
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{D as a,p as o}from"./framework-CoXA0nY6.js";import{c as s}from"./infrastructure-Djv3I7gr.js";import{o as c}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as l,Qn as u,Sy as d,ir as f,nr as p,qm as m,sI as h,to as g,tr as _,vr as v}from"./ui-components-DSSaN2w_.js";import{r as y}from"./index-DTdi5Ufa.js";import{i as b,n as x,t as S}from"./getIcon-BKYKFGnN.js";import{t as C}from"./MetadataFormDialog-Bf5wwigQ.js";var w=e(t(),1),T=r(),E=class extends w.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[MetadataDetailPage] Schema rendering error:`,e,t.componentStack)}render(){return this.state.hasError?(0,T.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/5 p-6 text-center`,"data-testid":`schema-render-error`,children:[(0,T.jsx)(g,{className:`h-8 w-8 mx-auto mb-3 text-destructive`}),(0,T.jsxs)(`p`,{className:`text-sm font-medium text-destructive`,children:[`Failed to render `,this.props.fallbackLabel||`detail`,` page`]}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:this.state.error?.message||`An unexpected error occurred.`})]}):this.props.children}};function D({schema:e}){let t=e.body||[];return t.length===0?null:(0,T.jsx)(`div`,{className:`flex flex-col gap-6`,"data-testid":`schema-detail-content`,children:t.map((e,t)=>(0,T.jsx)(a,{schema:e},e?.id||t))})}function O(){let e=i(),{appName:t,metadataType:r,itemName:a}=n(),g=t?`/apps/${t}`:``,O=y(),{refresh:k}=o(),{user:A}=s(),j=A?.role===`admin`,M=r?b(r):void 0,[N,P]=(0,w.useState)(null),[F,I]=(0,w.useState)(!0),[L,R]=(0,w.useState)(!1),[z,B]=(0,w.useState)(!1),V=(0,w.useRef)(O);V.current=O;let H=(0,w.useRef)(M?.label);H.current=M?.label;let U=(0,w.useCallback)(async()=>{let e=V.current;if(!(!e||!r||!a)){I(!0);try{P((await e.getItems(r)).find(e=>String(e.name)===a&&!e._deleted)??null)}catch{c.error(`Failed to load ${H.current??r}`)}finally{I(!1)}}},[r,a]);(0,w.useEffect)(()=>{U()},[U]);let W=(0,w.useCallback)(async e=>{let t=V.current;if(!(!t||!r||!a)){B(!0);try{let n={...N,...e};await t.saveMetadataItem(r,a,n),await k(),await U(),c.success(`${H.current??`Item`} "${a}" updated`)}catch{throw c.error(`Failed to update "${a}"`),Error(`Failed to save ${H.current??`item`} "${a}"`)}finally{B(!1)}}},[r,a,N,k,U]),G=M?.customRoute?`${g}${M.customRoute}`:`${g}/system/metadata/${r??``}`;if(!M)return(0,T.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,T.jsx)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${g}/system`),children:`Back to System Settings`})]})});if(M.pageSchemaFactory){let t=M.pageSchemaFactory(a,N),n=S(M.icon);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(h,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(n,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:t.title||a}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` · `,(0,T.jsx)(`span`,{className:`font-mono text-xs`,children:a})]})]})]})}),(0,T.jsx)(E,{fallbackLabel:M.label,children:(0,T.jsx)(D,{schema:t})})]})}let K=S(M.icon),q=M.editable!==!1&&j,J=M.formFields??x,Y=M.detailComponent;return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(h,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(K,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:F?`Loading...`:String(N?.label??N?.name??a)}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` Details`]})]})]}),q&&!F&&N&&(0,T.jsxs)(v,{variant:`outline`,onClick:()=>R(!0),disabled:z,"data-testid":`detail-edit-btn`,children:[(0,T.jsx)(m,{className:`mr-2 h-4 w-4`}),`Edit`]})]}),F&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`detail-loading`,children:[(0,T.jsx)(d,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading...`]}),!F&&!N&&(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`detail-not-found`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[M.label,` "`,a,`" not found.`]}),(0,T.jsxs)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(G),children:[`Back to `,M.pluralLabel]})]}),!F&&N&&(0,T.jsx)(T.Fragment,{children:Y?(0,T.jsx)(Y,{item:N}):(0,T.jsxs)(u,{"data-testid":`detail-card`,children:[(0,T.jsx)(_,{children:(0,T.jsxs)(p,{className:`flex items-center gap-2`,children:[(0,T.jsx)(f,{variant:`secondary`,children:M.label}),String(N.name??``)]})}),(0,T.jsx)(l,{children:(0,T.jsx)(`dl`,{className:`grid gap-3 sm:grid-cols-2`,children:J.map(e=>(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{className:`text-sm font-medium text-muted-foreground`,children:e.label}),(0,T.jsx)(`dd`,{className:`mt-1 text-sm`,children:String(N[e.key]??`—`)})]},e.key))})})]})}),q&&N&&(0,T.jsx)(C,{open:L,onOpenChange:R,mode:`edit`,typeLabel:M.label,formFields:M.formFields,initialValues:N,onSubmit:W})]})}export{O as MetadataDetailPage};
@@ -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{Cy as r,Gn as i,Jn as a,Kn as o,Un as s,Wn as c,dn as l,fn as u,pt as d,qn as f,wt as p,yr as m}from"./ui-components-B7mlp0en.js";import{n as h}from"./getIcon-DF6zJOtU.js";var g=e(t(),1),_=n();function v({open:e,onOpenChange:t,mode:n,typeLabel:v,formFields:y,initialValues:b,onSubmit:x}){let S=y??h,C=n===`edit`,[w,T]=(0,g.useState)({}),[E,D]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(e){let e={};for(let t of S)e[t.key]=String(b?.[t.key]??``);T(e)}},[e,b,S]);let O=(0,g.useCallback)((e,t)=>{T(n=>({...n,[e]:t}))},[]),k=(0,g.useCallback)(async()=>{D(!0);try{await x(w),t(!1)}catch{}finally{D(!1)}},[w,x,t]),A=S.filter(e=>e.required).every(e=>(w[e.key]??``).trim().length>0);return(0,_.jsx)(s,{open:e,onOpenChange:t,children:(0,_.jsxs)(c,{className:`sm:max-w-[480px]`,"data-testid":`metadata-form-dialog`,children:[(0,_.jsxs)(f,{children:[(0,_.jsx)(a,{children:C?`Edit ${v}`:`New ${v}`}),(0,_.jsx)(i,{children:C?`Update the ${v.toLowerCase()} details below.`:`Fill in the details to create a new ${v.toLowerCase()}.`})]}),(0,_.jsx)(`div`,{className:`space-y-4 py-4`,children:S.map(e=>{let t=E||C&&e.disabledOnEdit===!0,n=w[e.key]??``,r=`metadata-field-${e.key}`;return(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsxs)(u,{htmlFor:r,children:[e.label,e.required&&(0,_.jsx)(`span`,{className:`text-destructive ml-1`,"aria-hidden":`true`,children:`*`})]}),e.type===`textarea`?(0,_.jsx)(d,{id:r,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`select`&&e.options?(0,_.jsxs)(`select`,{id:r,value:n,onChange:t=>O(e.key,t.target.value),disabled:t,"aria-required":e.required?!0:void 0,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,"data-testid":`metadata-field-${e.key}`,children:[(0,_.jsx)(`option`,{value:``,children:`Select...`}),e.options.map(e=>(0,_.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):e.type===`number`?(0,_.jsx)(l,{id:r,type:`number`,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`boolean`?(0,_.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,_.jsx)(p,{id:r,checked:n===`true`,onCheckedChange:t=>O(e.key,String(t)),disabled:t,"data-testid":`metadata-field-${e.key}`}),(0,_.jsx)(u,{htmlFor:r,className:`text-sm text-muted-foreground cursor-pointer`,children:n===`true`?`Yes`:`No`})]}):(0,_.jsx)(l,{id:r,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`})]},e.key)})}),(0,_.jsxs)(o,{children:[(0,_.jsx)(m,{variant:`outline`,onClick:()=>t(!1),disabled:E,"data-testid":`metadata-form-cancel-btn`,children:`Cancel`}),(0,_.jsxs)(m,{onClick:k,disabled:E||!A,"data-testid":`metadata-form-submit-btn`,children:[E&&(0,_.jsx)(r,{className:`mr-2 h-4 w-4 animate-spin`}),C?`Save`:`Create`]})]})]})})}export{v 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{Ct as r,Gn as i,Hn as a,Kn as o,Sy as s,Un as c,Wn as l,dn as u,ft as d,qn as f,un as p,vr as m}from"./ui-components-DSSaN2w_.js";import{n as h}from"./getIcon-BKYKFGnN.js";var g=e(t(),1),_=n();function v({open:e,onOpenChange:t,mode:n,typeLabel:v,formFields:y,initialValues:b,onSubmit:x}){let S=y??h,C=n===`edit`,[w,T]=(0,g.useState)({}),[E,D]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(e){let e={};for(let t of S)e[t.key]=String(b?.[t.key]??``);T(e)}},[e,b,S]);let O=(0,g.useCallback)((e,t)=>{T(n=>({...n,[e]:t}))},[]),k=(0,g.useCallback)(async()=>{D(!0);try{await x(w),t(!1)}catch{}finally{D(!1)}},[w,x,t]),A=S.filter(e=>e.required).every(e=>(w[e.key]??``).trim().length>0);return(0,_.jsx)(a,{open:e,onOpenChange:t,children:(0,_.jsxs)(c,{className:`sm:max-w-[480px]`,"data-testid":`metadata-form-dialog`,children:[(0,_.jsxs)(o,{children:[(0,_.jsx)(f,{children:C?`Edit ${v}`:`New ${v}`}),(0,_.jsx)(l,{children:C?`Update the ${v.toLowerCase()} details below.`:`Fill in the details to create a new ${v.toLowerCase()}.`})]}),(0,_.jsx)(`div`,{className:`space-y-4 py-4`,children:S.map(e=>{let t=E||C&&e.disabledOnEdit===!0,n=w[e.key]??``,i=`metadata-field-${e.key}`;return(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsxs)(u,{htmlFor:i,children:[e.label,e.required&&(0,_.jsx)(`span`,{className:`text-destructive ml-1`,"aria-hidden":`true`,children:`*`})]}),e.type===`textarea`?(0,_.jsx)(d,{id:i,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`select`&&e.options?(0,_.jsxs)(`select`,{id:i,value:n,onChange:t=>O(e.key,t.target.value),disabled:t,"aria-required":e.required?!0:void 0,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,"data-testid":`metadata-field-${e.key}`,children:[(0,_.jsx)(`option`,{value:``,children:`Select...`}),e.options.map(e=>(0,_.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):e.type===`number`?(0,_.jsx)(p,{id:i,type:`number`,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`boolean`?(0,_.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,_.jsx)(r,{id:i,checked:n===`true`,onCheckedChange:t=>O(e.key,String(t)),disabled:t,"data-testid":`metadata-field-${e.key}`}),(0,_.jsx)(u,{htmlFor:i,className:`text-sm text-muted-foreground cursor-pointer`,children:n===`true`?`Yes`:`No`})]}):(0,_.jsx)(p,{id:i,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`})]},e.key)})}),(0,_.jsxs)(i,{children:[(0,_.jsx)(m,{variant:`outline`,onClick:()=>t(!1),disabled:E,"data-testid":`metadata-form-cancel-btn`,children:`Cancel`}),(0,_.jsxs)(m,{onClick:k,disabled:E||!A,"data-testid":`metadata-form-submit-btn`,children:[E&&(0,_.jsx)(s,{className:`mr-2 h-4 w-4 animate-spin`}),C?`Save`:`Create`]})]})]})})}export{v as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{c as o}from"./infrastructure-Djv3I7gr.js";import{o as s}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as c,Ld as l,Qn as u,Sy as d,ir as ee,lm as te,po as f,qm as p,sI as m,un as ne,vr as h}from"./ui-components-DSSaN2w_.js";import{r as re}from"./index-DTdi5Ufa.js";import{i as g,t as ie}from"./getIcon-BKYKFGnN.js";import{t as ae}from"./MetadataFormDialog-Bf5wwigQ.js";var _=e(t(),1),v=r();function y({items:e,columns:t,editable:n=!1,saving:r=!1,deletingName:i=null,typeLabel:a=`item`,rowActions:o=[],onItemClick:s,onEdit:c,onDelete:l}){return(0,v.jsx)(`div`,{className:`rounded-lg border bg-card`,"data-testid":`metadata-grid`,children:(0,v.jsx)(`div`,{className:`overflow-x-auto`,children:(0,v.jsxs)(`table`,{className:`w-full text-sm`,"aria-label":`${a} list`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{className:`border-b bg-muted/50`,children:[t.map(e=>(0,v.jsx)(`th`,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,style:e.width?{width:e.width}:void 0,children:e.label},e.key)),n&&(0,v.jsx)(`th`,{className:`px-4 py-3 text-right font-medium text-muted-foreground w-24`,children:`Actions`})]})}),(0,v.jsx)(`tbody`,{children:e.map(e=>{let u=String(e.name??``);return(0,v.jsxs)(`tr`,{className:`border-b last:border-0 hover:bg-accent/50 cursor-pointer transition-colors`,"data-testid":`metadata-item-${u}`,onClick:()=>s?.(u),children:[t.map(t=>{let n=String(e[t.key]??`—`);return(0,v.jsx)(`td`,{className:`px-4 py-3 truncate max-w-[200px]`,title:n,children:n},t.key)}),n&&(0,v.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,v.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[o.map(t=>(0,v.jsx)(h,{variant:t.variant??`ghost`,size:`icon`,title:t.label,"aria-label":t.label,onClick:n=>{n.stopPropagation(),t.handler?.(e)},"data-testid":`row-action-${t.key}-${u}`,children:(0,v.jsx)(`span`,{className:`text-xs`,children:t.label.charAt(0)})},t.key)),(0,v.jsx)(h,{variant:`ghost`,size:`icon`,title:`Edit ${a}`,onClick:t=>{t.stopPropagation(),c?.(e)},disabled:r,"data-testid":`edit-${u}-btn`,children:(0,v.jsx)(p,{className:`h-4 w-4`})}),(0,v.jsx)(h,{variant:`ghost`,size:`icon`,title:i===u?`Click again to confirm`:`Delete ${a}`,onClick:e=>{e.stopPropagation(),l?.(u)},disabled:r,"data-testid":`delete-${u}-btn`,children:(0,v.jsx)(f,{className:`h-4 w-4 ${i===u?`text-destructive`:``}`})})]})})]},u)})})]})})})}function b(){let e=i(),{appName:t,metadataType:r}=n(),b=t?`/apps/${t}`:``,x=re(),{refresh:S}=a(),{user:C}=o(),w=C?.role===`admin`,T=r?g(r):void 0,[E,D]=(0,_.useState)([]),[O,k]=(0,_.useState)(!0),[A,oe]=(0,_.useState)(``),[j,M]=(0,_.useState)(!1),[N,P]=(0,_.useState)(null),[F,I]=(0,_.useState)(!1),[L,R]=(0,_.useState)(`create`),[z,B]=(0,_.useState)(null),V=(0,_.useCallback)(async()=>{if(!(!x||!r)){k(!0);try{D((await x.getItems(r)).filter(e=>!e._deleted))}catch{s.error(`Failed to load ${T?.pluralLabel??r}`)}finally{k(!1)}}},[x,r,T?.pluralLabel]);(0,_.useEffect)(()=>{V()},[V]);let H=(0,_.useMemo)(()=>{if(!A.trim())return E;let e=A.toLowerCase();return E.filter(t=>{let n=String(t.name??``).toLowerCase(),r=String(t.label??``).toLowerCase();return n.includes(e)||r.includes(e)})},[E,A]),U=(0,_.useCallback)(async e=>{if(!(!x||!r))if(N===e){M(!0);try{await x.deleteMetadataItem(r,e),D(t=>t.filter(t=>t.name!==e)),await S(),s.success(`${T?.label??`Item`} "${e}" deleted`)}catch{s.error(`Failed to delete "${e}"`)}finally{M(!1),P(null)}}else P(e)},[x,r,N,T?.label,S]),W=(0,_.useCallback)(()=>{B(null),R(`create`),I(!0)},[]),G=(0,_.useCallback)(e=>{B(e),R(`edit`),I(!0)},[]),K=(0,_.useCallback)(async e=>{if(!x||!r)return;let t=e.name??String(z?.name??``);if(t){M(!0);try{let n=L===`edit`?{...z,...e}:{...e};await x.saveMetadataItem(r,t,n),await S(),await V(),s.success(L===`edit`?`${T?.label??`Item`} "${t}" updated`:`${T?.label??`Item`} "${t}" created`)}catch{throw s.error(L===`edit`?`Failed to update "${t}"`:`Failed to create "${t}"`),Error(`Failed to save ${T?.label??`item`} "${t}"`)}finally{M(!1)}}},[x,r,z,L,T?.label,S,V]);if(!T)return(0,v.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:(0,v.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,v.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,v.jsx)(h,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${b}/system`),children:`Back to System Settings`})]})});let q=ie(T.icon),J=T.editable!==!1&&w,Y=T.listComponent;if(Y)return(0,v.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,v.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,v.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,v.jsx)(h,{variant:`ghost`,size:`icon`,onClick:()=>e(`${b}/system`),"data-testid":`back-to-hub-btn`,children:(0,v.jsx)(m,{className:`h-4 w-4`})}),(0,v.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,v.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,v.jsxs)(`div`,{className:`min-w-0`,children:[(0,v.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:T.pluralLabel}),(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:T.description})]})]})}),(0,v.jsx)(Y,{config:T,basePath:b,metadataType:r,isAdmin:w})]});let X=(T.actions??[]).filter(e=>e.scope===`page`),Z=(T.actions??[]).filter(e=>e.scope===`row`),Q=T.listMode??`card`,$=Q===`grid`||Q===`table`,se=T.columns??[{key:`name`,label:`Name`},{key:`label`,label:`Label`}];return(0,v.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,v.jsx)(h,{variant:`ghost`,size:`icon`,onClick:()=>e(`${b}/system`),"data-testid":`back-to-hub-btn`,children:(0,v.jsx)(m,{className:`h-4 w-4`})}),(0,v.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,v.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,v.jsxs)(`div`,{className:`min-w-0`,children:[(0,v.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:T.pluralLabel}),(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:T.description})]})]}),J&&(0,v.jsxs)(h,{onClick:W,"data-testid":`create-metadata-btn`,children:[(0,v.jsx)(te,{className:`mr-2 h-4 w-4`}),`New `,T.label]}),X.length>0&&(0,v.jsx)(`div`,{className:`flex items-center gap-2`,children:X.map(e=>(0,v.jsx)(h,{variant:e.variant??`outline`,onClick:()=>e.handler?.(),"data-testid":`page-action-${e.key}`,children:e.label},e.key))})]}),(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,v.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,v.jsxs)(`label`,{htmlFor:`metadata-search`,className:`sr-only`,children:[`Search `,T.pluralLabel.toLowerCase()]}),(0,v.jsx)(l,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,v.jsx)(ne,{id:`metadata-search`,placeholder:`Search ${T.pluralLabel.toLowerCase()}...`,value:A,onChange:e=>oe(e.target.value),className:`pl-8`,"data-testid":`metadata-search-input`})]}),(0,v.jsxs)(ee,{variant:`secondary`,"data-testid":`metadata-count-badge`,children:[H.length,` `,T.pluralLabel.toLowerCase()]})]}),O&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-loading`,children:[(0,v.jsx)(d,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading `,T.pluralLabel.toLowerCase(),`...`]}),j&&(0,v.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-saving`,children:[(0,v.jsx)(d,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Saving...`]}),!O&&H.length===0&&(0,v.jsx)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`metadata-empty`,children:(0,v.jsxs)(`p`,{children:[`No `,T.pluralLabel.toLowerCase(),` found.`]})}),!O&&H.length>0&&!$&&(0,v.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:H.map(t=>{let n=String(t.name??``),i=String(t.label??t.name??``),a=String(t.description??``);return(0,v.jsx)(u,{className:`transition-colors hover:bg-accent/50 cursor-pointer`,"data-testid":`metadata-item-${n}`,onClick:()=>e(`${b}/system/metadata/${r}/${n}`),children:(0,v.jsxs)(c,{className:`flex items-center justify-between p-4`,children:[(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsx)(`p`,{className:`font-medium truncate`,children:i}),(0,v.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:n}),a&&(0,v.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 truncate`,children:a})]}),J&&(0,v.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 ml-2`,children:[Z.map(e=>(0,v.jsx)(h,{variant:e.variant??`ghost`,size:`icon`,title:e.label,onClick:n=>{n.stopPropagation(),e.handler?.(t)},"data-testid":`row-action-${e.key}-${n}`,children:(0,v.jsx)(`span`,{className:`text-xs`,children:e.label.charAt(0)})},e.key)),(0,v.jsx)(h,{variant:`ghost`,size:`icon`,title:`Edit ${T.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),G(t)},disabled:j,"data-testid":`edit-${n}-btn`,children:(0,v.jsx)(p,{className:`h-4 w-4`})}),(0,v.jsx)(h,{variant:`ghost`,size:`icon`,title:N===n?`Click again to confirm`:`Delete ${T.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),U(n)},disabled:j,"data-testid":`delete-${n}-btn`,children:(0,v.jsx)(f,{className:`h-4 w-4 ${N===n?`text-destructive`:``}`})})]})]})},n)})}),!O&&H.length>0&&$&&(0,v.jsx)(y,{items:H,columns:se,editable:J,saving:j,deletingName:N,typeLabel:T.label.toLowerCase(),rowActions:Z,onItemClick:t=>e(`${b}/system/metadata/${r}/${t}`),onEdit:G,onDelete:U}),J&&(0,v.jsx)(ae,{open:F,onOpenChange:I,mode:L,typeLabel:T.label,formFields:T.formFields,initialValues:z??void 0,onSubmit:K})]})}export{b as MetadataManagerPage};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-B5ROGaJH.css"])))=>i.map(i=>d[i]);
2
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,p as a,t as o}from"./vendor-react-B1k2FF9f.js";import{D as s,f as c,p as l}from"./framework-CoXA0nY6.js";import{o as u}from"./vendor-ui-utils-Dyl9EYZi.js";import{Gt as d,Jm as f,Jt as p,Kt as m,Yt as h,at as g,cT as _,it as v,ot as y,qt as b}from"./ui-components-B7mlp0en.js";import{o as x,s as S}from"./index-CPatxDwz.js";var C=t(n(),1),w=o();function T({open:e,onOpenChange:t,title:n,description:r,schema:i,onSchemaChange:a,collection:o,recordName:s,children:l}){let f=c(),g=(0,C.useRef)(i);g.current=i;let _=(0,C.useCallback)(async e=>{try{if(f)return await f.update(o,s,e),!0}catch(e){console.warn(`[DesignDrawer] Auto-save failed:`,e)}return!1},[f,o,s]),v=(0,C.useCallback)(async e=>{a(e),await _(e)},[a,_]);return(0,C.useEffect)(()=>{if(!e)return;let t=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),_(g.current).then(e=>{e&&u.success(`${n} saved`)}))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,_,n]),(0,w.jsx)(d,{open:e,onOpenChange:t,modal:!1,children:(0,w.jsxs)(m,{side:`right`,hideOverlay:!0,className:`w-full sm:w-[540px] sm:max-w-[540px] lg:w-[640px] lg:max-w-[640px] p-0 flex flex-col`,"data-testid":`design-drawer`,children:[(0,w.jsxs)(p,{className:`px-4 py-3 border-b shrink-0`,children:[(0,w.jsx)(h,{children:n}),(0,w.jsx)(b,{className:r?``:`sr-only`,children:r||`Visual editor — configure and preview ${n}`})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-auto p-4`,children:l(i,v)})]})})}var E=e({PageView:()=>O}),D=(0,C.lazy)(()=>i(()=>import(`./src-D5NTzWsi.js`).then(e=>e.t).then(e=>({default:e.PageCanvasEditor})),__vite__mapDeps([0])));function O(){let{pageName:e}=r(),[t]=a(),{showDebug:n}=S(),[i,o]=(0,C.useState)(!1),{pages:c}=l(),u=c?.find(t=>t.name===e),[d,p]=(0,C.useState)(null),m=(0,C.useCallback)(()=>{p(u),o(!0)},[u]),h=(0,C.useCallback)(e=>{o(e)},[]);if(!u)return(0,w.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,w.jsxs)(v,{children:[(0,w.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,w.jsx)(_,{className:`h-6 w-6 text-muted-foreground`})}),(0,w.jsx)(y,{children:`Page Not Found`}),(0,w.jsxs)(g,{children:[`The page "`,e,`" could not be found. It may have been removed or renamed.`]})]})});let b=Object.fromEntries(t.entries()),E=i&&d?d:u;return(0,w.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,w.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative group`,children:[(0,w.jsx)(`div`,{className:`absolute top-1.5 sm:top-2 right-1.5 sm:right-2 z-50 flex items-center gap-1.5 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,children:(0,w.jsxs)(`button`,{type:`button`,onClick:m,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-button`,children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5`}),`Edit`]})}),(0,w.jsx)(s,{schema:{...E,type:E.type||`page`,context:{...E.context,params:b}}})]}),(0,w.jsx)(x,{open:n,sections:[{title:`Page Configuration`,data:E}]}),(0,w.jsx)(T,{open:i,onOpenChange:h,title:`Edit Page: ${u.label||u.title||e}`,schema:d||u,onSchemaChange:p,collection:`sys_page`,recordName:e,children:(e,t)=>(0,w.jsx)(C.Suspense,{fallback:(0,w.jsx)(`div`,{className:`p-4 text-muted-foreground`,children:`Loading editor…`}),children:(0,w.jsx)(D,{schema:e,onChange:t})})})]})}export{E as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-BL3SEdAz.css"])))=>i.map(i=>d[i]);
2
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,p as a,t as o}from"./vendor-react-B1k2FF9f.js";import{D as s,f as c,p as l}from"./framework-CoXA0nY6.js";import{o as u}from"./vendor-ui-utils-Dyl9EYZi.js";import{Gt as d,Jt as f,Kt as p,Wt as m,at as h,it as g,qm as _,qt as v,rt as y,sT as b}from"./ui-components-DSSaN2w_.js";import{o as x,s as S}from"./index-DTdi5Ufa.js";var C=t(n(),1),w=o();function T({open:e,onOpenChange:t,title:n,description:r,schema:i,onSchemaChange:a,collection:o,recordName:s,children:l}){let h=c(),g=(0,C.useRef)(i);g.current=i;let _=(0,C.useCallback)(async e=>{try{if(h)return await h.update(o,s,e),!0}catch(e){console.warn(`[DesignDrawer] Auto-save failed:`,e)}return!1},[h,o,s]),y=(0,C.useCallback)(async e=>{a(e),await _(e)},[a,_]);return(0,C.useEffect)(()=>{if(!e)return;let t=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),_(g.current).then(e=>{e&&u.success(`${n} saved`)}))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,_,n]),(0,w.jsx)(m,{open:e,onOpenChange:t,modal:!1,children:(0,w.jsxs)(d,{side:`right`,hideOverlay:!0,className:`w-full sm:w-[540px] sm:max-w-[540px] lg:w-[640px] lg:max-w-[640px] p-0 flex flex-col`,"data-testid":`design-drawer`,children:[(0,w.jsxs)(v,{className:`px-4 py-3 border-b shrink-0`,children:[(0,w.jsx)(f,{children:n}),(0,w.jsx)(p,{className:r?``:`sr-only`,children:r||`Visual editor — configure and preview ${n}`})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-auto p-4`,children:l(i,y)})]})})}var E=e({PageView:()=>O}),D=(0,C.lazy)(()=>i(()=>import(`./src-DwuebCF9.js`).then(e=>e.t).then(e=>({default:e.PageCanvasEditor})),__vite__mapDeps([0])));function O(){let{pageName:e}=r(),[t]=a(),{showDebug:n}=S(),[i,o]=(0,C.useState)(!1),{pages:c}=l(),u=c?.find(t=>t.name===e),[d,f]=(0,C.useState)(null),p=(0,C.useCallback)(()=>{f(u),o(!0)},[u]),m=(0,C.useCallback)(e=>{o(e)},[]);if(!u)return(0,w.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,w.jsxs)(y,{children:[(0,w.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,w.jsx)(b,{className:`h-6 w-6 text-muted-foreground`})}),(0,w.jsx)(h,{children:`Page Not Found`}),(0,w.jsxs)(g,{children:[`The page "`,e,`" could not be found. It may have been removed or renamed.`]})]})});let v=Object.fromEntries(t.entries()),E=i&&d?d:u;return(0,w.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,w.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative group`,children:[(0,w.jsx)(`div`,{className:`absolute top-1.5 sm:top-2 right-1.5 sm:right-2 z-50 flex items-center gap-1.5 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,children:(0,w.jsxs)(`button`,{type:`button`,onClick:p,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-button`,children:[(0,w.jsx)(_,{className:`h-3.5 w-3.5`}),`Edit`]})}),(0,w.jsx)(s,{schema:{...E,type:E.type||`page`,context:{...E.context,params:v}}})]}),(0,w.jsx)(x,{open:n,sections:[{title:`Page Configuration`,data:E}]}),(0,w.jsx)(T,{open:i,onOpenChange:m,title:`Edit Page: ${u.label||u.title||e}`,schema:d||u,onSchemaChange:f,collection:`sys_page`,recordName:e,children:(e,t)=>(0,w.jsx)(C.Suspense,{fallback:(0,w.jsx)(`div`,{className:`p-4 text-muted-foreground`,children:`Loading editor…`}),children:(0,w.jsx)(D,{schema:e,onChange:t})})})]})}export{E as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{c as r,r as i}from"./infrastructure-Djv3I7gr.js";import{$n as a,FA as o,Qn as s,ar as c,cr as l,dn as u,er as d,fy as f,ir as p,lr as m,na as h,nr as g,or as _,sr as v,tr as y,un as b,vr as x,wA as S}from"./ui-components-DSSaN2w_.js";var C=e(t(),1),w=n();function T(){let{user:e,updateUser:t,isLoading:n}=r(),[T,E]=(0,C.useState)(e?.name??``),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null);return e?(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-2xl`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Profile`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage your account settings`})]}),(0,w.jsx)(s,{children:(0,w.jsx)(a,{className:`pt-6`,children:(0,w.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,w.jsxs)(c,{className:`h-16 w-16`,children:[(0,w.jsx)(v,{src:e.image??void 0,alt:e.name??`User`}),(0,w.jsx)(_,{className:`text-lg bg-primary text-primary-foreground`,children:i(e)})]}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsx)(`p`,{className:`text-lg font-semibold truncate`,children:e.name??`User`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground truncate`,children:e.email}),(0,w.jsx)(p,{variant:`secondary`,className:`mt-1`,children:e.role??`member`})]})]})})}),(0,w.jsxs)(s,{children:[(0,w.jsxs)(y,{children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(h,{className:`h-4 w-4 text-muted-foreground`}),(0,w.jsx)(g,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,w.jsx)(d,{children:`Update your name and view account details`})]}),(0,w.jsx)(a,{children:(0,w.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),A(null),O(!1);try{await t({name:T}),O(!0)}catch(e){A(e instanceof Error?e.message:String(e))}},className:`space-y-4`,children:[k&&(0,w.jsxs)(l,{variant:`destructive`,children:[(0,w.jsx)(o,{className:`h-4 w-4`}),(0,w.jsx)(m,{children:k})]}),D&&(0,w.jsxs)(l,{children:[(0,w.jsx)(S,{className:`h-4 w-4 text-green-600`}),(0,w.jsx)(m,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(u,{htmlFor:`profile-name`,children:`Name`}),(0,w.jsx)(b,{id:`profile-name`,type:`text`,value:T,onChange:e=>E(e.target.value),required:!0,"aria-required":`true`,disabled:n})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(u,{htmlFor:`profile-email`,children:`Email`}),(0,w.jsx)(b,{id:`profile-email`,type:`email`,value:e.email,disabled:!0,className:`bg-muted text-muted-foreground`}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Email cannot be changed.`})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(u,{children:`Role`}),(0,w.jsx)(b,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,w.jsx)(x,{type:`submit`,disabled:n,className:`w-full sm:w-auto`,children:n?`Saving...`:`Save Changes`})]})})]}),(0,w.jsx)(s,{children:(0,w.jsxs)(y,{children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(f,{className:`h-4 w-4 text-muted-foreground`}),(0,w.jsx)(g,{className:`text-base sm:text-lg`,children:`Change Password`})]}),(0,w.jsx)(d,{children:`To change your password, use the password reset flow from the login page.`})]})})]}):null}export{T as ProfilePage};
@@ -0,0 +1 @@
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,t as i,u as a}from"./vendor-react-B1k2FF9f.js";import{a as o,g as s}from"./framework-CoXA0nY6.js";import{c,u as l}from"./infrastructure-Djv3I7gr.js";import{o as u}from"./vendor-ui-utils-Dyl9EYZi.js";import{$i as d,$t as f,DD as p,Gn as m,Hn as h,Kn as g,Qt as _,Un as v,Wn as y,Zt as b,_r as x,at as S,dn as C,dr as w,en as T,fr as E,ft as D,gr as O,hr as k,it as ee,mr as A,pr as j,qn as M,rt as te,tn as N,un as P,ur as F,vr as I}from"./ui-components-DSSaN2w_.js";import{n as ne}from"./utils-DMMB8Xfh.js";import{a as re,o as ie}from"./plugins-views-Bi5okDge.js";import{i as ae,o as oe,s as se}from"./index-DTdi5Ufa.js";var L=t(n(),1),R=i(),z=(0,L.createContext)(void 0);function B({children:e}){let[t,n]=(0,L.useState)(`home`),[r,i]=(0,L.useState)(),[a,o]=(0,L.useState)(),s=(0,L.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,R.jsx)(z.Provider,{value:s,children:e})}function V(){return(0,L.useContext)(z)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function ce(e){let{setRecordTitle:t}=V();(0,L.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}function H(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,L.useState)(`disconnected`),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)([]),[p,m]=(0,L.useState)(null),h=(0,L.useRef)(null),g=(0,L.useRef)(0),_=(0,L.useRef)(null),v=(0,L.useRef)(new Map),y=(0,L.useRef)([]),b=(0,L.useRef)(!0),x=(0,L.useRef)(!1),S=(0,L.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,L.useCallback)(e=>{for(;y.current.length>0;){let t=y.current.shift(),r={type:t.type,channel:n,data:t.data,timestamp:new Date().toISOString()};e.send(JSON.stringify(r))}},[n]),w=(0,L.useCallback)(()=>{if(typeof WebSocket>`u`){m(Error(`WebSocket is not available in this environment`)),c(`error`);return}if(!t){m(Error(`WebSocket URL is required`)),c(`error`);return}try{let e=new URL(t);if(e.protocol!==`ws:`&&e.protocol!==`wss:`){m(Error(`WebSocket URL must use ws: or wss: protocol`)),c(`error`);return}}catch{m(Error(`Invalid WebSocket URL`)),c(`error`);return}h.current&&=(x.current=!0,h.current.close(),null),x.current=!1,c(`connecting`),m(null);let e=o?`${t}?token=${encodeURIComponent(o)}&channel=${encodeURIComponent(n)}`:`${t}?channel=${encodeURIComponent(n)}`,s;try{s=new WebSocket(e)}catch(e){if(!b.current)return;m(e instanceof Error?e:Error(`Failed to create WebSocket connection`)),c(`error`);return}h.current=s,s.onopen=()=>{b.current&&(c(`connected`),m(null),g.current=0,C(s))},s.onmessage=e=>{if(b.current)try{let t=JSON.parse(String(e.data));if(t.channel!==n)return;u(t),f(e=>[...e,t]);let r=v.current.get(t.type);r&&r.forEach(e=>e(t.data))}catch{}},s.onerror=()=>{b.current&&(m(Error(`WebSocket connection error`)),c(`error`))},s.onclose=()=>{if(b.current){if(h.current=null,x.current){c(`disconnected`);return}if(r&&g.current<a){c(`reconnecting`);let e=Math.min(i*2**g.current,3e4);g.current+=1,_.current=setTimeout(()=>{b.current&&w()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,C]),T=(0,L.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,L.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,L.useCallback)((e,t)=>{let r=h.current;if(r&&r.readyState===WebSocket.OPEN){let i={type:e,channel:n,data:t,timestamp:new Date().toISOString()};r.send(JSON.stringify(i))}else y.current.push({type:e,data:t})},[n]),O=(0,L.useCallback)((e,t)=>(v.current.has(e)||v.current.set(e,new Set),v.current.get(e).add(t),()=>{let n=v.current.get(e);n&&(n.delete(t),n.size===0&&v.current.delete(e))}),[]);return(0,L.useEffect)(()=>(b.current=!0,t&&w(),()=>{b.current=!1,S(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:D,subscribe:O,disconnect:T,reconnect:E,error:p}}var U=0;function W(){return U+=1,`conflict-${Date.now()}-${U}`}var G=0;function K(){return G+=1,`ver-${Date.now()}-${G}`}function q(e,t,n){let[r,i]=(0,L.useState)([]),[a,o]=(0,L.useState)([]);return{versions:r,currentVersion:(0,L.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,L.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:K(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,L.useCallback)((n,r,a)=>{o(o=>{let s=o.find(e=>e.id===n);if(!s)return o;let c;switch(r){case`local`:c=s.localValue;break;case`remote`:c=s.remoteValue;break;case`merge`:c=a??s.localValue;break}return i(n=>{let i=n.length===0?1:n[n.length-1].version+1,a={id:K(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:{[s.field]:{before:s.baseValue,after:c}},message:`Resolved conflict on "${s.field}" using ${r} strategy`};return[...n,a]}),o.filter(e=>e.id!==n)})},[e,t]),resolveAllConflicts:(0,L.useCallback)(n=>{o(r=>{if(r.length===0)return r;let a={};for(let e of r)a[e.field]={before:e.baseValue,after:n===`local`?e.localValue:e.remoteValue};return i(r=>{let i=r.length===0?1:r[r.length-1].version+1,o={id:K(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:a,message:`Resolved all conflicts using ${n} strategy`};return[...r,o]}),[]})},[e,t]),revertToVersion:(0,L.useCallback)(n=>{let a=r.findIndex(e=>e.id===n);if(a===-1)return null;let o={};for(let e=0;e<=a;e++){let t=r[e];for(let[e,n]of Object.entries(t.changes))o[e]=n.after}let s={},c={};for(let e of r)for(let[t,n]of Object.entries(e.changes))c[t]=n.after;for(let[e,t]of Object.entries(o))c[e]!==t&&(s[e]={before:c[e],after:t});return Object.keys(s).length>0&&i(n=>{let i=n.length===0?1:n[n.length-1].version+1,o={id:K(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:s,message:`Reverted to version ${r[a].version}`};return[...n,o]}),o},[r,e,t]),compareVersions:(0,L.useCallback)((e,t)=>{let n=r.findIndex(t=>t.id===e),i=r.findIndex(e=>e.id===t);if(n===-1||i===-1)return null;let[a,o]=n<i?[n,i]:[i,n],s=e=>{let t={};for(let n=0;n<=e;n++)for(let[e,i]of Object.entries(r[n].changes))t[e]=i.after;return t},c=s(a),l=s(o),u=new Set([...Object.keys(c),...Object.keys(l)]),d={};for(let e of u){let t=c[e],n=l[e];t!==n&&(d[e]={before:t,after:n})}return d},[r]),addConflict:(0,L.useCallback)(e=>{let t={...e,id:W()};o(e=>[...e,t])},[]),clearHistory:(0,L.useCallback)(()=>{i([]),o([])},[])}}var J={sm:24,md:32,lg:40},Y={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function X(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Z({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=J[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,L.useMemo)(()=>e.slice(0,t),[e,t]),u=Math.max(0,e.length-t),d={display:`inline-flex`,alignItems:`center`,flexDirection:`row-reverse`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`},f={width:`${a}px`,height:`${a}px`,borderRadius:`50%`,border:`2px solid #fff`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`${s}px`,fontWeight:600,color:`#fff`,position:`relative`,flexShrink:0,overflow:`hidden`,boxSizing:`border-box`},p={...f,backgroundColor:`#e2e8f0`,color:`#475569`,marginLeft:`-${o}px`},m={position:`absolute`,bottom:`-1px`,right:`-1px`,width:`${c}px`,height:`${c}px`,borderRadius:`50%`,border:`2px solid #fff`,boxSizing:`border-box`},h=(0,L.useMemo)(()=>[...l].reverse(),[l]);return L.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&L.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>L.createElement(`div`,{key:e.userId,style:{...f,backgroundColor:e.color,marginLeft:t>0||u>0?`-${o}px`:`0`},title:`${e.userName} (${e.status})`},e.avatar?L.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):X(e.userName),r&&L.createElement(`span`,{style:{...m,backgroundColor:Y[e.status]}}))))}function Q({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,R.jsx)(F,{open:e.open,onOpenChange:e=>{e||r()},children:(0,R.jsxs)(j,{children:[(0,R.jsxs)(O,{children:[(0,R.jsx)(x,{children:e.options?.title||`Confirm Action`}),(0,R.jsx)(A,{children:e.message})]}),(0,R.jsxs)(k,{children:[(0,R.jsx)(E,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,R.jsx)(w,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function le({state:e,onOpenChange:t}){let[n,r]=(0,L.useState)({}),[i,a]=(0,L.useState)({});(0,L.useEffect)(()=>{if(e.open){let t={};for(let n of e.params)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);r(t),a({})}},[e.open,e.params]);let o=e=>e==null?!0:typeof e==`string`?e.trim()===``:Array.isArray(e)?e.length===0:!1,s=()=>{let r={};for(let t of e.params)t.required&&o(n[t.name])&&(r[t.name]=!0);if(Object.keys(r).length>0){a(r);return}e.resolve?.(n),t(!1)},c=()=>{e.resolve?.(null),t(!1)},l=(e,t)=>{r(n=>({...n,[e]:t})),a(t=>({...t,[e]:!1}))};return(0,R.jsx)(h,{open:e.open,onOpenChange:e=>{e||c()},children:(0,R.jsxs)(v,{children:[(0,R.jsxs)(g,{children:[(0,R.jsx)(M,{children:`Action Parameters`}),(0,R.jsx)(y,{children:`Please provide the required information to continue.`})]}),(0,R.jsx)(`div`,{className:`grid gap-4 py-4`,children:e.params.map(e=>(0,R.jsxs)(`div`,{className:`grid gap-2`,children:[(0,R.jsxs)(C,{htmlFor:e.name,children:[e.label,e.required&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,R.jsxs)(b,{value:n[e.name]??``,onValueChange:t=>l(e.name,t),children:[(0,R.jsx)(T,{id:e.name,className:i[e.name]?`border-destructive`:``,children:(0,R.jsx)(N,{placeholder:e.placeholder||`Select ${e.label}`})}),(0,R.jsx)(_,{children:e.options.map(e=>(0,R.jsx)(f,{value:e.value,children:e.label},e.value))})]}):e.type===`textarea`?(0,R.jsx)(D,{id:e.name,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}):e.type===`number`?(0,R.jsx)(P,{id:e.name,type:`number`,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value===``?void 0:t.target.valueAsNumber),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}):(0,R.jsx)(P,{id:e.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(e.type)?e.type:`text`,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}),i[e.name]&&(0,R.jsxs)(`p`,{className:`text-xs text-destructive`,children:[e.label,` is required`]}),e.helpText&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText})]},e.name))}),(0,R.jsxs)(m,{children:[(0,R.jsx)(I,{variant:`outline`,onClick:c,children:`Cancel`}),(0,R.jsx)(I,{onClick:s,children:`Confirm`})]})]})})}var ue=e({RecordDetailView:()=>$}),de={id:`current-user`,name:`Demo User`};function $({dataSource:e,objects:t,onEdit:n}){let{objectName:i,recordId:f}=r(),{showDebug:m}=se(),{user:h}=c(),g=a(),{t:_}=o(),[v,y]=(0,L.useState)(!0),[b,x]=(0,L.useState)([]),[C,w]=(0,L.useState)([]),[T,E]=(0,L.useState)(0),[D,O]=(0,L.useState)({}),[k,A]=(0,L.useState)(),j=t.find(e=>e.name===i);ce(k);let M=f,[N,P]=(0,L.useState)({open:!1,message:``}),[F,I]=(0,L.useState)({open:!1,params:[]}),z=(0,L.useCallback)((e,t)=>new Promise(n=>{P({open:!0,message:e,options:t,resolve:n})}),[]),B=(0,L.useCallback)(e=>new Promise(t=>{I({open:!0,params:e,resolve:t})}),[]),V=(0,L.useCallback)((e,t)=>{t?.type===`error`?u.error(e):u.success(e)},[]),H=(0,L.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):g(e)},[g]),U=(0,L.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(i,M,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(i,M,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(i,M,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(i,M,r);break}let a=t.refreshAfter===!0;return a&&E(e=>e+1),{success:!0,reload:a}}catch(e){return{success:!1,error:e.message}}},[e,i,M]),W=(0,L.useMemo)(()=>l(),[]),G=(0,L.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=await W(`https://demo.objectstack.ai/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:M,objectName:i,params:e.params??{}})}),r=await n.json().catch(()=>null);if(!n.ok||r&&r.success===!1)return{success:!1,error:r?.error||`Flow "${t}" failed (HTTP ${n.status})`};let a=e.refreshAfter!==!1;return a&&E(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[W,M,i]),K=(0,L.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{};try{let r=e.objectName||i||`global`,a=await W(`https://demo.objectstack.ai/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:M,params:n})}),o=await a.json().catch(()=>null);if(!a.ok||o&&o.success===!1)return{success:!1,error:o?.error||`Action "${t}" failed (HTTP ${a.status})`};let s=e.refreshAfter!==!1;return s&&E(e=>e+1),{success:!0,data:o?.data,reload:s}}catch(e){return{success:!1,error:e.message}}},[W,M,i]),q=(0,L.useMemo)(()=>{if(!j||!t)return[];let e=[];for(let n of t)if(n.name!==j.name)for(let[t,r]of Object.entries(n.fields||{}))r&&(r.type===`lookup`||r.type===`master_detail`)&&(r.reference_to||r.reference)===j.name&&e.push({childObject:n.name,childLabel:n.label||n.name,referenceField:t});return e},[j,t]);(0,L.useEffect)(()=>{if(!e||!M||q.length===0)return;let t=!1;return Promise.all(q.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:M}}).then(e=>({childObject:t,items:Array.isArray(e)?e:e?.data||[]})).catch(e=>(console.warn(`[RecordDetailView] Failed to fetch related ${t}:`,e),{childObject:t,items:[]})))).then(e=>{if(t)return;let n={};for(let{childObject:t,items:r}of e)n[t]=r;O(n)}),()=>{t=!0}},[e,M,q]);let J=h?{id:h.id,name:h.name,avatar:h.image}:de;(0,L.useEffect)(()=>{if(!e||!i||!M)return;let t=`${i}:${M}`;e.find(`sys_presence`,{$filter:{recordId:M}}).then(e=>{e.data?.length&&w(e.data)}).catch(()=>{}),e.find(`sys_comment`,{$filter:{threadId:t},$orderby:{createdAt:`asc`}}).then(e=>{e.data?.length&&x(e.data.map(e=>({id:e.id,type:`comment`,actor:e.author?.name??`Unknown`,actorAvatarUrl:e.author?.avatar,body:e.content,createdAt:e.createdAt,updatedAt:e.updatedAt,parentId:e.parentId,reactions:e.reactions?Object.entries(e.reactions).map(([e,t])=>({emoji:e,count:t.length,reacted:t.includes(J.id)})):void 0})))}).catch(()=>{})},[e,i,M,J]);let Y=(0,L.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:J.name,actorAvatarUrl:`avatar`in J?J.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(x(e=>[...e,n]),e){let r=`${i}:${M}`;e.create(`sys_comment`,{id:n.id,threadId:r,author:J,content:t,mentions:[],createdAt:n.createdAt}).catch(()=>{})}},[J,e,i,M]),X=(0,L.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:J.name,actorAvatarUrl:`avatar`in J?J.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(x(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let a=`${i}:${M}`;e.create(`sys_comment`,{id:r.id,threadId:a,author:J,content:n,mentions:[],createdAt:r.createdAt,parentId:t}).catch(()=>{})}},[J,e,i,M]),ue=(0,L.useCallback)((t,n)=>{x(r=>r.map(r=>{if(r.id!==t)return r;let i=[...r.reactions??[]],a=i.findIndex(e=>e.emoji===n);if(a>=0){let e=i[a];e.reacted?e.count<=1?i.splice(a,1):i[a]={...e,count:e.count-1,reacted:!1}:i[a]={...e,count:e.count+1,reacted:!0}}else i.push({emoji:n,count:1,reacted:!0});let o={...r,reactions:i};return e&&e.update(`sys_comment`,String(t),{$toggleReaction:{emoji:n,userId:J.id}}).catch(()=>{}),o}))},[J.id,e]);(0,L.useEffect)(()=>{y(!0),queueMicrotask(()=>y(!1))},[i,f]);let $=(0,L.useMemo)(()=>{if(!j)return{type:`detail-view`};let e=j.primaryField||Object.keys(j.fields||{}).find(e=>e===`name`||e===`title`),n=j.views?.form?.sections,r=n&&n.length>0?n.map(e=>({title:e.title,collapsible:e.collapsible,defaultCollapsed:e.defaultCollapsed,fields:(e.fields||[]).map(e=>{let t=typeof e==`string`?e:e.name,n=j.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${j.name} definition`),{name:t,label:t};let r=n.reference_to||n.reference;return{name:t,label:n.label||t,type:n.type||`text`,...n.options&&{options:n.options},...r&&{reference_to:r},...n.reference_field&&{reference_field:n.reference_field},...n.currency&&{currency:n.currency}}})})):[{showBorder:!1,fields:Object.keys(j.fields||{}).map(e=>{let t=j.fields[e],n=t.reference_to||t.reference;return{name:e,label:t.label||e,type:t.type||`text`,...t.options&&{options:t.options},...n&&{reference_to:n},...t.reference_field&&{reference_field:t.reference_field},...t.currency&&{currency:t.currency}}})}],i=(()=>{let e=new Set;return(j.actions||[]).filter(t=>t.locations?.includes(`record_header`)?t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0:!1)})(),a=j.views?.detail?.highlightFields??[],o=j.views?.detail?.sectionGroups??j.views?.form?.sectionGroups,s=q.map(({childObject:e,childLabel:n,referenceField:r})=>{let i=t.find(t=>t.name===e);return{title:n,type:`table`,api:e,data:D[e]||[],referenceField:r,icon:i?.icon}});return{type:`detail-view`,objectName:j.name,resourceId:M,showBack:!0,onBack:`history`,showEdit:!0,title:j.label,primaryField:e,sections:r,autoTabs:!0,autoDiscoverRelated:!0,...s.length>0&&{related:s},...a.length>0&&{highlightFields:a},...o&&o.length>0&&{sectionGroups:o},...i.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:i}]}}},[j?.name,M,D,T]);return v?(0,R.jsx)(ae,{}):j?(0,R.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,R.jsx)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:C.length>0&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`Users viewing this record`,children:[(0,R.jsx)(d,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,R.jsx)(Z,{users:C,size:`sm`,maxVisible:4,showStatus:!0})]})}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,R.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,R.jsx)(s,{context:{record:{},objectName:i,user:J},onConfirm:z,onToast:V,onNavigate:H,onParamCollection:B,handlers:{api:U,flow:G,script:K,modal:K},children:(0,R.jsx)(ie,{schema:$,dataSource:e,objectLabel:j.label,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=ne(j,e);t&&t!==k&&t!==`Untitled`&&A(t)},onEdit:()=>{n({id:M})},discussionSlot:(0,R.jsx)(re,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:b,onAddComment:Y,onAddReply:X,onToggleReaction:ue})},T)})}),(0,R.jsx)(oe,{open:m,sections:[{title:`View Schema`,data:$}]})]}),(0,R.jsx)(Q,{state:N,onOpenChange:e=>{e||P(e=>({...e,open:!1}))}}),(0,R.jsx)(le,{state:F,onOpenChange:e=>{e||I(e=>({...e,open:!1}))}})]}):(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,R.jsxs)(te,{children:[(0,R.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,R.jsx)(p,{className:`h-6 w-6 text-muted-foreground`})}),(0,R.jsx)(S,{children:`Object Not Found`}),(0,R.jsxs)(ee,{children:[`Object "`,i,`" definition missing. Check your configuration or navigate back to select a valid object.`]})]})})}export{q as a,V as c,Z as i,le as n,H as o,Q as r,B as s,ue as t};
@@ -1 +1 @@
1
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,r as i,t as a,u as o}from"./vendor-react-B1k2FF9f.js";import{F as s,a as c,f as l,p as u}from"./framework-CoXA0nY6.js";import{c as d,d as f}from"./infrastructure-Djv3I7gr.js";import{o as p}from"./vendor-ui-utils-Dyl9EYZi.js";import{OD as m,at as h,cI as g,it as _,ot as v,yr as y}from"./ui-components-B7mlp0en.js";import{t as b}from"./plugin-form-DOfn-uRa.js";import{i as x}from"./index-CPatxDwz.js";var S=t(n(),1),C=a(),w=(0,S.createContext)(null);function T({children:e,user:t={},app:n={},data:r={}}){let i=(0,S.useMemo)(()=>({user:t,app:n,data:r,evaluator:new s({user:t,app:n,data:r})}),[t,n,r]);return(0,C.jsx)(w.Provider,{value:i,children:e})}function E(){let e=(0,S.useContext)(w);if(!e){let e={user:{},app:{},data:{}};return{...e,evaluator:new s(e)}}return e}function D(e,t){if(e==null||e===!0||e===`true`)return!0;if(e===!1||e===`false`)return!1;if(typeof e==`string`&&e.includes("${"))try{return t.evaluateCondition(e)}catch{return!0}return!0}var O=e({RecordFormPage:()=>k});function k({mode:e}){let{appName:t,objectName:n,recordId:a}=r(),w=o(),E=l(),{objects:O,loading:k}=u(),{t:A}=c(),{objectLabel:j}=f(),{user:M}=d(),N=(0,S.useMemo)(()=>O.find(e=>e.name===n),[O,n]),P=`/apps/${t}`,F=`${P}/${n}`,I=e===`edit`&&a?`${P}/${n}/record/${encodeURIComponent(a)}`:F,L=(0,S.useCallback)(()=>{typeof window<`u`&&window.history.length>1?w(-1):w(I,{replace:!0})},[w,I]),R=N?j(N):n??``,z=e===`create`?A(`form.createTitle`,{object:R,defaultValue:`New ${R}`}):A(`form.editTitle`,{object:R,defaultValue:`Edit ${R}`}),B=(0,S.useCallback)(()=>{p.success(e===`create`?A(`form.createSuccess`,{object:R,defaultValue:`${R} created successfully`}):A(`form.updateSuccess`,{object:R,defaultValue:`${R} updated successfully`})),L()},[e,A,R,L]),V=(0,S.useCallback)(()=>{L()},[L]),H=(0,S.useMemo)(()=>M?{name:M.name,email:M.email,role:M.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[M]),U=(0,S.useMemo)(()=>new s({user:H,app:{name:t},data:{}}),[H,t]),W=(0,S.useMemo)(()=>N?.fields?Array.isArray(N.fields)?N.fields.filter(e=>typeof e==`string`?!0:D(e.visible,U)).map(e=>typeof e==`string`?e:e.name):Object.entries(N.fields).filter(([,e])=>D(e.visible,U)).map(([e])=>e):[],[N,U]);return k?(0,C.jsx)(x,{}):N?(0,C.jsx)(T,{user:H,app:{name:t},data:{},children:(0,C.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,C.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,C.jsx)(y,{variant:`ghost`,size:`sm`,onClick:L,"data-testid":`record-form-page-back`,"aria-label":A(`common.back`,{defaultValue:`Back`}),children:(0,C.jsx)(g,{className:`h-4 w-4`})}),(0,C.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,C.jsx)(i,{to:F,className:`hover:text-foreground transition-colors`,children:R}),(0,C.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,C.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:z})]})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,C.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,C.jsx)(b,{schema:{type:`object-form`,formType:`simple`,objectName:N.name,mode:e,recordId:e===`edit`?a:void 0,title:z,description:e===`create`?A(`form.createDescription`,{object:R,defaultValue:`Create a new ${R}.`}):A(`form.editDescription`,{object:R,defaultValue:`Edit this ${R}.`}),layout:`vertical`,fields:W,onSuccess:B,onCancel:V,showSubmit:!0,showCancel:!0,submitText:A(`form.saveRecord`,{defaultValue:`Save`}),cancelText:A(`common.cancel`,{defaultValue:`Cancel`})},dataSource:E??void 0},`${e}:${n}:${a??`new`}`)})})]})}):(0,C.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,C.jsxs)(_,{children:[(0,C.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,C.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,C.jsx)(v,{children:`Object Not Found`}),(0,C.jsxs)(h,{children:[`Object "`,n,`" definition missing. Check your configuration or navigate back to select a valid object.`]}),(0,C.jsx)(`div`,{className:`mt-4`,children:(0,C.jsxs)(y,{variant:`outline`,onClick:()=>w(P),children:[(0,C.jsx)(g,{className:`mr-2 h-4 w-4`}),`Back`]})})]})})}export{E as i,T as n,D as r,O as t};
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,r as i,t as a,u as o}from"./vendor-react-B1k2FF9f.js";import{F as s,a as c,f as l,p as u}from"./framework-CoXA0nY6.js";import{c as d,d as f}from"./infrastructure-Djv3I7gr.js";import{o as p}from"./vendor-ui-utils-Dyl9EYZi.js";import{DD as m,at as h,it as g,rt as _,sI as v,vr as y}from"./ui-components-DSSaN2w_.js";import{t as b}from"./plugin-form-BFt_k4to.js";import{i as x}from"./index-DTdi5Ufa.js";var S=t(n(),1),C=a(),w=(0,S.createContext)(null);function T({children:e,user:t={},app:n={},data:r={}}){let i=(0,S.useMemo)(()=>({user:t,app:n,data:r,evaluator:new s({user:t,app:n,data:r})}),[t,n,r]);return(0,C.jsx)(w.Provider,{value:i,children:e})}function E(){let e=(0,S.useContext)(w);if(!e){let e={user:{},app:{},data:{}};return{...e,evaluator:new s(e)}}return e}function D(e,t){if(e==null||e===!0||e===`true`)return!0;if(e===!1||e===`false`)return!1;if(typeof e==`string`&&e.includes("${"))try{return t.evaluateCondition(e)}catch{return!0}return!0}var O=e({RecordFormPage:()=>k});function k({mode:e}){let{appName:t,objectName:n,recordId:a}=r(),w=o(),E=l(),{objects:O,loading:k}=u(),{t:A}=c(),{objectLabel:j}=f(),{user:M}=d(),N=(0,S.useMemo)(()=>O.find(e=>e.name===n),[O,n]),P=`/apps/${t}`,F=`${P}/${n}`,I=e===`edit`&&a?`${P}/${n}/record/${encodeURIComponent(a)}`:F,L=(0,S.useCallback)(()=>{typeof window<`u`&&window.history.length>1?w(-1):w(I,{replace:!0})},[w,I]),R=N?j(N):n??``,z=e===`create`?A(`form.createTitle`,{object:R,defaultValue:`New ${R}`}):A(`form.editTitle`,{object:R,defaultValue:`Edit ${R}`}),B=(0,S.useCallback)(()=>{p.success(e===`create`?A(`form.createSuccess`,{object:R,defaultValue:`${R} created successfully`}):A(`form.updateSuccess`,{object:R,defaultValue:`${R} updated successfully`})),L()},[e,A,R,L]),V=(0,S.useCallback)(()=>{L()},[L]),H=(0,S.useMemo)(()=>M?{name:M.name,email:M.email,role:M.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[M]),U=(0,S.useMemo)(()=>new s({user:H,app:{name:t},data:{}}),[H,t]),W=(0,S.useMemo)(()=>N?.fields?Array.isArray(N.fields)?N.fields.filter(e=>typeof e==`string`?!0:D(e.visible,U)).map(e=>typeof e==`string`?e:e.name):Object.entries(N.fields).filter(([,e])=>D(e.visible,U)).map(([e])=>e):[],[N,U]);return k?(0,C.jsx)(x,{}):N?(0,C.jsx)(T,{user:H,app:{name:t},data:{},children:(0,C.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,C.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,C.jsx)(y,{variant:`ghost`,size:`sm`,onClick:L,"data-testid":`record-form-page-back`,"aria-label":A(`common.back`,{defaultValue:`Back`}),children:(0,C.jsx)(v,{className:`h-4 w-4`})}),(0,C.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,C.jsx)(i,{to:F,className:`hover:text-foreground transition-colors`,children:R}),(0,C.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,C.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:z})]})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,C.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,C.jsx)(b,{schema:{type:`object-form`,formType:`simple`,objectName:N.name,mode:e,recordId:e===`edit`?a:void 0,title:z,description:e===`create`?A(`form.createDescription`,{object:R,defaultValue:`Create a new ${R}.`}):A(`form.editDescription`,{object:R,defaultValue:`Edit this ${R}.`}),layout:`vertical`,fields:W,onSuccess:B,onCancel:V,showSubmit:!0,showCancel:!0,submitText:A(`form.saveRecord`,{defaultValue:`Save`}),cancelText:A(`common.cancel`,{defaultValue:`Cancel`})},dataSource:E??void 0},`${e}:${n}:${a??`new`}`)})})]})}):(0,C.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,C.jsxs)(_,{children:[(0,C.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,C.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,C.jsx)(h,{children:`Object Not Found`}),(0,C.jsxs)(g,{children:[`Object "`,n,`" definition missing. Check your configuration or navigate back to select a valid object.`]}),(0,C.jsx)(`div`,{className:`mt-4`,children:(0,C.jsxs)(y,{variant:`outline`,onClick:()=>w(P),children:[(0,C.jsx)(v,{className:`mr-2 h-4 w-4`}),`Back`]})})]})})}export{E as i,T as n,D as r,O as t};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-B5ROGaJH.css","assets/plugins-views-DnNKJB60.css"])))=>i.map(i=>d[i]);
2
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,t as a}from"./vendor-react-B1k2FF9f.js";import{f as o,p as s}from"./framework-CoXA0nY6.js";import{Cy as c,Jm as l,at as u,it as d,jj as f,ot as p}from"./ui-components-B7mlp0en.js";import{o as m,s as h}from"./index-CPatxDwz.js";var g=e({ReportView:()=>S}),_=t(n(),1),v=a(),y=(0,_.lazy)(()=>i(()=>import(`./plugins-views-DqZMtAOw.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0,1]))),b=(0,_.lazy)(()=>i(()=>import(`./plugins-views-DqZMtAOw.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0,1]))),x=[{value:`month`,label:`Month`,type:`text`},{value:`revenue`,label:`Revenue`,type:`number`},{value:`count`,label:`Count`,type:`number`},{value:`region`,label:`Region`,type:`text`},{value:`product`,label:`Product`,type:`text`},{value:`source`,label:`Lead Source`,type:`text`},{value:`stage`,label:`Stage`,type:`text`},{value:`amount`,label:`Amount`,type:`number`}];function S({dataSource:e}){let{reportName:t}=r(),{showDebug:n}=h(),i=o(),[a,g]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),{reports:w,objects:T,loading:E,refresh:D}=s(),O=w?.find(e=>e.name===t),[k,A]=(0,_.useState)(O),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)([]),[F,I]=(0,_.useState)(!1),L=(0,_.useMemo)(()=>{let e=j||k,t=e?.objectName||e?.dataSource?.object||e?.dataSource?.resource;if(t&&T?.length){let e=T.find(e=>e.name===t);if(e?.fields){let t=e.fields;return Array.isArray(t)?t.map(e=>typeof e==`string`?{value:e,label:e,type:`text`}:{value:e.name,label:e.label||e.name,type:e.type||`text`}):Object.entries(t).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))}}return x},[j,k,T]),R=(0,_.useCallback)(async e=>{try{i&&(await i.update(`sys_report`,t,e),D().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,t,D]),z=(0,_.useCallback)(()=>{M(k),g(!0),C(e=>e+1)},[k]),B=(0,_.useCallback)(()=>{g(!1)},[]),V=(0,_.useMemo)(()=>j||k,[S]),H=(0,_.useCallback)(e=>{M(e),R(e),C(e=>e+1)},[R]),U=(0,_.useCallback)((e,t)=>{M(n=>({...n,[e]:t}))},[]);(0,_.useEffect)(()=>{A(O)},[O]),(0,_.useEffect)(()=>{a||M(null)},[O]);let W=j||k,G=(0,_.useMemo)(()=>JSON.stringify(W?.filters),[W?.filters]),K=(0,_.useMemo)(()=>JSON.stringify(W?.dataSource),[W?.dataSource]),q=(0,_.useMemo)(()=>JSON.stringify(W?.data),[W?.data]);if((0,_.useEffect)(()=>{if(!W||!e){P([]);return}if(W.data&&Array.isArray(W.data)){P(W.data);return}if(W.dataSource){(async()=>{I(!0);try{let t=W.dataSource.object||W.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),P([]);return}P((await e.find(t,{$filter:W.dataSource.filter,$orderby:W.dataSource.sort,$top:W.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),P([])}finally{I(!1)}})();return}if(W.objectName){(async()=>{I(!0);try{P((await e.find(W.objectName,{$filter:W.filters,$orderby:W.sort,$top:W.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),P([])}finally{I(!1)}})();return}P([])},[W?.objectName,W?.limit,G,K,q,e]),E)return(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(c,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!O||!k)return!E&&!O?(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsxs)(d,{children:[(0,v.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,v.jsx)(f,{className:`h-6 w-6 text-muted-foreground`})}),(0,v.jsx)(p,{children:`Report Not Found`}),(0,v.jsxs)(u,{children:[`The report "`,t,`" could not be found. It may have been removed or renamed.`]})]})}):(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(c,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let J=e=>{let t={...e};if(!t.title&&t.label&&(t.title=t.label),!t.fields&&Array.isArray(t.columns)&&(t.fields=t.columns.map(e=>({name:e.field||e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap,...e.aggregate?{aggregation:e.aggregate,showInSummary:!0}:{}}))),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.reportType||`tabular`,i=[];if((r===`summary`||n)&&i.push({type:`summary`,title:`Key Metrics`}),i.push({type:`table`,title:`Details`,columns:t.fields.map(e=>({name:e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))}),t.chartConfig?.chartType&&i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:t.chartConfig.chartType,xAxisField:t.chartConfig.xAxisField,yAxisFields:t.chartConfig.yAxisFields}}),Array.isArray(e.sections)){let n=e.sections.filter(e=>e.type===`chart`&&!t.chartConfig?.chartType);i.push(...n)}t.sections=i}else t.sections||=[];return t},Y=j||k,X={type:`report-viewer`,report:J(Y),data:N,showToolbar:!0,allowExport:!0,loading:F};return(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:Y.title||Y.label||`Report Viewer`}),Y.description&&(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:Y.description})]}),(0,v.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,v.jsxs)(`button`,{type:`button`,onClick:z,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`report-edit-button`,children:[(0,v.jsx)(l,{className:`h-3.5 w-3.5`}),`Edit`]})})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,v.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,v.jsx)(`div`,{className:`max-w-5xl mx-auto shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,v.jsx)(_.Suspense,{fallback:(0,v.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:`Loading report…`}),children:(0,v.jsx)(y,{schema:X})})})}),(0,v.jsx)(_.Suspense,{fallback:null,children:(0,v.jsx)(b,{open:a,onClose:B,config:V,onSave:H,onFieldChange:U,availableFields:L})}),(0,v.jsx)(m,{open:n,sections:[{title:`Report Configuration`,data:Y}]})]})]})}export{g as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-BL3SEdAz.css","assets/plugins-views-DnNKJB60.css"])))=>i.map(i=>d[i]);
2
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,t as a}from"./vendor-react-B1k2FF9f.js";import{f as o,p as s}from"./framework-CoXA0nY6.js";import{Aj as c,Sy as l,at as u,it as d,qm as f,rt as p}from"./ui-components-DSSaN2w_.js";import{o as m,s as h}from"./index-DTdi5Ufa.js";var g=e({ReportView:()=>S}),_=t(n(),1),v=a(),y=(0,_.lazy)(()=>i(()=>import(`./plugins-views-Bi5okDge.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0,1]))),b=(0,_.lazy)(()=>i(()=>import(`./plugins-views-Bi5okDge.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0,1]))),x=[{value:`month`,label:`Month`,type:`text`},{value:`revenue`,label:`Revenue`,type:`number`},{value:`count`,label:`Count`,type:`number`},{value:`region`,label:`Region`,type:`text`},{value:`product`,label:`Product`,type:`text`},{value:`source`,label:`Lead Source`,type:`text`},{value:`stage`,label:`Stage`,type:`text`},{value:`amount`,label:`Amount`,type:`number`}];function S({dataSource:e}){let{reportName:t}=r(),{showDebug:n}=h(),i=o(),[a,g]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),{reports:w,objects:T,loading:E,refresh:D}=s(),O=w?.find(e=>e.name===t),[k,A]=(0,_.useState)(O),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)([]),[F,I]=(0,_.useState)(!1),L=(0,_.useMemo)(()=>{let e=j||k,t=e?.objectName||e?.dataSource?.object||e?.dataSource?.resource;if(t&&T?.length){let e=T.find(e=>e.name===t);if(e?.fields){let t=e.fields;return Array.isArray(t)?t.map(e=>typeof e==`string`?{value:e,label:e,type:`text`}:{value:e.name,label:e.label||e.name,type:e.type||`text`}):Object.entries(t).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))}}return x},[j,k,T]),R=(0,_.useCallback)(async e=>{try{i&&(await i.update(`sys_report`,t,e),D().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,t,D]),z=(0,_.useCallback)(()=>{M(k),g(!0),C(e=>e+1)},[k]),B=(0,_.useCallback)(()=>{g(!1)},[]),V=(0,_.useMemo)(()=>j||k,[S]),H=(0,_.useCallback)(e=>{M(e),R(e),C(e=>e+1)},[R]),U=(0,_.useCallback)((e,t)=>{M(n=>({...n,[e]:t}))},[]);(0,_.useEffect)(()=>{A(O)},[O]),(0,_.useEffect)(()=>{a||M(null)},[O]);let W=j||k,G=(0,_.useMemo)(()=>JSON.stringify(W?.filters),[W?.filters]),K=(0,_.useMemo)(()=>JSON.stringify(W?.dataSource),[W?.dataSource]),q=(0,_.useMemo)(()=>JSON.stringify(W?.data),[W?.data]);if((0,_.useEffect)(()=>{if(!W||!e){P([]);return}if(W.data&&Array.isArray(W.data)){P(W.data);return}if(W.dataSource){(async()=>{I(!0);try{let t=W.dataSource.object||W.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),P([]);return}P((await e.find(t,{$filter:W.dataSource.filter,$orderby:W.dataSource.sort,$top:W.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),P([])}finally{I(!1)}})();return}if(W.objectName){(async()=>{I(!0);try{P((await e.find(W.objectName,{$filter:W.filters,$orderby:W.sort,$top:W.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),P([])}finally{I(!1)}})();return}P([])},[W?.objectName,W?.limit,G,K,q,e]),E)return(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(l,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!O||!k)return!E&&!O?(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsxs)(p,{children:[(0,v.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,v.jsx)(c,{className:`h-6 w-6 text-muted-foreground`})}),(0,v.jsx)(u,{children:`Report Not Found`}),(0,v.jsxs)(d,{children:[`The report "`,t,`" could not be found. It may have been removed or renamed.`]})]})}):(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(l,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let J=e=>{let t={...e};if(!t.title&&t.label&&(t.title=t.label),!t.fields&&Array.isArray(t.columns)&&(t.fields=t.columns.map(e=>({name:e.field||e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap,...e.aggregate?{aggregation:e.aggregate,showInSummary:!0}:{}}))),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.reportType||`tabular`,i=[];if((r===`summary`||n)&&i.push({type:`summary`,title:`Key Metrics`}),i.push({type:`table`,title:`Details`,columns:t.fields.map(e=>({name:e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))}),t.chartConfig?.chartType&&i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:t.chartConfig.chartType,xAxisField:t.chartConfig.xAxisField,yAxisFields:t.chartConfig.yAxisFields}}),Array.isArray(e.sections)){let n=e.sections.filter(e=>e.type===`chart`&&!t.chartConfig?.chartType);i.push(...n)}t.sections=i}else t.sections||=[];return t},Y=j||k,X={type:`report-viewer`,report:J(Y),data:N,showToolbar:!0,allowExport:!0,loading:F};return(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:Y.title||Y.label||`Report Viewer`}),Y.description&&(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:Y.description})]}),(0,v.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,v.jsxs)(`button`,{type:`button`,onClick:z,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`report-edit-button`,children:[(0,v.jsx)(f,{className:`h-3.5 w-3.5`}),`Edit`]})})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,v.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,v.jsx)(`div`,{className:`max-w-5xl mx-auto shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,v.jsx)(_.Suspense,{fallback:(0,v.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:`Loading report…`}),children:(0,v.jsx)(y,{schema:X})})})}),(0,v.jsx)(_.Suspense,{fallback:null,children:(0,v.jsx)(b,{open:a,onClose:B,config:V,onSave:H,onFieldChange:U,availableFields:L})}),(0,v.jsx)(m,{open:n,sections:[{title:`Report Configuration`,data:Y}]})]})]})}export{g as t};
@@ -1 +1 @@
1
- import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,p as i,r as a,t as o}from"./vendor-react-B1k2FF9f.js";import{p as s}from"./framework-CoXA0nY6.js";import{$n as c,OD as l,Rd as u,ar as d,cI as f,cT as p,dn as m,er as h,jj as g,xb as _}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";var v=e({SearchResultsPage:()=>w}),y=t(n(),1),b=o();function x(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...x(n.children)):t.push(n);return t}var S={object:l,dashboard:_,page:p,report:g},C={object:`bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200`,dashboard:`bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200`,page:`bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200`,report:`bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200`};function w(){let{appName:e}=r(),[t,n]=i(),[o,p]=(0,y.useState)(t.get(`q`)||``),{apps:g}=s(),_=g||[],v=_.find(t=>t.name===e)||_[0],w=`/apps/${e}`,T=(0,y.useMemo)(()=>v?x(v.navigation||[]).map(e=>{let t=`#`;return e.type===`object`?(t=`${w}/${e.objectName}`,e.viewName&&(t+=`/view/${e.viewName}`)):e.type===`dashboard`?t=`${w}/dashboard/${e.dashboardName}`:e.type===`page`?t=`${w}/page/${e.pageName}`:e.type===`report`&&(t=`${w}/report/${e.reportName}`),{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:t,type:e.type,description:e.description}}).filter(e=>e.href!==`#`):[],[v,w]),E=(0,y.useMemo)(()=>{if(!o.trim())return T;let e=o.toLowerCase();return T.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[T,o]),D=e=>{p(e),n(e?{q:e}:{})},O=(0,y.useMemo)(()=>{let e={};for(let t of E)(e[t.type]||=[]).push(t);return e},[E]);return(0,b.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(a,{to:w,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,b.jsx)(f,{className:`h-4 w-4`}),`Back`]}),(0,b.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Search`})]}),(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:`Search objects, dashboards, pages, reports`}),(0,b.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,b.jsx)(m,{id:`search-results-input`,value:o,onChange:e=>D(e.target.value),placeholder:`Search objects, dashboards, pages, reports...`,className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,b.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.trim()?`${E.length} result${E.length===1?``:`s`} for "${o}"`:`${T.length} items available`}),E.length===0?(0,b.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,b.jsx)(u,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,b.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:`No results found`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:`Try adjusting your search terms`})]}):(0,b.jsx)(`div`,{className:`space-y-6`,children:Object.entries(O).map(([e,t])=>(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,b.jsx)(S[e]||l,{className:`h-4 w-4`}),e.charAt(0).toUpperCase()+e.slice(1),`s`,(0,b.jsx)(d,{variant:`secondary`,className:`ml-1 text-xs`,children:t.length})]}),(0,b.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>{let t=S[e.type]||l;return(0,b.jsx)(a,{to:e.href,className:`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:(0,b.jsx)(c,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,b.jsxs)(h,{className:`flex items-center gap-3 p-3`,children:[(0,b.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${C[e.type]||``}`,children:(0,b.jsx)(t,{className:`h-4 w-4`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm font-medium truncate`,children:e.label}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]}),(0,b.jsx)(d,{variant:`outline`,className:`text-xs shrink-0`,children:e.type})]})})},e.id)})})]},e))})]})}export{v as t};
1
+ import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,p as i,r as a,t as o}from"./vendor-react-B1k2FF9f.js";import{p as s}from"./framework-CoXA0nY6.js";import{$n as c,Aj as l,DD as u,Ld as d,Qn as f,bb as p,ir as m,sI as h,sT as g,un as _}from"./ui-components-DSSaN2w_.js";import"./index-DTdi5Ufa.js";var v=e({SearchResultsPage:()=>w}),y=t(n(),1),b=o();function x(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...x(n.children)):t.push(n);return t}var S={object:u,dashboard:p,page:g,report:l},C={object:`bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200`,dashboard:`bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200`,page:`bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200`,report:`bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200`};function w(){let{appName:e}=r(),[t,n]=i(),[o,l]=(0,y.useState)(t.get(`q`)||``),{apps:p}=s(),g=p||[],v=g.find(t=>t.name===e)||g[0],w=`/apps/${e}`,T=(0,y.useMemo)(()=>v?x(v.navigation||[]).map(e=>{let t=`#`;return e.type===`object`?(t=`${w}/${e.objectName}`,e.viewName&&(t+=`/view/${e.viewName}`)):e.type===`dashboard`?t=`${w}/dashboard/${e.dashboardName}`:e.type===`page`?t=`${w}/page/${e.pageName}`:e.type===`report`&&(t=`${w}/report/${e.reportName}`),{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:t,type:e.type,description:e.description}}).filter(e=>e.href!==`#`):[],[v,w]),E=(0,y.useMemo)(()=>{if(!o.trim())return T;let e=o.toLowerCase();return T.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[T,o]),D=e=>{l(e),n(e?{q:e}:{})},O=(0,y.useMemo)(()=>{let e={};for(let t of E)(e[t.type]||=[]).push(t);return e},[E]);return(0,b.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(a,{to:w,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,b.jsx)(h,{className:`h-4 w-4`}),`Back`]}),(0,b.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Search`})]}),(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:`Search objects, dashboards, pages, reports`}),(0,b.jsx)(d,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,b.jsx)(_,{id:`search-results-input`,value:o,onChange:e=>D(e.target.value),placeholder:`Search objects, dashboards, pages, reports...`,className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,b.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.trim()?`${E.length} result${E.length===1?``:`s`} for "${o}"`:`${T.length} items available`}),E.length===0?(0,b.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,b.jsx)(d,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,b.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:`No results found`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:`Try adjusting your search terms`})]}):(0,b.jsx)(`div`,{className:`space-y-6`,children:Object.entries(O).map(([e,t])=>(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,b.jsx)(S[e]||u,{className:`h-4 w-4`}),e.charAt(0).toUpperCase()+e.slice(1),`s`,(0,b.jsx)(m,{variant:`secondary`,className:`ml-1 text-xs`,children:t.length})]}),(0,b.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>{let t=S[e.type]||u;return(0,b.jsx)(a,{to:e.href,className:`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:(0,b.jsx)(f,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,b.jsxs)(c,{className:`flex items-center gap-3 p-3`,children:[(0,b.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${C[e.type]||``}`,children:(0,b.jsx)(t,{className:`h-4 w-4`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm font-medium truncate`,children:e.label}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]}),(0,b.jsx)(m,{variant:`outline`,className:`text-xs shrink-0`,children:e.type})]})})},e.id)})})]},e))})]})}export{v as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{f as a,p as o}from"./framework-CoXA0nY6.js";import{$n as s,Cy as c,Jb as l,KM as u,Kd as d,ar as f,ea as p,ed as m,er as h,nr as g,ra as _,rr as v,tr as y}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";import{r as b,t as x}from"./getIcon-DF6zJOtU.js";var S=e(t(),1),C=r();function w(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,w=a(),{apps:T,objects:E,dashboards:D,reports:O,pages:k}=o(),[A,j]=(0,S.useState)({apps:null,objects:null,users:null,orgs:null,roles:null,permissions:null,auditLogs:null,dashboard:null,page:null,report:null}),[M,N]=(0,S.useState)(!0),P=(0,S.useCallback)(async()=>{if(w){N(!0);try{let[e,t,n,r,i]=await Promise.all([w.find(`sys_user`).catch(()=>({data:[]})),w.find(`sys_org`).catch(()=>({data:[]})),w.find(`sys_role`).catch(()=>({data:[]})),w.find(`sys_permission`).catch(()=>({data:[]})),w.find(`sys_audit_log`).catch(()=>({data:[]}))]);j({apps:T?.length??0,objects:E?.length??0,users:e.data?.length??0,orgs:t.data?.length??0,roles:n.data?.length??0,permissions:r.data?.length??0,auditLogs:i.data?.length??0,dashboard:D?.length??0,page:k?.length??0,report:O?.length??0})}catch{}finally{N(!1)}}},[w,T,E,D,O,k]);(0,S.useEffect)(()=>{P()},[P]);let F=b().map(e=>{let t=e.customRoute?`${r}${e.customRoute}`:`${r}/system/metadata/${e.type}`,n=x(e.icon),i=null;return i=e.type===`app`?A.apps:e.type===`object`?A.objects:A[e.type]??null,{title:e.pluralLabel,description:e.description,icon:n,href:t,countLabel:e.pluralLabel.toLowerCase(),count:i}}),I=[{title:`Users`,description:`Manage system users and accounts`,icon:p,href:`${r}/system/users`,countLabel:`users`,count:A.users},{title:`Organizations`,description:`Manage organizations and teams`,icon:u,href:`${r}/system/organizations`,countLabel:`organizations`,count:A.orgs},{title:`Roles`,description:`Configure roles and access levels`,icon:m,href:`${r}/system/roles`,countLabel:`roles`,count:A.roles},{title:`Permissions`,description:`Manage permission rules and assignments`,icon:l,href:`${r}/system/permissions`,countLabel:`permissions`,count:A.permissions},{title:`Audit Log`,description:`View system activity and changes`,icon:d,href:`${r}/system/audit-log`,countLabel:`entries`,count:A.auditLogs},{title:`Profile`,description:`View and edit your account settings`,icon:_,href:`${r}/system/profile`,countLabel:``,count:null}],L=[...F,...I];return(0,C.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`System Settings`}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage applications, users, roles, permissions, and system configuration`})]}),M&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,C.jsx)(c,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading statistics...`]}),(0,C.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:L.map(t=>{let n=t.icon;return(0,C.jsxs)(s,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>e(t.href),"data-testid":`hub-card-${t.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${t.title}: ${t.description}`,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},children:[(0,C.jsxs)(g,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,C.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,C.jsx)(n,{className:`h-5 w-5`})}),(0,C.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,C.jsx)(v,{className:`text-base`,children:t.title}),(0,C.jsx)(y,{className:`text-xs`,children:t.description})]})]}),(0,C.jsx)(h,{className:`pt-0`,children:t.count!==null&&(0,C.jsxs)(f,{variant:`secondary`,children:[t.count,` `,t.countLabel]})})]},t.title)})})]})}export{w as SystemHubPage};
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{f as a,p as o}from"./framework-CoXA0nY6.js";import{$i as s,$n as c,$u as l,GM as u,Gd as d,Qn as f,Sy as p,er as m,ir as h,na as g,nr as _,qb as v,tr as y}from"./ui-components-DSSaN2w_.js";import"./index-DTdi5Ufa.js";import{r as b,t as x}from"./getIcon-BKYKFGnN.js";var S=e(t(),1),C=r();function w(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,w=a(),{apps:T,objects:E,dashboards:D,reports:O,pages:k}=o(),[A,j]=(0,S.useState)({apps:null,objects:null,users:null,orgs:null,roles:null,permissions:null,auditLogs:null,dashboard:null,page:null,report:null}),[M,N]=(0,S.useState)(!0),P=(0,S.useCallback)(async()=>{if(w){N(!0);try{let[e,t,n,r,i]=await Promise.all([w.find(`sys_user`).catch(()=>({data:[]})),w.find(`sys_org`).catch(()=>({data:[]})),w.find(`sys_role`).catch(()=>({data:[]})),w.find(`sys_permission`).catch(()=>({data:[]})),w.find(`sys_audit_log`).catch(()=>({data:[]}))]);j({apps:T?.length??0,objects:E?.length??0,users:e.data?.length??0,orgs:t.data?.length??0,roles:n.data?.length??0,permissions:r.data?.length??0,auditLogs:i.data?.length??0,dashboard:D?.length??0,page:k?.length??0,report:O?.length??0})}catch{}finally{N(!1)}}},[w,T,E,D,O,k]);(0,S.useEffect)(()=>{P()},[P]);let F=b().map(e=>{let t=e.customRoute?`${r}${e.customRoute}`:`${r}/system/metadata/${e.type}`,n=x(e.icon),i=null;return i=e.type===`app`?A.apps:e.type===`object`?A.objects:A[e.type]??null,{title:e.pluralLabel,description:e.description,icon:n,href:t,countLabel:e.pluralLabel.toLowerCase(),count:i}}),I=[{title:`Users`,description:`Manage system users and accounts`,icon:s,href:`${r}/system/users`,countLabel:`users`,count:A.users},{title:`Organizations`,description:`Manage organizations and teams`,icon:u,href:`${r}/system/organizations`,countLabel:`organizations`,count:A.orgs},{title:`Roles`,description:`Configure roles and access levels`,icon:l,href:`${r}/system/roles`,countLabel:`roles`,count:A.roles},{title:`Permissions`,description:`Manage permission rules and assignments`,icon:v,href:`${r}/system/permissions`,countLabel:`permissions`,count:A.permissions},{title:`Audit Log`,description:`View system activity and changes`,icon:d,href:`${r}/system/audit-log`,countLabel:`entries`,count:A.auditLogs},{title:`Profile`,description:`View and edit your account settings`,icon:g,href:`${r}/system/profile`,countLabel:``,count:null}],L=[...F,...I];return(0,C.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`System Settings`}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage applications, users, roles, permissions, and system configuration`})]}),M&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,C.jsx)(p,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading statistics...`]}),(0,C.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:L.map(t=>{let n=t.icon;return(0,C.jsxs)(f,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>e(t.href),"data-testid":`hub-card-${t.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${t.title}: ${t.description}`,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},children:[(0,C.jsxs)(y,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,C.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,C.jsx)(n,{className:`h-5 w-5`})}),(0,C.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,C.jsx)(_,{className:`text-base`,children:t.title}),(0,C.jsx)(m,{className:`text-xs`,children:t.description})]})]}),(0,C.jsx)(c,{className:`pt-0`,children:t.count!==null&&(0,C.jsxs)(h,{variant:`secondary`,children:[t.count,` `,t.countLabel]})})]},t.title)})})]})}export{w as SystemHubPage};
@@ -1 +1 @@
1
- import{V as e}from"./framework-CoXA0nY6.js";import{n as t}from"./vendor-objectstack-CBpPY_xk.js";var n=class{cache;inflight;maxSize;ttl;stats;constructor(e={}){this.cache=new Map,this.inflight=new Map,this.maxSize=e.maxSize||100,this.ttl=e.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0,coalesced:0}}async get(e,t){let n=Date.now(),r=this.cache.get(e);if(r){if(n-r.timestamp<this.ttl)return r.accessCount++,r.lastAccessed=n,this.stats.hits++,this.cache.delete(e),this.cache.set(e,r),r.data;this.cache.delete(e)}let i=this.inflight.get(e);if(i)return this.stats.coalesced++,i;this.stats.misses++;let a=(async()=>{try{let n=await t();return this.set(e,n),n}finally{this.inflight.delete(e)}})();return this.inflight.set(e,a),a}prime(e,t){this.set(e,t)}set(e,t){let n=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,{data:t,timestamp:n,accessCount:1,lastAccessed:n})}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}invalidate(e){e?this.cache.delete(e):this.cache.clear()}clear(){this.cache.clear(),this.inflight.clear(),this.stats={hits:0,misses:0,evictions:0,coalesced:0}}getStats(){let e=this.stats.hits+this.stats.misses,t=e>0?this.stats.hits/e:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,coalesced:this.stats.coalesced,hitRate:t}}getCachedSync(e){let t=this.cache.get(e);if(t){if(this.ttl>0&&Date.now()-t.timestamp>this.ttl){this.cache.delete(e);return}return this.cache.delete(e),this.cache.set(e,t),this.stats.hits++,t.data}}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>=this.ttl?(this.cache.delete(e),!1):!0:!1}},r=class extends Error{constructor(e,t,n,r){super(e),this.code=t,this.statusCode=n,this.details=r,this.name=`ObjectStackError`,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}},i=class extends r{constructor(e,t){super(`Metadata not found for object: ${e}`,`METADATA_NOT_FOUND`,404,{objectName:e,...t}),this.name=`MetadataNotFoundError`}},a=class extends r{constructor(e,t,n,r,i){super(`Bulk ${e} operation failed: ${t} succeeded, ${n} failed`,`BULK_OPERATION_ERROR`,500,{operation:e,successCount:t,failureCount:n,errors:r,...i}),this.successCount=t,this.failureCount=n,this.errors=r,this.name=`BulkOperationError`}getSummary(){let e=this.successCount+this.failureCount,t=e>0?this.failureCount/e:0;return{operation:this.details?.operation,total:e,successful:this.successCount,failed:this.failureCount,failureRate:t,errors:this.errors}}},o=class extends r{constructor(e,t,n,r){super(`Connection error: ${e}`,`CONNECTION_ERROR`,r||503,{url:t,...n}),this.url=t,this.name=`ConnectionError`}},s=class extends r{constructor(e=`Authentication failed`,t,n){super(e,`AUTHENTICATION_ERROR`,n||401,t),this.name=`AuthenticationError`}},c=class extends r{constructor(e,t,n,r){super(e,`VALIDATION_ERROR`,400,{field:t,validationErrors:n,...r}),this.field=t,this.validationErrors=n,this.name=`ValidationError`}getValidationErrors(){return this.validationErrors||[]}};function l(e,t){let n=e?.status||e?.statusCode||500,a=e?.message||e?.statusText||`Unknown error`,l={context:t,response:{status:n,data:e?.data,headers:e?.headers}};switch(n){case 401:return new s(a,l,401);case 403:return new s(a,l,403);case 404:return t?.includes(`metadata`)||t?.includes(`schema`)||t?.includes(`getObjectSchema`)?new i(u(t),l):new r(a,`NOT_FOUND`,404,l);case 400:return new c(a,void 0,e?.data?.errors,l);case 503:return new o(a,e?.config?.url,l,503);case 504:return new o(a,e?.config?.url,l,504);default:return new r(a,`UNKNOWN_ERROR`,n,l)}}function u(e){if(!e)return`unknown`;let t=e.match(/\(([^)]+)\)/);return t?t[1]:`unknown`}var d={equals:`=`,eq:`=`,"==":`=`,not_equals:`!=`,notequals:`!=`,ne:`!=`,greater_than:`>`,greaterthan:`>`,gt:`>`,greater_than_or_equal:`>=`,greater_than_or_equals:`>=`,greaterthanorequal:`>=`,gte:`>=`,less_than:`<`,lessthan:`<`,lt:`<`,less_than_or_equal:`<=`,less_than_or_equals:`<=`,lessthanorequal:`<=`,lte:`<=`,in:`in`,not_in:`nin`,notin:`nin`,nin:`nin`,contains:`contains`,not_contains:`notcontains`,notcontains:`notcontains`,starts_with:`startswith`,startswith:`startswith`,ends_with:`endswith`,endswith:`endswith`,between:`between`,is_null:`isnull`,isnull:`isnull`,is_not_null:`isnotnull`,isnotnull:`isnotnull`};function f(e){return typeof e==`string`?d[e.toLowerCase()]??d[e]??e:null}function p(e){if(!e||typeof e!=`object`)return null;let t=e.field??e.name,n=f(e.operator??e.op??`=`);return!t||!n?null:[String(t),n,e.value]}var m=new Map;async function h(e,t){let n=e||`<default>`,r=m.get(n);if(r)return r;let i=t().catch(e=>{throw m.delete(n),e});return m.set(n,i),i}function g(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(g).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${g(t[e])}`).join(`,`)}}`}var _=class{client;connected=!1;connectPromise=null;metadataCache;connectionState=`disconnected`;connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;fetchImpl;inflightFinds=new Map;constructor(e){this.client=new t(e),this.metadataCache=new n(e.cache),this.autoReconnect=e.autoReconnect??!0,this.maxReconnectAttempts=e.maxReconnectAttempts??3,this.reconnectDelay=e.reconnectDelay??1e3,this.baseUrl=e.baseUrl,this.token=e.token,this.fetchImpl=e.fetch||globalThis.fetch.bind(globalThis)}async connect(){if(!this.connected)return this.connectPromise?this.connectPromise:(this.setConnectionState(`connecting`),this.connectPromise=(async()=>{try{let e=this.baseUrl||``,t=e?`${e.replace(/\/$/,``)}/api/v1/discovery`:`/api/v1/discovery`,n=await h(e,async()=>{let e=await this.fetchImpl(t,{method:`GET`,headers:this.token?{Authorization:`Bearer ${this.token}`}:void 0});if(!e.ok)throw Error(`discovery ${e.status} ${e.statusText}`);let n=await e.json();return n&&typeof n.success==`boolean`&&`data`in n?n.data:n});this.client.discoveryInfo=n,this.connected=!0,this.reconnectAttempts=0,this.setConnectionState(`connected`)}catch(e){let t=new o(e instanceof Error?e.message:`Failed to connect to ObjectStack server`,void 0,{originalError:e});if(this.setConnectionState(`error`,t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw t}finally{this.connectPromise=null}})(),this.connectPromise)}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState(`reconnecting`);let e=this.reconnectDelay*2**(this.reconnectAttempts-1);await new Promise(t=>setTimeout(t,e)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState===`connected`}onConnectionStateChange(e){return this.connectionStateListeners.push(e),()=>{let t=this.connectionStateListeners.indexOf(e);t>-1&&this.connectionStateListeners.splice(t,1)}}onBatchProgress(e){return this.batchProgressListeners.push(e),()=>{let t=this.batchProgressListeners.indexOf(e);t>-1&&this.batchProgressListeners.splice(t,1)}}setConnectionState(e,t){this.connectionState=e;let n={state:e,timestamp:Date.now(),error:t};this.connectionStateListeners.forEach(e=>{try{e(n)}catch(e){console.error(`Error in connection state listener:`,e)}})}emitBatchProgress(e){this.batchProgressListeners.forEach(t=>{try{t(e)}catch(e){console.error(`Error in batch progress listener:`,e)}})}async find(e,t){let n=`${e}::${g(t)}`,r=this.inflightFinds.get(n);if(r)return r;let i=(async()=>{if(await this.connect(),t?.$expand&&t.$expand.length>0){let n=await this.rawFindWithPopulate(e,t);return this.normalizeQueryResult(n,t)}let n=this.convertQueryParams(t),r=await this.client.data.find(e,n);return this.normalizeQueryResult(r,t)})();return this.inflightFinds.set(n,i),i.finally(()=>{this.inflightFinds.get(n)===i&&this.inflightFinds.delete(n)}),i}async findOne(e,t,n){if(await this.connect(),n?.$expand&&n.$expand.length>0)try{let r={...n,$filter:{id:String(t)},$top:1},i=await this.rawFindWithPopulate(e,r);if(Array.isArray(i))return i[0]||null;let a=i;return(a.records||a.value||[])[0]||null}catch(e){if(e?.status===404)return null}try{return(await this.client.data.get(e,String(t))).record}catch(e){if(e?.status===404)return null;throw e}}async create(e,t){return await this.connect(),(await this.client.data.create(e,t)).record}async update(e,t,n){return await this.connect(),(await this.client.data.update(e,String(t),n)).record}async delete(e,t){return await this.connect(),(await this.client.data.delete(e,String(t))).deleted}async bulk(e,t,n){if(await this.connect(),!n||n.length===0)return[];let i=n.length,o=0,s=0,c=()=>{this.emitBatchProgress({operation:t,total:i,completed:o,failed:s,percentage:i>0?(o+s)/i*100:0})};try{switch(t){case`create`:{c();let t=await this.client.data.createMany(e,n);return o=t.length,s=i-o,c(),t}case`delete`:{let t=n.map(e=>e.id).filter(Boolean);if(t.length===0){let e=n.map((e,t)=>({index:t,error:`Missing ID for item at index ${t}`}));throw s=n.length,c(),new a(`delete`,0,n.length,e)}return c(),await this.client.data.deleteMany(e,t),o=t.length,s=i-o,c(),[]}case`update`:{if(typeof this.client.data.updateMany==`function`)try{c();let t=this.client.data.updateMany,r=await t(e,n);return o=r.length,s=i-o,c(),r}catch{}let t=[],r=[];for(let i=0;i<n.length;i++){let a=n[i],l=a.id;if(!l){r.push({index:i,error:`Missing ID`}),s++,c();continue}try{let n=await this.client.data.update(e,String(l),a);t.push(n.record),o++,c()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({index:i,error:t}),s++,c()}}if(r.length>0)throw new a(`update`,t.length,r.length,r,{resource:e,totalRecords:n.length});return t}default:throw new r(`Unsupported bulk operation: ${t}`,`UNSUPPORTED_OPERATION`,400)}}catch(i){if(c(),i instanceof a||i instanceof r)throw i;let o=i instanceof Error?i.message:String(i),s=n.map((e,t)=>({index:t,error:o}));throw new a(t,0,n.length,s,{resource:e,originalError:i})}}normalizeQueryResult(e,t){if(Array.isArray(e))return{data:e,total:e.length,page:1,pageSize:e.length,hasMore:!1};let n=e,r=n.records||n.value||[];return{data:r,total:n.total??n.count??r.length,page:t?.$skip&&t.$top?Math.floor(t.$skip/t.$top)+1:1,pageSize:t?.$top,hasMore:t?.$top?r.length===t.$top:!1}}async rawFindWithPopulate(e,t){let n=new URLSearchParams;if(t.$expand&&t.$expand.length>0&&n.set(`populate`,t.$expand.join(`,`)),t.$top!==void 0&&n.set(`top`,String(t.$top)),t.$skip!==void 0&&n.set(`skip`,String(t.$skip)),t.$select&&t.$select.length>0&&n.set(`select`,t.$select.join(`,`)),t.$orderby)if(Array.isArray(t.$orderby)){let e=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}).join(`,`);n.set(`sort`,e)}else{let e=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e).join(`,`);n.set(`sort`,e)}t.$filter!==void 0&&t.$filter!==null&&((Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0)||n.set(`filter`,JSON.stringify(t.$filter)));let r=this.baseUrl.replace(/\/$/,``),i=n.toString(),a=`${r}${/\/api\/v\d+$/i.test(r)?`/data`:`/api/v1/data`}/${e}${i?`?${i}`:``}`,o={"Content-Type":`application/json`};this.token&&(o.Authorization=`Bearer ${this.token}`);let s=await this.fetchImpl(a,{method:`GET`,headers:o});if(!s.ok){let e=await s.json().catch(()=>({message:s.statusText})),t=Error(e?.error?.message||e?.message||s.statusText);throw t.status=s.status,t}let c=await s.json();return c&&typeof c.success==`boolean`&&`data`in c?c.data:c}convertQueryParams(t){if(!t)return{};let n={};if(t.$select&&(n.select=t.$select),t.$filter!==void 0&&t.$filter!==null&&!(Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0))if(Array.isArray(t.$filter))if(t.$filter.length>0&&typeof t.$filter[0]==`object`&&!Array.isArray(t.$filter[0])&&t.$filter[0].field!==void 0){let e=t.$filter.map(e=>p(e)).filter(e=>e!==null);e.length===0||(e.length===1?n.filters=e[0]:n.filters=[`and`,...e])}else n.filters=t.$filter;else n.filters=e(t.$filter);return t.$orderby&&(Array.isArray(t.$orderby)?n.sort=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),t.$skip!==void 0&&(n.skip=t.$skip),t.$top!==void 0&&(n.top=t.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw n?.status===404||n?.statusCode===404?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,`views/${t}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async aggregate(e,t){await this.connect();try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.filters=t.filter);let i=await this.client.analytics.query(r),a=Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[];if(a.length>0&&a.every(e=>e==null?!0:!(n in e&&e[n]!=null||t.field in e&&e[t.field]!=null))){let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}return a.map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}aggregateClientSide(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async getItems(e,t){return await this.connect(),await Promise.all(t.map(async t=>{let n=`${e}:${t}`;return this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n})}))}getCached(e){return this.metadataCache.getCachedSync(e)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(e){this.metadataCache.invalidate(e)}clearCache(){this.metadataCache.clear()}async uploadFile(e,t,n){await this.connect();let i=new FormData;i.append(`file`,t),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async uploadFiles(e,t,n){await this.connect();let i=new FormData;t.forEach((e,t)=>{i.append(`files`,e,e.name||`file-${t}`)}),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}getAuthHeaders(){let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e}};export{h as n,_ as t};
1
+ import{V as e}from"./framework-CoXA0nY6.js";import{n as t}from"./vendor-objectstack-CBpPY_xk.js";var n=class{cache;inflight;maxSize;ttl;stats;constructor(e={}){this.cache=new Map,this.inflight=new Map,this.maxSize=e.maxSize||100,this.ttl=e.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0,coalesced:0}}async get(e,t){let n=Date.now(),r=this.cache.get(e);if(r){if(n-r.timestamp<this.ttl)return r.accessCount++,r.lastAccessed=n,this.stats.hits++,this.cache.delete(e),this.cache.set(e,r),r.data;this.cache.delete(e)}let i=this.inflight.get(e);if(i)return this.stats.coalesced++,i;this.stats.misses++;let a=(async()=>{try{let n=await t();return this.set(e,n),n}finally{this.inflight.delete(e)}})();return this.inflight.set(e,a),a}prime(e,t){this.set(e,t)}set(e,t){let n=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,{data:t,timestamp:n,accessCount:1,lastAccessed:n})}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}invalidate(e){e?this.cache.delete(e):this.cache.clear()}clear(){this.cache.clear(),this.inflight.clear(),this.stats={hits:0,misses:0,evictions:0,coalesced:0}}getStats(){let e=this.stats.hits+this.stats.misses,t=e>0?this.stats.hits/e:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,coalesced:this.stats.coalesced,hitRate:t}}getCachedSync(e){let t=this.cache.get(e);if(t){if(this.ttl>0&&Date.now()-t.timestamp>this.ttl){this.cache.delete(e);return}return this.cache.delete(e),this.cache.set(e,t),this.stats.hits++,t.data}}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>=this.ttl?(this.cache.delete(e),!1):!0:!1}},r=class extends Error{constructor(e,t,n,r){super(e),this.code=t,this.statusCode=n,this.details=r,this.name=`ObjectStackError`,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}},i=class extends r{constructor(e,t){super(`Metadata not found for object: ${e}`,`METADATA_NOT_FOUND`,404,{objectName:e,...t}),this.name=`MetadataNotFoundError`}},a=class extends r{constructor(e,t,n,r,i){super(`Bulk ${e} operation failed: ${t} succeeded, ${n} failed`,`BULK_OPERATION_ERROR`,500,{operation:e,successCount:t,failureCount:n,errors:r,...i}),this.successCount=t,this.failureCount=n,this.errors=r,this.name=`BulkOperationError`}getSummary(){let e=this.successCount+this.failureCount,t=e>0?this.failureCount/e:0;return{operation:this.details?.operation,total:e,successful:this.successCount,failed:this.failureCount,failureRate:t,errors:this.errors}}},o=class extends r{constructor(e,t,n,r){super(`Connection error: ${e}`,`CONNECTION_ERROR`,r||503,{url:t,...n}),this.url=t,this.name=`ConnectionError`}},s=class extends r{constructor(e=`Authentication failed`,t,n){super(e,`AUTHENTICATION_ERROR`,n||401,t),this.name=`AuthenticationError`}},c=class extends r{constructor(e,t,n,r){super(e,`VALIDATION_ERROR`,400,{field:t,validationErrors:n,...r}),this.field=t,this.validationErrors=n,this.name=`ValidationError`}getValidationErrors(){return this.validationErrors||[]}};function l(e,t){let n=e?.status||e?.statusCode||500,a=e?.message||e?.statusText||`Unknown error`,l={context:t,response:{status:n,data:e?.data,headers:e?.headers}};switch(n){case 401:return new s(a,l,401);case 403:return new s(a,l,403);case 404:return t?.includes(`metadata`)||t?.includes(`schema`)||t?.includes(`getObjectSchema`)?new i(u(t),l):new r(a,`NOT_FOUND`,404,l);case 400:return new c(a,void 0,e?.data?.errors,l);case 503:return new o(a,e?.config?.url,l,503);case 504:return new o(a,e?.config?.url,l,504);default:return new r(a,`UNKNOWN_ERROR`,n,l)}}function u(e){if(!e)return`unknown`;let t=e.match(/\(([^)]+)\)/);return t?t[1]:`unknown`}var d={equals:`=`,eq:`=`,"==":`=`,not_equals:`!=`,notequals:`!=`,ne:`!=`,greater_than:`>`,greaterthan:`>`,gt:`>`,greater_than_or_equal:`>=`,greater_than_or_equals:`>=`,greaterthanorequal:`>=`,gte:`>=`,less_than:`<`,lessthan:`<`,lt:`<`,less_than_or_equal:`<=`,less_than_or_equals:`<=`,lessthanorequal:`<=`,lte:`<=`,in:`in`,not_in:`nin`,notin:`nin`,nin:`nin`,contains:`contains`,not_contains:`notcontains`,notcontains:`notcontains`,starts_with:`startswith`,startswith:`startswith`,ends_with:`endswith`,endswith:`endswith`,between:`between`,is_null:`isnull`,isnull:`isnull`,is_not_null:`isnotnull`,isnotnull:`isnotnull`};function f(e){return typeof e==`string`?d[e.toLowerCase()]??d[e]??e:null}function p(e){if(!e||typeof e!=`object`)return null;let t=e.field??e.name,n=f(e.operator??e.op??`=`);return!t||!n?null:[String(t),n,e.value]}var m=new Map;async function h(e,t){let n=e||`<default>`,r=m.get(n);if(r)return r;let i=t().catch(e=>{throw m.delete(n),e});return m.set(n,i),i}function g(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(g).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${g(t[e])}`).join(`,`)}}`}var _=class{client;connected=!1;connectPromise=null;metadataCache;connectionState=`disconnected`;connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;fetchImpl;inflightFinds=new Map;constructor(e){this.client=new t(e),this.metadataCache=new n(e.cache),this.autoReconnect=e.autoReconnect??!0,this.maxReconnectAttempts=e.maxReconnectAttempts??3,this.reconnectDelay=e.reconnectDelay??1e3,this.baseUrl=e.baseUrl,this.token=e.token,this.fetchImpl=e.fetch||globalThis.fetch.bind(globalThis)}async connect(){if(!this.connected)return this.connectPromise?this.connectPromise:(this.setConnectionState(`connecting`),this.connectPromise=(async()=>{try{let e=this.baseUrl||``,t=e?`${e.replace(/\/$/,``)}/api/v1/discovery`:`/api/v1/discovery`,n=await h(e,async()=>{let e=await this.fetchImpl(t,{method:`GET`,headers:this.token?{Authorization:`Bearer ${this.token}`}:void 0});if(!e.ok)throw Error(`discovery ${e.status} ${e.statusText}`);let n=await e.json();return n&&typeof n.success==`boolean`&&`data`in n?n.data:n});this.client.discoveryInfo=n,this.connected=!0,this.reconnectAttempts=0,this.setConnectionState(`connected`)}catch(e){let t=new o(e instanceof Error?e.message:`Failed to connect to ObjectStack server`,void 0,{originalError:e});if(this.setConnectionState(`error`,t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw t}finally{this.connectPromise=null}})(),this.connectPromise)}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState(`reconnecting`);let e=this.reconnectDelay*2**(this.reconnectAttempts-1);await new Promise(t=>setTimeout(t,e)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState===`connected`}onConnectionStateChange(e){return this.connectionStateListeners.push(e),()=>{let t=this.connectionStateListeners.indexOf(e);t>-1&&this.connectionStateListeners.splice(t,1)}}onBatchProgress(e){return this.batchProgressListeners.push(e),()=>{let t=this.batchProgressListeners.indexOf(e);t>-1&&this.batchProgressListeners.splice(t,1)}}setConnectionState(e,t){this.connectionState=e;let n={state:e,timestamp:Date.now(),error:t};this.connectionStateListeners.forEach(e=>{try{e(n)}catch(e){console.error(`Error in connection state listener:`,e)}})}emitBatchProgress(e){this.batchProgressListeners.forEach(t=>{try{t(e)}catch(e){console.error(`Error in batch progress listener:`,e)}})}async find(e,t){let n=`${e}::${g(t)}`,r=this.inflightFinds.get(n);if(r)return r;let i=(async()=>{if(await this.connect(),t?.$expand&&t.$expand.length>0){let n=await this.rawFindWithPopulate(e,t);return this.normalizeQueryResult(n,t)}let n=this.convertQueryParams(t),r=await this.client.data.find(e,n);return this.normalizeQueryResult(r,t)})();return this.inflightFinds.set(n,i),i.finally(()=>{this.inflightFinds.get(n)===i&&this.inflightFinds.delete(n)}),i}async findOne(e,t,n){if(await this.connect(),n?.$expand&&n.$expand.length>0)try{let r={...n,$filter:{id:String(t)},$top:1},i=await this.rawFindWithPopulate(e,r);if(Array.isArray(i))return i[0]||null;let a=i;return(a.records||a.value||[])[0]||null}catch(e){if(e?.status===404)return null}try{return(await this.client.data.get(e,String(t))).record}catch(e){if(e?.status===404)return null;throw e}}async create(e,t){return await this.connect(),(await this.client.data.create(e,t)).record}async update(e,t,n){return await this.connect(),(await this.client.data.update(e,String(t),n)).record}async delete(e,t){return await this.connect(),(await this.client.data.delete(e,String(t))).deleted}async bulk(e,t,n){if(await this.connect(),!n||n.length===0)return[];let i=n.length,o=0,s=0,c=()=>{this.emitBatchProgress({operation:t,total:i,completed:o,failed:s,percentage:i>0?(o+s)/i*100:0})};try{switch(t){case`create`:{c();let t=await this.client.data.createMany(e,n);return o=t.length,s=i-o,c(),t}case`delete`:{let t=n.map(e=>e.id).filter(Boolean);if(t.length===0){let e=n.map((e,t)=>({index:t,error:`Missing ID for item at index ${t}`}));throw s=n.length,c(),new a(`delete`,0,n.length,e)}return c(),await this.client.data.deleteMany(e,t),o=t.length,s=i-o,c(),[]}case`update`:{if(typeof this.client.data.updateMany==`function`)try{c();let t=this.client.data.updateMany,r=await t(e,n);return o=r.length,s=i-o,c(),r}catch{}let t=[],r=[];for(let i=0;i<n.length;i++){let a=n[i],l=a.id;if(!l){r.push({index:i,error:`Missing ID`}),s++,c();continue}try{let n=await this.client.data.update(e,String(l),a);t.push(n.record),o++,c()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({index:i,error:t}),s++,c()}}if(r.length>0)throw new a(`update`,t.length,r.length,r,{resource:e,totalRecords:n.length});return t}default:throw new r(`Unsupported bulk operation: ${t}`,`UNSUPPORTED_OPERATION`,400)}}catch(i){if(c(),i instanceof a||i instanceof r)throw i;let o=i instanceof Error?i.message:String(i),s=n.map((e,t)=>({index:t,error:o}));throw new a(t,0,n.length,s,{resource:e,originalError:i})}}normalizeQueryResult(e,t){if(Array.isArray(e))return{data:e,total:e.length,page:1,pageSize:e.length,hasMore:!1};let n=e,r=n.records||n.value||[];return{data:r,total:n.total??n.count??r.length,page:t?.$skip&&t.$top?Math.floor(t.$skip/t.$top)+1:1,pageSize:t?.$top,hasMore:t?.$top?r.length===t.$top:!1}}async rawFindWithPopulate(e,t){let n=new URLSearchParams;if(t.$expand&&t.$expand.length>0&&n.set(`populate`,t.$expand.join(`,`)),t.$top!==void 0&&n.set(`top`,String(t.$top)),t.$skip!==void 0&&n.set(`skip`,String(t.$skip)),t.$select&&t.$select.length>0){let e=t.$select.includes(`id`)?t.$select:[`id`,...t.$select];n.set(`select`,e.join(`,`))}if(t.$orderby)if(Array.isArray(t.$orderby)){let e=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}).join(`,`);n.set(`sort`,e)}else{let e=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e).join(`,`);n.set(`sort`,e)}t.$filter!==void 0&&t.$filter!==null&&((Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0)||n.set(`filter`,JSON.stringify(t.$filter)));let r=this.baseUrl.replace(/\/$/,``),i=n.toString(),a=`${r}${/\/api\/v\d+$/i.test(r)?`/data`:`/api/v1/data`}/${e}${i?`?${i}`:``}`,o={"Content-Type":`application/json`};this.token&&(o.Authorization=`Bearer ${this.token}`);let s=await this.fetchImpl(a,{method:`GET`,headers:o});if(!s.ok){let e=await s.json().catch(()=>({message:s.statusText})),t=Error(e?.error?.message||e?.message||s.statusText);throw t.status=s.status,t}let c=await s.json();return c&&typeof c.success==`boolean`&&`data`in c?c.data:c}convertQueryParams(t){if(!t)return{};let n={};if(t.$select&&(n.select=t.$select.includes(`id`)?t.$select:[`id`,...t.$select]),t.$filter!==void 0&&t.$filter!==null&&!(Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0))if(Array.isArray(t.$filter))if(t.$filter.length>0&&typeof t.$filter[0]==`object`&&!Array.isArray(t.$filter[0])&&t.$filter[0].field!==void 0){let e=t.$filter.map(e=>p(e)).filter(e=>e!==null);e.length===0||(e.length===1?n.filters=e[0]:n.filters=[`and`,...e])}else n.filters=t.$filter;else n.filters=e(t.$filter);return t.$orderby&&(Array.isArray(t.$orderby)?n.sort=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),t.$skip!==void 0&&(n.skip=t.$skip),t.$top!==void 0&&(n.top=t.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw n?.status===404||n?.statusCode===404?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,`views/${t}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async aggregate(e,t){await this.connect();try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.filters=t.filter);let i=await this.client.analytics.query(r),a=Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[];if(a.length>0&&a.every(e=>e==null?!0:!(n in e&&e[n]!=null||t.field in e&&e[t.field]!=null))){let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}return a.map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}aggregateClientSide(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async getItems(e,t){return await this.connect(),await Promise.all(t.map(async t=>{let n=`${e}:${t}`;return this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n})}))}getCached(e){return this.metadataCache.getCachedSync(e)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(e){this.metadataCache.invalidate(e)}clearCache(){this.metadataCache.clear()}async uploadFile(e,t,n){await this.connect();let i=new FormData;i.append(`file`,t),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async uploadFiles(e,t,n){await this.connect();let i=new FormData;t.forEach((e,t)=>{i.append(`files`,e,e.name||`file-${t}`)}),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}getAuthHeaders(){let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e}};export{h as n,_ as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n,u as r}from"./vendor-react-B1k2FF9f.js";import{p as i}from"./framework-CoXA0nY6.js";import{o as a}from"./vendor-ui-utils-Dyl9EYZi.js";import{Cy as o,OD as s,Q as c}from"./ui-components-B7mlp0en.js";import{r as l}from"./src-D5NTzWsi.js";import{n as u,r as d,t as f}from"./index-CPatxDwz.js";function p(e,t){let n=t?.label||e,r=t?.description||e,i=[{type:`object-detail-tabs`,id:`${e}-tabs`,objectName:e}];return{type:`page`,name:`object-detail-${e}`,title:n,description:r,icon:`database`,pageType:`record_detail`,object:e,body:i}}var m=e(t(),1),h=n();function g({basePath:e,metadataType:t}){let n=r(),{objects:s,refresh:c}=i(),p=d(),g=(0,m.useMemo)(()=>(s||[]).map(u),[s]),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(!1),x=_??g,S=(0,m.useRef)(x),C=(0,m.useCallback)(r=>{n(`${e}/system/metadata/${t}/${r.name}`)},[n,e,t]),w=(0,m.useCallback)(async e=>{let t=S.current;if(v(e),S.current=e,!p){a.error(`Service unavailable — changes saved locally only`);return}let n=f.diffObjects(t,e);b(!0);try{if(n)n.type===`delete`?await p.deleteObject(n.object.name):await p.saveObject(n.object);else for(let t of e)await p.saveObject(t);await c();let t=n?n.type===`create`?`Object "${n.object.label||n.object.name}" created`:n.type===`update`?`Object "${n.object.label||n.object.name}" updated`:`Object "${n.object.label||n.object.name}" deleted`:`Object definitions updated`;a.success(t)}catch(e){v(t),S.current=t,a.error(e?.message||`Failed to save object changes`)}finally{b(!1)}},[p,c]);return(0,h.jsxs)(h.Fragment,{children:[y&&(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`object-saving-indicator`,children:[(0,h.jsx)(o,{className:`h-4 w-4 animate-spin`}),`Saving object changes…`]}),(0,h.jsx)(l,{objects:x,onObjectsChange:w,onSelectObject:C,showSystemObjects:!0})]})}var _=[{type:`app`,label:`Application`,pluralLabel:`Applications`,description:`Manage all configured applications`,icon:`layout-grid`,customRoute:`/system/apps`,countSource:`metadata`},{type:`object`,label:`Object`,pluralLabel:`Object Manager`,description:`Manage object definitions and field configurations`,icon:`database`,countSource:`metadata`,pageSchemaFactory:(e,t)=>p(e,t),listComponent:g},{type:`dashboard`,label:`Dashboard`,pluralLabel:`Dashboards`,description:`Manage dashboard layouts and widgets`,icon:`layout-dashboard`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`dashboard_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Dashboard`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`page`,label:`Page`,pluralLabel:`Pages`,description:`Manage custom page definitions`,icon:`file-text`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`page_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Page`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`report`,label:`Report`,pluralLabel:`Reports`,description:`Manage report configurations and templates`,icon:`bar-chart-3`,listMode:`grid`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`report_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Report`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]}];function v(e){return _.find(t=>t.type===e)}function y(){return _}var b=[{key:`name`,label:`Name`,required:!0,placeholder:`api_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`Display Label`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}];function x(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var S=new Map;function C(e){if(!e)return s;let t=S.get(e);if(t)return t;let n=x(e),r=e=>m.createElement(c,{name:n,fallback:s,...e});return r.displayName=`LucideIcon(${e})`,S.set(e,r),r}export{v as i,b as n,y as r,C as t};
1
+ import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n,u as r}from"./vendor-react-B1k2FF9f.js";import{p as i}from"./framework-CoXA0nY6.js";import{o as a}from"./vendor-ui-utils-Dyl9EYZi.js";import{DD as o,Sy as s,Z as c}from"./ui-components-DSSaN2w_.js";import{r as l}from"./src-DwuebCF9.js";import{n as u,r as d,t as f}from"./index-DTdi5Ufa.js";function p(e,t){let n=t?.label||e,r=t?.description||e,i=[{type:`object-detail-tabs`,id:`${e}-tabs`,objectName:e}];return{type:`page`,name:`object-detail-${e}`,title:n,description:r,icon:`database`,pageType:`record_detail`,object:e,body:i}}var m=e(t(),1),h=n();function g({basePath:e,metadataType:t}){let n=r(),{objects:o,refresh:c}=i(),p=d(),g=(0,m.useMemo)(()=>(o||[]).map(u),[o]),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(!1),x=_??g,S=(0,m.useRef)(x),C=(0,m.useCallback)(r=>{n(`${e}/system/metadata/${t}/${r.name}`)},[n,e,t]),w=(0,m.useCallback)(async e=>{let t=S.current;if(v(e),S.current=e,!p){a.error(`Service unavailable — changes saved locally only`);return}let n=f.diffObjects(t,e);b(!0);try{if(n)n.type===`delete`?await p.deleteObject(n.object.name):await p.saveObject(n.object);else for(let t of e)await p.saveObject(t);await c();let t=n?n.type===`create`?`Object "${n.object.label||n.object.name}" created`:n.type===`update`?`Object "${n.object.label||n.object.name}" updated`:`Object "${n.object.label||n.object.name}" deleted`:`Object definitions updated`;a.success(t)}catch(e){v(t),S.current=t,a.error(e?.message||`Failed to save object changes`)}finally{b(!1)}},[p,c]);return(0,h.jsxs)(h.Fragment,{children:[y&&(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`object-saving-indicator`,children:[(0,h.jsx)(s,{className:`h-4 w-4 animate-spin`}),`Saving object changes…`]}),(0,h.jsx)(l,{objects:x,onObjectsChange:w,onSelectObject:C,showSystemObjects:!0})]})}var _=[{type:`app`,label:`Application`,pluralLabel:`Applications`,description:`Manage all configured applications`,icon:`layout-grid`,customRoute:`/system/apps`,countSource:`metadata`},{type:`object`,label:`Object`,pluralLabel:`Object Manager`,description:`Manage object definitions and field configurations`,icon:`database`,countSource:`metadata`,pageSchemaFactory:(e,t)=>p(e,t),listComponent:g},{type:`dashboard`,label:`Dashboard`,pluralLabel:`Dashboards`,description:`Manage dashboard layouts and widgets`,icon:`layout-dashboard`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`dashboard_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Dashboard`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`page`,label:`Page`,pluralLabel:`Pages`,description:`Manage custom page definitions`,icon:`file-text`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`page_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Page`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`report`,label:`Report`,pluralLabel:`Reports`,description:`Manage report configurations and templates`,icon:`bar-chart-3`,listMode:`grid`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`report_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Report`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]}];function v(e){return _.find(t=>t.type===e)}function y(){return _}var b=[{key:`name`,label:`Name`,required:!0,placeholder:`api_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`Display Label`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}];function x(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var S=new Map;function C(e){if(!e)return o;let t=S.get(e);if(t)return t;let n=x(e),r=e=>m.createElement(c,{name:n,fallback:o,...e});return r.displayName=`LucideIcon(${e})`,S.set(e,r),r}export{v as i,b as n,y as r,C as t};