@lobu/runtime-server 24.9.0 → 24.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/catalogs/automations.json +2 -2
- package/dist/catalogs/connectors.json +16 -4
- package/dist/catalogs/skills.json +1 -1
- package/dist/component.json +1 -1
- package/dist/connectors/postgres.ts +39 -24
- package/dist/connectors/whatsapp-web-adapter.js +41 -10
- package/dist/connectors/whatsapp-web-helpers.ts +12 -2
- package/dist/connectors/whatsapp_web.ts +18 -2
- package/dist/db/migrations/20261112210000_instance_identity.sql +18 -0
- package/dist/dependencies.bun.lock +62 -60
- package/dist/embeddings-server.mjs +38 -5
- package/dist/owletto/dist/assets/_-CYvj1y65.js +3 -0
- package/dist/owletto/dist/assets/_-CeLTSYYY.js +2 -0
- package/dist/owletto/dist/assets/_agentId-BB5E-L6T.js +2 -0
- package/dist/owletto/dist/assets/{_agentId-bna2tPsW.js → _agentId-DN0EwMAC.js} +2 -2
- package/dist/owletto/dist/assets/_automationId-DvUl9CSd.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-CVKfL9AG.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey.index-Cv6FzK1v.js +2 -0
- package/dist/owletto/dist/assets/{_conversationId-zcs-S3dY.js → _conversationId-CPpNySjO.js} +2 -2
- package/dist/owletto/dist/assets/_eventId-DZKicuq6.js +2 -0
- package/dist/owletto/dist/assets/_owner-Dauk3YuD.js +3 -0
- package/dist/owletto/dist/assets/_shape-cKrEID3T.js +2 -0
- package/dist/owletto/dist/assets/_slug-DJx_8fsV.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-CPVzVKEf.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-CW8gexOQ.js +2 -0
- package/dist/owletto/dist/assets/accept-invitation-Dwq1GAnG.js +2 -0
- package/dist/owletto/dist/assets/activity-route-location-C1jcXC7v.js +2 -0
- package/dist/owletto/dist/assets/activity-route-view-D78Wj0RH.js +2 -0
- package/dist/owletto/dist/assets/agent-connect-pages-DoI9UR0a.js +4 -0
- package/dist/owletto/dist/assets/{agent-editor-form-Bnc_q5WD.js → agent-editor-form-DlavYg2q.js} +2 -2
- package/dist/owletto/dist/assets/{agent-loading-shells-xteN-pyK.js → agent-loading-shells-DYqQphN7.js} +2 -2
- package/dist/owletto/dist/assets/agent-permissions-matrix-C1L8IcYR.js +2 -0
- package/dist/owletto/dist/assets/{agent-skill-context-r0O0BVOu.js → agent-skill-context-D1nMrVod.js} +2 -2
- package/dist/owletto/dist/assets/{agent-subpage-shell-C2KpYdu3.js → agent-subpage-shell-2w7vTeXw.js} +2 -2
- package/dist/owletto/dist/assets/{agent-thread-Bv_chdPy.js → agent-thread-BopD-2k1.js} +3 -3
- package/dist/owletto/dist/assets/{app._appId-BUcNaSMS.js → app._appId-BXeFXW1w.js} +2 -2
- package/dist/owletto/dist/assets/{assist-composer-B1LykXpD.js → assist-composer-CL5x8pNt.js} +2 -2
- package/dist/owletto/dist/assets/automation-run-now-MtxUTfzd.js +2 -0
- package/dist/owletto/dist/assets/{callback-kSLa4n5s.js → callback-BgfwP1Eo.js} +2 -2
- package/dist/owletto/dist/assets/{card-C01y1O-W.js → card-DtLIFq7D.js} +2 -2
- package/dist/owletto/dist/assets/{claim-Dnux9Lqf.js → claim-CT3hYVMF.js} +2 -2
- package/dist/owletto/dist/assets/{client-activity-scopes-BBIq16tG.js → client-activity-scopes-BPbRX-Pe.js} +2 -2
- package/dist/owletto/dist/assets/{client-rows-DGh1O-Fu.js → client-rows-vrNA6FLs.js} +2 -2
- package/dist/owletto/dist/assets/clients-xnzZeEdZ.js +2 -0
- package/dist/owletto/dist/assets/{code-editor-BdRMYojw.js → code-editor-mrKkAfcE.js} +2 -2
- package/dist/owletto/dist/assets/connect-NUCSay8X.js +2 -0
- package/dist/owletto/dist/assets/{connect-menu-D4w-JhJW.js → connect-menu-C6iVtuSo.js} +2 -2
- package/dist/owletto/dist/assets/connect._clientId-Cp-d9Q5b.js +2 -0
- package/dist/owletto/dist/assets/{connected._clientId-BsDzltNz.js → connected._clientId-ROfVgp9h.js} +2 -2
- package/dist/owletto/dist/assets/connection-BMz740Wi.js +2 -0
- package/dist/owletto/dist/assets/{connection-feed-detail-CJju0qiw.js → connection-feed-detail-0VAJiZTP.js} +2 -2
- package/dist/owletto/dist/assets/connector-page-shell-BFv21yuv.js +2 -0
- package/dist/owletto/dist/assets/{connector-provenance-B2C2cjBg.js → connector-provenance-b59RfBtk.js} +2 -2
- package/dist/owletto/dist/assets/connectors-nYS31lO2.js +2 -0
- package/dist/owletto/dist/assets/consent-cPRF9JQv.js +2 -0
- package/dist/owletto/dist/assets/{copy-button-BhXeXLIm.js → copy-button-C3wMMv63.js} +2 -2
- package/dist/owletto/dist/assets/{core.esm-CJUp2aNZ.js → core.esm-C9QlSrgK.js} +3 -3
- package/dist/owletto/dist/assets/{create-DUlRsFNn.js → create-ASRN3Obq.js} +2 -2
- package/dist/owletto/dist/assets/create-CBcodaSO.js +2 -0
- package/dist/owletto/dist/assets/create-CGOWfMk4.js +2 -0
- package/dist/owletto/dist/assets/{create-automation-form-D141prEG.js → create-automation-form-CLicoPH5.js} +3 -3
- package/dist/owletto/dist/assets/create._connectorKey-s4xkktTC.js +2 -0
- package/dist/owletto/dist/assets/{custom-guardrail-edits-DuQ28xv3.js → custom-guardrail-edits-BUL7nmuO.js} +2 -2
- package/dist/owletto/dist/assets/{definition-comparison-BUDNuAN_.js → definition-comparison-4UYMI6BK.js} +2 -2
- package/dist/owletto/dist/assets/{detail-page-skeleton-BRHaq5Sj.js → detail-page-skeleton-C8v3rJXK.js} +2 -2
- package/dist/owletto/dist/assets/device-BBwsOi7q.js +2 -0
- package/dist/owletto/dist/assets/{device-pin-tombstone-BIM-ziCH.js → device-pin-tombstone-Bcpe7nAA.js} +2 -2
- package/dist/owletto/dist/assets/{device._deviceId-BnPqTgK1.js → device._deviceId-DLT4jh0Z.js} +2 -2
- package/dist/owletto/dist/assets/{dynamic-schema-form-OkIZImgp.js → dynamic-schema-form-BDT8x0Vg.js} +2 -2
- package/dist/owletto/dist/assets/{entity-options-CpeX7iiX.js → entity-options-B9hm9V87.js} +2 -2
- package/dist/owletto/dist/assets/entity-page-DZjzQ2V4.js +2 -0
- package/dist/owletto/dist/assets/entity-pages-BWBpttz3.js +2 -0
- package/dist/owletto/dist/assets/entity-schema-graph-lMMx3HhR.js +2 -0
- package/dist/owletto/dist/assets/{entity-type-page-MgZ7_0oh.js → entity-type-page-CkQm0yEu.js} +2 -2
- package/dist/owletto/dist/assets/{event-detail-D6AH6a2C.js → event-detail-CkzfakTK.js} +2 -2
- package/dist/owletto/dist/assets/events-feed-DmRzikZW.js +2 -0
- package/dist/owletto/dist/assets/{filter-editors-DDTwyYt0.js → filter-editors-CQoSj-20.js} +3 -3
- package/dist/owletto/dist/assets/{full-page-spinner-DWo519BU.js → full-page-spinner-CYyCnKve.js} +2 -2
- package/dist/owletto/dist/assets/index-BE7eb2kE.js +2 -0
- package/dist/owletto/dist/assets/index-BFR0uiKY.js +2 -0
- package/dist/owletto/dist/assets/{index-Cd8jMsz8.js → index-BS5Ty3tf.js} +2 -2
- package/dist/owletto/dist/assets/index-C38OzBpB.js +2 -0
- package/dist/owletto/dist/assets/{index-D1UCJQl1.js → index-C3hz9tzx.js} +2 -2
- package/dist/owletto/dist/assets/index-CDyFQ32o.js +2 -0
- package/dist/owletto/dist/assets/{index-BW7IFKXC.js → index-CUndAH6o.js} +2 -2
- package/dist/owletto/dist/assets/index-CiKysEhV.js +2 -0
- package/dist/owletto/dist/assets/{index-CdDNNAx2.js → index-DByaMzsG.js} +274 -274
- package/dist/owletto/dist/assets/index-DfdinB7B.js +2 -0
- package/dist/owletto/dist/assets/index-DgMM4Zt5.css +1 -0
- package/dist/owletto/dist/assets/index-Xk711gVC.js +2 -0
- package/dist/owletto/dist/assets/{index-DmqnKGqW.js → index-ittfA0k8.js} +2 -2
- package/dist/owletto/dist/assets/{json-diff-C-WQqyIf.js → json-diff-mcDgyct_.js} +2 -2
- package/dist/owletto/dist/assets/{list-skeleton-0B1bTrAK.js → list-skeleton-DsYGUHxi.js} +2 -2
- package/dist/owletto/dist/assets/login-EoLq136v.js +2 -0
- package/dist/owletto/dist/assets/{logout-D474YsYQ.js → logout-gLgEQOiX.js} +2 -2
- package/dist/owletto/dist/assets/{member-scope-gate-CH_0jHiM.js → member-scope-gate-vvkgSAb2.js} +2 -2
- package/dist/owletto/dist/assets/memory-browse-page-DvDtwrEI.js +74 -0
- package/dist/owletto/dist/assets/{model-selector-XYmk7Iru.js → model-selector-D3vSMLO2.js} +2 -2
- package/dist/owletto/dist/assets/{needs-you-list-Bd4iiiqm.js → needs-you-list-B5Bgd05M.js} +2 -2
- package/dist/owletto/dist/assets/{new-CJ6TF3Vc.js → new-BPW3V0Y1.js} +2 -2
- package/dist/owletto/dist/assets/new-Bk_flKQO.js +2 -0
- package/dist/owletto/dist/assets/new-C5HtQdM_.js +2 -0
- package/dist/owletto/dist/assets/new-dLXsCHBd.js +2 -0
- package/dist/owletto/dist/assets/organization-DBfgBkzq.js +2 -0
- package/dist/owletto/dist/assets/{peek-pane-content-Cc8YX1oy.js → peek-pane-content-c2PG3TEX.js} +2 -2
- package/dist/owletto/dist/assets/{pending-seed-D7-ld7as.js → pending-seed-CBhx2Ql-.js} +2 -2
- package/dist/owletto/dist/assets/{proposal-review-shell-BWRJidwb.js → proposal-review-shell-B-jYcKfB.js} +2 -2
- package/dist/owletto/dist/assets/public-shell-ready-D8TijlRY.js +2 -0
- package/dist/owletto/dist/assets/record-activity-DnRVOrG2.js +2 -0
- package/dist/owletto/dist/assets/{record-session-ClKBr1_C.js → record-session-CAmGHMyM.js} +2 -2
- package/dist/owletto/dist/assets/{renderer-DZ0w2k2r.js → renderer-olRv_HMI.js} +3 -3
- package/dist/owletto/dist/assets/reset-password-B9_xi8Pq.js +2 -0
- package/dist/owletto/dist/assets/{run-initiator-B8IRlRd-.js → run-initiator-DhE5v4z0.js} +2 -2
- package/dist/owletto/dist/assets/runs-C8sZQr4o.js +2 -0
- package/dist/owletto/dist/assets/{runs-list-8gUPWjP4.js → runs-list-CwtH-wmk.js} +2 -2
- package/dist/owletto/dist/assets/{schema-value-k19Ata7u.js → schema-value-zTJGE4eh.js} +3 -3
- package/dist/owletto/dist/assets/{scoped-feed-bar-L7h-Ca4u.js → scoped-feed-bar-BKyJSa3_.js} +2 -2
- package/dist/owletto/dist/assets/{settings-BZqntV3E.js → settings-z02cvVS3.js} +2 -2
- package/dist/owletto/dist/assets/source-record-panels-CGmKIJdN.js +2 -0
- package/dist/owletto/dist/assets/{status-variants-BR_iGWN5.js → status-variants-DyRCXBzM.js} +2 -2
- package/dist/owletto/dist/assets/subDays-D8nHthaS.js +2 -0
- package/dist/owletto/dist/assets/{table-C3DMoL4K.js → table-C637cQxG.js} +2 -2
- package/dist/owletto/dist/assets/use-automations-CgWNoYio.js +2 -0
- package/dist/owletto/dist/assets/use-login-redirect-tDdhXTpt.js +2 -0
- package/dist/owletto/dist/assets/{use-mention-search-CtbixPEE.js → use-mention-search-D-kIKchD.js} +2 -2
- package/dist/owletto/dist/assets/view-param-filters-CUCj9Df-.js +2 -0
- package/dist/owletto/dist/assets/{views-access-required-CvIIxdS_.js → views-access-required-C35Dyt91.js} +2 -2
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +2733 -1795
- package/npm-shrinkwrap.json +238 -221
- package/package.json +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +6 -0
- package/vendor/connector-sdk/dist/index.d.ts +1 -0
- package/vendor/connector-sdk/dist/index.js +1 -0
- package/vendor/connector-sdk/dist/ip-reachability.d.ts +1 -1
- package/vendor/connector-sdk/dist/ip-reachability.js +1 -1
- package/vendor/connector-sdk/dist/logger.d.ts +1 -1
- package/vendor/connector-sdk/dist/logger.js +1 -1
- package/vendor/connector-sdk/dist/reaction-client-types.d.ts +3 -1
- package/vendor/connector-sdk/dist/retry.d.ts +1 -1
- package/vendor/connector-sdk/dist/retry.js +1 -1
- package/vendor/connector-sdk/dist/source-withheld-error.d.ts +16 -0
- package/vendor/connector-sdk/dist/source-withheld-error.js +19 -0
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/classify-error.d.ts +1 -1
- package/vendor/core/dist/classify-error.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +28 -3
- package/vendor/core/dist/contracts/tools/manage-automations.js +27 -8
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +8 -0
- package/vendor/core/dist/contracts/tools/manage-entity.js +11 -3
- package/vendor/core/dist/contracts/tools/save-memory.d.ts +11 -1
- package/vendor/core/dist/contracts/tools/save-memory.js +25 -3
- package/vendor/core/dist/contracts/tools/search-memory.js +1 -1
- package/vendor/core/dist/credentials.d.ts +12 -0
- package/vendor/core/dist/credentials.js +1 -0
- package/vendor/core/dist/errors.js +2 -2
- package/vendor/core/dist/worker/auth.d.ts +5 -0
- package/vendor/core/dist/worker/auth.js +15 -4
- package/vendor/core/package.json +1 -1
- package/vendor/postgres/cf/src/connection.js +7 -2
- package/vendor/postgres/cjs/src/connection.js +7 -2
- package/vendor/postgres/src/connection.js +7 -2
- package/vendor/views/dist/native.d.ts +33 -1
- package/vendor/views/dist/native.js +3 -0
- package/vendor/views/package.json +1 -1
- package/dist/owletto/dist/assets/_-B2C9B2RM.js +0 -2
- package/dist/owletto/dist/assets/_-CjyiGzwB.js +0 -3
- package/dist/owletto/dist/assets/_agentId-DKHXGvS2.js +0 -2
- package/dist/owletto/dist/assets/_automationId-CowRFD4E.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey._connectionId-dE6im18z.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey.index-DqwSv8Zs.js +0 -2
- package/dist/owletto/dist/assets/_eventId-BVOVizs4.js +0 -2
- package/dist/owletto/dist/assets/_owner-DsvIC94q.js +0 -3
- package/dist/owletto/dist/assets/_shape-CWjpzcvv.js +0 -2
- package/dist/owletto/dist/assets/_slug-DuCxYsJk.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-BqVeHB6Z.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-DzyOCG5U.js +0 -2
- package/dist/owletto/dist/assets/accept-invitation-k1u3zBcn.js +0 -2
- package/dist/owletto/dist/assets/activity-route-view-jTBMW7a9.js +0 -2
- package/dist/owletto/dist/assets/agent-connect-pages-D3mVM_q4.js +0 -4
- package/dist/owletto/dist/assets/agent-permissions-matrix-C_ayr0pd.js +0 -2
- package/dist/owletto/dist/assets/automation-run-now-CjkJIkaZ.js +0 -2
- package/dist/owletto/dist/assets/clients-BCvjAJDT.js +0 -2
- package/dist/owletto/dist/assets/connect-DZeFSGIH.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-IZEMQJ64.js +0 -2
- package/dist/owletto/dist/assets/connection-C7glVpPE.js +0 -2
- package/dist/owletto/dist/assets/connector-page-shell-BeuyjiB2.js +0 -2
- package/dist/owletto/dist/assets/connectors-DSQ5AWPf.js +0 -2
- package/dist/owletto/dist/assets/consent-B6Aw_89N.js +0 -2
- package/dist/owletto/dist/assets/create-CWcza8NT.js +0 -2
- package/dist/owletto/dist/assets/create-bGOYifof.js +0 -2
- package/dist/owletto/dist/assets/create._connectorKey-Ds4tpwHP.js +0 -2
- package/dist/owletto/dist/assets/device-D3fzoIrM.js +0 -2
- package/dist/owletto/dist/assets/entity-page-Cjc8oXA2.js +0 -2
- package/dist/owletto/dist/assets/entity-pages-18xSANrS.js +0 -2
- package/dist/owletto/dist/assets/entity-schema-graph-uwZ-P0t8.js +0 -2
- package/dist/owletto/dist/assets/events-feed-BI7wNRUY.js +0 -2
- package/dist/owletto/dist/assets/index-9tTjJo_J.css +0 -1
- package/dist/owletto/dist/assets/index-BYcFrinP.js +0 -2
- package/dist/owletto/dist/assets/index-BhJsTy-C.js +0 -2
- package/dist/owletto/dist/assets/index-CEcsgXDj.js +0 -2
- package/dist/owletto/dist/assets/index-CPscKk2u.js +0 -2
- package/dist/owletto/dist/assets/index-CfJ2-EpK.js +0 -2
- package/dist/owletto/dist/assets/index-D5DM4g2w.js +0 -2
- package/dist/owletto/dist/assets/index-DznAbTOF.js +0 -2
- package/dist/owletto/dist/assets/login-CH7P2AyR.js +0 -2
- package/dist/owletto/dist/assets/memory-browse-page-Ba4aYavw.js +0 -74
- package/dist/owletto/dist/assets/new-BOsrRqp8.js +0 -2
- package/dist/owletto/dist/assets/new-DGPOjak2.js +0 -2
- package/dist/owletto/dist/assets/new-Q0XqiZq2.js +0 -2
- package/dist/owletto/dist/assets/organization-hD_Z6TSd.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-CRyAZATw.js +0 -2
- package/dist/owletto/dist/assets/record-activity-9ux6SfCd.js +0 -2
- package/dist/owletto/dist/assets/reset-password-D2RfrEVZ.js +0 -2
- package/dist/owletto/dist/assets/runs-CuC7WMtd.js +0 -2
- package/dist/owletto/dist/assets/source-record-panels-C4UItfdk.js +0 -2
- package/dist/owletto/dist/assets/subDays-hOwerOLo.js +0 -2
- package/dist/owletto/dist/assets/use-automations-CdtiVLCv.js +0 -2
- package/dist/owletto/dist/assets/use-login-redirect-CYlVkAhE.js +0 -2
- package/dist/owletto/dist/assets/view-param-filters-BdN8OU35.js +0 -2
- /package/vendor/postgres/{.bun-tag-c81dacd34e959a7a → .bun-tag-652f2580b8090d71} +0 -0
package/dist/owletto/dist/assets/{device._deviceId-BnPqTgK1.js → device._deviceId-DLT4jh0Z.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{aE as F,j8 as ne,j9 as U,r as v,j as e,ja as P,B as y,ai as L,jb as C,cO as V,aV as te,ic as z,m as Y,bk as M,hk as ae,hl as ce,C as ie,hn as oe,cB as re,jc as le,a8 as de,c as me,a_ as ue,jd as xe,je as he,jf as pe,a$ as fe,aW as je,as as I,bj as T,L as A,jg as ge,jh as ve,bb as be,ji as ye,jj as Ne,a3 as ke,dt as _e,j3 as q,U as we,cc as Ce,dI as Se,dv as $e,dw as O,ex as De,jk as K,aT as Pe}from"./index-CdDNNAx2.js";import{C as Le}from"./connector-page-shell-BeuyjiB2.js";import{D as ze,R as Ee}from"./detail-page-skeleton-BRHaq5Sj.js";import{S as Ie,g as Ae}from"./status-variants-BR_iGWN5.js";import{c as G,C as Re}from"./device-pin-tombstone-BIM-ziCH.js";import{w as R}from"./workspace-label-o_QfBuCM.js";import"./list-skeleton-0B1bTrAK.js";import"./runs-CuC7WMtd.js";import"./filter-editors-DDTwyYt0.js";import"./subDays-hOwerOLo.js";import"./runs-list-8gUPWjP4.js";import"./run-initiator-B8IRlRd-.js";import"./use-automations-CdtiVLCv.js";import"./clients-BCvjAJDT.js";function Me(s,n,o){const h=new Set(s.capabilities??[]),m=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key)),r=new Set(J(s,o).map(t=>t.connector_key));return n.filter(t=>F(t)&&!!t.required_capability&&h.has(t.required_capability)&&!m.has(t.key)&&!r.has(t.key))}function J(s,n){return s.organization_slug===n?s.update_required:[]}function Be(s,n,o){const h=s.organization_slug;if(!h||h===o)return[];const m=new Set(n.map(t=>t.key)),r=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key));return s.connectors.filter(t=>t.organization_slug!==h||m.has(t.connector_key)||r.has(t.connector_key)?!1:(r.add(t.connector_key),!0))}function Te({device:s,organizationId:n,ownerSlug:o,connectable:h,unavailable:m}){const r=ne(),t=U(),[u,p]=v.useState(null),[j,a]=v.useState(null),[f,N]=v.useState(null),[g,d]=v.useState([]),x=s.organization_id===n,b=async c=>{p(null),N(null),a(c.key);try{x||await t.mutateAsync({deviceWorkerId:s.id,organizationId:n});const w=await r.mutateAsync({connector_key:c.key,device_worker_id:s.id}),S=w.connection_id??w.connection?.id;if(S===void 0)throw new Error(w.instructions??"The connection was not created.");d($=>[...$.filter(D=>D.connectorKey!==c.key),{connectorKey:c.key,name:c.name,connectionId:S,instructions:w.status==="setup_required"?w.instructions:void 0}])}catch(w){N({key:c.key,message:w instanceof Error?w.message:"Could not connect."})}finally{a(null)}},k=new Set(g.map(c=>c.connectorKey)),l=J(s,o),i=h.filter(c=>!k.has(c.key));return e.jsxs("div",{className:"mt-4 space-y-3",children:[g.map(c=>e.jsx(qe,{outcome:c,device:s,organizationId:n},c.connectorKey)),i.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Supported by this device"}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Not connected in this workspace yet.",x?null:" Connecting one moves the device here; you will be asked to confirm first."]}),e.jsx("div",{className:"divide-y border-y",children:i.map(c=>e.jsxs("div",{className:"space-y-2 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-sm font-medium",children:[c.name,c.required_capability&&P[c.required_capability]&&P[c.required_capability]!==c.name?e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:P[c.required_capability]}):null]}),e.jsxs(y,{size:"sm",variant:"outline","aria-label":`Connect ${c.name}`,disabled:j!==null,onClick:()=>x?void b(c):p(c.key),children:[j===c.key?e.jsx(L,{className:"mr-1.5"}):null,"Connect"]})]}),u===c.key?e.jsx(Q,{device:s,ownerSlug:o,title:"Move device to this workspace",intro:`${C(s)} lives in ${s.organization_name??"another workspace"}. A device serves one workspace at a time, so it has to move here before it can be connected.`,confirmLabel:"Move here and connect",onConfirm:()=>void b(c),onCancel:()=>p(null)}):null,f?.key===c.key?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.message}):null]},c.key))})]}):null,l.length>0?e.jsxs("div",{role:"status",children:[e.jsx("p",{className:"text-xs font-medium",children:"Update Lobu on this device"}),e.jsx("ul",{className:"mt-1 space-y-1 text-xs text-muted-foreground",children:l.map(c=>e.jsx("li",{children:`${c.display_name} — this device has ${c.device_version}, this workspace uses ${c.workspace_version}`},c.connector_key))})]}):null,m.length>0?e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:m.map(c=>e.jsx("li",{children:`${c.display_name} — set up on this device in ${s.organization_name??"its home workspace"}, not available in this workspace yet`},c.connector_key))}):null]})}function Q({device:s,ownerSlug:n,title:o,intro:h,aftermath:m,confirmLabel:r,pending:t=!1,onConfirm:u,onCancel:p}){const j=s.connector_count,a=s.connectors.filter(f=>f.organization_slug===n).length;return e.jsxs("div",{role:"alertdialog","aria-label":o,className:"space-y-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs",children:[e.jsx("p",{children:h}),e.jsxs("p",{className:"text-muted-foreground",children:[j>0?`Moving pauses and unpins all ${j} connection${j===1?"":"s"} pinned to it${a>0?`, including ${a} in this workspace`:""}. They stay paused until you reconnect them.`:"It has no pinned connections, so nothing is paused.",m?` ${m}`:null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",disabled:t,onClick:u,children:[t?e.jsx(L,{className:"mr-1.5"}):null,r]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:t,onClick:p,children:"Cancel"})]})]})}function qe({outcome:s,device:n,organizationId:o}){const{data:h=[],isLoading:m}=V(o,{connectionIds:[s.connectionId]}),r=h.find(p=>p.id===s.connectionId),t=C(n);if(m)return e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Checking ",s.name,"…"]});const u=[];if(!r)u.push(`${s.name} was created but could not be loaded yet.`);else if(r.status!=="active"){const p=G(r);u.push(`${s.name} is ${r.status}${p?`: ${p}`:"."}`)}return s.instructions&&u.push(s.instructions),n.online||u.push(`${t} is offline. ${s.name} runs once it reconnects.`),e.jsx("div",{role:"status",className:"rounded-lg border px-3 py-2 text-sm",children:u.length===0?e.jsxs("p",{children:[s.name," is ready on ",t,"."]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium",children:[s.name," connected, not ready yet"]}),e.jsx("ul",{className:"mt-1 list-disc pl-4 text-xs text-muted-foreground",children:u.map(p=>e.jsx("li",{children:p},p))})]})})}function W({device:s,organizationId:n,ownerSlug:o,selectedConnection:h,openSettings:m}){const{data:r=[],isLoading:t,isError:u,refetch:p}=te(n),j=new Map(r.map(d=>[d.key,d])),a=new Map,f=[];for(const d of s.connectors){if(d.organization_slug!==o)continue;const x=j.get(d.connector_key);if(!x||!F(x)){f.push(d);continue}const b=x.required_capability??`connector:${x.key}`,k=a.get(b)??{key:b,name:x.name,connections:[]};k.name=P[b]??x.name,k.connections.push(d),a.set(b,k)}const N=Me(s,r,o),g=Be(s,r,o);return e.jsxs(e.Fragment,{children:[e.jsxs(z,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),s.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!n||t?e.jsx(Y,{className:"h-24 w-full"}):u?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void p(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(d=>e.jsx(H,{group:d,deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:j,selectedConnection:h,openSettings:m},d.key))}),n&&!t&&!u?e.jsx(Te,{device:s,organizationId:n,ownerSlug:o,connectable:N,unavailable:g}):null,M(s)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),n&&f.length>0&&!t&&!u?e.jsxs(z,{title:"Apps and sources",count:String(f.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:[...new Set(f.map(d=>d.connector_key))].map(d=>e.jsx(H,{group:{key:d,name:j.get(d)?.name??d,connections:f.filter(x=>x.connector_key===d)},deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:j,selectedConnection:h,openSettings:m},d))})]}):null]})}function H({group:s,deviceId:n,organizationId:o,ownerSlug:h,definitionsByKey:m,selectedConnection:r,openSettings:t}){const u=s.connections.some(a=>a.connection_id===r),[p,j]=v.useState(u);return v.useEffect(()=>{u&&r!==void 0&&j(!0)},[u,r]),e.jsxs(ae,{open:p,onOpenChange:j,children:[e.jsxs(ce,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(ie,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:s.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:s.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":s.connections.length>1?`${s.connections.length} connections`:"Configured"})]}),e.jsx(oe,{className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:s.connections.map(a=>e.jsx(Oe,{summary:a,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m.get(a.connector_key),openSettings:a.connection_id===r&&t},a.connection_id))})})]})}function Oe({summary:s,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m,openSettings:r}){const{data:t=[],isLoading:u,isError:p,refetch:j}=V(o,{connectionIds:[s.connection_id]}),a=t.find(g=>g.id===s.connection_id&&g.device_worker_id===n),f=m?.name??s.connector_key,N=a?G(a):null;return e.jsxs("section",{id:`connection-${s.connection_id}`,"aria-label":f,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:re(a)}),e.jsx("span",{children:a.status})]}):null,u||!o?e.jsx(Y,{className:"h-24 w-full"}):p?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void j(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[N?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:N}):null,e.jsx("div",{className:"mb-4",children:e.jsx(le,{connection:a})}),e.jsx(Re,{connection:a,connectorDef:m,ownerSlug:h,openSettings:r,showActivity:!1,showShare:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function Ke({device:s,ownerSlug:n}){const o=v.useId(),{data:h=[]}=de(),m=U(),[r,t]=v.useState(!1),[u,p]=v.useState(null),[j,a]=v.useState(null),f=h.filter(l=>l.is_member).map(l=>({id:l.id,name:l.name,isPersonal:l.is_personal===!0})),N=f.find(l=>l.id===s.organization_id),g=N?R(N):s.organization_name??"No workspace",d=f.filter(l=>l.id!==s.organization_id),x=d.find(l=>l.id===u)??null,b=()=>{t(!1),p(null)},k=async l=>{a(null);try{await m.mutateAsync({deviceWorkerId:s.id,organizationId:l}),b()}catch(i){a(i instanceof Error?i.message:"Could not move the device.")}};return e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace: "}),g]}),!r&&d.length>0?e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{a(null),t(!0)},children:"Change workspace"}):null]}),r?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:o,className:"text-xs text-muted-foreground",children:"Move to"}),e.jsxs("select",{id:o,value:u??"",disabled:m.isPending,onChange:l=>p(l.target.value||null),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Choose a workspace"}),d.map(l=>e.jsx("option",{value:l.id,children:R(l)},l.id))]}),x?null:e.jsx(y,{size:"sm",variant:"ghost",onClick:b,children:"Cancel"})]}):null,x?e.jsx(Q,{device:s,ownerSlug:n,title:`Move device to ${x.name}`,intro:`Move ${C(s)} from ${g} to ${R(x)}?`,aftermath:`It is set up fresh in ${x.name}, with its connections there private to you until you share them.`,confirmLabel:"Move device",pending:m.isPending,onConfirm:()=>void k(x.id),onCancel:b}):null,j?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:j}):null]})}function We({ownerSlug:s,deviceId:n,organizationId:o,selectedConnection:h,openSettings:m}){const r=me(),{data:t=[],isLoading:u,isError:p,refetch:j}=ue(),a=xe(),f=he(),[N,g]=v.useState(!1),[d,x]=v.useState(!1),[b,k]=v.useState(""),l=pe(t,n),i=l&&fe(l,s)?l:void 0,c=i?.id??n,{data:w=[]}=je(o,{profileKind:"browser_session"}),S=v.useMemo(()=>w.filter(_=>_.device_worker_id===c&&_.status!=="revoked"),[w,c]),$=i?.label?.trim()??"";if(v.useEffect(()=>{d||k($)},[$,d]),u)return e.jsx(ze,{label:"Loading device"});if(p)return e.jsx(I,{children:e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{children:"Could not load this device."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void j(),children:"Retry"})]})});if(!i&&l&&o)return e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{platform:M(l),className:"h-5 w-5"}),e.jsx("h1",{className:"text-base font-semibold",children:C(l)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device lives in"," ",l.organization_name??"another workspace",", not this workspace."]}),e.jsx(W,{device:l,organizationId:o,ownerSlug:s})]});if(!i)return e.jsxs(I,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(A,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const D=ge(i),E=D?ve(s,D,be()):void 0,X=M(i),Z=ye(i.app_version),ee=Ne(i,Z),B=()=>{const _=b.trim(),se=i.label?.trim()??"";if(_===se){x(!1);return}f.mutate({deviceWorkerId:i.id,label:_.length===0?null:_},{onSuccess:()=>x(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(Le,{header:e.jsx(_e,{breadcrumb:e.jsx($e,{crumbs:[e.jsx(A,{to:"/$owner/connectors",params:{owner:s},search:{},className:O,children:"Connectors"},"connectors"),...E?[e.jsx(A,{to:"/$owner/connectors/app/$appId",params:{owner:s,appId:E.id},className:O,children:E.name},"app")]:[]]}),icon:e.jsx(T,{platform:X,className:"h-5 w-5"}),title:d?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(we,{"aria-label":"Device name",value:b,onChange:_=>k(_.target.value),placeholder:C({...i,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:_=>{_.key==="Enter"?(_.preventDefault(),N||B()):_.key==="Escape"&&(g(!1),k(i.label?.trim()??""),x(!1))}}),N?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",i.connector_count>0?`and un-pins ${i.connector_count} connector${i.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(y,{variant:"destructive",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(i.id,{onSuccess:()=>{g(!1),r({to:"/$owner/connectors",params:{owner:s},search:{}})}}),children:[a.isPending?e.jsx(L,{className:"mr-1.5"}):null,a.isPending?"Removing...":"Confirm remove"]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:a.isPending,onClick:()=>g(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(y,{size:"sm",onClick:B,disabled:f.isPending,children:[f.isPending?e.jsx(L,{className:"mr-1.5"}):null,f.isPending?"Saving...":"Save"]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>{k(i.label?.trim()??""),x(!1)},children:"Cancel"}),e.jsxs(y,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:f.isPending||a.isPending,onClick:()=>g(!0),children:[e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[C(i),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{g(!1),k(i.label?.trim()??""),x(!0)},children:e.jsx(Se,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${i.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),i.online?i.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:ee||void 0,caption:`Last seen ${q(new Date(i.last_seen_at),{addSuffix:!0})}${i.last_sync_at?` · Last sync ${q(new Date(i.last_sync_at),{addSuffix:!0})}`:""}`}),children:[e.jsx(Ke,{device:i,ownerSlug:s}),i.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(ke,{className:"h-3.5 w-3.5 shrink-0"}),i.connector_error_count," connector",i.connector_error_count===1?"":"s"," pinned to this device ",i.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(W,{device:i,organizationId:o,ownerSlug:s,selectedConnection:h,openSettings:m}),S.length>0?e.jsx(z,{title:"Browser auth profiles",children:e.jsx(He,{profiles:S})}):null,e.jsx(z,{title:"Runs",children:e.jsx(Ee,{scope:{deviceId:c},ownerSlug:s})})]})})}function He({profiles:s}){return s.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:s.map(n=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:n.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:n.connector_key??"Any connector"}),n.browser_kind?e.jsxs("span",{children:["· ",n.browser_kind]}):null,n.captured_at?e.jsxs("span",{title:n.captured_at,children:["· captured ",De(n.captured_at)]}):null,typeof n.cookie_count=="number"?e.jsxs("span",{children:["· ",n.cookie_count," cookie",n.cookie_count===1?"":"s"]}):null]})]}),e.jsx(Ie,{status:n.is_expired?"error":Ae(n.status),showDot:!0,children:n.is_expired?"expired":n.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},n.id))})})}function cs(){const{owner:s,deviceId:n}=K.useParams(),{connection:o,settings:h}=K.useSearch();return e.jsx(Pe,{owner:s,children:({ownerSlug:m,organizationId:r})=>e.jsx(We,{ownerSlug:m,deviceId:n,organizationId:r,selectedConnection:o,openSettings:h})})}export{cs as component};
|
|
2
|
-
//# sourceMappingURL=device._deviceId-
|
|
1
|
+
import{aD as F,j4 as ne,j5 as U,r as v,j as e,j6 as P,B as y,al as L,j7 as C,cK as V,aU as te,i8 as z,m as Y,bj as M,hg as ae,hh as ie,C as ce,hj as oe,cx as re,j8 as le,ad as de,c as me,aZ as ue,j9 as xe,ja as he,jb as pe,a_ as fe,aV as je,au as A,bi as T,L as I,jc as ge,jd as ve,ba as be,je as ye,jf as Ne,a8 as ke,dr as _e,i$ as q,$ as we,c9 as Ce,dE as Se,ds as $e,dt as K,ev as De,jg as O,aS as Pe}from"./index-DByaMzsG.js";import{C as Le}from"./connector-page-shell-BFv21yuv.js";import{D as ze,R as Ee}from"./detail-page-skeleton-C8v3rJXK.js";import{S as Ae,g as Ie}from"./status-variants-DyRCXBzM.js";import{c as G,C as Re}from"./device-pin-tombstone-Bcpe7nAA.js";import{w as R}from"./workspace-label-o_QfBuCM.js";import"./list-skeleton-DsYGUHxi.js";import"./runs-C8sZQr4o.js";import"./filter-editors-CQoSj-20.js";import"./subDays-D8nHthaS.js";import"./runs-list-CwtH-wmk.js";import"./run-initiator-DhE5v4z0.js";import"./use-automations-CgWNoYio.js";import"./clients-xnzZeEdZ.js";function Me(s,n,o){const h=new Set(s.capabilities??[]),m=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key)),r=new Set(Z(s,o).map(t=>t.connector_key));return n.filter(t=>F(t)&&!!t.required_capability&&h.has(t.required_capability)&&!m.has(t.key)&&!r.has(t.key))}function Z(s,n){return s.organization_slug===n?s.update_required:[]}function Be(s,n,o){const h=s.organization_slug;if(!h||h===o)return[];const m=new Set(n.map(t=>t.key)),r=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key));return s.connectors.filter(t=>t.organization_slug!==h||m.has(t.connector_key)||r.has(t.connector_key)?!1:(r.add(t.connector_key),!0))}function Te({device:s,organizationId:n,ownerSlug:o,connectable:h,unavailable:m}){const r=ne(),t=U(),[u,p]=v.useState(null),[j,a]=v.useState(null),[f,N]=v.useState(null),[g,d]=v.useState([]),x=s.organization_id===n,b=async i=>{p(null),N(null),a(i.key);try{x||await t.mutateAsync({deviceWorkerId:s.id,organizationId:n});const w=await r.mutateAsync({connector_key:i.key,device_worker_id:s.id}),S=w.connection_id??w.connection?.id;if(S===void 0)throw new Error(w.instructions??"The connection was not created.");d($=>[...$.filter(D=>D.connectorKey!==i.key),{connectorKey:i.key,name:i.name,connectionId:S,instructions:w.status==="setup_required"?w.instructions:void 0}])}catch(w){N({key:i.key,message:w instanceof Error?w.message:"Could not connect."})}finally{a(null)}},k=new Set(g.map(i=>i.connectorKey)),l=Z(s,o),c=h.filter(i=>!k.has(i.key));return e.jsxs("div",{className:"mt-4 space-y-3",children:[g.map(i=>e.jsx(qe,{outcome:i,device:s,organizationId:n},i.connectorKey)),c.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Supported by this device"}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Not connected in this workspace yet.",x?null:" Connecting one moves the device here; you will be asked to confirm first."]}),e.jsx("div",{className:"divide-y border-y",children:c.map(i=>e.jsxs("div",{className:"space-y-2 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-sm font-medium",children:[i.name,i.required_capability&&P[i.required_capability]&&P[i.required_capability]!==i.name?e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:P[i.required_capability]}):null]}),e.jsxs(y,{size:"sm",variant:"outline","aria-label":`Connect ${i.name}`,disabled:j!==null,onClick:()=>x?void b(i):p(i.key),children:[j===i.key?e.jsx(L,{className:"mr-1.5"}):null,"Connect"]})]}),u===i.key?e.jsx(J,{device:s,ownerSlug:o,title:"Move device to this workspace",intro:`${C(s)} lives in ${s.organization_name??"another workspace"}. A device serves one workspace at a time, so it has to move here before it can be connected.`,confirmLabel:"Move here and connect",onConfirm:()=>void b(i),onCancel:()=>p(null)}):null,f?.key===i.key?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.message}):null]},i.key))})]}):null,l.length>0?e.jsxs("div",{role:"status",children:[e.jsx("p",{className:"text-xs font-medium",children:"Update Lobu on this device"}),e.jsx("ul",{className:"mt-1 space-y-1 text-xs text-muted-foreground",children:l.map(i=>e.jsx("li",{children:`${i.display_name} — this device has ${i.device_version}, this workspace uses ${i.workspace_version}`},i.connector_key))})]}):null,m.length>0?e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:m.map(i=>e.jsx("li",{children:`${i.display_name} — set up on this device in ${s.organization_name??"its home workspace"}, not available in this workspace yet`},i.connector_key))}):null]})}function J({device:s,ownerSlug:n,title:o,intro:h,aftermath:m,confirmLabel:r,pending:t=!1,onConfirm:u,onCancel:p}){const j=s.connector_count,a=s.connectors.filter(f=>f.organization_slug===n).length;return e.jsxs("div",{role:"alertdialog","aria-label":o,className:"space-y-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs",children:[e.jsx("p",{children:h}),e.jsxs("p",{className:"text-muted-foreground",children:[j>0?`Moving pauses and unpins all ${j} connection${j===1?"":"s"} pinned to it${a>0?`, including ${a} in this workspace`:""}. They stay paused until you reconnect them.`:"It has no pinned connections, so nothing is paused.",m?` ${m}`:null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",disabled:t,onClick:u,children:[t?e.jsx(L,{className:"mr-1.5"}):null,r]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:t,onClick:p,children:"Cancel"})]})]})}function qe({outcome:s,device:n,organizationId:o}){const{data:h=[],isLoading:m}=V(o,{connectionIds:[s.connectionId]}),r=h.find(p=>p.id===s.connectionId),t=C(n);if(m)return e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Checking ",s.name,"…"]});const u=[];if(!r)u.push(`${s.name} was created but could not be loaded yet.`);else if(r.status!=="active"){const p=G(r);u.push(`${s.name} is ${r.status}${p?`: ${p}`:"."}`)}return s.instructions&&u.push(s.instructions),n.online||u.push(`${t} is offline. ${s.name} runs once it reconnects.`),e.jsx("div",{role:"status",className:"rounded-lg border px-3 py-2 text-sm",children:u.length===0?e.jsxs("p",{children:[s.name," is ready on ",t,"."]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium",children:[s.name," connected, not ready yet"]}),e.jsx("ul",{className:"mt-1 list-disc pl-4 text-xs text-muted-foreground",children:u.map(p=>e.jsx("li",{children:p},p))})]})})}function H({device:s,organizationId:n,ownerSlug:o,selectedConnection:h,openSettings:m}){const{data:r=[],isLoading:t,isError:u,refetch:p}=te(n),j=new Map(r.map(d=>[d.key,d])),a=new Map,f=[];for(const d of s.connectors){if(d.organization_slug!==o)continue;const x=j.get(d.connector_key);if(!x||!F(x)){f.push(d);continue}const b=x.required_capability??`connector:${x.key}`,k=a.get(b)??{key:b,name:x.name,connections:[]};k.name=P[b]??x.name,k.connections.push(d),a.set(b,k)}const N=Me(s,r,o),g=Be(s,r,o);return e.jsxs(e.Fragment,{children:[e.jsxs(z,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),s.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!n||t?e.jsx(Y,{className:"h-24 w-full"}):u?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void p(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(d=>e.jsx(W,{group:d,deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:j,selectedConnection:h,openSettings:m},d.key))}),n&&!t&&!u?e.jsx(Te,{device:s,organizationId:n,ownerSlug:o,connectable:N,unavailable:g}):null,M(s)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),n&&f.length>0&&!t&&!u?e.jsxs(z,{title:"Apps and sources",count:String(f.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:[...new Set(f.map(d=>d.connector_key))].map(d=>e.jsx(W,{group:{key:d,name:j.get(d)?.name??d,connections:f.filter(x=>x.connector_key===d)},deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:j,selectedConnection:h,openSettings:m},d))})]}):null]})}function W({group:s,deviceId:n,organizationId:o,ownerSlug:h,definitionsByKey:m,selectedConnection:r,openSettings:t}){const u=s.connections.some(a=>a.connection_id===r),[p,j]=v.useState(u);return v.useEffect(()=>{u&&r!==void 0&&j(!0)},[u,r]),e.jsxs(ae,{open:p,onOpenChange:j,children:[e.jsxs(ie,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(ce,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:s.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:s.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":s.connections.length>1?`${s.connections.length} connections`:"Configured"})]}),e.jsx(oe,{className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:s.connections.map(a=>e.jsx(Ke,{summary:a,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m.get(a.connector_key),openSettings:a.connection_id===r&&t},a.connection_id))})})]})}function Ke({summary:s,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m,openSettings:r}){const{data:t=[],isLoading:u,isError:p,refetch:j}=V(o,{connectionIds:[s.connection_id]}),a=t.find(g=>g.id===s.connection_id&&g.device_worker_id===n),f=m?.name??s.connector_key,N=a?G(a):null;return e.jsxs("section",{id:`connection-${s.connection_id}`,"aria-label":f,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:re(a)}),e.jsx("span",{children:a.status})]}):null,u||!o?e.jsx(Y,{className:"h-24 w-full"}):p?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void j(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[N?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:N}):null,e.jsx("div",{className:"mb-4",children:e.jsx(le,{connection:a})}),e.jsx(Re,{connection:a,connectorDef:m,ownerSlug:h,openSettings:r,showActivity:!1,showShare:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function Oe({device:s,ownerSlug:n}){const o=v.useId(),{data:h=[]}=de(),m=U(),[r,t]=v.useState(!1),[u,p]=v.useState(null),[j,a]=v.useState(null),f=h.filter(l=>l.is_member).map(l=>({id:l.id,name:l.name,isPersonal:l.is_personal===!0})),N=f.find(l=>l.id===s.organization_id),g=N?R(N):s.organization_name??"No workspace",d=f.filter(l=>l.id!==s.organization_id),x=d.find(l=>l.id===u)??null,b=()=>{t(!1),p(null)},k=async l=>{a(null);try{await m.mutateAsync({deviceWorkerId:s.id,organizationId:l}),b()}catch(c){a(c instanceof Error?c.message:"Could not move the device.")}};return e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace: "}),g]}),!r&&d.length>0?e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{a(null),t(!0)},children:"Change workspace"}):null]}),r?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:o,className:"text-xs text-muted-foreground",children:"Move to"}),e.jsxs("select",{id:o,value:u??"",disabled:m.isPending,onChange:l=>p(l.target.value||null),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Choose a workspace"}),d.map(l=>e.jsx("option",{value:l.id,children:R(l)},l.id))]}),x?null:e.jsx(y,{size:"sm",variant:"ghost",onClick:b,children:"Cancel"})]}):null,x?e.jsx(J,{device:s,ownerSlug:n,title:`Move device to ${x.name}`,intro:`Move ${C(s)} from ${g} to ${R(x)}?`,aftermath:`It is set up fresh in ${x.name}, with its connections there private to you until you share them.`,confirmLabel:"Move device",pending:m.isPending,onConfirm:()=>void k(x.id),onCancel:b}):null,j?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:j}):null]})}function He({ownerSlug:s,deviceId:n,organizationId:o,selectedConnection:h,openSettings:m}){const r=me(),{data:t=[],isLoading:u,isError:p,refetch:j}=ue(),a=xe(),f=he(),[N,g]=v.useState(!1),[d,x]=v.useState(!1),[b,k]=v.useState(""),l=pe(t,n),c=l&&fe(l,s)?l:void 0,i=c?.id??n,{data:w=[]}=je(o,{profileKind:"browser_session"}),S=v.useMemo(()=>w.filter(_=>_.device_worker_id===i&&_.status!=="revoked"),[w,i]),$=c?.label?.trim()??"";if(v.useEffect(()=>{d||k($)},[$,d]),u)return e.jsx(ze,{label:"Loading device"});if(p)return e.jsx(A,{children:e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{children:"Could not load this device."}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>void j(),children:"Retry"})]})});if(!c&&l&&o)return e.jsxs(A,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{platform:M(l),className:"h-5 w-5"}),e.jsx("h1",{className:"text-base font-semibold",children:C(l)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device lives in"," ",l.organization_name??"another workspace",", not this workspace."]}),e.jsx(H,{device:l,organizationId:o,ownerSlug:s})]});if(!c)return e.jsxs(A,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(I,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const D=ge(c),E=D?ve(s,D,be()):void 0,Q=M(c),X=ye(c.app_version),ee=Ne(c,X),B=()=>{const _=b.trim(),se=c.label?.trim()??"";if(_===se){x(!1);return}f.mutate({deviceWorkerId:c.id,label:_.length===0?null:_},{onSuccess:()=>x(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(Le,{header:e.jsx(_e,{breadcrumb:e.jsx($e,{crumbs:[e.jsx(I,{to:"/$owner/connectors",params:{owner:s},search:{},className:K,children:"Connectors"},"connectors"),...E?[e.jsx(I,{to:"/$owner/connectors/app/$appId",params:{owner:s,appId:E.id},className:K,children:E.name},"app")]:[]]}),icon:e.jsx(T,{platform:Q,className:"h-5 w-5"}),title:d?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(we,{"aria-label":"Device name",value:b,onChange:_=>k(_.target.value),placeholder:C({...c,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:_=>{_.key==="Enter"?(_.preventDefault(),N||B()):_.key==="Escape"&&(g(!1),k(c.label?.trim()??""),x(!1))}}),N?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",c.connector_count>0?`and un-pins ${c.connector_count} connector${c.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(y,{variant:"destructive",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(c.id,{onSuccess:()=>{g(!1),r({to:"/$owner/connectors",params:{owner:s},search:{}})}}),children:[a.isPending?e.jsx(L,{className:"mr-1.5"}):null,a.isPending?"Removing...":"Confirm remove"]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:a.isPending,onClick:()=>g(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(y,{size:"sm",onClick:B,disabled:f.isPending,children:[f.isPending?e.jsx(L,{className:"mr-1.5"}):null,f.isPending?"Saving...":"Save"]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>{k(c.label?.trim()??""),x(!1)},children:"Cancel"}),e.jsxs(y,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:f.isPending||a.isPending,onClick:()=>g(!0),children:[e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[C(c),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{g(!1),k(c.label?.trim()??""),x(!0)},children:e.jsx(Se,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${c.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),c.online?c.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:ee||void 0,caption:`Last seen ${q(new Date(c.last_seen_at),{addSuffix:!0})}${c.last_sync_at?` · Last sync ${q(new Date(c.last_sync_at),{addSuffix:!0})}`:""}`}),children:[e.jsx(Oe,{device:c,ownerSlug:s}),c.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(ke,{className:"h-3.5 w-3.5 shrink-0"}),c.connector_error_count," connector",c.connector_error_count===1?"":"s"," pinned to this device ",c.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(H,{device:c,organizationId:o,ownerSlug:s,selectedConnection:h,openSettings:m}),S.length>0?e.jsx(z,{title:"Browser auth profiles",children:e.jsx(We,{profiles:S})}):null,e.jsx(z,{title:"Runs",children:e.jsx(Ee,{scope:{deviceId:i},ownerSlug:s})})]})})}function We({profiles:s}){return s.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:s.map(n=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:n.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:n.connector_key??"Any connector"}),n.browser_kind?e.jsxs("span",{children:["· ",n.browser_kind]}):null,n.captured_at?e.jsxs("span",{title:n.captured_at,children:["· captured ",De(n.captured_at)]}):null,typeof n.cookie_count=="number"?e.jsxs("span",{children:["· ",n.cookie_count," cookie",n.cookie_count===1?"":"s"]}):null]})]}),e.jsx(Ae,{status:n.is_expired?"error":Ie(n.status),showDot:!0,children:n.is_expired?"expired":n.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},n.id))})})}function is(){const{owner:s,deviceId:n}=O.useParams(),{connection:o,settings:h}=O.useSearch();return e.jsx(Pe,{owner:s,children:({ownerSlug:m,organizationId:r})=>e.jsx(He,{ownerSlug:m,deviceId:n,organizationId:r,selectedConnection:o,openSettings:h})})}export{is as component};
|
|
2
|
+
//# sourceMappingURL=device._deviceId-DLT4jh0Z.js.map
|
package/dist/owletto/dist/assets/{dynamic-schema-form-OkIZImgp.js → dynamic-schema-form-BDT8x0Vg.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e,fI as M,T as _,a6 as ae,br as ie,bs as re,bt as ne,bu as le,bv as ce,f_ as me,gM as de,gN as I,gO as p,gP as oe,gQ as R,gR as ue,B as O,cc as H,cU as G,U as J,dW as xe,fK as be,gS as je,aP as Q,gT as fe,a4 as ye,i as q,gU as he,r as Z,aF as Ne,aG as ge,gV as we,aI as Se,eA as $e,e9 as k}from"./index-CdDNNAx2.js";import{d as E,h as ve,F as Oe,i as z,j as Te}from"./renderer-DZ0w2k2r.js";import{T as Be,a as De,b as C,c as W,d as Ie,e as P}from"./table-C3DMoL4K.js";import{p as K,a as Ae}from"./schema-value-k19Ata7u.js";function ee(l){return l.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ee(l,r=!1){return l?Ae(l,r):r?"Pick a date and time":"Pick a date"}function V(l){if(!l)return"";const r=K(l);if(Number.isNaN(r.getTime()))return"";const s=r.getTimezoneOffset()*6e4;return new Date(r.getTime()-s).toISOString().slice(0,16)}function X(l){if(!l)return;const r=new Date(l);if(!Number.isNaN(r.getTime()))return r.toISOString()}function A(l,r){const s=r==="slug"?l.slug:l.metadata?.[r];return s==null?"":String(s)}function Y({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,includeTime:N=!1,clearable:j}){const m=r?K(r):void 0,[d,u]=Z.useState(()=>V(r).slice(11));return Z.useEffect(()=>{u(V(r).slice(11))},[r]),e.jsx("div",{className:"relative",children:e.jsxs(Ne,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",disabled:a,className:q("w-full justify-start rounded-md bg-muted px-3 text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(we,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:Ee(r,N)})]})}),e.jsxs(Se,{className:"w-auto space-y-3 p-0",align:"start",children:[e.jsx($e,{mode:"single",selected:m,defaultMonth:m,onSelect:i=>{if(!i)return;if(!N){s(k(i,"yyyy-MM-dd"));return}const t=d||"00:00";s(X(`${k(i,"yyyy-MM-dd")}T${t}`))},initialFocus:!0}),N?e.jsxs("div",{className:"border-t p-3 pt-0",children:[e.jsx(_,{htmlFor:`${l}-time`,className:"text-xs text-muted-foreground",children:"Time"}),e.jsx(J,{id:`${l}-time`,type:"time",value:d,onChange:i=>{u(i.target.value);const t=r?V(r).slice(0,10):m?k(m,"yyyy-MM-dd"):"";t&&s(X(`${t}T${i.target.value}`))},disabled:a})]}):null,j&&r?e.jsx("div",{className:"border-t p-2",children:e.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:()=>s(void 0),children:"Clear"})}):null]})]})})}function Fe({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,entityType:N,lookupField:j,numeric:m=!1,orgContext:d}){const u=o=>{if(o===void 0||o==="")return s(void 0);if(!m)return s(o);const x=Number(o);s(Number.isFinite(x)?x:o)},{data:i}=xe(N,d,{limit:be}),t=(i?.entities??[]).filter(o=>A(o,j)!==""),S=r==null?"":String(r),v=t.find(o=>A(o,j)===S);return d?a?e.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm",children:v?.name||S||"-"}):e.jsx(je,{contentClassName:"w-[320px]",searchPlaceholder:`Search ${z(N).toLowerCase()}...`,emptyText:`No ${N} found.`,trigger:o=>e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsx("span",{className:q("truncate",!S&&"text-muted-foreground"),children:v?.name||S||`Select ${z(N).toLowerCase()}`}),e.jsx(he,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,x)=>{const n=x.trim(),f=n.length>0&&!t.some(y=>A(y,j)===n);return e.jsxs(e.Fragment,{children:[f?e.jsxs(Q,{value:`use ${n}`,onSelect:()=>{u(n),o()},children:[e.jsx(fe,{className:"mr-2 h-3.5 w-3.5 opacity-60"}),e.jsxs("span",{className:"truncate",children:["Use ",e.jsx("span",{className:"font-medium",children:n})]})]}):null,t.map(y=>{const h=A(y,j),T=h===S;return e.jsxs(Q,{value:`${y.name} ${y.slug} ${y.entity_type} ${h}`,onSelect:()=>{u(h||void 0),o()},children:[e.jsx(ye,{className:q("mr-2 h-4 w-4",T?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:y.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.slug})]})]},`${y.id}-${h}`)})]})}}):e.jsx(J,{id:l,"aria-label":c,"aria-describedby":w,type:m?"number":"text",value:S,onChange:o=>u(o.target.value||void 0),disabled:a})}function se({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:j,ariaLabel:m,helpId:d}){const u=E(r,s),i=ee(l),t=N||s.readOnly===!0,S=s.type==="object"||!!s.properties,v=s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties),o=s.type==="array"&&!!s.items&&(s.items?.type==="string"||s.items?.type==="number"||s.items?.type==="integer"||s.items?.type==="boolean");if(s.type==="boolean")return e.jsx(ae,{id:i,"aria-label":m,"aria-describedby":d,checked:a??!1,onCheckedChange:n=>c(n),disabled:t});let x;if(s.enum&&Array.isArray(s.enum))x=e.jsxs(ie,{value:a==null?"":String(a),onValueChange:n=>c(n===""?void 0:s.type==="number"||s.type==="integer"?Number(n):n),disabled:t,children:[e.jsx(re,{id:i,"aria-label":m,"aria-describedby":d,children:e.jsx(ne,{placeholder:`Select ${u.toLowerCase()}`})}),e.jsx(le,{children:s.enum.map(n=>{const f=String(n);return e.jsx(ce,{value:f,children:me(s,n)??z(f)},f)})})]});else if(s["x-link-entity-type"])x=e.jsx(Fe,{id:i,value:a,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,entityType:s["x-link-entity-type"],lookupField:s["x-link-lookup-field"]||"slug",numeric:s.type==="number"||s.type==="integer",orgContext:j});else if(s.type==="number"||s.type==="integer")x=e.jsx(de,{id:i,ariaLabel:m,ariaDescribedBy:d,value:a,onChange:c,integer:s.type==="integer",placeholder:`Enter ${u.toLowerCase()}`,readOnly:t});else if(S){const n=M(s.properties),f=new Set(s.required??[]),y=I(a)?a:{};x=Object.keys(s.properties??{}).length===0||!I(a)&&a!==void 0&&a!==null?e.jsx(p,{id:i,value:a,ariaLabel:`${u} JSON object`,ariaDescribedBy:d,readOnly:t,onChange:c}):e.jsx("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3 rounded-md border p-3",children:n.map(([h,T])=>e.jsx(te,{fieldPath:`${l}.${h}`,fieldKey:h,prop:T,value:y[h],onChange:$=>{const b={...y};$===void 0?delete b[h]:b[h]=$,c(b)},isRequired:f.has(h),readonly:t,orgContext:j},h))})}else if(o)x=a!=null&&!oe(a)?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c}):e.jsx(ue,{id:i,value:a,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,ariaLabel:m,ariaDescribedBy:d,readOnly:t,showHelp:!m,onChange:c});else if(v&&s.items){const n=Array.isArray(a)?a:[],f=M(s.items.properties),y=new Set(s.items.required??[]),h=s.maxItems===void 0||n.length<s.maxItems,T=s.minItems===void 0||n.length>s.minItems;x=!Array.isArray(a)&&a!==void 0&&a!==null||Object.keys(s.items.properties??{}).length>0&&n.some($=>!I($))?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:"object",minItems:s.minItems,maxItems:s.maxItems,onChange:c}):Object.keys(s.items.properties??{}).length===0?e.jsxs("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3",children:[n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No rows"}):n.map(($,b)=>e.jsxs("fieldset",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("legend",{className:"px-1 text-xs font-medium text-muted-foreground",children:["Row ",b+1]}),e.jsx(p,{id:`${i}-${b}-json`,value:$,ariaLabel:`${u} row ${b+1} JSON object`,readOnly:t,onChange:B=>{const g=[...n];g[b]=B,c(g)}}),t?null:e.jsxs(O,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((B,g)=>g!==b)),children:[e.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Remove row"]})]},`${l}.${b}`)),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]}):e.jsxs("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Be,{children:[e.jsx(De,{children:e.jsxs(C,{children:[f.map(([$,b])=>e.jsxs(W,{children:[E($,b),y.has($)?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]},$)),t?null:e.jsx(W,{className:"w-12"})]})}),e.jsx(Ie,{children:n.length===0?e.jsx(C,{children:e.jsx(P,{colSpan:f.length+(t?0:1),className:"text-sm text-muted-foreground",children:"No rows"})}):n.map(($,b)=>{const B=I($)?$:{};return e.jsxs(C,{children:[f.map(([g,D])=>e.jsx(P,{className:"align-top",children:e.jsx(se,{fieldPath:`${l}.${b}.${g}`,fieldKey:g,prop:D,ariaLabel:E(g,D),value:B[g],onChange:L=>{const U=[...n],F={...B};L===void 0?delete F[g]:F[g]=L,U[b]=F,c(U)},isRequired:y.has(g),readonly:t,orgContext:j})},g)),t?null:e.jsx(P,{className:"align-top",children:e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((g,D)=>D!==b)),children:e.jsx(H,{className:"h-4 w-4"})})})]},`${l}.${b}`)})})]})}),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]})}else if(s.type==="array")x=e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c});else if(s.format==="date")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,clearable:!w});else if(s.format==="date-time")x=e.jsx(Y,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,includeTime:!0,clearable:!w});else{const n=s.format==="uri"||s.format==="url";x=e.jsx(J,{id:i,"aria-label":m,"aria-describedby":d,type:n?"url":"text",value:a??"",onChange:f=>c(f.target.value||void 0),placeholder:n?"https://example.com":`Enter ${u.toLowerCase()}`,disabled:t})}return x}function te({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,control:j,orgContext:m,customControl:d}){const u=E(r,s),i=ve(s),t=ee(l),S=i?`${t}-description`:void 0,v=i?e.jsx("p",{id:S,className:"text-xs text-muted-foreground",children:i}):null,o=j?e.jsx(Oe,{control:j}):null,x=d??e.jsx(se,{fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:m,helpId:S});if(s.type==="boolean"){const f=e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[x,e.jsxs(_,{htmlFor:t,className:"flex items-center gap-1.5 font-normal",children:[u,o]})]});return v?e.jsxs("div",{className:"space-y-1",children:[f,v]}):f}const n=s.type==="object"||!!s.properties||s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties);return e.jsxs("div",{className:"space-y-1.5",children:[n?e.jsxs("p",{id:`${t}-label`,className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}):e.jsxs(_,{htmlFor:t,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}),x,v]})}function Ve(l){const r={};for(const[s,a]of Object.entries(l)){const c=Te(a);c!==void 0&&(r[s]=c)}return r}function Me({schema:l,values:r,onValuesChange:s,readonly:a=!1,fieldControls:c,orgContext:w,renderControl:N}){const j=l,m=j?.properties,d=new Set(j?.required??[]),u=(i,t)=>{s({...r,[i]:t})};return!m||Object.keys(m).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:M(m).map(([i,t])=>"x-measure"in t||"x-dimension"in t?null:e.jsx(te,{fieldPath:i,fieldKey:i,prop:t,value:r[i],onChange:S=>u(i,S),isRequired:d.has(i),readonly:a,control:c?.[i],orgContext:w,customControl:N?.(i,t,r[i])},i))})}export{Me as D,se as S,Ve as c};
|
|
2
|
-
//# sourceMappingURL=dynamic-schema-form-
|
|
1
|
+
import{j as e,fG as V,Z as q,ab as ae,bq as ie,br as re,bs as ne,bt as le,bu as ce,fY as me,gI as de,gJ as E,gK as H,gL as oe,gM as R,gN as ue,B as O,c9 as U,dg as G,$ as z,dU as xe,fI as be,gO as je,aO as Q,gP as fe,a9 as ye,i as J,gQ as he,r as Z,aE as Ne,aF as ge,gR as we,aH as $e,ey as Se,e7 as k}from"./index-DByaMzsG.js";import{h as A,i as ve,F as Oe,j as L,k as Te}from"./renderer-olRv_HMI.js";import{T as Be,a as De,b as C,c as X,d as Ee,e as P}from"./table-C637cQxG.js";import{p as K,a as Ie}from"./schema-value-zTJGE4eh.js";function ee(l){return l.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ae(l,r=!1){return l?Ie(l,r):r?"Pick a date and time":"Pick a date"}function M(l){if(!l)return"";const r=K(l);if(Number.isNaN(r.getTime()))return"";const s=r.getTimezoneOffset()*6e4;return new Date(r.getTime()-s).toISOString().slice(0,16)}function Y(l){if(!l)return;const r=new Date(l);if(!Number.isNaN(r.getTime()))return r.toISOString()}function I(l,r){const s=r==="slug"?l.slug:l.metadata?.[r];return s==null?"":String(s)}function W({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,includeTime:N=!1,clearable:j}){const m=r?K(r):void 0,[d,u]=Z.useState(()=>M(r).slice(11));return Z.useEffect(()=>{u(M(r).slice(11))},[r]),e.jsx("div",{className:"relative",children:e.jsxs(Ne,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",disabled:a,className:J("w-full justify-start rounded-md bg-muted px-3 text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(we,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:Ae(r,N)})]})}),e.jsxs($e,{className:"w-auto space-y-3 p-0",align:"start",children:[e.jsx(Se,{mode:"single",selected:m,defaultMonth:m,onSelect:i=>{if(!i)return;if(!N){s(k(i,"yyyy-MM-dd"));return}const t=d||"00:00";s(Y(`${k(i,"yyyy-MM-dd")}T${t}`))},initialFocus:!0}),N?e.jsxs("div",{className:"border-t p-3 pt-0",children:[e.jsx(q,{htmlFor:`${l}-time`,className:"text-xs text-muted-foreground",children:"Time"}),e.jsx(z,{id:`${l}-time`,type:"time",value:d,onChange:i=>{u(i.target.value);const t=r?M(r).slice(0,10):m?k(m,"yyyy-MM-dd"):"";t&&s(Y(`${t}T${i.target.value}`))},disabled:a})]}):null,j&&r?e.jsx("div",{className:"border-t p-2",children:e.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:()=>s(void 0),children:"Clear"})}):null]})]})})}function Fe({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,entityType:N,lookupField:j,numeric:m=!1,orgContext:d}){const u=o=>{if(o===void 0||o==="")return s(void 0);if(!m)return s(o);const x=Number(o);s(Number.isFinite(x)?x:o)},{data:i}=xe(N,d,{limit:be}),t=(i?.entities??[]).filter(o=>I(o,j)!==""),$=r==null?"":String(r),v=t.find(o=>I(o,j)===$);return d?a?e.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm",children:v?.name||$||"-"}):e.jsx(je,{contentClassName:"w-[320px]",searchPlaceholder:`Search ${L(N).toLowerCase()}...`,emptyText:`No ${N} found.`,trigger:o=>e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsx("span",{className:J("truncate",!$&&"text-muted-foreground"),children:v?.name||$||`Select ${L(N).toLowerCase()}`}),e.jsx(he,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,x)=>{const n=x.trim(),f=n.length>0&&!t.some(y=>I(y,j)===n);return e.jsxs(e.Fragment,{children:[f?e.jsxs(Q,{value:`use ${n}`,onSelect:()=>{u(n),o()},children:[e.jsx(fe,{className:"mr-2 h-3.5 w-3.5 opacity-60"}),e.jsxs("span",{className:"truncate",children:["Use ",e.jsx("span",{className:"font-medium",children:n})]})]}):null,t.map(y=>{const h=I(y,j),T=h===$;return e.jsxs(Q,{value:`${y.name} ${y.slug} ${y.entity_type} ${h}`,onSelect:()=>{u(h||void 0),o()},children:[e.jsx(ye,{className:J("mr-2 h-4 w-4",T?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:y.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.slug})]})]},`${y.id}-${h}`)})]})}}):e.jsx(z,{id:l,"aria-label":c,"aria-describedby":w,type:m?"number":"text",value:$,onChange:o=>u(o.target.value||void 0),disabled:a})}function se({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:j,ariaLabel:m,helpId:d}){const u=A(r,s),i=ee(l),t=N||s.readOnly===!0,$=s.type==="object"||!!s.properties,v=s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties),o=s.type==="array"&&!!s.items&&(s.items?.type==="string"||s.items?.type==="number"||s.items?.type==="integer"||s.items?.type==="boolean");if(s.type==="boolean")return e.jsx(ae,{id:i,"aria-label":m,"aria-describedby":d,checked:a??!1,onCheckedChange:n=>c(n),disabled:t});let x;if(s.enum&&Array.isArray(s.enum))x=e.jsxs(ie,{value:a==null?"":String(a),onValueChange:n=>c(n===""?void 0:s.type==="number"||s.type==="integer"?Number(n):n),disabled:t,children:[e.jsx(re,{id:i,"aria-label":m,"aria-describedby":d,children:e.jsx(ne,{placeholder:`Select ${u.toLowerCase()}`})}),e.jsx(le,{children:s.enum.map(n=>{const f=String(n);return e.jsx(ce,{value:f,children:me(s,n)??L(f)},f)})})]});else if(s["x-link-entity-type"])x=e.jsx(Fe,{id:i,value:a,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,entityType:s["x-link-entity-type"],lookupField:s["x-link-lookup-field"]||"slug",numeric:s.type==="number"||s.type==="integer",orgContext:j});else if(s.type==="number"||s.type==="integer")x=e.jsx(de,{id:i,ariaLabel:m,ariaDescribedBy:d,value:a,onChange:c,integer:s.type==="integer",placeholder:`Enter ${u.toLowerCase()}`,readOnly:t});else if($){const n=V(s.properties),f=new Set(s.required??[]),y=E(a)?a:{};x=Object.keys(s.properties??{}).length===0||!E(a)&&a!==void 0&&a!==null?e.jsx(H,{id:i,value:a,ariaLabel:`${u} JSON object`,ariaDescribedBy:d,readOnly:t,onChange:c}):e.jsx("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3 rounded-md border p-3",children:n.map(([h,T])=>e.jsx(te,{fieldPath:`${l}.${h}`,fieldKey:h,prop:T,value:y[h],onChange:S=>{const b={...y};S===void 0?delete b[h]:b[h]=S,c(b)},isRequired:f.has(h),readonly:t,orgContext:j},h))})}else if(o)x=a!=null&&!oe(a)?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c}):e.jsx(ue,{id:i,value:a,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,ariaLabel:m,ariaDescribedBy:d,readOnly:t,showHelp:!m,onChange:c});else if(v&&s.items){const n=Array.isArray(a)?a:[],f=V(s.items.properties),y=new Set(s.items.required??[]),h=s.maxItems===void 0||n.length<s.maxItems,T=s.minItems===void 0||n.length>s.minItems;x=!Array.isArray(a)&&a!==void 0&&a!==null||Object.keys(s.items.properties??{}).length>0&&n.some(S=>!E(S))?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:"object",minItems:s.minItems,maxItems:s.maxItems,onChange:c}):Object.keys(s.items.properties??{}).length===0?e.jsxs("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3",children:[n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No rows"}):n.map((S,b)=>e.jsxs("fieldset",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("legend",{className:"px-1 text-xs font-medium text-muted-foreground",children:["Row ",b+1]}),e.jsx(H,{id:`${i}-${b}-json`,value:S,ariaLabel:`${u} row ${b+1} JSON object`,readOnly:t,onChange:B=>{const g=[...n];g[b]=B,c(g)}}),t?null:e.jsxs(O,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((B,g)=>g!==b)),children:[e.jsx(U,{className:"mr-1.5 h-4 w-4"}),"Remove row"]})]},`${l}.${b}`)),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]}):e.jsxs("fieldset",{"aria-label":m,"aria-labelledby":m?void 0:`${i}-label`,"aria-describedby":d,className:"space-y-3",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Be,{children:[e.jsx(De,{children:e.jsxs(C,{children:[f.map(([S,b])=>e.jsxs(X,{children:[A(S,b),y.has(S)?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]},S)),t?null:e.jsx(X,{className:"w-12"})]})}),e.jsx(Ee,{children:n.length===0?e.jsx(C,{children:e.jsx(P,{colSpan:f.length+(t?0:1),className:"text-sm text-muted-foreground",children:"No rows"})}):n.map((S,b)=>{const B=E(S)?S:{};return e.jsxs(C,{children:[f.map(([g,D])=>e.jsx(P,{className:"align-top",children:e.jsx(se,{fieldPath:`${l}.${b}.${g}`,fieldKey:g,prop:D,ariaLabel:A(g,D),value:B[g],onChange:_=>{const p=[...n],F={...B};_===void 0?delete F[g]:F[g]=_,p[b]=F,c(p)},isRequired:y.has(g),readonly:t,orgContext:j})},g)),t?null:e.jsx(P,{className:"align-top",children:e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((g,D)=>D!==b)),children:e.jsx(U,{className:"h-4 w-4"})})})]},`${l}.${b}`)})})]})}),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]})}else if(s.type==="array")x=e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:d,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c});else if(s.format==="date")x=e.jsx(W,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,clearable:!w});else if(s.format==="date-time")x=e.jsx(W,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:m,ariaDescribedBy:d,includeTime:!0,clearable:!w});else{const n=s.format==="uri"||s.format==="url";x=e.jsx(z,{id:i,"aria-label":m,"aria-describedby":d,type:n?"url":"text",value:a??"",onChange:f=>c(f.target.value||void 0),placeholder:n?"https://example.com":`Enter ${u.toLowerCase()}`,disabled:t})}return x}function te({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,control:j,orgContext:m,customControl:d}){const u=A(r,s),i=ve(s),t=ee(l),$=i?`${t}-description`:void 0,v=i?e.jsx("p",{id:$,className:"text-xs text-muted-foreground",children:i}):null,o=j?e.jsx(Oe,{control:j}):null,x=d??e.jsx(se,{fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:m,helpId:$});if(s.type==="boolean"){const f=e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[x,e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5 font-normal",children:[u,o]})]});return v?e.jsxs("div",{className:"space-y-1",children:[f,v]}):f}const n=s.type==="object"||!!s.properties||s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties);return e.jsxs("div",{className:"space-y-1.5",children:[n?e.jsxs("p",{id:`${t}-label`,className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}):e.jsxs(q,{htmlFor:t,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}),x,v]})}function Me(l){const r={};for(const[s,a]of Object.entries(l)){const c=Te(a);c!==void 0&&(r[s]=c)}return r}function Ve({schema:l,values:r,onValuesChange:s,readonly:a=!1,fieldControls:c,orgContext:w,renderControl:N}){const j=l,m=j?.properties,d=new Set(j?.required??[]),u=(i,t)=>{s({...r,[i]:t})};return!m||Object.keys(m).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:V(m).map(([i,t])=>"x-measure"in t||"x-dimension"in t?null:e.jsx(te,{fieldPath:i,fieldKey:i,prop:t,value:r[i],onChange:$=>u(i,$),isRequired:d.has(i),readonly:a,control:c?.[i],orgContext:w,customControl:N?.(i,t,r[i])},i))})}export{Ve as D,se as S,Me as c};
|
|
2
|
+
//# sourceMappingURL=dynamic-schema-form-BDT8x0Vg.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as
|
|
2
|
-
//# sourceMappingURL=entity-options-
|
|
1
|
+
import{c as j,n as C,j as e,bq as _,br as m,bs as S,bt as b,bu as i,cD as u,cx as w}from"./index-DByaMzsG.js";const h="__connection_picker_create_new__";function k({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:o=!1,ariaLabel:p="Connection"}){const f=j(),l=C().org?.slug,c=a?s.filter(t=>t.connector_key===a):s,x=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(_,{value:r,onValueChange:x,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[o?e.jsxs(e.Fragment,{children:[e.jsx(i,{value:"workspace",children:"Current workspace"}),c.length>0?e.jsx(u,{}):null]}):null,c.map(t=>e.jsx(i,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[c.length>0||o?e.jsx(u,{}):null,e.jsx(i,{value:h,children:"Connect an app…"})]}):null]})]})}function v(s){const r=[];for(const n of s)typeof n.id=="number"&&r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...v(n.children));return r}export{k as C,v as f};
|
|
2
|
+
//# sourceMappingURL=entity-options-B9hm9V87.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{e8 as Re,r as E,c3 as Ee,k8 as w,gh as Fe,eE as se,j as e,B as N,u as J,k1 as De,m as ae,gq as pe,k9 as Ce,V as Le,c as fe,b as Be,c4 as B,n as Pe,w as Ve,eG as Q,cJ as $e,gC as Oe,ka as Te,dE as Me,cg as ne,ci as ie,fX as Ie,gm as Ae,dv as ze,hL as He,hM as Ue,hN as Ke,hO as qe,hP as We,kb as Ge,c8 as Xe,Z as q,$ as oe,f3 as Qe,a8 as Ye,gf as re,fe as W,ds as Je,L as G,dt as X}from"./index-DByaMzsG.js";import{N as Ze,d as et,f as tt,g as st,S as at,h as nt}from"./entity-pages-BWBpttz3.js";import{R as it}from"./record-activity-DnRVOrG2.js";import{D as ot}from"./dynamic-schema-form-BDT8x0Vg.js";import{r as rt,V as lt}from"./views-access-required-C35Dyt91.js";import{a as xe,V as le,M as ct,b as dt}from"./view-param-filters-CUCj9Df-.js";import{o as ut,k as Y,h as mt,q as ce,c as ge,R as ve,r as ht,d as pt}from"./renderer-olRv_HMI.js";import"./table-C637cQxG.js";import{a as ft}from"./source-record-panels-CGmKIJdN.js";import{r as xt,R as de,b as gt}from"./events-feed-DmRzikZW.js";import{a as vt}from"./record-session-CAmGHMyM.js";import"./schema-value-zTJGE4eh.js";import"./filter-editors-CQoSj-20.js";import"./subDays-D8nHthaS.js";import"./runs-C8sZQr4o.js";import"./activity-route-location-C1jcXC7v.js";import"./event-kind-options-fHAIXu24.js";import"./clients-xnzZeEdZ.js";import"./client-activity-scopes-BPbRX-Pe.js";import"./client-rows-vrNA6FLs.js";import"./run-initiator-DhE5v4z0.js";import"./list-skeleton-DsYGUHxi.js";import"./use-automations-CgWNoYio.js";import"./agent-loading-shells-DYqQphN7.js";import"./member-scope-gate-vvkgSAb2.js";import"./app-bridge-C4nPtae3.js";import"./card-DtLIFq7D.js";import"./definition-comparison-4UYMI6BK.js";import"./json-diff-mcDgyct_.js";import"./code-editor-mrKkAfcE.js";import"./index-Vcq4gwWv.js";import"./copy-button-C3wMMv63.js";import"./device-automation-Dp3faMvp.js";function yt(t,s){if(t===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in t)return t;if(typeof t=="function")return{shouldBlockFn:async()=>await t(),enableBeforeUnload:!0,withResolver:!1};const i=!!(t.condition??!0),n=t.blockerFn;return{shouldBlockFn:async()=>i&&n!==void 0?await n():i,enableBeforeUnload:i,withResolver:n===void 0}}function jt(t,s){const{shouldBlockFn:i,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:d=!1}=yt(t),o=Re(),{history:r}=o,[c,h]=E.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return E.useEffect(()=>{const p=async x=>{function l(y){const b=o.parseLocation(y),v=o.getMatchedRoutes(b.pathname);return v.foundRoute===void 0?{routeId:"__notFound__",fullPath:b.pathname,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(y.search)}:{routeId:v.foundRoute.id,fullPath:v.foundRoute.fullPath,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(y.search)}}const m=l(x.currentLocation),u=l(x.nextLocation);if(m.routeId==="__notFound__"&&u.routeId!=="__notFound__")return!1;const f=await i({action:x.action,current:m,next:u});if(!d)return f;if(!f)return!1;const _=await new Promise(y=>{h({status:"blocked",current:m,next:u,action:x.action,proceed:()=>y(!1),reset:()=>y(!0)})});return h({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),_};return a?void 0:r.block({blockerFn:p,enableBeforeUnload:n})},[i,n,a,d,r,o]),c}function H(t,s){return se(Y(t))===se(Y(s))}function bt(t,s){const i={};for(const n of new Set([...Object.keys(t),...Object.keys(s)]))H(t[n],s[n])||(i[n]=Y(t[n])??null);return Object.keys(i).length>0?i:void 0}function kt(t,s){return[...new Set([...Object.keys(t),...Object.keys(s)])].filter(i=>{try{return!H(t[i],s[i])}catch{return!0}})}function ue(t,s){return{name:t.name,slug:t.slug,metadata:ut(t.metadata??{},s)}}function _t(t,s,i){const n=new Set(i),a={},d={},o=new Set([...Object.keys(t.values.metadata),...Object.keys(t.baseline.metadata),...Object.keys(s.metadata)]);for(const r of o){const c=n.has(r),h=c?t.values.metadata[r]:t.baseline.metadata[r],p=H(h,s.metadata[r])?h:s.metadata[r];p!==void 0&&(a[r]=p);let x=!1;if(!c)try{x=!H(t.values.metadata[r],t.baseline.metadata[r])}catch{x=!0}const l=x?t.values.metadata[r]:p;l!==void 0&&(d[r]=l)}return{baseline:{name:s.name,slug:s.slug,metadata:a},values:{name:s.name,slug:s.slug,metadata:d}}}function Nt({entity:t,schema:s,orgContext:i}){const n=E.useMemo(()=>ue(t,s),[t,s]),a=Ee(w(t),n,s),d=Fe(i),{values:o,baseline:r,commit:c}=a,h=E.useMemo(()=>kt(o.metadata,r.metadata),[o.metadata,r.metadata]),p=o.name!==r.name||o.slug!==r.slug,x=E.useCallback((m,u)=>a.setValues(f=>({...f,metadata:{...f.metadata,[m]:u}})),[a.setValues]),l=async({note:m}={})=>{if(typeof t.id!="number")throw new Error("Source records are read-only");if(!a.canSubmit)return null;const u=bt(o.metadata,r.metadata),f=o.name.trim()!==r.name.trim();if(!u&&!p)return null;const _=await d.mutateAsync({entityId:t.id,name:f?o.name.trim():void 0,slug:o.slug,metadata:u,field_note:u&&m?.trim()||void 0}),y=ue(_.entity,s);return c(b=>_t(b,y,Object.keys(u??{})),y),{held:_.blocked_fields??[],approvalUrl:_.approval_url}};return{values:o,baseline:r,revision:a.revision,setValues:a.setValues,setMetadataField:x,reset:a.reset,save:l,saving:d.isPending,dirtyKeys:h,identityDirty:p,isDirty:p||h.length>0,canSubmit:a.canSubmit,hasConflict:a.hasConflict,hasInvalidInput:a.hasInvalidInput}}const St=3,wt=50;function ye(t){const s=E.useRef(null);return E.useEffect(()=>{t&&(s.current?.scrollIntoView?.({block:"start"}),s.current?.focus())},[t]),s}function V({headingRef:t,children:s}){return e.jsx("h3",{ref:t,tabIndex:-1,className:"text-xs font-medium uppercase tracking-wide text-muted-foreground outline-none",children:s})}function Rt({entityId:t,entityName:s,ownerSlug:i,orgContext:n,focus:a,collapsed:d=!1}){const o=J(),r=ye(a),{data:c,isLoading:h,isError:p,refetch:x}=De(t,n,{limit:wt});if(t===void 0)return null;if(h)return e.jsxs("section",{className:"space-y-2","aria-busy":"true",children:[e.jsx(V,{headingRef:r,children:"Linked"}),e.jsx(ae,{className:"h-4 w-24"}),e.jsx(ae,{className:"h-6 w-full rounded-md"})]});if(p||!c)return e.jsxs("section",{className:"space-y-2",children:[e.jsx(V,{headingRef:r,children:"Linked"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Could not load this record's links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void x(),children:"Retry"})]})]});if(c.countsByType.length===0&&!c.hasMore&&!c.failures?.length)return a?e.jsxs("section",{className:"space-y-2",children:[e.jsx(V,{headingRef:r,children:"Linked"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No links to other records yet."})]}):null;if(d){const l=c.countsByType.flatMap(m=>{const u=m.count===1?c.rows.find(f=>f.relationship_type_slug===m.relationship_type_slug):void 0;return u?[xt(u,m.relationship_type_name)]:[m.relationship_type_name,String(m.count)]});return e.jsxs("section",{className:"space-y-1","aria-label":"Linked records",children:[e.jsx(V,{headingRef:r,children:"Linked"}),e.jsx(de,{count:c.failures?.length??0,onRetry:()=>void x()}),e.jsx("p",{"data-testid":"linked-summary",className:"truncate text-sm text-muted-foreground",children:l.join(" · ")})]})}return e.jsxs("section",{className:"space-y-3","aria-label":"Linked records",children:[e.jsx(V,{headingRef:r,children:"Linked"}),e.jsx(de,{count:c.failures?.length??0,onRetry:()=>void x()}),c.hasMore&&o?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>o.open({href:"",key:`record-links:${t}`,title:"Linked records",recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,label:"Linked records"}}),children:"Browse linked records"}):null,c.countsByType.map(l=>{const m=c.rows.filter(f=>f.relationship_type_slug===l.relationship_type_slug).slice(0,St),u=l.count>m.length;return e.jsxs("div",{className:"space-y-1 text-sm",children:[u||m.length===0?e.jsxs("p",{className:"text-muted-foreground",children:[l.relationship_type_name,u?e.jsxs("span",{className:"tabular-nums text-muted-foreground/70",children:[" ","· ",l.count,c.countsScope==="page"?" shown":""]}):null]}):null,e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[m.map(f=>e.jsx(gt,{row:f,label:l.relationship_type_name,entityId:t,ownerSlug:i,orgContext:n},f.id)),u&&o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary",onClick:()=>o.open({href:"",key:`record-links:${t}:${l.relationship_type_slug}`,title:`${l.relationship_type_name} · ${l.count}`,recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,relationshipType:l.relationship_type_slug,label:l.relationship_type_name}}),children:["Show all ",l.count]}):null]})]},l.relationship_type_slug)})]})}function Et({record:t,ownerSlug:s,orgContext:i,focus:n}){const[a,d]=E.useState(n),o=ye(n);return e.jsxs("section",{className:"space-y-2",children:[e.jsx(V,{headingRef:o,children:"Linked"}),a?e.jsx(ft,{record:t,ownerSlug:s,orgContext:i}):e.jsx(N,{type:"button",variant:"outline",size:"sm",className:"h-7",onClick:()=>d(!0),children:"Find linked records"})]})}const Ft="$name";function je({outcome:t,schema:s}){if(!t||t.held.length===0)return null;const i=s?.properties??{},n=t.held.map(a=>a===Ft?"Name":mt(a,i[a]??{}));return e.jsxs("div",{role:"status",className:"rounded-md bg-amber-500/10 px-3 py-2 text-sm text-amber-700 dark:text-amber-300",children:[n.join(", ")," ",n.length===1?"needs":"need"," approval before ",n.length===1?"it changes":"they change",".",t.approvalUrl?e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:t.approvalUrl,className:"underline",children:"Review"})]}):null]})}const Dt=320,Ct={},Lt=()=>{};function Bt({view:t,orgSlug:s,recordUrl:i,scope:n}){const a=J(),d=`${i}${pe(t.key)}`,o=a?()=>a.open({href:d,title:t.name}):void 0,r=!t.untitled,c=r||!!t.description,h=c||!!o;return e.jsxs("section",{className:"min-w-0 rounded-lg border","data-testid":"view-card","data-view":t.key,"aria-label":r?void 0:t.name,children:[h?e.jsxs("header",{className:c?"flex items-start justify-between gap-3 px-4 pt-3 pb-2":"flex justify-end px-2 pt-1.5",children:[c?e.jsxs("div",{className:"min-w-0",children:[r?e.jsx("h3",{className:"truncate text-sm font-medium",children:t.name}):null,t.description?e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.description}):null]}):null,o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:o,"aria-label":`Open ${t.name}`,children:[e.jsx(Ce,{className:"h-3.5 w-3.5"}),"Open"]}):null]}):null,e.jsx("div",{className:h?"px-4 pb-3":"px-4 py-3",children:e.jsx(xe,{orgSlug:s,viewKey:t.key,scope:n,params:Ct,onParamsChange:Lt,contentHash:t.content_hash,title:t.name,minHeight:64,displayMode:"inline",maxHeight:Dt,onRequestDisplayMode:o?p=>{p==="fullscreen"&&o()}:void 0})})]})}function Pt({recordUrl:t,dirty:s,onDiscard:i}){const n=jt({disabled:!s,enableBeforeUnload:s,withResolver:!0,shouldBlockFn:({next:d})=>d.pathname!==t&&!d.pathname.startsWith(`${t}${pe("")}`)}),a=n.status==="blocked";return e.jsx(He,{open:a,onOpenChange:d=>{!d&&a&&n.reset()},children:e.jsxs(Ue,{className:"max-w-sm",children:[e.jsxs(Ke,{children:[e.jsx(qe,{children:"Discard unsaved changes?"}),e.jsx(We,{children:"This record has edits that are not saved. Leaving discards them."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>a&&n.reset(),children:"Keep editing"}),e.jsx(N,{type:"button",variant:"destructive",onClick:()=>{a&&(i(),n.proceed())},children:"Discard"})]})]})})}const me=6;function Vt({entity:t,ownerSlug:s,orgContext:i,recordUrl:n,schema:a,entityTypeName:d,isTypeLoading:o,record:r,canEdit:c,editing:h,onEditingChange:p,outcome:x,onSaved:l,formId:m,fieldLimit:u,onDeleted:f}){const _=h&&c,y=J(),b={entity:{id:w(t),name:t.name,entity_type:t.entity_type},ownerSlug:s,orgContext:i,schema:a,record:r,editing:_};vt(b);const v=y?.item?.recordField,D={ownerSlug:s,orgContext:i,controls:t.field_controls,dirtyKeys:r.dirtyKeys,openField:y?L=>y.open(rt(b,L.key)):void 0,openFieldKey:v?.entityId===w(t)?v.field:void 0},C=e.jsx(Pt,{recordUrl:n,dirty:_&&r.isDirty,onDiscard:()=>{r.reset(),p(!1)}});if(o)return e.jsx(ze,{rows:6});if(_)return e.jsxs(e.Fragment,{children:[C,e.jsx($t,{formId:m,entity:t,entityTypeName:d,schema:a,record:r,orgContext:i,renderControl:(L,P,F)=>ht(P)?e.jsx(pt,{field:{key:L,prop:P},value:F,context:D}):void 0,onSaved:l,onDeleted:f,onDone:()=>p(!1)})]});const R=ge(r.revision);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(je,{outcome:x,schema:a}),e.jsx(ve,{fields:R,fieldLimit:u,values:r.values.metadata,context:D})]})}function $t({formId:t,entity:s,entityTypeName:i,schema:n,record:a,orgContext:d,renderControl:o,onSaved:r,onDeleted:c,onDone:h}){const p=Ge(),x=s.field_controls,{name:l,slug:m,metadata:u}=a.values,f=g=>a.setValues(j=>({...j,name:g})),_=g=>a.setValues(j=>({...j,slug:g})),y=g=>a.setValues(j=>({...j,metadata:g})),[b,v]=B(w(s),""),[D,C]=B(w(s),null),[R,L]=B(w(s),null),[P,F]=B(w(s),!1),[S,$]=B(w(s),null),O=a.dirtyKeys.length>0,I=async g=>{if(g.preventDefault(),!!a.canSubmit){if(C(null),!l.trim()){C("Name is required");return}try{const j=await a.save({note:b});L(j),r(j),v(""),j?.held.length||h()}catch(j){C(j instanceof Error?j.message:"Failed to update entity")}}},U=async()=>{$(null);try{if(typeof s.id!="number")throw new Error("Source records are read-only");await p.mutateAsync({entityId:s.id}),F(!1),c?.()}catch(g){$(g instanceof Error?g.message:"Failed to delete entity")}},A=[s.total_content>0&&`${s.total_content} content item${s.total_content===1?"":"s"}`,s.automations_count>0&&`${s.automations_count} Automation${s.automations_count===1?"":"s"}`,s.active_connections>0&&`${s.active_connections} connector${s.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return e.jsxs("form",{id:t,onSubmit:I,className:"space-y-4",children:[e.jsx(Xe,{visible:a.hasConflict,onReload:a.reset}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(q,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(oe,{id:"sidebar-name",value:l,onChange:g=>f(g.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(q,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(oe,{id:"sidebar-slug",value:m,onChange:g=>_(g.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),a.revision&&Object.keys(a.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(at,{}),e.jsx(ot,{schema:a.revision,values:u,onValuesChange:y,fieldControls:x,orgContext:d,renderControl:o})]}),O&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(q,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Qe,{id:"sidebar-correction-note",value:b,onChange:g=>v(g.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),D&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx(je,{outcome:R,schema:n}),P?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Ye,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',s.name,'"?']}),A&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",A,". This cannot be easily undone."]})]})]}),S&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:S}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{F(!1),$(null)},children:"Cancel"}),e.jsx(N,{type:"button",variant:"destructive",size:"sm",onClick:U,disabled:p.isPending,children:p.isPending?"Deleting...":`Delete ${i||"entity"}`})]})]}):e.jsx("div",{className:"pt-2",children:e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>F(!0),children:"Delete"})})]})}function be(t,s){const i=new Set(t.measure_columns??[]),n=s?.properties??{};return Object.keys(t.metadata??{}).filter(a=>a!=="id"&&a!=="slug"&&a!=="name"&&!Ie(n[a])&&n[a]?.const===void 0).map(a=>({key:a,prop:n[a]??{},label:n[a]?.["x-table-label"]??(i.has(a)?a:Ae(a.replace(/_/g," "))),numeric:i.has(a)}))}function Ot({entity:t,schema:s,ownerSlug:i,orgContext:n,fieldLimit:a}){const d=be(t,s);return e.jsxs("div",{children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Managed by the source"}),e.jsx(ve,{fields:d,fieldLimit:a,values:t.metadata??{},context:{ownerSlug:i,orgContext:n}})]})}const he="owletto:record-details-expanded";function Tt(){const[t,s]=E.useState(()=>{try{return window.localStorage.getItem(he)==="1"}catch{return!1}});return[t,n=>{s(n);try{window.localStorage.setItem(he,n?"1":"0")}catch{}}]}function Mt({namespace:t,entity:s,recordUrl:i,viewKey:n,title:a,onDeleted:d}){const o=Le({strict:!1}),r=fe(),c=E.useRef(null),h=Be(c,Ze),[p,x]=Tt(),[l,m]=B(w(s),!1),u={slug:t.slug,organizationId:t.id},{isMember:f,isPublic:_,isLoading:y}=Pe(t.slug),b=f||_,v=Ve({...u,organizationId:f?t.id:null}),{data:D,isLoading:C}=Q(s.entity_type,u),R=D?.metadata_schema,{isAdmin:L,isLoading:P}=$e(f?u.organizationId:void 0),F=f&&L&&!P&&!s.is_derived,S=Nt({entity:s,schema:R,orgContext:u}),[$,O]=B(w(s),null),I=`record-form-${s.id}`,U=l&&F,A=b?v.data??[]:[],g=Oe(A,{type:s.entity_type,id:w(s)}),j=Te(g,n),z=!n&&o.tab==="relationships",ke=k=>void r({to:".",search:K=>ne(K,k),replace:!0}),Z={type:s.entity_type,entity:s.is_derived?s.slug:s.id??s.slug},T=h&&!p&&!l&&!z,ee=s.is_derived?ce(be(s,R),s.metadata??{}).length:ce(ge(S.revision),S.values.metadata).length,te=T?me:void 0,_e=e.jsxs("div",{className:"space-y-6",children:[s.is_derived?e.jsxs(e.Fragment,{children:[e.jsx(Ot,{entity:s,schema:R,ownerSlug:t.slug,orgContext:u,fieldLimit:te}),e.jsx(Et,{record:{type:s.entity_type,key:s.slug},ownerSlug:t.slug,orgContext:u,focus:z})]}):e.jsxs(e.Fragment,{children:[e.jsx(Vt,{entity:s,ownerSlug:t.slug,orgContext:u,recordUrl:i,schema:R,entityTypeName:D?.name,isTypeLoading:C,record:S,canEdit:F,editing:l,onEditingChange:m,outcome:$,onSaved:O,formId:I,fieldLimit:te,onDeleted:d}),e.jsx(Rt,{entityId:typeof s.id=="number"?s.id:void 0,entityName:s.name,ownerSlug:t.slug,orgContext:u,focus:z,collapsed:T})]}),h&&!l&&!z?e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary","aria-expanded":!T,onClick:()=>x(T),children:T?ee>me?`Show all ${ee} fields`:"Show all details":"Show fewer"}):null]}),Ne=k=>e.jsx(tt,{rootRef:c,narrow:h,details:_e,summary:e.jsx(st,{entity:s,schema:R,context:{ownerSlug:t.slug,orgContext:u}}),children:k}),Se=U?e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{S.reset(),O(null),m(!1)},children:"Cancel"}),e.jsx(N,{type:"submit",form:I,size:"sm",disabled:!S.canSubmit||!S.isDirty||S.saving||!S.values.name.trim(),children:S.saving?"Saving...":"Save"})]}):F&&!C?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:()=>{O(null),m(!0)},children:[e.jsx(Me,{className:"h-3.5 w-3.5"}),"Edit"]}):null,M=k=>e.jsx(et,{entity:s,owner:t.slug,schema:R,title:a??null,actions:Se,layout:"content",children:k});if(n&&!b)return M(y?null:e.jsx(lt,{}));if(n&&v.data===void 0)return M(v.isError?e.jsx(le,{onRetry:()=>void v.refetch()}):null);if(j.kind==="missing")return M(e.jsx(ct,{viewKey:j.key,backTo:i,backLabel:`Back to ${s.name}`}));if(j.kind==="view"){const{view:k}=j;return M(e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx(dt,{decls:k.params,params:ie(o),onParamsChange:K=>void r({to:".",search:we=>ne(we,K)})}),e.jsx(xe,{orgSlug:t.slug,viewKey:k.key,scope:Z,params:ie(o),onParamsChange:ke,paramDecls:k.params,contentHash:k.content_hash,title:k.name,minHeight:320})]}))}return M(Ne(e.jsxs("div",{className:"min-w-0 space-y-4",children:[b&&v.isError&&e.jsx(le,{onRetry:()=>void v.refetch()}),g.map(k=>e.jsx(Bt,{view:k,orgSlug:t.slug,recordUrl:i,scope:Z},k.key)),e.jsxs("section",{"aria-labelledby":"record-activity-heading",className:"min-w-0",children:[e.jsx("h2",{id:"record-activity-heading",className:"mb-2 text-sm font-medium text-muted-foreground",children:"Activity"}),e.jsx(it,{entity:s,organizationId:t.id,ownerSlug:t.slug})]})]})))}function It(t){return t?.trim()?t:void 0}function js({namespace:t,path:s,entity:i,viewKey:n}){const a=fe(),{data:d}=Q(i.entity_type,{slug:t.slug}),o=s[0]?.entity_type??i.entity_type,{data:r}=Q(o,{slug:t.slug}),c=It(d?.icon),h=s.map(l=>({entity_type:l.entity_type,slug:l.slug})),p=`/${t.slug}/${re(i.entity_type)}`,x=W(t.slug,h);return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:[e.jsx(Je,{crumbs:[...o==="$member"?[]:[e.jsx(G,{to:"/$owner",params:{owner:t.slug},search:{section:"entity-type"},className:X,children:"Entity types"},"home")],e.jsx(G,{to:`/${t.slug}/${re(o)}`,className:X,children:o==="$member"?"Team":r?.name??o},"type"),...s.slice(0,-1).map((l,m)=>e.jsx(G,{to:W(t.slug,h.slice(0,m+1)),className:X,children:l.name},l.id))],current:i.name}),e.jsx(Mt,{namespace:t,entity:i,recordUrl:x,viewKey:n,title:e.jsx(nt,{entity:i,schema:d?.metadata_schema,icon:c}),onDeleted:()=>{const l=s.slice(0,-1);l.length>0?a({to:W(t.slug,l)}):a({to:p})}})]})}export{js as EntityPage};
|
|
2
|
+
//# sourceMappingURL=entity-page-DZjzQ2V4.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as x,j as e,bz as ue,i as K,aE as me,aF as xe,B as F,go as he,aH as pe,cP as ge,fG as ne,gm as T,fX as fe,dL as A,a7 as Z,L as P,fe as je,b as ve,m as E}from"./index-DByaMzsG.js";import{p as _,n as be,e as re,b as ye,g as Ne,f as q,R as we,c as Se,d as _e}from"./renderer-olRv_HMI.js";import{S as J}from"./schema-value-zTJGE4eh.js";import{T as ke,a as Ce,b as B,c as Y,d as Ee,e as H}from"./table-C637cQxG.js";var Le="Separator",ee="horizontal",Re=["horizontal","vertical"],ae=x.forwardRef((t,s)=>{const{decorative:n,orientation:l=ee,...o}=t,a=Me(l)?l:ee,h=n?{role:"none"}:{"aria-orientation":a==="vertical"?a:void 0,role:"separator"};return e.jsx(ue.div,{"data-orientation":a,...h,...o,ref:s})});ae.displayName=Le;function Me(t){return Re.includes(t)}var oe=ae;const Pe=x.forwardRef(({className:t,orientation:s="horizontal",decorative:n=!0,...l},o)=>e.jsx(oe,{ref:o,decorative:n,orientation:s,className:K("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...l}));Pe.displayName=oe.displayName;function Ae({choices:t,visible:s,onChange:n}){return e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(F,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:e.jsx(he,{className:"h-4 w-4"})})}),e.jsxs(pe,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),t.map(l=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[e.jsx("input",{type:"checkbox",checked:!s||s.includes(l.field),onChange:o=>{const a=s??t.map(c=>c.field);n(o.target.checked?[...a,l.field]:a.filter(c=>c!==l.field))}}),l.label]},l.field))]})]})}function Fe({direction:t}){return t?e.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:t==="asc"?"Sort ascending":"Sort descending"}),t==="asc"?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):e.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:"Sort"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function te(t,s){const n=t?.properties;if(n)return Object.entries(n).find(([,l])=>l[s])?.[0]}function Te(t){const s=t.trim(),n=s.split(/[\s._@/-]+/).filter(Boolean),l=n.length>=2?`${n[0][0]}${n[1][0]}`:(n[0]??s).slice(0,2);let o=0;for(let a=0;a<s.length;a++)o=o*31+s.charCodeAt(a)>>>0;return{initials:l.toUpperCase()||"?",hue:o%360}}function Oe(t){const[s,n]=x.useState();return x.useEffect(()=>{if(!t||!globalThis.crypto?.subtle){n(void 0);return}let l=!1;const o=t.trim().toLowerCase();return crypto.subtle.digest("SHA-256",new TextEncoder().encode(o)).then(a=>{l||n(Array.from(new Uint8Array(a)).map(c=>c.toString(16).padStart(2,"0")).join(""))}),()=>{l=!0}},[t]),s?`https://www.gravatar.com/avatar/${s}?d=identicon&s=80`:void 0}function le({metadata:t,metadataSchema:s,name:n,typeIcon:l,className:o="h-6 w-6",iconClassName:a="h-5 w-5",initialsFallback:c=!1}){const h=te(s,"x-image"),j=te(s,"x-email"),y=h&&t?.[h]||void 0,v=j&&t?.[j]||void 0,N=Oe(y?void 0:v),w=y||N,[k,L]=x.useState(!1);if(x.useEffect(()=>{L(!1)},[w]),w&&!k)return e.jsx("img",{src:w,alt:n,referrerPolicy:"no-referrer",onError:()=>L(!0),className:K("rounded-full object-cover border border-border",o)});if(c){const R=n.trim()||v||ze(t,s)||n,{initials:O,hue:z}=Te(R);return e.jsx("span",{role:"img","aria-label":n,className:K("inline-grid place-items-center rounded-full border border-border font-semibold text-white select-none",o),style:{background:`oklch(0.55 0.13 ${z})`,fontSize:"0.85em"},children:O})}return e.jsx(ge,{icon:l,className:a})}function ze(t,s){if(!t)return;const n=s?.properties,l=["email","handle","username","login","github","x_handle","slug"],o=Object.keys(n||t);for(const a of o)if(l.includes(a.toLowerCase())){const c=t[a];if(typeof c=="string"&&c.trim())return c}}function S({column:t,children:s,alignRight:n=!1}){return e.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${n?" ml-auto":""}`,onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[s,e.jsx(Fe,{direction:t.getIsSorted()})]})}function se(t,s,n){const l=ne(t?.properties).filter(([a,c])=>(!s||a!=="name")&&!c["x-image"]&&c["x-table-column"]===!0);if(l.length)return l.map(([a,c])=>({field:a,label:c["x-table-label"]??T(a.replaceAll("_"," "))}));if(!s)return[];const o=n.find(a=>Object.keys(_(a.metadata)).length>0);return Object.keys(_(o?.metadata)).filter(a=>a!=="id"&&a!=="slug"&&a!=="name"&&!fe(t?.properties?.[a])).map(a=>({field:a,label:T(a.replaceAll("_"," "))}))}function Ie(t){return t.some(s=>Object.hasOwn(_(s.metadata),"name"))}function $e(t,s){return A(t,re(s))}function Be(t){return`${t.entityType}:${t.lookupField}`}const He=new Set(["stage","category","round_type","investor_type"]);function Ke(t,s){const n=t.toLowerCase();return n==="mrr"||n==="arr"||n==="revenue"||n==="valuation"||n==="funding_raised"||n==="fund_size"||n.endsWith("_usd")||s.description?.toLowerCase().includes("usd")===!0}function Ue(t,s){if(Ke(t,s))return"currency";if(He.has(t)||t.endsWith("_slug"))return"enum"}function Ve({entities:t,owner:s,schema:n,entityTypeIcon:l,isDerived:o,measureColumns:a,linkedEntityLookups:c,hasAnyParents:h,sorting:j,onSortingChange:y,visibleColumns:v,columnChoices:N,onVisibleColumnsChange:w,page:k,pageSize:L,totalCount:R,hasMore:O,pageTitle:z,onPrevPage:ie,onNextPage:ce}){const M=N?.length&&w?e.jsx(Ae,{choices:N,visible:v,onChange:w}):null,f=n?.properties,U=!o||Ie(t),V=x.useMemo(()=>f?Object.fromEntries(Object.entries(f).flatMap(([i,r])=>r["x-link-entity-type"]?[[i,{entityType:r["x-link-entity-type"],lookupField:r["x-link-lookup-field"]||"slug"}]]:[])):{},[f]),C=x.useMemo(()=>f?se({properties:f},o,[]).map(({field:r})=>[r,f[r]]).map(([r,u])=>{const m=V[r],d=m?c[Be(m)]:void 0;return{id:o?r:`meta_${r}`,accessorFn:p=>{const g=_(p.metadata);return be(g[r],u.enum)},header:({column:p})=>{const g=u["x-table-label"]||u.title||u.description||T(r.replace(/_/g," "));return o?e.jsx(S,{column:p,children:g}):g},cell:({getValue:p})=>e.jsx(J,{value:p(),prop:u,format:Ue(r,u),className:"text-muted-foreground",resolveLink:d?g=>{const b=d[g];return b?{label:b.name,to:A(s,[{entity_type:b.entity_type,slug:b.slug}])}:void 0}:void 0})}}):[],[o,V,c,s,f]),W=x.useMemo(()=>new Set(a),[a]),I=x.useMemo(()=>!o||C.length>0?[]:se({properties:f},!0,t).map(({field:r})=>r).map(r=>{const u=W.has(r);return{id:r,accessorFn:m=>_(m.metadata)[r],header:({column:m})=>e.jsxs(S,{column:m,children:[u?r:T(r.replace(/_/g," ")),u&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:m})=>e.jsx(J,{value:m(),prop:f?.[r],className:u?"tabular-nums":"text-muted-foreground"}),meta:u?{align:"right"}:void 0}}),[o,C,t,W,f]),D=x.useMemo(()=>{const i=n?.["x-table-relationships"];return!i||i.length===0?[]:i.map(r=>({id:`rel_${r.relationship_type}`,accessorFn:u=>u.relationships?.[r.relationship_type]??[],header:r.label,cell:({getValue:u})=>{const m=u();return!m||m.length===0?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:m.map((d,p)=>{const g=A(s,[{entity_type:d.entity_type,slug:d.slug}]);return e.jsxs("span",{children:[e.jsx(P,{to:g,className:"text-primary hover:underline",onClick:b=>b.stopPropagation(),children:d.name}),p<m.length-1&&","]},d.id)})})}}))},[s,n]),G=x.useMemo(()=>h||t.some(r=>r.parent_name&&r.parent_slug&&r.parent_entity_type)?[{id:"parent",accessorFn:r=>r.parent_name,header:"Parent",cell:({row:r})=>{if(!r.original.parent_name||!r.original.parent_slug||!r.original.parent_entity_type)return e.jsx("span",{className:"text-muted-foreground",children:"-"});const u=A(s,[{entity_type:r.original.parent_entity_type,slug:r.original.parent_slug}]);return e.jsx(P,{to:u,className:"text-primary hover:underline",children:r.original.parent_name})}}]:[],[t,h,s]),X=x.useMemo(()=>{const i=[],r=t.some(d=>(d.total_content??0)>0),u=t.some(d=>(d.active_connections??0)>0),m=t.some(d=>(d.automations_count??0)>0);return r&&i.push({accessorKey:"total_content",header:({column:d})=>e.jsx(S,{column:d,alignRight:!0,children:"Activity"}),cell:({row:d,getValue:p})=>{const g=p()??0;if(g===0)return e.jsx("span",{className:"tabular-nums",children:"0"});const b=re(d.original);return e.jsx(P,{to:je(s,b),className:"tabular-nums hover:underline",children:g})},meta:{align:"right"}}),u&&i.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:d})=>{const p=d();return p&&p>0?e.jsxs(Z,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[p," active"]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),m&&i.push({accessorKey:"automations_count",header:({column:d})=>e.jsx(S,{column:d,alignRight:!0,children:"Automations"}),cell:({getValue:d})=>e.jsx("span",{className:"tabular-nums",children:d()??0}),meta:{align:"right"}}),i},[t,s]),Q=x.useMemo(()=>[{accessorKey:"name",header:({column:i})=>U?e.jsx(S,{column:i,children:"Name"}):"Name",cell:({row:i})=>{const r=_(i.original.metadata);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{metadata:r,metadataSchema:n,name:i.original.name,typeIcon:l,className:"h-6 w-6 shrink-0"}),e.jsx("div",{className:"min-w-0",children:(()=>{const u=$e(s,i.original);return e.jsx(P,{to:u,className:"block max-w-56 truncate font-medium hover:underline",title:i.original.name,children:i.original.name})})()})]})}},...G,...C,...I,...D,...X,...o?[]:[{accessorKey:"created_at",header:({column:i})=>e.jsx(S,{column:i,children:"Created"}),cell:({getValue:i})=>e.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(i()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[s,G,C,I,D,X,n,l,o,U]),$=ye({data:t,columns:Q,state:{sorting:j,columnVisibility:Object.fromEntries([...C,...I].flatMap(i=>i.id?[[i.id,!v||v.includes(o?i.id:i.id.replace(/^meta_/,""))]]:[]))},onSortingChange:y,getCoreRowModel:Ne(),manualSorting:!0,enableSortingRemoval:!1}),de=t.length>0||k>0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border",children:e.jsxs(ke,{className:"min-w-[48rem]",children:[e.jsx(Ce,{children:$.getHeaderGroups().map(i=>e.jsxs(B,{children:[i.headers.map(r=>e.jsx(Y,{"aria-sort":r.column.getIsSorted()==="asc"?"ascending":r.column.getIsSorted()==="desc"?"descending":void 0,className:r.column.columnDef.meta?.align==="right"?"text-right":"",children:r.isPlaceholder?null:q(r.column.columnDef.header,r.getContext())},r.id)),M?e.jsx(Y,{className:"w-10 pr-2 text-right",children:M}):null]},i.id))}),e.jsx(Ee,{children:$.getRowModel().rows.length?$.getRowModel().rows.map(i=>e.jsxs(B,{children:[i.getVisibleCells().map(r=>e.jsx(H,{className:r.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:q(r.column.columnDef.cell,r.getContext())},r.id)),M?e.jsx(H,{}):null]},i.id)):e.jsx(B,{children:e.jsx(H,{colSpan:Q.length+(M?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),de&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:["Showing ",t.length," of ",R," ",z.toLowerCase()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",k+1," of ",Math.max(1,Math.ceil(R/L))]}),e.jsx(F,{variant:"outline",size:"sm",onClick:ie,disabled:k===0,children:"Previous"}),e.jsx(F,{variant:"outline",size:"sm",onClick:ce,disabled:!O,children:"Next"})]})]})]})}const We=720;function De(){return e.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(E,{className:"h-9 max-w-sm flex-1"}),e.jsx(E,{className:"h-9 w-28"})]}),e.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[e.jsx("div",{className:"border-b px-4 py-3",children:e.jsx(E,{className:"h-3 w-1/3"})}),e.jsx("div",{className:"divide-y",children:Array.from({length:5},(t,s)=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx(E,{className:"h-3 flex-1"}),e.jsx(E,{className:"h-3 w-16 shrink-0"})]},s))})]})]})}function tt({title:t,actions:s,controls:n,table:l,children:o,loading:a=!1,error:c=null,onRetry:h,empty:j=e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"No records."})}){return e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[typeof t=="string"?e.jsx("h2",{className:"text-lg font-semibold",children:t}):t,s]}),e.jsxs("div",{children:[n,a?e.jsx(De,{}):c!==null?e.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[c,h?e.jsx(F,{className:"ml-3",variant:"outline",size:"sm",onClick:h,children:"Retry"}):null]}):o!==void 0?o:l?e.jsx(Ve,{...l}):j]})]})}function Ge(t,s){return s?.properties?ne(s.properties).map(([n,l])=>({key:n,prop:l})):Object.keys(t.metadata??{}).map(n=>({key:n,prop:{}}))}function Xe({entity:t,schema:s,icon:n}){return e.jsxs(e.Fragment,{children:[e.jsx(le,{metadata:t.metadata,metadataSchema:s?{...s}:void 0,name:t.name,typeIcon:n,className:"h-6 w-6 shrink-0"}),e.jsx("h2",{className:"truncate text-lg font-semibold leading-tight",children:t.name})]})}function Qe({entity:t,schema:s,context:n}){const l=Se(s?{...s}:void 0).filter(({key:o,prop:a})=>a["x-table-column"]===!0&&!a["x-image"]&&t.metadata?.[o]!==void 0&&t.metadata[o]!==null&&t.metadata[o]!=="");return l.length?e.jsx("p",{"data-testid":"record-summary",className:"-mt-2 truncate text-sm text-muted-foreground tabular-nums",children:l.map(({key:o,prop:a},c)=>e.jsxs("span",{children:[c>0?" · ":null,e.jsx(_e,{field:{key:o,prop:a},value:t.metadata?.[o],context:n})]},o))}):null}function Ze({details:t,summary:s,children:n,rootRef:l,narrow:o}){return e.jsx("div",{ref:l,className:"min-w-0 space-y-4",children:o?e.jsxs(e.Fragment,{children:[s,e.jsx("section",{"aria-label":"Details","data-testid":"record-details",children:t}),n]}):e.jsxs("div",{className:"grid grid-cols-[18rem_minmax(0,1fr)] gap-6",children:[e.jsx("aside",{className:"sticky top-12 max-h-[calc(100dvh-7rem)] min-w-0 self-start overflow-y-auto overscroll-contain pr-2 pb-16",children:t}),n]})})}function st({entity:t,owner:s,schema:n,title:l,actions:o,details:a,summary:c,children:h,layout:j="record"}){const y=x.useRef(null),v=ve(y,We),N=e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"record-header",className:"sticky top-0 z-30 -mx-4 flex h-12 items-center justify-between gap-3 bg-background px-4 lg:-mx-6 lg:px-6",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:l===void 0?e.jsx(Xe,{entity:t,schema:n}):l}),o]}),j==="content"?h:e.jsx(Ze,{rootRef:y,narrow:v,details:a===void 0?e.jsx(we,{fields:Ge(t,n),values:t.metadata??{},context:{ownerSlug:s}}):a,summary:c===void 0?e.jsx(Qe,{entity:t,schema:n,context:{ownerSlug:s}}):c,children:h})]});return j==="content"?N:e.jsx("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:N})}export{le as E,We as N,Pe as S,Ve as a,tt as b,De as c,st as d,se as e,Ze as f,Qe as g,Xe as h};
|
|
2
|
+
//# sourceMappingURL=entity-pages-BWBpttz3.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as _,j as N,B as xe,dg as lt,fD as ut,fE as dt,c1 as ft,i as ve,cP as yt,m as ye,bx as ht,cY as mt}from"./index-DByaMzsG.js";function Ge(t){let n=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(const c of t)n=Math.min(n,c.x-c.w/2),i=Math.max(i,c.x+c.w/2),r=Math.min(r,c.y-c.h/2),l=Math.max(l,c.y+c.h/2);return Number.isFinite(n)?{x0:n,y0:r,x1:i,y1:l}:null}const be=(t,n,r)=>t<n?n:t>r?r:t;function pt(t,n,r,{padding:i=.12,minZoom:l=.2,maxZoom:c=1.2}={}){const x=Math.max(1,t.x1-t.x0),w=Math.max(1,t.y1-t.y0),E=be(Math.min(n/(x*(1+i)),r/(w*(1+i))),l,c);return{z:E,x:n/2-(t.x0+t.x1)/2*E,y:r/2-(t.y0+t.y1)/2*E}}function xt(t,n,r=0){if(t===n){const h=t.x+t.w/2,p=t.y-t.h/2;return[{x:h-30,y:p},{x:h-30,y:p-26},{x:h+22,y:p-26},{x:h+22,y:t.y-6},{x:h,y:t.y-6}]}const i=r*8,l=t.x+t.w/2,c=t.y+be(i,-t.h/2+6,t.h/2-6),x=n.x-n.w/2,w=n.y+be(i,-n.h/2+6,n.h/2-6);if(x-l>=40){const h=(l+x)/2+i;return[{x:l,y:c},{x:h,y:c},{x:h,y:w},{x,y:w}]}const E=Math.max(t.y+t.h/2,n.y+n.h/2)+24+Math.abs(i),k=Math.min(t.y-t.h/2,n.y-n.h/2)-24-Math.abs(i),g=(c+w)/2,u=Math.abs(E-g)<=Math.abs(k-g)?E:k,f=l+24+Math.abs(i),y=x-24-Math.abs(i);return[{x:l,y:c},{x:f,y:c},{x:f,y:u},{x:y,y:u},{x:y,y:w},{x,y:w}]}function gt(t,n,r){const i=r.x-n.x,l=r.y-n.y,c=i*i+l*l,x=c?be(((t.x-n.x)*i+(t.y-n.y)*l)/c,0,1):0;return Math.hypot(t.x-(n.x+x*i),t.y-(n.y+x*l))}function wt(t,n){let r=Number.POSITIVE_INFINITY;for(let i=0;i<n.length-1;i++)r=Math.min(r,gt(t,n[i],n[i+1]));return r}function vt(t,n){return Math.abs(n.x-t.x)<=t.w/2&&Math.abs(n.y-t.y)<=t.h/2}class ie{cells=new Set;static CELL_W=12;static CELL_H=16;keys(n){const r=[],i=Math.floor(n.x0/ie.CELL_W),l=Math.floor(n.x1/ie.CELL_W),c=Math.floor(n.y0/ie.CELL_H),x=Math.floor(n.y1/ie.CELL_H);for(let w=i;w<=l;w++)for(let E=c;E<=x;E++)r.push(w*1e5+E);return r}isFree(n){return this.keys(n).every(r=>!this.cells.has(r))}reserve(n){for(const r of this.keys(n))this.cells.add(r)}}function bt(t,n,r,i,l){const c=t.slice(0,-1).map((u,f)=>({i:f,length:Math.hypot(t[f+1].x-u.x,t[f+1].y-u.y)})).sort((u,f)=>f.length-u.length);if(c.length===0)return null;const x=u=>({x0:u.x-n/2,x1:u.x+n/2,y0:u.y-r/2,y1:u.y+r/2}),w=u=>({x:(t[u].x+t[u+1].x)/2,y:(t[u].y+t[u+1].y)/2});for(const{i:u,length:f}of c){if(!l&&f<n*.7)break;const y=w(u);if(i.isFree(x(y)))return i.reserve(x(y)),y}if(!l)return null;const E=w(c[0].i),g=[-1,1,-1.6,1.6].map(u=>({x:E.x,y:E.y+u*(r+12)})).find(u=>i.isFree(x(u)))??E;return i.reserve(x(g)),g}const kt=t=>N.jsx(yt,{icon:t||null,className:"h-4 w-4"}),Mt='600 14px "DM Sans", system-ui, sans-serif',Et='400 11px "DM Sans", system-ui, sans-serif',St='500 9px "DM Sans", system-ui, sans-serif',Tt='500 11px "DM Sans", system-ui, sans-serif',he=18,Be=8;function qe(t){const n=getComputedStyle(t),r=(i,l)=>n.getPropertyValue(i).trim()||l;return{foreground:r("--foreground","#141414"),muted:r("--muted-foreground","#545454"),card:r("--card","#ffffff"),background:r("--background","#fcfcfb"),border:r("--border","#e7e4dc"),primary:r("--primary","#2f63e8"),mutedSurface:r("--muted","#f3f1ea")}}function ge(t,n,r){if(t.measureText(n).width<=r)return n;let i=0,l=n.length;for(;i<l;){const c=Math.ceil((i+l)/2);t.measureText(`${n.slice(0,c)}…`).width<=r?i=c:l=c-1}return`${n.slice(0,i)}…`}function _t(t,n,r,i){const l=Math.hypot(r.x-n.x,r.y-n.y);if(l<1)return;const c=(r.x-n.x)/l,x=(r.y-n.y)/l;t.moveTo(r.x-c*i-x*i*.55,r.y-x*i+c*i*.55),t.lineTo(r.x,r.y),t.lineTo(r.x-c*i+x*i*.55,r.y-x*i-c*i*.55)}function tn({boxes:t,edges:n,label:r,onOpenBox:i,openLabel:l,onConnect:c,renderIcon:x=kt,className:w}){const E=_.useRef(null),k=_.useRef(null),g=_.useRef(null),u=_.useRef({z:1,x:0,y:0}),f=_.useRef({w:0,h:0,dpr:1}),y=_.useRef(!0),h=_.useRef(new Map),p=_.useRef(null),L=_.useRef(null),O=_.useRef(new Map),C=_.useRef(null),A=_.useRef(""),q=_.useRef(!1),[a,I]=_.useState(()=>new Map),[S,$]=_.useState(null),[K,R]=_.useState(null),[j,Q]=_.useState(null),[B,Oe]=_.useState(null),[Je,Ze]=_.useState(0),{placed:U,movedIds:me}=_.useMemo(()=>{const o=new Map,e=new Set;for(const s of t){const d=a.get(s.id);d&&d.from.x===s.x&&d.from.y===s.y?(o.set(s.id,{...s,x:d.at.x,y:d.at.y}),e.add(s.id)):o.set(s.id,s)}return{placed:o,movedIds:e}},[t,a]),re=_.useMemo(()=>{const o=new Map;for(const s of n){const d=[s.source,s.target].sort().join("|");o.set(d,[...o.get(d)??[],s])}const e=new Map;for(const s of n){const d=U.get(s.source),v=U.get(s.target);if(!d||!v)continue;if(s.route&&!me.has(d.id)&&!me.has(v.id)){e.set(s.id,s.route);continue}const b=o.get([s.source,s.target].sort().join("|"))??[s];e.set(s.id,xt(d,v,b.indexOf(s)-(b.length-1)/2))}return e},[n,U,me]),F=_.useCallback(()=>{y.current=!0},[]),ce=_.useCallback(()=>{const o=Ge([...U.values()]),{w:e,h:s}=f.current;!o||!e||!s||(u.current=pt(o,e,s),q.current=!0,F())},[U,F]),ae=o=>{u.current=o,q.current=!1,F()},Ce=o=>{const e=Ge(o),{w:s,h:d}=f.current;if(!e||!s||!d)return;const v=u.current,b=24;e.x0*v.z+v.x>=b&&e.y0*v.z+v.y>=b&&e.x1*v.z+v.x<=s-b&&e.y1*v.z+v.y<=d-b||ae({...v,x:s/2-(e.x0+e.x1)/2*v.z,y:d/2-(e.y0+e.y1)/2*v.z})},Qe=o=>{Oe(o);const e=U.get(o);e&&Ce([e])},se=t.map(o=>`${o.id}@${Math.round(o.x)},${Math.round(o.y)}`).join(";");_.useEffect(()=>{!se||A.current===se||f.current.w&&(A.current=se,ce())},[se,ce]);const Ae=_.useRef(ce);Ae.current=ce;const Pe=_.useRef(se);Pe.current=se,_.useEffect(()=>{const o=E.current,e=k.current;if(!o||!e||typeof ResizeObserver>"u")return;const s=()=>{const v=window.devicePixelRatio||1,b=o.clientWidth,H=o.clientHeight;f.current={w:b,h:H,dpr:v},e.width=Math.round(b*v),e.height=Math.round(H*v);const W=Pe.current;W&&b&&H&&(A.current!==W||q.current)&&(A.current=W,Ae.current()),F()};s();const d=new ResizeObserver(s);return d.observe(o),()=>d.disconnect()},[F]);const[et,tt]=_.useState(0);_.useEffect(()=>{const o=g.current,e=k.current;if(!o||!e)return;const s=qe(e).muted;for(const d of o.querySelectorAll("[data-icon-key]")){const v=d.dataset.iconKey??"";if(h.current.has(v))continue;const b=d.querySelector("svg"),H=b?null:d.querySelector("img")?.src;if(!b&&!H){h.current.set(v,d.textContent??"");continue}const W=new Image;if(W.onload=F,W.onerror=()=>{h.current.delete(v),tt(T=>T+1)},b){const T=b.cloneNode(!0);T.getAttribute("width")||T.setAttribute("width","24"),T.getAttribute("height")||T.setAttribute("height","24");const M=new XMLSerializer().serializeToString(T).replaceAll("currentColor",s);W.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(M)}`}else H&&(W.src=H);h.current.set(v,W)}},[t,Je,et,F]);const le=(o,e)=>{const s=u.current;return{x:(o-s.x)/s.z,y:(e-s.y)/s.z}},ke=(o,e)=>{const s=u.current,d=le(o,e),v=S&&S.kind!=="edge"?U.get(S.box.id):void 0;if(v&&c){const T=Ye(v);if(Math.hypot(T.x*s.z+s.x-o,T.y*s.z+s.y-e)<=Be+3)return{kind:"handle",box:v}}const b=[...U.values()];for(let T=b.length-1;T>=0;T--)if(vt(b[T],d))return{kind:"box",box:b[T]};let H=null,W=7/s.z;for(const T of n){const M=re.get(T.id);if(!M)continue;const V=wt(d,M);V<W&&(W=V,H=T)}return H?{kind:"edge",edge:H}:null},ee=_.useMemo(()=>{const o=new Set;for(const s of[K,j])s&&o.add(s);S?.kind==="edge"&&o.add(S.edge.id);const e=S&&S.kind!=="edge"?S.box.id:B;if(e)for(const s of n)(s.source===e||s.target===e)&&o.add(s.id);for(const s of n)s.dimmed&&o.delete(s.id);return o},[n,S,K,j,B]);_.useEffect(F,[U,re,ee,S,B,F]);const ze=_.useCallback(()=>{const o=k.current,e=o?.getContext("2d");if(!o||!e)return;const{w:s,h:d,dpr:v}=f.current,b=qe(o),H=getComputedStyle(o),W=new Map,T=m=>{let P=W.get(m);return P===void 0&&(P=H.getPropertyValue(m).trim(),W.set(m,P)),P},{z:M,x:V,y:X}=u.current,ue=m=>({x:m.x*M+V,y:m.y*M+X});e.setTransform(v,0,0,v,0,0),e.clearRect(0,0,s,d);const Se=S&&S.kind!=="edge"?S.box.id:null;e.lineJoin="round";for(const m of n){const P=re.get(m.id);if(!P)continue;const z=P.map(ue),D=ee.has(m.id);e.globalAlpha=m.dimmed?.15:D?.95:.55,e.strokeStyle=m.accent?T(m.accent):D?b.foreground:b.muted,e.lineWidth=D?1.75:1.25,e.beginPath(),e.moveTo(z[0].x,z[0].y);for(const G of z.slice(1))e.lineTo(G.x,G.y);m.directed&&_t(e,z[z.length-2],z[z.length-1],8),e.stroke()}const $e=new ie;for(const m of U.values()){const P=ue(m),z=m.w*M,D=m.h*M,G=P.x-z/2,Y=P.y-D/2;if($e.reserve({x0:G,y0:Y,x1:G+z,y1:Y+D}),G>s||Y>d||G+z<0||Y+D<0)continue;const de=Se===m.id||C.current?.over?.id===m.id;e.globalAlpha=m.dimmed?.25:1,e.beginPath(),e.roundRect(G,Y,z,D,8*M),e.fillStyle=m.muted?b.mutedSurface:b.card,e.fill(),e.lineWidth=de||B===m.id?1.5:1,e.strokeStyle=de||B===m.id?b.primary:b.border,e.stroke();const fe=m.accent&&T(m.accent);if(fe&&(e.save(),e.clip(),e.fillStyle=fe,e.fillRect(G,Y,3*M,D),e.restore()),14*M<5)continue;const te=12*M,J=16*M,ne=m.meta?Y+D/2-8*M:Y+D/2,oe=h.current.get(m.icon??"");oe instanceof HTMLImageElement&&oe.complete&&oe.naturalWidth>0?e.drawImage(oe,G+te,ne-J/2,J,J):typeof oe=="string"&&oe&&(e.font=`${14*M}px system-ui, sans-serif`,e.textBaseline="middle",e.textAlign="left",e.fillText(oe,G+te,ne));const pe=G+te+J+8*M,We=12*M;e.textBaseline="middle",e.textAlign="left";let Ie=G+z-We-pe;if(m.badge){e.font=St.replace("9px",`${9*M}px`);const Fe=ge(e,m.badge.toUpperCase(),Ie*.35),Ne=e.measureText(Fe).width+8*M,He=G+z-We-Ne;e.strokeStyle=b.border,e.lineWidth=1,e.beginPath(),e.roundRect(He,ne-7*M,Ne,14*M,3*M),e.stroke(),e.fillStyle=b.muted,e.fillText(Fe,He+4*M,ne+.5),Ie-=Ne+6*M}e.font=Mt.replace("14px",`${14*M}px`),e.fillStyle=b.foreground,e.fillText(ge(e,m.title,Ie),pe,ne+.5),m.meta&&(e.font=Et.replace("11px",`${11*M}px`),e.fillStyle=b.muted,e.fillText(ge(e,m.meta,G+z-te-pe),pe,Y+D/2+10*M))}const Te=C.current,_e=Te?.from??(Se?U.get(Se):void 0);if(c&&_e&&_e.w*M>=60){const m=ue(Ye(_e));if(e.globalAlpha=1,Te){const P=ue(Te.to);e.strokeStyle=b.primary,e.lineWidth=2,e.setLineDash([6,4]),e.beginPath(),e.moveTo(m.x,m.y),e.lineTo(P.x,P.y),e.stroke(),e.setLineDash([])}e.fillStyle=b.card,e.strokeStyle=b.primary,e.lineWidth=1.5,e.beginPath(),e.arc(m.x,m.y,Be,0,Math.PI*2),e.fill(),e.stroke(),e.beginPath(),e.moveTo(m.x-4,m.y),e.lineTo(m.x+4,m.y),e.moveTo(m.x,m.y-4),e.lineTo(m.x,m.y+4),e.stroke()}e.font=Tt,e.textAlign="center",e.textBaseline="middle";const ct=(m,P,z,D)=>{e.globalAlpha=1,e.fillStyle=b.background,e.strokeStyle=z?b.foreground:b.border,e.lineWidth=1,e.beginPath(),e.roundRect(m.x-D/2,m.y-he/2,D,he,5),e.fill(),e.stroke(),e.fillStyle=z?b.foreground:b.muted,e.fillText(P,m.x,m.y+.5)},at=[...n].sort((m,P)=>Number(ee.has(P.id))-Number(ee.has(m.id)));for(const m of at){const P=re.get(m.id);if(!P||m.dimmed&&!ee.has(m.id))continue;const z=P.map(ue),D=ee.has(m.id),Y=(D?m.details:[m.summary]).map(J=>ge(e,J,200)),de=Math.max(...Y.map(J=>e.measureText(J).width))+14,fe=Y.length*(he+2);if(!D&&M<.45)continue;const te=bt(z,de,fe,$e,D);te&&Y.forEach((J,ne)=>{ct({x:te.x,y:te.y-fe/2+(he+2)*ne+he/2},J,D,de)})}e.globalAlpha=1},[n,re,U,ee,S,B,c]);_.useEffect(()=>{let o=0;const e=()=>{o=requestAnimationFrame(e),y.current&&(y.current=!1,ze())};return o=requestAnimationFrame(e),document.addEventListener("visibilitychange",F),()=>{cancelAnimationFrame(o),document.removeEventListener("visibilitychange",F)}},[ze,F]),_.useEffect(()=>{const o=new MutationObserver(()=>{h.current.clear(),Ze(e=>e+1),F()});return o.observe(document.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),()=>o.disconnect()},[F]);const Me=(o,e,s)=>{const d=u.current,v=Math.min(3,Math.max(.15,d.z*o));ae({z:v,x:e-(e-d.x)*(v/d.z),y:s-(s-d.y)*(v/d.z)})},Ee=o=>{const e=k.current?.getBoundingClientRect();return{x:o.clientX-(e?.left??0),y:o.clientY-(e?.top??0)}},nt=o=>{if(o.button!==0&&o.pointerType==="mouse")return;o.currentTarget.setPointerCapture(o.pointerId);const e=Ee(o);if(o.pointerType==="touch"&&(O.current.set(o.pointerId,e),O.current.size===2)){const[v,b]=[...O.current.values()];p.current=null,C.current=null,L.current={d:Math.hypot(v.x-b.x,v.y-b.y)||1,mid:{x:(v.x+b.x)/2,y:(v.y+b.y)/2}};return}const s=ke(e.x,e.y),d={start:e,last:e,hit:s,moved:!1};if(s?.kind==="handle")C.current={from:s.box,to:le(e.x,e.y),over:null};else if(s?.kind==="box"){const v=le(e.x,e.y);d.grab={x:s.box.x-v.x,y:s.box.y-v.y}}p.current=d},ot=o=>{const e=Ee(o);O.current.has(o.pointerId)&&O.current.set(o.pointerId,e);const s=L.current;if(s&&O.current.size===2){const[T,M]=[...O.current.values()],V=Math.hypot(T.x-M.x,T.y-M.y)||1,X={x:(T.x+M.x)/2,y:(T.y+M.y)/2};ae({...u.current,x:u.current.x+X.x-s.mid.x,y:u.current.y+X.y-s.mid.y}),Me(V/s.d,X.x,X.y),L.current={d:V,mid:X};return}const d=p.current;if(!d){const T=ke(e.x,e.y);$(V=>It(V,T)?V:T);const M=k.current;M&&(M.style.cursor=T?.kind==="handle"?"crosshair":T?"pointer":"grab");return}const v=e.x-d.last.x,b=e.y-d.last.y;if(d.last=e,!d.moved&&Math.hypot(e.x-d.start.x,e.y-d.start.y)>4&&(d.moved=!0),!d.moved)return;const H=C.current;if(H){H.to=le(e.x,e.y);const T=ke(e.x,e.y);H.over=T?.kind==="box"?T.box:null,F();return}const W=d.hit;if(W?.kind==="box"&&d.grab){const T=le(e.x,e.y),M=t.find(X=>X.id===W.box.id);if(!M)return;const V={x:T.x+d.grab.x,y:T.y+d.grab.y};I(X=>new Map(X).set(M.id,{at:V,from:{x:M.x,y:M.y}}));return}ae({...u.current,x:u.current.x+v,y:u.current.y+b}),k.current&&(k.current.style.cursor="grabbing")},rt=o=>{if(O.current.delete(o.pointerId),L.current){O.current.size<2&&(L.current=null),p.current=null;return}const e=p.current;p.current=null;const s=C.current;if(C.current=null,!e)return;if(k.current&&(k.current.style.cursor="grab"),s){F(),s.over&&c&&c(s.from.id,s.over.id);return}if(e.moved)return;const d=e.hit;d?.kind==="box"?i(d.box.id):d?.kind==="edge"?R(v=>v===d.edge.id?null:d.edge.id):R(null)},st=o=>{O.current.delete(o.pointerId),L.current=null,p.current=null,C.current=null,F()};_.useEffect(()=>{const o=k.current;if(!o)return;const e=s=>{s.preventDefault();const d=Ee(s);s.ctrlKey||s.metaKey?Me(Math.exp(-s.deltaY*(s.ctrlKey?.01:.002)),d.x,d.y):ae({...u.current,x:u.current.x-s.deltaX,y:u.current.y-s.deltaY})};return o.addEventListener("wheel",e,{passive:!1}),()=>o.removeEventListener("wheel",e)});const De=o=>Me(o,f.current.w/2,f.current.h/2),it=[...new Set(t.map(o=>o.icon??""))];return N.jsxs("div",{ref:E,className:ve("relative h-full w-full overflow-hidden",w),children:[N.jsx("canvas",{ref:k,"aria-hidden":"true",className:"block h-full w-full cursor-grab touch-none",onPointerDown:nt,onPointerMove:ot,onPointerUp:rt,onPointerCancel:st,onPointerLeave:()=>{p.current||$(null)}}),N.jsxs("ul",{ref:g,"aria-label":r,className:"sr-only",children:[it.map(o=>N.jsx("li",{"aria-hidden":"true","data-icon-key":o,children:x(o)},`icon:${o}`)),t.map(o=>N.jsx("li",{children:N.jsx("button",{type:"button",onClick:()=>i(o.id),onFocus:()=>Qe(o.id),onBlur:()=>Oe(null),children:l(o)})},o.id)),n.map(o=>N.jsx("li",{"data-revealed":ee.has(o.id)||void 0,children:N.jsx("button",{type:"button","aria-pressed":K===o.id,onClick:()=>R(e=>e===o.id?null:o.id),onFocus:()=>{Q(o.id);const e=re.get(o.id);e&&Ce(e.map(s=>({...s,w:0,h:0})))},onBlur:()=>Q(null),children:o.ariaLabel})},o.id))]}),N.jsxs("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:[N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom in",onClick:()=>De(1.25),children:N.jsx(lt,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Zoom out",onClick:()=>De(.8),children:N.jsx(ut,{className:"h-3.5 w-3.5"})}),N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Fit to view",onClick:ce,children:N.jsx(dt,{className:"h-3.5 w-3.5"})}),me.size>0?N.jsx(xe,{type:"button",variant:"outline",size:"icon",className:"h-7 w-7","aria-label":"Reset layout",onClick:()=>I(new Map),children:N.jsx(ft,{className:"h-3.5 w-3.5"})}):null]})]})}const Ye=t=>({x:t.x+t.w/2,y:t.y});function It(t,n){return!t||!n?t===n:t.kind==="edge"||n.kind==="edge"?t.kind==="edge"&&n.kind==="edge"&&t.edge.id===n.edge.id:t.kind===n.kind&&t.box.id===n.box.id}function nn({label:t,fill:n=!1}){return N.jsxs("div",{role:"status","aria-label":t,"aria-busy":"true",className:ve("flex min-w-0 flex-col gap-3",n&&"min-h-0 flex-1"),children:[N.jsx("div",{className:"flex min-w-0 items-center gap-3",children:N.jsx("div",{"aria-hidden":"true",className:"min-w-0 flex-1",children:N.jsx(ye,{className:"h-5 w-3/4 max-w-xl rounded-none"})})}),N.jsx("div",{className:ve("relative flex min-h-0 flex-col",n&&"flex-1"),"aria-hidden":"true",children:N.jsxs("div",{className:ve("relative min-h-[420px]",n?"flex-1":"h-[70vh]"),children:[N.jsxs("div",{className:"absolute top-1/2 left-1/2 flex h-16 w-52 -translate-x-1/2 -translate-y-1/2 items-center gap-3 rounded-xl border border-border bg-card px-4",children:[N.jsx(ye,{className:"h-4 w-4 shrink-0 rounded-none"}),N.jsxs("div",{className:"flex flex-1 flex-col gap-2",children:[N.jsx(ye,{className:"h-3.5 w-24 rounded-none"}),N.jsx(ye,{className:"h-2.5 w-32 rounded-none"})]})]}),N.jsx("div",{className:"absolute bottom-3 left-3 flex flex-col gap-1",children:["in","out","fit"].map(r=>N.jsx("div",{className:"flex h-7 w-7 items-center justify-center border border-input bg-background",children:N.jsx(ye,{className:"h-3 w-3 rounded-none"})},r))})]})})]})}function we(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Re={exports:{}},Ke;function Nt(){return Ke||(Ke=1,(function(t,n){(function(r){t.exports=r()})(function(){return(function(){function r(i,l,c){function x(k,g){if(!l[k]){if(!i[k]){var u=typeof we=="function"&&we;if(!g&&u)return u(k,!0);if(w)return w(k,!0);var f=new Error("Cannot find module '"+k+"'");throw f.code="MODULE_NOT_FOUND",f}var y=l[k]={exports:{}};i[k][0].call(y.exports,function(h){var p=i[k][1][h];return x(p||h)},y,y.exports,r,i,l,c)}return l[k].exports}for(var w=typeof we=="function"&&we,E=0;E<c.length;E++)x(c[E]);return x}return r})()({1:[function(r,i,l){Object.defineProperty(l,"__esModule",{value:!0}),l.default=void 0;function c(f){"@babel/helpers - typeof";return c=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(y){return typeof y}:function(y){return y&&typeof Symbol=="function"&&y.constructor===Symbol&&y!==Symbol.prototype?"symbol":typeof y},c(f)}function x(f,y){if(!(f instanceof y))throw new TypeError("Cannot call a class as a function")}function w(f,y){for(var h=0;h<y.length;h++){var p=y[h];p.enumerable=p.enumerable||!1,p.configurable=!0,"value"in p&&(p.writable=!0),Object.defineProperty(f,k(p.key),p)}}function E(f,y,h){return y&&w(f.prototype,y),Object.defineProperty(f,"prototype",{writable:!1}),f}function k(f){var y=g(f,"string");return c(y)=="symbol"?y:y+""}function g(f,y){if(c(f)!="object"||!f)return f;var h=f[Symbol.toPrimitive];if(h!==void 0){var p=h.call(f,y);if(c(p)!="object")return p;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(f)}l.default=(function(){function f(){var y=this,h=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},p=h.defaultLayoutOptions,L=p===void 0?{}:p,O=h.algorithms,C=O===void 0?["layered","stress","mrtree","radial","force","disco","sporeOverlap","sporeCompaction","rectpacking"]:O,A=h.workerFactory,q=h.workerUrl;if(x(this,f),this.defaultLayoutOptions=L,this.initialized=!1,typeof q>"u"&&typeof A>"u")throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.");var a=A;typeof q<"u"&&typeof A>"u"&&(a=function($){return new Worker($)});var I=a(q);if(typeof I.postMessage!="function")throw new TypeError("Created worker does not provide the required 'postMessage' function.");this.worker=new u(I),this.worker.postMessage({cmd:"register",algorithms:C}).then(function(S){return y.initialized=!0}).catch(console.err)}return E(f,[{key:"layout",value:function(h){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},L=p.layoutOptions,O=L===void 0?this.defaultLayoutOptions:L,C=p.logging,A=C===void 0?!1:C,q=p.measureExecutionTime,a=q===void 0?!1:q;return h?this.worker.postMessage({cmd:"layout",graph:h,layoutOptions:O,options:{logging:A,measureExecutionTime:a}}):Promise.reject(new Error("Missing mandatory parameter 'graph'."))}},{key:"knownLayoutAlgorithms",value:function(){return this.worker.postMessage({cmd:"algorithms"})}},{key:"knownLayoutOptions",value:function(){return this.worker.postMessage({cmd:"options"})}},{key:"knownLayoutCategories",value:function(){return this.worker.postMessage({cmd:"categories"})}},{key:"terminateWorker",value:function(){this.worker&&this.worker.terminate()}}])})();var u=(function(){function f(y){var h=this;if(x(this,f),y===void 0)throw new Error("Missing mandatory parameter 'worker'.");this.resolvers={},this.worker=y,this.worker.onmessage=function(p){setTimeout(function(){h.receive(h,p)},0)}}return E(f,[{key:"postMessage",value:function(h){var p=this.id||0;this.id=p+1,h.id=p;var L=this;return new Promise(function(O,C){L.resolvers[p]=function(A,q){A?(L.convertGwtStyleError(A),C(A)):O(q)},L.worker.postMessage(h)})}},{key:"receive",value:function(h,p){var L=p.data,O=h.resolvers[L.id];O&&(delete h.resolvers[L.id],L.error?O(L.error):O(null,L.data))}},{key:"terminate",value:function(){this.worker&&this.worker.terminate()}},{key:"convertGwtStyleError",value:function(h){if(h){var p=h.__java$exception;p&&(p.cause&&p.cause.backingJsObject&&(h.cause=p.cause.backingJsObject,this.convertGwtStyleError(h.cause)),delete h.__java$exception)}}}])})()},{}],2:[function(r,i,l){var c=r("./elk-api.js").default;Object.defineProperty(i.exports,"__esModule",{value:!0}),i.exports=c,c.default=c},{"./elk-api.js":1}]},{},[2])(2)})})(Re)),Re.exports}var Rt=Nt();const jt=ht(Rt);function Lt(t){return new Worker("/assets/elk-worker.min-BENGc9gn.js",{name:t?.name})}const Ot=200,Ct=320,Xe=56,At=7.4,Pt=5.9,zt=84,Dt=48;function $t(t,n){return Math.round(Math.min(Ct,Math.max(Ot,zt+t.length*At,Dt+n.length*Pt)))}function Wt(t,n){const r=[];return t>0&&r.push(`${t} ${t===1?"field":"fields"}`),typeof n=="number"&&r.push(`${n.toLocaleString()} ${n===1?"record":"records"}`),r.join(" · ")}function Ue(t,n){return t.slug<n.slug?-1:t.slug>n.slug?1:0}function Ft(t,n){const r=new Set;return t.filter(i=>i.status!=="active"||i.organization_slug&&i.organization_slug!==n||r.has(i.slug)?!1:(r.add(i.slug),!0))}function Ht(t){const n=t.metadata_schema;if(!n||typeof n!="object")return 0;const r=n.properties;return!r||typeof r!="object"?0:Object.keys(r).length}function Gt(t){const{entityTypes:n,relationshipTypes:r,rulesBySlug:i}=t,l=t.ownerSlug??"",c=[...n].sort(Ue),x=Ft(r,l).sort(Ue),w=a=>!a.organization_slug||a.organization_slug===l,E=a=>a.organization_slug||l,k=new Map;for(const a of c)k.set(a.slug,[...k.get(a.slug)??[],a]);const g=a=>(k.get(a.slug)?.length??0)>1?`${E(a)}:${a.slug}`:a.slug,u=new Set(c.filter(w).map(g)),f=a=>{const I=k.get(a)??[];return I.find(w)??(I.length===1?I[0]:void 0)},y=new Set(u),h=x.flatMap(a=>[...i[a.slug]??[]].sort((I,S)=>I.id-S.id).flatMap(I=>{const S=f(I.source_entity_type_slug),$=f(I.target_entity_type_slug);if(!S||!$)return[];const K=g(S),R=g($);return!u.has(K)&&!u.has(R)?[]:(y.add(K),y.add(R),[{rt:a,source:K,target:R}])})),p=c.filter(a=>y.has(g(a))),L=[],O=new Map,C=new Map;for(const{rt:a,source:I,target:S}of h){const $=`${a.slug}|${I}|${S}`,K=C.get($);if(K){K.ruleCount+=1;continue}const R={slug:a.slug,label:a.name||a.slug,ruleCount:1};C.set($,R);const j=`${I}|${S}`,Q=O.get(j);if(Q){Q.data.relationships.push(R),Q.data.isSymmetric=Q.data.isSymmetric&&a.is_symmetric;continue}const B={id:`pair:${I}|${S}`,source:I,target:S,data:{relationships:[R],isSymmetric:a.is_symmetric}};O.set(j,B),L.push(B)}const A=new Map;for(const{rt:a,source:I,target:S}of h){const $=A.get(a.slug)??new Set;$.add(`${I}|${S}`),A.set(a.slug,$)}for(const{rt:a}of h)if(A.get(a.slug)?.size===1&&typeof a.relationship_count=="number")for(const I of C.values())I.slug===a.slug&&(I.linkCount=a.relationship_count);return{nodes:p.map(a=>{const I=a.name||a.slug,S=Ht(a),$=Wt(S,a.entity_count);return{id:g(a),width:$t(I,$),height:Xe,data:{slug:a.slug,label:I,icon:a.icon,isSystem:mt(a),organizationSlug:w(a)?void 0:E(a),metaLabel:$}}}),edges:L}}const Z=24,Bt=72,qt=16,Yt=48,Kt=64,je=16,Ut=720;function Vt(t,n){const r=new Map(t.map(c=>[c.id,c.id])),i=c=>{const x=r.get(c)??c;if(x===c)return c;const w=i(x);return r.set(c,w),w};for(const c of n)r.set(i(c.source),i(c.target));const l=new Map;for(const c of t){const x=i(c.id);l.set(x,[...l.get(x)??[],c])}return[...l.values()].sort((c,x)=>x.length-c.length)}function Xt(t,n,r,i){const l=new Map(t.flatMap((g,u)=>g.map(f=>[f.id,u]))),c=t.map(()=>({top:1/0,bottom:-1/0})),x=(g,u,f)=>{const y=c[l.get(g)??0];y.top=Math.min(y.top,u),y.bottom=Math.max(y.bottom,f)};for(const g of n)x(g.id,g.position.y,g.position.y+g.height);for(const g of r)for(const u of i.get(g.id)??[])x(g.source,u.y,u.y);let w=Z;const E=c.map(({top:g,bottom:u})=>{const f=w-g;return w=u+f+Yt,f}),k=g=>E[l.get(g)??0];for(const g of r){const u=i.get(g.id);u&&i.set(g.id,u.map(f=>({x:f.x,y:f.y+k(g.source)})))}return n.map(g=>({...g,position:{x:g.position.x,y:g.position.y+k(g.id)}}))}function Jt(t,n){const r=Z,i=Math.max(r+Ut,...n.map(w=>w.position.x+w.width));let l=n.length>0?Math.max(...n.map(w=>w.position.y+w.height))+Kt:Z;const c=[...new Set(t.map(w=>w.lane??0))].sort((w,E)=>w-E),x=[];for(const w of c){let E=r,k=0;for(const g of t.filter(u=>(u.lane??0)===w))E>r&&E+g.width>i&&(E=r,l+=k+je,k=0),x.push({...g,position:{x:E,y:l}}),E+=g.width+je,k=Math.max(k,g.height);l+=k+je*2}return x}let Ve=null;function Zt(){return Ve??=new jt({workerFactory:()=>new Lt}),Ve}const Le={"elk.algorithm":"layered","elk.direction":"RIGHT","elk.edgeRouting":"ORTHOGONAL","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"24","elk.layered.spacing.nodeNodeBetweenLayers":"80","elk.spacing.nodeNode":"48","elk.spacing.edgeEdge":"14","elk.spacing.edgeNode":"24","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.crossingMinimization.semiInteractive":"true"};async function Qt(t,{elk:n=Zt(),targetAspect:r}={}){const i=new Set;for(const a of t.edges)i.add(a.source),i.add(a.target);const l=t.nodes.some(a=>a.lane!==void 0),c=t.nodes.filter(a=>i.has(a.id)),x=l?Vt(c,t.edges):[c],w=x.flat(),E=t.nodes.filter(a=>!i.has(a.id)),k=l?[]:E,g=l?E:[],u=k.reduce((a,I)=>Math.max(a,I.width),0),f=k.length>0?Z+u+Bt:0,y=a=>({x:a.x+Z+f,y:a.y+Z});let h=[];const p=new Map;if(w.length>0){const a=t.edges.filter(R=>R.source!==R.target),I=R=>n.layout({id:"root",layoutOptions:l?{...R,"elk.partitioning.activate":"true","elk.separateConnectedComponents":"false"}:R,children:w.map(j=>({id:j.id,width:j.width,height:j.height,...l?{layoutOptions:{"elk.partitioning.partition":String(j.lane??1)}}:{}})),edges:a.map(j=>({id:j.id,sources:[j.layoutReversed?j.target:j.source],targets:[j.layoutReversed?j.source:j.target]}))});let S=await I(Le);const $=r&&S.width&&S.height?r*S.width/S.height:1;if($>1.08){const R=Number(Le["elk.spacing.nodeNode"]),j=Math.min($,2.2);S=await I({...Le,"elk.spacing.nodeNode":String(Math.round(Math.min(180,R*j+Xe*(j-1))))})}const K=new Map((S.children??[]).map(R=>[R.id,R]));h=w.map(R=>{const j=K.get(R.id);return{...R,position:y({x:j?.x??0,y:j?.y??0})}});for(const R of S.edges??[]){const j=(R.sections??[]).flatMap(B=>[B.startPoint,...B.bendPoints??[],B.endPoint]);if(j.length<2)continue;const Q=t.edges.find(B=>B.id===R.id)?.layoutReversed;p.set(R.id,(Q?[...j].reverse():j).map(y))}}let L=Z;const O=k.map(a=>{const I={x:Z,y:L};return L+=a.height+qt,{...a,position:I}});l&&(h=Xt(x,h,t.edges,p));const C=Jt(g,h),A=new Map([...h,...O,...C].map(a=>[a.id,a]));return{nodes:t.nodes.map(a=>A.get(a.id)??{...a,position:{x:Z,y:Z}}),edges:t.edges.map(a=>({...a,route:p.get(a.id)??null}))}}function on(t,n){return Qt(Gt(t),n)}export{nn as G,Xe as H,on as a,Gt as b,tn as c,Qt as l,$t as n,Ft as s};
|
|
2
|
+
//# sourceMappingURL=entity-schema-graph-lMMx3HhR.js.map
|
package/dist/owletto/dist/assets/{entity-type-page-MgZ7_0oh.js → entity-type-page-CkQm0yEu.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{G as $,cD as de,dr as ue,cG as H,j as e,bS as me,r as h,cE as xe,cF as he,aF as pe,aG as ge,B as g,cU as U,aI as fe,T as S,br as q,bs as P,bt as M,bu as L,bv as k,U as E,ai as je,hb as ve,hc as Ne,a2 as K,d0 as ye,X as W,dj as be,C as we,a6 as Se,cc as ae,fm as ne,hd as Ce,a3 as re,he as ke,gm as Ee,c6 as _e,c7 as Y,cb as Te,f5 as Re,bT as Oe,hf as De,i as Q,dE as Ae,dF as Fe,dG as ze,L as le,d7 as qe,dH as Pe,A as Me}from"./index-CdDNNAx2.js";import{f as B}from"./event-kind-options-fHAIXu24.js";import{C as ie}from"./code-editor-BdRMYojw.js";function Le({entityType:s}){const{orgContext:a}=$(),{data:o,isLoading:n}=de(a),{data:r}=ue(a),t=(o||[]).filter(u=>u.status==="active"),i=t.filter(u=>!u.organization_slug||u.organization_slug===a?.slug),c=i.filter(u=>u.purpose!==H),d=i.filter(u=>u.purpose===H),x=t.filter(u=>u.organization_slug&&u.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(me,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:c,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),x.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:x,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ve,{entityTypeSlug:s.slug,relationshipTypes:c,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Ie,{relationshipType:r,entityTypeSlug:s,allEntityTypes:o,readOnly:n},r.id))})}function Ie({relationshipType:s,entityTypeSlug:a,allEntityTypes:o,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=ve(s.slug,r),i=Ne(),c=(t||[]).filter(x=>x.source_entity_type_slug===a||x.target_entity_type_slug===a);if(c.length===0)return null;const d=new Map(o.map(x=>[x.slug,x.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx(K,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(K,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),c.map(x=>e.jsx(Ue,{rule:x,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(x.id),isRemoving:i.isPending,readOnly:n},x.id))]})}function Ue({rule:s,entityTypeSlug:a,entityTypeNameMap:o,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,c]=h.useState(!1),d=s.source_entity_type_slug===a,x=d?s.target_entity_type_slug:s.source_entity_type_slug,u=o.get(x)||x;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":u}),e.jsx(ye,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?u:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(g,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>c(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>c(!0),disabled:r,children:e.jsx(W,{className:"h-3 w-3"})})})]})}function Ve({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o}){const{orgContext:n}=$(),r=o.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=h.useState(!1),[c,d]=h.useState("existing"),[x,u]=h.useState(""),[N,b]=h.useState(""),[w,y]=h.useState("source"),[v,f]=h.useState(""),[T,R]=h.useState(""),[D,O]=h.useState(!1),[A,C]=h.useState(null),m=xe(),p=he(),j=()=>{d("existing"),u(""),b(""),y("source"),f(""),R(""),O(!1),C(null)},_=l=>{i(l),l||j()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),V=async()=>{C(null);try{let l=x;if(c==="new"){if(!v.trim()){C("Name is required");return}const G=T.trim()||F(v);if(!G){C("Slug is required");return}l=(await m.mutateAsync({slug:G,name:v.trim(),is_symmetric:D})).relationship_type.slug}if(!l){C("Select a relationship type");return}if(!N){C("Select a target entity type");return}const I=w==="source"?s:N,oe=w==="source"?N:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:oe}),_(!1)}catch(l){C(l instanceof Error?l.message:"An error occurred")}},z=m.isPending||p.isPending;return e.jsxs(pe,{open:t,onOpenChange:_,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(g,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(fe,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(g,{variant:c==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(g,{variant:c==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),c==="existing"?e.jsxs(q,{value:x,onValueChange:u,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:v,onChange:l=>{f(l.target.value),T||R("")}}),e.jsx(E,{placeholder:v?F(v)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:T,onChange:l=>R(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>O(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:w,onValueChange:l=>y(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(S,{className:"text-xs",children:[w==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:N,onValueChange:b,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(g,{size:"sm",className:"w-full",onClick:V,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Be({options:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const i=o.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((c,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,c)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(c),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}const Je=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function $e({examples:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const t=o.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((c,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}function We({field:s,onChange:a,onDelete:o}){const[n,r]=h.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(be,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsx(E,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Je.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(Se,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:o,children:e.jsx(ae,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Be,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(E,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(E,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx($e,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function X({value:s,onChange:a,readonly:o,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{value:s,onChange:a,readonly:o,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Z(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const o of Object.values(a)){if(!o||typeof o!="object")return!1;const n=o,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function ce(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},o=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,c={id:ce(),name:n,required:o.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...c,type:"enum",enumOptions:r.enum||[]}:{...c,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const o=Number(s);return Number.isNaN(o)?s:o}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function Ge(s,a="auto"){const o={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(c=>se(c,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(c=>({value:c,label:c.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(c.toLowerCase())}))}:{}}),o[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:o};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"?a:"auto"}function He({value:s,onChange:a,readonly:o=!1}){const[n,r]=h.useState("visual"),[t,i]=h.useState([]),[c,d]=h.useState("auto"),[x,u]=h.useState(""),[N,b]=h.useState(null),[w,y]=h.useState(!1),v=h.useRef(!1);h.useEffect(()=>{if(v.current){v.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),u(""),y(!1);return}const m=JSON.stringify(s,null,2);u(m),d(te(s)),Z(s)?(i(ee(s)),y(!1)):(y(!0),r("json"))},[s]);const f=h.useCallback((m,p)=>{v.current=!0;const j=Ge(m,p),_=m.some(F=>F.name.trim());u(_?JSON.stringify(j,null,2):""),a(_?j:void 0)},[a]),T=h.useCallback(m=>{i(m),f(m,c)},[f,c]),R=h.useCallback(m=>{d(m),f(t,m)},[f,t]),D=h.useCallback(m=>{if(v.current=!0,u(m),!m.trim()){b(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(m);b(null),d(te(p)),Z(p)?(i(ee(p)),y(!1)):y(!0),a(p)}catch(p){b(p instanceof Error?p.message:"Invalid JSON")}},[a]),O=()=>{T([...t,{id:ce(),name:"",type:"string",required:!1}])},A=(m,p)=>{const j=[...t];j[m]=p,T(j)},C=m=>{T(t.filter((p,j)=>j!==m))};return o?e.jsx(X,{value:x,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!w&&r("visual"),disabled:w,className:"h-7 text-xs",children:[e.jsx(ne,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(g,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),w&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(re,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((m,p)=>e.jsx(We,{field:m,onChange:j=>A(p,j),onDelete:()=>C(p)},m.id)),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:O,className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(m=>m.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, otherwise table)."})]}),e.jsxs(q,{value:c,onValueChange:m=>R(m),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"})]})]})]})]}):e.jsx(X,{value:x,onChange:D,error:N})]})}function Ke(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ye({entityType:s,onCancel:a,onSaved:o}){const n=!!s,r=ke(),t=Ee(),i=s?.slug??"new",c=_e(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,x]=c.field("name"),[u,N]=c.field("slug"),[b,w]=c.field("description"),[y,v]=c.field("icon"),[f,T]=c.field("color"),[R,D]=c.field("metadataSchema"),[O,A]=c.field("backingSql"),[C,m]=Y(i,n),[p,j]=Y(i,null),_=O.trim().length>0,F=l=>{x(l),!n&&!C&&N(Ke(l))},V=async()=>{if(!c.canSubmit)return;if(j(null),!d.trim()){j("Name is required");return}if(!n&&!u.trim()){j("Slug is required");return}const l=_?{sql:O.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:R,backing:l}):await r.mutateAsync({slug:u.trim(),name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:R,backing:l}),o()}catch(I){j(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(Te,{visible:c.hasConflict,onReload:c.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-name",children:"Name"}),e.jsx(E,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-slug",children:"Slug"}),e.jsx(E,{id:"et-slug",value:u,onChange:l=>{m(!0),N(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:b,onChange:l=>w(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(E,{id:"et-icon",value:y,onChange:l=>v(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{id:"et-color",value:f,onChange:l=>T(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),f&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:f}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ie,{value:O,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),_?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ne,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(S,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(He,{value:R,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Le,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Oe,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(g,{onClick:V,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function as({entityType:s,onClose:a,orgContext:o,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,c]=h.useState(!1),[d,x]=h.useState(null),u=De(),N=s?.entity_count??0,b=N>0,w=async()=>{if(s){x(null);try{await u.mutateAsync(s.slug),a()}catch(f){x(f instanceof Error?f.message:"Failed to delete")}}},y=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",v=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Q("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h1",{className:Q("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:y}),t&&o.slug&&s?e.jsx(Qe,{owner:o.slug,typeSlug:s.slug}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:v})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ye,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[o.slug&&s?e.jsx(Xe,{owner:o.slug,entityType:s}):null,!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:i?e.jsxs("div",{className:"space-y-3",children:[b?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(re,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",N===1?"is":"are"," ",N," entit",N===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),d&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:d}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>{c(!1),x(null)},children:"Cancel"}),e.jsx(g,{variant:"destructive",size:"sm",onClick:w,disabled:b||u.isPending,children:u.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(g,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>c(!0),children:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}function Qe({owner:s,typeSlug:a}){return e.jsx(Ae,{delayDuration:200,children:e.jsxs(Fe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(g,{asChild:!0,variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground",children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a},children:[e.jsx(qe,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Activity"})]})})}),e.jsx(Pe,{children:"Activity"})]})})}function Xe({owner:s,entityType:a}){const o=Object.entries(a.event_kinds??{}).sort(([n],[r])=>B(n).localeCompare(B(r)));return e.jsxs("section",{"aria-label":"Event kinds",className:"border-t border-border pt-4 space-y-2",children:[e.jsxs("h2",{className:"text-sm font-medium",children:["Event kinds on ",a.name]}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"This type declares no event kinds."}):e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:o.map(([n,r])=>e.jsx("li",{children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a.slug,semantic_types:n},className:"flex items-center gap-3 px-3 py-2 text-sm transition-colors hover:bg-accent/50",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-medium",children:B(n)}),r?.description?e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:r.description}):null]}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:["View in Activity",e.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":"true"})]})]})},n))})]})}export{as as E};
|
|
2
|
-
//# sourceMappingURL=entity-type-page-
|
|
1
|
+
import{M as $,cz as de,dq as ue,cC as K,j as e,bQ as me,r as h,cA as xe,cB as he,aE as pe,aF as ge,B as g,dg as I,aH as fe,Z as S,bq as q,br as P,bs as M,bt as L,bu as k,$ as E,al as je,h7 as ve,h8 as Ne,a7 as Y,cX as ye,X as W,dh as be,C as we,ab as Se,c9 as ae,fk as ne,h9 as Ce,a8 as re,ha as ke,gk as Ee,c3 as _e,c4 as Q,c8 as Re,f3 as Te,bR as Oe,hb as De,i as X,dA as Ae,dB as Fe,dC as ze,L as le,d5 as qe,dD as Pe,A as Me}from"./index-DByaMzsG.js";import{f as U}from"./event-kind-options-fHAIXu24.js";import{C as ie}from"./code-editor-mrKkAfcE.js";function Le({entityType:s}){const{orgContext:a}=$(),{data:o,isLoading:n}=de(a),{data:r}=ue(a),t=(o||[]).filter(u=>u.status==="active"),i=t.filter(u=>!u.organization_slug||u.organization_slug===a?.slug),c=i.filter(u=>u.purpose!==K),d=i.filter(u=>u.purpose===K),x=t.filter(u=>u.organization_slug&&u.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(me,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:c,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),x.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:x,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Be,{entityTypeSlug:s.slug,relationshipTypes:c,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Ve,{relationshipType:r,entityTypeSlug:s,allEntityTypes:o,readOnly:n},r.id))})}function Ve({relationshipType:s,entityTypeSlug:a,allEntityTypes:o,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=ve(s.slug,r),i=Ne(),c=(t||[]).filter(x=>x.source_entity_type_slug===a||x.target_entity_type_slug===a);if(c.length===0)return null;const d=new Map(o.map(x=>[x.slug,x.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx(Y,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(Y,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),c.map(x=>e.jsx(Ie,{rule:x,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(x.id),isRemoving:i.isPending,readOnly:n},x.id))]})}function Ie({rule:s,entityTypeSlug:a,entityTypeNameMap:o,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,c]=h.useState(!1),d=s.source_entity_type_slug===a,x=d?s.target_entity_type_slug:s.source_entity_type_slug,u=o.get(x)||x;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":u}),e.jsx(ye,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?u:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(g,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>c(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(g,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>c(!0),disabled:r,children:e.jsx(W,{className:"h-3 w-3"})})})]})}function Be({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:o}){const{orgContext:n}=$(),r=o.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=h.useState(!1),[c,d]=h.useState("existing"),[x,u]=h.useState(""),[N,b]=h.useState(""),[w,y]=h.useState("source"),[v,f]=h.useState(""),[R,T]=h.useState(""),[D,O]=h.useState(!1),[A,C]=h.useState(null),m=xe(),p=he(),j=()=>{d("existing"),u(""),b(""),y("source"),f(""),T(""),O(!1),C(null)},_=l=>{i(l),l||j()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),B=async()=>{C(null);try{let l=x;if(c==="new"){if(!v.trim()){C("Name is required");return}const H=R.trim()||F(v);if(!H){C("Slug is required");return}l=(await m.mutateAsync({slug:H,name:v.trim(),is_symmetric:D})).relationship_type.slug}if(!l){C("Select a relationship type");return}if(!N){C("Select a target entity type");return}const V=w==="source"?s:N,oe=w==="source"?N:s;await p.mutateAsync({slug:l,source_entity_type_slug:V,target_entity_type_slug:oe}),_(!1)}catch(l){C(l instanceof Error?l.message:"An error occurred")}},z=m.isPending||p.isPending;return e.jsxs(pe,{open:t,onOpenChange:_,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(g,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(I,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(fe,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(g,{variant:c==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(g,{variant:c==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),c==="existing"?e.jsxs(q,{value:x,onValueChange:u,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:v,onChange:l=>{f(l.target.value),R||T("")}}),e.jsx(E,{placeholder:v?F(v)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:R,onChange:l=>T(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>O(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:w,onValueChange:l=>y(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(S,{className:"text-xs",children:[w==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:N,onValueChange:b,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(g,{size:"sm",className:"w-full",onClick:B,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({options:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const i=o.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((c,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,c)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(c),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(I,{className:"h-3 w-3"})})]})]})}const Je=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function $e({examples:s,onChange:a}){const[o,n]=h.useState(""),r=()=>{const t=o.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((c,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(E,{value:o,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(g,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(I,{className:"h-3 w-3"})})]})]})}function We({field:s,onChange:a,onDelete:o}){const[n,r]=h.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(be,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"})}),e.jsx(E,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Je.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(Se,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(g,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:o,children:e.jsx(ae,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ue,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(E,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(E,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx($e,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:o,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ie,{value:s,onChange:a,readonly:o,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function G(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const o of Object.values(a)){if(!o||typeof o!="object")return!1;const n=o,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function ce(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},o=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,c={id:ce(),name:n,required:o.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...c,type:"enum",enumOptions:r.enum||[]}:{...c,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const o=Number(s);return Number.isNaN(o)?s:o}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function He(s,a="auto"){const o={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(c=>se(c,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(c=>({value:c,label:c.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(c.toLowerCase())}))}:{}}),o[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:o};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"?a:"auto"}function Ke({value:s,onChange:a,readonly:o=!1}){const[n,r]=h.useState("visual"),[t,i]=h.useState([]),[c,d]=h.useState("auto"),[x,u]=h.useState(""),[N,b]=h.useState(null),[w,y]=h.useState(!1),v=h.useRef(!1);h.useEffect(()=>{if(v.current){v.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),u(""),y(!1);return}const m=JSON.stringify(s,null,2);u(m),d(te(s)),G(s)?(i(ee(s)),y(!1)):(y(!0),r("json"))},[s]);const f=h.useCallback((m,p)=>{v.current=!0;const j=He(m,p),_=m.some(F=>F.name.trim());u(_?JSON.stringify(j,null,2):""),a(_?j:void 0)},[a]),R=h.useCallback(m=>{i(m),f(m,c)},[f,c]),T=h.useCallback(m=>{d(m),f(t,m)},[f,t]),D=h.useCallback(m=>{if(v.current=!0,u(m),!m.trim()){b(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(m);b(null),d(te(p)),G(p)?(i(ee(p)),y(!1)):y(!0),a(p)}catch(p){b(p instanceof Error?p.message:"Invalid JSON")}},[a]),O=()=>{R([...t,{id:ce(),name:"",type:"string",required:!1}])},A=(m,p)=>{const j=[...t];j[m]=p,R(j)},C=m=>{R(t.filter((p,j)=>j!==m))};return o?e.jsx(Z,{value:x,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!w&&r("visual"),disabled:w,className:"h-7 text-xs",children:[e.jsx(ne,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(g,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),w&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(re,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((m,p)=>e.jsx(We,{field:m,onChange:j=>A(p,j),onDelete:()=>C(p)},m.id)),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:O,className:"w-full",children:[e.jsx(I,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(m=>m.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, otherwise table)."})]}),e.jsxs(q,{value:c,onValueChange:m=>T(m),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"})]})]})]})]}):e.jsx(Z,{value:x,onChange:D,error:N})]})}function Ye(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Qe({entityType:s,onCancel:a,onSaved:o}){const n=!!s,r=ke(),t=Ee(),i=s?.slug??"new",c=_e(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,x]=c.field("name"),[u,N]=c.field("slug"),[b,w]=c.field("description"),[y,v]=c.field("icon"),[f,R]=c.field("color"),[T,D]=c.field("metadataSchema"),[O,A]=c.field("backingSql"),[C,m]=Q(i,n),[p,j]=Q(i,null),_=O.trim().length>0,F=l=>{x(l),!n&&!C&&N(Ye(l))},B=async()=>{if(!c.canSubmit)return;if(j(null),!d.trim()){j("Name is required");return}if(!n&&!u.trim()){j("Slug is required");return}const l=_?{sql:O.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:T,backing:l}):await r.mutateAsync({slug:u.trim(),name:d.trim(),description:b.trim()||void 0,icon:y.trim()||void 0,color:f.trim()||void 0,metadata_schema:_?void 0:T,backing:l}),o()}catch(V){j(V instanceof Error?V.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(Re,{visible:c.hasConflict,onReload:c.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-name",children:"Name"}),e.jsx(E,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-slug",children:"Slug"}),e.jsx(E,{id:"et-slug",value:u,onChange:l=>{m(!0),N(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-desc",children:"Description"}),e.jsx(Te,{id:"et-desc",value:b,onChange:l=>w(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(E,{id:"et-icon",value:y,onChange:l=>v(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{id:"et-color",value:f,onChange:l=>R(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),f&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:f}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ie,{value:O,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),_?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ne,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(S,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(Ke,{value:T,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(S,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Le,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Oe,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(g,{onClick:B,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function as({entityType:s,onClose:a,orgContext:o,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,c]=h.useState(!1),[d,x]=h.useState(null),u=De(),N=s?.entity_count??0,b=N>0,w=async()=>{if(s){x(null);try{await u.mutateAsync(s.slug),a()}catch(f){x(f instanceof Error?f.message:"Failed to delete")}}},y=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",v=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:y}),t&&o.slug&&s?e.jsx(Xe,{owner:o.slug,typeSlug:s.slug}):null]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:v})]}),e.jsx("div",{className:"py-4",children:e.jsx(Qe,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[o.slug&&s?e.jsx(Ze,{owner:o.slug,entityType:s}):null,!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:i?e.jsxs("div",{className:"space-y-3",children:[b?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(re,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",N===1?"is":"are"," ",N," entit",N===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),d&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:d}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{variant:"outline",size:"sm",onClick:()=>{c(!1),x(null)},children:"Cancel"}),e.jsx(g,{variant:"destructive",size:"sm",onClick:w,disabled:b||u.isPending,children:u.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(g,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>c(!0),children:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}function Xe({owner:s,typeSlug:a}){return e.jsx(Ae,{delayDuration:200,children:e.jsxs(Fe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(g,{asChild:!0,variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground",children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a},children:[e.jsx(qe,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Activity"})]})})}),e.jsx(Pe,{children:"Activity"})]})})}function Ze({owner:s,entityType:a}){const o=Object.entries(a.event_kinds??{}).sort(([n],[r])=>U(n).localeCompare(U(r)));return e.jsxs("section",{"aria-label":"Event kinds",className:"border-t border-border pt-4 space-y-2",children:[e.jsxs("h2",{className:"text-sm font-medium",children:["Event kinds on ",a.name]}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"This type declares no event kinds."}):e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:o.map(([n,r])=>e.jsx("li",{children:e.jsxs(le,{to:"/$owner/events",params:{owner:s},search:{type:a.slug,semantic_types:n},className:"flex items-center gap-3 px-3 py-2 text-sm transition-colors hover:bg-accent/50",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block font-medium",children:U(n)}),r?.description?e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:r.description}):null]}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:["View in Activity",e.jsx(Me,{className:"h-3.5 w-3.5","aria-hidden":"true"})]})]})},n))})]})}export{as as E};
|
|
2
|
+
//# sourceMappingURL=entity-type-page-CkQm0yEu.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=event-detail-
|
|
1
|
+
import{H as q,ad as I,h5 as J,r as B,h6 as Q,gG as W,j as s,ch as M,L as X}from"./index-DByaMzsG.js";import{E as Y}from"./events-feed-DmRzikZW.js";import{b as Z,a as z,V as K,M as ee}from"./view-param-filters-CUCj9Df-.js";const se={},te="calc(100dvh - 120px)";function ie({owner:a,organizationId:o,eventId:c,viewKey:r,params:f,onParamsChange:d,onSelectView:g,dense:h=!1,fullBleed:k=!1}){const{isAuthenticated:y,isReady:E}=q(),{data:O,isLoading:w}=I(),P=O?.some(t=>t.id===o&&t.is_member),i=a!=="me"&&o!==null&&E&&y&&!w&&P,n=J(i?{slug:a,organizationId:o}:null,c),[j,L]=B.useState(se),[T,b]=B.useState(null),m=Q(n.views,r),e=i&&!n.isLoading&&!n.isError&&m.kind==="view"?m.view:null,v=e?`${W(a,e.key)}/${e.content_hash}/${e.eventId}`:null,x=e!==null&&T===v,V=M(a,c),F=a!=="me"&&(!E||y&&(w||n.isLoading)),H=e!==null&&!x&&!F,u=k&&H,U=(k||h)&&H,N=F?s.jsx("div",{role:"status",className:"py-8 text-sm text-muted-foreground",children:"Loading event view…"}):e&&!x?s.jsxs(s.Fragment,{children:[s.jsx(Z,{decls:e.params,params:f??j,onParamsChange:t=>d?d(e.key,t,{replace:!1}):L(t)}),s.jsx(z,{orgSlug:a,viewKey:e.key,scope:{event:e.eventId},params:f??j,onParamsChange:t=>d?d(e.key,t):L(t),paramDecls:e.params,onLoadError:()=>b(v),contentHash:e.content_hash,title:e.name,minHeight:h?240:320,fixedHeight:U?te:void 0},v)]}):void 0;return s.jsxs("div",{className:u?"w-full space-y-3":"mx-auto w-full max-w-3xl space-y-3",...u?{"data-testid":"event-view-fullbleed"}:{},children:[i&&n.isError&&s.jsx(K,{onRetry:n.refetch}),(i||a==="me"&&r)&&!n.isLoading&&!n.isError&&m.kind==="missing"&&s.jsx(ee,{viewKey:m.key,backTo:V,backLabel:"Back to the event"}),x&&s.jsxs("div",{role:"alert",className:"rounded-md border p-3 text-sm",children:[s.jsx("p",{children:"The custom view couldn’t load. The event content is shown below."}),s.jsx("button",{type:"button",className:"mt-2 underline",onClick:()=>b(null),children:"Retry custom view"})]}),s.jsx(Y,{presentation:"detail",organizationId:o,ownerSlug:a,filters:{contentIds:[c],...a==="me"?{sortBy:"date",sortOrder:"desc"}:{}},hideDetails:h,renderDetail:t=>{const p=N!=null&&(t==null||!!r),A=(i?n.views:[]).filter(l=>!p||l.key!==e?.key).map(l=>({key:l.key,name:l.name,href:M(a,c,l.key)})),D=l=>l.length?s.jsx("nav",{"aria-label":"Event views",className:"flex flex-wrap gap-3 text-sm",children:l.map(({key:$,name:C,href:_})=>s.jsx(X,{to:_,className:"underline",onClick:g?G=>{G.preventDefault(),g(_)}:void 0,children:C},$))}):null,R=[...A],S=[...A];return i&&r&&t!=null&&S.unshift({key:":event",name:"Event details",href:V}),{content:p?N:t,nativeHeading:!p&&t!=null,headingAside:u?D(R):void 0,links:u?null:D(S)}}})]})}export{ie as E};
|
|
2
|
+
//# sourceMappingURL=event-detail-CkzfakTK.js.map
|