@objectstack/console 9.5.1 → 9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/assets/{AdapterProvider-BrKPQ1rE.js → AdapterProvider-o2n9dY2j.js} +1 -1
  2. package/dist/assets/{AiPendingActionsPage-BcncanbT.js → AiPendingActionsPage-DGAL-HJ9.js} +1 -1
  3. package/dist/assets/{ApiConsolePage-C6tVqeCx.js → ApiConsolePage-DNuInlzy.js} +1 -1
  4. package/dist/assets/{AppDocsIndex-D--pdm0E.js → AppDocsIndex-DtACBq8P.js} +1 -1
  5. package/dist/assets/{AppManagementPage-B66TgUPL.js → AppManagementPage-BSgP2T9T.js} +1 -1
  6. package/dist/assets/{ApprovalsInboxPage-C8mv1Yo5.js → ApprovalsInboxPage-jrTqrLxX.js} +1 -1
  7. package/dist/assets/{AuditLogPage-CS-Jundr.js → AuditLogPage-B_gxba-u.js} +1 -1
  8. package/dist/assets/{ComponentNavView-Br-wa130.js → ComponentNavView-BSV-rPCq.js} +1 -1
  9. package/dist/assets/ConsoleFloatingChatbot-B1xDv7X-.js +1 -0
  10. package/dist/assets/DashboardView-BNUhTJ8Y.js +1 -0
  11. package/dist/assets/{DashboardWidgetInspector-Cr6cJ0BC.js → DashboardWidgetInspector-CNmycNmj.js} +1 -1
  12. package/dist/assets/{DeveloperHubPage-B3I-35Xy.js → DeveloperHubPage-YvUkG7Lt.js} +1 -1
  13. package/dist/assets/{ExpressionProvider-CqfGEBur.js → ExpressionProvider-Cuv0RaiR.js} +1 -1
  14. package/dist/assets/{FlowRunsPage-CATcsy8B.js → FlowRunsPage-DdjGSDw1.js} +1 -1
  15. package/dist/assets/{IntegrationsPage-Cq1qq5jk.js → IntegrationsPage-C8k36Ie_.js} +1 -1
  16. package/dist/assets/{InterfaceListPage-OHu23CRA.js → InterfaceListPage-DTHEyaKG.js} +1 -1
  17. package/dist/assets/{ManagedByBadge-BodEaDXN.js → ManagedByBadge-B60ZX6y9.js} +1 -1
  18. package/dist/assets/{MarketplaceInstalledPage-B5oYOVdC.js → MarketplaceInstalledPage-DJN3P4aw.js} +1 -1
  19. package/dist/assets/{MarketplacePackagePage-DnmqDFCq.js → MarketplacePackagePage-BUrsYfA7.js} +1 -1
  20. package/dist/assets/{MarketplacePage-C5lziiq9.js → MarketplacePage-q23E8dYU.js} +1 -1
  21. package/dist/assets/{MetadataInspector-BMHaVCoM.js → MetadataInspector-zJtxyFau.js} +1 -1
  22. package/dist/assets/{MetadataProvider-Cvue7gQ0.js → MetadataProvider-BagIop6q.js} +1 -1
  23. package/dist/assets/PageView-M09zUJqv.js +1 -0
  24. package/dist/assets/{ProfilePage-BBeI_CPu.js → ProfilePage-0yyBZHjT.js} +1 -1
  25. package/dist/assets/PublicFormsPage-BPEDFiNo.js +1 -0
  26. package/dist/assets/{RecentItemsProvider-gLV-GFpQ.js → RecentItemsProvider-B76qldBH.js} +1 -1
  27. package/dist/assets/RecordDetailView-cj45YVH-.js +1 -0
  28. package/dist/assets/RecordFormPage-DqFdHPz8.js +1 -0
  29. package/dist/assets/{ReportDefaultInspector-CmSJUILm.js → ReportDefaultInspector-D5dIioUJ.js} +1 -1
  30. package/dist/assets/{ReportView-_NBbKT5l.js → ReportView-Cx-qFxJZ.js} +1 -1
  31. package/dist/assets/{RuntimeDraftBar-DroTFTnx.js → RuntimeDraftBar-Be6SQ4g6.js} +1 -1
  32. package/dist/assets/{SearchResultsPage-D9HdE2xf.js → SearchResultsPage-DkQMPMlE.js} +1 -1
  33. package/dist/assets/{SettingsHub-Ca4TQg_Q.js → SettingsHub-el09ZPJP.js} +1 -1
  34. package/dist/assets/{SettingsView-6GSnMLNA.js → SettingsView-BiYeb1nb.js} +1 -1
  35. package/dist/assets/{SystemHubPage-maebng1S.js → SystemHubPage-QSk3FL5a.js} +1 -1
  36. package/dist/assets/{data-adapter-SqbPGFBI.js → data-adapter-BtpuYbBh.js} +1 -1
  37. package/dist/assets/{framework-CVigpa4L.js → framework-ZJouI0cJ.js} +6 -6
  38. package/dist/assets/{highlighted-body-OFNGDK62-B0SlzSfX.js → highlighted-body-OFNGDK62-DfdyR_41.js} +1 -1
  39. package/dist/assets/index-B99f8h8i.js +4 -0
  40. package/dist/assets/index-BXu9hpEZ.css +2 -0
  41. package/dist/assets/infrastructure-CJNwTVno.js +3 -0
  42. package/dist/assets/{marketplaceApi-Cw1CUgrg.js → marketplaceApi-DCvJ2C6u.js} +1 -1
  43. package/dist/assets/{mergeServerFields-DKhjl-pc.js → mergeServerFields-DPrTk8u4.js} +2 -2
  44. package/dist/assets/mermaid-GHXKKRXX-BF-AoOMn.js +1 -0
  45. package/dist/assets/metadata-admin-DT8BohcC.js +19 -0
  46. package/dist/assets/{plugin-calendar-BWXBFRkE.js → plugin-calendar-CwYuZf8c.js} +1 -1
  47. package/dist/assets/plugin-charts-DhlEvpuy.js +7 -0
  48. package/dist/assets/{plugin-chatbot-CBg5Zd15.js → plugin-chatbot-CJsfoGAD.js} +45 -45
  49. package/dist/assets/plugin-dashboard-CGRjBe2V.js +5 -0
  50. package/dist/assets/plugin-form-C5yl9byI.js +1 -0
  51. package/dist/assets/plugin-gantt-C5hIQDHF.js +23 -0
  52. package/dist/assets/{plugin-grid-BsA9XQ8Q.js → plugin-grid-2QHjCxCx.js} +4 -4
  53. package/dist/assets/{plugin-kanban-DTWtfUzv.js → plugin-kanban-LtqKit9T.js} +1 -1
  54. package/dist/assets/{plugin-map-B-PDDoET.js → plugin-map-Cz9tJHoZ.js} +1 -1
  55. package/dist/assets/{plugin-markdown--e1MOP0x.js → plugin-markdown-_H-xFg2t.js} +1 -1
  56. package/dist/assets/{plugin-report-BTvuqkOa.js → plugin-report-DA6bVPuW.js} +2 -2
  57. package/dist/assets/{plugin-timeline-Dmqt8jd_.js → plugin-timeline-DjngAdR-.js} +1 -1
  58. package/dist/assets/plugin-view-BUsWmCh-.js +1 -0
  59. package/dist/assets/plugins-views-yfd0iHKg.js +4 -0
  60. package/dist/assets/resolveActionParams-ergReBd1.js +9 -0
  61. package/dist/assets/{skeletons-D42JPA2I.js → skeletons-BRDBm95C.js} +1 -1
  62. package/dist/assets/{src-B-bY4wJT.js → src-B5JRlZgC.js} +1 -1
  63. package/dist/assets/{types-HYNWZWMw.js → types-fX7qb4I3.js} +1 -1
  64. package/dist/assets/ui-components-Bs-DxYrW.js +42 -0
  65. package/dist/assets/{ui-layout-DM7b0Gu1.js → ui-layout-CswtJjnW.js} +1 -1
  66. package/dist/assets/{useActionModal-DcFjU7Dq.js → useActionModal-d8GNl1HP.js} +1 -1
  67. package/dist/assets/{vendor-markdown-DIJxJfmj.js → vendor-markdown-CyAGIM8D.js} +2 -2
  68. package/dist/assets/vendor-objectstack-BNd856rx.js +96 -0
  69. package/dist/assets/{vendor-sentry-Cv_7Tgs6.js → vendor-sentry-BIOhD5Kg.js} +14 -14
  70. package/dist/index.html +4 -4
  71. package/package.json +1 -1
  72. package/dist/assets/ConsoleFloatingChatbot-CIsrrZv4.js +0 -1
  73. package/dist/assets/DashboardView-HNhMjAZZ.js +0 -1
  74. package/dist/assets/PageView-H7j3JwJI.js +0 -1
  75. package/dist/assets/PublicFormsPage-Bhp5KfIY.js +0 -1
  76. package/dist/assets/RecordDetailView-CGxfnls1.js +0 -1
  77. package/dist/assets/RecordFormPage-B8sjq5K3.js +0 -1
  78. package/dist/assets/index-TlmJdKxQ.js +0 -4
  79. package/dist/assets/index-mrmp6qU6.css +0 -2
  80. package/dist/assets/infrastructure-ckitl7Ev.js +0 -3
  81. package/dist/assets/mermaid-GHXKKRXX-DOu_26de.js +0 -1
  82. package/dist/assets/metadata-admin-2GXysZST.js +0 -19
  83. package/dist/assets/plugin-charts-Ck5EMx6H.js +0 -7
  84. package/dist/assets/plugin-dashboard-DJturdHm.js +0 -5
  85. package/dist/assets/plugin-form-CM6RvRf2.js +0 -1
  86. package/dist/assets/plugin-gantt-DO7NQ-4h.js +0 -23
  87. package/dist/assets/plugin-view-CmAdMV7R.js +0 -1
  88. package/dist/assets/plugins-views-BP1sk9hy.js +0 -4
  89. package/dist/assets/resolveActionParams-CWIOgcoF.js +0 -9
  90. package/dist/assets/ui-components-BK0FqwOC.js +0 -42
  91. package/dist/assets/vendor-objectstack-RB3xvhcR.js +0 -102
package/dist/index.html CHANGED
@@ -18,12 +18,12 @@
18
18
  <script>
19
19
  window.process = window.process || { env: { NODE_ENV: 'development' }, version: '', platform: 'browser' };
20
20
  </script>
21
- <script type="module" crossorigin src="./assets/index-TlmJdKxQ.js"></script>
21
+ <script type="module" crossorigin src="./assets/index-B99f8h8i.js"></script>
22
22
  <link rel="stylesheet" crossorigin href="./assets/ui-components-BL3SEdAz.css">
23
23
  <link rel="stylesheet" crossorigin href="./assets/plugin-dashboard-DnNKJB60.css">
24
- <link rel="stylesheet" crossorigin href="./assets/index-mrmp6qU6.css">
25
- <link rel="modulepreload" href="./assets/framework-CVigpa4L.js" />
26
- <link rel="modulepreload" href="./assets/ui-components-BK0FqwOC.js" />
24
+ <link rel="stylesheet" crossorigin href="./assets/index-BXu9hpEZ.css">
25
+ <link rel="modulepreload" href="./assets/framework-ZJouI0cJ.js" />
26
+ <link rel="modulepreload" href="./assets/ui-components-Bs-DxYrW.js" />
27
27
  <link rel="modulepreload" href="./assets/vendor-radix-CSVEhP0L.js" />
28
28
  <link rel="modulepreload" href="./assets/vendor-react-DR370ovB.js" />
29
29
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/console",
3
- "version": "9.5.1",
3
+ "version": "9.7.0",
4
4
  "description": "Prebuilt Console SPA pinned to this @objectstack/framework release. Source of truth: @object-ui/console (https://github.com/objectstack-ai/objectui).",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/objectstack-ai/framework/tree/main/packages/console",
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,l as n,t as r,u as i}from"./vendor-react-DR370ovB.js";import{r as a}from"./framework-CVigpa4L.js";import{Bt as o,Ht as s,Ut as c,Vt as l,Wt as u,ai as d,hr as f,vi as p,w as m}from"./ui-components-BK0FqwOC.js";import{r as h}from"./vendor-ui-utils-rQOI1gAo.js";import{a as g,i as _,n as v}from"./MetadataProvider-Cvue7gQ0.js";import{a as y,d as b,f as x,p as S,r as C,t as ee,u as w}from"./plugin-chatbot-CBg5Zd15.js";import{i as T}from"./runtime-config-BeHVOPm3.js";import{a as E,i as te,o as ne,r as D}from"./index-TlmJdKxQ.js";var O=e(t(),1),k=r(),A={data_chat:{zh:`智能助手`,en:`Assistant`},metadata_assistant:{zh:`元数据开发助手`,en:`Metadata Assistant`}};function j(e,t,n){let r=t?A[t]:void 0;return r?e?r.zh:r.en:n}function re(e,t,n,r,i){let a=(e??``).toLowerCase().startsWith(`zh`),o=j(a,n,r),s=i.slice(0,2).map(e=>e.label||e.name);if(a){let e=[s[0]?`查询最近创建的${s[0]}`:`帮我查询最近的数据`,s[0]?`统计${s[0]}的总数量`:`统计各对象的记录数量`,s[1]?`${s[1]}有哪些字段?`:`当前应用里有哪些数据对象?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`你好,我是${o}`,emptyDescription:`随时帮你查询和分析「${t}」中的数据。试试下面的问题,或直接输入你的需求。`,clear:`清空对话`,sendHint:`发送`,agentActivity:`执行过程`,toolCompleted:`已完成`,toolRunning:`运行中`,toolAwaitingApproval:`等待确认`,toolFailed:`失败`,toolDetailsHidden:`已隐藏工具参数和原始结果,仅保留过程摘要。`,copy:`复制`,copied:`已复制`,regenerate:`重新生成`,model:`模型`,submit:`发送`,uploadFiles:`上传文件`,stopResponse:`停止生成`,trace:`调试 trace`,viewTrace:`查看调试 trace`},placeholder:`向${o}提问…`,loadingPlaceholder:`正在加载助手…`,title:`${t} 智能助手`,newChat:`开启新对话`,share:`分享对话`,reviewDraft:e=>`查看 ${e} 项变更`,publishDrafts:`发布`,published:`已发布`,publishOk:`已发布,对象已生效。`,publishFailed:`发布失败`,seedWarn:`已发布,但部分示例数据未能载入。`,openBuiltApp:`打开应用`,suggestions:e}}let c=[s[0]?`Show the latest ${s[0]}`:`Show my most recent records`,s[0]?`How many ${s[0]} are there?`:`Count records by status`,s[1]?`What fields does ${s[1]} have?`:`What data can I work with here?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`Hi, I'm ${o}`,emptyDescription:`I can help you query and analyze your ${t} data. Try a prompt below, or just type your question.`,clear:`Clear`,sendHint:`to send`,agentActivity:`Agent activity`,toolCompleted:`Completed`,toolRunning:`Running`,toolAwaitingApproval:`Awaiting approval`,toolFailed:`Failed`,toolDetailsHidden:`Tool inputs and raw results are hidden in this view.`,copy:`Copy`,copied:`Copied`,regenerate:`Regenerate`,model:`Model`,submit:`Submit`,uploadFiles:`Upload files`,stopResponse:`Stop response`,trace:`trace`,viewTrace:`View trace`},placeholder:`Ask ${o}...`,loadingPlaceholder:`Loading assistant...`,title:`${t} Assistant`,newChat:`New chat`,share:`Share conversation`,reviewDraft:e=>`Review ${e} change${e===1?``:`s`}`,publishDrafts:`Publish`,published:`Published`,publishOk:`Published — objects are now live.`,publishFailed:`Publish failed`,seedWarn:`Published, but some sample data failed to load.`,openBuiltApp:`Open app`,suggestions:c}}var M=`/api/v1/ai`;function N(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${M}`}function ie(e,t){if(!e||e.type!==`object`)return null;let n=e.label||e.name||`this object`;return(t??``).toLowerCase().startsWith(`zh`)?[`为「${n}」补充字段`,`为「${n}」建议校验规则`,`添加一个状态选项字段`]:[`Add fields to ${n}`,`Suggest validations for ${n}`,`Add a status picklist field`]}var P=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`,`metadata`]);function F(e){try{return decodeURIComponent(e)}catch{return e}}function I(e,t){let n=e.split(`/`).filter(Boolean),r=n.indexOf(`apps`);if(r===-1||n.length<r+3)return{};let i=F(n[r+2]);if(P.has(i)||!t.some(e=>e.name===i))return{};let a=n[r+3]?F(n[r+3]):void 0,o=a&&a!==`new`?a:void 0;return{objectName:i,...o?{recordId:o}:{}}}function L({appLabel:e,appName:t,objects:r,agents:b,agentsLoading:w,activeAgent:E,onAgentChange:A,showAgentPicker:j,chatApi:M,apiBase:N,defaultOpen:P=!1,conversationId:F,initialMessages:L}){let{language:R}=a(),z=i(),B=n(),V=O.useMemo(()=>I(B.pathname,r),[B.pathname,r]),{editor:H}=g(),U=O.useMemo(()=>!L||L.length===0?[]:S(L),[L]),W=O.useMemo(()=>b.find(e=>e.name===E)?.label??E??e,[b,E,e]),G=O.useMemo(()=>re(R,e,E,W,r),[R,e,E,W,r]),K=O.useMemo(()=>ie(H,R),[H,R]),{messages:q,isLoading:J,error:ae,sendMessage:Y,stop:oe,reload:se,clear:X}=x({api:M,conversationId:F,body:{context:{activeApp:e,appName:t,objects:r.map(e=>({name:e.name,label:e.label})),agentName:E,autoPublishAiBuilds:T().features.autoPublishAiBuilds,...V.objectName?{objectName:V.objectName}:{},...V.recordId?{recordId:V.recordId}:{},...H?{editing:H}:{}}},initialMessages:U,autoResponse:!M,autoResponseText:r.length>0?`I can help you work with ${r.map(e=>e.label||e.name).join(`, `)}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600});O.useEffect(()=>{ne(F,te(q))},[F,q]);let Z=ee({messages:q,apiBase:N,continueConversation:e=>{Y(e)}}),Q=j&&b.length>1?(0,k.jsxs)(o,{value:E,onValueChange:A,disabled:w,children:[(0,k.jsx)(c,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,k.jsx)(u,{placeholder:`Choose agent...`})}),(0,k.jsx)(l,{align:`end`,children:b.map(e=>(0,k.jsxs)(s,{value:e.name,className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,k.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[ce,$]=O.useState(!1),le=O.useMemo(()=>N.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[N]),ue=(0,k.jsxs)(k.Fragment,{children:[q.length>0?(0,k.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.newChat,title:G.newChat,"data-testid":`floating-chatbot-new`,onClick:X,children:(0,k.jsx)(d,{className:`h-4 w-4`})}):null,F?(0,k.jsx)(f,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.share,title:G.share,"data-testid":`floating-chatbot-share`,onClick:()=>$(!0),children:(0,k.jsx)(p,{className:`h-4 w-4`})}):null]});return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(C,{floatingConfig:{position:`bottom-right`,defaultOpen:P,panelWidth:420,panelHeight:560,title:G.title,triggerSize:56},headerExtra:Q,headerActions:ue,messages:q,labels:G.labels,showAvatars:!0,hideClearBar:!0,assistantAvatarFallback:G.agentLabel,suggestions:q.length===0?K??G.suggestions:void 0,placeholder:E?G.placeholder:w?G.loadingPlaceholder:G.placeholder,onSendMessage:e=>Y(e),onClear:X,onStop:J?oe:void 0,onReload:se,isLoading:J,error:ae,enableMarkdown:!0,onToolApprove:Z.decide,toolDecisions:Z.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onReviewDraft:e=>{e[0]&&_(e[0])},toolReviewLabel:G.reviewDraft,onOpenBuiltApp:e=>z(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:G.openBuiltApp,onPreviewDraftApp:(e,t)=>z(t?.materialized?`/apps/${encodeURIComponent(e)}`:`/apps/${encodeURIComponent(e)}?preview=draft`),onDraftArtifacts:e=>{for(let t of e)v(t)},fetchPendingDraftCount:D,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;i&&i.success===!1?h.warning(G.seedWarn,{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):h.success(G.publishOk);let a=(n?.data?.published??n?.published??[]).find(e=>e?.type===`app`&&e?.name);return a?.name&&z(`/apps/${encodeURIComponent(a.name)}`),{ok:!0,health:y(n)}}catch(e){return h.error(G.publishFailed,{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:G.publishDrafts,publishedLabel:G.published,autoPublishDrafts:T().features.autoPublishAiBuilds}),F&&(0,k.jsx)(m,{open:ce,onOpenChange:$,objectName:`ai_conversations`,recordId:F,recordLabel:`this conversation`,apiBase:le})]})}function R({appLabel:e,appName:t,objects:n,apiBase:r,defaultAgent:i,showAgentPicker:a,defaultOpen:o=!1,userId:s}){let c=O.useMemo(()=>N(r),[r]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},u=l.VITE_AI_DEFAULT_AGENT,d=a??l.VITE_AI_SHOW_AGENT_PICKER===`true`,{agents:f,isLoading:p,error:m}=b({apiBase:c}),[h,g]=O.useState(void 0);O.useEffect(()=>{if(!h&&f.length>0){let e=w(f,i??u);e&&g(e)}},[f,h,i,u]);let _=h?`${c}/agents/${encodeURIComponent(h)}/chat`:void 0,{conversationId:v,initialMessages:y}=E({userId:s,scope:h,apiBase:c});return(0,k.jsx)(L,{appLabel:e,appName:t,objects:n,agents:f,agentsLoading:p,agentsError:m,activeAgent:h,onAgentChange:g,showAgentPicker:d,chatApi:_,apiBase:c,defaultOpen:o,conversationId:v,initialMessages:y},`${_??`local`}:${v??`pending`}`)}export{R as default};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,t as i}from"./vendor-react-DR370ovB.js";import{f as a}from"./infrastructure-ckitl7Ev.js";import{T as o,r as s,w as c}from"./framework-CVigpa4L.js";import{As as l,Ba as u,Bn as d,Es as f,H as p,Hi as m,Hn as h,Ln as g,Qr as _,R as v,Rn as y,Sr as b,Vn as x,Vr as S,Yi as C,dc as w,hr as T,js as E,rc as D,z as O,za as k,zn as ee,zr as A}from"./ui-components-BK0FqwOC.js";import{r as j}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-BrKPQ1rE.js";import{n as te}from"./plugin-form-CM6RvRf2.js";import"./MetadataProvider-Cvue7gQ0.js";import{r as ne}from"./ExpressionProvider-CqfGEBur.js";import{C as re,r as M}from"./mergeServerFields-DKhjl-pc.js";import{r as N}from"./utils-bipVuqQL.js";import{n as ie,r as ae,t as oe}from"./MetadataInspector-BMHaVCoM.js";import{r as se,t as P}from"./RuntimeDraftBar-DroTFTnx.js";import{n as ce}from"./skeletons-D42JPA2I.js";import{n as le}from"./plugin-dashboard-DJturdHm.js";import{n as F,t as I}from"./DashboardWidgetInspector-Cr6cJ0BC.js";var L=e(n(),1),R=i();function ue({open:e,onClose:t,schema:n,selectedWidgetId:r,onSelectWidget:i,onSave:a,onChange:o,onRemoveWidget:c,name:l,metadataClient:u,onAfterChange:d}){let{t:f}=s(),p=(0,L.useMemo)(()=>M(),[]),[m,h]=(0,L.useState)(!1),[g,_]=(0,L.useState)(0),v=(0,L.useCallback)(e=>{h(!0),o({...n??{},...e})},[n,o]),y=(0,L.useCallback)(e=>{o(e),h(!1)},[o]),x=(0,L.useCallback)(e=>{i(e&&e.kind===`widget`?e.id:null)},[i]),C=Array.isArray(n?.widgets)?n.widgets:[],w=r?C.find(e=>e?.id===r):null;if(!e)return null;let E=typeof n?.name==`string`?n.name:``,O=w?f(`widget.editor.title`,{defaultValue:`Edit widget`}):f(`dashboard.editor.title`,{defaultValue:`Edit dashboard`});return(0,R.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`dashboard-config-panel`,role:`complementary`,"aria-label":O,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[w&&(0,R.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>i(null),className:`h-7 w-7 p-0`,"aria-label":f(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),title:f(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),"data-testid":`dashboard-config-back`,children:(0,R.jsx)(D,{className:`h-4 w-4`})}),(0,R.jsx)(`div`,{className:`text-sm font-medium truncate`,children:O})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&c&&(0,R.jsx)(T,{variant:`ghost`,size:`sm`,onClick:()=>c(r),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"aria-label":f(`widget.editor.delete`,{defaultValue:`Delete widget`}),title:f(`widget.editor.delete`,{defaultValue:`Delete widget`}),"data-testid":`widget-delete-button`,children:(0,R.jsx)(S,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(T,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":f(`common.close`,{defaultValue:`Close`}),"data-testid":`dashboard-config-close`,children:(0,R.jsx)(b,{className:`h-4 w-4`})})]})]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:w?(0,R.jsx)(I,{type:`dashboard`,name:E,draft:n??{},selection:{kind:`widget`,id:r},onPatch:v,onClearSelection:()=>i(null),onSelectionChange:x,readOnly:!1,locale:p}):(0,R.jsx)(F,{type:`dashboard`,name:E,draft:n??{},onPatch:v,onSelectionChange:x,readOnly:!1,locale:p})}),(0,R.jsxs)(`div`,{"data-testid":`dashboard-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,R.jsx)(P,{type:`dashboard`,name:l||E||void 0,metadataClient:u,dirty:m,onResume:y,savedSignal:g,onAfterChange:d}),(0,R.jsx)(T,{size:`sm`,onClick:()=>{a(n??{}),h(!1),_(e=>e+1)},"data-testid":`dashboard-config-save`,children:f(`common.save`,{defaultValue:`Save`})})]})]})}var z=t({DashboardView:()=>U}),B=[{type:`metric`,label:`KPI Metric`,Icon:A},{type:`bar`,label:`Bar Chart`,Icon:E},{type:`line`,label:`Line Chart`,Icon:l},{type:`pie`,label:`Pie Chart`,Icon:f},{type:`table`,label:`Table`,Icon:_},{type:`pivot`,label:`Pivot`,Icon:k}],V=0;function H(){return V+=1,`widget_${Date.now()}_${V}`}function de(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:H()})}}function fe(e){let t=B.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function U({dataSource:e}){let{dashboardName:t}=r(),{showDebug:n}=ie(),i=c(),l=re(),{t:f}=s(),{dashboardLabel:_,dashboardDescription:b}=w(),{user:S}=a(),E=S?.role===`admin`,[D,k]=(0,L.useState)(!0),[A,M]=(0,L.useState)(!1),[P,F]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),V=(0,L.useCallback)(e=>{z(t=>(t&&t.resolve(e),null))},[]),U=(0,L.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;z({schema:n,resolve:t})}),[]),pe=(0,L.useMemo)(()=>({export_dashboard_pdf:async()=>{j.info(f(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return j.error(f(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(j.info(f(`dashboardActions.forecastSoon`)),{success:!0})}),[f]);(0,L.useEffect)(()=>{k(!0),J(null),M(!1),F(null),queueMicrotask(()=>k(!1))},[t]);let{dashboards:me,objects:W,refresh:G}=o(),{app:he}=ne(),K=ae(me,t,he?._packageId),[q,J]=(0,L.useState)(null);(0,L.useEffect)(()=>{A||J(null)},[K]);let Y=(0,L.useCallback)(async e=>{try{l&&await se(`dashboard`,t,e,{metadataClient:l}),G().catch(()=>{})}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`[DashboardView] Auto-save failed:`,e),j.error(`Failed to save dashboard: ${t}`)}},[l,t,G]),ge=(0,L.useCallback)(()=>{J(de(K)),M(!0)},[K]),_e=(0,L.useCallback)(()=>{M(!1),F(null)},[]),ve=(0,L.useCallback)(e=>{if(!q)return;let t=H(),n={id:t,title:fe(e),type:e,layout:{x:0,y:q.widgets?.length??0,w:q.columns??2,h:1}},r={...q,widgets:[...q.widgets||[],n]};J(r),Y(r),F(t)},[q,Y]),ye=(0,L.useCallback)(e=>{if(!q)return;let t={...q,widgets:q.widgets.filter(t=>t.id!==e)};J(t),Y(t),P===e&&F(null)},[q,P,Y]),X=(0,L.useCallback)(e=>{let t=q||K;if(!t)return;let n={...t,widgets:e};J(n),Y(n)},[q,K,Y]),be=(q||K)??null,Z=(0,L.useMemo)(()=>new Set((W||[]).map(e=>e?.name).filter(Boolean)),[W]),Q=q||K,$=(0,L.useMemo)(()=>{if(!Q||Z.size===0)return Q;let e=Q.widgets;if(!Array.isArray(e)||e.length===0)return Q;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?Z.has(t):!0});return t.length===e.length?Q:{...Q,widgets:t}},[Q,Z]);return D?(0,R.jsx)(ce,{}):K?(0,R.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,R.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,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=N(($||K).title,f),t=N(K.label,f),n=_({name:K.name,label:t});return(0,R.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||K.name})})(),(()=>{let e=($||K).description??K.description,t=b({name:K.name,description:N(e,f)});return t?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[A&&(0,R.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:B.map(({type:e,label:t,Icon:n})=>(0,R.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>ve(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,R.jsx)(m,{className:`h-3 w-3`}),(0,R.jsx)(n,{className:`h-3 w-3`})]},e))}),E&&(0,R.jsxs)(`button`,{type:`button`,onClick:ge,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,R.jsx)(C,{className:`h-3.5 w-3.5`}),f(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,R.jsx)(le,{schema:$,dataSource:e,designMode:A,selectedWidgetId:P,onWidgetClick:F,onWidgetsReorder:X,modalHandler:U,scriptHandlers:pe,hideHeaderText:!0})}),(0,R.jsx)(ue,{open:A&&E,onClose:_e,schema:be,selectedWidgetId:P,onSelectWidget:F,onSave:Y,onChange:J,onRemoveWidget:ye,name:t,metadataClient:l,onAfterChange:()=>G().catch(()=>{})}),(0,R.jsx)(oe,{open:n,sections:[{title:`Dashboard Configuration`,data:$}]})]}),I&&I.schema?.objectName?(0,R.jsx)(te,{schema:{type:`object-form`,formType:`modal`,objectName:I.schema.objectName,mode:I.schema.mode||`create`,recordId:I.schema.recordId,title:I.schema.title,description:I.schema.description,fields:I.schema.fields,open:!0,onOpenChange:e=>{e||V({success:!1})},onSuccess:e=>{V({success:!0,reload:!0,data:e})},onCancel:()=>{V({success:!1})},showSubmit:!0,showCancel:!0},dataSource:i}):I?(0,R.jsx)(g,{open:!0,onOpenChange:e=>{e||V({success:!1})},children:(0,R.jsxs)(y,{children:[(0,R.jsxs)(x,{children:[(0,R.jsx)(h,{children:I.schema?.title||f(`actionDialog.defaultActionTitle`)}),I.schema?.description&&(0,R.jsx)(ee,{children:I.schema.description})]}),(0,R.jsxs)(d,{children:[(0,R.jsx)(T,{variant:`outline`,onClick:()=>V({success:!1}),children:f(`actionDialog.cancel`)}),(0,R.jsx)(T,{onClick:()=>V({success:!0}),children:f(`actionDialog.ok`)})]})]})}):null]}):(0,R.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,R.jsxs)(v,{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)(u,{className:`h-6 w-6 text-muted-foreground`})}),(0,R.jsx)(p,{children:f(`empty.dashboardNotFound`)}),(0,R.jsx)(O,{children:f(`empty.dashboardNotFoundDescription`,{name:t})})]})})}export{z as t};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,l as i,p as a,t as o,u as s}from"./vendor-react-DR370ovB.js";import{f as c,m as l}from"./infrastructure-ckitl7Ev.js";import{B as u,O as d,T as f,r as p,w as m}from"./framework-CVigpa4L.js";import{H as h,R as g,So as _,Yi as v,dc as y,z as b}from"./ui-components-BK0FqwOC.js";import{r as x}from"./vendor-ui-utils-rQOI1gAo.js";import"./MetadataProvider-Cvue7gQ0.js";import{r as S}from"./ExpressionProvider-CqfGEBur.js";import{n as C,r as w,t as T}from"./MetadataInspector-BMHaVCoM.js";import{t as E}from"./InterfaceListPage-OHu23CRA.js";import{a as D,i as O,n as k,r as A,t as j}from"./resolveActionParams-CWIOgcoF.js";var M=e(n(),1),N=o(),P={id:`current-user`,name:`Demo User`};function F(e){let{dataSource:t,objects:n,objectName:r,onRefresh:i}=e,a=s(),{user:o,activeOrganization:u}=c(),{fieldLabel:d,fieldOptionLabel:f,actionParamText:p}=y(),m=(0,M.useMemo)(()=>r?n?.find(e=>e.name===r):void 0,[n,r]),h=r||m?.name,g=(0,M.useCallback)(()=>{i?.()},[i]),[_,v]=(0,M.useState)({open:!1,message:``}),[b,S]=(0,M.useState)({open:!1,params:[]}),[C,w]=(0,M.useState)({open:!1}),[T,E]=(0,M.useState)(null),F=(0,M.useRef)(new Set),I=(0,M.useCallback)((e,t)=>new Promise(n=>{w({open:!0,spec:e,data:t,resolve:n})}),[]),L=(0,M.useCallback)((e,t)=>new Promise(n=>{v({open:!0,message:e,options:t,resolve:n})}),[]),R=(0,M.useCallback)((e,t)=>new Promise(i=>{let a=t?.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,o=j(e,{objectName:r||m?.name||``,objects:n||[],fieldLabel:d,fieldOptionLabel:f,row:a}),s=r||m?.name;S({open:!0,params:o.map(e=>({...e,label:p(s,t?.name,e.name,`label`,e.label)??e.label,placeholder:p(s,t?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:p(s,t?.name,e.name,`helpText`,e.helpText)??e.helpText})),title:t?.label||t?.title,description:t?.description,resolve:i})}),[r,m,n,d,f,p]),z=o?{id:o.id,name:o.name,avatar:o.image}:P,B=(0,M.useCallback)((e,t)=>{t?.type===`error`?x.error(e):x.success(e)},[]),V=(0,M.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):a(e)},[a]),H=(0,M.useMemo)(()=>l(),[]),U=(0,M.useCallback)(async e=>{try{let n=e.target||e.name,r=e.params||{},i=typeof n==`string`?n:``;if(i.startsWith(`/`)||/^https?:\/\//i.test(i)){let t={...r},n=t._rowRecord;delete t._rowRecord;let a=i;n&&/\{[a-z_][a-z0-9_]*\}/i.test(a)&&(a=a.replace(/\{([a-z_][a-z0-9_]*)\}/gi,(e,t)=>{let r=n[t];return r==null?``:encodeURIComponent(String(r))}));let o=a.startsWith(`http`)?a:`${a}`,s=e.bodyShape&&typeof e.bodyShape==`object`&&e.bodyShape.wrap?e.bodyShape.wrap:void 0,c=s?{[s]:t}:{...t};if(n&&e.recordIdParam){let t=n[e.recordIdField||`id`];t!=null&&(c[e.recordIdParam]=t)}/\/api\/v1\/auth\//.test(a)&&!c.organizationId&&u?.id&&(c.organizationId=u.id),e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(c,e.bodyExtra);let l=(e.method||`POST`).toUpperCase(),d={method:l,headers:{"Content-Type":`application/json`},credentials:`include`};l!==`GET`&&l!==`DELETE`&&(d.body=JSON.stringify(c));let f=await H(o,d);if(!f.ok){let e=`HTTP ${f.status}`;try{let t=await f.json();e=t?.error||t?.message||e}catch{}return{success:!1,error:e}}let p=await f.json().catch(()=>({}));return e.refreshAfter!==!1&&g(),{success:!0,data:p,reload:e.refreshAfter!==!1}}let a=e.objectName||h;a&&typeof t?.execute==`function`?await t.execute(a,n,r):a&&r.recordId&&Object.keys(r).length>1&&typeof t?.update==`function`&&await t.update(a,r.recordId,r);let o=e.refreshAfter!==!1;return o&&g(),{success:!0,reload:o}}catch(e){return{success:!1,error:e.message}}},[t,h,H,u,g]),W=(0,M.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No flow target provided for flow action`};try{let r={...e.params||{}},i=r._rowRecord;delete r._rowRecord;let a=r.recordId??i?.id;if(a==null){let e=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(e.length===1)a=e[0]?.id;else if(e.length>1)return{success:!1,error:`This flow runs on a single record — select exactly one row.`}}a!=null&&r.recordId==null&&(r.recordId=a);let o=await H(`/api/v1/automation/${encodeURIComponent(n)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,objectName:e.objectName||h,params:r})}),s=await o.json().catch(()=>null);if(!o.ok||s&&s.success===!1)return{success:!1,error:s?.error||`Flow "${n}" failed (HTTP ${o.status})`};let c=s?.data??{};if(c.status===`paused`&&c.screen)return E({flowName:n,runId:c.runId,screen:c.screen}),{success:!0};let l=e.refreshAfter!==!1;return l&&g(),{success:!0,data:s?.data,reload:l}}catch(e){return{success:!1,error:e.message}}},[H,h,g]),G=(0,M.useCallback)(async(e,t)=>{let n=e.target||e.name;if(!n)return{success:!1,error:`No action target provided`};let r=e.params&&!Array.isArray(e.params)?{...e.params}:{},i=r._rowRecord;delete r._rowRecord;let a=e.recordIdField||`id`,o=r.recordId??i?.[a];if(o==null){let e=Array.isArray(t?.selectedRecords)?t.selectedRecords:[];if(e.length===1)o=e[0]?.[a];else if(e.length>1)return{success:!1,error:`This action runs on a single record — select exactly one row.`}}let s=`${n}:${o??``}`;if(F.current.has(s))return{success:!1,error:`Action already in progress`};F.current.add(s);let c=null;if(e.opensInNewTab)try{c=window.open(`about:blank`,`_blank`),c&&(c.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),c.document.close())}catch{c=null}try{let t=typeof e.newTabUrl==`string`?e.newTabUrl:``;if(e.opensInNewTab&&t){if(o==null){if(c)try{c.close()}catch{}return{success:!1,error:`This action runs on a single record — no record id available.`}}let n=`${window.location.origin}${t.replace(`{recordId}`,encodeURIComponent(String(o)))}`;if(c)try{c.location.href=n}catch{try{c.close()}catch{}window.location.href=n}else{let e=null;try{e=window.open(n,`_blank`)}catch{e=null}e||x(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(n,`_blank`)}catch{window.location.href=n}}},duration:1e4})}return e.refreshAfter===!0&&g(),{success:!0}}let i=e.objectName||h||`global`,a=await H(`/api/v1/actions/${encodeURIComponent(i)}/${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:o,params:r})}),s=await a.json().catch(()=>null);if(!a.ok||s&&s.success===!1){let e=s?.error||`Action "${n}" failed (HTTP ${a.status})`;if(c)try{c.close()}catch{}return x.error(e),{success:!1,error:e}}let l=e.refreshAfter!==!1;l&&g();let u=s?.data,d=u&&typeof u==`object`&&typeof u.redirectUrl==`string`?u.redirectUrl:null;if(d)if(c)try{c.location.href=d}catch{try{c.close()}catch{}window.location.href=d}else{let e=null;try{e=window.open(d,`_blank`)}catch{e=null}e||x(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(d,`_blank`)}catch{window.location.href=d}}},duration:1e4})}else if(c)try{c.close()}catch{}return{success:!0,data:u,reload:l}}catch(e){if(c)try{c.close()}catch{}let t=e.message;return x.error(t),{success:!1,error:t}}finally{F.current.delete(s)}},[H,h,g]);return{confirmHandler:L,toastHandler:B,navigateHandler:V,paramCollectionHandler:R,resultDialogHandler:I,apiHandler:U,flowHandler:W,serverActionHandler:G,authFetch:H,actionProviderProps:(0,M.useMemo)(()=>({context:{...r?{objectName:r}:{},user:z,apiBase:``,activeOrganization:u?{id:u.id,slug:u.slug,name:u.name}:null},onConfirm:L,onToast:B,onNavigate:V,onParamCollection:R,onResultDialog:I,handlers:{api:U,flow:W,script:G,modal:G}}),[r,z,u,L,B,V,R,I,U,W,G]),dialogs:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(D,{state:_,onOpenChange:e=>{e||v({open:!1,message:``})}}),(0,N.jsx)(O,{state:b,onOpenChange:e=>{e||S({open:!1,params:[]})}}),(0,N.jsx)(A,{state:C,onAcknowledge:()=>{C.resolve?.(),w({open:!1})}}),(0,N.jsx)(k,{state:T,authFetch:H,baseUrl:``,onClose:()=>E(null),onComplete:()=>{E(null),g()}})]})}}function I({children:e,...t}){let n=F(t);return(0,N.jsxs)(d,{...n.actionProviderProps,children:[e,n.dialogs]})}var L=t({PageView:()=>R});function R(){let{t:e}=p(),{pageName:t}=r(),[n]=a(),{showDebug:o}=C(),l=s(),d=i(),{user:y}=c(),x=y?.role===`admin`,{pages:D,objects:O}=f(),{app:k}=S(),A=m(),[j,P]=(0,M.useState)(0),F=w(D,t,k?._packageId);if(!F)return(0,N.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,N.jsxs)(g,{children:[(0,N.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,N.jsx)(_,{className:`h-6 w-6 text-muted-foreground`})}),(0,N.jsx)(h,{children:e(`empty.pageNotFound`)}),(0,N.jsx)(b,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let L=Object.fromEntries(n.entries()),R=d.pathname.match(/\/apps\/([^/]+)/)?.[1],z=x&&!!R&&!!t;return(0,N.jsx)(I,{dataSource:A,objects:O,onRefresh:()=>P(e=>e+1),children:(0,N.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,N.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:[z&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{z&&l(`/apps/${R}/metadata/page/${encodeURIComponent(t)}`)},className:`absolute right-3 top-3 z-30 inline-flex h-7 w-7 items-center justify-center rounded-md border border-input bg-background/90 text-muted-foreground shadow-sm backdrop-blur hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-in-studio-button`,title:e(`common.editInStudio`,{defaultValue:`Edit in studio`}),"aria-label":e(`common.editInStudio`,{defaultValue:`Edit in studio`}),children:(0,N.jsx)(v,{className:`h-3.5 w-3.5`})}),F.interfaceConfig?.source?(0,N.jsx)(E,{page:F},j):(0,N.jsx)(u,{schema:{...F,type:F.type||`page`,context:{...F.context,params:L,refreshKey:j}}},j)]}),(0,N.jsx)(T,{open:o,sections:[{title:`Page Configuration`,data:F}]})]})})}export{F as n,L as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{w as r}from"./framework-CVigpa4L.js";import{$n as i,Bn as a,Fo as o,Hi as ee,Hn as s,Ia as te,Jn as ne,Jo as re,Li as ie,Ln as c,Pi as ae,Qo as oe,Rn as l,Vn as u,Xn as se,Yn as ce,Zn as le,bi as ue,ct as d,dt as f,hr as p,lt as m,nn as h,on as g,ot as de,qn as fe,st as pe,ut as me,zn as _}from"./ui-components-BK0FqwOC.js";import{r as v}from"./vendor-ui-utils-rQOI1gAo.js";import"./index-TlmJdKxQ.js";var y=e(t(),1),b=n();function he(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function x(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function S(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[S,ge]=(0,y.useState)([]),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(null),[_e,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(!1),[ve,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(`thank-you`),[V,H]=(0,y.useState)(``),[U,W]=(0,y.useState)(``),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=async()=>{if(!e?.meta?.getItems){E(`meta.getItems is not available on this client`),w(!1);return}w(!0),E(null);try{let t=await e.meta.getItems(`view`),r=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[],i=[],a=[];for(let e of r){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,r=n?.publicLink,o=he(r);n?.allowAnonymous&&o&&r?i.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:r,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}n(i),ge(a)}catch(e){E(e?.message??String(e))}finally{w(!1)}};(0,y.useEffect)(()=>{Y()},[]);let X=typeof window<`u`?window.location.origin:``,Z=e=>`${X}/console/f/${e}`,ye=e=>`<iframe src="${Z(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${Z(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,Q=async(e,t)=>{try{await navigator.clipboard.writeText(t),v.success(`Copied ${e}`)}catch{v.error(`Clipboard unavailable`)}},xe=async()=>{if(!O||!A)return;let t=S.find(e=>e.name===O);if(!t)return;let n=x(A);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};N(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),D(!1),k(``),j(``),await Y()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{N(!1)}},Se=e=>{I(e),R(e.slug);let t=e.spec?.submitBehavior;B(t?.kind??`thank-you`),H(t?.title??``),W(t?.message??``),K(t?.url??``),P(!0)},Ce=async()=>{if(!F)return;let t=x(L);if(!t){v.error(`Invalid slug`);return}let n;switch(z){case`thank-you`:n={kind:`thank-you`},V&&(n.title=V),U&&(n.message=U);break;case`redirect`:if(!G){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:G};break;case`continue`:case`next-record`:n={kind:z};break}let r={...F.spec,sharing:{...F.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};J(!0);try{await e.meta.saveItem(`view`,F.name,r),v.success(`Saved ${F.name}`),P(!1),I(null),await Y()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{J(!1)}},$=t.length>0;return(0,b.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,b.jsxs)(fe,{children:[(0,b.jsxs)(se,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(le,{className:`flex items-center gap-2`,children:[(0,b.jsx)(ie,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(ce,{children:`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(p,{variant:`default`,size:`sm`,onClick:()=>D(!0),disabled:S.length===0,title:S.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ee,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(p,{variant:`outline`,size:`sm`,onClick:Y,disabled:C,children:[(0,b.jsx)(ae,{className:`h-3.5 w-3.5 ${C?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(ne,{children:[T&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:T}),!C&&!$&&(0,b.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,b.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,b.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,b.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),$&&(0,b.jsxs)(de,{children:[(0,b.jsx)(me,{children:(0,b.jsxs)(f,{children:[(0,b.jsx)(m,{children:`Name`}),(0,b.jsx)(m,{children:`Object`}),(0,b.jsx)(m,{children:`Slug`}),(0,b.jsx)(m,{children:`Public URL`}),(0,b.jsx)(m,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(pe,{children:t.map(e=>{let t=Z(e.slug);return(0,b.jsxs)(f,{children:[(0,b.jsx)(d,{children:(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,b.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,b.jsx)(d,{children:e.object?(0,b.jsx)(i,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(d,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(d,{children:(0,b.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[t,(0,b.jsx)(o,{className:`h-3 w-3`})]})}),(0,b.jsx)(d,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(p,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(te,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(p,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,ye(e.slug)),children:(0,b.jsx)(oe,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(p,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>Q(`React snippet`,be(e.slug)),children:(0,b.jsx)(re,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(p,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(ue,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(c,{open:_e,onOpenChange:D,children:(0,b.jsxs)(l,{className:`sm:max-w-md`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(s,{children:`Publish a FormView`}),(0,b.jsxs)(_,{children:[`Pick an existing FormView and turn it into a public form by enabling `,(0,b.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,b.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`publish-view`,children:`FormView`}),(0,b.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),S.map(e=>(0,b.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`publish-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(h,{id:`publish-slug`,placeholder:`contact-us`,value:A,onChange:e=>j(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(a,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>D(!1),disabled:M,children:`Cancel`}),(0,b.jsx)(p,{onClick:xe,disabled:M||!O||!A,children:M?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(c,{open:ve,onOpenChange:P,children:(0,b.jsxs)(l,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(s,{children:F?`Edit ${F.label??F.name}`:`Edit form`}),(0,b.jsx)(_,{children:`Configure the public URL and what happens after submit.`})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`edit-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(h,{id:`edit-slug`,value:L,onChange:e=>R(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`edit-behavior`,children:`After submit`}),(0,b.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:z,onChange:e=>B(e.target.value),children:[(0,b.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,b.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,b.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,b.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),z===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(h,{id:`edit-tytitle`,placeholder:`Thanks!`,value:V,onChange:e=>H(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(h,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:U,onChange:e=>W(e.target.value)})]})]}),z===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(g,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(h,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:G,onChange:e=>K(e.target.value)})]})]}),(0,b.jsxs)(a,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>P(!1),disabled:q,children:`Cancel`}),(0,b.jsx)(p,{onClick:Ce,disabled:q||!L,children:q?`Saving…`:`Save`})]})]})})]})}export{S as PublicFormsPage};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,l as i,r as a,t as o,u as s}from"./vendor-react-DR370ovB.js";import{f as c,m as l}from"./infrastructure-ckitl7Ev.js";import{B as u,O as d,d as f,lt as p,m,p as h,r as g,x as _}from"./framework-CVigpa4L.js";import{H as v,R as y,Ss as b,Uo as x,dc as S,z as ee}from"./ui-components-BK0FqwOC.js";import{r as C}from"./vendor-ui-utils-rQOI1gAo.js";import{n as te}from"./RecentItemsProvider-gLV-GFpQ.js";import{i as ne,n as re,t as ie}from"./useActionModal-DcFjU7Dq.js";import{i as ae,n as oe}from"./utils-bipVuqQL.js";import{n as se,t as ce}from"./MetadataInspector-BMHaVCoM.js";import{n as le,o as ue,r as de,s as fe}from"./plugins-views-BP1sk9hy.js";import{t as pe}from"./ManagedByBadge-BodEaDXN.js";import{t as me}from"./skeletons-D42JPA2I.js";import{a as he,i as ge,n as _e,r as ve,t as ye}from"./resolveActionParams-CWIOgcoF.js";var w=e(n(),1),T=o(),be=(0,w.createContext)(void 0);function E({children:e}){let[t,n]=(0,w.useState)(`home`),[r,i]=(0,w.useState)(),[a,o]=(0,w.useState)(),s=(0,w.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,T.jsx)(be.Provider,{value:s,children:e})}function D(){return(0,w.useContext)(be)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function xe(e){let{setRecordTitle:t}=D();(0,w.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}function O(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,w.useState)(`disconnected`),[l,u]=(0,w.useState)(null),[d,f]=(0,w.useState)([]),[p,m]=(0,w.useState)(null),h=(0,w.useRef)(null),g=(0,w.useRef)(0),_=(0,w.useRef)(null),v=(0,w.useRef)(new Map),y=(0,w.useRef)([]),b=(0,w.useRef)(!0),x=(0,w.useRef)(!1),S=(0,w.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),ee=(0,w.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]),C=(0,w.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,ee(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&&C()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,ee]),te=(0,w.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),ne=(0,w.useCallback)(()=>{S(),g.current=0,C()},[C,S]),re=(0,w.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]),ie=(0,w.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,w.useEffect)(()=>(b.current=!0,t&&C(),()=>{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:re,subscribe:ie,disconnect:te,reconnect:ne,error:p}}var k=0;function Se(){return k+=1,`conflict-${Date.now()}-${k}`}var Ce=0;function A(){return Ce+=1,`ver-${Date.now()}-${Ce}`}function j(e,t,n){let[r,i]=(0,w.useState)([]),[a,o]=(0,w.useState)([]);return{versions:r,currentVersion:(0,w.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,w.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:A(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,w.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:A(),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,w.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:A(),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,w.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:A(),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,w.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,w.useCallback)(e=>{let t={...e,id:Se()};o(e=>[...e,t])},[]),clearHistory:(0,w.useCallback)(()=>{i([]),o([])},[])}}var M={sm:24,md:32,lg:40},N={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function P(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function we({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=M[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,w.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,w.useMemo)(()=>[...l].reverse(),[l]);return w.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&w.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>w.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?w.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):P(e.userName),r&&w.createElement(`span`,{style:{...m,backgroundColor:N[e.status]}}))))}var Te=w.createContext({});function Ee(){let e=w.useContext(Te),[t,n]=w.useState([]);return w.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function De(e,t){let n=w.useContext(Te),[r,i]=w.useState([]);return w.useEffect(()=>{if(!n.subscribeRecord||!e||!t){i([]);return}return n.subscribeRecord({objectName:e,recordId:t},e=>{i(Array.isArray(e)?e:[])})},[n,e,t]),r}var Oe={platform:{create:!0,import:!0,edit:!0,delete:!0,exportCsv:!0},config:{create:!0,import:!1,edit:!0,delete:!0,exportCsv:!0},system:{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"append-only":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0},"better-auth":{create:!1,import:!1,edit:!1,delete:!1,exportCsv:!0}};function ke(e){let t=Oe[e?.managedBy??`platform`]??Oe.platform,n=e?.userActions??{};return{create:n.create??t.create,import:n.import??t.import,edit:n.edit??t.edit,delete:n.delete??t.delete,exportCsv:n.exportCsv??t.exportCsv}}var Ae=new Set([`record:discussion`,`record:chatter`]);function je(e){let t=new WeakSet,n=e=>{if(!e||typeof e!=`object`||t.has(e))return!1;if(t.add(e),Array.isArray(e))return e.some(n);let r=e?.type;return typeof r==`string`&&Ae.has(r)?!0:[e.children,e.items,e.body,e.components,e.properties?.children,e.properties?.items,e.regions].some(n)};return n(e)}var Me=t({RecordDetailView:()=>Re}),Ne={id:`current-user`,name:`Demo User`},Pe=new Set([`created_at`,`created_by`,`updated_at`,`updated_by`]),Fe=new Set([`organization_id`,`tenant_id`,`is_deleted`,`deleted_at`]),F=[`description`,`notes`,`note`,`remark`,`remarks`,`comments`],Ie=new Set([`textarea`,`markdown`,`html`,`rich-text`,`json`,`code`]);function Le(e,t){if(Ie.has(t?.type))return!0;let n=e.toLowerCase();return F.some(e=>n===e||n.endsWith(`_${e}`))}function Re({dataSource:e,objects:t,onEdit:n,objectNameOverride:o,recordIdOverride:be,embedded:E}){let D=r(),O=D.appName,k=o??D.objectName,Se=be??D.recordId,{showDebug:Ce}=se(),{user:A}=c(),j=s(),M=i().state?.from,{t:N}=g(),{objectLabel:P,viewLabel:Te,sectionLabel:Ee,actionLabel:Oe,actionConfirm:Ae,actionSuccess:Me,actionParamText:F,fieldLabel:Ie,fieldOptionLabel:Re}=S(),{isFavorite:ze,toggleFavorite:Be,refreshLabel:Ve}=ne(),{addRecentItem:He}=te(),[Ue,We]=(0,w.useState)(!0),[Ge,I]=(0,w.useState)([]),[L,Ke]=(0,w.useState)([]),[qe,R]=(0,w.useState)(0),[Je,z]=(0,w.useState)(null),[Ye,Xe]=(0,w.useState)({}),[Ze,Qe]=(0,w.useState)(null),[$e,et]=(0,w.useState)(!1),[B,tt]=(0,w.useState)(),V=t.find(e=>e.name===k);xe(E?void 0:B);let H=Se,U=De(k,H),W=(0,w.useMemo)(()=>!k||!H?null:{id:`record:${k}:${H}`,label:B||H||``,href:`/apps/${O}/${k}/record/${H}`,type:`record`},[O,k,H,B]),nt=W?ze(W.id):!1,rt=(0,w.useCallback)(()=>{W&&Be(W)},[W,Be]),{page:G,slots:K}=_(k),it=(0,w.useMemo)(()=>{if(typeof window<`u`)try{let e=new URLSearchParams(window.location.search).get(`renderViaSchema`);if(e===`0`||e===`false`)return!1;if(e===`1`||e===`true`)return!0}catch{}return V?.detail?.renderViaSchema!==!1},[V]),at=(0,w.useMemo)(()=>G||!V||!it&&!K?null:le(V,K?{slots:K}:void 0),[it,G,K,V]),q=G||at,[J,ot]=(0,w.useState)(null),[st,Y]=(0,w.useState)(`idle`);(0,w.useEffect)(()=>{let t=!1;if(!q||!H||!k||!e?.findOne){ot(null),Y(`idle`);return}let n=p(V?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{Y(`loading`),(r?e.findOne(k,H,r):e.findOne(k,H)).then(e=>{t||(e&&typeof e==`object`?(ot(e),Y(`loaded`)):(ot(null),Y(`missing`)))}).catch(()=>{t||(ot(null),Y(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==k||String(t.recordId)!==String(H)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[q,k,H,e,V]),(0,w.useEffect)(()=>{if(!J||typeof J!=`object`||!V)return;let e=oe(V,J);e&&e!==`Untitled`&&e!==B&&tt(e)},[J,V,B]),(0,w.useEffect)(()=>{if(!k||!H||!O||!B)return;let e=`record:${k}:${H}`;He({id:e,label:B,href:`/apps/${O}/${k}/record/${H}`,type:`record`}),Ve(e,B)},[O,k,H,B,He,Ve]);let[ct,lt]=(0,w.useState)({open:!1,message:``}),[ut,dt]=(0,w.useState)({open:!1,params:[]}),[ft,pt]=(0,w.useState)({open:!1}),mt=(0,w.useCallback)((e,t)=>new Promise(n=>{pt({open:!0,spec:e,data:t,resolve:n})}),[]),ht=(0,w.useCallback)((e,t)=>new Promise(n=>{lt({open:!0,message:e,options:t,resolve:n})}),[]),gt=(0,w.useCallback)((e,n)=>new Promise(r=>{let i=ye(e,{objectName:k||V?.name||``,objects:t||[],fieldLabel:Ie,fieldOptionLabel:Re}),a=k||V?.name;dt({open:!0,params:i.map(e=>({...e,label:F(a,n?.name,e.name,`label`,e.label)??e.label,placeholder:F(a,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:F(a,n?.name,e.name,`helpText`,e.helpText)??e.helpText})),title:n?.label||n?.title,description:n?.description,resolve:r})}),[k,V,t,Ie,Re,F]),_t=(0,w.useCallback)((e,t)=>{t?.type===`error`?C.error(e):C.success(e)},[]),vt=(0,w.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):j(e)},[j]),yt=(0,w.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(k,H,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(k,H,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(k,H,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(k,H,r);break}let i=t.refreshAfter===!0;return i&&R(e=>e+1),{success:!0,reload:i}}catch(e){return{success:!1,error:e.message}}},[e,k,H]),{modalHandler:bt,modalElement:xt}=ie(e),X=(0,w.useMemo)(()=>l(),[]),St=(0,w.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 X(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:H,objectName:k,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 i=r?.data??{};if(i.status===`paused`&&i.screen)return z({flowName:t,runId:i.runId,screen:i.screen}),{success:!0};let a=e.refreshAfter!==!1;return a&&R(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[X,H,k]),Ct=(0,w.useRef)(new Set),wt=(0,w.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:{},r=`${t}:${H??``}`;if(Ct.current.has(r))return{success:!1,error:`Action already in progress`};Ct.current.add(r);let i=null;if(e.opensInNewTab)try{i=window.open(`about:blank`,`_blank`),i&&(i.document.write(`<!doctype html><meta charset="utf-8"><title>正在打开… Opening…</title><body style="margin:0;font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;height:100vh;gap:16px;color:#4b5563"><div style="width:28px;height:28px;border:3px solid #e5e7eb;border-top-color:#6366f1;border-radius:50%;animation:s .8s linear infinite"></div><div>正在为你打开环境…</div><style>@keyframes s{to{transform:rotate(360deg)}}</style></body>`),i.document.close())}catch{i=null}try{let r=typeof e.newTabUrl==`string`?e.newTabUrl:``;if(e.opensInNewTab&&r){if(H==null){if(i)try{i.close()}catch{}return{success:!1,error:`This action runs on a single record — no record id available.`}}let t=`${window.location.origin}${r.replace(`{recordId}`,encodeURIComponent(String(H)))}`;if(i)try{i.location.href=t}catch{try{i.close()}catch{}window.location.href=t}else{let e=null;try{e=window.open(t,`_blank`)}catch{e=null}e||C(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(t,`_blank`)}catch{window.location.href=t}}},duration:1e4})}return e.refreshAfter===!0&&R(e=>e+1),{success:!0}}let a=e.objectName||k||`global`,o=await X(`/api/v1/actions/${encodeURIComponent(a)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:H,params:n})}),s=await o.json().catch(()=>null);if(!o.ok||s&&s.success===!1){let e=s?.error||`Action "${t}" failed (HTTP ${o.status})`;if(i)try{i.close()}catch{}return C.error(e),{success:!1,error:e}}let c=e.refreshAfter!==!1;c&&R(e=>e+1);let l=s?.data;if(l&&typeof l==`object`&&typeof l.redirectUrl==`string`){let e=l.redirectUrl;if(i)try{i.location.href=e}catch{try{i.close()}catch{}window.location.href=e}else{let t=null;try{t=window.open(e,`_blank`)}catch{t=null}t||C(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(e,`_blank`)}catch{window.location.href=e}}},duration:1e4})}}else if(i)try{i.close()}catch{}return{success:!0,data:l,reload:c}}catch(e){if(i)try{i.close()}catch{}let t=e.message;return C.error(t),{success:!1,error:t}}finally{Ct.current.delete(r)}},[X,H,k]),Z=re(k,H,A?.id),Tt=(0,w.useRef)(Z);Tt.current=Z;let Et=(0,w.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await Tt.current.approve({comment:n.comment});else if(t===`reject_request`)await Tt.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return R(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Dt=(0,w.useMemo)(()=>ae(V,t),[V,t]);(0,w.useEffect)(()=>{if(q||!e||!H||Dt.length===0)return;let t=!1;return Promise.all(Dt.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:H}}).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;Xe(n)}),()=>{t=!0}},[e,H,Dt,V,q]);let Ot=(0,w.useMemo)(()=>!V||V.name===`sys_audit_log`||V.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[V,t]);(0,w.useEffect)(()=>{if(!e||!H||!V||!Ot){Qe(null);return}let t=!1;return et(!0),e.find(`sys_audit_log`,{$filter:{record_id:H,object_name:V.name},$orderby:{created_at:`desc`},$top:50,$select:[`id`,`created_at`,`action`,`user_id`,`old_value`,`new_value`]}).then(async n=>{if(t)return;let r=Array.isArray(n)?n:n?.data||[],i=Array.from(new Set(r.map(e=>e?.user_id).filter(e=>typeof e==`string`&&e.length>0))),a=new Map;if(i.length>0)try{let t=await e.find(`sys_user`,{$filter:{id:{$in:i}},$top:i.length,$select:[`id`,`name`,`email`,`image`]}),n=Array.isArray(t)?t:t?.data||[];a=new Map(n.map(e=>[e.id,{name:e.name||e.email||null,image:e.image||null}]))}catch(e){console.warn(`[RecordDetailView] Failed to resolve audit user names:`,e)}let o={};for(let[e,t]of Object.entries(V.fields||{}))t?.label&&(o[e]=t.label);let s=e=>{if(!e)return null;if(typeof e==`object`)return e;if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return null};Qe(r.map(e=>{let t=e?.user_id?a.get(e.user_id):void 0,n=s(e?.old_value)||{},r=s(e?.new_value)||{},i=new Set([...Object.keys(n),...Object.keys(r)]),c=Array.from(i).filter(e=>JSON.stringify(n[e])!==JSON.stringify(r[e])).map(e=>({field:e,label:o[e]||e,from:n[e],to:r[e]}));return{...e,user_name:t?.name??null,user_avatar:t?.image??null,changes:c.length>0?c:void 0}}))}).catch(e=>{t||(console.warn(`[RecordDetailView] Failed to fetch sys_audit_log:`,e),Qe([]))}).finally(()=>{t||et(!1)}),()=>{t=!0}},[e,H,V,Ot]),(0,w.useEffect)(()=>{if(!e)return;let t=!1,n=A?[{id:String(A.id),label:A.name||A.email||String(A.id),avatarUrl:A.image||void 0}]:[];return(async()=>{try{let r=await e.find(`sys_user`,{$top:50,$select:[`id`,`name`,`email`,`image`]});if(t)return;let i=(Array.isArray(r)?r:r?.data||[]).map(e=>({id:String(e.id),label:e.name||e.email||String(e.id),avatarUrl:e.image||void 0})).filter(e=>e.label),a=new Set(n.map(e=>e.id)),o=[...n,...i.filter(e=>!a.has(e.id))];Ke(o.length>0?o:n)}catch{if(t)return;Ke(n)}})(),()=>{t=!0}},[e,A?.id,A?.name,A?.email]);let Q=(0,w.useMemo)(()=>A?{id:A.id,name:A.name,avatar:A.image}:Ne,[A?.id,A?.name,A?.image]);(0,w.useEffect)(()=>{if(!e||!k||!H)return;let t=`${k}:${H}`,n=e=>{if(!e)return;let t;if(typeof e==`string`)try{t=JSON.parse(e)}catch{return}else typeof e==`object`&&(t=e);if(t)return Object.entries(t).map(([e,t])=>({emoji:e,count:Array.isArray(t)?t.length:0,reacted:Array.isArray(t)&&t.includes(Q.id)}))};e.find(`sys_comment`,{$filter:{thread_id:t},$orderby:{created_at:`asc`}}).then(e=>{if(!e?.data?.length)return;let t=e.data.map(e=>({id:e.id,type:`comment`,actor:e.author_name??`Unknown`,actorAvatarUrl:e.author_avatar_url??void 0,body:e.body??``,createdAt:e.created_at,updatedAt:e.updated_at,parentId:e.parent_id??void 0,reactions:n(e.reactions)}));I(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{});let r={created:`field_change`,updated:`field_change`,deleted:`field_change`,assigned:`field_change`,shared:`field_change`,system:`system`,completed:`task`,commented:void 0,mentioned:void 0,login:void 0,logout:void 0};e.find(`sys_activity`,{$filter:{object_name:k,record_id:H},$orderby:{timestamp:`asc`},$top:200}).then(e=>{if(!e?.data?.length)return;let t=[];for(let n of e.data){let e=r[n.type];if(!e)continue;let i=n.timestamp;(!i||i===`NOW()`||Number.isNaN(Date.parse(i)))&&(i=n.created_at),t.push({id:n.id,type:e,actor:n.actor_name??`System`,actorAvatarUrl:n.actor_avatar_url??void 0,body:n.summary??``,createdAt:i})}t.length&&I(e=>{let n=new Map;for(let r of[...e,...t])n.set(String(r.id),r);return Array.from(n.values()).sort((e,t)=>(e.createdAt?Date.parse(e.createdAt):0)-(t.createdAt?Date.parse(t.createdAt):0))})}).catch(()=>{})},[e,k,H,Q]);let kt=(0,w.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:Q.name,actorAvatarUrl:`avatar`in Q?Q.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(I(e=>[...e,n]),e){let r=`${k}:${H}`,i=de(t,L);e.create(`sys_comment`,{id:n.id,thread_id:r,author_id:Q.id,author_name:Q.name,author_avatar_url:`avatar`in Q?Q.avatar:void 0,body:t,mentions:JSON.stringify(i),created_at:n.createdAt}).catch(()=>{})}},[Q,e,k,H,L]),At=(0,w.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:Q.name,actorAvatarUrl:`avatar`in Q?Q.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(I(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${k}:${H}`,a=de(n,L);e.create(`sys_comment`,{id:r.id,thread_id:i,author_id:Q.id,author_name:Q.name,author_avatar_url:`avatar`in Q?Q.avatar:void 0,body:n,mentions:JSON.stringify(a),created_at:r.createdAt,parent_id:t}).catch(()=>{})}},[Q,e,k,H,L]),jt=(0,w.useCallback)((t,n)=>{I(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};if(e){let n=Q.id,r={};for(let e of i){let t=[];for(e.reacted&&t.push(n);t.length<e.count;)t.push(`__other__`);r[e.emoji]=t}e.update(`sys_comment`,String(t),{reactions:JSON.stringify(r)}).catch(()=>{})}return o}))},[Q.id,e]);(0,w.useEffect)(()=>{We(!0),queueMicrotask(()=>We(!1))},[k,Se]);let $=(0,w.useMemo)(()=>{if(!V)return{type:`detail-view`};let n=V.primaryField||Object.keys(V.fields||{}).find(e=>e===`name`||e===`title`),r=V.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?Ee(V.name,e.name,e.title||e.name):e.title,collapsible:e.collapsible,defaultCollapsed:e.defaultCollapsed,fields:(e.fields||[]).filter(e=>{let t=typeof e==`string`?e:e.name;return!V.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=V.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${V.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}}})})):(()=>{let e=Object.keys(V.fields||{}).filter(e=>!Pe.has(e)&&!Fe.has(e)&&!V.fields[e]?.hidden),t=e=>{let t=V.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}}},n=e.filter(e=>!Le(e,V.fields[e])),r=e.filter(e=>Le(e,V.fields[e]));return r.length===0||n.length===0?[{showBorder:!1,fields:e.map(t)}]:[{showBorder:!1,fields:n.map(t)},{name:`details`,title:Ee(V.name,`details`,N(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(V.actions||[]).filter(t=>t.locations?.includes(`record_header`)?t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0:!1).map(e=>({...e,label:Oe(V.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:Ae(V.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:Me(V.name,e.name,e.successMessage)}}));if(Z.available&&Z.canDecide){let e={name:`comment`,label:N(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:N(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`default`,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:N(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:N(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,locations:[`record_header`],refreshAfter:!0,confirmText:N(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:N(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),o=V.views?.detail?.highlightFields??[],s=V.views?.detail?.sectionGroups??V.views?.form?.sectionGroups,c=O?`/apps/${O}`:``,l=Dt.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let s=t.find(e=>e.name===n),l=H||``,u=a||(s?P({name:s.name,label:s.label||r}):r),d=()=>{let e=new URLSearchParams({[i]:l}).toString();return`${c}/${n}/new${e?`?${e}`:``}`},f=()=>{let e=new URLSearchParams({[`filter[${i}]`]:l}).toString();return`${c}/${n}${e?`?${e}`:``}`},p=e=>{let t=e?.id||e?._id;return t?`${c}/${n}/record/${encodeURIComponent(String(t))}/edit`:null},m=e=>{let t=e?.id||e?._id;return t?`${c}/${n}/record/${encodeURIComponent(String(t))}`:null},h=c?()=>j(d()):void 0,g=c?()=>j(f()):void 0,_=c?e=>{let t=m(e);t&&j(t)}:void 0,v=c?e=>{let t=p(e);t&&j(t)}:void 0,y=e&&l?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),C.success(N(`detail.deleteSuccess`,{defaultValue:`Deleted`})),Xe(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){C.error(e?.message||N(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:u,type:`table`,api:n,data:Ye[n]||[],referenceField:i,...Array.isArray(o)&&o.length>0?{columns:o}:{},icon:s?.icon,displayField:s?.displayNameField||(Array.isArray(s?.compactLayout)?s.compactLayout[0]:void 0),onNew:h,onViewAll:g,onRowClick:_,onRowEdit:v,onRowDelete:y}}),u=ke(V);return{type:`detail-view`,objectName:V.name,resourceId:H,showBack:!E,onBack:`history`,showEdit:u.edit,title:V.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...Ot&&{history:{entries:Ze??[],loading:$e&&Ze===null}},...l.length>0&&{related:l},...o.length>0&&{highlightFields:o},...s&&s.length>0&&{sectionGroups:s},...a.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:a}]}}},[V?.name,H,Ye,qe,O,j,e,N,P,t,Ot,Ze,$e,Z.available,Z.canDecide,Z.pendingRequest,Z.latestRequest,E]);if(Ue)return(0,T.jsx)(me,{});if(!V)return(0,T.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,T.jsxs)(y,{children:[(0,T.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,T.jsx)(x,{className:`h-6 w-6 text-muted-foreground`})}),(0,T.jsx)(v,{children:N(`empty.objectNotFound`)}),(0,T.jsx)(ee,{children:N(`empty.objectNotFoundDescription`,{name:k})})]})});if(q&&st===`missing`)return(0,T.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,T.jsxs)(y,{children:[(0,T.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,T.jsx)(x,{className:`h-6 w-6 text-muted-foreground`})}),(0,T.jsx)(v,{children:N(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,T.jsx)(ee,{children:N(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(q){let t=q?.disableDiscussion===!0,r=je(q),i=!t&&!r,o=(()=>{let e=$.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),s=(()=>{let t=ke(V),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:N(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:H,objectName:k}}))}}),r.push({name:`sys_edit`,label:N(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:H})})),r.push({name:`sys_share`,label:N(`detail.share`,{defaultValue:`Share`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:async()=>{try{if(navigator.share){await navigator.share({title:document.title,url:window.location.href});return}}catch{return}try{await navigator.clipboard.writeText(window.location.href),C.success(N(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){C.error(N(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:N(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=N(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(k,H),C.success(N(`detail.deleted`,{defaultValue:`Record deleted`})),j(`${O?`/apps/${O}`:``}/${k}`,{replace:!0})}catch(e){C.error(e?.message||`Delete failed`)}}}),r})(),c=o.length>0?o:void 0,l=Array.isArray($.related)?$.related.filter(e=>e?.api&&e?.referenceField).map(e=>({title:e.title,objectName:e.api,relationshipField:e.referenceField,...Array.isArray(e.columns)?{columns:e.columns}:{},...typeof e.pageSize==`number`?{limit:e.pageSize}:{},...e.icon?{icon:e.icon}:{}})):void 0,p=$.history?{entries:$.history.entries??[],loading:!!$.history.loading,emptyText:$.history.emptyText}:void 0,g=G?q:le(V,{sections:$.sections,highlightFields:Array.isArray($.highlightFields)?$.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:c,related:l,history:p,showReferenceRail:V?.detail?.showReferenceRail===!0||void 0,hideReferenceRail:V?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:V?.detail?.hideRelatedTab===!0||void 0,...K?{slots:K}:{}});return(0,T.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,T.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[U.length>0&&(0,T.jsx)(we,{users:U,size:`sm`,maxVisible:3,showStatus:!0}),(0,T.jsx)(pe,{managedBy:V?.managedBy})]}),(0,T.jsx)(m,{objectName:k,recordId:H,data:J,objectSchema:V,dataSource:e,embedded:E,headerSystemActions:s,isFavorite:nt,onToggleFavorite:W?rt:void 0,children:(0,T.jsx)(h,{children:(0,T.jsx)(f,{items:Ge,onAddComment:kt,onAddReply:At,onToggleReaction:jt,mentionSuggestions:L,children:(0,T.jsxs)(d,{context:{record:J||{},objectName:k,user:Q},onConfirm:ht,onToast:_t,onNavigate:vt,onParamCollection:gt,onResultDialog:mt,onModal:bt,handlers:{api:yt,flow:St,script:wt,approval:Et},children:[(0,T.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,T.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[M?.pathname&&M?.label&&(0,T.jsxs)(a,{to:M.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,T.jsx)(b,{className:`h-4 w-4`}),(0,T.jsx)(`span`,{children:M.label})]}),(0,T.jsx)(u,{schema:g}),i&&(0,T.jsx)(`div`,{className:`mt-6`,children:(0,T.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:Ge,onAddComment:kt,onAddReply:At,onToggleReaction:jt,mentionSuggestions:L})})]}),(0,T.jsx)(ce,{open:Ce,sections:[{title:`Page Schema`,data:g}]})]}),xt]})})})}),(0,T.jsx)(he,{state:ct,onOpenChange:e=>{e||lt(e=>({...e,open:!1}))}}),(0,T.jsx)(ge,{state:ut,onOpenChange:e=>{e||dt(e=>({...e,open:!1}))}}),(0,T.jsx)(ve,{state:ft,onAcknowledge:()=>{ft.resolve?.(),pt({open:!1})}}),(0,T.jsx)(_e,{state:Je,authFetch:X,baseUrl:``,onClose:()=>z(null),onComplete:()=>{z(null),R(e=>e+1)}})]})}return(0,T.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,T.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[U.length>0&&(0,T.jsx)(we,{users:U,size:`sm`,maxVisible:3,showStatus:!0}),(0,T.jsx)(pe,{managedBy:V?.managedBy})]}),(0,T.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,T.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,T.jsxs)(d,{context:{record:{},objectName:k,user:Q},onConfirm:ht,onToast:_t,onNavigate:vt,onParamCollection:gt,onResultDialog:mt,onModal:bt,handlers:{api:yt,flow:St,script:wt,approval:Et},children:[(0,T.jsx)(fe,{schema:$,dataSource:e,objectLabel:P({name:V.name,label:V.label}),isFavorite:nt,onToggleFavorite:W?rt:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=oe(V,e);t&&t!==B&&t!==`Untitled`&&tt(t)},onEdit:()=>{n({id:H})},discussionSlot:(0,T.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:Ge,onAddComment:kt,onAddReply:At,onToggleReaction:jt})},qe),xt]})}),(0,T.jsx)(ce,{open:Ce,sections:[{title:`View Schema`,data:$}]})]}),(0,T.jsx)(he,{state:ct,onOpenChange:e=>{e||lt(e=>({...e,open:!1}))}}),(0,T.jsx)(ge,{state:ut,onOpenChange:e=>{e||dt(e=>({...e,open:!1}))}}),(0,T.jsx)(ve,{state:ft,onAcknowledge:()=>{ft.resolve?.(),pt({open:!1})}}),(0,T.jsx)(_e,{state:Je,authFetch:X,baseUrl:``,onClose:()=>z(null),onComplete:()=>{z(null),R(e=>e+1)}})]})}export{we as a,E as c,Ee as i,D as l,Me as n,j as o,ke as r,O as s,Re as t};
@@ -1 +0,0 @@
1
- import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,p as i,r as a,t as o,u as s}from"./vendor-react-DR370ovB.js";import{f as c}from"./infrastructure-ckitl7Ev.js";import{T as l,r as u,st as d,w as f}from"./framework-CVigpa4L.js";import{H as p,R as m,Uo as h,dc as g,hr as _,rc as v,z as y}from"./ui-components-BK0FqwOC.js";import{r as b}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-BrKPQ1rE.js";import{t as x}from"./plugin-form-CM6RvRf2.js";import"./MetadataProvider-Cvue7gQ0.js";import{n as S,t as C}from"./ExpressionProvider-CqfGEBur.js";import{t as w}from"./ManagedByBadge-BodEaDXN.js";import{t as T}from"./skeletons-D42JPA2I.js";var E=t({RecordFormPage:()=>k}),D=e(n(),1),O=o();function k({mode:e}){let{appName:t,objectName:n,recordId:o}=r(),E=s(),[k]=i(),A=f(),{objects:j,loading:M}=l(),{t:N}=u(),{objectLabel:P}=g(),{user:F,getAuthConfig:I}=c(),[L,R]=(0,D.useState)({});(0,D.useEffect)(()=>{let e=!1;return I().then(t=>{e||R(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[I]);let z=(0,D.useMemo)(()=>{if(e!==`create`)return;let t=[];for(let[e,n]of k.entries())e&&n&&t.push([e,n]);return t.length>0?Object.fromEntries(t):void 0},[e,k.toString()]),B=(0,D.useMemo)(()=>j.find(e=>e.name===n),[j,n]),V=`/apps/${t}`,H=`${V}/${n}`,U=e===`edit`&&o?`${V}/${n}/record/${encodeURIComponent(o)}`:H,W=(0,D.useCallback)(()=>{typeof window<`u`&&window.history.length>1?E(-1):E(U,{replace:!0})},[E,U]),G=B?P(B):n??``,K=e===`create`?N(`form.createTitle`,{object:G,defaultValue:`New ${G}`}):N(`form.editTitle`,{object:G,defaultValue:`Edit ${G}`}),q=(0,D.useCallback)(()=>{b.success(e===`create`?N(`form.createSuccess`,{object:G,defaultValue:`${G} created successfully`}):N(`form.updateSuccess`,{object:G,defaultValue:`${G} updated successfully`})),W()},[e,N,G,W]),J=(0,D.useCallback)(()=>{W()},[W]),Y=(0,D.useMemo)(()=>F?{name:F.name,email:F.email,role:F.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[F]),X=(0,D.useMemo)(()=>new d({user:Y,app:{name:t},data:{}}),[Y,t]),Z=(0,D.useMemo)(()=>B?.fields?Array.isArray(B.fields)?B.fields.filter(e=>typeof e==`string`?!0:S(e.visible,X)).map(e=>typeof e==`string`?e:e.name):Object.entries(B.fields).filter(([,e])=>S(e.visible,X)).map(([e])=>e):[],[B,X]);return M?(0,O.jsx)(T,{}):B?(0,O.jsx)(C,{user:Y,app:{name:t},data:{},features:L,children:(0,O.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,O.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,O.jsx)(_,{variant:`ghost`,size:`sm`,onClick:W,"data-testid":`record-form-page-back`,"aria-label":N(`common.back`,{defaultValue:`Back`}),children:(0,O.jsx)(v,{className:`h-4 w-4`})}),(0,O.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,O.jsx)(a,{to:H,className:`hover:text-foreground transition-colors`,children:G}),(0,O.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,O.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:K}),(0,O.jsx)(w,{managedBy:B?.managedBy,className:`ml-1`})]})]}),(0,O.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,O.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,O.jsx)(x,{schema:{type:`object-form`,formType:`simple`,objectName:B.name,mode:e,recordId:e===`edit`?o:void 0,...z&&{initialValues:z},title:K,description:e===`create`?N(`form.createDescription`,{object:G,defaultValue:`Create a new ${G}.`}):N(`form.editDescription`,{object:G,defaultValue:`Edit this ${G}.`}),layout:`vertical`,fields:Z,subforms:B.form?.subforms??B.formViews?.default?.subforms,onSuccess:q,onCancel:J,showSubmit:!0,showCancel:!0,submitText:N(`form.saveRecord`,{defaultValue:`Save`}),cancelText:N(`common.cancel`,{defaultValue:`Cancel`})},dataSource:A??void 0},`${e}:${n}:${o??`new`}`)})})]})}):(0,O.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,O.jsxs)(m,{children:[(0,O.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,O.jsx)(h,{className:`h-6 w-6 text-muted-foreground`})}),(0,O.jsx)(p,{children:N(`empty.objectNotFound`)}),(0,O.jsx)(y,{children:N(`empty.objectNotFoundDescription`,{name:n})}),(0,O.jsx)(`div`,{className:`mt-4`,children:(0,O.jsxs)(_,{variant:`outline`,onClick:()=>E(V),children:[(0,O.jsx)(v,{className:`mr-2 h-4 w-4`}),N(`empty.back`)]})})]})})}export{E as t};