@objectstack/console 9.9.0 → 9.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AiPendingActionsPage-BI-QQNee.js → AiPendingActionsPage-BDYUc-T8.js} +1 -1
- package/dist/assets/{ApiConsolePage-CPV6vWpt.js → ApiConsolePage-BJB9Xho6.js} +1 -1
- package/dist/assets/{AppDocsIndex-D4Y3i2rM.js → AppDocsIndex-Cj0DpA3d.js} +1 -1
- package/dist/assets/{AppManagementPage-CLiHbNPr.js → AppManagementPage-BzjUDLx3.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-CAyznoRP.js → ApprovalsInboxPage-Dym3zM3t.js} +1 -1
- package/dist/assets/{AuditLogPage-BeEqEy4g.js → AuditLogPage-BJh3wy1L.js} +1 -1
- package/dist/assets/{ComponentNavView-DmALsugj.js → ComponentNavView-BFSklq8D.js} +1 -1
- package/dist/assets/{ConsoleFloatingChatbot-CXwRB3yg.js → ConsoleFloatingChatbot-_UeVODsx.js} +1 -1
- package/dist/assets/{DashboardView-BF0o0wgx.js → DashboardView-kL9_gMzd.js} +1 -1
- package/dist/assets/{DashboardWidgetInspector-DIMge0qc.js → DashboardWidgetInspector-BN8Yy27Q.js} +1 -1
- package/dist/assets/{DeveloperHubPage-DbQwi1EV.js → DeveloperHubPage-CB5nkyun.js} +1 -1
- package/dist/assets/{FlowRunsPage-CJDL4g0k.js → FlowRunsPage-65yB_BWO.js} +1 -1
- package/dist/assets/{IntegrationsPage-DU_wvj4-.js → IntegrationsPage-8M_88h2y.js} +2 -2
- package/dist/assets/{InterfaceListPage-DZpFSsQf.js → InterfaceListPage-CBomrdcf.js} +1 -1
- package/dist/assets/{ManagedByBadge-Difq_L_A.js → ManagedByBadge-Bmg77Q4v.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-CXUE33gy.js → MarketplaceAccessDenied-CX0RbkOJ.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-CBfcARvX.js → MarketplaceInstalledPage-BYXiUCpz.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-BWCVUz3e.js → MarketplacePackagePage-C8yVjW5r.js} +2 -2
- package/dist/assets/{MarketplacePage-BT-WkhAG.js → MarketplacePage-pVW-NfrG.js} +1 -1
- package/dist/assets/{MetadataInspector-BRICMLXW.js → MetadataInspector-CACgSTc7.js} +1 -1
- package/dist/assets/{MetadataProvider-CEw2X-qL.js → MetadataProvider-Dh20h6BN.js} +1 -1
- package/dist/assets/{PageView-CP-3dRzz.js → PageView-D388xYQA.js} +1 -1
- package/dist/assets/{ProfilePage-BAtKSxuK.js → ProfilePage-SXmEEOn3.js} +1 -1
- package/dist/assets/{PublicFormsPage-D7D2WWL7.js → PublicFormsPage-aXes2XrW.js} +1 -1
- package/dist/assets/{RecordDetailView-BdQK61l2.js → RecordDetailView-DIiHv2mR.js} +1 -1
- package/dist/assets/{RecordFormPage-lFVOsTl0.js → RecordFormPage-C052nJig.js} +1 -1
- package/dist/assets/ReportDefaultInspector-CjR-PcBn.js +1 -0
- package/dist/assets/{ReportView-BHtzV5eK.js → ReportView-M_mx8mgW.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-DXwH4Hvd.js → RuntimeDraftBar-DTf-DIfT.js} +1 -1
- package/dist/assets/{SearchResultsPage-CE_LTSSU.js → SearchResultsPage-DGuFKZit.js} +1 -1
- package/dist/assets/{SettingsHub-BLEC_8Ao.js → SettingsHub-eYWWi8O5.js} +1 -1
- package/dist/assets/{SettingsView-BEjR60F6.js → SettingsView-Cq3IKOhI.js} +1 -1
- package/dist/assets/{SystemHubPage-DjNBraYu.js → SystemHubPage-6FccxnKY.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-DiT7C6XW.js → highlighted-body-OFNGDK62-CKMBhexn.js} +1 -1
- package/dist/assets/index-A8r_lURn.js +4 -0
- package/dist/assets/index-BGyrRTzt.css +2 -0
- package/dist/assets/{mergeServerFields-djmY7AgR.js → mergeServerFields-CMIOI8QD.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-C3g3SOag.js +1 -0
- package/dist/assets/metadata-admin-ORqaeHUJ.js +19 -0
- package/dist/assets/plugin-calendar-Czocnijo.js +1 -0
- package/dist/assets/{plugin-charts-AMObsZz3.js → plugin-charts-dCyWH9k8.js} +1 -1
- package/dist/assets/{plugin-chatbot-Ch8YIyYL.js → plugin-chatbot-BpAQS7-q.js} +6 -6
- package/dist/assets/plugin-dashboard-CjtE0zwv.js +5 -0
- package/dist/assets/plugin-form-Dzz6GAZM.js +1 -0
- package/dist/assets/plugin-gantt-BedjcmIc.js +23 -0
- package/dist/assets/plugin-grid-BqmF7p-H.js +6 -0
- package/dist/assets/{plugin-kanban-DOsTOpJz.js → plugin-kanban-Dq0xJjXt.js} +1 -1
- package/dist/assets/{plugin-map-Bid9UXOR.js → plugin-map-DG62gl97.js} +1 -1
- package/dist/assets/{plugin-markdown-BUQOG31j.js → plugin-markdown-BL0QvMCD.js} +1 -1
- package/dist/assets/{plugin-report-FxG9jOvy.js → plugin-report-DckNGNq6.js} +1 -1
- package/dist/assets/{plugin-timeline-DDrFKEb8.js → plugin-timeline-dBrX3lS3.js} +1 -1
- package/dist/assets/plugin-view-DCPYomdU.js +1 -0
- package/dist/assets/plugins-views-B-EGcBP2.js +4 -0
- package/dist/assets/{resolveActionParams-C_x4GXvS.js → resolveActionParams-B_7wSkli.js} +1 -1
- package/dist/assets/{skeletons-B_SNEnMn.js → skeletons-BK7w4pLE.js} +1 -1
- package/dist/assets/src-9qM7N8MR.js +2 -0
- package/dist/assets/{src-DbxuLwqh.js → src-Czx03pos.js} +1 -1
- package/dist/assets/{types-CosU35As.js → types-C2_UYDEK.js} +1 -1
- package/dist/assets/{ui-components-CrPYFyEM.js → ui-components-NS_7__gn.js} +7 -7
- package/dist/assets/{ui-layout-DAWxaQvy.js → ui-layout-BdKOzi1L.js} +1 -1
- package/dist/assets/{useActionModal-DDu3wUOI.js → useActionModal-BE61500N.js} +1 -1
- package/dist/assets/{useReconcileOnError-Agbi2njU.js → useReconcileOnError-Cvd01WQv.js} +1 -1
- package/dist/assets/{utils-bipVuqQL.js → utils-29quoGQV.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +1 -1
- package/dist/assets/ReportDefaultInspector-GD1EQSTh.js +0 -1
- package/dist/assets/index-CJe1zUD0.css +0 -2
- package/dist/assets/index-DdQV1cqi.js +0 -4
- package/dist/assets/mermaid-GHXKKRXX-CK-9EMhD.js +0 -1
- package/dist/assets/metadata-admin-BbJpmVQm.js +0 -19
- package/dist/assets/plugin-calendar-DQC9zdKq.js +0 -1
- package/dist/assets/plugin-dashboard-C7fxXXeO.js +0 -5
- package/dist/assets/plugin-form-gQDKenio.js +0 -1
- package/dist/assets/plugin-gantt-BHmpu6VX.js +0 -23
- package/dist/assets/plugin-grid-boi_rkH3.js +0 -6
- package/dist/assets/plugin-view-DhNkNfUe.js +0 -1
- package/dist/assets/plugins-views-DUKPQNs8.js +0 -4
- package/dist/assets/src-Bzm5L_v8.js +0 -2
|
@@ -1 +1 @@
|
|
|
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-CJNwTVno.js";import{A as u,B as d,O as f,T as p,r as m,w as h}from"./framework-BLEk-ou3.js";import{Co as g,H as _,R as v,Xi as y,gc as b,z as x}from"./ui-components-CrPYFyEM.js";import{r as S}from"./vendor-ui-utils-rQOI1gAo.js";import"./MetadataProvider-CEw2X-qL.js";import{r as C}from"./ExpressionProvider-DKFCgLsJ.js";import{n as w,r as T,t as E}from"./MetadataInspector-BRICMLXW.js";import{t as D}from"./InterfaceListPage-DZpFSsQf.js";import{a as O,i as k,n as A,r as j,t as M}from"./resolveActionParams-C_x4GXvS.js";var N=e(n(),1),P=o(),F={id:`current-user`,name:`Demo User`,isPlatformAdmin:!1};function I(e){let{dataSource:t,objects:n,objectName:r,onRefresh:i}=e,a=s(),{user:o,activeOrganization:d}=c(),{fieldLabel:f,fieldOptionLabel:p,actionParamText:m,actionParamOptionLabel:h,actionDescription:g}=b(),_=(0,N.useMemo)(()=>r?n?.find(e=>e.name===r):void 0,[n,r]),v=r||_?.name,y=(0,N.useCallback)(()=>{i?.()},[i]),x=u({dataSource:t,onUndo:()=>{y(),S.success(`Change undone`)}}),[C,w]=(0,N.useState)({open:!1,message:``}),[T,E]=(0,N.useState)({open:!1,params:[]}),[D,I]=(0,N.useState)({open:!1}),[L,R]=(0,N.useState)(null),z=(0,N.useRef)(new Set),B=(0,N.useCallback)((e,t)=>new Promise(n=>{I({open:!0,spec:e,data:t,resolve:n})}),[]),V=(0,N.useCallback)((e,t)=>new Promise(n=>{w({open:!0,message:e,options:t,resolve:n})}),[]),H=(0,N.useCallback)((e,t)=>new Promise(i=>{let a=t?.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,o=M(e,{objectName:r||_?.name||``,objects:n||[],fieldLabel:f,fieldOptionLabel:p,row:a}),s=r||_?.name;E({open:!0,params:o.map(e=>({...e,label:m(s,t?.name,e.name,`label`,e.label)??e.label,placeholder:m(s,t?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:m(s,t?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(n=>({...n,label:h(s,t?.name,e.name,n.value,n.label)})):e.options})),title:t?.label||t?.title,description:g(s,t?.name,t?.description),resolve:i})}),[r,_,n,f,p,m,h]),U=o?{id:o.id,name:o.name,avatar:o.image,isPlatformAdmin:o?.isPlatformAdmin??!1}:F,W=(0,N.useCallback)((e,t)=>{if(t?.type===`error`){S.error(e);return}if(t?.undo){S.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{x.undo()}}});return}S.success(e,{duration:t?.duration})},[x]),G=(0,N.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):a(e)},[a]),K=(0,N.useMemo)(()=>l(),[]),q=(0,N.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&&d?.id&&(c.organizationId=d.id),e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(c,e.bodyExtra);let l=(e.method||`POST`).toUpperCase(),u={method:l,headers:{"Content-Type":`application/json`},credentials:`include`};l!==`GET`&&l!==`DELETE`&&(u.body=JSON.stringify(c));let f=await K(o,u);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&&y(),{success:!0,data:p,reload:e.refreshAfter!==!1}}let a=e.objectName||v,o=r._rowRecord,s={...r};delete s._rowRecord;let c=s.recordId??o?.[e.recordIdField||`id`];delete s.recordId,a&&typeof t?.execute==`function`?await t.execute(a,n,s):a&&c&&Object.keys(s).length>0&&typeof t?.update==`function`&&await t.update(a,c,s);let l;if(e.undoable&&a&&c&&o&&Object.keys(s).length>0&&typeof t?.update==`function`){let t={};for(let e of Object.keys(s))t[e]=o[e]??null;l={id:`undo-${a}-${c}-${Date.now()}`,type:`update`,objectName:a,recordId:String(c),timestamp:Date.now(),description:e.label||`Undo ${a}`,undoData:t,redoData:{...s}}}let u=e.refreshAfter!==!1;return u&&y(),{success:!0,reload:u,undo:l}}catch(e){return{success:!1,error:e.message}}},[t,v,K,d,y]),J=(0,N.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 K(`/api/v1/automation/${encodeURIComponent(n)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,objectName:e.objectName||v,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 R({flowName:n,runId:c.runId,screen:c.screen}),{success:!0,silent:!0};let l=e.refreshAfter!==!1;return l&&y(),{success:!0,data:s?.data,reload:l}}catch(e){return{success:!1,error:e.message}}},[K,v,y]),Y=(0,N.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(z.current.has(s))return{success:!1,error:`Action already in progress`};z.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||S(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(n,`_blank`)}catch{window.location.href=n}}},duration:1e4})}return e.refreshAfter===!0&&y(),{success:!0}}let i=e.objectName||v||`global`,a=await K(`/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 S.error(e),{success:!1,error:e}}let l=e.refreshAfter!==!1;l&&y();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||S(`浏览器拦截了弹窗 / 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 S.error(t),{success:!1,error:t}}finally{z.current.delete(s)}},[K,v,y]);return{confirmHandler:V,toastHandler:W,navigateHandler:G,paramCollectionHandler:H,resultDialogHandler:B,apiHandler:q,flowHandler:J,serverActionHandler:Y,authFetch:K,actionProviderProps:(0,N.useMemo)(()=>({context:{...r?{objectName:r}:{},user:U,apiBase:``,activeOrganization:d?{id:d.id,slug:d.slug,name:d.name}:null},onConfirm:V,onToast:W,onNavigate:G,onParamCollection:H,onResultDialog:B,handlers:{api:q,flow:J,script:Y,modal:Y}}),[r,U,d,V,W,G,H,B,q,J,Y]),dialogs:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(O,{state:C,onOpenChange:e=>{e||w({open:!1,message:``})}}),(0,P.jsx)(k,{state:T,onOpenChange:e=>{e||E({open:!1,params:[]})}}),(0,P.jsx)(j,{state:D,onAcknowledge:()=>{D.resolve?.(),I({open:!1})}}),(0,P.jsx)(A,{state:L,authFetch:K,baseUrl:``,dataSource:t,objects:n,onClose:()=>R(null),onComplete:()=>{R(null),y()}})]})}}function L({children:e,...t}){let n=I(t);return(0,P.jsxs)(f,{...n.actionProviderProps,children:[e,n.dialogs]})}var R=t({PageView:()=>z});function z(){let{t:e}=m(),{pageName:t}=r(),[n]=a(),{showDebug:o}=w(),l=s(),u=i(),{user:f}=c(),b=f?.role===`admin`,{pages:S,objects:O}=p(),{app:k}=C(),A=h(),[j,M]=(0,N.useState)(0),F=T(S,t,k?._packageId);if(!F)return(0,P.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,P.jsxs)(v,{children:[(0,P.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,P.jsx)(g,{className:`h-6 w-6 text-muted-foreground`})}),(0,P.jsx)(_,{children:e(`empty.pageNotFound`)}),(0,P.jsx)(x,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let I=Object.fromEntries(n.entries()),R=u.pathname.match(/\/apps\/([^/]+)/)?.[1],z=b&&!!R&&!!t;return(0,P.jsx)(L,{dataSource:A,objects:O,onRefresh:()=>M(e=>e+1),children:(0,P.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,P.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:[z&&(0,P.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,P.jsx)(y,{className:`h-3.5 w-3.5`})}),F.interfaceConfig?.source?(0,P.jsx)(D,{page:F},j):(0,P.jsx)(d,{schema:{...F,type:F.type||`page`,context:{...F.context,params:I,refreshKey:j}}},j)]}),(0,P.jsx)(E,{open:o,sections:[{title:`Page Configuration`,data:F}]})]})})}export{I as n,R as t};
|
|
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-CJNwTVno.js";import{A as u,B as d,O as f,T as p,r as m,w as h}from"./framework-BLEk-ou3.js";import{Co as g,H as _,R as v,Xi as y,gc as b,z as x}from"./ui-components-NS_7__gn.js";import{r as S}from"./vendor-ui-utils-rQOI1gAo.js";import"./MetadataProvider-Dh20h6BN.js";import{r as C}from"./ExpressionProvider-DKFCgLsJ.js";import{n as w,r as T,t as E}from"./MetadataInspector-CACgSTc7.js";import{t as D}from"./InterfaceListPage-CBomrdcf.js";import{a as O,i as k,n as A,r as j,t as M}from"./resolveActionParams-B_7wSkli.js";var N=e(n(),1),P=o(),F={id:`current-user`,name:`Demo User`,isPlatformAdmin:!1};function I(e){let{dataSource:t,objects:n,objectName:r,onRefresh:i}=e,a=s(),{user:o,activeOrganization:d}=c(),{fieldLabel:f,fieldOptionLabel:p,actionParamText:m,actionParamOptionLabel:h,actionDescription:g}=b(),_=(0,N.useMemo)(()=>r?n?.find(e=>e.name===r):void 0,[n,r]),v=r||_?.name,y=(0,N.useCallback)(()=>{i?.()},[i]),x=u({dataSource:t,onUndo:()=>{y(),S.success(`Change undone`)}}),[C,w]=(0,N.useState)({open:!1,message:``}),[T,E]=(0,N.useState)({open:!1,params:[]}),[D,I]=(0,N.useState)({open:!1}),[L,R]=(0,N.useState)(null),z=(0,N.useRef)(new Set),B=(0,N.useCallback)((e,t)=>new Promise(n=>{I({open:!0,spec:e,data:t,resolve:n})}),[]),V=(0,N.useCallback)((e,t)=>new Promise(n=>{w({open:!0,message:e,options:t,resolve:n})}),[]),H=(0,N.useCallback)((e,t)=>new Promise(i=>{let a=t?.params&&!Array.isArray(t.params)?t.params._rowRecord:void 0,o=M(e,{objectName:r||_?.name||``,objects:n||[],fieldLabel:f,fieldOptionLabel:p,row:a}),s=r||_?.name;E({open:!0,params:o.map(e=>({...e,label:m(s,t?.name,e.name,`label`,e.label)??e.label,placeholder:m(s,t?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:m(s,t?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(n=>({...n,label:h(s,t?.name,e.name,n.value,n.label)})):e.options})),title:t?.label||t?.title,description:g(s,t?.name,t?.description),resolve:i})}),[r,_,n,f,p,m,h]),U=o?{id:o.id,name:o.name,avatar:o.image,isPlatformAdmin:o?.isPlatformAdmin??!1}:F,W=(0,N.useCallback)((e,t)=>{if(t?.type===`error`){S.error(e);return}if(t?.undo){S.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{x.undo()}}});return}S.success(e,{duration:t?.duration})},[x]),G=(0,N.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):a(e)},[a]),K=(0,N.useMemo)(()=>l(),[]),q=(0,N.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&&d?.id&&(c.organizationId=d.id),e.bodyExtra&&typeof e.bodyExtra==`object`&&Object.assign(c,e.bodyExtra);let l=(e.method||`POST`).toUpperCase(),u={method:l,headers:{"Content-Type":`application/json`},credentials:`include`};l!==`GET`&&l!==`DELETE`&&(u.body=JSON.stringify(c));let f=await K(o,u);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&&y(),{success:!0,data:p,reload:e.refreshAfter!==!1}}let a=e.objectName||v,o=r._rowRecord,s={...r};delete s._rowRecord;let c=s.recordId??o?.[e.recordIdField||`id`];delete s.recordId,a&&typeof t?.execute==`function`?await t.execute(a,n,s):a&&c&&Object.keys(s).length>0&&typeof t?.update==`function`&&await t.update(a,c,s);let l;if(e.undoable&&a&&c&&o&&Object.keys(s).length>0&&typeof t?.update==`function`){let t={};for(let e of Object.keys(s))t[e]=o[e]??null;l={id:`undo-${a}-${c}-${Date.now()}`,type:`update`,objectName:a,recordId:String(c),timestamp:Date.now(),description:e.label||`Undo ${a}`,undoData:t,redoData:{...s}}}let u=e.refreshAfter!==!1;return u&&y(),{success:!0,reload:u,undo:l}}catch(e){return{success:!1,error:e.message}}},[t,v,K,d,y]),J=(0,N.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 K(`/api/v1/automation/${encodeURIComponent(n)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:a,objectName:e.objectName||v,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 R({flowName:n,runId:c.runId,screen:c.screen}),{success:!0,silent:!0};let l=e.refreshAfter!==!1;return l&&y(),{success:!0,data:s?.data,reload:l}}catch(e){return{success:!1,error:e.message}}},[K,v,y]),Y=(0,N.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(z.current.has(s))return{success:!1,error:`Action already in progress`};z.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||S(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(n,`_blank`)}catch{window.location.href=n}}},duration:1e4})}return e.refreshAfter===!0&&y(),{success:!0}}let i=e.objectName||v||`global`,a=await K(`/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 S.error(e),{success:!1,error:e}}let l=e.refreshAfter!==!1;l&&y();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||S(`浏览器拦截了弹窗 / 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 S.error(t),{success:!1,error:t}}finally{z.current.delete(s)}},[K,v,y]);return{confirmHandler:V,toastHandler:W,navigateHandler:G,paramCollectionHandler:H,resultDialogHandler:B,apiHandler:q,flowHandler:J,serverActionHandler:Y,authFetch:K,actionProviderProps:(0,N.useMemo)(()=>({context:{...r?{objectName:r}:{},user:U,apiBase:``,activeOrganization:d?{id:d.id,slug:d.slug,name:d.name}:null},onConfirm:V,onToast:W,onNavigate:G,onParamCollection:H,onResultDialog:B,handlers:{api:q,flow:J,script:Y,modal:Y}}),[r,U,d,V,W,G,H,B,q,J,Y]),dialogs:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(O,{state:C,onOpenChange:e=>{e||w({open:!1,message:``})}}),(0,P.jsx)(k,{state:T,onOpenChange:e=>{e||E({open:!1,params:[]})}}),(0,P.jsx)(j,{state:D,onAcknowledge:()=>{D.resolve?.(),I({open:!1})}}),(0,P.jsx)(A,{state:L,authFetch:K,baseUrl:``,dataSource:t,objects:n,onClose:()=>R(null),onComplete:()=>{R(null),y()}})]})}}function L({children:e,...t}){let n=I(t);return(0,P.jsxs)(f,{...n.actionProviderProps,children:[e,n.dialogs]})}var R=t({PageView:()=>z});function z(){let{t:e}=m(),{pageName:t}=r(),[n]=a(),{showDebug:o}=w(),l=s(),u=i(),{user:f}=c(),b=f?.role===`admin`,{pages:S,objects:O}=p(),{app:k}=C(),A=h(),[j,M]=(0,N.useState)(0),F=T(S,t,k?._packageId);if(!F)return(0,P.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,P.jsxs)(v,{children:[(0,P.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,P.jsx)(g,{className:`h-6 w-6 text-muted-foreground`})}),(0,P.jsx)(_,{children:e(`empty.pageNotFound`)}),(0,P.jsx)(x,{children:e(`empty.pageNotFoundDescription`,{name:t})})]})});let I=Object.fromEntries(n.entries()),R=u.pathname.match(/\/apps\/([^/]+)/)?.[1],z=b&&!!R&&!!t;return(0,P.jsx)(L,{dataSource:A,objects:O,onRefresh:()=>M(e=>e+1),children:(0,P.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,P.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative`,children:[z&&(0,P.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,P.jsx)(y,{className:`h-3.5 w-3.5`})}),F.interfaceConfig?.source?(0,P.jsx)(D,{page:F},j):(0,P.jsx)(d,{schema:{...F,type:F.type||`page`,context:{...F.context,params:I,refreshKey:j}}},j)]}),(0,P.jsx)(E,{open:o,sections:[{title:`Page Configuration`,data:F}]})]})})}export{I as n,R as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{f as r,o as i}from"./infrastructure-CJNwTVno.js";import{$n as a,Jn as o,Ma as s,Pr as c,Sr as l,Xn as u,Yn as d,Zn as f,b as p,er as m,gs as h,hr as g,ir as _,ja as v,jr as y,nn as b,nr as x,on as S,qn as C,rr as w,tr as T,ys as E}from"./ui-components-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{f as r,o as i}from"./infrastructure-CJNwTVno.js";import{$n as a,Jn as o,Ma as s,Pr as c,Sr as l,Xn as u,Yn as d,Zn as f,b as p,er as m,gs as h,hr as g,ir as _,ja as v,jr as y,nn as b,nr as x,on as S,qn as C,rr as w,tr as T,ys as E}from"./ui-components-NS_7__gn.js";var D=e(t(),1),O=n();function k(){let{user:e,updateUser:t,isLoading:n,changePassword:v,setInitialPassword:k,hasLocalPassword:j}=r(),{upload:M}=p(),[N,P]=(0,D.useState)(e?.name??``),[F,I]=(0,D.useState)(!1),[L,R]=(0,D.useState)(null),z=(0,D.useRef)(null),[B,V]=(0,D.useState)(!1),[H,U]=(0,D.useState)(null);return(0,D.useEffect)(()=>{P(e?.name??``)},[e?.name]),e?(0,O.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-2xl`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Profile`}),(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage your account settings`})]}),(0,O.jsx)(C,{children:(0,O.jsxs)(o,{className:`pt-6`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,O.jsxs)(m,{className:`h-16 w-16`,children:[(0,O.jsx)(x,{src:e.image??void 0,alt:e.name??`User`}),(0,O.jsx)(T,{className:`text-lg bg-primary text-primary-foreground`,children:i(e)})]}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`text-lg font-semibold truncate`,children:e.name??`User`}),(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground truncate`,children:e.email}),(0,O.jsx)(a,{variant:`secondary`,className:`mt-1`,children:e.role??`member`})]}),(0,O.jsxs)(`div`,{className:`flex flex-col gap-2 shrink-0`,children:[(0,O.jsx)(`input`,{ref:z,type:`file`,accept:`image/*`,className:`hidden`,onChange:async e=>{let n=e.target.files?.[0];if(z.current&&(z.current.value=``),n){V(!0),U(null);try{await t({image:(await M(n)).url})}catch(e){U(e instanceof Error?e.message:String(e))}finally{V(!1)}}},"data-testid":`profile-avatar-file`}),(0,O.jsxs)(g,{type:`button`,variant:`outline`,size:`sm`,disabled:B,onClick:()=>z.current?.click(),"data-testid":`profile-avatar-upload-btn`,children:[B?(0,O.jsx)(s,{className:`mr-2 h-4 w-4 animate-spin`}):(0,O.jsx)(c,{className:`mr-2 h-4 w-4`}),e.image?`Replace`:`Upload`]}),e.image&&(0,O.jsxs)(g,{type:`button`,variant:`ghost`,size:`sm`,disabled:B,onClick:async()=>{V(!0),U(null);try{await t({image:null})}catch(e){U(e instanceof Error?e.message:String(e))}finally{V(!1)}},"data-testid":`profile-avatar-remove-btn`,children:[(0,O.jsx)(l,{className:`mr-2 h-4 w-4`}),`Remove`]})]})]}),H&&(0,O.jsxs)(w,{variant:`destructive`,className:`mt-4`,children:[(0,O.jsx)(E,{className:`h-4 w-4`}),(0,O.jsx)(_,{children:H})]})]})}),(0,O.jsxs)(C,{children:[(0,O.jsxs)(u,{children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(y,{className:`h-4 w-4 text-muted-foreground`}),(0,O.jsx)(f,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,O.jsx)(d,{children:`Update your name and view account details`})]}),(0,O.jsx)(o,{children:(0,O.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),R(null),I(!1);try{await t({name:N}),I(!0)}catch(e){R(e instanceof Error?e.message:String(e))}},className:`space-y-4`,children:[L&&(0,O.jsxs)(w,{variant:`destructive`,children:[(0,O.jsx)(E,{className:`h-4 w-4`}),(0,O.jsx)(_,{children:L})]}),F&&(0,O.jsxs)(w,{children:[(0,O.jsx)(h,{className:`h-4 w-4 text-green-600`}),(0,O.jsx)(_,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{htmlFor:`profile-name`,children:`Name`}),(0,O.jsx)(b,{id:`profile-name`,type:`text`,value:N,onChange:e=>P(e.target.value),required:!0,"aria-required":`true`,disabled:n})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{htmlFor:`profile-email`,children:`Email`}),(0,O.jsx)(b,{id:`profile-email`,type:`email`,value:e.email,disabled:!0,className:`bg-muted text-muted-foreground`}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Email cannot be changed.`})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{children:`Role`}),(0,O.jsx)(b,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,O.jsx)(g,{type:`submit`,disabled:n,className:`w-full sm:w-auto`,children:n?`Saving…`:`Save Changes`})]})})]}),(0,O.jsx)(A,{changePassword:v,setInitialPassword:k,hasLocalPassword:j})]}):null}function A({changePassword:e,setInitialPassword:t,hasLocalPassword:n,highlight:r,onPasswordSet:i}){let[a,s]=(0,D.useState)(null),[c,l]=(0,D.useState)(``),[p,m]=(0,D.useState)(``),[y,x]=(0,D.useState)(``),[T,k]=(0,D.useState)(!1),[A,j]=(0,D.useState)(null),[M,N]=(0,D.useState)(null);(0,D.useEffect)(()=>{let e=!1;return n().then(t=>{e||s(t)}).catch(()=>{e||s(!1)}),()=>{e=!0}},[n]);let P=()=>{l(``),m(``),x(``)},F=async n=>{if(n.preventDefault(),j(null),N(null),p.length<8){j(`Password must be at least 8 characters`);return}if(p!==y){j(`Passwords do not match`);return}k(!0);try{if(a){if(!c){j(`Enter your current password`),k(!1);return}await e(c,p),N(`Password changed.`)}else await t(p),N(`Local password set. You can now sign in with email and password on this environment.`),s(!0),i?.();P()}catch(e){j(e instanceof Error?e.message:String(e))}finally{k(!1)}},I=a===null;return(0,O.jsxs)(C,{className:r?`ring-2 ring-amber-300 dark:ring-amber-700`:void 0,children:[(0,O.jsxs)(u,{children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),(0,O.jsx)(f,{className:`text-base sm:text-lg`,children:a?`Change Password`:`Set Local Password`})]}),(0,O.jsx)(d,{children:a?`Update the password you use to sign in to this environment.`:`You signed in via single sign-on. Set a local password to also sign in with email and password on this environment.`})]}),(0,O.jsx)(o,{children:(0,O.jsxs)(`form`,{onSubmit:F,className:`space-y-4 max-w-md`,children:[a&&(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{htmlFor:`current-password`,children:`Current password`}),(0,O.jsx)(b,{id:`current-password`,type:`password`,autoComplete:`current-password`,value:c,onChange:e=>l(e.target.value),disabled:T||I,required:!0})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{htmlFor:`new-password`,children:a?`New password`:`Password`}),(0,O.jsx)(b,{id:`new-password`,type:`password`,autoComplete:`new-password`,value:p,onChange:e=>m(e.target.value),disabled:T||I,minLength:8,required:!0})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(S,{htmlFor:`confirm-password`,children:`Confirm password`}),(0,O.jsx)(b,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,value:y,onChange:e=>x(e.target.value),disabled:T||I,minLength:8,required:!0})]}),A&&(0,O.jsxs)(w,{variant:`destructive`,children:[(0,O.jsx)(E,{className:`h-4 w-4`}),(0,O.jsx)(_,{children:A})]}),M&&(0,O.jsxs)(w,{children:[(0,O.jsx)(h,{className:`h-4 w-4`}),(0,O.jsx)(_,{children:M})]}),(0,O.jsx)(g,{type:`submit`,disabled:T||I,className:`w-full sm:w-auto`,children:T?`Saving…`:a?`Change password`:`Set password`})]})})]})}export{k as ProfilePage};
|
|
@@ -1 +1 @@
|
|
|
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-BLEk-ou3.js";import{$n as i,$o as a,Bn as o,Fi as ee,Hn as s,Ia as te,Io as ne,Jn as re,Ln as c,Ri as ie,Rn as l,Ui as ae,Vn as u,Xn as oe,Yn as se,Yo as ce,Zn as le,ct as d,dt as f,hr as p,lt as m,nn as h,on as g,ot as ue,qn as de,st as fe,ut as pe,yi as me,zn as _}from"./ui-components-CrPYFyEM.js";import{r as v}from"./vendor-ui-utils-rQOI1gAo.js";import"./src-Bzm5L_v8.js";var y=e(t(),1),b=n();function x(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function S(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function C(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[C,he]=(0,y.useState)([]),[w,T]=(0,y.useState)(!0),[E,D]=(0,y.useState)(null),[ge,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(!1),[_e,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`thank-you`),[H,U]=(0,y.useState)(``),[W,G]=(0,y.useState)(``),[K,q]=(0,y.useState)(``),[J,Y]=(0,y.useState)(!1),X=async()=>{if(!e?.meta?.getItems){D(`meta.getItems is not available on this client`),T(!1);return}T(!0),D(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=x(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),he(a)}catch(e){D(e?.message??String(e))}finally{T(!1)}};(0,y.useEffect)(()=>{X()},[]);let ve=typeof window<`u`?window.location.origin:``,Z=e=>`${ve}/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(!k||!j)return;let t=C.find(e=>e.name===k);if(!t)return;let n=S(j);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};P(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),O(!1),A(``),M(``),await X()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{P(!1)}},Se=e=>{L(e),z(e.slug);let t=e.spec?.submitBehavior;V(t?.kind??`thank-you`),U(t?.title??``),G(t?.message??``),q(t?.url??``),F(!0)},Ce=async()=>{if(!I)return;let t=S(R);if(!t){v.error(`Invalid slug`);return}let n;switch(B){case`thank-you`:n={kind:`thank-you`},H&&(n.title=H),W&&(n.message=W);break;case`redirect`:if(!K){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:K};break;case`continue`:case`next-record`:n={kind:B};break}let r={...I.spec,sharing:{...I.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};Y(!0);try{await e.meta.saveItem(`view`,I.name,r),v.success(`Saved ${I.name}`),F(!1),L(null),await X()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{Y(!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)(de,{children:[(0,b.jsxs)(oe,{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)(se,{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:()=>O(!0),disabled:C.length===0,title:C.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ae,{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:X,disabled:w,children:[(0,b.jsx)(ee,{className:`h-3.5 w-3.5 ${w?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(re,{children:[E&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:E}),!w&&!$&&(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)(ue,{children:[(0,b.jsx)(pe,{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)(fe,{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)(ne,{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)(a,{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)(ce,{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)(me,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(c,{open:ge,onOpenChange:O,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:k,onChange:e=>A(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),C.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:j,onChange:e=>M(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>O(!1),disabled:N,children:`Cancel`}),(0,b.jsx)(p,{onClick:xe,disabled:N||!k||!j,children:N?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(c,{open:_e,onOpenChange:F,children:(0,b.jsxs)(l,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(s,{children:I?`Edit ${I.label??I.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:R,onChange:e=>z(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:B,onChange:e=>V(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)`})]})]}),B===`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:H,onChange:e=>U(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:W,onChange:e=>G(e.target.value)})]})]}),B===`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:K,onChange:e=>q(e.target.value)})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>F(!1),disabled:J,children:`Cancel`}),(0,b.jsx)(p,{onClick:Ce,disabled:J||!R,children:J?`Saving…`:`Save`})]})]})})]})}export{C as PublicFormsPage};
|
|
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-BLEk-ou3.js";import{$n as i,$o as a,Bn as o,Fi as ee,Hn as s,Ia as te,Io as ne,Jn as re,Ln as c,Ri as ie,Rn as l,Ui as ae,Vn as u,Xn as oe,Yn as se,Yo as ce,Zn as le,ct as d,dt as f,hr as p,lt as m,nn as h,on as g,ot as ue,qn as de,st as fe,ut as pe,yi as me,zn as _}from"./ui-components-NS_7__gn.js";import{r as v}from"./vendor-ui-utils-rQOI1gAo.js";import"./src-9qM7N8MR.js";var y=e(t(),1),b=n();function x(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function S(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function C(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[C,he]=(0,y.useState)([]),[w,T]=(0,y.useState)(!0),[E,D]=(0,y.useState)(null),[ge,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(!1),[_e,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`thank-you`),[H,U]=(0,y.useState)(``),[W,G]=(0,y.useState)(``),[K,q]=(0,y.useState)(``),[J,Y]=(0,y.useState)(!1),X=async()=>{if(!e?.meta?.getItems){D(`meta.getItems is not available on this client`),T(!1);return}T(!0),D(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=x(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),he(a)}catch(e){D(e?.message??String(e))}finally{T(!1)}};(0,y.useEffect)(()=>{X()},[]);let ve=typeof window<`u`?window.location.origin:``,Z=e=>`${ve}/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(!k||!j)return;let t=C.find(e=>e.name===k);if(!t)return;let n=S(j);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};P(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),O(!1),A(``),M(``),await X()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{P(!1)}},Se=e=>{L(e),z(e.slug);let t=e.spec?.submitBehavior;V(t?.kind??`thank-you`),U(t?.title??``),G(t?.message??``),q(t?.url??``),F(!0)},Ce=async()=>{if(!I)return;let t=S(R);if(!t){v.error(`Invalid slug`);return}let n;switch(B){case`thank-you`:n={kind:`thank-you`},H&&(n.title=H),W&&(n.message=W);break;case`redirect`:if(!K){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:K};break;case`continue`:case`next-record`:n={kind:B};break}let r={...I.spec,sharing:{...I.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};Y(!0);try{await e.meta.saveItem(`view`,I.name,r),v.success(`Saved ${I.name}`),F(!1),L(null),await X()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{Y(!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)(de,{children:[(0,b.jsxs)(oe,{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)(se,{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:()=>O(!0),disabled:C.length===0,title:C.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ae,{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:X,disabled:w,children:[(0,b.jsx)(ee,{className:`h-3.5 w-3.5 ${w?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(re,{children:[E&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:E}),!w&&!$&&(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)(ue,{children:[(0,b.jsx)(pe,{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)(fe,{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)(ne,{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)(a,{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)(ce,{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)(me,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(c,{open:ge,onOpenChange:O,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:k,onChange:e=>A(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),C.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:j,onChange:e=>M(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>O(!1),disabled:N,children:`Cancel`}),(0,b.jsx)(p,{onClick:xe,disabled:N||!k||!j,children:N?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(c,{open:_e,onOpenChange:F,children:(0,b.jsxs)(l,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(u,{children:[(0,b.jsx)(s,{children:I?`Edit ${I.label??I.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:R,onChange:e=>z(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:B,onChange:e=>V(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)`})]})]}),B===`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:H,onChange:e=>U(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:W,onChange:e=>G(e.target.value)})]})]}),B===`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:K,onChange:e=>q(e.target.value)})]})]}),(0,b.jsxs)(o,{children:[(0,b.jsx)(p,{variant:`ghost`,onClick:()=>F(!1),disabled:J,children:`Cancel`}),(0,b.jsx)(p,{onClick:Ce,disabled:J||!R,children:J?`Saving…`:`Save`})]})]})})]})}export{C as PublicFormsPage};
|
|
@@ -1 +1 @@
|
|
|
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-CJNwTVno.js";import{A as u,B as d,O as f,d as p,m,p as h,r as g,ut as _,x as v}from"./framework-BLEk-ou3.js";import{Es as y,H as b,R as x,Wo as S,gc as ee,z as C}from"./ui-components-CrPYFyEM.js";import{r as w}from"./vendor-ui-utils-rQOI1gAo.js";import{n as te}from"./RecentItemsProvider-B76qldBH.js";import{i as ne,n as re,t as ie}from"./useActionModal-DDu3wUOI.js";import{i as ae,n as oe}from"./utils-bipVuqQL.js";import{n as se,t as ce}from"./MetadataInspector-BRICMLXW.js";import{n as le,o as ue,r as de,s as fe}from"./plugins-views-DUKPQNs8.js";import{t as pe}from"./ManagedByBadge-Difq_L_A.js";import{t as me}from"./skeletons-B_SNEnMn.js";import{a as he,i as ge,n as _e,r as ve,t as ye}from"./resolveActionParams-C_x4GXvS.js";var T=e(n(),1),E=o(),be=(0,T.createContext)(void 0);function D({children:e}){let[t,n]=(0,T.useState)(`home`),[r,i]=(0,T.useState)(),[a,o]=(0,T.useState)(),s=(0,T.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,E.jsx)(be.Provider,{value:s,children:e})}function O(){return(0,T.useContext)(be)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function xe(e){let{setRecordTitle:t}=O();(0,T.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}function k(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,T.useState)(`disconnected`),[l,u]=(0,T.useState)(null),[d,f]=(0,T.useState)([]),[p,m]=(0,T.useState)(null),h=(0,T.useRef)(null),g=(0,T.useRef)(0),_=(0,T.useRef)(null),v=(0,T.useRef)(new Map),y=(0,T.useRef)([]),b=(0,T.useRef)(!0),x=(0,T.useRef)(!1),S=(0,T.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),ee=(0,T.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,T.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]),w=(0,T.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),te=(0,T.useCallback)(()=>{S(),g.current=0,C()},[C,S]),ne=(0,T.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]),re=(0,T.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,T.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:ne,subscribe:re,disconnect:w,reconnect:te,error:p}}var A=0;function Se(){return A+=1,`conflict-${Date.now()}-${A}`}var j=0;function M(){return j+=1,`ver-${Date.now()}-${j}`}function N(e,t,n){let[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)([]);return{versions:r,currentVersion:(0,T.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,T.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:M(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,T.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:M(),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,T.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:M(),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,T.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:M(),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,T.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,T.useCallback)(e=>{let t={...e,id:Se()};o(e=>[...e,t])},[]),clearHistory:(0,T.useCallback)(()=>{i([]),o([])},[])}}var P={sm:24,md:32,lg:40},F={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Ce(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=P[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,T.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,T.useMemo)(()=>[...l].reverse(),[l]);return T.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&T.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>T.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?T.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Ce(e.userName),r&&T.createElement(`span`,{style:{...m,backgroundColor:F[e.status]}}))))}var Te=T.createContext({});function Ee(){let e=T.useContext(Te),[t,n]=T.useState([]);return T.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function De(e,t){let n=T.useContext(Te),[r,i]=T.useState([]);return T.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`]),I=[`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 I.some(e=>n===e||n.endsWith(`_${e}`))}function Re({dataSource:e,objects:t,onEdit:n,objectNameOverride:o,recordIdOverride:be,embedded:D}){let O=r(),k=O.appName,A=o??O.objectName,Se=be??O.recordId,{showDebug:j}=se(),{user:M}=c(),N=s(),P=i().state?.from,{t:F}=g(),{objectLabel:Ce,viewLabel:Te,sectionLabel:Ee,actionLabel:Oe,actionConfirm:Ae,actionSuccess:Me,actionParamText:I,actionParamOptionLabel:Ie,actionDescription:Re,fieldLabel:ze,fieldOptionLabel:Be}=ee(),{isFavorite:Ve,toggleFavorite:He,refreshLabel:Ue}=ne(),{addRecentItem:We}=te(),[Ge,Ke]=(0,T.useState)(!0),[qe,L]=(0,T.useState)([]),[R,Je]=(0,T.useState)([]),[Ye,z]=(0,T.useState)(0),[Xe,B]=(0,T.useState)(null),[Ze,Qe]=(0,T.useState)({}),[$e,et]=(0,T.useState)(null),[tt,nt]=(0,T.useState)(!1),[V,rt]=(0,T.useState)(),H=t.find(e=>e.name===A);xe(D?void 0:V);let U=Se,it=De(A,U),W=(0,T.useMemo)(()=>!A||!U?null:{id:`record:${A}:${U}`,label:V||U||``,href:`/apps/${k}/${A}/record/${U}`,type:`record`},[k,A,U,V]),at=W?Ve(W.id):!1,ot=(0,T.useCallback)(()=>{W&&He(W)},[W,He]),{page:st,slots:G}=v(A),ct=(0,T.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 H?.detail?.renderViaSchema!==!1},[H]),lt=(0,T.useMemo)(()=>st||!H||!ct&&!G?null:le(H,G?{slots:G}:void 0),[ct,st,G,H]),K=st||lt,[q,ut]=(0,T.useState)(null),[dt,J]=(0,T.useState)(`idle`);(0,T.useEffect)(()=>{let t=!1;if(!K||!U||!A||!e?.findOne){ut(null),J(`idle`);return}let n=_(H?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{J(`loading`),(r?e.findOne(A,U,r):e.findOne(A,U)).then(e=>{t||(e&&typeof e==`object`?(ut(e),J(`loaded`)):(ut(null),J(`missing`)))}).catch(()=>{t||(ut(null),J(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==A||String(t.recordId)!==String(U)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[K,A,U,e,H]),(0,T.useEffect)(()=>{if(!q||typeof q!=`object`||!H)return;let e=oe(H,q);e&&e!==`Untitled`&&e!==V&&rt(e)},[q,H,V]),(0,T.useEffect)(()=>{if(!A||!U||!k||!V)return;let e=`record:${A}:${U}`;We({id:e,label:V,href:`/apps/${k}/${A}/record/${U}`,type:`record`}),Ue(e,V)},[k,A,U,V,We,Ue]);let[ft,pt]=(0,T.useState)({open:!1,message:``}),[mt,ht]=(0,T.useState)({open:!1,params:[]}),[gt,_t]=(0,T.useState)({open:!1}),vt=(0,T.useCallback)((e,t)=>new Promise(n=>{_t({open:!0,spec:e,data:t,resolve:n})}),[]),yt=(0,T.useCallback)((e,t)=>new Promise(n=>{pt({open:!0,message:e,options:t,resolve:n})}),[]),bt=(0,T.useCallback)((e,n)=>new Promise(r=>{let i=ye(e,{objectName:A||H?.name||``,objects:t||[],fieldLabel:ze,fieldOptionLabel:Be}),a=A||H?.name;ht({open:!0,params:i.map(e=>({...e,label:I(a,n?.name,e.name,`label`,e.label)??e.label,placeholder:I(a,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:I(a,n?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(t=>({...t,label:Ie(a,n?.name,e.name,t.value,t.label)})):e.options})),title:n?.label||n?.title,description:Re(a,n?.name,n?.description),resolve:r})}),[A,H,t,ze,Be,I,Ie]),xt=u({dataSource:e,onUndo:()=>{z(e=>e+1),w.success(`Change undone`)}}),St=(0,T.useCallback)((e,t)=>{if(t?.type===`error`){w.error(e);return}if(t?.undo){w.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{xt.undo()}}});return}w.success(e,{duration:t?.duration})},[xt]),Ct=(0,T.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):N(e)},[N]),wt=(0,T.useCallback)(async t=>{try{let n=t.target||t.name,r={...t.params||{}};delete r._rowRecord;let i;switch(n){case`opportunity_change_stage`:await e.update(A,U,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(A,U,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(A,U,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:if(Object.keys(r).length>0){if(t.undoable&&q&&A&&U){let e={};for(let t of Object.keys(r))e[t]=q[t]??null;i={id:`undo-${A}-${U}-${Date.now()}`,type:`update`,objectName:A,recordId:String(U),timestamp:Date.now(),description:t.label||`Undo ${A}`,undoData:e,redoData:{...r}}}await e.update(A,U,r)}break}let a=t.refreshAfter===!0;return(a||i)&&z(e=>e+1),{success:!0,reload:a,undo:i}}catch(e){return{success:!1,error:e.message}}},[e,A,U,q]),{modalHandler:Tt,modalElement:Et}=ie(e),Y=(0,T.useMemo)(()=>l(),[]),Dt=(0,T.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 Y(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:U,objectName:A,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 B({flowName:t,runId:i.runId,screen:i.screen}),{success:!0,silent:!0};let a=e.refreshAfter!==!1;return a&&z(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Y,U,A]),Ot=(0,T.useRef)(new Set),kt=(0,T.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}:${U??``}`;if(Ot.current.has(r))return{success:!1,error:`Action already in progress`};Ot.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(U==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(U)))}`;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||w(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(t,`_blank`)}catch{window.location.href=t}}},duration:1e4})}return e.refreshAfter===!0&&z(e=>e+1),{success:!0}}let a=e.objectName||A||`global`,o=await Y(`/api/v1/actions/${encodeURIComponent(a)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:U,params:n})}),s=await o.json().catch(()=>null),c=s?.data,l=c&&typeof c==`object`&&c.success===!1;if(!o.ok||s&&s.success===!1||l){let e=l&&c.error||s?.error||`Action "${t}" failed (HTTP ${o.status})`;if(i)try{i.close()}catch{}return w.error(e),{success:!1,error:e}}let u=e.refreshAfter!==!1;u&&z(e=>e+1);let d=s?.data;if(d&&typeof d==`object`&&typeof d.redirectUrl==`string`){let e=d.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||w(`浏览器拦截了弹窗 / 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:d,reload:u}}catch(e){if(i)try{i.close()}catch{}let t=e.message;return w.error(t),{success:!1,error:t}}finally{Ot.current.delete(r)}},[Y,U,A]),X=re(A,U,M?.id),At=(0,T.useRef)(X);At.current=X;let jt=(0,T.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await At.current.approve({comment:n.comment});else if(t===`reject_request`)await At.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return z(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Mt=(0,T.useMemo)(()=>ae(H,t),[H,t]);(0,T.useEffect)(()=>{if(K||!e||!U||Mt.length===0)return;let t=!1;return Promise.all(Mt.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:U}}).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;Qe(n)}),()=>{t=!0}},[e,U,Mt,H,K]);let Z=(0,T.useMemo)(()=>!H||H.name===`sys_audit_log`||H.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[H,t]);(0,T.useEffect)(()=>{if(!e||!U||!H||!Z){et(null);return}let t=!1;return nt(!0),e.find(`sys_audit_log`,{$filter:{record_id:U,object_name:H.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(H.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};et(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),et([]))}).finally(()=>{t||nt(!1)}),()=>{t=!0}},[e,U,H,Z]),(0,T.useEffect)(()=>{if(!e)return;let t=!1,n=M?[{id:String(M.id),label:M.name||M.email||String(M.id),avatarUrl:M.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))];Je(o.length>0?o:n)}catch{if(t)return;Je(n)}})(),()=>{t=!0}},[e,M?.id,M?.name,M?.email]);let Q=(0,T.useMemo)(()=>M?{id:M.id,name:M.name,avatar:M.image}:Ne,[M?.id,M?.name,M?.image]);(0,T.useEffect)(()=>{if(!e||!A||!U)return;let t=`${A}:${U}`,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)}));L(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:A,record_id:U},$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,sourceObject:n.source_object??void 0,sourceId:n.source_id??void 0})}t.length&&L(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,A,U,Q]);let Nt=(0,T.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(L(e=>[...e,n]),e){let r=`${A}:${U}`,i=de(t,R);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,A,U,R]),Pt=(0,T.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(L(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${A}:${U}`,a=de(n,R);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,A,U,R]),Ft=(0,T.useCallback)((t,n)=>{L(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,T.useEffect)(()=>{Ke(!0),queueMicrotask(()=>Ke(!1))},[A,Se]);let $=(0,T.useMemo)(()=>{if(!H)return{type:`detail-view`};let n=H.primaryField||Object.keys(H.fields||{}).find(e=>e===`name`||e===`title`),r=H.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?Ee(H.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!H.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=H.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${H.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(H.fields||{}).filter(e=>!Pe.has(e)&&!Fe.has(e)&&!H.fields[e]?.hidden),t=e=>{let t=H.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,H.fields[e])),r=e.filter(e=>Le(e,H.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(H.name,`details`,F(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(H.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(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:Ae(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:Me(H.name,e.name,e.successMessage)}}));if(X.available&&X.canDecide){let e={name:`comment`,label:F(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:F(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`default`,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:F(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:F(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,locations:[`record_header`],refreshAfter:!0,confirmText:F(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:F(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),o=H.views?.detail?.highlightFields??[],s=H.views?.detail?.sectionGroups??H.views?.form?.sectionGroups,c=k?`/apps/${k}`:``,l=Mt.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let s=t.find(e=>e.name===n),l=U||``,u=a||(s?Ce({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?()=>N(d()):void 0,g=c?()=>N(f()):void 0,_=c?e=>{let t=m(e);t&&N(t)}:void 0,v=c?e=>{let t=p(e);t&&N(t)}:void 0,y=e&&l?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),w.success(F(`detail.deleteSuccess`,{defaultValue:`Deleted`})),Qe(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){w.error(e?.message||F(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:u,type:`table`,api:n,data:Ze[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(H);return{type:`detail-view`,objectName:H.name,resourceId:U,showBack:!D,onBack:`history`,showEdit:u.edit,title:H.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...Z&&{history:{entries:$e??[],loading:tt&&$e===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}]}}},[H?.name,U,Ze,Ye,k,N,e,F,Ce,t,Z,$e,tt,X.available,X.canDecide,X.pendingRequest,X.latestRequest,D]);if(Ge)return(0,E.jsx)(me,{});if(!H)return(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,E.jsxs)(x,{children:[(0,E.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,E.jsx)(S,{className:`h-6 w-6 text-muted-foreground`})}),(0,E.jsx)(b,{children:F(`empty.objectNotFound`)}),(0,E.jsx)(C,{children:F(`empty.objectNotFoundDescription`,{name:A})})]})});if(K&&dt===`missing`)return(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,E.jsxs)(x,{children:[(0,E.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,E.jsx)(S,{className:`h-6 w-6 text-muted-foreground`})}),(0,E.jsx)(b,{children:F(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,E.jsx)(C,{children:F(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(K){let r=K?.disableDiscussion===!0,i=je(K),o=!r&&!i,s=(()=>{let e=$.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),c=(()=>{let t=ke(H),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:F(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:U,objectName:A}}))}}),r.push({name:`sys_edit`,label:F(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:U})})),r.push({name:`sys_share`,label:F(`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),w.success(F(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){w.error(F(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:F(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=F(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(A,U),w.success(F(`detail.deleted`,{defaultValue:`Record deleted`})),N(`${k?`/apps/${k}`:``}/${A}`,{replace:!0})}catch(e){w.error(e?.message||`Delete failed`)}}}),r})(),l=s.length>0?s:void 0,u=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,g=$.history?{entries:$.history.entries??[],loading:!!$.history.loading,emptyText:$.history.emptyText}:void 0,_=st?K:le(H,{sections:$.sections,highlightFields:Array.isArray($.highlightFields)?$.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:l,related:u,history:g,showReferenceRail:H?.detail?.showReferenceRail===!0||void 0,hideReferenceRail:H?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:H?.detail?.hideRelatedTab===!0||void 0,...G?{slots:G}:{}});return(0,E.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,E.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[it.length>0&&(0,E.jsx)(we,{users:it,size:`sm`,maxVisible:3,showStatus:!0}),(0,E.jsx)(pe,{managedBy:H?.managedBy})]}),(0,E.jsx)(m,{objectName:A,recordId:U,data:q,objectSchema:H,dataSource:e,embedded:D,headerSystemActions:c,isFavorite:at,onToggleFavorite:W?ot:void 0,children:(0,E.jsx)(h,{children:(0,E.jsx)(p,{items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft,mentionSuggestions:R,children:(0,E.jsxs)(f,{context:{record:q||{},objectName:A,user:Q},onConfirm:yt,onToast:St,onNavigate:Ct,onParamCollection:bt,onResultDialog:vt,onModal:Tt,handlers:{api:wt,flow:Dt,script:kt,approval:jt},children:[(0,E.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,E.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[P?.pathname&&P?.label&&(0,E.jsxs)(a,{to:P.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(y,{className:`h-4 w-4`}),(0,E.jsx)(`span`,{children:P.label})]}),(0,E.jsx)(d,{schema:_}),o&&(0,E.jsx)(`div`,{className:`mt-6`,children:(0,E.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft,mentionSuggestions:R})})]}),(0,E.jsx)(ce,{open:j,sections:[{title:`Page Schema`,data:_}]})]}),Et]})})})}),(0,E.jsx)(he,{state:ft,onOpenChange:e=>{e||pt(e=>({...e,open:!1}))}}),(0,E.jsx)(ge,{state:mt,onOpenChange:e=>{e||ht(e=>({...e,open:!1}))}}),(0,E.jsx)(ve,{state:gt,onAcknowledge:()=>{gt.resolve?.(),_t({open:!1})}}),(0,E.jsx)(_e,{state:Xe,authFetch:Y,baseUrl:``,dataSource:e,objects:t,onClose:()=>B(null),onComplete:()=>{B(null),z(e=>e+1)}})]})}return(0,E.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,E.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[it.length>0&&(0,E.jsx)(we,{users:it,size:`sm`,maxVisible:3,showStatus:!0}),(0,E.jsx)(pe,{managedBy:H?.managedBy})]}),(0,E.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,E.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,E.jsxs)(f,{context:{record:{},objectName:A,user:Q},onConfirm:yt,onToast:St,onNavigate:Ct,onParamCollection:bt,onResultDialog:vt,onModal:Tt,handlers:{api:wt,flow:Dt,script:kt,approval:jt},children:[(0,E.jsx)(fe,{schema:$,dataSource:e,objectLabel:Ce({name:H.name,label:H.label}),isFavorite:at,onToggleFavorite:W?ot:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=oe(H,e);t&&t!==V&&t!==`Untitled`&&rt(t)},onEdit:()=>{n({id:U})},discussionSlot:(0,E.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft})},Ye),Et]})}),(0,E.jsx)(ce,{open:j,sections:[{title:`View Schema`,data:$}]})]}),(0,E.jsx)(he,{state:ft,onOpenChange:e=>{e||pt(e=>({...e,open:!1}))}}),(0,E.jsx)(ge,{state:mt,onOpenChange:e=>{e||ht(e=>({...e,open:!1}))}}),(0,E.jsx)(ve,{state:gt,onAcknowledge:()=>{gt.resolve?.(),_t({open:!1})}}),(0,E.jsx)(_e,{state:Xe,authFetch:Y,baseUrl:``,dataSource:e,objects:t,onClose:()=>B(null),onComplete:()=>{B(null),z(e=>e+1)}})]})}export{we as a,D as c,Ee as i,O as l,Me as n,N as o,ke as r,k as s,Re as t};
|
|
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-CJNwTVno.js";import{A as u,B as d,O as f,d as p,m,p as h,r as g,ut as _,x as v}from"./framework-BLEk-ou3.js";import{Es as y,H as b,R as x,Wo as S,gc as ee,z as C}from"./ui-components-NS_7__gn.js";import{r as w}from"./vendor-ui-utils-rQOI1gAo.js";import{n as te}from"./RecentItemsProvider-B76qldBH.js";import{i as ne,n as re,t as ie}from"./useActionModal-BE61500N.js";import{r as ae,t as oe}from"./utils-29quoGQV.js";import{n as se,t as ce}from"./MetadataInspector-CACgSTc7.js";import{n as le,o as ue,r as de,s as fe}from"./plugins-views-B-EGcBP2.js";import{t as pe}from"./ManagedByBadge-Bmg77Q4v.js";import{t as me}from"./skeletons-BK7w4pLE.js";import{a as he,i as ge,n as _e,r as ve,t as ye}from"./resolveActionParams-B_7wSkli.js";var T=e(n(),1),E=o(),be=(0,T.createContext)(void 0);function D({children:e}){let[t,n]=(0,T.useState)(`home`),[r,i]=(0,T.useState)(),[a,o]=(0,T.useState)(),s=(0,T.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,E.jsx)(be.Provider,{value:s,children:e})}function O(){return(0,T.useContext)(be)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function xe(e){let{setRecordTitle:t}=O();(0,T.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}function k(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,T.useState)(`disconnected`),[l,u]=(0,T.useState)(null),[d,f]=(0,T.useState)([]),[p,m]=(0,T.useState)(null),h=(0,T.useRef)(null),g=(0,T.useRef)(0),_=(0,T.useRef)(null),v=(0,T.useRef)(new Map),y=(0,T.useRef)([]),b=(0,T.useRef)(!0),x=(0,T.useRef)(!1),S=(0,T.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),ee=(0,T.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,T.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]),w=(0,T.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),te=(0,T.useCallback)(()=>{S(),g.current=0,C()},[C,S]),ne=(0,T.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]),re=(0,T.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,T.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:ne,subscribe:re,disconnect:w,reconnect:te,error:p}}var A=0;function Se(){return A+=1,`conflict-${Date.now()}-${A}`}var j=0;function M(){return j+=1,`ver-${Date.now()}-${j}`}function N(e,t,n){let[r,i]=(0,T.useState)([]),[a,o]=(0,T.useState)([]);return{versions:r,currentVersion:(0,T.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,T.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:M(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,T.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:M(),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,T.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:M(),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,T.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:M(),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,T.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,T.useCallback)(e=>{let t={...e,id:Se()};o(e=>[...e,t])},[]),clearHistory:(0,T.useCallback)(()=>{i([]),o([])},[])}}var P={sm:24,md:32,lg:40},F={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Ce(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=P[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,T.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,T.useMemo)(()=>[...l].reverse(),[l]);return T.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&T.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>T.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?T.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Ce(e.userName),r&&T.createElement(`span`,{style:{...m,backgroundColor:F[e.status]}}))))}var Te=T.createContext({});function Ee(){let e=T.useContext(Te),[t,n]=T.useState([]);return T.useEffect(()=>{if(!e.subscribeTenant){n([]);return}return e.subscribeTenant(e=>{n(Array.isArray(e)?e:[])})},[e]),t}function De(e,t){let n=T.useContext(Te),[r,i]=T.useState([]);return T.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`]),I=[`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 I.some(e=>n===e||n.endsWith(`_${e}`))}function Re({dataSource:e,objects:t,onEdit:n,objectNameOverride:o,recordIdOverride:be,embedded:D}){let O=r(),k=O.appName,A=o??O.objectName,Se=be??O.recordId,{showDebug:j}=se(),{user:M}=c(),N=s(),P=i().state?.from,{t:F}=g(),{objectLabel:Ce,viewLabel:Te,sectionLabel:Ee,actionLabel:Oe,actionConfirm:Ae,actionSuccess:Me,actionParamText:I,actionParamOptionLabel:Ie,actionDescription:Re,fieldLabel:ze,fieldOptionLabel:Be}=ee(),{isFavorite:Ve,toggleFavorite:He,refreshLabel:Ue}=ne(),{addRecentItem:We}=te(),[Ge,Ke]=(0,T.useState)(!0),[qe,L]=(0,T.useState)([]),[R,Je]=(0,T.useState)([]),[Ye,z]=(0,T.useState)(0),[Xe,B]=(0,T.useState)(null),[Ze,Qe]=(0,T.useState)({}),[$e,et]=(0,T.useState)(null),[tt,nt]=(0,T.useState)(!1),[V,rt]=(0,T.useState)(),H=t.find(e=>e.name===A);xe(D?void 0:V);let U=Se,it=De(A,U),W=(0,T.useMemo)(()=>!A||!U?null:{id:`record:${A}:${U}`,label:V||U||``,href:`/apps/${k}/${A}/record/${U}`,type:`record`},[k,A,U,V]),at=W?Ve(W.id):!1,ot=(0,T.useCallback)(()=>{W&&He(W)},[W,He]),{page:st,slots:G}=v(A),ct=(0,T.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 H?.detail?.renderViaSchema!==!1},[H]),lt=(0,T.useMemo)(()=>st||!H||!ct&&!G?null:le(H,G?{slots:G}:void 0),[ct,st,G,H]),K=st||lt,[q,ut]=(0,T.useState)(null),[dt,J]=(0,T.useState)(`idle`);(0,T.useEffect)(()=>{let t=!1;if(!K||!U||!A||!e?.findOne){ut(null),J(`idle`);return}let n=_(H?.fields),r=n.length>0?{$expand:n}:void 0,i=()=>{J(`loading`),(r?e.findOne(A,U,r):e.findOne(A,U)).then(e=>{t||(e&&typeof e==`object`?(ut(e),J(`loaded`)):(ut(null),J(`missing`)))}).catch(()=>{t||(ut(null),J(`missing`))})};i();let a=e=>{let t=e.detail||{};t.objectName!==A||String(t.recordId)!==String(U)||i()};return window.addEventListener(`objectui:record-changed`,a),()=>{t=!0,window.removeEventListener(`objectui:record-changed`,a)}},[K,A,U,e,H]),(0,T.useEffect)(()=>{if(!q||typeof q!=`object`||!H)return;let e=oe(H,q);e&&e!==`Untitled`&&e!==V&&rt(e)},[q,H,V]),(0,T.useEffect)(()=>{if(!A||!U||!k||!V)return;let e=`record:${A}:${U}`;We({id:e,label:V,href:`/apps/${k}/${A}/record/${U}`,type:`record`}),Ue(e,V)},[k,A,U,V,We,Ue]);let[ft,pt]=(0,T.useState)({open:!1,message:``}),[mt,ht]=(0,T.useState)({open:!1,params:[]}),[gt,_t]=(0,T.useState)({open:!1}),vt=(0,T.useCallback)((e,t)=>new Promise(n=>{_t({open:!0,spec:e,data:t,resolve:n})}),[]),yt=(0,T.useCallback)((e,t)=>new Promise(n=>{pt({open:!0,message:e,options:t,resolve:n})}),[]),bt=(0,T.useCallback)((e,n)=>new Promise(r=>{let i=ye(e,{objectName:A||H?.name||``,objects:t||[],fieldLabel:ze,fieldOptionLabel:Be}),a=A||H?.name;ht({open:!0,params:i.map(e=>({...e,label:I(a,n?.name,e.name,`label`,e.label)??e.label,placeholder:I(a,n?.name,e.name,`placeholder`,e.placeholder)??e.placeholder,helpText:I(a,n?.name,e.name,`helpText`,e.helpText)??e.helpText,options:Array.isArray(e.options)?e.options.map(t=>({...t,label:Ie(a,n?.name,e.name,t.value,t.label)})):e.options})),title:n?.label||n?.title,description:Re(a,n?.name,n?.description),resolve:r})}),[A,H,t,ze,Be,I,Ie]),xt=u({dataSource:e,onUndo:()=>{z(e=>e+1),w.success(`Change undone`)}}),St=(0,T.useCallback)((e,t)=>{if(t?.type===`error`){w.error(e);return}if(t?.undo){w.success(e,{duration:t.duration,action:{label:t.undo.label||`Undo`,onClick:()=>{xt.undo()}}});return}w.success(e,{duration:t?.duration})},[xt]),Ct=(0,T.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):N(e)},[N]),wt=(0,T.useCallback)(async t=>{try{let n=t.target||t.name,r={...t.params||{}};delete r._rowRecord;let i;switch(n){case`opportunity_change_stage`:await e.update(A,U,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(A,U,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(A,U,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:if(Object.keys(r).length>0){if(t.undoable&&q&&A&&U){let e={};for(let t of Object.keys(r))e[t]=q[t]??null;i={id:`undo-${A}-${U}-${Date.now()}`,type:`update`,objectName:A,recordId:String(U),timestamp:Date.now(),description:t.label||`Undo ${A}`,undoData:e,redoData:{...r}}}await e.update(A,U,r)}break}let a=t.refreshAfter===!0;return(a||i)&&z(e=>e+1),{success:!0,reload:a,undo:i}}catch(e){return{success:!1,error:e.message}}},[e,A,U,q]),{modalHandler:Tt,modalElement:Et}=ie(e),Y=(0,T.useMemo)(()=>l(),[]),Dt=(0,T.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 Y(`/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:U,objectName:A,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 B({flowName:t,runId:i.runId,screen:i.screen}),{success:!0,silent:!0};let a=e.refreshAfter!==!1;return a&&z(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[Y,U,A]),Ot=(0,T.useRef)(new Set),kt=(0,T.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}:${U??``}`;if(Ot.current.has(r))return{success:!1,error:`Action already in progress`};Ot.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(U==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(U)))}`;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||w(`浏览器拦截了弹窗 / Popup blocked`,{description:`点击在新标签页打开环境`,action:{label:`打开环境`,onClick:()=>{try{window.open(t,`_blank`)}catch{window.location.href=t}}},duration:1e4})}return e.refreshAfter===!0&&z(e=>e+1),{success:!0}}let a=e.objectName||A||`global`,o=await Y(`/api/v1/actions/${encodeURIComponent(a)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:U,params:n})}),s=await o.json().catch(()=>null),c=s?.data,l=c&&typeof c==`object`&&c.success===!1;if(!o.ok||s&&s.success===!1||l){let e=l&&c.error||s?.error||`Action "${t}" failed (HTTP ${o.status})`;if(i)try{i.close()}catch{}return w.error(e),{success:!1,error:e}}let u=e.refreshAfter!==!1;u&&z(e=>e+1);let d=s?.data;if(d&&typeof d==`object`&&typeof d.redirectUrl==`string`){let e=d.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||w(`浏览器拦截了弹窗 / 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:d,reload:u}}catch(e){if(i)try{i.close()}catch{}let t=e.message;return w.error(t),{success:!1,error:t}}finally{Ot.current.delete(r)}},[Y,U,A]),X=re(A,U,M?.id),At=(0,T.useRef)(X);At.current=X;let jt=(0,T.useCallback)(async e=>{let t=e.target||e.name,n=e.params&&!Array.isArray(e.params)?e.params:{};try{if(t===`approve_request`)await At.current.approve({comment:n.comment});else if(t===`reject_request`)await At.current.reject({comment:n.comment});else return{success:!1,error:`Unknown approval target: ${t}`};return z(e=>e+1),{success:!0,reload:!0}}catch(e){return{success:!1,error:e?.message||String(e)}}},[]),Mt=(0,T.useMemo)(()=>ae(H,t),[H,t]);(0,T.useEffect)(()=>{if(K||!e||!U||Mt.length===0)return;let t=!1;return Promise.all(Mt.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:U}}).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;Qe(n)}),()=>{t=!0}},[e,U,Mt,H,K]);let Z=(0,T.useMemo)(()=>!H||H.name===`sys_audit_log`||H.enable?.trackHistory!==!0?!1:t.some(e=>e.name===`sys_audit_log`),[H,t]);(0,T.useEffect)(()=>{if(!e||!U||!H||!Z){et(null);return}let t=!1;return nt(!0),e.find(`sys_audit_log`,{$filter:{record_id:U,object_name:H.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(H.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};et(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),et([]))}).finally(()=>{t||nt(!1)}),()=>{t=!0}},[e,U,H,Z]),(0,T.useEffect)(()=>{if(!e)return;let t=!1,n=M?[{id:String(M.id),label:M.name||M.email||String(M.id),avatarUrl:M.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))];Je(o.length>0?o:n)}catch{if(t)return;Je(n)}})(),()=>{t=!0}},[e,M?.id,M?.name,M?.email]);let Q=(0,T.useMemo)(()=>M?{id:M.id,name:M.name,avatar:M.image}:Ne,[M?.id,M?.name,M?.image]);(0,T.useEffect)(()=>{if(!e||!A||!U)return;let t=`${A}:${U}`,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)}));L(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:A,record_id:U},$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,sourceObject:n.source_object??void 0,sourceId:n.source_id??void 0})}t.length&&L(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,A,U,Q]);let Nt=(0,T.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(L(e=>[...e,n]),e){let r=`${A}:${U}`,i=de(t,R);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,A,U,R]),Pt=(0,T.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(L(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let i=`${A}:${U}`,a=de(n,R);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,A,U,R]),Ft=(0,T.useCallback)((t,n)=>{L(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,T.useEffect)(()=>{Ke(!0),queueMicrotask(()=>Ke(!1))},[A,Se]);let $=(0,T.useMemo)(()=>{if(!H)return{type:`detail-view`};let n=H.primaryField||Object.keys(H.fields||{}).find(e=>e===`name`||e===`title`),r=H.views?.form?.sections,i=r&&r.length>0?r.map(e=>({title:e.name?Ee(H.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!H.fields?.[t]?.hidden}).map(e=>{let t=typeof e==`string`?e:e.name,n=H.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${H.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(H.fields||{}).filter(e=>!Pe.has(e)&&!Fe.has(e)&&!H.fields[e]?.hidden),t=e=>{let t=H.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,H.fields[e])),r=e.filter(e=>Le(e,H.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(H.name,`details`,F(`detail.sectionMoreDetails`,`More details`)),collapsible:!0,defaultCollapsed:!1,showBorder:!0,fields:r.map(t)}]})(),a=(()=>{let e=new Set,t=(H.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(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:Ae(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:Me(H.name,e.name,e.successMessage)}}));if(X.available&&X.canDecide){let e={name:`comment`,label:F(`approvals.comment`,{defaultValue:`Comment (optional)`}),type:`text`,multiline:!0};t.push({name:`approve_request`,type:`approval`,target:`approve_request`,label:F(`approvals.approve`,{defaultValue:`Approve`}),icon:`check`,variant:`default`,locations:[`record_header`],refreshAfter:!0,collectParams:[e],successMessage:F(`approvals.approveSuccess`,{defaultValue:`Approved`})}),t.push({name:`reject_request`,type:`approval`,target:`reject_request`,label:F(`approvals.reject`,{defaultValue:`Reject`}),icon:`x`,variant:`destructive`,locations:[`record_header`],refreshAfter:!0,confirmText:F(`approvals.rejectConfirm`,{defaultValue:`Reject this approval request?`}),collectParams:[e],successMessage:F(`approvals.rejectSuccess`,{defaultValue:`Rejected`})})}return t})(),o=H.views?.detail?.highlightFields??[],s=H.views?.detail?.sectionGroups??H.views?.form?.sectionGroups,c=k?`/apps/${k}`:``,l=Mt.map(({childObject:n,childLabel:r,referenceField:i,title:a,columns:o})=>{let s=t.find(e=>e.name===n),l=U||``,u=a||(s?Ce({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?()=>N(d()):void 0,g=c?()=>N(f()):void 0,_=c?e=>{let t=m(e);t&&N(t)}:void 0,v=c?e=>{let t=p(e);t&&N(t)}:void 0,y=e&&l?async t=>{let r=t?.id||t?._id;if(r)try{await e.delete(n,r),w.success(F(`detail.deleteSuccess`,{defaultValue:`Deleted`})),Qe(e=>({...e,[n]:(e[n]||[]).filter(e=>(e.id||e._id)!==r)}))}catch(e){w.error(e?.message||F(`detail.deleteError`,{defaultValue:`Delete failed`}))}}:void 0;return{title:u,type:`table`,api:n,data:Ze[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(H);return{type:`detail-view`,objectName:H.name,resourceId:U,showBack:!D,onBack:`history`,showEdit:u.edit,title:H.label,primaryField:n,sections:i,autoTabs:!0,autoDiscoverRelated:!0,...Z&&{history:{entries:$e??[],loading:tt&&$e===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}]}}},[H?.name,U,Ze,Ye,k,N,e,F,Ce,t,Z,$e,tt,X.available,X.canDecide,X.pendingRequest,X.latestRequest,D]);if(Ge)return(0,E.jsx)(me,{});if(!H)return(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,E.jsxs)(x,{children:[(0,E.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,E.jsx)(S,{className:`h-6 w-6 text-muted-foreground`})}),(0,E.jsx)(b,{children:F(`empty.objectNotFound`)}),(0,E.jsx)(C,{children:F(`empty.objectNotFoundDescription`,{name:A})})]})});if(K&&dt===`missing`)return(0,E.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,E.jsxs)(x,{children:[(0,E.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,E.jsx)(S,{className:`h-6 w-6 text-muted-foreground`})}),(0,E.jsx)(b,{children:F(`empty.recordNotFound`,{defaultValue:`Record not found`})}),(0,E.jsx)(C,{children:F(`empty.recordNotFoundDescription`,{defaultValue:`The record you are looking for does not exist or may have been deleted.`})})]})});if(K){let r=K?.disableDiscussion===!0,i=je(K),o=!r&&!i,s=(()=>{let e=$.actions;if(!Array.isArray(e))return[];let t=e.find(e=>Array.isArray(e?.actions))?.actions??e;return Array.isArray(t)?t:[]})(),c=(()=>{let t=ke(H),r=[];return t.edit&&(r.push({name:`sys_inline_edit`,label:F(`detail.editFieldsInline`,{defaultValue:`Edit fields`}),type:`script`,locations:[`record_header`],variant:`outline`,onClick:()=>{window.dispatchEvent(new CustomEvent(`objectui:record:inline-edit-toggle`,{detail:{recordId:U,objectName:A}}))}}),r.push({name:`sys_edit`,label:F(`detail.edit`,{defaultValue:`Edit`}),type:`script`,locations:[`record_header`],variant:`default`,onClick:()=>n({id:U})})),r.push({name:`sys_share`,label:F(`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),w.success(F(`detail.linkCopied`,{defaultValue:`Link copied`}))}catch(e){w.error(F(`detail.linkCopyFailed`,{defaultValue:`Failed to copy link`})+(e?.message?`: ${e.message}`:``))}}}),t.delete&&r.push({name:`sys_delete`,label:F(`detail.delete`,{defaultValue:`Delete`}),type:`script`,locations:[`record_header`],variant:`destructive`,onClick:async()=>{let t=F(`detail.deleteConfirmation`,{defaultValue:`Are you sure you want to delete this record?`});if(window.confirm(t))try{await e.delete(A,U),w.success(F(`detail.deleted`,{defaultValue:`Record deleted`})),N(`${k?`/apps/${k}`:``}/${A}`,{replace:!0})}catch(e){w.error(e?.message||`Delete failed`)}}}),r})(),l=s.length>0?s:void 0,u=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,g=$.history?{entries:$.history.entries??[],loading:!!$.history.loading,emptyText:$.history.emptyText}:void 0,_=st?K:le(H,{sections:$.sections,highlightFields:Array.isArray($.highlightFields)?$.highlightFields.map(e=>typeof e==`string`?e:e?.name).filter(e=>!!e):void 0,headerActions:l,related:u,history:g,showReferenceRail:H?.detail?.showReferenceRail===!0||void 0,hideReferenceRail:H?.detail?.hideReferenceRail===!0||void 0,hideRelatedTab:H?.detail?.hideRelatedTab===!0||void 0,...G?{slots:G}:{}});return(0,E.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,E.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[it.length>0&&(0,E.jsx)(we,{users:it,size:`sm`,maxVisible:3,showStatus:!0}),(0,E.jsx)(pe,{managedBy:H?.managedBy})]}),(0,E.jsx)(m,{objectName:A,recordId:U,data:q,objectSchema:H,dataSource:e,embedded:D,headerSystemActions:c,isFavorite:at,onToggleFavorite:W?ot:void 0,children:(0,E.jsx)(h,{children:(0,E.jsx)(p,{items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft,mentionSuggestions:R,children:(0,E.jsxs)(f,{context:{record:q||{},objectName:A,user:Q},onConfirm:yt,onToast:St,onNavigate:Ct,onParamCollection:bt,onResultDialog:vt,onModal:Tt,handlers:{api:wt,flow:Dt,script:kt,approval:jt},children:[(0,E.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,E.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:[P?.pathname&&P?.label&&(0,E.jsxs)(a,{to:P.pathname,className:`inline-flex items-center gap-1 mb-3 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(y,{className:`h-4 w-4`}),(0,E.jsx)(`span`,{children:P.label})]}),(0,E.jsx)(d,{schema:_}),o&&(0,E.jsx)(`div`,{className:`mt-6`,children:(0,E.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft,mentionSuggestions:R})})]}),(0,E.jsx)(ce,{open:j,sections:[{title:`Page Schema`,data:_}]})]}),Et]})})})}),(0,E.jsx)(he,{state:ft,onOpenChange:e=>{e||pt(e=>({...e,open:!1}))}}),(0,E.jsx)(ge,{state:mt,onOpenChange:e=>{e||ht(e=>({...e,open:!1}))}}),(0,E.jsx)(ve,{state:gt,onAcknowledge:()=>{gt.resolve?.(),_t({open:!1})}}),(0,E.jsx)(_e,{state:Xe,authFetch:Y,baseUrl:``,dataSource:e,objects:t,onClose:()=>B(null),onComplete:()=>{B(null),z(e=>e+1)}})]})}return(0,E.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,E.jsxs)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:[it.length>0&&(0,E.jsx)(we,{users:it,size:`sm`,maxVisible:3,showStatus:!0}),(0,E.jsx)(pe,{managedBy:H?.managedBy})]}),(0,E.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,E.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,E.jsxs)(f,{context:{record:{},objectName:A,user:Q},onConfirm:yt,onToast:St,onNavigate:Ct,onParamCollection:bt,onResultDialog:vt,onModal:Tt,handlers:{api:wt,flow:Dt,script:kt,approval:jt},children:[(0,E.jsx)(fe,{schema:$,dataSource:e,objectLabel:Ce({name:H.name,label:H.label}),isFavorite:at,onToggleFavorite:W?ot:void 0,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=oe(H,e);t&&t!==V&&t!==`Untitled`&&rt(t)},onEdit:()=>{n({id:U})},discussionSlot:(0,E.jsx)(ue,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:qe,onAddComment:Nt,onAddReply:Pt,onToggleReaction:Ft})},Ye),Et]})}),(0,E.jsx)(ce,{open:j,sections:[{title:`View Schema`,data:$}]})]}),(0,E.jsx)(he,{state:ft,onOpenChange:e=>{e||pt(e=>({...e,open:!1}))}}),(0,E.jsx)(ge,{state:mt,onOpenChange:e=>{e||ht(e=>({...e,open:!1}))}}),(0,E.jsx)(ve,{state:gt,onAcknowledge:()=>{gt.resolve?.(),_t({open:!1})}}),(0,E.jsx)(_e,{state:Xe,authFetch:Y,baseUrl:``,dataSource:e,objects:t,onClose:()=>B(null),onComplete:()=>{B(null),z(e=>e+1)}})]})}export{we as a,D as c,Ee as i,O as l,Me as n,N as o,ke as r,k as s,Re as t};
|
|
@@ -1 +1 @@
|
|
|
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-CJNwTVno.js";import{T as l,ct as u,r as d,w as f}from"./framework-BLEk-ou3.js";import{H as p,R as m,Wo as h,gc as g,hr as _,sc as v,z as y}from"./ui-components-
|
|
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-CJNwTVno.js";import{T as l,ct as u,r as d,w as f}from"./framework-BLEk-ou3.js";import{H as p,R as m,Wo as h,gc as g,hr as _,sc as v,z as y}from"./ui-components-NS_7__gn.js";import{r as b}from"./vendor-ui-utils-rQOI1gAo.js";import"./AdapterProvider-DJb3ZVmJ.js";import{t as x}from"./plugin-form-Dzz6GAZM.js";import"./MetadataProvider-Dh20h6BN.js";import{n as S,t as C}from"./ExpressionProvider-DKFCgLsJ.js";import{t as w}from"./ManagedByBadge-Bmg77Q4v.js";import{t as T}from"./skeletons-BK7w4pLE.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}=d(),{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 u({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]);if(M)return(0,O.jsx)(T,{});if(!B)return(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`)]})})]})});let Q=B.form??B.formViews?.default??{},$=[`tabbed`,`wizard`,`split`].includes(Q.type)?Q.type:`simple`,ee=$!==`simple`&&Array.isArray(Q.sections)?{sections:Q.sections,defaultTab:Q.defaultTab,tabPosition:Q.tabPosition,allowSkip:Q.allowSkip,showStepIndicator:Q.showStepIndicator,splitDirection:Q.splitDirection,splitSize:Q.splitSize,splitResizable:Q.splitResizable}:{};return(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:$,...ee,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`}`)})})]})})}export{E as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{R as r,f as i,h as a}from"./vendor-objectstack-BNd856rx.js";import{$n as o,$t as s,Bs as c,Co as l,Da as u,Ea as d,Fa as f,Gs as p,Ho as m,Ia as h,Is as g,Ji as _,Kr as v,Lr as y,Mo as b,Ni as x,Or as ee,Pa as te,Qi as ne,Qo as S,Rs as C,Si as w,Sr as re,Ui as ie,Ur as ae,Xa as oe,Yi as se,Yr as ce,Zi as le,ca as ue,di as de,ec as fe,en as pe,fa as me,hs as he,io as ge,ja as _e,li as ve,ls as ye,ni as be,on as xe,oo as Se,pa as Ce,pi as T,rs as E,si as D,tc as O,tn as k,to as A,wr as we,zi as Te}from"./ui-components-NS_7__gn.js";import{C as j,_ as Ee,a as De,g as M,h as Oe,i as N,m as P,n as ke,r as Ae,t as je,v as F,y as Me}from"./mergeServerFields-CMIOI8QD.js";var I=e(t(),1),L=(e,t,n,r,i)=>({id:e,label:t,labelZh:n,category:r,Icon:i}),R={text:L(`text`,`Text`,`单行文本`,`text`,y),textarea:L(`textarea`,`Text Area`,`多行文本`,`text`,v),email:L(`email`,`Email`,`邮箱`,`text`,fe),url:L(`url`,`URL`,`网址`,`text`,Se),phone:L(`phone`,`Phone`,`电话`,`text`,_),password:L(`password`,`Password`,`密码`,`text`,_e),markdown:L(`markdown`,`Markdown`,`Markdown`,`text`,l),html:L(`html`,`HTML`,`HTML`,`text`,S),richtext:L(`richtext`,`Rich Text`,`富文本`,`text`,ve),number:L(`number`,`Number`,`数字`,`number`,A),currency:L(`currency`,`Currency`,`货币`,`number`,m),percent:L(`percent`,`Percent`,`百分比`,`number`,se),date:L(`date`,`Date`,`日期`,`date`,C),datetime:L(`datetime`,`Date/Time`,`日期时间`,`date`,C),time:L(`time`,`Time`,`时间`,`date`,E),boolean:L(`boolean`,`Checkbox`,`复选框`,`logic`,D),toggle:L(`toggle`,`Toggle`,`开关`,`logic`,ae),select:L(`select`,`Picklist`,`下拉选择`,`selection`,te),multiselect:L(`multiselect`,`Multi-Select`,`多选`,`selection`,f),radio:L(`radio`,`Radio`,`单选`,`selection`,he),checkboxes:L(`checkboxes`,`Checkboxes`,`复选组`,`selection`,f),lookup:L(`lookup`,`Lookup`,`查找关系`,`relation`,h),master_detail:L(`master_detail`,`Master-Detail`,`主从关系`,`relation`,we),tree:L(`tree`,`Tree`,`树形关系`,`relation`,me),image:L(`image`,`Image`,`图片`,`media`,oe),file:L(`file`,`File`,`文件`,`media`,ne),avatar:L(`avatar`,`Avatar`,`头像`,`media`,ye),video:L(`video`,`Video`,`视频`,`media`,ee),audio:L(`audio`,`Audio`,`音频`,`media`,Ce),formula:L(`formula`,`Formula`,`公式`,`calculated`,c),summary:L(`summary`,`Rollup`,`汇总`,`calculated`,T),autonumber:L(`autonumber`,`Auto Number`,`自动编号`,`calculated`,A),composite:L(`composite`,`Composite`,`复合字段`,`advanced`,p),repeater:L(`repeater`,`Repeater`,`重复字段`,`advanced`,x),location:L(`location`,`Location`,`地理坐标`,`advanced`,u),address:L(`address`,`Address`,`地址`,`advanced`,d),code:L(`code`,`Code`,`代码`,`advanced`,S),json:L(`json`,`JSON`,`JSON`,`advanced`,b),color:L(`color`,`Color`,`颜色`,`advanced`,ue),rating:L(`rating`,`Rating`,`评分`,`advanced`,be),slider:L(`slider`,`Slider`,`滑块`,`advanced`,de),signature:L(`signature`,`Signature`,`签名`,`advanced`,le),qrcode:L(`qrcode`,`QR Code`,`二维码`,`advanced`,Te),progress:L(`progress`,`Progress`,`进度条`,`advanced`,g),tags:L(`tags`,`Tags`,`标签`,`advanced`,ce),vector:L(`vector`,`Vector`,`向量`,`advanced`,O)},Ne=[`text`,`number`,`date`,`logic`,`selection`,`relation`,`media`,`calculated`,`advanced`],Pe={text:`Text`,number:`Number`,date:`Date & Time`,logic:`Logic`,selection:`Selection`,relation:`Relation`,media:`Media`,calculated:`Calculated`,advanced:`Advanced`},z={text:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-600 dark:border-slate-700/50 dark:bg-slate-800/40 dark:text-slate-300`},number:{icon:`text-blue-600 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-800/50 dark:bg-blue-950/40 dark:text-blue-300`},date:{icon:`text-violet-600 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-800/50 dark:bg-violet-950/40 dark:text-violet-300`},logic:{icon:`text-amber-600 dark:text-amber-400`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800/50 dark:bg-amber-950/40 dark:text-amber-300`},selection:{icon:`text-teal-600 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-800/50 dark:bg-teal-950/40 dark:text-teal-300`},relation:{icon:`text-indigo-600 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-800/50 dark:bg-indigo-950/40 dark:text-indigo-300`},media:{icon:`text-pink-600 dark:text-pink-400`,badge:`border-pink-200 bg-pink-50 text-pink-700 dark:border-pink-800/50 dark:bg-pink-950/40 dark:text-pink-300`},calculated:{icon:`text-emerald-600 dark:text-emerald-400`,badge:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-800/50 dark:bg-emerald-950/40 dark:text-emerald-300`},advanced:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-700/50 dark:bg-zinc-800/40 dark:text-zinc-300`}};function Fe(e){return z[B(e).category]}var Ie={text:`文本`,number:`数值`,date:`日期/时间`,logic:`逻辑`,selection:`选择`,relation:`关系`,media:`媒体`,calculated:`计算`,advanced:`高级`},Le=Ne.map(e=>({category:e,types:Object.keys(R).filter(t=>R[t].category===e)}));function B(e){return typeof e==`string`&&e in R?R[e]:{id:`text`,label:typeof e==`string`?e:`unknown`,labelZh:typeof e==`string`?e:`未知`,category:`advanced`,Icon:y}}var V=n(),H=`text/x-objectui-viewcol`;function U({type:e}){let t=B(e),n=Fe(e),r=t.Icon;return(0,V.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 ${n.icon}`})}function W({index:e,label:t,fieldName:n,fieldType:r,selected:i,canEdit:a,dragging:o,dropBefore:s,onSelect:c,onRemove:l,onDragStart:u,onDragEnd:d,onDragOverRow:f,onDropRow:p}){return(0,V.jsxs)(`div`,{className:`relative`,children:[s&&(0,V.jsx)(`span`,{className:`pointer-events-none absolute -top-0.5 left-0 right-0 h-0.5 rounded bg-primary`}),(0,V.jsxs)(`div`,{role:`button`,tabIndex:0,draggable:a,"aria-pressed":i,onDragStart:t=>{a&&(t.dataTransfer.effectAllowed=`move`,t.dataTransfer.setData(H,String(e)),u())},onDragEnd:d,onDragOver:e=>{!a||!o||e.dataTransfer.types.includes(H)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,f())},onDrop:e=>{a&&e.dataTransfer.types.includes(H)&&(e.preventDefault(),e.stopPropagation(),p())},onClick:c,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),c())},className:`group flex items-center gap-2 rounded-md border bg-card px-2 py-1.5 text-xs transition-colors hover:border-primary/40 `+(i?`border-primary ring-1 ring-primary `:`border-border `)+(a?`cursor-grab active:cursor-grabbing`:``),children:[a&&(0,V.jsx)(ge,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/40 group-hover:text-muted-foreground`}),(0,V.jsx)(U,{type:r}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:t}),n&&n!==t&&(0,V.jsx)(`code`,{className:`max-w-[7rem] shrink-0 truncate text-[10px] text-muted-foreground`,children:n}),a&&(0,V.jsx)(`span`,{role:`button`,tabIndex:0,"aria-label":`Remove ${t}`,onClick:e=>{e.stopPropagation(),l()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),l())},className:`inline-flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/60 hover:bg-destructive/10 hover:text-destructive`,children:(0,V.jsx)(re,{className:`h-3 w-3`})})]})]})}function G({fields:e,usedNames:t,loading:n,error:r,onAdd:i}){let a=I.useMemo(()=>Ae(),[]),[c,l]=I.useState(!1),[u,d]=I.useState(``),f=I.useMemo(()=>{let t=u.trim().toLowerCase();return t?e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t)):e},[e,u]);return(0,V.jsxs)(s,{open:c,onOpenChange:l,children:[(0,V.jsx)(k,{asChild:!0,children:(0,V.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-md border border-dashed px-2 py-1 text-xs text-muted-foreground hover:border-primary/40 hover:bg-accent/40 hover:text-foreground`,children:[(0,V.jsx)(ie,{className:`h-3.5 w-3.5`}),` `,N(`engine.form.addFieldPlain`,a)]})}),(0,V.jsxs)(pe,{align:`start`,className:`w-72 p-0`,children:[(0,V.jsxs)(`div`,{className:`relative border-b p-2`,children:[(0,V.jsx)(w,{className:`pointer-events-none absolute left-4 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,V.jsx)(`input`,{autoFocus:!0,value:u,onChange:e=>d(e.target.value),placeholder:N(`engine.form.searchFields`,a),className:`h-8 w-full rounded border border-input bg-background pl-7 pr-2 text-xs outline-none focus:border-primary`})]}),(0,V.jsx)(`div`,{className:`max-h-72 overflow-auto p-1`,children:n?(0,V.jsx)(K,{children:N(`engine.form.loadingFields`,a)}):r?(0,V.jsx)(K,{tone:`warn`,children:De(`engine.form.noObjectFields`,a,{error:r})}):f.length===0?(0,V.jsx)(K,{children:N(u?`engine.form.noMatchingFields`:`engine.form.noFieldsOnObject`,a)}):f.map(e=>{let n=t.has(e.name);return(0,V.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent`,children:[(0,V.jsx)(U,{type:e.type}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label}),e.name!==e.label&&(0,V.jsx)(`code`,{className:`max-w-[6rem] truncate text-[10px] text-muted-foreground`,children:e.name}),n&&(0,V.jsx)(o,{variant:`secondary`,className:`px-1 py-0 text-[9px]`,children:N(`engine.form.added`,a)})]},e.name)})})]})]})}function K({children:e,tone:t}){return(0,V.jsx)(`div`,{className:`px-2 py-4 text-center text-[11px] `+(t===`warn`?`text-amber-600 dark:text-amber-300`:`text-muted-foreground`),children:e})}function Re(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function q(e){let t=typeof e.name==`string`?e.name:``;if(!t)return null;let n=Array.isArray(e.dimensions)?e.dimensions.filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({name:e.name,type:typeof e.type==`string`?e.type:void 0})):[],r=Array.isArray(e.measures)?e.measures.filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({name:e.name,aggregate:typeof e.aggregate==`string`?e.aggregate:void 0,certified:e.certified===!0})):[];return{name:t,label:Re(e.label,t),dimensions:n,measures:r}}function ze(e){let t=j(),[n,r]=I.useState({datasets:e??[],loading:!e,error:null});return I.useEffect(()=>{if(e){r({datasets:e,loading:!1,error:null});return}let n=!1;return r(e=>({...e,loading:!0,error:null})),t.list(`dataset`).then(e=>{n||r({datasets:(Array.isArray(e)?e:[]).map(q).filter(e=>e!==null),loading:!1,error:null})}).catch(e=>{n||r({datasets:[],loading:!1,error:e?.message??String(e)})}),()=>{n=!0}},[t,e]),n}function Be(e,t){let n=j(),r=e?t.datasets.find(t=>t.name===e):void 0,i=!!e&&!t.loading&&(!r||r.dimensions.length===0&&r.measures.length===0),[a,o]=I.useState(null);I.useEffect(()=>{if(!i||!e||a?.name===e)return;let t=!1;return n.get(`dataset`,e).then(n=>{t||o({name:e,entry:n?q(n):null,error:n?null:`Dataset not found`})}).catch(n=>{t||o({name:e,entry:null,error:n?.message??String(n)})}),()=>{t=!0}},[n,e,i,a]);let s=i&&a?.name===e?a.entry:r;return{dimensions:s?.dimensions??[],measures:s?.measures??[],loading:t.loading||i&&a?.name!==e,error:(i&&a?.name===e?a.error:null)??t.error}}var Ve={io:`input`,unrepresentable:`any`},He=new Set([`dataset`,`values`,`rows`,`columns`,`name`]),J,Y=!1;function X(){if(J||Y)return J;try{J=r(i,Ve)}catch(e){Y=!0,typeof console<`u`&&console.warn(`[report-schema] failed to derive Report JSONSchema from spec`,e)}return J}var Z;function Ue(){if(Z)return Z;if(!(!a||typeof a!=`object`)){try{let e=JSON.parse(JSON.stringify(a)),t=X()?.properties;for(let n of e.sections??[])n.fields=(n.fields??[]).filter(e=>{let n=typeof e==`string`?e:e?.field;return!(He.has(n)||t&&!(n in t))});if(t&&`runtimeFilter`in t){let t=new Set;for(let n of e.sections??[])for(let e of n.fields??[])t.add(typeof e==`string`?e:e?.field);t.has(`runtimeFilter`)||(e.sections=[...e.sections??[],{label:`Filter`,description:`Render-time scope filter, ANDed at query time.`,collapsible:!0,collapsed:!0,fields:[{field:`runtimeFilter`,widget:`json`}]}])}e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Z=e}catch(e){typeof console<`u`&&console.warn(`[report-schema] failed to prepare reportForm from spec`,e);return}return Z}}var We=new Set([`type`,`label`,`name`,`dataset`,`values`,`rows`,`columns`]),Ge={tabular:`engine.inspector.report.type.tabular`,summary:`engine.inspector.report.type.summary`,matrix:`engine.inspector.report.type.matrix`,joined:`engine.inspector.report.type.joined`};function Ke(e,t){return I.useMemo(()=>{let n=X()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`tabular`,`summary`,`matrix`,`joined`]).map(e=>{let n=Ge[e],r=n?N(n,t):e;return{value:e,label:r===n?e:r}});return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:e}),r},[e,t])}function Q(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function $({label:e,emptyText:t,names:n,options:r,loading:i,error:a,readOnly:s,onCommit:c}){let[l,u]=I.useState(null),[d,f]=I.useState(null),p=I.useMemo(()=>new Set(n),[n]),m=I.useMemo(()=>{let e=new Map;for(let t of r)e.set(t.name,t.type);return e},[r]);return(0,V.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(xe,{className:`text-xs text-muted-foreground`,children:e}),(0,V.jsx)(o,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,V.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:t}):(0,V.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,V.jsx)(W,{index:t,label:e,fieldName:e,fieldType:m.get(e)??`number`,selected:!1,canEdit:!s,dragging:l!==null,dropBefore:d===t&&l!==null&&l!==t,onSelect:()=>{},onRemove:()=>c(Me(n,t,null)),onDragStart:()=>u(t),onDragEnd:()=>{u(null),f(null)},onDragOverRow:()=>f(t),onDropRow:()=>{l!=null&&l!==t&&c(F(n,l,t)),u(null),f(null)}},`${e}-${t}`))}),!s&&(0,V.jsx)(G,{fields:r,usedNames:p,loading:i,error:a,onAdd:e=>c(Ee(n,e.name))})]})}function qe({draft:e,onPatch:t,readOnly:n,locale:r,datasetCatalogOverride:i,serverSchema:a}){let o=I.useCallback(e=>N(e,r),[r]),s=typeof e.type==`string`?e.type:`tabular`,c=Ke(s,r),l=typeof e.label==`string`?e.label:``,u=typeof e.dataset==`string`?e.dataset:``,d=I.useMemo(()=>Q(e.values),[e.values]),f=I.useMemo(()=>Q(e.rows),[e.rows]),p=I.useMemo(()=>Q(e.columns),[e.columns]),m=ze(i),h=Be(u||void 0,m),g=I.useMemo(()=>{let e=m.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return u&&!e.some(e=>e.value===u)&&e.push({value:u,label:u}),e},[m.datasets,u]),_=I.useMemo(()=>h.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[h.measures]),v=I.useMemo(()=>h.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[h.dimensions]),y=s!==`joined`,{schema:b,form:x}=I.useMemo(()=>je({bundledSchema:X(),bundledForm:Ue(),serverSchema:a,excludeFields:We,sectionTitle:N(`engine.inspector.moreFields`,r)}),[a,r]);return(0,V.jsxs)(Oe,{kindLabel:o(`engine.inspector.report.kind`),title:String(l||e.name||o(`engine.inspector.report.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.report.close`),hideClose:!0,children:[(0,V.jsx)(M,{label:o(`engine.inspector.report.label`),value:l,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.report.labelPlaceholder`),disabled:n}),(0,V.jsx)(P,{label:o(`engine.inspector.report.type`),value:s,options:c,onCommit:e=>t({type:e}),disabled:n}),y&&(0,V.jsxs)(V.Fragment,{children:[m.datasets.length>0||u?(0,V.jsx)(P,{label:o(`engine.inspector.report.dataset`),value:u,options:g,onCommit:e=>t({dataset:e}),disabled:n}):(0,V.jsx)(M,{label:o(`engine.inspector.report.dataset`),value:u,onCommit:e=>t({dataset:e}),placeholder:o(`engine.inspector.report.datasetPlaceholder`),disabled:n,mono:!0}),(0,V.jsx)($,{label:o(`engine.inspector.report.values`),emptyText:o(`engine.inspector.report.valuesEmpty`),names:d,options:_,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({values:e})}),(0,V.jsx)($,{label:o(`engine.inspector.report.rows`),emptyText:o(`engine.inspector.report.rowsEmpty`),names:f,options:v,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({rows:e})}),s===`matrix`&&(0,V.jsx)($,{label:o(`engine.inspector.report.columnsAcross`),emptyText:o(`engine.inspector.report.columnsAcrossEmpty`),names:p,options:v,loading:h.loading,error:h.error,readOnly:n,onCommit:e=>t({columns:e})})]}),(0,V.jsx)(`div`,{className:`border-t pt-3`,children:b?(0,V.jsx)(ke,{schema:b,form:x,value:e,hiddenFields:[`type`,`label`,`name`,`dataset`,`values`,`rows`,`columns`],readOnly:n,onChange:e=>t(e)}):(0,V.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.report.noSchema`)})})]})}export{Ie as a,Le as c,Pe as i,G as n,z as o,W as r,R as s,qe as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,m as i,t as a,u as o}from"./vendor-react-DR370ovB.js";import{f as s}from"./infrastructure-CJNwTVno.js";import{T as c,r as l,w as u}from"./framework-BLEk-ou3.js";import{Fs as d,H as f,Ma as p,R as m,Sr as h,Xi as g,hr as _,z as v}from"./ui-components-CrPYFyEM.js";import"./AdapterProvider-DJb3ZVmJ.js";import"./MetadataProvider-CEw2X-qL.js";import{r as y}from"./ExpressionProvider-DKFCgLsJ.js";import{C as b,r as x}from"./mergeServerFields-djmY7AgR.js";import{n as S,r as C,t as w}from"./MetadataInspector-BRICMLXW.js";import{t as T}from"./ReportDefaultInspector-GD1EQSTh.js";import{r as E,t as D}from"./RuntimeDraftBar-DXwH4Hvd.js";var O=e(n(),1),k=a();function A({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,name:a,metadataClient:o,onAfterChange:s}){let{t:c}=l(),u=(0,O.useMemo)(()=>x(),[]),[d,f]=(0,O.useState)(!1),p=(0,O.useMemo)(()=>({...n??{}}),[n]),[m,g]=(0,O.useState)(p),v=(0,O.useRef)(m),y=(0,O.useRef)(p);y.current!==p&&(y.current=p,v.current=p,g(p),f(!1));let b=(0,O.useCallback)(e=>{let t={...v.current,...e};if(v.current=t,g(t),f(!0),i)for(let[n,r]of Object.entries(e))i(n,r,t)},[i]),S=(0,O.useCallback)(()=>{r(v.current),f(!1),t()},[r,t]),C=(0,O.useCallback)(e=>{let t={...e};v.current=t,g(t),f(!1)},[]),w=(0,O.useCallback)(()=>{t()},[t]);return e?(0,k.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`report-config-panel`,role:`complementary`,"aria-label":c(`report.editor.title`,{defaultValue:`Edit report`}),children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium truncate`,children:c(`report.editor.title`,{defaultValue:`Edit report`})}),(0,k.jsx)(_,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":c(`common.close`,{defaultValue:`Close`}),"data-testid":`report-config-close`,children:(0,k.jsx)(h,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,k.jsx)(T,{type:`report`,name:typeof m.name==`string`?m.name:``,draft:m,readOnly:!1,locale:u,onPatch:b})}),(0,k.jsxs)(`div`,{"data-testid":`report-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,k.jsx)(D,{type:`report`,name:a,metadataClient:o,dirty:d,onResume:C,onAfterChange:s}),(0,k.jsx)(_,{variant:`ghost`,size:`sm`,onClick:w,"data-testid":`report-config-discard`,children:c(`common.cancel`,{defaultValue:`Cancel`})}),(0,k.jsx)(_,{size:`sm`,onClick:S,"data-testid":`report-config-save`,children:c(`common.save`,{defaultValue:`Save`})})]})]}):null}var j=t({ReportView:()=>P}),M=(0,O.lazy)(()=>i(()=>import(`./plugin-report-FxG9jOvy.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),N=(0,O.lazy)(()=>i(()=>import(`./plugin-report-FxG9jOvy.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),ee=[{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 P({dataSource:e}){let{t}=l(),{appName:n,reportName:i}=r(),a=o(),{showDebug:h}=S();u();let _=b(),{user:x}=s(),T=x?.role===`admin`,[D,j]=(0,O.useState)(!1),[P,F]=(0,O.useState)(0),{reports:I,objects:L,loading:R,refresh:z}=c(),{app:B}=y(),V=C(I,i,B?._packageId),[H,U]=(0,O.useState)(V),[W,G]=(0,O.useState)(null),[K,q]=(0,O.useState)([]),[J,Y]=(0,O.useState)(!1),X=(0,O.useCallback)(e=>{if(!e||!L?.length)return;let t=L.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.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(n).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))},[L]),te=(0,O.useCallback)(async({dataset:e,groupKey:t})=>{try{let r=await _.get(`dataset`,e),i=typeof r?.object==`string`?r.object:void 0;if(!i)return;let o=Array.isArray(r?.dimensions)?r.dimensions:[],s=new Map(o.filter(e=>e?.name).map(e=>[e.name,e])),c=L?.find(e=>e.name===i)?.fields,l=e=>{if(Array.isArray(c))return c.find(t=>t?.name===e);if(c&&typeof c==`object`)return c[e]},u=new URLSearchParams;for(let[e,n]of Object.entries(t)){if(n==null)continue;let t=s.get(e);if(t?.dateGranularity)continue;let r=t?.field||e,i=l(r);if(i?.type===`lookup`||i?.type===`master_detail`)continue;let a=n;if(Array.isArray(i?.options)){let e=i.options.find(e=>e?.label===n||e?.value===n);e&&e.value!=null&&(a=e.value)}u.set(`filter[${r}]`,String(a))}let d=u.toString();a(`${n?`/apps/${n}`:``}/${i}${d?`?${d}`:``}`)}catch(e){console.warn(`ReportView: drill navigation failed`,e)}},[_,a,n,L]),ne=(0,O.useMemo)(()=>{let e=W||H;return X(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??ee},[W,H,X]),Z=(0,O.useCallback)(async e=>{try{_&&(await E(`report`,i,e,{metadataClient:_}),z().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[_,i,z]),re=(0,O.useCallback)(()=>{G(H),j(!0),F(e=>e+1)},[H]),ie=(0,O.useCallback)(()=>{j(!1)},[]),ae=(0,O.useMemo)(()=>W||H,[P]),oe=(0,O.useCallback)(e=>{G(e),Z(e),F(e=>e+1)},[Z]),se=(0,O.useCallback)((e,t)=>{G(n=>({...n,[e]:t}))},[]);(0,O.useEffect)(()=>{U(V)},[V]),(0,O.useEffect)(()=>{D||G(null)},[V]);let Q=W||H,ce=(0,O.useMemo)(()=>JSON.stringify(Q?.filters),[Q?.filters]),le=(0,O.useMemo)(()=>JSON.stringify(Q?.dataSource),[Q?.dataSource]),ue=(0,O.useMemo)(()=>JSON.stringify(Q?.data),[Q?.data]);if((0,O.useEffect)(()=>{if(!Q||!e){q([]);return}if(Q.data&&Array.isArray(Q.data)){q(Q.data);return}if(Q.dataSource){(async()=>{Y(!0);try{let t=Q.dataSource.object||Q.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),q([]);return}q((await e.find(t,{$filter:Q.dataSource.filter,$orderby:Q.dataSource.sort,$top:Q.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),q([])}finally{Y(!1)}})();return}if(Q.objectName){(async()=>{Y(!0);try{q((await e.find(Q.objectName,{$filter:Q.filters,$orderby:Q.sort,$top:Q.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),q([])}finally{Y(!1)}})();return}q([])},[Q?.objectName,Q?.limit,ce,le,ue,e]),R)return(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsx)(p,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!V||!H)return!R&&!V?(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsxs)(m,{children:[(0,k.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,k.jsx)(d,{className:`h-6 w-6 text-muted-foreground`})}),(0,k.jsx)(f,{children:t(`empty.reportNotFound`)}),(0,k.jsx)(v,{children:t(`empty.reportNotFoundDescription`,{name:i})})]})}):(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsx)(p,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let de=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?L?.find(e=>e.name===n):null,i=Array.isArray(r?.fields)?r.fields:r?.fields?Object.entries(r.fields).map(([e,t])=>({name:e,...t})):[],a={};for(let e of i)e&&e.name&&(a[e.name]=e);let o=e=>{let t=e.name||e.field,n=t?a[t]:void 0;if(!n)return e;let r={...e};if(r.type===void 0&&n.type!==void 0&&(r.type=n.type),r.options===void 0&&Array.isArray(n.options)&&(r.options=n.options),r.referenceTo===void 0){let e=n.referenceTo||n.reference?.to||n.target;e&&(r.referenceTo=e)}return r.label===void 0&&n.label&&(r.label=n.label),r};if(!t.fields&&Array.isArray(t.columns)?t.fields=t.columns.map(e=>{let t=o(e);return{name:t.field||t.name,label:t.label,type:t.type,options:t.options,referenceTo:t.referenceTo,format:t.format,renderAs:t.renderAs,colorMap:t.colorMap,...t.aggregate?{aggregation:t.aggregate,showInSummary:!0}:{}}}):Array.isArray(t.fields)&&(t.fields=t.fields.map(o)),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.type||t.reportType||`tabular`,i=[];(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,options:e.options,referenceTo:e.referenceTo,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))});let a=t.chart||t.chartConfig,o=a?.type||a?.chartType;if(o){let e=a.xAxis||a.xAxisField,t=a.yAxis||a.yAxisFields?.[0];i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:o,xAxisField:e,yAxisFields:t?[t]:a.yAxisFields}})}if(Array.isArray(e.sections)){let t=e.sections.filter(e=>e.type===`chart`&&!o);i.push(...t)}t.sections=i}else t.sections||=[];return t},$=W||H,fe=!!($&&(typeof $.dataset==`string`||$.type===`joined`&&Array.isArray($.blocks)&&$.blocks.some(e=>typeof e?.dataset==`string`)))||!!($&&$.objectName&&($.type===`matrix`||$.type===`joined`||$.type===`summary`||$.type===`tabular`||$.type===void 0||Array.isArray($.groupingsAcross)&&$.groupingsAcross.length>0||Array.isArray($.columns))),pe={type:`report-viewer`,report:de($),data:K,showToolbar:!0,allowExport:!0,loading:J};return(0,k.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,k.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,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:$.title||$.label||`Report Viewer`}),$.description&&(0,k.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:$.description})]}),(0,k.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:T&&(0,k.jsxs)(`button`,{type:`button`,onClick:re,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,k.jsx)(g,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,k.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,k.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,k.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,k.jsx)(O.Suspense,{fallback:(0,k.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:fe?(0,k.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,k.jsx)(N,{schema:$,dataSource:e,rows:K,onDrill:te})}):(0,k.jsx)(M,{schema:pe})})})}),(0,k.jsx)(A,{open:D&&T,onClose:ie,config:ae,onSave:oe,onFieldChange:se,availableFields:ne,getFieldsForObject:X,name:i,metadataClient:_,onAfterChange:()=>z().catch(()=>{})}),(0,k.jsx)(w,{open:h,sections:[{title:`Report Configuration`,data:$}]})]})]})}export{j as t};
|
|
2
|
+
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,f as r,m as i,t as a,u as o}from"./vendor-react-DR370ovB.js";import{f as s}from"./infrastructure-CJNwTVno.js";import{T as c,r as l,w as u}from"./framework-BLEk-ou3.js";import{H as d,Is as f,Ma as p,R as m,Sr as h,Xi as g,hr as _,z as v}from"./ui-components-NS_7__gn.js";import"./AdapterProvider-DJb3ZVmJ.js";import"./MetadataProvider-Dh20h6BN.js";import{r as y}from"./ExpressionProvider-DKFCgLsJ.js";import{C as b,r as x}from"./mergeServerFields-CMIOI8QD.js";import{n as S,r as C,t as w}from"./MetadataInspector-CACgSTc7.js";import{t as T}from"./ReportDefaultInspector-CjR-PcBn.js";import{r as E,t as D}from"./RuntimeDraftBar-DTf-DIfT.js";var O=e(n(),1),k=a();function A({open:e,onClose:t,config:n,onSave:r,onFieldChange:i,name:a,metadataClient:o,onAfterChange:s}){let{t:c}=l(),u=(0,O.useMemo)(()=>x(),[]),[d,f]=(0,O.useState)(!1),p=(0,O.useMemo)(()=>({...n??{}}),[n]),[m,g]=(0,O.useState)(p),v=(0,O.useRef)(m),y=(0,O.useRef)(p);y.current!==p&&(y.current=p,v.current=p,g(p),f(!1));let b=(0,O.useCallback)(e=>{let t={...v.current,...e};if(v.current=t,g(t),f(!0),i)for(let[n,r]of Object.entries(e))i(n,r,t)},[i]),S=(0,O.useCallback)(()=>{r(v.current),f(!1),t()},[r,t]),C=(0,O.useCallback)(e=>{let t={...e};v.current=t,g(t),f(!1)},[]),w=(0,O.useCallback)(()=>{t()},[t]);return e?(0,k.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`report-config-panel`,role:`complementary`,"aria-label":c(`report.editor.title`,{defaultValue:`Edit report`}),children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium truncate`,children:c(`report.editor.title`,{defaultValue:`Edit report`})}),(0,k.jsx)(_,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":c(`common.close`,{defaultValue:`Close`}),"data-testid":`report-config-close`,children:(0,k.jsx)(h,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,k.jsx)(T,{type:`report`,name:typeof m.name==`string`?m.name:``,draft:m,readOnly:!1,locale:u,onPatch:b})}),(0,k.jsxs)(`div`,{"data-testid":`report-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,k.jsx)(D,{type:`report`,name:a,metadataClient:o,dirty:d,onResume:C,onAfterChange:s}),(0,k.jsx)(_,{variant:`ghost`,size:`sm`,onClick:w,"data-testid":`report-config-discard`,children:c(`common.cancel`,{defaultValue:`Cancel`})}),(0,k.jsx)(_,{size:`sm`,onClick:S,"data-testid":`report-config-save`,children:c(`common.save`,{defaultValue:`Save`})})]})]}):null}var j=t({ReportView:()=>P}),M=(0,O.lazy)(()=>i(()=>import(`./plugin-report-DckNGNq6.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0]),import.meta.url)),N=(0,O.lazy)(()=>i(()=>import(`./plugin-report-DckNGNq6.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url)),ee=[{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 P({dataSource:e}){let{t}=l(),{appName:n,reportName:i}=r(),a=o(),{showDebug:h}=S();u();let _=b(),{user:x}=s(),T=x?.role===`admin`,[D,j]=(0,O.useState)(!1),[P,F]=(0,O.useState)(0),{reports:I,objects:L,loading:R,refresh:z}=c(),{app:B}=y(),V=C(I,i,B?._packageId),[H,U]=(0,O.useState)(V),[W,G]=(0,O.useState)(null),[K,q]=(0,O.useState)([]),[J,Y]=(0,O.useState)(!1),X=(0,O.useCallback)(e=>{if(!e||!L?.length)return;let t=L.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.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(n).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))},[L]),te=(0,O.useCallback)(async({dataset:e,groupKey:t})=>{try{let r=await _.get(`dataset`,e),i=typeof r?.object==`string`?r.object:void 0;if(!i)return;let o=Array.isArray(r?.dimensions)?r.dimensions:[],s=new Map(o.filter(e=>e?.name).map(e=>[e.name,e])),c=L?.find(e=>e.name===i)?.fields,l=e=>{if(Array.isArray(c))return c.find(t=>t?.name===e);if(c&&typeof c==`object`)return c[e]},u=new URLSearchParams;for(let[e,n]of Object.entries(t)){if(n==null)continue;let t=s.get(e);if(t?.dateGranularity)continue;let r=t?.field||e,i=l(r);if(i?.type===`lookup`||i?.type===`master_detail`)continue;let a=n;if(Array.isArray(i?.options)){let e=i.options.find(e=>e?.label===n||e?.value===n);e&&e.value!=null&&(a=e.value)}u.set(`filter[${r}]`,String(a))}let d=u.toString();a(`${n?`/apps/${n}`:``}/${i}${d?`?${d}`:``}`)}catch(e){console.warn(`ReportView: drill navigation failed`,e)}},[_,a,n,L]),ne=(0,O.useMemo)(()=>{let e=W||H;return X(e?.objectName||e?.dataSource?.object||e?.dataSource?.resource)??ee},[W,H,X]),Z=(0,O.useCallback)(async e=>{try{_&&(await E(`report`,i,e,{metadataClient:_}),z().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[_,i,z]),re=(0,O.useCallback)(()=>{G(H),j(!0),F(e=>e+1)},[H]),ie=(0,O.useCallback)(()=>{j(!1)},[]),ae=(0,O.useMemo)(()=>W||H,[P]),oe=(0,O.useCallback)(e=>{G(e),Z(e),F(e=>e+1)},[Z]),se=(0,O.useCallback)((e,t)=>{G(n=>({...n,[e]:t}))},[]);(0,O.useEffect)(()=>{U(V)},[V]),(0,O.useEffect)(()=>{D||G(null)},[V]);let Q=W||H,ce=(0,O.useMemo)(()=>JSON.stringify(Q?.filters),[Q?.filters]),le=(0,O.useMemo)(()=>JSON.stringify(Q?.dataSource),[Q?.dataSource]),ue=(0,O.useMemo)(()=>JSON.stringify(Q?.data),[Q?.data]);if((0,O.useEffect)(()=>{if(!Q||!e){q([]);return}if(Q.data&&Array.isArray(Q.data)){q(Q.data);return}if(Q.dataSource){(async()=>{Y(!0);try{let t=Q.dataSource.object||Q.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),q([]);return}q((await e.find(t,{$filter:Q.dataSource.filter,$orderby:Q.dataSource.sort,$top:Q.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),q([])}finally{Y(!1)}})();return}if(Q.objectName){(async()=>{Y(!0);try{q((await e.find(Q.objectName,{$filter:Q.filters,$orderby:Q.sort,$top:Q.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),q([])}finally{Y(!1)}})();return}q([])},[Q?.objectName,Q?.limit,ce,le,ue,e]),R)return(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsx)(p,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!V||!H)return!R&&!V?(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsxs)(m,{children:[(0,k.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,k.jsx)(f,{className:`h-6 w-6 text-muted-foreground`})}),(0,k.jsx)(d,{children:t(`empty.reportNotFound`)}),(0,k.jsx)(v,{children:t(`empty.reportNotFoundDescription`,{name:i})})]})}):(0,k.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,k.jsx)(p,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let de=e=>{let t={...e};!t.title&&t.label&&(t.title=t.label);let n=t.objectName||t.dataSource?.object||t.dataSource?.resource,r=n?L?.find(e=>e.name===n):null,i=Array.isArray(r?.fields)?r.fields:r?.fields?Object.entries(r.fields).map(([e,t])=>({name:e,...t})):[],a={};for(let e of i)e&&e.name&&(a[e.name]=e);let o=e=>{let t=e.name||e.field,n=t?a[t]:void 0;if(!n)return e;let r={...e};if(r.type===void 0&&n.type!==void 0&&(r.type=n.type),r.options===void 0&&Array.isArray(n.options)&&(r.options=n.options),r.referenceTo===void 0){let e=n.referenceTo||n.reference?.to||n.target;e&&(r.referenceTo=e)}return r.label===void 0&&n.label&&(r.label=n.label),r};if(!t.fields&&Array.isArray(t.columns)?t.fields=t.columns.map(e=>{let t=o(e);return{name:t.field||t.name,label:t.label,type:t.type,options:t.options,referenceTo:t.referenceTo,format:t.format,renderAs:t.renderAs,colorMap:t.colorMap,...t.aggregate?{aggregation:t.aggregate,showInSummary:!0}:{}}}):Array.isArray(t.fields)&&(t.fields=t.fields.map(o)),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.type||t.reportType||`tabular`,i=[];(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,options:e.options,referenceTo:e.referenceTo,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))});let a=t.chart||t.chartConfig,o=a?.type||a?.chartType;if(o){let e=a.xAxis||a.xAxisField,t=a.yAxis||a.yAxisFields?.[0];i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:o,xAxisField:e,yAxisFields:t?[t]:a.yAxisFields}})}if(Array.isArray(e.sections)){let t=e.sections.filter(e=>e.type===`chart`&&!o);i.push(...t)}t.sections=i}else t.sections||=[];return t},$=W||H,fe=!!($&&(typeof $.dataset==`string`||$.type===`joined`&&Array.isArray($.blocks)&&$.blocks.some(e=>typeof e?.dataset==`string`)))||!!($&&$.objectName&&($.type===`matrix`||$.type===`joined`||$.type===`summary`||$.type===`tabular`||$.type===void 0||Array.isArray($.groupingsAcross)&&$.groupingsAcross.length>0||Array.isArray($.columns))),pe={type:`report-viewer`,report:de($),data:K,showToolbar:!0,allowExport:!0,loading:J};return(0,k.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,k.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,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:$.title||$.label||`Report Viewer`}),$.description&&(0,k.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:$.description})]}),(0,k.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:T&&(0,k.jsxs)(`button`,{type:`button`,onClick:re,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,k.jsx)(g,{className:`h-3.5 w-3.5`}),t(`common.edit`)]})})]}),(0,k.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,k.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,k.jsx)(`div`,{className:`w-full shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,k.jsx)(O.Suspense,{fallback:(0,k.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:t(`common.loading`,{defaultValue:`Loading…`})}),children:fe?(0,k.jsx)(`div`,{className:`p-4 sm:p-6`,children:(0,k.jsx)(N,{schema:$,dataSource:e,rows:K,onDrill:te})}):(0,k.jsx)(M,{schema:pe})})})}),(0,k.jsx)(A,{open:D&&T,onClose:ie,config:ae,onSave:oe,onFieldChange:se,availableFields:ne,getFieldsForObject:X,name:i,metadataClient:_,onAfterChange:()=>z().catch(()=>{})}),(0,k.jsx)(w,{open:h,sections:[{title:`Report Configuration`,data:$}]})]})]})}export{j as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{Ir as r,Ma as i,hr as a,xi as o}from"./ui-components-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{Ir as r,Ma as i,hr as a,xi as o}from"./ui-components-NS_7__gn.js";import{a as s,i as c,r as l}from"./mergeServerFields-CMIOI8QD.js";var u=e(t(),1);function d(e){if(!e||typeof e!=`object`)return null;let t=e;if(`item`in t){let e=t.item;return!e||typeof e!=`object`?null:Object.keys(e).length>0?e:null}return Object.keys(t).length>0?t:null}async function f(e,t,n,r){await r.metadataClient.save(e,t,n,{mode:`draft`})}async function p(e,t,n,r){return await r.metadataClient.save(e,t,n,{mode:`draft`}),t}async function m(e,t,n){return d(await n.metadataClient.get(e,t,{state:`draft`}))}async function h(e,t,n){await n.metadataClient.reset(e,t,{state:`draft`})}async function g(e,t,n){await n.metadataClient.publish(e,t)}var _=n();function v({type:e,name:t,metadataClient:n,dirty:d,onResume:f,onAfterChange:p,savedSignal:v}){let y=l(),[b,x]=(0,u.useState)(!1),[S,C]=(0,u.useState)(!1),w=(0,u.useRef)(null),T=(0,u.useCallback)(async()=>{if(!t||!n){x(!1);return}let r;try{r=await m(e,t,{metadataClient:n})}catch{x(!1);return}if(x(!!r),r&&f&&w.current!==t){w.current=t;try{f(r)}catch(e){console.error(`[RuntimeDraftBar] Resume draft failed:`,e)}}},[e,t,n,f]);(0,u.useEffect)(()=>{T()},[T]);let E=(0,u.useRef)(v);(0,u.useEffect)(()=>{v!==E.current&&(E.current=v,v&&x(!0))},[v]);let D=(0,u.useCallback)(async()=>{if(t){C(!0);try{await g(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Publish failed:`,e)}finally{C(!1)}}},[e,t,n,p]),O=(0,u.useCallback)(async()=>{if(t&&!(typeof confirm==`function`&&!confirm(s(`engine.edit.discardDraftConfirm`,y,{type:e,name:t})))){C(!0);try{await h(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Discard draft failed:`,e)}finally{C(!1)}}},[e,t,n,p,y]);return b?(0,_.jsxs)(`div`,{className:`mr-auto flex items-center gap-2`,"data-testid":`runtime-draft-bar`,children:[(0,_.jsxs)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,title:c(`engine.edit.draftPending`,y),"data-testid":`runtime-draft-indicator`,children:[`● `,c(`engine.edit.draftPending`,y)]}),(0,_.jsx)(a,{variant:`ghost`,size:`sm`,onClick:O,disabled:S,className:`h-7 w-7 p-0 text-muted-foreground`,title:c(`engine.edit.discardDraft`,y),"aria-label":c(`engine.edit.discardDraft`,y),"data-testid":`runtime-draft-discard`,children:(0,_.jsx)(r,{className:`h-3.5 w-3.5`})}),(0,_.jsx)(a,{size:`sm`,onClick:D,disabled:S||d,className:`h-7 px-2 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:c(d?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,y),"data-testid":`runtime-draft-publish`,children:S?(0,_.jsx)(i,{className:`h-3.5 w-3.5 animate-spin`}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(o,{className:`h-3.5 w-3.5 mr-1`}),c(`engine.edit.publish`,y)]})})]}):null}export{p as n,f as r,v as t};
|
|
@@ -1 +1 @@
|
|
|
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}from"./vendor-react-DR370ovB.js";import{f as s}from"./infrastructure-CJNwTVno.js";import{T as c,r as l}from"./framework-BLEk-ou3.js";import{$n as u,Co as d,
|
|
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}from"./vendor-react-DR370ovB.js";import{f as s}from"./infrastructure-CJNwTVno.js";import{T as c,r as l}from"./framework-BLEk-ou3.js";import{$n as u,Co as d,Ha as f,Is as p,Jn as m,Si as h,Wo as g,nn as _,qn as v,sc as y}from"./ui-components-NS_7__gn.js";import"./MetadataProvider-Dh20h6BN.js";import{n as b}from"./ui-layout-BdKOzi1L.js";import{n as x}from"./appRoute-D5vwtoc_.js";var S=t({SearchResultsPage:()=>O}),C=e(n(),1),w=o();function T(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...T(n.children)):t.push(n);return t}var E={object:g,dashboard:f,page:d,report:p},D={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 O(){let{t:e}=l(),{appName:t}=r(),[n,o]=i(),[d,f]=(0,C.useState)(n.get(`q`)||``),{apps:p}=c(),S=p||[],O=x(S,t)||S[0],k=`/apps/${t}`,{user:A}=s(),j=(0,C.useMemo)(()=>{if(!O)return[];let e=T(O.navigation||[]),t={currentUserId:A?.id??null};return e.map(e=>{let{href:n}=b(e,k,t);return{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:n,type:e.type,description:e.description}}).filter(e=>e.href!==`#`)},[O,k,A?.id]),M=(0,C.useMemo)(()=>{if(!d.trim())return j;let e=d.toLowerCase();return j.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[j,d]),N=e=>{f(e),o(e?{q:e}:{})},P=(0,C.useMemo)(()=>{let e={};for(let t of M)(e[t.type]||=[]).push(t);return e},[M]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,w.jsxs)(a,{to:k,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,w.jsx)(y,{className:`h-4 w-4`}),e(`search.back`)]}),(0,w.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`search.title`)})]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:e(`search.placeholder`)}),(0,w.jsx)(h,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(_,{id:`search-results-input`,value:d,onChange:e=>N(e.target.value),placeholder:e(`search.placeholder`),className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,w.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:d.trim()?e(M.length===1?`search.resultsCount`:`search.resultsCountPlural`,{count:M.length,query:d}):e(`search.itemsAvailable`,{count:j.length})}),M.length===0?(0,w.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,w.jsx)(h,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,w.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:e(`search.noResults`)}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:e(`search.noResultsHint`)})]}):(0,w.jsx)(`div`,{className:`space-y-6`,children:Object.entries(P).map(([t,n])=>{let r=E[t]||g,i=`search.type${t.charAt(0).toUpperCase()}${t.slice(1)}s`;return`${t.charAt(0).toUpperCase()}${t.slice(1)}`,(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,w.jsx)(r,{className:`h-4 w-4`}),e(i),(0,w.jsx)(u,{variant:`secondary`,className:`ml-1 text-xs`,children:n.length})]}),(0,w.jsx)(`div`,{className:`grid gap-2`,children:n.map(t=>{let n=E[t.type]||g,r=`search.badge${t.type.charAt(0).toUpperCase()}${t.type.slice(1)}`;return(0,w.jsx)(a,{to:t.href,className:`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:(0,w.jsx)(v,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,w.jsxs)(m,{className:`flex items-center gap-3 p-3`,children:[(0,w.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${D[t.type]||``}`,children:(0,w.jsx)(n,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,w.jsx)(`p`,{className:`text-sm font-medium truncate`,children:t.label}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:t.description})]}),(0,w.jsx)(u,{variant:`outline`,className:`text-xs shrink-0`,children:e(r)})]})})},t.id)})})]},t)})})]})}export{S as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n,u as r}from"./vendor-react-DR370ovB.js";import{$n as i,Jn as a,Mt as o,Xn as s,Yn as c,Zn as l,bi as u,qn as d}from"./ui-components-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n,u as r}from"./vendor-react-DR370ovB.js";import{$n as i,Jn as a,Mt as o,Xn as s,Yn as c,Zn as l,bi as u,qn as d}from"./ui-components-NS_7__gn.js";import{o as f,r as p,t as m}from"./types-C2_UYDEK.js";var h=e(t(),1),g=n();function _(){let e=r(),[t,n]=(0,h.useState)(null),[_,v]=(0,h.useState)(null);(0,h.useEffect)(()=>{p().then(e=>n(e.manifests??[])).catch(e=>v(e?.message??`Failed to load settings`))},[]);let y=(0,h.useMemo)(()=>{if(!t)return null;let e=new Map;for(let n of[...t].sort((e,t)=>(e.order??999)-(t.order??999))){let t=n.category??`Other`,r=e.get(t)??[];r.push(n),e.set(t,r)}return e},[t]);return(0,g.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,g.jsx)(u,{className:`h-7 w-7 text-muted-foreground`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Settings`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure your workspace, integrations, and feature flags.`})]})]}),_?(0,g.jsx)(d,{children:(0,g.jsx)(a,{className:`py-8 text-center text-sm text-destructive`,children:_})}):null,t?t.length===0?(0,g.jsx)(d,{children:(0,g.jsx)(a,{className:`py-12 text-center text-sm text-muted-foreground`,children:`No settings registered. Plugins can register settings manifests via the SettingsService.`})}):Array.from(y??[]).map(([t,n])=>(0,g.jsxs)(`section`,{className:`mb-8`,children:[(0,g.jsx)(`h2`,{className:`text-sm font-semibold tracking-wide uppercase text-muted-foreground mb-3`,children:t}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:n.map(t=>(0,g.jsxs)(d,{className:`cursor-pointer hover:border-primary/50 hover:shadow-sm transition-all`,onClick:()=>e(`/system/settings/${t.namespace}`),children:[(0,g.jsxs)(s,{className:`pb-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,g.jsx)(t.icon?f(t.icon):u,{className:`h-6 w-6 text-muted-foreground`}),t.beta?(0,g.jsx)(i,{variant:`secondary`,className:`text-[10px]`,children:`Beta`}):null]}),(0,g.jsx)(l,{className:`text-base mt-2`,children:m(t.label)}),t.description?(0,g.jsx)(c,{className:`text-xs`,children:t.description}):null]}),(0,g.jsx)(a,{className:`pt-0`,children:(0,g.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.specifiers.length,` setting`,t.specifiers.length===1?``:`s`]})})]},t.namespace))})]},t)):(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsx)(o,{className:`h-6 w-32`}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:3}).map((e,t)=>(0,g.jsx)(o,{className:`h-32 w-full`},t))})]})]})}export{_ as SettingsHub};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-DR370ovB.js";import{r as a}from"./framework-BLEk-ou3.js";import{$n as o,Ai as s,Bt as c,Ht as l,Ja as u,Jn as d,Kn as f,Ma as p,Mt as m,Ts as h,Ut as g,Vt as _,Wt as v,Xt as y,Zt as b,ar as x,ft as S,hr as C,ir as w,ja as T,nn as E,on as D,pt as O,qn as k,rr as A,sc as j,tt as M,zt as N}from"./ui-components-CrPYFyEM.js";import{r as P}from"./vendor-ui-utils-rQOI1gAo.js";import{a as F,i as I,n as L,o as R,t as z}from"./types-CosU35As.js";var B=e(t(),1),V=r();function H({reason:e,className:t}){return(0,V.jsxs)(o,{variant:`outline`,className:`gap-1 border-amber-300 bg-amber-50 text-amber-900 ${t??``}`,title:e??`Pinned by environment variable — cannot be edited from the UI.`,children:[(0,V.jsx)(T,{className:`h-3 w-3`}),`Locked by env`]})}function U({resolved:e,labels:t}){let n=e.cascadeChain;if(!n||n.length===0)return null;let r=n.find(e=>e.effective)??n[n.length-1],i=n.find(e=>e!==r&&e.value!==null&&e.value!==void 0),a=e=>t?.sourceLabel?.(e)??e;return r.scope!=="default"&&r.scope!==`user`&&r.scope!==`tenant`?(0,V.jsxs)(o,{variant:`outline`,className:`text-blue-700 border-blue-300 text-[10px]`,children:[`Inherited from `,a(r.scope)]}):i?(0,V.jsxs)(o,{variant:`outline`,className:`text-amber-700 border-amber-300 text-[10px]`,children:[`Overrides `,a(i.scope)]}):null}function W({spec:e,resolved:t,labelText:n,labels:r}){return(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(D,{className:`text-sm font-medium`,children:[n,e.required?(0,V.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`}):null]}),e.deprecated?(0,V.jsxs)(o,{variant:`outline`,className:`text-amber-700 border-amber-300`,children:[`Deprecated`,e.replacedBy?` → ${e.replacedBy}`:``]}):null,t?.locked?(0,V.jsx)(H,{reason:t.lockedReason}):null,t&&!t.locked?(0,V.jsx)(U,{resolved:t,labels:r}):null,t?.source&&t.source!=="default"&&!t.locked?(0,V.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r?.sourceLabel?.(t.source)??t.source}):null]})}function G({description:e}){return e?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e}):null}function K(e){let{spec:t,resolved:n,value:r,onChange:i,onAction:a,locked:o,saving:s,labels:d}=e,p=(0,B.useId)(),m=!!(o||s),T=z(t.label),k=t.key&&d?d.fieldLabel(t.key,T):T,j=t.key&&d?d.fieldHelp(t.key,t.description):t.description;if(t.type===`group`){let e=t.id&&d?d.groupTitle(t.id,T):T,n=t.id&&d?d.groupDescription(t.id,t.description):t.description;return(0,V.jsxs)(`div`,{className:`pt-6 pb-2`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold tracking-tight text-foreground/90`,children:e}),n?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n}):null,(0,V.jsx)(N,{className:`mt-3`})]})}if(t.type===`info_banner`)return(0,V.jsxs)(A,{variant:t.bannerSeverity===`error`?`destructive`:`default`,className:`my-2`,children:[(0,V.jsx)(u,{className:`h-4 w-4`}),(0,V.jsx)(x,{children:T}),t.bannerText?(0,V.jsx)(w,{children:t.bannerText}):null]});if(t.type===`child_pane`)return(0,V.jsxs)(`a`,{href:`#/settings/${t.childNamespace}`,className:`flex items-center justify-between rounded-md border border-border bg-card px-4 py-3 hover:bg-accent transition-colors`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:T}),t.description?(0,V.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description}):null]}),(0,V.jsx)(h,{className:`h-4 w-4 text-muted-foreground`})]});if(t.type===`title_value`)return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),(0,V.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(r??`—`)})]});if(t.type===`action_button`){let e=t.icon?R(t.icon):null,n=t.id??t.key??`test`,r=d?d.actionLabel(n,T):T;return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:r}),t.description?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t.description}):null]}),(0,V.jsxs)(C,{size:`sm`,variant:`secondary`,onClick:a,disabled:s,children:[e?(0,V.jsx)(e,{className:`h-4 w-4 mr-1.5`}):null,r]})]})}let P=e=>(0,V.jsxs)(`div`,{className:`space-y-1.5 py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),e,(0,V.jsx)(G,{description:j})]}),F=e=>{let n=typeof e.label==`string`?e.label:e.label?.defaultValue??String(e.value);return!t.key||!d?n:d.optionLabel(t.key,String(e.value),n)};switch(t.type){case`text`:case`email`:case`url`:case`phone`:return P((0,V.jsx)(E,{id:p,type:t.type===`email`?`email`:t.type===`url`?`url`:`text`,value:r??``,minLength:t.minLength,maxLength:t.maxLength,pattern:t.pattern,disabled:m,onChange:e=>i(e.target.value)}));case`password`:return P((0,V.jsx)(E,{id:p,type:`password`,autoComplete:`new-password`,placeholder:r?`••••••••`:``,disabled:m,onChange:e=>i(e.target.value)}));case`textarea`:return P((0,V.jsx)(M,{id:p,rows:t.rows??4,value:r??``,minLength:t.minLength,maxLength:t.maxLength,disabled:m,onChange:e=>i(e.target.value)}));case`number`:return P((0,V.jsx)(E,{id:p,type:`number`,value:r,min:t.min,max:t.max,step:t.step,disabled:m,onChange:e=>i(e.target.value===``?null:Number(e.target.value))}));case`toggle`:return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),(0,V.jsx)(G,{description:j})]}),(0,V.jsx)(S,{id:p,checked:!!r,disabled:m,onCheckedChange:e=>i(e)})]});case`select`:return P((0,V.jsxs)(c,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:m,children:[(0,V.jsx)(g,{id:p,children:(0,V.jsx)(v,{placeholder:`Select…`})}),(0,V.jsx)(_,{children:t.options?.map(e=>(0,V.jsx)(l,{value:String(e.value),children:F(e)},String(e.value)))})]}));case`radio`:return P((0,V.jsx)(y,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:m,children:t.options?.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(b,{value:String(e.value),id:`${p}-${e.value}`}),(0,V.jsx)(D,{htmlFor:`${p}-${e.value}`,className:`text-sm font-normal`,children:F(e)})]},String(e.value)))}));case`multiselect`:{let e=Array.isArray(r)?r:[];return P((0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:t.options?.map(t=>{let n=String(t.value);return(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(f,{checked:e.map(String).includes(n),disabled:m,onCheckedChange:t=>{let r=new Set(e.map(String));t?r.add(n):r.delete(n),i(Array.from(r))}}),F(t)]},n)})}))}case`slider`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(O,{value:[Number(r??t.min??0)],min:t.min??0,max:t.max??100,step:t.step??1,disabled:m,onValueChange:e=>i(e[0]),className:`flex-1`}),(0,V.jsx)(`span`,{className:`text-sm tabular-nums w-12 text-right`,children:String(r??t.min??0)})]}));case`color`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(E,{id:p,type:`color`,value:r??`#000000`,disabled:m,onChange:e=>i(e.target.value),className:`w-16 h-9 p-1`}),(0,V.jsx)(E,{value:r??``,disabled:m,onChange:e=>i(e.target.value),className:`flex-1 font-mono text-sm`})]}));case`json`:return P((0,V.jsx)(M,{id:p,rows:t.rows??6,className:`font-mono text-xs`,value:typeof r==`string`?r:JSON.stringify(r??null,null,2),disabled:m,onChange:e=>i(e.target.value)}));default:return P((0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Unsupported specifier type: `,t.type]}))}}var q=new Set([`common`,`validation`,`errors`,`system`,`auth`]);function J(e){let{t,i18n:n}=a();return(0,B.useMemo)(()=>{let r=()=>{if(!n||typeof n.getResourceBundle!=`function`)return[];let e=n.language||`en`,t=n.getResourceBundle(e,`translation`);return t?Object.keys(t).filter(e=>!q.has(e)&&t[e]&&typeof t[e]==`object`&&t[e].settings):[]},i=(n,i)=>{if(!e)return i;try{let i=r();for(let r of i){let i=`${r}.settings.${e}.${n}`,a=t(i,{defaultValue:``});if(a&&a!==i&&a!==``)return a}}catch{}return i},a=(e,r)=>{try{if(!n||typeof n.getResourceBundle!=`function`)return r;let i=n.language||`en`,a=n.getResourceBundle(i,`translation`);if(!a)return r;for(let n of Object.keys(a)){if(q.has(n))continue;let r=a[n];if(!r||typeof r!=`object`||!(`settingsCommon`in r))continue;let i=`${n}.settingsCommon.${e}`,o=t(i,{defaultValue:``});if(o&&o!==i&&o!==``)return o}}catch{}return r},o={env:`Env`,global:`Global`,tenant:`Tenant`,user:`User`,default:`Default`};return{title:e=>i(`title`,e)??e,description:e=>i(`description`,e),groupTitle:(e,t)=>i(`groups.${e}.title`,t)??t,groupDescription:(e,t)=>i(`groups.${e}.description`,t),fieldLabel:(e,t)=>i(`keys.${e}.label`,t)??t,fieldHelp:(e,t)=>i(`keys.${e}.help`,t),fieldPlaceholder:(e,t)=>i(`keys.${e}.placeholder`,t),optionLabel:(e,t,n)=>i(`keys.${e}.options.${t}`,n)??n,actionLabel:(e,t)=>i(`actions.${e}.label`,t)??t,actionConfirm:(e,t)=>i(`actions.${e}.confirmText`,t),actionSuccess:(e,t)=>i(`actions.${e}.successMessage`,t),sourceLabel:e=>a(`sourceLabels.${e}`,o[e]??e)}},[e,t,n,n?.language])}function Y(e,t){if(!e)return!0;let n=e.trim().match(/^\$\{(.+)\}$/);if(!n)return!0;try{return!!Function(`data`,`with (data) { return (${n[1]}); }`)(t)}catch{return!0}}function X(){let e=n(),t=i(),r=e.namespace??``,[a,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(!0),[f,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(null),[v,y]=(0,B.useState)({}),b=(0,B.useCallback)(async()=>{u(!0),_(null);try{c(await L(r)),y({})}catch(e){_(e?.message??`Failed to load settings`)}finally{u(!1)}},[r]);(0,B.useEffect)(()=>{r&&b()},[r,b]);let x=(0,B.useMemo)(()=>{let e={};if(!a)return e;for(let[t,n]of Object.entries(a.values))e[t]=n.value;return{...e,...v}},[a,v]),S=(0,B.useMemo)(()=>Object.keys(v),[v]),w=J(r);if(!r)return(0,V.jsx)(`div`,{className:`p-6 text-muted-foreground`,children:`No namespace selected.`});if(l)return(0,V.jsxs)(`div`,{className:`p-6 space-y-3 max-w-3xl`,children:[(0,V.jsx)(m,{className:`h-8 w-1/3`}),(0,V.jsx)(m,{className:`h-4 w-2/3`}),(0,V.jsx)(m,{className:`h-32 w-full`}),(0,V.jsx)(m,{className:`h-32 w-full`})]});if(g)return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>t(-1),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` Back`]}),(0,V.jsx)(k,{className:`mt-3`,children:(0,V.jsx)(d,{className:`py-8 text-center text-sm text-destructive`,children:g})})]});if(!a)return null;let{manifest:T,values:E}=a,D=T.icon?R(T.icon):null,O=w.title(z(T.label)),A=w.description(T.description),M=async()=>{if(S.length!==0){h(!0);try{let e=await F(r,v);c({...a,values:{...E,...e.values}}),y({}),P.success(`Settings saved`)}catch(e){e?.payload?.error?.code===`SETTINGS_LOCKED`?P.error(`Locked by environment: ${e.payload.error.key}`):P.error(e?.message??`Save failed`)}finally{h(!1)}}},N=async e=>{h(!0);try{let t=await I(r,e,v);t.ok?P.success(t.message??`Action succeeded`):P.error(t.message??`Action failed`)}catch(e){P.error(e?.message??`Action failed`)}finally{h(!1)}};return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl mx-auto pb-32`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>t(`/system/settings`),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` All settings`]}),(0,V.jsxs)(`div`,{className:`mt-3 flex items-start gap-3`,children:[D?(0,V.jsx)(D,{className:`h-7 w-7 mt-0.5 text-muted-foreground`}):null,(0,V.jsxs)(`div`,{className:`flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:O}),T.beta?(0,V.jsx)(o,{variant:`secondary`,children:`Beta`}):null]}),A?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:A}):null]})]}),T.helpText?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-4 whitespace-pre-wrap`,children:T.helpText}):null,(0,V.jsx)(`div`,{className:`mt-6 divide-y`,children:T.specifiers.filter(e=>Y(e.visible,x)).map((e,t)=>{let n=e.key,r=n?E[n]:void 0;return(0,V.jsx)(K,{spec:e,resolved:r,value:n?n in v?v[n]:r?.value:void 0,onChange:e=>n&&y(t=>({...t,[n]:e})),onAction:e.type===`action_button`?()=>N(e.id??n??`test`):void 0,locked:r?.locked,saving:f,labels:w},(n??`_layout_${t}`)+t)})}),S.length>0?(0,V.jsx)(`div`,{className:`fixed bottom-0 inset-x-0 bg-background/95 backdrop-blur border-t shadow-lg z-40`,children:(0,V.jsxs)(`div`,{className:`max-w-3xl mx-auto px-6 py-3 flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[S.length,` unsaved change`,S.length>1?`s`:``]}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>y({}),disabled:f,children:[(0,V.jsx)(s,{className:`h-4 w-4 mr-1`}),` Discard`]}),(0,V.jsxs)(C,{onClick:M,disabled:f,children:[f?(0,V.jsx)(p,{className:`h-4 w-4 mr-1 animate-spin`}):null,`Save changes`]})]})]})}):null]})}export{X as SettingsView};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-DR370ovB.js";import{r as a}from"./framework-BLEk-ou3.js";import{$n as o,Ai as s,Bt as c,Ht as l,Ja as u,Jn as d,Kn as f,Ma as p,Mt as m,Ts as h,Ut as g,Vt as _,Wt as v,Xt as y,Zt as b,ar as x,ft as S,hr as C,ir as w,ja as T,nn as E,on as D,pt as O,qn as k,rr as A,sc as j,tt as M,zt as N}from"./ui-components-NS_7__gn.js";import{r as P}from"./vendor-ui-utils-rQOI1gAo.js";import{a as F,i as I,n as L,o as R,t as z}from"./types-C2_UYDEK.js";var B=e(t(),1),V=r();function H({reason:e,className:t}){return(0,V.jsxs)(o,{variant:`outline`,className:`gap-1 border-amber-300 bg-amber-50 text-amber-900 ${t??``}`,title:e??`Pinned by environment variable — cannot be edited from the UI.`,children:[(0,V.jsx)(T,{className:`h-3 w-3`}),`Locked by env`]})}function U({resolved:e,labels:t}){let n=e.cascadeChain;if(!n||n.length===0)return null;let r=n.find(e=>e.effective)??n[n.length-1],i=n.find(e=>e!==r&&e.value!==null&&e.value!==void 0),a=e=>t?.sourceLabel?.(e)??e;return r.scope!=="default"&&r.scope!==`user`&&r.scope!==`tenant`?(0,V.jsxs)(o,{variant:`outline`,className:`text-blue-700 border-blue-300 text-[10px]`,children:[`Inherited from `,a(r.scope)]}):i?(0,V.jsxs)(o,{variant:`outline`,className:`text-amber-700 border-amber-300 text-[10px]`,children:[`Overrides `,a(i.scope)]}):null}function W({spec:e,resolved:t,labelText:n,labels:r}){return(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(D,{className:`text-sm font-medium`,children:[n,e.required?(0,V.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`}):null]}),e.deprecated?(0,V.jsxs)(o,{variant:`outline`,className:`text-amber-700 border-amber-300`,children:[`Deprecated`,e.replacedBy?` → ${e.replacedBy}`:``]}):null,t?.locked?(0,V.jsx)(H,{reason:t.lockedReason}):null,t&&!t.locked?(0,V.jsx)(U,{resolved:t,labels:r}):null,t?.source&&t.source!=="default"&&!t.locked?(0,V.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r?.sourceLabel?.(t.source)??t.source}):null]})}function G({description:e}){return e?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e}):null}function K(e){let{spec:t,resolved:n,value:r,onChange:i,onAction:a,locked:o,saving:s,labels:d}=e,p=(0,B.useId)(),m=!!(o||s),T=z(t.label),k=t.key&&d?d.fieldLabel(t.key,T):T,j=t.key&&d?d.fieldHelp(t.key,t.description):t.description;if(t.type===`group`){let e=t.id&&d?d.groupTitle(t.id,T):T,n=t.id&&d?d.groupDescription(t.id,t.description):t.description;return(0,V.jsxs)(`div`,{className:`pt-6 pb-2`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold tracking-tight text-foreground/90`,children:e}),n?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n}):null,(0,V.jsx)(N,{className:`mt-3`})]})}if(t.type===`info_banner`)return(0,V.jsxs)(A,{variant:t.bannerSeverity===`error`?`destructive`:`default`,className:`my-2`,children:[(0,V.jsx)(u,{className:`h-4 w-4`}),(0,V.jsx)(x,{children:T}),t.bannerText?(0,V.jsx)(w,{children:t.bannerText}):null]});if(t.type===`child_pane`)return(0,V.jsxs)(`a`,{href:`#/settings/${t.childNamespace}`,className:`flex items-center justify-between rounded-md border border-border bg-card px-4 py-3 hover:bg-accent transition-colors`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:T}),t.description?(0,V.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description}):null]}),(0,V.jsx)(h,{className:`h-4 w-4 text-muted-foreground`})]});if(t.type===`title_value`)return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),(0,V.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(r??`—`)})]});if(t.type===`action_button`){let e=t.icon?R(t.icon):null,n=t.id??t.key??`test`,r=d?d.actionLabel(n,T):T;return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:r}),t.description?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t.description}):null]}),(0,V.jsxs)(C,{size:`sm`,variant:`secondary`,onClick:a,disabled:s,children:[e?(0,V.jsx)(e,{className:`h-4 w-4 mr-1.5`}):null,r]})]})}let P=e=>(0,V.jsxs)(`div`,{className:`space-y-1.5 py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),e,(0,V.jsx)(G,{description:j})]}),F=e=>{let n=typeof e.label==`string`?e.label:e.label?.defaultValue??String(e.value);return!t.key||!d?n:d.optionLabel(t.key,String(e.value),n)};switch(t.type){case`text`:case`email`:case`url`:case`phone`:return P((0,V.jsx)(E,{id:p,type:t.type===`email`?`email`:t.type===`url`?`url`:`text`,value:r??``,minLength:t.minLength,maxLength:t.maxLength,pattern:t.pattern,disabled:m,onChange:e=>i(e.target.value)}));case`password`:return P((0,V.jsx)(E,{id:p,type:`password`,autoComplete:`new-password`,placeholder:r?`••••••••`:``,disabled:m,onChange:e=>i(e.target.value)}));case`textarea`:return P((0,V.jsx)(M,{id:p,rows:t.rows??4,value:r??``,minLength:t.minLength,maxLength:t.maxLength,disabled:m,onChange:e=>i(e.target.value)}));case`number`:return P((0,V.jsx)(E,{id:p,type:`number`,value:r,min:t.min,max:t.max,step:t.step,disabled:m,onChange:e=>i(e.target.value===``?null:Number(e.target.value))}));case`toggle`:return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:k,labels:d}),(0,V.jsx)(G,{description:j})]}),(0,V.jsx)(S,{id:p,checked:!!r,disabled:m,onCheckedChange:e=>i(e)})]});case`select`:return P((0,V.jsxs)(c,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:m,children:[(0,V.jsx)(g,{id:p,children:(0,V.jsx)(v,{placeholder:`Select…`})}),(0,V.jsx)(_,{children:t.options?.map(e=>(0,V.jsx)(l,{value:String(e.value),children:F(e)},String(e.value)))})]}));case`radio`:return P((0,V.jsx)(y,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:m,children:t.options?.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(b,{value:String(e.value),id:`${p}-${e.value}`}),(0,V.jsx)(D,{htmlFor:`${p}-${e.value}`,className:`text-sm font-normal`,children:F(e)})]},String(e.value)))}));case`multiselect`:{let e=Array.isArray(r)?r:[];return P((0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:t.options?.map(t=>{let n=String(t.value);return(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(f,{checked:e.map(String).includes(n),disabled:m,onCheckedChange:t=>{let r=new Set(e.map(String));t?r.add(n):r.delete(n),i(Array.from(r))}}),F(t)]},n)})}))}case`slider`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(O,{value:[Number(r??t.min??0)],min:t.min??0,max:t.max??100,step:t.step??1,disabled:m,onValueChange:e=>i(e[0]),className:`flex-1`}),(0,V.jsx)(`span`,{className:`text-sm tabular-nums w-12 text-right`,children:String(r??t.min??0)})]}));case`color`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(E,{id:p,type:`color`,value:r??`#000000`,disabled:m,onChange:e=>i(e.target.value),className:`w-16 h-9 p-1`}),(0,V.jsx)(E,{value:r??``,disabled:m,onChange:e=>i(e.target.value),className:`flex-1 font-mono text-sm`})]}));case`json`:return P((0,V.jsx)(M,{id:p,rows:t.rows??6,className:`font-mono text-xs`,value:typeof r==`string`?r:JSON.stringify(r??null,null,2),disabled:m,onChange:e=>i(e.target.value)}));default:return P((0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Unsupported specifier type: `,t.type]}))}}var q=new Set([`common`,`validation`,`errors`,`system`,`auth`]);function J(e){let{t,i18n:n}=a();return(0,B.useMemo)(()=>{let r=()=>{if(!n||typeof n.getResourceBundle!=`function`)return[];let e=n.language||`en`,t=n.getResourceBundle(e,`translation`);return t?Object.keys(t).filter(e=>!q.has(e)&&t[e]&&typeof t[e]==`object`&&t[e].settings):[]},i=(n,i)=>{if(!e)return i;try{let i=r();for(let r of i){let i=`${r}.settings.${e}.${n}`,a=t(i,{defaultValue:``});if(a&&a!==i&&a!==``)return a}}catch{}return i},a=(e,r)=>{try{if(!n||typeof n.getResourceBundle!=`function`)return r;let i=n.language||`en`,a=n.getResourceBundle(i,`translation`);if(!a)return r;for(let n of Object.keys(a)){if(q.has(n))continue;let r=a[n];if(!r||typeof r!=`object`||!(`settingsCommon`in r))continue;let i=`${n}.settingsCommon.${e}`,o=t(i,{defaultValue:``});if(o&&o!==i&&o!==``)return o}}catch{}return r},o={env:`Env`,global:`Global`,tenant:`Tenant`,user:`User`,default:`Default`};return{title:e=>i(`title`,e)??e,description:e=>i(`description`,e),groupTitle:(e,t)=>i(`groups.${e}.title`,t)??t,groupDescription:(e,t)=>i(`groups.${e}.description`,t),fieldLabel:(e,t)=>i(`keys.${e}.label`,t)??t,fieldHelp:(e,t)=>i(`keys.${e}.help`,t),fieldPlaceholder:(e,t)=>i(`keys.${e}.placeholder`,t),optionLabel:(e,t,n)=>i(`keys.${e}.options.${t}`,n)??n,actionLabel:(e,t)=>i(`actions.${e}.label`,t)??t,actionConfirm:(e,t)=>i(`actions.${e}.confirmText`,t),actionSuccess:(e,t)=>i(`actions.${e}.successMessage`,t),sourceLabel:e=>a(`sourceLabels.${e}`,o[e]??e)}},[e,t,n,n?.language])}function Y(e,t){if(!e)return!0;let n=e.trim().match(/^\$\{(.+)\}$/);if(!n)return!0;try{return!!Function(`data`,`with (data) { return (${n[1]}); }`)(t)}catch{return!0}}function X(){let e=n(),t=i(),r=e.namespace??``,[a,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(!0),[f,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(null),[v,y]=(0,B.useState)({}),b=(0,B.useCallback)(async()=>{u(!0),_(null);try{c(await L(r)),y({})}catch(e){_(e?.message??`Failed to load settings`)}finally{u(!1)}},[r]);(0,B.useEffect)(()=>{r&&b()},[r,b]);let x=(0,B.useMemo)(()=>{let e={};if(!a)return e;for(let[t,n]of Object.entries(a.values))e[t]=n.value;return{...e,...v}},[a,v]),S=(0,B.useMemo)(()=>Object.keys(v),[v]),w=J(r);if(!r)return(0,V.jsx)(`div`,{className:`p-6 text-muted-foreground`,children:`No namespace selected.`});if(l)return(0,V.jsxs)(`div`,{className:`p-6 space-y-3 max-w-3xl`,children:[(0,V.jsx)(m,{className:`h-8 w-1/3`}),(0,V.jsx)(m,{className:`h-4 w-2/3`}),(0,V.jsx)(m,{className:`h-32 w-full`}),(0,V.jsx)(m,{className:`h-32 w-full`})]});if(g)return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>t(-1),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` Back`]}),(0,V.jsx)(k,{className:`mt-3`,children:(0,V.jsx)(d,{className:`py-8 text-center text-sm text-destructive`,children:g})})]});if(!a)return null;let{manifest:T,values:E}=a,D=T.icon?R(T.icon):null,O=w.title(z(T.label)),A=w.description(T.description),M=async()=>{if(S.length!==0){h(!0);try{let e=await F(r,v);c({...a,values:{...E,...e.values}}),y({}),P.success(`Settings saved`)}catch(e){e?.payload?.error?.code===`SETTINGS_LOCKED`?P.error(`Locked by environment: ${e.payload.error.key}`):P.error(e?.message??`Save failed`)}finally{h(!1)}}},N=async e=>{h(!0);try{let t=await I(r,e,v);t.ok?P.success(t.message??`Action succeeded`):P.error(t.message??`Action failed`)}catch(e){P.error(e?.message??`Action failed`)}finally{h(!1)}};return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl mx-auto pb-32`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>t(`/system/settings`),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` All settings`]}),(0,V.jsxs)(`div`,{className:`mt-3 flex items-start gap-3`,children:[D?(0,V.jsx)(D,{className:`h-7 w-7 mt-0.5 text-muted-foreground`}):null,(0,V.jsxs)(`div`,{className:`flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:O}),T.beta?(0,V.jsx)(o,{variant:`secondary`,children:`Beta`}):null]}),A?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:A}):null]})]}),T.helpText?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-4 whitespace-pre-wrap`,children:T.helpText}):null,(0,V.jsx)(`div`,{className:`mt-6 divide-y`,children:T.specifiers.filter(e=>Y(e.visible,x)).map((e,t)=>{let n=e.key,r=n?E[n]:void 0;return(0,V.jsx)(K,{spec:e,resolved:r,value:n?n in v?v[n]:r?.value:void 0,onChange:e=>n&&y(t=>({...t,[n]:e})),onAction:e.type===`action_button`?()=>N(e.id??n??`test`):void 0,locked:r?.locked,saving:f,labels:w},(n??`_layout_${t}`)+t)})}),S.length>0?(0,V.jsx)(`div`,{className:`fixed bottom-0 inset-x-0 bg-background/95 backdrop-blur border-t shadow-lg z-40`,children:(0,V.jsxs)(`div`,{className:`max-w-3xl mx-auto px-6 py-3 flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[S.length,` unsaved change`,S.length>1?`s`:``]}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(C,{variant:`ghost`,size:`sm`,onClick:()=>y({}),disabled:f,children:[(0,V.jsx)(s,{className:`h-4 w-4 mr-1`}),` Discard`]}),(0,V.jsxs)(C,{onClick:M,disabled:f,children:[f?(0,V.jsx)(p,{className:`h-4 w-4 mr-1 animate-spin`}):null,`Save changes`]})]})]})}):null]})}export{X as SettingsView};
|