erdbpro 3.5.2 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AdminRoute-DdWMfsoB.js → AdminRoute-BjQp7Qkw.js} +2 -2
- package/dist/assets/{Combination-CUVb9ofm.js → Combination-V_AHx6qx.js} +1 -1
- package/dist/assets/{DataViewerModeToolbar-D-Gz8RBr.js → DataViewerModeToolbar-B88MzPD6.js} +1 -1
- package/dist/assets/{DbClientEditorRoute-DwfHzSEu.js → DbClientEditorRoute-DGxvKsxx.js} +1 -1
- package/dist/assets/{DiagramEditorRoute-C6j5Rhfq.js → DiagramEditorRoute-oDDntY8T.js} +1 -1
- package/dist/assets/{DrawingEditorRoute-DKAA6Mfs.js → DrawingEditorRoute-DZIBK5bA.js} +2 -2
- package/dist/assets/{DrawingsView-c3OqClYs.js → DrawingsView-CUS2f0K3.js} +8 -8
- package/dist/assets/{ERDComments-BvMTuCQR.js → ERDComments-BN8ryun0.js} +1 -1
- package/dist/assets/{FlowchartEditorRoute-BWMbqdRZ.js → FlowchartEditorRoute-BbMbDyYZ.js} +1 -1
- package/dist/assets/{LibraryRoute-CbSV7ZgF.js → LibraryRoute-FRaTntpB.js} +1 -1
- package/dist/assets/{NoteEditorRoute-DptPPyeK.js → NoteEditorRoute-B-_sANnj.js} +2 -2
- package/dist/assets/{NotesView-CClivjq6.js → NotesView-DqGuoMLE.js} +1 -1
- package/dist/assets/{TeamInventoryRoute-DPAahWna.js → TeamInventoryRoute-8WYAewWg.js} +1 -1
- package/dist/assets/{TeamManagementRoute-Q7uBrAgL.js → TeamManagementRoute-BUru3Ak9.js} +1 -1
- package/dist/assets/{TrashView-CN-ii4bu.js → TrashView-Ci6VQzb8.js} +1 -1
- package/dist/assets/{UserManagementRoute-CraXQoFT.js → UserManagementRoute-DUrPbzBX.js} +1 -1
- package/dist/assets/{WorkspaceProvider-BjP-0tZX.js → WorkspaceProvider-DkMvUEsL.js} +3 -3
- package/dist/assets/{abnfDiagram-VCTEODGH-CctxbdFa.js → abnfDiagram-VCTEODGH-DLEPIgXQ.js} +1 -1
- package/dist/assets/{ar-SA-G6X2FPQ2-B14UAgYA.js → ar-SA-G6X2FPQ2-DiKrSvez.js} +1 -1
- package/dist/assets/{architectureDiagram-5GKGNRK7-DrLG3CAd.js → architectureDiagram-5GKGNRK7-igPWmlV8.js} +1 -1
- package/dist/assets/{az-AZ-76LH7QW2-oPiKDK6R.js → az-AZ-76LH7QW2-BkQxoEzS.js} +1 -1
- package/dist/assets/{bg-BG-XCXSNQG7-Dq5utYBc.js → bg-BG-XCXSNQG7-DnBlxteG.js} +1 -1
- package/dist/assets/{blockDiagram-I7D4REHJ-YPzHBKmD.js → blockDiagram-I7D4REHJ-q9tu4qK_.js} +1 -1
- package/dist/assets/{bn-BD-2XOGV67Q-B0EgC990.js → bn-BD-2XOGV67Q-CEB3reDP.js} +1 -1
- package/dist/assets/{c4Diagram-7LVT6UL2-Cc8VcyUW.js → c4Diagram-7LVT6UL2-fv8ZNrLp.js} +1 -1
- package/dist/assets/{ca-ES-6MX7JW3Y-Czrv8qsm.js → ca-ES-6MX7JW3Y-DKE-UttO.js} +1 -1
- package/dist/assets/channel-DvECy8NV.js +1 -0
- package/dist/assets/{chunk-4HAMMTFA-fCsPruHC.js → chunk-4HAMMTFA-DygKuhnx.js} +1 -1
- package/dist/assets/{chunk-75Z2AOVW-nqpwZPmt.js → chunk-75Z2AOVW-Dr8QMXDX.js} +1 -1
- package/dist/assets/{chunk-DU6HZSFF-MlHhVKIY.js → chunk-DU6HZSFF-C6om838V.js} +1 -1
- package/dist/assets/{chunk-EIO257PC-BA-BMtJ1.js → chunk-EIO257PC-DuxOWMcL.js} +1 -1
- package/dist/assets/{chunk-F27PBJKO-D_FWF5HN.js → chunk-F27PBJKO-ChzDggPY.js} +1 -1
- package/dist/assets/{chunk-GMAD6QVW-D9ojck2W.js → chunk-GMAD6QVW-Dv-9jKAo.js} +1 -1
- package/dist/assets/{chunk-GVQU2GXP-DmBmByvO.js → chunk-GVQU2GXP-BTrtiX_k.js} +1 -1
- package/dist/assets/{chunk-IMKFNOWR-Ckf4Q14H.js → chunk-IMKFNOWR-C5Z-xReF.js} +1 -1
- package/dist/assets/{chunk-L3NEJ4N5-BtmyuZeA.js → chunk-L3NEJ4N5-BHUZT2SI.js} +1 -1
- package/dist/assets/{chunk-OSK3NFVY-tdkIFyHJ.js → chunk-OSK3NFVY-CfQ9a5Se.js} +1 -1
- package/dist/assets/{chunk-P2QGCYS3-_Q5G5K4_.js → chunk-P2QGCYS3-2hAmAyf9.js} +1 -1
- package/dist/assets/{chunk-POPQ4Y6H-D29XfrJc.js → chunk-POPQ4Y6H-CylKUaPs.js} +1 -1
- package/dist/assets/{chunk-PWAF6VOD-BoE1WXR-.js → chunk-PWAF6VOD-B7jA_fSF.js} +1 -1
- package/dist/assets/{chunk-SHT3W25Y-Cy8iFy9A.js → chunk-SHT3W25Y-SPP0QxjC.js} +1 -1
- package/dist/assets/{chunk-SVP7TREG-Hl2SwW40.js → chunk-SVP7TREG-C1rkaUbj.js} +1 -1
- package/dist/assets/{chunk-TICWLB2K-DWjEkyuR.js → chunk-TICWLB2K-CgLLPaxM.js} +1 -1
- package/dist/assets/classDiagram-ZZMXUADV-DrcfDqnt.js +1 -0
- package/dist/assets/classDiagram-v2-VYDZK3BY-DrcfDqnt.js +1 -0
- package/dist/assets/{cs-CZ-2BRQDIVT-Y7q2S1rC.js → cs-CZ-2BRQDIVT-CYiWN9KF.js} +1 -1
- package/dist/assets/{cynefinDiagram-5FMLGOSQ-DPtqfnmE.js → cynefinDiagram-5FMLGOSQ-Coh-YDyu.js} +1 -1
- package/dist/assets/{da-DK-5WZEPLOC-AyY4oRiO.js → da-DK-5WZEPLOC-ByoGCFaX.js} +1 -1
- package/dist/assets/{dagre-GXQ25YYZ-DLDXx4WE.js → dagre-GXQ25YYZ-TSBSqrXT.js} +1 -1
- package/dist/assets/{de-DE-XR44H4JA-Beyy-XuR.js → de-DE-XR44H4JA-C5ur1SMd.js} +1 -1
- package/dist/assets/{diagram-S7CK7UJ4-YnoFRT5v.js → diagram-S7CK7UJ4-Cexm7hJK.js} +1 -1
- package/dist/assets/{diagram-UQ7AKVKN-B8EVBEN1.js → diagram-UQ7AKVKN-DpPB5aPr.js} +1 -1
- package/dist/assets/{diagram-VSXAHHWV-BZVlVGLp.js → diagram-VSXAHHWV-OJk-Vj1h.js} +1 -1
- package/dist/assets/{diagram-VX7I27RA-gzkCbd5b.js → diagram-VX7I27RA-LYZzp8ge.js} +1 -1
- package/dist/assets/{diagram-Z3DM3KII-BUD3fzF-.js → diagram-Z3DM3KII-F9Qwrk_7.js} +1 -1
- package/dist/assets/{dist-sgklCL8C.js → dist-CCYRTfue.js} +4 -4
- package/dist/assets/{ebnfDiagram-PWID7BFC-C8307e9s.js → ebnfDiagram-PWID7BFC-DL516UrL.js} +1 -1
- package/dist/assets/{el-GR-BZB4AONW-C8ClmARa.js → el-GR-BZB4AONW-BUR1GynN.js} +1 -1
- package/dist/assets/{en-B4ZKOASM-Zh-DwO75.js → en-B4ZKOASM-BwkK8SG5.js} +1 -1
- package/dist/assets/{erDiagram-RLTQ6QDP-DhKYD6tb.js → erDiagram-RLTQ6QDP-DftgdJA0.js} +1 -1
- package/dist/assets/{erdActions-BJMdmq5G.js → erdActions-XEHrDkpE.js} +1 -1
- package/dist/assets/{es-ES-U4NZUMDT-BDU1gT0z.js → es-ES-U4NZUMDT-DvrHl28s.js} +1 -1
- package/dist/assets/{eu-ES-A7QVB2H4-B15mx4pr.js → eu-ES-A7QVB2H4-Cm1n43RK.js} +1 -1
- package/dist/assets/{fa-IR-HGAKTJCU-ClqZ8wKN.js → fa-IR-HGAKTJCU-CalCmvtF.js} +1 -1
- package/dist/assets/{fi-FI-Z5N7JZ37-DoXny78y.js → fi-FI-Z5N7JZ37-D2FqG8h5.js} +1 -1
- package/dist/assets/flowDiagram-HODETNUW-B69Aq9Z1.js +1 -0
- package/dist/assets/{fr-FR-RHASNOE6-CGqhsENL.js → fr-FR-RHASNOE6-BPCga10x.js} +1 -1
- package/dist/assets/{ganttDiagram-EL5Y4UJY-BRXwOdmz.js → ganttDiagram-EL5Y4UJY-Dwssz-8U.js} +1 -1
- package/dist/assets/{gitGraphDiagram-WWUBYQGX-tIDzKajA.js → gitGraphDiagram-WWUBYQGX-DaRhzoAw.js} +1 -1
- package/dist/assets/{gl-ES-HMX3MZ6V-C2rGw2kc.js → gl-ES-HMX3MZ6V-CpbzimQ2.js} +1 -1
- package/dist/assets/{he-IL-6SHJWFNN-a8KGDFok.js → he-IL-6SHJWFNN-BqPyV1Xh.js} +1 -1
- package/dist/assets/{hi-IN-IWLTKZ5I-DrDDaDr1.js → hi-IN-IWLTKZ5I-C6yByv2n.js} +1 -1
- package/dist/assets/{hu-HU-A5ZG7DT2-Br0D_wrW.js → hu-HU-A5ZG7DT2-CNgAuEdt.js} +1 -1
- package/dist/assets/{id-ID-SAP4L64H-B8kAjtmG.js → id-ID-SAP4L64H-DpPvMLFS.js} +1 -1
- package/dist/assets/{image-GAAHSSAO-DjAGIXbU.js → image-GAAHSSAO-CwTWzTtG.js} +1 -1
- package/dist/assets/{index-CaOyA42p.js → index-xLqjbUVL.js} +4 -4
- package/dist/assets/{infoDiagram-27XIBGKW-IQBzTwHL.js → infoDiagram-27XIBGKW-BsEeMPyo.js} +1 -1
- package/dist/assets/{ishikawaDiagram-5VMMS53U-BXyr-Br_.js → ishikawaDiagram-5VMMS53U-CaakGIh9.js} +1 -1
- package/dist/assets/{it-IT-JPQ66NNP-C8VUGhv-.js → it-IT-JPQ66NNP-DyTmGTZy.js} +1 -1
- package/dist/assets/{ja-JP-DBVTYXUO-H4pX95fs.js → ja-JP-DBVTYXUO-Bkvfcz0c.js} +1 -1
- package/dist/assets/{journeyDiagram-3NMN7TZE-habROpkc.js → journeyDiagram-3NMN7TZE-CQr1huCQ.js} +1 -1
- package/dist/assets/{kaa-6HZHGXH3-BEuPLl9y.js → kaa-6HZHGXH3-m_mOshDh.js} +1 -1
- package/dist/assets/{kab-KAB-ZGHBKWFO-CmmMBhGA.js → kab-KAB-ZGHBKWFO-Bc-Q_P0X.js} +1 -1
- package/dist/assets/{kanban-definition-UXKFOSKX-UzlXpEvx.js → kanban-definition-UXKFOSKX-CXnu1yi-.js} +1 -1
- package/dist/assets/{kk-KZ-P5N5QNE5-PEJNkAwS.js → kk-KZ-P5N5QNE5-DnNzYxpi.js} +1 -1
- package/dist/assets/{km-KH-HSX4SM5Z-BKbMomDw.js → km-KH-HSX4SM5Z-CI7GY9Se.js} +1 -1
- package/dist/assets/{ko-KR-MTYHY66A-C4ZbfUVe.js → ko-KR-MTYHY66A-JmxmiOJF.js} +1 -1
- package/dist/assets/{ku-TR-6OUDTVRD-cUrWVcIZ.js → ku-TR-6OUDTVRD-BkaDP5Th.js} +1 -1
- package/dist/assets/{line-Dc7II6Ye.js → line-X6pOsa-H.js} +1 -1
- package/dist/assets/{lt-LT-XHIRWOB4-C1bdqm_d.js → lt-LT-XHIRWOB4-BFSQQCPo.js} +1 -1
- package/dist/assets/{lv-LV-5QDEKY6T-DsnlglCV.js → lv-LV-5QDEKY6T-BByO7aXM.js} +1 -1
- package/dist/assets/{mindmap-definition-YA3MSWOX-Cb7rd0QN.js → mindmap-definition-YA3MSWOX-BeBATkgJ.js} +1 -1
- package/dist/assets/{mr-IN-CRQNXWMA-Ct7zXQHp.js → mr-IN-CRQNXWMA-DwWRAH8i.js} +1 -1
- package/dist/assets/{my-MM-5M5IBNSE-BEFMfpo0.js → my-MM-5M5IBNSE-C467h0Jr.js} +1 -1
- package/dist/assets/{nb-NO-T6EIAALU-ColFEaA4.js → nb-NO-T6EIAALU-CASi-rDx.js} +1 -1
- package/dist/assets/{nl-NL-IS3SIHDZ-tnf21Jvf.js → nl-NL-IS3SIHDZ-Bc8KGSO8.js} +1 -1
- package/dist/assets/{nn-NO-6E72VCQL-DJS34rZa.js → nn-NO-6E72VCQL-CEtNH0NE.js} +1 -1
- package/dist/assets/{note-importer-Rw-2fWQj.js → note-importer-mHEzGrVx.js} +2 -2
- package/dist/assets/{oc-FR-POXYY2M6-D11YbA23.js → oc-FR-POXYY2M6-CftGZJoB.js} +1 -1
- package/dist/assets/{pa-IN-N4M65BXN-kwmv87ar.js → pa-IN-N4M65BXN-B2mAlD29.js} +1 -1
- package/dist/assets/{pegDiagram-XKGWAZYB-BntElqXF.js → pegDiagram-XKGWAZYB-DvS82ii9.js} +1 -1
- package/dist/assets/percentages-BXMCSKIN-Cb3yWtaE.js +1 -0
- package/dist/assets/{pieDiagram-E7YTZNPT-DI6j9zlI.js → pieDiagram-E7YTZNPT-CvYxrLTQ.js} +1 -1
- package/dist/assets/{pl-PL-T2D74RX3-CgRJ9Kb5.js → pl-PL-T2D74RX3-DLC-uWAW.js} +1 -1
- package/dist/assets/{popover-DGUE4WfZ.js → popover-DcdaCTLH.js} +1 -1
- package/dist/assets/{pt-BR-5N22H2LF-C_y37wxT.js → pt-BR-5N22H2LF-CRaq1SW5.js} +1 -1
- package/dist/assets/{pt-PT-UZXXM6DQ-a9aLRLRQ.js → pt-PT-UZXXM6DQ-EJmHLsB6.js} +1 -1
- package/dist/assets/{quadrantDiagram-AXDQQJYC-BpvPoymn.js → quadrantDiagram-AXDQQJYC-BMtMzh4C.js} +1 -1
- package/dist/assets/{railroadDiagram-O6MQD6OU-Du9GNL7X.js → railroadDiagram-O6MQD6OU-5WqVh3hY.js} +1 -1
- package/dist/assets/{requirementDiagram-BXWQKSXE-DtUMUjVt.js → requirementDiagram-BXWQKSXE-BrU3U_p8.js} +1 -1
- package/dist/assets/{ro-RO-JPDTUUEW-CfTCPkpo.js → ro-RO-JPDTUUEW-rmuBGcGv.js} +1 -1
- package/dist/assets/{ru-RU-B4JR7IUQ-e--90NPq.js → ru-RU-B4JR7IUQ-BUHSl2mV.js} +1 -1
- package/dist/assets/{sankeyDiagram-P5KCCOFB-YTCfXR0P.js → sankeyDiagram-P5KCCOFB-V8mBkWT3.js} +1 -1
- package/dist/assets/{sequenceDiagram-WJ2MYXX4-BHKKadTh.js → sequenceDiagram-WJ2MYXX4-v2E8wAGA.js} +1 -1
- package/dist/assets/{si-LK-N5RQ5JYF-C8EYUOXU.js → si-LK-N5RQ5JYF-DNmSbf_6.js} +1 -1
- package/dist/assets/{sk-SK-C5VTKIMK--hTf_BhR.js → sk-SK-C5VTKIMK-D9Z8_SrL.js} +1 -1
- package/dist/assets/{sl-SI-NN7IZMDC-CBolQ_1f.js → sl-SI-NN7IZMDC-CIWEYLwV.js} +1 -1
- package/dist/assets/{stateDiagram-D77RDMKH-BD8uJjCr.js → stateDiagram-D77RDMKH-BRv5K0Hh.js} +1 -1
- package/dist/assets/stateDiagram-v2-MP3YSRHH-B6sDYqlR.js +1 -0
- package/dist/assets/subset-shared.chunk-Cm74vOja.js +1 -0
- package/dist/assets/{subset-worker.chunk-DL6eLuxa.js → subset-worker.chunk-YB-QnV14.js} +1 -1
- package/dist/assets/{sv-SE-XGPEYMSR-BkCH7b0v.js → sv-SE-XGPEYMSR-B3lwb9az.js} +1 -1
- package/dist/assets/{swimlanes-42K2YHIH-C3vcbzQJ.js → swimlanes-42K2YHIH-P7QbKrYf.js} +1 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-D9CVqRTs.js +8 -0
- package/dist/assets/{ta-IN-2NMHFXQM-CwgTKGNu.js → ta-IN-2NMHFXQM-W-7DL00D.js} +1 -1
- package/dist/assets/{th-TH-HPSO5L25-Dhp7jRvZ.js → th-TH-HPSO5L25-BHy8Ee54.js} +1 -1
- package/dist/assets/{timeline-definition-24CTP7MA-DMLwL0Qx.js → timeline-definition-24CTP7MA-C5n3XBAf.js} +1 -1
- package/dist/assets/{tr-TR-DEFEU3FU-CgFkVkyi.js → tr-TR-DEFEU3FU-gDiYgC1v.js} +1 -1
- package/dist/assets/{uk-UA-QMV73CPH-Dyr8STNr.js → uk-UA-QMV73CPH-ap9q7puf.js} +1 -1
- package/dist/assets/{useLeaveGuard-C1UXBxDg.js → useLeaveGuard-C4lXrsPo.js} +1 -1
- package/dist/assets/{vennDiagram-4TSXK5OY-CTG_pHwh.js → vennDiagram-4TSXK5OY-BuplTj7c.js} +1 -1
- package/dist/assets/{vi-VN-M7AON7JQ-DEgd8kmg.js → vi-VN-M7AON7JQ-CyhnvXKd.js} +1 -1
- package/dist/assets/{w3c-keyname-D_eH12P5.js → w3c-keyname-BAyKiYyI.js} +1 -1
- package/dist/assets/{wardleyDiagram-VM6X3IG4-CMYNWh7r.js → wardleyDiagram-VM6X3IG4-Dq672ii1.js} +1 -1
- package/dist/assets/{xychartDiagram-S5SC5T6Z-IiSgiVzs.js → xychartDiagram-S5SC5T6Z-STmWX1kE.js} +1 -1
- package/dist/assets/{zh-CN-LNUGB5OW-DnAt5X3m.js → zh-CN-LNUGB5OW-N_XiLfj-.js} +1 -1
- package/dist/assets/{zh-HK-E62DVLB3-D9IBdPbx.js → zh-HK-E62DVLB3-DlA0Xl6p.js} +1 -1
- package/dist/assets/{zh-TW-RAJ6MFWO-D3iEL-2F.js → zh-TW-RAJ6MFWO-DhF3DIYV.js} +1 -1
- package/dist/index.html +7 -7
- package/package.json +1 -1
- package/dist/assets/channel-DAHbpGbp.js +0 -1
- package/dist/assets/classDiagram-ZZMXUADV-CzotunHc.js +0 -1
- package/dist/assets/classDiagram-v2-VYDZK3BY-CzotunHc.js +0 -1
- package/dist/assets/flowDiagram-HODETNUW-DRE5zOdl.js +0 -1
- package/dist/assets/percentages-BXMCSKIN-DIR2-_uI.js +0 -1
- package/dist/assets/stateDiagram-v2-MP3YSRHH-BXBo2H7G.js +0 -1
- package/dist/assets/subset-shared.chunk-DAYQYGik.js +0 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-D-HpmiiX.js +0 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrashView-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{c as r}from"./chunk-BV7QT456-B3UxAK3W.js";import{t as i}from"./preload-helper-BLdHbfdN.js";import"./WorkspaceProvider-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TrashView-Ci6VQzb8.js","assets/rolldown-runtime-BCiCTKAo.js","assets/jsx-runtime-Cl3nUQcN.js","assets/createLucideIcon-DCn6SI1F.js","assets/button-CYI0LXM3.js","assets/pen-tool-CoHyO7pC.js","assets/refresh-ccw-CWK4vSVV.js","assets/trash-2-CV7XVyhd.js","assets/alert-dialog-DXnJdv-M.js","assets/useOpenInteractionType-BlKZ7jMy.js","assets/api-DuV0sTuY.js","assets/preload-helper-BLdHbfdN.js","assets/fileOwnership-CF3Bm_pU.js","assets/useAuth-splnWP_7.js","assets/index-xLqjbUVL.js","assets/chunk-BV7QT456-B3UxAK3W.js","assets/note-importer-mHEzGrVx.js","assets/src-C_gRsKqw.js","assets/value-CHmTzbgv.js","assets/image-compression-su-JvgYP.js","assets/useField-E2Vk7I_Z.js","assets/popover-DcdaCTLH.js","assets/dropdown-menu-BoXeiuAZ.js","assets/check-BwjD7EK2.js","assets/getPseudoElementBounds-BEHunO5c.js","assets/CompositeList-BqU8Qax7.js","assets/useCompositeItem-DK528yJL.js","assets/ERDComments-BN8ryun0.js","assets/select-CdQCv8yP.js","assets/ConfirmModal-pEN41Kyx.js","assets/ellipsis-CfqIMSId.js","assets/dialog-BIk9Y-3N.js","assets/w3c-keyname-BAyKiYyI.js","assets/input-CMgoax5D.js","assets/refresh-cw-DyBeWpoi.js","assets/chevron-left-D_Hf28gP.js","assets/field-BXvmJTfd.js","assets/hard-drive-Chd5URlA.js","assets/message-square-B1YYK_eY.js","assets/sparkles-BTRhjhc4.js","assets/useLeaveGuard-C4lXrsPo.js","assets/label-CfaCFYRS.js","assets/extends-CvVTau-c.js","assets/WorkspaceProvider-DkMvUEsL.js","assets/localPersistence-CGAJ2Ky5.js","assets/diagramVersioning-DlDBcvq6.js","assets/dist-js-CGfv5pu7.js","assets/core-5A5Ti_Rw.js","assets/WorkspaceContext-CitlpD55.js","assets/index-CFRelQ4M.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{c as r}from"./chunk-BV7QT456-B3UxAK3W.js";import{t as i}from"./preload-helper-BLdHbfdN.js";import"./WorkspaceProvider-DkMvUEsL.js";import{n as a}from"./WorkspaceContext-CitlpD55.js";var o=e(t(),1),s=n(),c=o.lazy(()=>i(()=>import(`./TrashView-Ci6VQzb8.js`).then(e=>({default:e.TrashView})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49])));function l(){let{pathname:e}=r();return e===`/trash`?(0,s.jsx)(u,{}):null}function u(){let{trashData:e,isTrashLoading:t,handleTrashRestoreProject:n,handleTrashRestoreDiagram:r,handleTrashRestoreNote:i,handleTrashRestoreDrawing:l,handleTrashRestoreFlowchart:u,handleTrashRestoreDbClient:d,handleTrashProjectPermanentDelete:f,handleTrashDiagramPermanentDelete:p,handleTrashNotePermanentDelete:m,handleTrashDrawingPermanentDelete:h,handleTrashFlowchartPermanentDelete:g,fetchTrash:_,handleTrashDbClientPermanentDelete:v}=a();return(0,s.jsx)(o.Suspense,{fallback:(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,s.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,s.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,s.jsx)(`span`,{className:`text-xs text-muted-foreground/60 animate-pulse`,children:`Loading trash...`})]})}),children:(0,s.jsx)(c,{trashData:e,restoreProject:n,restoreDiagram:r,restoreNote:i,restoreDrawing:l,restoreFlowchart:u,restoreDbClient:d,fetchTrash:_,handleProjectPermanentDelete:f,handleDiagramPermanentDelete:p,handleNotePermanentDelete:m,handleDrawingPermanentDelete:h,handleFlowchartPermanentDelete:g,handleDbClientPermanentDelete:v,isLoading:t})})}export{l as AdminRoute};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t}from"./jsx-runtime-Cl3nUQcN.js";import{E as n,T as r,w as i}from"./index-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t}from"./jsx-runtime-Cl3nUQcN.js";import{E as n,T as r,w as i}from"./index-xLqjbUVL.js";var a=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},o=new WeakMap,s=new WeakMap,c={},l=0,u=function(e){return e&&(e.host||u(e.parentNode))},d=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=u(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},f=function(e,t,n,r){var i=d(t,Array.isArray(e)?e:[e]);c[n]||(c[n]=new WeakMap);var a=c[n],u=[],f=new Set,p=new Set(i),m=function(e){e&&!f.has(e)&&(f.add(e),m(e.parentNode))};i.forEach(m);var h=function(e){e&&!p.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(f.has(e))h(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(o.get(e)||0)+1,l=(a.get(e)||0)+1;o.set(e,c),a.set(e,l),u.push(e),c===1&&i&&s.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return h(t),f.clear(),l++,function(){u.forEach(function(e){var t=o.get(e)-1,i=a.get(e)-1;o.set(e,t),a.set(e,i),t||(s.has(e)||e.removeAttribute(r),s.delete(e)),i||e.removeAttribute(n)}),l--,l||(o=new WeakMap,o=new WeakMap,s=new WeakMap,c={})}},p=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||a(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),f(r,i,n,`aria-hidden`)):function(){return null}},m=e(t()),h=`right-scroll-bar-position`,g=`width-before-scroll-bar`,_=`with-scroll-bars-hidden`,v=`--removed-body-scroll-bar-size`;function y(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function b(e,t){var n=(0,m.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var x=typeof window<`u`?m.useLayoutEffect:m.useEffect,S=new WeakMap;function ee(e,t){var n=b(t||null,function(t){return e.forEach(function(e){return y(e,t)})});return x(function(){var t=S.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||y(e,null)}),i.forEach(function(e){r.has(e)||y(e,a)})}S.set(n,e)},[e]),n}function C(e){return e}function w(e,t){t===void 0&&(t=C);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function T(e){e===void 0&&(e={});var t=w(null);return t.options=i({async:!0,ssr:!1},e),t}var E=function(e){var t=e.sideCar,n=r(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var a=t.read();if(!a)throw Error(`Sidecar medium not found`);return m.createElement(a,i({},n))};E.isSideCarExport=!0;function te(e,t){return e.useMedium(t),E}var D=T(),O=function(){},k=m.forwardRef(function(e,t){var n=m.useRef(null),a=m.useState({onScrollCapture:O,onWheelCapture:O,onTouchMoveCapture:O}),o=a[0],s=a[1],c=e.forwardProps,l=e.children,u=e.className,d=e.removeScrollBar,f=e.enabled,p=e.shards,h=e.sideCar,g=e.noRelative,_=e.noIsolation,v=e.inert,y=e.allowPinchZoom,b=e.as,x=b===void 0?`div`:b,S=e.gapMode,C=r(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),w=h,T=ee([n,t]),E=i(i({},C),o);return m.createElement(m.Fragment,null,f&&m.createElement(w,{sideCar:D,removeScrollBar:d,shards:p,noRelative:g,noIsolation:_,inert:v,setCallbacks:s,allowPinchZoom:!!y,lockRef:n,gapMode:S}),c?m.cloneElement(m.Children.only(l),i(i({},E),{ref:T})):m.createElement(x,i({},E,{className:u,ref:T}),l))});k.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},k.classNames={fullWidth:g,zeroRight:h};var ne=function(){if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function re(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=ne();return t&&e.setAttribute(`nonce`,t),e}function A(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function j(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var M=function(){var e=0,t=null;return{add:function(n){e==0&&(t=re())&&(A(t,n),j(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},N=function(){var e=M();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},P=function(){var e=N();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},ie={left:0,top:0,right:0,gap:0},F=function(e){return parseInt(e||``,10)||0},ae=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[F(n),F(r),F(i)]},oe=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return ie;var t=ae(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},se=P(),I=`data-scroll-locked`,ce=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
|
|
2
2
|
.${_} {
|
|
3
3
|
overflow: hidden ${r};
|
|
4
4
|
padding-right: ${s}px ${r};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{a as r,i,o as a,s as o}from"./createLucideIcon-DCn6SI1F.js";import{d as s}from"./chunk-BV7QT456-B3UxAK3W.js";import{A as c,C as l,Ct as u,D as d,Dt as f,E as p,F as m,M as h,N as g,O as _,Ot as v,P as y,S as b,St as x,T as S,Tt as C,_ as w,a as T,b as E,bt as D,c as O,ct as k,d as A,dt as ee,f as j,ft as M,g as N,h as P,ht as F,it as te,j as I,l as ne,lt as L,m as re,o as R,p as z,s as B,st as V,u as ie,ut as H,vt as U,w as ae,wt as oe,x as se,xt as ce,yt as le}from"./note-importer-Rw-2fWQj.js";import{t as W}from"./button-CYI0LXM3.js";import{s as ue}from"./useField-E2Vk7I_Z.js";import{c as de,d as fe,l as pe,n as me,o as he,r as ge,t as _e}from"./popover-DGUE4WfZ.js";import{a as G,d as ve,f as ye,l as be,r as xe,s as Se,t as Ce,u as we}from"./dropdown-menu-BoXeiuAZ.js";import{t as Te}from"./check-BwjD7EK2.js";import{r as Ee}from"./getPseudoElementBounds-BEHunO5c.js";import{A as De,Ct as Oe,D as ke,Et as K,O as q,P as Ae,Tt as je,Y as J,a as Me,at as Ne,i as Pe,k as Fe,n as Ie,ot as Le,r as Re,t as ze}from"./ERDComments-BvMTuCQR.js";import{A as Be,C as Ve,D as He,E as Ue,O as We,S as Ge,T as Ke,_ as qe,b as Je,g as Ye,h as Xe,i as Ze,k as Qe,v as $e,w as et,x as tt,y as nt}from"./w3c-keyname-D_eH12P5.js";import{n as rt,t as Y}from"./refresh-cw-DyBeWpoi.js";import{t as it}from"./chevron-left-D_Hf28gP.js";import{i as at,n as ot,o as st,s as ct,t as X}from"./select-CdQCv8yP.js";import{n as lt,t as ut}from"./ConfirmModal-pEN41Kyx.js";import{a as dt,c as ft,d as pt,f as mt,h as ht,i as gt,l as _t,m as vt,n as yt,o as bt,p as xt,s as St,t as Ct,u as wt}from"./erdActions-BJMdmq5G.js";import{r as Tt}from"./pen-tool-CoHyO7pC.js";import{t as Et}from"./ellipsis-CfqIMSId.js";import{a as Dt,i as Ot,o as kt,r as At,t as jt}from"./field-BXvmJTfd.js";import{n as Mt,r as Nt,t as Pt}from"./redo-2-CUB0gf4Y.js";import{t as Ft}from"./message-square-B1YYK_eY.js";import{_ as It,a as Lt,d as Rt,i as zt,l as Bt,n as Vt,o as Ht,s as Ut,t as Wt,v as Gt}from"./dialog-BIk9Y-3N.js";import{t as Kt}from"./sparkles-BTRhjhc4.js";import{t as qt}from"./trash-2-CV7XVyhd.js";import{C as Jt,a as Yt,c as Xt,i as Zt,l as Qt,n as $t,o as en,r as tn,s as nn,t as rn,u as an}from"./alert-dialog-DXnJdv-M.js";import{t as on}from"./undo-2-eBLOetyj.js";import{c as sn,n as cn,o as ln}from"./api-DuV0sTuY.js";import{t as Z}from"./input-CMgoax5D.js";import{C as un,D as dn,E as fn,S as pn,T as mn,_ as hn,b as gn,c as _n,d as vn,f as yn,g as bn,h as xn,l as Sn,m as Cn,n as wn,o as Tn,p as En,r as Dn,t as On,u as kn,v as An,w as jn,x as Mn,y as Nn}from"./useLeaveGuard-C1UXBxDg.js";import{A as Pn,C as Fn,D as In,E as Ln,G as Rn,S as zn,T as Bn,a as Vn,b as Hn,d as Un,f as Wn,i as Gn,j as Kn,k as qn,m as Jn,p as Yn,u as Xn,w as Zn,x as Qn,y as $n}from"./WorkspaceProvider-BjP-0tZX.js";import{t as er}from"./localPersistence-CGAJ2Ky5.js";import{n as tr}from"./WorkspaceContext-CitlpD55.js";import{t as nr}from"./label-CfaCFYRS.js";import{A as rr,B as ir,F as ar,H as or,I as sr,L as cr,M as lr,N as ur,R as dr,U as fr,Y as pr,k as mr,ln as hr,z as gr}from"./index-CaOyA42p.js";/* empty css */var Q=e(t(),1),$=n(),_r=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);function vr(e,t){return e.source===t.source&&e.target===t.target&&_r(e.sourceHandle)===_r(t.sourceHandle)&&_r(e.targetHandle)===_r(t.targetHandle)}function yr(e,t){let n=t?.nodes||{},r=new Set(e.flatMap(e=>(e.foreign_keys||[]).map(e=>`${e.ref_table}.${e.ref_column}`))),i=e.map((e,t)=>{let i=n[e.table_name]||{};return{id:e.table_name,type:`entity`,position:{x:i.x??t%4*280+50,y:i.y??Math.floor(t/4)*220+50},data:{id:e.table_name,name:e.table_name,x:i.x??0,y:i.y??0,color:i.color??`#6b7280`,columns:(e.columns||[]).map(t=>({...p(t,`${e.table_name}.${t.name}`),_is_fk:(e.foreign_keys||[]).some(e=>e.column===t.name),_is_ref:r.has(`${e.table_name}.${t.name}`)})),collapsed:i.collapsed??!1,hidden_columns:i.hidden_columns??[],note:i.note??``,isReadOnly:!0}}}),a=[],o=new Map(i.map(e=>[e.id,new Set(e.data.columns.map(e=>e.name))]));for(let n of e)for(let e of n.foreign_keys||[]){if(!o.get(n.table_name)?.has(e.column)||!o.get(e.ref_table)?.has(e.ref_column))continue;let r=`${n.table_name}.${e.column}->${e.ref_table}.${e.ref_column}`,i=t?.edgeHandles?.[r]||{};a.push({id:r,source:n.table_name,target:e.ref_table,sourceHandle:i.sourceHandle||`col-${n.table_name}.${e.column}-source`,targetHandle:i.targetHandle||`col-${e.ref_table}.${e.ref_column}-target`,type:`smoothstep`,data:{constraint_name:e.constraint_name,on_delete:e.on_delete,on_update:e.on_update}})}if(!Object.keys(n).length){let e=E(i,a);return{nodes:e,edges:se(e,a)}}return{nodes:i,edges:a}}function br(e,t,n,r){let i=Object.fromEntries(e.map(e=>[e.id,{x:e.position.x,y:e.position.y,color:e.data.color,collapsed:e.data.collapsed??!1,hidden_columns:e.data.hidden_columns??[],note:e.data.note??``}])),a=r&&Object.fromEntries(r.map(e=>[e.id,{sourceHandle:e.sourceHandle,targetHandle:e.targetHandle}]));return{...n,nodes:i,viewport:t,...a?{edgeHandles:a}:{},_type:`production_db_positions`}}var xr=`erd-production-db-tabs:`,Sr=new Map,Cr=new Map;function wr(e){let t=Sr.get(e);return t||(t=new Map,Sr.set(e,t),Sr.size>5&&Sr.delete(Sr.keys().next().value)),t}var Tr=e=>Cr.get(e),Er=(e,t)=>{Cr.set(e,t),Cr.size>5&&Cr.delete(Cr.keys().next().value)},Dr=e=>Cr.delete(e),Or=(e=``)=>({id:crypto.randomUUID(),enabled:!0,column:e,operator:`CONTAINS`,value:``,value2:``}),kr=(0,Q.createContext)(null),Ar=()=>(0,Q.useContext)(kr),jr=`erdbpro:notes-companion-edit-entity`,Mr=`!w-2 !h-2 !border-none cursor-crosshair opacity-0 transition-opacity duration-150 group-hover:!opacity-100 group-focus-within:!opacity-100`,Nr=(0,Q.memo)(({col:e,borderColor:t,typeColor:n,hideHandles:r,onDoubleClick:i})=>{let a=e._is_fk,s=e.diffState,c=(0,Q.useMemo)(()=>({top:`50%`,left:`-4px`,transform:`translate(-50%, -50%)`,backgroundColor:t,zIndex:50}),[t]),l=(0,Q.useMemo)(()=>({top:`50%`,right:`-4px`,transform:`translate(50%, -50%)`,backgroundColor:t,zIndex:50}),[t]),u=(0,Q.useMemo)(()=>s===`new`?`bg-emerald-500/10 hover:bg-emerald-500/15 border-b border-emerald-500/20`:s===`deleted`?`bg-red-500/10 hover:bg-red-500/15 line-through opacity-50 border-b border-red-500/20`:`border-border/50 hover:bg-muted`,[s]);return(0,$.jsxs)(`div`,{className:o(`erd-column-row group relative px-3 py-2 flex items-center justify-between transition-colors border-b last:border-b-0`,u),title:e.comment||void 0,onDoubleClick:i,children:[r?(0,$.jsxs)($.Fragment,{children:[e._is_ref&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`target`,position:C.Left,id:`col-${e.id}-target`,className:Mr,style:c}),(0,$.jsx)(M,{type:`target`,position:C.Right,id:`col-${e.id}-target-r`,className:Mr,style:l})]}),e._is_fk&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`source`,position:C.Left,id:`col-${e.id}-source-l`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Right,id:`col-${e.id}-source`,className:Mr,style:l})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`target`,position:C.Left,id:`col-${e.id}-target`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Left,id:`col-${e.id}-source-l`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Right,id:`col-${e.id}-source`,className:Mr,style:l}),(0,$.jsx)(M,{type:`target`,position:C.Right,id:`col-${e.id}-target-r`,className:Mr,style:l})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{className:o(`text-sm font-medium`,e.is_pk?`text-foreground`:`text-foreground/80`,s===`new`&&`text-emerald-400 font-semibold`,s===`deleted`&&`text-red-400/80 line-through`),children:s===`new`?`+ ${e.name}`:s===`deleted`?`- ${e.name}`:e.name})}),(0,$.jsxs)(`div`,{className:`flex flex-col items-end gap-0.5 max-w-35`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[11px] font-mono font-semibold`,style:{color:s===`new`?`#10b981`:s===`deleted`?`#ef4444`:n},children:d(e.type,e.max_length,e.numeric_precision,e.numeric_scale).toLowerCase()}),e.comment&&(0,$.jsx)(Ft,{className:`w-3 h-3 text-muted-foreground`}),(e.is_pk||a)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.is_pk&&(0,$.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/40 uppercase tracking-tighter`,children:`pk`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/40 uppercase tracking-tighter`,children:`fk`})]})]}),e.type.toUpperCase()===`ENUM`&&e.enum_values&&(0,$.jsxs)(`span`,{className:`font-mono italic text-right leading-tight wrap-break-word max-w-full text-[8.5px] text-muted-foreground`,children:[`(`,e.enum_values,`)`]})]})]})}),Pr=(0,Q.memo)(({data:e,id:t,selected:n})=>{let r=Me(),{isReadOnly:i,duplicateEntity:a,sourceType:s,setSelectedNodeId:c}=Rn(),l=Ar(),u=!!e._notesCompanion,d=!u&&(s===`production_db`||!!e.isReadOnly),f=i||!!e.isDiffMode||d,[p,m]=(0,Q.useState)(!1),h=ce(),g=(0,Q.useMemo)(()=>e.columns.map(e=>`${e.id}-${e.name}-${e.sort_order}`).join(`,`),[e.columns]);(0,Q.useEffect)(()=>{h(t)},[t,g,h]);let _=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&(u?window.dispatchEvent(new CustomEvent(jr,{detail:{id:t}})):(c(t),l?.(t)))},[f,u,t,c,l]),v=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&m(!0)},[f]),y=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&a(t)},[f,a,t]),b=e=>{e.preventDefault(),e.stopPropagation(),window.dispatchEvent(new CustomEvent(Re,{detail:{type:`table`,id:t}}))},x=()=>{window.dispatchEvent(new CustomEvent(`deleteEntity`,{detail:t})),m(!1)},S=e.diffState,{borderColor:C,headerBg:w,typeColor:T}=(0,Q.useMemo)(()=>S===`new`?{borderColor:`#10b981`,headerBg:`rgba(16, 185, 129, 0.15)`,typeColor:`#10b981`}:S===`deleted`?{borderColor:`#ef4444`,headerBg:`rgba(239, 68, 68, 0.15)`,typeColor:`#ef4444`}:S===`modified`?{borderColor:`#f59e0b`,headerBg:`rgba(245, 158, 11, 0.15)`,typeColor:`#f59e0b`}:{borderColor:e.color,headerBg:`${e.color}20`,typeColor:e.color},[e.color,S]),E=(0,Q.useMemo)(()=>o(`bg-card text-foreground rounded-lg border-2 min-w-[220px] erd-node-container`,n&&`ring-2 ring-primary/50`,S===`new`&&`shadow-[0_0_20px_rgba(16,185,129,0.35)] border-emerald-500/50`,S===`deleted`&&`opacity-40 shadow-[0_0_15px_rgba(239,68,68,0.25)] border-red-500/50`,S===`modified`&&`shadow-[0_0_20px_rgba(245,158,11,0.3)] border-amber-500/50`),[n,S]),D=(0,Q.useMemo)(()=>[...e.columns].sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),[e.columns]),O=(!i||!!r)&&!u&&!d&&!e.isDiffMode,k=(0,$.jsxs)(`div`,{className:`relative`,children:[!e.isDiffMode&&(0,$.jsx)(`div`,{className:`absolute -right-1 -top-1 z-20`,children:(0,$.jsx)(ze,{anchor:{type:`table`,id:t}})}),(0,$.jsxs)(`div`,{className:E,style:{borderColor:C,overflow:`visible`},children:[(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between border-b-2 cursor-pointer group/header`,style:{backgroundColor:w,borderColor:C},onDoubleClick:f?void 0:_,title:f?void 0:`Double-click to edit table`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Tt,{className:`w-4 h-4 transition-transform group-hover/header:rotate-12`,style:{color:C}}),(0,$.jsx)(`span`,{className:o(`font-bold text-sm tracking-wide uppercase`,S===`deleted`&&`line-through text-red-400`),children:e.name}),S===`new`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 rounded uppercase tracking-wider`,children:`NEW`}),S===`deleted`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-red-500/20 text-red-400 border border-red-500/30 rounded uppercase tracking-wider`,children:`DEL`}),S===`modified`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30 rounded uppercase tracking-wider`,children:`MOD`})]}),!u&&(!f||i&&!!r&&!e.isDiffMode&&!d)&&(0,$.jsxs)(Ce,{children:[(0,$.jsx)(ye,{className:`nodrag nopan p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors focus:outline-none`,onPointerDown:e=>e.stopPropagation(),onPointerUp:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),children:(0,$.jsx)(Et,{className:`w-4 h-4`})}),(0,$.jsxs)(xe,{align:`end`,className:`w-44 bg-popover border-border text-popover-foreground z-1000`,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(G,{onClick:_,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(tt,{className:`w-4 h-4 mr-2`}),`Edit`]}),(0,$.jsxs)(G,{onClick:y,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(hr,{className:`w-4 h-4 mr-2`}),`Duplicate`]})]}),r&&(0,$.jsxs)(G,{onClick:b,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(Ft,{className:`w-4 h-4 mr-2`}),`Comment`]}),!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Se,{className:`bg-border`}),(0,$.jsxs)(G,{onClick:v,className:`cursor-pointer text-destructive focus:text-destructive hover:bg-destructive/10 focus:bg-destructive/10`,children:[(0,$.jsx)(qt,{className:`w-4 h-4 mr-2`}),`Delete Table`]})]})]})]})]}),(0,$.jsx)(`div`,{className:o(`flex flex-col`,!f&&`cursor-pointer`),onDoubleClick:f?void 0:_,title:f?void 0:`Double-click to edit table`,children:D.map(e=>(0,$.jsx)(Nr,{col:e,borderColor:C,typeColor:T,hideHandles:d,onDoubleClick:f?void 0:_},e.id))})]})]});return(0,$.jsxs)($.Fragment,{children:[O?(0,$.jsxs)(ke,{children:[(0,$.jsx)(Ae,{className:`contents`,children:k}),(0,$.jsxs)(q,{className:`w-48`,children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Fe,{onClick:_,children:[(0,$.jsx)(tt,{"aria-hidden":`true`}),`Edit`]}),(0,$.jsxs)(Fe,{onClick:y,children:[(0,$.jsx)(hr,{"aria-hidden":`true`}),`Duplicate`]})]}),r&&(0,$.jsxs)(Fe,{onClick:b,children:[(0,$.jsx)(Ft,{"aria-hidden":`true`}),`Comment`]}),!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(De,{}),(0,$.jsxs)(Fe,{variant:`destructive`,onClick:v,children:[(0,$.jsx)(qt,{"aria-hidden":`true`}),`Delete`]})]})]})]}):k,(0,$.jsx)(rn,{open:p,onOpenChange:m,children:(0,$.jsxs)(Yt,{size:`sm`,className:`max-w-100`,children:[(0,$.jsxs)(Xt,{children:[(0,$.jsx)(Qt,{className:`bg-destructive/10`,children:(0,$.jsx)(Jt,{className:`w-5 h-5 text-destructive`})}),(0,$.jsx)(an,{children:`Delete Table`})]}),(0,$.jsx)(tn,{children:(0,$.jsxs)(en,{children:[`Are you sure you want to delete the table `,(0,$.jsx)(`strong`,{children:e.name}),`? This action cannot be undone.`]})}),(0,$.jsxs)(nn,{children:[(0,$.jsx)(Zt,{onClick:e=>{e.stopPropagation(),m(!1)},children:`Cancel`}),(0,$.jsx)($t,{onClick:e=>{e.stopPropagation(),x()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})});function Fr(e){if(e.kind===`column`){let t=e.id.replace(/^column:/,``);return t.slice(0,t.lastIndexOf(`.`))}return e.kind===`relation`?e.label.split(`.`)[0]:e.label}function Ir(e){return e.kind===`column`?e.label.slice(e.label.lastIndexOf(`.`)+1):e.kind===`table`?`Table definition`:e.label}function Lr(e){if(e.kind===`table`)return`TABLE`;if(e.kind===`relation`)return`FK`;let t=e.proposed??e.current;return t&&`is_pk`in t?t.type:`—`}function Rr({diff:e,approvedIds:t,showChecklist:n,label:r,rejectLabel:i=`Reject All`,canMerge:a=!0,selectable:s=a,checklistTitle:c=`Select changes to merge:`,onApprovedIdsChange:l,onShowChecklistChange:u,onReject:d,onMerge:f}){let p=(0,Q.useMemo)(()=>e.changes.map(e=>e.id),[e.changes]),m=(0,Q.useMemo)(()=>{let t=new Map;for(let n of e.changes){let e=Fr(n);t.set(e,[...t.get(e)||[],n])}return[...t]},[e.changes]),h=(0,Q.useMemo)(()=>[`table`,`column`,`relation`].map(t=>{let n=e.changes.filter(e=>e.kind===t).length;return n?`${n} ${t}${n===1?``:`s`}`:null}).filter(Boolean).join(` · `),[e.changes]),g=t.length===p.length;return(0,$.jsxs)(`div`,{"data-pending-review":!0,className:`pointer-events-none absolute inset-x-0 bottom-4 z-50 flex flex-col items-center justify-center gap-2.5 px-3`,children:[n&&(0,$.jsxs)(`div`,{className:`pointer-events-auto w-[min(560px,100%)] rounded-2xl border bg-popover/95 p-4 shadow-2xl backdrop-blur-md`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider text-muted-foreground`,children:c}),s&&(0,$.jsx)(W,{variant:`link`,size:`xs`,onClick:()=>l(g?[]:p),children:g?`Unselect All`:`Select All`})]}),(0,$.jsx)(`div`,{className:`flex max-h-75 flex-col gap-3 overflow-y-auto pr-1 custom-scrollbar`,children:m.map(([e,n])=>(0,$.jsxs)(`section`,{className:`shrink-0 overflow-hidden rounded-lg border`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b bg-muted/50 px-3 py-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold`,children:e}),(0,$.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[n.length,` change`,n.length===1?``:`s`]})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_minmax(72px,auto)_auto] gap-3 border-b px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(`span`,{}),(0,$.jsx)(`span`,{children:`Column`}),(0,$.jsx)(`span`,{children:`Type`}),(0,$.jsx)(`span`,{children:`Change`})]}),(0,$.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(e=>{let n=t.includes(e.id);return(0,$.jsxs)(`label`,{className:o(`grid cursor-pointer grid-cols-[auto_minmax(0,1fr)_minmax(72px,auto)_auto] items-center gap-3 px-3 py-2.5 transition-colors`,n?`bg-background text-foreground hover:bg-muted/50`:`bg-muted/20 text-muted-foreground hover:bg-muted/40`),children:[s?(0,$.jsx)(or,{checked:n,onCheckedChange:()=>l(n?t.filter(t=>t!==e.id):[...t,e.id]),className:`border-border bg-transparent data-checked:border-emerald-500 data-checked:bg-emerald-500`}):(0,$.jsx)(`span`,{className:`size-2 rounded-full bg-muted-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:Ir(e)}),(0,$.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:Lr(e)}),(0,$.jsx)(`span`,{className:o(`rounded border px-1.5 py-0.5 text-[10px] font-semibold uppercase`,e.state===`new`&&`border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`,e.state===`deleted`&&`border-destructive/30 bg-destructive/10 text-destructive`,e.state===`modified`&&`border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400`),children:e.state})]},e.id)})})]},e))})]}),(0,$.jsxs)(`div`,{className:`pointer-events-auto flex max-w-full items-center gap-2 overflow-x-auto rounded-2xl border bg-popover/95 p-2.5 shadow-2xl backdrop-blur-md no-scrollbar`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-1.5`,children:[r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`size-2 rounded-full bg-emerald-500`}),(0,$.jsx)(`span`,{className:`max-w-52 truncate text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:r}),(0,$.jsx)(dn,{orientation:`vertical`,className:`mx-1 h-4`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 text-[11px] font-bold`,children:[e.newCount>0&&(0,$.jsxs)(`span`,{className:`text-emerald-500`,children:[e.newCount,` New`]}),e.modifiedCount>0&&(0,$.jsxs)(`span`,{className:`text-amber-500`,children:[e.modifiedCount,` Mod`]}),e.deletedCount>0&&(0,$.jsxs)(`span`,{className:`text-destructive`,children:[e.deletedCount,` Del`]})]}),h&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:h})]}),(0,$.jsx)(dn,{orientation:`vertical`,className:`h-6`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>u(!n),children:`Review Changes`}),(0,$.jsx)(W,{variant:`destructive`,onClick:d,children:i}),a&&(0,$.jsx)(W,{onClick:f,disabled:t.length===0,children:`Merge Selected`})]})]})]})}var zr=e=>e.trim().toLowerCase(),Br=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),Vr=(e,t)=>e.data.columns.find(e=>String(e.id)===Br(t));function Hr(e,t){let n=t.find(t=>t.id===e.source),r=t.find(t=>t.id===e.target);if(!n||!r)return null;let i=Vr(n,e.sourceHandle),a=Vr(r,e.targetHandle);return!i||!a?null:`${zr(n.data.name)}.${zr(i.name)}>${zr(r.data.name)}.${zr(a.name)}`}function Ur(e,t){return e.type.toLowerCase()!==t.type.toLowerCase()||!!e.is_pk!=!!t.is_pk||!!e.is_nullable!=!!t.is_nullable||!!e.is_unique!=!!t.is_unique||(e.default_value??null)!==(t.default_value??null)||(e.comment||``)!==(t.comment||``)||(e.max_length??null)!==(t.max_length??null)||(e.numeric_precision??null)!==(t.numeric_precision??null)||(e.numeric_scale??null)!==(t.numeric_scale??null)||(e.enum_name||``)!==(t.enum_name||``)||(e.enum_values||``)!==(t.enum_values||``)}function Wr(e){let t=t=>zr(e.data.columns.find(e=>String(e.id)===String(t))?.name||t);return JSON.stringify({comment:e.data.comment||``,constraints:(e.data.constraints||[]).map(e=>({kind:e.kind,name:e.name||``,columns:(e.column_ids||[]).map(t),expression:e.expression||``})).sort((e,t)=>JSON.stringify(e).localeCompare(JSON.stringify(t))),indexes:(e.data.indexes||[]).map(e=>({name:e.name||``,columns:e.column_ids.map(t),unique:!!e.is_unique,algorithm:e.algorithm||``})).sort((e,t)=>JSON.stringify(e).localeCompare(JSON.stringify(t)))})}function Gr(e,t){let n=(e,t)=>String(e.data?.[t]||``).toLowerCase();return(e.label||``)!==(t.label||``)||n(e,`on_delete`)!==n(t,`on_delete`)||n(e,`on_update`)!==n(t,`on_update`)||n(e,`constraint_name`)!==n(t,`constraint_name`)}function Kr(e,t,n,r){let i=[],a=new Map(e.map(e=>[zr(e.data.name),e])),o=new Map(n.map(e=>[zr(e.data.name),e])),s=new Set([...a.keys(),...o.keys()]),c=[];for(let e of s){let t=a.get(e),n=o.get(e),r=`table:${e}`;if(!t&&n){i.push({id:r,kind:`table`,state:`new`,label:n.data.name,proposed:n}),c.push({...n,data:{...n.data,diffState:`new`}});continue}if(t&&!n){i.push({id:r,kind:`table`,state:`deleted`,label:t.data.name,current:t}),c.push({...t,data:{...t.data,columns:t.data.columns.map(e=>({...e,diffState:`deleted`})),diffState:`deleted`}});continue}if(!t||!n)continue;let s=new Map(t.data.columns.map(e=>[zr(e.name),e])),l=new Map(n.data.columns.map(e=>[zr(e.name),e])),u=new Set([...s.keys(),...l.keys()]),d=Wr(t)!==Wr(n);d&&i.push({id:r,kind:`table`,state:`modified`,label:t.data.name,current:t,proposed:n});let f=[];for(let n of u){let r=s.get(n),a=l.get(n),o=`column:${e}.${n}`,c=`${t.data.name}.${r?.name||a?.name||n}`;!r&&a?(d=!0,i.push({id:o,kind:`column`,state:`new`,label:c,proposed:a}),f.push({...a,diffState:`new`})):r&&!a?(d=!0,i.push({id:o,kind:`column`,state:`deleted`,label:c,current:r}),f.push({...r,diffState:`deleted`})):r&&a&&Ur(r,a)?(d=!0,i.push({id:o,kind:`column`,state:`modified`,label:c,current:r,proposed:a}),f.push({...a,diffState:`new`})):r&&f.push(r)}c.push({...t,data:{...t.data,columns:f,diffState:d?`modified`:void 0}})}let l=new Map(t.flatMap(t=>{let n=Hr(t,e);return n?[[n,t]]:[]})),u=new Map(r.flatMap(e=>{let t=Hr(e,n);return t?[[t,e]]:[]})),d=new Set([...l.keys(),...u.keys()]);for(let e of d){let t=l.get(e),n=u.get(e),r=`relation:${e}`;!t&&n?i.push({id:r,kind:`relation`,state:`new`,label:e,proposed:n}):t&&!n?i.push({id:r,kind:`relation`,state:`deleted`,label:e,current:t}):t&&n&&Gr(t,n)&&i.push({id:r,kind:`relation`,state:`modified`,label:e,current:t,proposed:n})}return{nodes:c,edges:r,changes:i,newCount:i.filter(e=>e.state===`new`).length,modifiedCount:i.filter(e=>e.state===`modified`).length,deletedCount:i.filter(e=>e.state===`deleted`).length}}var qr=e=>e.trim().toLowerCase(),Jr=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),Yr=(e,t,n)=>`col-${t}${e?.match(/-(source|target)(-(l|r))?$/)?.[0]||`-${n}`}`;function Xr(e,t,n){let r=t.find(t=>t.id===e.source),i=t.find(t=>t.id===e.target),a=r?.data.columns.find(t=>t.id===Jr(e.sourceHandle)),o=i?.data.columns.find(t=>t.id===Jr(e.targetHandle)),s=r&&n.find(e=>qr(e.data.name)===qr(r.data.name)),c=i&&n.find(e=>qr(e.data.name)===qr(i.data.name)),l=s&&a&&s.data.columns.find(e=>qr(e.name)===qr(a.name)),u=c&&o&&c.data.columns.find(e=>qr(e.name)===qr(o.name));return!s||!c||!l||!u?null:{...e,source:s.id,target:c.id,sourceHandle:Yr(e.sourceHandle,l.id,`source`),targetHandle:Yr(e.targetHandle,u.id,`target`)}}function Zr(e,t,n,r,i,a){let o=new Set(a),s=new Map(i.changes.map(e=>[e.id,e])),c=new Map(n.map(e=>[qr(e.data.name),e])),l=new Map(e.map(e=>[qr(e.data.name),e])),u=[];for(let[e,t]of l){let n=c.get(e),r=s.get(`table:${e}`);if(!n){r&&o.has(r.id)||u.push(t);continue}let i=!!r&&o.has(r.id),a=t.data.columns.flatMap(t=>{let r=qr(t.name),i=n.data.columns.find(e=>qr(e.name)===r),a=s.get(`column:${e}.${r}`);return i?[a&&o.has(a.id)?i:t]:a&&o.has(a.id)?[]:[t]});for(let r of n.data.columns){let n=qr(r.name);if(t.data.columns.some(e=>qr(e.name)===n))continue;let i=s.get(`column:${e}.${n}`);i&&o.has(i.id)&&a.push(r)}let l=new Set(a.map(e=>String(e.id))),d=(e=[])=>e.every(e=>l.has(String(e)));u.push({...t,data:{...t.data,...i?{comment:n.data.comment,constraints:(n.data.constraints||[]).filter(e=>d(e.column_ids)),indexes:(n.data.indexes||[]).filter(e=>d(e.column_ids))}:{},columns:a}})}for(let[e,t]of c){if(l.has(e))continue;let n=s.get(`table:${e}`);n&&o.has(n.id)&&u.push(t)}let d=t.filter(t=>Xr(t,e,u)),f=new Map(t.flatMap(t=>{let n=Hr(t,e);return n?[[n,t]]:[]}));for(let t of i.changes.filter(e=>e.kind===`relation`&&o.has(e.id))){let r=t.id.replace(/^relation:/,``);if(f.get(r)){let t=d.findIndex(t=>Hr(t,e)===r);t>=0&&d.splice(t,1)}if(t.state!==`deleted`&&t.proposed&&`source`in t.proposed){let e=Xr(t.proposed,n,u);e&&d.push(e)}}return{nodes:ae(u),edges:d}}function Qr(e,t){let[n,r]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),o=(0,Q.useRef)(e),s=(0,Q.useRef)(t);return o.current=e,s.current=t,(0,Q.useEffect)(()=>(r(!1),()=>{a.current?.abort(),a.current=null}),[e]),{sync:(0,Q.useCallback)(async()=>{if(!e||a.current)return;let t=new AbortController,n=ln();a.current=t;let c=()=>a.current===t&&o.current===e&&ln()===n&&!t.signal.aborted;r(!0);try{let n=await cn(`/api/catalogs/${e}/schema`,{method:`POST`,signal:t.signal}),r=await n.json();if(!c())return;if(!n.ok)throw Error(r.error||`Failed to sync schema`);if(!Array.isArray(r.schema))throw Error(`Invalid database schema response`);s.current(r)}catch(e){c()&&i.error(e instanceof Error?e.message:`Failed to sync schema`)}finally{a.current===t&&(a.current=null,r(!1))}},[e]),isSyncing:n}}function $r(e,t=[],n=null){let r=t.length>0,i=Math.max(0,...e.map(e=>e.zIndex??0)),a=i+1e3,o=i+1001;return e.map(e=>{let i=r&&t.some(t=>e.source===t||e.target===t),s=i||e.selected||e.id===n?`var(--edge-selected)`:`var(--edge-color)`,c=[e.className];return i?c.push(`edge-animated-active`):r&&c.push(`edge-dimmed`),{...e,...e.selected?{zIndex:a}:{},...e.id===n?{zIndex:o}:{},type:`smoothstep`,style:{...e.style,stroke:s,strokeWidth:2},markerEnd:{type:oe.Arrow,color:s,width:10,height:10},className:c.filter(Boolean).join(` `)}})}function ei(e){let t=[];for(let n of e){let e=t.at(-1),r=t.at(-2);(e?.x!==n.x||e.y!==n.y)&&(r&&e&&(r.x===e.x&&e.x===n.x||r.y===e.y&&e.y===n.y)&&t.pop(),t.push(n))}return t}function ti(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function ni(e,t,n=[]){let r=ei(e),i=r[t.segment],a=r[t.segment+1];if(!i||!a)return null;let o=Math.abs(a.x-i.x)+Math.abs(a.y-i.y),s=(i.y===a.y?t.width:t.height)/2+12;if(o<s*2)return null;let c=Math.min(1-s/o,Math.max(s/o,t.ratio)),l={x:i.x+(a.x-i.x)*c,y:i.y+(a.y-i.y)*c};return n.some(e=>ti(ri(l,t),e))?null:l}function ri(e,t){return{x:e.x-t.width/2-4,y:e.y-t.height/2-4,width:t.width+8,height:t.height+8}}function ii(e){let t=ei(e.points),n=Math.max(32,e.label.length*7+8);return t.slice(1).flatMap((e,r)=>{let i=t[r],a=Math.abs(e.x-i.x)+Math.abs(e.y-i.y),o=i.y===e.y?n:22,s=o/2+12;if(a<s*2)return[];let c=new Set([a/2,s,a-s]);for(let e=s;e<=a-s;e+=o+12)c.add(e);return[...c].sort((e,t)=>Math.abs(e-a/2)-Math.abs(t-a/2)).map(e=>({segment:r,ratio:e/a,width:n,height:22,shared:!1}))}).sort((e,n)=>Number(t[e.segment].x===t[e.segment+1].x)-Number(t[n.segment].x===t[n.segment+1].x))}function ai(e,t){let n=new Map,r=[],i=[];for(let a of[...e].sort((e,t)=>e.id.localeCompare(t.id))){let o=ii(a).filter(e=>{let n=ri(ni(a.points,e),e);return![...t,...r].some(e=>ti(n,e))}),s=o.find(t=>{let n=ri(ni(a.points,t),t);return!e.some(e=>e.id!==a.id&&e.points.slice(1).some((t,r)=>Jn(e.points[r],t,[n])))});s?(n.set(a.id,s),r.push(ri(ni(a.points,s),s))):o[0]&&i.push(a)}for(let e of i){let i=ii(e).find(n=>{let i=ri(ni(e.points,n),n);return![...t,...r].some(e=>ti(i,e))});i&&n.set(e.id,{...i,shared:!0})}return n}function oi(e,t,n){let r=t.get(e);return r?!r.shared||e===n:!1}var si=(0,Q.createContext)({anchors:new Map,activeId:null});function ci({nodes:e,edges:t,tables:n,activeId:r,children:i}){let{getInternalNode:a}=U(),o=(0,Q.useMemo)(()=>{let r=new Map(e.map(e=>[e.id,e])),i=e=>{let t=a(e),n=r.get(e);return t&&n?{...t,internals:{...t.internals,positionAbsolute:n.position}}:void 0};return ai(t.flatMap(e=>{if(e.label===void 0||e.label===null||e.label===``)return[];let t=i(e.source),r=i(e.target);if(!t||!r)return[];let a=f({id:e.id,sourceNode:t,targetNode:r,sourceHandle:e.sourceHandle??null,targetHandle:e.targetHandle??null,connectionMode:u.Strict});return a?[{id:e.id,label:String(e.label),points:Wn({x:a.sourceX,y:a.sourceY},{x:a.targetX,y:a.targetY},a.sourcePosition===C.Right,a.targetPosition===C.Right,n)}]:[]}),n)},[e,t,n,a]),s=(0,Q.useMemo)(()=>({anchors:o,activeId:r}),[o,r]);return(0,$.jsx)(si.Provider,{value:s,children:i})}var li=(0,Q.createContext)([]);function ui(e){let t=(0,Q.useContext)(li),n=(0,Q.useContext)(si),{getInternalNode:r}=U(),i=le(t=>!!(t.nodeLookup.get(e.source)?.dragging||t.nodeLookup.get(e.target)?.dragging)),{points:a,obstacles:o}=(0,Q.useMemo)(()=>{let n=[r(e.source),r(e.target)].flatMap(e=>e?[{id:e.id,...e.internals.positionAbsolute,...S(e)}]:[]),a=Xn(t,n);return{points:(i?Yn:Wn)({x:e.sourceX,y:e.sourceY},{x:e.targetX,y:e.targetY},e.sourcePosition===C.Right,e.targetPosition===C.Right,a),obstacles:a}},[e.source,e.target,e.sourceX,e.sourceY,e.targetX,e.targetY,e.sourcePosition,e.targetPosition,t,r,i]),s=Un(a),c=n.anchors.get(e.id),l=c?ni(a,c,o):null,u=l&&oi(e.id,n.anchors,n.activeId),d=n.activeId===e.id||e.selected;return(0,$.jsxs)(`g`,{className:d?`erd-edge-active`:void 0,children:[e.label!=null&&(0,$.jsx)(`title`,{children:String(e.label)}),(0,$.jsx)(L,{id:e.id,path:s,markerStart:e.markerStart,markerEnd:e.markerEnd,style:e.style,interactionWidth:e.interactionWidth,label:u?e.label:void 0,labelX:l?.x,labelY:l?.y,labelStyle:d?{...e.labelStyle,fill:`var(--edge-selected)`,fontWeight:600}:e.labelStyle,labelShowBg:e.labelShowBg,labelBgStyle:e.labelBgStyle})]})}function di(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e===t[n])}function fi({isReadOnly:e,isProductionDb:t,addEntity:n,onImportSQL:r,onAutoLayout:i,explorerOpen:a,explorerShortcut:s,onToggleExplorer:c,onOpenDBML:l,onOpenRepository:u,handleSync:d,isSyncing:f,handleExportImage:p,undo:m,redo:h,canUndo:g,canRedo:_}){let v=pr(),y=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent),b=`Undo (${y?`⌘Z`:`Ctrl+Z`})`,x=`Redo (${y?`⇧⌘Z`:`Ctrl+Y`})`,S=(e,t)=>v?t:(0,$.jsxs)(de,{children:[(0,$.jsx)(fe,{render:t.props.disabled?(0,$.jsx)(`span`,{className:`inline-flex`,children:t}):t}),(0,$.jsx)(pe,{side:`right`,children:e})]}),C=`h-9 px-3 border-border hover:bg-muted bg-muted/50 text-xs font-semibold cursor-pointer`,w=o(`size-3.5`,v&&`sm:mr-1.5`),T=e=>v&&(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:e});return(0,$.jsx)(`div`,{className:o(`absolute z-10 pointer-events-none flex`,v?`top-6 inset-x-0 justify-center px-3`:`top-4 left-4 bottom-28 items-start`),children:(0,$.jsxs)(`div`,{role:`group`,"aria-label":`ERD tools`,className:o(`flex gap-1.5 p-1.5 bg-background/95 backdrop-blur-md border border-border/50 rounded-2xl shadow-2xl pointer-events-auto no-scrollbar`,v?`items-center max-w-full overflow-x-auto`:`flex-col items-center max-h-full overflow-y-auto`),children:[S(`Explorer (${s.label})`,(0,$.jsxs)(W,{onClick:c,variant:a?`secondary`:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Explorer: tables and relationships`,"aria-pressed":a,"aria-keyshortcuts":t?void 0:s.ariaKeyShortcuts,className:v?C:void 0,children:[(0,$.jsx)(pt,{className:w}),T(`Explorer`)]})),!e&&(0,$.jsx)(`div`,{className:o(`bg-border shrink-0`,v?`w-px h-6 mx-0.5`:`h-px w-6 my-0.5`)}),!e&&S(`Add Table`,(0,$.jsxs)(W,{onClick:n,size:v?`sm`:`icon-lg`,"aria-label":`Add Table`,className:v?`h-9 px-3 sm:px-4 font-bold shadow-lg shadow-primary/20 cursor-pointer`:void 0,children:[(0,$.jsx)(he,{className:o(`size-4`,v&&`sm:mr-2`)}),T(`Add Table`)]})),!e&&S(`Import SQL`,(0,$.jsxs)(W,{onClick:r,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Import SQL`,className:v?C:void 0,children:[(0,$.jsx)(qe,{className:w}),T(`Import SQL`)]})),!t&&!e&&S(`DBML`,(0,$.jsxs)(W,{onClick:l,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`DBML`,className:v?C:void 0,children:[(0,$.jsx)(Tt,{className:w}),T(`DBML`)]})),!e&&!t&&sn()&&S(`Repository`,(0,$.jsxs)(W,{onClick:u,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Repository`,className:v?C:void 0,children:[(0,$.jsx)(et,{className:w}),T(`Repository`)]})),i&&(!e||t)&&S(`Auto Layout`,(0,$.jsxs)(W,{onClick:i,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Auto Layout`,className:v?C:void 0,children:[(0,$.jsx)(Nt,{className:w}),T(`Auto Layout`)]})),t&&S(f?`Syncing...`:`Sync`,(0,$.jsxs)(W,{onClick:d,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":f?`Syncing...`:`Sync`,disabled:f,className:v?`h-9 px-3 border-amber-500/50 hover:bg-amber-500/10 bg-amber-500/5 text-amber-600 dark:text-amber-400 text-xs font-semibold cursor-pointer`:void 0,children:[(0,$.jsx)(Y,{className:o(w,f&&`animate-spin`)}),T(f?`Syncing...`:`Sync`)]})),t&&S(`Export SVG`,(0,$.jsxs)(W,{onClick:p,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Export SVG`,title:v?`Export SVG`:void 0,className:v?C:void 0,children:[(0,$.jsx)(Oe,{className:w}),T(`Export SVG`)]})),!e&&(0,$.jsxs)(`div`,{className:o(`flex gap-0.5`,v?`items-center ml-auto`:`flex-col items-center`),children:[S(b,(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:m,disabled:!g,"aria-label":b,title:v?b:void 0,className:v?`h-8 w-8 text-muted-foreground hover:text-foreground disabled:opacity-30`:void 0,children:(0,$.jsx)(on,{className:`size-4`})})),S(x,(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:h,disabled:!_,"aria-label":x,title:v?x:void 0,className:v?`h-8 w-8 text-muted-foreground hover:text-foreground disabled:opacity-30`:void 0,children:(0,$.jsx)(Pt,{className:`size-4`})}))]})]})})}var pi=e=>e?e.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``):null;function mi(e,t){let n=pi(t),r=n?e.data.columns.find(e=>e.id===n):void 0;return{nodeId:e.id,table:e.data.name,column:r?.name??n??``,isPk:!!r?.is_pk}}function hi(e,t){let n=new Map(e.map(e=>[e.id,e])),r=a[1].shortLabel;return t.flatMap(e=>{let t=n.get(e.source),i=n.get(e.target);if(!t||!i)return[];let o=mi(t,e.sourceHandle),s=mi(i,e.targetHandle),[c,l]=o.isPk&&!s.isPk?[s,o]:[o,s],u=a.find(t=>t.shortLabel===e.label)?.shortLabel??r,d=String(e.data?.constraint_name??``).trim();return[{id:e.id,fromNodeId:c.nodeId,fromTable:c.table,fromColumn:c.column,toNodeId:l.nodeId,toTable:l.table,toColumn:l.column,type:u,...d?{constraintName:d}:{}}]})}function gi(e,t){let n=t.trim().toLowerCase();return e.filter(e=>!n||`${e.fromTable}.${e.fromColumn} ${e.toTable}.${e.toColumn}`.toLowerCase().includes(n)).sort((e,t)=>e.fromTable.localeCompare(t.fromTable)||e.fromColumn.localeCompare(t.fromColumn)||e.toTable.localeCompare(t.toTable))}function _i(e){(0,Q.useEffect)(()=>{e.current?.querySelector(`[aria-current="true"]`)?.scrollIntoView({block:`nearest`})},[e])}var vi=e=>`${e.fromTable}.${e.fromColumn} → ${e.toTable}.${e.toColumn}`;function yi({rows:e,search:t,onSearchChange:n,activeId:r,onSelect:i,onEdit:a}){let o=(0,Q.useMemo)(()=>gi(e,t),[e,t]),s=(0,Q.useRef)(null);return _i(s),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-3 border-b p-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Relationships`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a?`Find a relationship or edit its properties.`:`Find a relationship on the canvas.`})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Gt,{className:`absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(Z,{value:t,onChange:e=>n(e.target.value),placeholder:`Search tables or columns...`,className:`pl-9`,autoFocus:!0})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Showing `,o.length,` of `,e.length,` relationships`]})]}),(0,$.jsxs)(`div`,{ref:s,className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-2`,children:[o.map(e=>{let t=vi(e);return(0,$.jsxs)(`div`,{className:`group flex items-center gap-1 rounded-md border border-transparent px-1 hover:border-border hover:bg-muted/50 has-[[aria-current=true]]:bg-muted has-[[aria-current=true]]:shadow-[inset_2px_0_0_var(--primary)]`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),"aria-current":e.id===r?`true`:void 0,className:`flex min-w-0 flex-1 items-start gap-2 px-2 py-2.5 text-left`,title:`Show ${t}`,children:[(0,$.jsx)(Ve,{className:`mt-0.5 size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-mono text-xs font-medium`,children:t}),e.constraintName&&(0,$.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.constraintName})]}),(0,$.jsx)(fr,{variant:`outline`,className:`shrink-0 font-mono text-[10px]`,children:e.type})]}),a&&(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:()=>a(e.id),title:`Edit ${t}`,"aria-label":`Edit relationship ${t}`,children:(0,$.jsx)(tt,{className:`size-3.5`})})]},e.id)}),o.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-10 text-center text-sm text-muted-foreground`,children:e.length===0?`No relationships yet.`:`No matching relationships found.`})]})]})}function bi(e,t){let n=t.trim().toLowerCase();return e.filter(e=>!n||e.data.name.toLowerCase().includes(n)).sort((e,t)=>e.data.name.localeCompare(t.data.name))}function xi({nodes:e,search:t,onSearchChange:n,activeId:r,onSelect:i,onEdit:a}){let o=(0,Q.useMemo)(()=>bi(e,t),[e,t]),s=(0,Q.useRef)(null);return _i(s),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-3 border-b p-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Tables`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a?`Find a table or open its properties.`:`Find a table on the canvas.`})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Gt,{className:`absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(Z,{value:t,onChange:e=>n(e.target.value),placeholder:`Search tables...`,className:`pl-9`,autoFocus:!0})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Showing `,o.length,` of `,e.length,` tables`]})]}),(0,$.jsxs)(`div`,{ref:s,className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-2`,children:[o.map(e=>(0,$.jsxs)(`div`,{className:`group flex items-center gap-1 rounded-md border border-transparent px-1 hover:border-border hover:bg-muted/50 has-[[aria-current=true]]:bg-muted has-[[aria-current=true]]:shadow-[inset_2px_0_0_var(--primary)]`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),"aria-current":e.id===r?`true`:void 0,className:`flex min-w-0 flex-1 items-center gap-2 px-2 py-2.5 text-left`,title:`Jump to ${e.data.name}`,children:[(0,$.jsx)(Mt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e.data.name}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.data.columns.length})]}),a&&(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:()=>a(e.id),title:`Edit ${e.data.name} properties`,"aria-label":`Edit ${e.data.name} properties`,children:(0,$.jsx)(tt,{className:`size-3.5`})})]},e.id)),o.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-10 text-center text-sm text-muted-foreground`,children:`No matching tables found.`})]})]})}var Si={tab:`tables`,tableSearch:``,relationshipSearch:``,activeTableId:null,activeRelationshipId:null,editingEdgeId:null};function Ci({nodes:e,edges:t,state:n,onChange:r,editing:i,onHighlight:a,onClose:s,shortcutLabel:c}){let l=(0,Q.useMemo)(()=>hi(e,t),[e,t]),u=i&&n.editingEdgeId?t.find(e=>e.id===n.editingEdgeId)??null:null,d=u?l.find(e=>e.id===u.id):void 0;return(0,Q.useEffect)(()=>{let i={};n.editingEdgeId&&!t.some(e=>e.id===n.editingEdgeId)&&(i.editingEdgeId=null),n.activeRelationshipId&&!t.some(e=>e.id===n.activeRelationshipId)&&(i.activeRelationshipId=null),n.activeTableId&&!e.some(e=>e.id===n.activeTableId)&&(i.activeTableId=null),Object.keys(i).length&&r(i)},[n.editingEdgeId,n.activeRelationshipId,n.activeTableId,e,t,r]),(0,$.jsxs)(`aside`,{"aria-label":`Explorer`,className:o(`nowheel absolute left-[4.5rem] top-3 bottom-3 z-20 flex w-[300px] max-w-[calc(100%-5.5rem)] flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-2xl`,`max-md:left-2 max-md:right-2 max-md:top-20 max-md:w-auto max-md:max-w-none`),children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:`Explorer`}),(0,$.jsx)(mn,{children:c})]}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:s,"aria-label":`Close Explorer`,title:`Close Explorer`,children:(0,$.jsx)(It,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-b px-3 pt-2 pb-2`,children:(0,$.jsx)(rr,{value:n.tab,onValueChange:e=>r({tab:e}),className:`w-full`,children:(0,$.jsxs)(lr,{className:`w-full`,children:[(0,$.jsxs)(ur,{value:`tables`,children:[`Tables (`,e.length,`)`]}),(0,$.jsxs)(ur,{value:`relationships`,children:[`Relationships (`,l.length,`)`]})]})})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:n.tab===`tables`?(0,$.jsx)(xi,{nodes:e,search:n.tableSearch,onSearchChange:e=>r({tableSearch:e}),activeId:n.activeTableId,onSelect:e=>{r({activeTableId:e}),a({type:`table`,id:e})},onEdit:i?e=>{r({activeTableId:e}),i.onEditTable(e)}:void 0}):i&&u?(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`shrink-0 border-b px-4 py-3`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r({editingEdgeId:null}),className:`flex shrink-0 items-center gap-1 font-medium text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(rt,{className:`size-3.5`}),` Relationships`]}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`span`,{className:`truncate font-mono font-medium text-foreground`,title:d?vi(d):void 0,children:d?vi(d):`Relationship`})]})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-2`,children:(0,$.jsx)(_n,{selectedEdge:u,nodes:e,onUpdateEdge:i.onUpdateEdge,onFlipEdge:i.onFlipEdge,onDeleteEdge:i.onDeleteEdge})})]}):(0,$.jsx)(yi,{rows:l,search:n.relationshipSearch,onSearchChange:e=>r({relationshipSearch:e}),activeId:n.activeRelationshipId,onSelect:e=>{r({activeRelationshipId:e}),a({type:`relationship`,id:e})},onEdit:i?e=>{r({activeRelationshipId:e,editingEdgeId:e}),a({type:`relationship`,id:e})}:void 0})}),(0,$.jsx)(`p`,{className:`shrink-0 border-t px-3 py-2 text-[11px] text-muted-foreground`,children:i?`Click a row to highlight it on the canvas · ✎ to edit`:`Click a row to highlight it on the canvas`})]})}var wi=[...r].sort((e,t)=>e.localeCompare(t));function Ti({value:e,onValueChange:t,className:n}){return(0,$.jsx)(Xe,{value:e,onChange:t,items:wi,placeholder:`Type`,searchPlaceholder:`Search type...`,emptyMessage:`No types found`,className:n,getItemValue:e=>e,getItemLabel:e=>e,filterItem:(e,t)=>e.toLowerCase().includes(t.toLowerCase())})}var Ei=[{id:`sql`,label:`SQL`,formats:[{id:`mysql`,label:`MySQL`},{id:`postgresql`,label:`PostgreSQL`}]},{id:`laravel`,label:`Laravel`,formats:[{id:`laravel_migration`,label:`Migration`},{id:`laravel_model`,label:`Model`}]},{id:`goravel`,label:`Goravel`,formats:[{id:`goravel`,label:`Model`},{id:`goravel_migration`,label:`Migration`}]},{id:`typescript`,label:`TypeScript`,formats:[{id:`typescript`,label:`Interface`},{id:`zod`,label:`Zod`}]},{id:`prisma`,label:`Prisma`,formats:[{id:`prisma`,label:`Schema`}]}],Di={mysql:Fn,postgresql:Zn,laravel_migration:Qn,laravel_model:zn,goravel:Hn,goravel_migration:$n,typescript:Ln,zod:In,prisma:Bn},Oi={mysql:`sql`,postgresql:`sql`,laravel_migration:`php`,laravel_model:`php`,goravel:`go`,goravel_migration:`go`,typescript:`typescript`,zod:`typescript`,prisma:`prisma`},ki={mysql:`sql`,postgresql:`sql`,laravel_migration:`php`,laravel_model:`php`,goravel:`go`,goravel_migration:`go`,typescript:`ts`,zod:`ts`,prisma:`prisma`};function Ai({entity:e,mode:t,onUpdateEntity:n,dbmlReadOnly:r=!1}){let{resolvedTheme:i}=tr(),[a,s]=Q.useState(Ei[0].id),[c,l]=Q.useState(Ei[0].formats[0].id),[u,d]=Q.useState(!1),f=Q.useMemo(()=>({id:e.id,type:`entity`,position:{x:e.x,y:e.y},data:e}),[e]),p=Q.useMemo(()=>R([f],[]),[f]),[h,g]=Q.useState(p);Q.useEffect(()=>g(p),[e.id,p]);let _=Ei.find(e=>e.id===a)??Ei[0],v=Di[c](e),y=Oi[c]||`sql`,b=m(),x=Q.useMemo(()=>{if(!b)return{entity:null,error:`Loading the DBML parser…`};if(!h.trim())return{entity:null,error:`DBML cannot be empty.`};try{let t=T(h);if(t.nodes.length!==1)return{entity:null,error:`DBML must contain exactly one Table block.`};let n=t.nodes[0].data;return n.name===e.name?{entity:n,error:``}:{entity:null,error:`The table name must be exactly "${e.name}".`}}catch(e){return{entity:null,error:e instanceof Error?e.message:`Invalid DBML.`}}},[h,e,b]),S=Q.useMemo(()=>{if(t===`dbml`)return[En()];switch(y){case`sql`:return[En()];case`php`:return[vn()];case`go`:return[kn(),...Sn(i)];case`typescript`:case`prisma`:return[yn({typescript:!0})];default:return[]}},[y,t,i]),C=async()=>{await navigator.clipboard.writeText(t===`dbml`?p:v),d(!0),window.setTimeout(()=>d(!1),2e3)},w=()=>{let t=new Blob([v],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase()}_${c}.${ki[c]||`txt`}`,r.click(),URL.revokeObjectURL(n)},E=()=>{let t=x.entity;if(!t)return;let r=new Map(e.columns.map(e=>[e.name.toLowerCase(),e])),i=(e=[])=>e.map(e=>{let n=t.columns.find(t=>t.id===e);return n?r.get(n.name.toLowerCase())?.id??e:e}),a={...e,comment:t.comment,columns:t.columns.map((e,t)=>({...e,id:r.get(e.name.toLowerCase())?.id??crypto.randomUUID(),_is_fk:r.get(e.name.toLowerCase())?._is_fk,sort_order:t})),constraints:(t.constraints||[]).map(t=>({...t,entity_id:e.id,column_ids:i(t.column_ids)})),indexes:(t.indexes||[]).map(t=>({...t,entity_id:e.id,column_ids:i(t.column_ids)}))};n(a),g(R([{id:a.id,type:`entity`,position:{x:a.x,y:a.y},data:a}],[]))};if(t===`dbml`){let t=h!==p;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold`,children:`Table DBML`}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r?`Read only. Edit the full schema from DBML in the toolbar.`:`Only the DBML for “${e.name}” can be edited.`})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden bg-muted`,children:(0,$.jsx)(Cn,{value:r?p:h,onChange:g,editable:!r,readOnly:r,extensions:S,theme:i===`dark`?xn:void 0,height:`100%`,basicSetup:{lineNumbers:!0,foldGutter:!1},className:`h-full text-[13px] text-foreground/90`})}),r?(0,$.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-border bg-muted/20 p-3`,children:(0,$.jsxs)(W,{variant:`outline`,onClick:C,children:[u?(0,$.jsx)(Te,{className:`mr-2 size-3.5 text-green-500`}):(0,$.jsx)(hr,{className:`mr-2 size-3.5`}),u?`Copied`:`Copy`]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-8 px-4 py-2 text-xs text-destructive`,children:x.error}),(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-border bg-muted/20 p-3`,children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>g(p),children:`Reset`}),(0,$.jsx)(W,{onClick:E,disabled:!!x.error||!t,children:`Apply DBML`})]})]})]})}return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b border-border px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto`,children:Ei.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>{s(e.id),l(e.formats[0].id)},className:o(`rounded-md px-2.5 py-1.5 text-[11px] font-semibold whitespace-nowrap`,a===e.id?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e.label},e.id))}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto rounded-lg bg-muted p-1`,children:_.formats.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:o(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-semibold whitespace-nowrap`,c===e.id?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:[(0,$.jsx)(Ue,{className:`size-3.5`}),e.label]},e.id))})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden bg-muted`,children:(0,$.jsx)(Cn,{value:v,extensions:S,theme:i===`dark`?xn:void 0,readOnly:!0,height:`100%`,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!1},className:`h-full text-[13px] text-foreground/90`})}),(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-border bg-muted/20 p-3`,children:[(0,$.jsxs)(W,{variant:`outline`,onClick:w,children:[(0,$.jsx)(Oe,{className:`mr-2 size-3.5`}),`Download`]}),(0,$.jsxs)(W,{variant:`outline`,onClick:C,children:[u?(0,$.jsx)(Te,{className:`mr-2 size-3.5 text-green-500`}):(0,$.jsx)(hr,{className:`mr-2 size-3.5`}),u?`Copied`:`Copy`]})]})]})}function ji(e,t,n,r){if(t===n)return null;let i=[...e].sort((e,t)=>(e.sort_order??0)-(t.sort_order??0)),a=i.find(e=>e.id===t);if(!a)return null;let o=i.filter(e=>e.id!==t),s=o.findIndex(e=>e.id===n);return s===-1?null:(o.splice(s+ +(r===`after`),0,a),o.map((e,t)=>({...e,sort_order:t})))}var Mi=[`#6366f1`,`#8b5cf6`,`#ec4899`,`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`],Ni=255,Pi=[{name:`created_at`,type:`TIMESTAMP`,is_nullable:!1},{name:`updated_at`,type:`TIMESTAMP`,is_nullable:!1},{name:`deleted_at`,type:`TIMESTAMP`,is_nullable:!0}],Fi=e=>{let t=e.trim();if(!t)return null;let n=Number.parseInt(t,10);return Number.isFinite(n)&&n>=0?n:null};function Ii({selectedEntity:e,onUpdateEntity:t,onDeleteEntity:n,onBackToTables:r,propertiesOnly:a=!1,headerActions:s,dbmlReadOnly:l=!1}){let[u,d]=(0,Q.useState)(e),[f,p]=(0,Q.useState)(`properties`),[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(Object.fromEntries(Pi.map(e=>[e.name,!0]))),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(null),T=(0,Q.useRef)(null),E=(0,Q.useRef)(null),D=(0,Q.useRef)(null),O=(0,Q.useRef)(!1),k=(0,Q.useRef)(null),A=(0,Q.useRef)(u?.columns?.length||0),ee=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=u?.columns?.length||0;e>A.current&&requestAnimationFrame(()=>{k.current?.scrollIntoView({behavior:`smooth`,block:`end`})}),A.current=e},[u?.columns?.length]);let[j,M]=(0,Q.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}});if((0,Q.useEffect)(()=>{e?.id!==u?.id&&d(e)},[e?.id]),!e||!u)return null;let N=(e,n=!1)=>{n?(D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{t(e,{immediate:!0})},300)):t(e)},P=e=>{d({...u,name:e})},F=e=>{let t={...u,color:e};d(t),N(t,!0)},te=()=>{let e=u.columns.reduce((e,t)=>Math.max(e,t.sort_order||0),-1),t={id:Math.random().toString(36).substring(2,11),name:`new_column`,type:`VARCHAR`,max_length:Ni,is_pk:!1,is_nullable:!0,default_value:`NULL`,sort_order:e+1},n={...u,columns:[...u.columns,t]};ee.current=t.id,d(n),N(n,!0)},ne=()=>{let e=new Set(u.columns.map(e=>e.name.toLowerCase())),t=Pi.filter(t=>g[t.name]&&!e.has(t.name));if(t.length===0){i.info(`Selected audit columns already exist or none were selected`);return}let n=u.columns.reduce((e,t)=>Math.max(e,t.sort_order||0),-1)+1,r=t.map((e,t)=>({id:crypto.randomUUID(),name:e.name,type:e.type,is_pk:!1,is_nullable:e.is_nullable,default_value:_(e.is_nullable?`NULL`:null,e.is_nullable),sort_order:n+t})),a={...u,columns:[...u.columns,...r]};ee.current=r[r.length-1].id,d(a),N(a,!0),b(!1),i.success(`${r.length} audit column${r.length===1?``:`s`} added`)},L=()=>{let e=u.columns.filter(e=>e.is_pk).sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),t=u.columns.filter(e=>!e.is_pk).sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),n=[...e,...t].map((e,t)=>({...e,sort_order:t})),r={...u,columns:n};d(r),N(r,!0)},re=(e,t)=>{d({...u,columns:u.columns.map(n=>n.id===e?{...n,...t}:n)})},R=(e,t,n=!1)=>{if(O.current){O.current=!1;return}if(`name`in t&&typeof t.name==`string`){let n=t.name.trim();if(u.columns.some(t=>t.id!==e&&t.name.toLowerCase()===n.toLowerCase())){i.error(`Column name "${n}" already exists in this table`);let t=u.columns.find(t=>t.id===e);t&&d({...u,columns:u.columns.map(n=>n.id===e?t:n)});return}t={...t,name:n}}if(`type`in t){let n=u.columns.find(t=>t.id===e);t={...t,.../^varchar$/i.test(String(t.type))&&n?.max_length==null&&{max_length:Ni},...!c(t.type)&&{max_length:null},...!I(t.type)&&{numeric_precision:null,numeric_scale:null}}}let r={...u,columns:u.columns.map(n=>{if(n.id!==e)return n;let r={...n,...t},i=_(r.default_value,!!r.is_nullable);return r.is_nullable&&!i?{...r,default_value:`NULL`}:{...r,default_value:i}})};d(r),N(r,n)},z=e=>{let t={...u,columns:e};d(t),N(t,!0)},B=()=>{T.current=null,E.current=null,w(null),S(null)},V=(e,t)=>{e.button===0&&(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),T.current=t,S(t))},ie=e=>{if(!T.current)return;e.preventDefault();let t=document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-column-id]`),n=t?.dataset.columnId;if(!t||!n)return;let r=t.getBoundingClientRect(),i=e.clientY<r.top+r.height/2?`before`:`after`,a={id:n,position:i};E.current=a,w(e=>e?.id===n&&e.position===i?e:a)},H=(e,t)=>{e.preventDefault();let n=E.current,r=n&&ji(u.columns,t,n.id,n.position);r&&z(r),B()},U=e=>{let t={...u,columns:u.columns.filter(t=>t.id!==e)};d(t),N(t,!0)};return(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-background px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex min-w-0 items-center gap-2 text-xs`,children:[r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:r,className:`flex shrink-0 items-center gap-1 font-medium text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(rt,{className:`size-3.5`}),` Tables`]}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-foreground`,children:u.name})]}):(0,$.jsx)(`span`,{className:`truncate font-medium text-foreground`,children:u.name}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`ml-auto shrink-0 text-destructive hover:bg-destructive/10 hover:text-destructive`,title:`Delete table`,"aria-label":`Delete table ${u.name}`,onClick:()=>M({isOpen:!0,title:`Delete Table`,message:`Are you sure you want to delete the table "${u.name}"? This action cannot be undone.`,onConfirm:()=>{D.current&&clearTimeout(D.current),n(u.id),M(e=>({...e,isOpen:!1}))}}),children:(0,$.jsx)(qt,{className:`size-4`})}),s]}),!a&&(0,$.jsx)(`div`,{className:`flex w-full gap-1 rounded-lg border border-border bg-muted p-1`,"aria-label":`Table editor sections`,children:[[`properties`,`Properties`],[`schema`,`Schema`],[`dbml`,`DBML`]].map(([e,t])=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>p(e),className:o(`flex flex-1 items-center justify-center rounded-md px-3 py-2 text-xs font-semibold transition-colors`,f===e?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:bg-background/60 hover:text-foreground`),children:t},e))})]}),!a&&f!==`properties`?(0,$.jsx)(Ai,{entity:u,mode:f,dbmlReadOnly:l,onUpdateEntity:e=>{d(e),t(e)}}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`shrink-0 bg-background pt-6 px-6 pb-4 border-b border-border/50 shadow-sm z-10`,children:(0,$.jsxs)(`section`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:`Table Name`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)($e,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground z-10`}),(0,$.jsx)(Z,{type:`text`,value:u.name,onChange:e=>P(e.target.value),onBlur:()=>N(u),className:`pl-10 h-10 transition-all focus:ring-1`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:`Theme Color`}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:[Mi.map(e=>(0,$.jsx)(`button`,{onClick:()=>F(e),className:o(`w-7 h-7 rounded-full border-2 transition-all shadow-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,u.color===e?`border-foreground scale-110 shadow-md`:`border-transparent hover:scale-105`),style:{backgroundColor:e}},e)),(0,$.jsx)(`label`,{className:o(`relative w-7 h-7 rounded-full border-2 transition-all shadow-sm cursor-pointer ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2`,Mi.includes(u.color)?`hover:scale-105`:`border-foreground scale-110 shadow-md`),style:{borderColor:Mi.includes(u.color)?u.color:void 0,backgroundColor:Mi.includes(u.color)?`transparent`:u.color},title:`Custom color`,children:(0,$.jsx)(Z,{type:`color`,value:u.color,onChange:e=>F(e.target.value),className:`absolute inset-0 h-full w-full cursor-pointer opacity-0`})})]})]})]})}),(0,$.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between bg-popover/95 py-2 px-6 border-b border-border/50 z-10 shadow-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:[`Columns (`,u.columns.length,`)`]}),(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:L,className:`h-6 w-6 text-muted-foreground hover:text-primary transition-colors`,title:`Normalize (PKs to top)`,children:(0,$.jsx)(Ye,{className:`w-3.5 h-3.5`})}),(0,$.jsxs)(_e,{open:y,onOpenChange:b,children:[(0,$.jsx)(ge,{render:(0,$.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-6 w-6 text-muted-foreground hover:text-primary`,title:`Generate audit columns`,"aria-label":`Generate audit columns`,children:(0,$.jsx)(ht,{className:`w-3.5 h-3.5`})})}),(0,$.jsxs)(me,{align:`start`,className:`w-56 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold`,children:`Generate audit columns`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add common timestamp fields.`})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:Pi.map(e=>{let t=u.columns.some(t=>t.name.toLowerCase()===e.name);return(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(or,{checked:g[e.name],disabled:t,onCheckedChange:t=>v(n=>({...n,[e.name]:t===!0}))}),(0,$.jsx)(`span`,{className:o(t&&`text-muted-foreground line-through`),children:e.name}),t&&(0,$.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`Exists`})]},e.name)})}),(0,$.jsx)(W,{type:`button`,size:`sm`,className:`w-full`,onClick:ne,children:`Generate selected`})]})]})]}),(0,$.jsx)(W,{onClick:te,className:`h-8 w-8 rounded-full shadow-sm hover:shadow-md transition-all bg-white text-black hover:bg-white/90`,size:`icon`,children:(0,$.jsx)(he,{className:`w-4 h-4`})})]}),(0,$.jsx)(`section`,{className:`flex-1 overflow-y-auto custom-scrollbar p-4 space-y-2 min-h-0`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[[...u.columns].sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)).map(e=>(0,$.jsxs)(Rt,{"data-column-id":e.id,className:o(`gap-1 p-2 bg-muted/10 border border-border/30 shadow-none hover:border-primary/30 transition-all`,x===e.id&&`opacity-50`,C?.id===e.id&&C.position===`before`&&`border-t-2 border-t-primary`,C?.id===e.id&&C.position===`after`&&`border-b-2 border-b-primary`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Drag ${e.name} to reorder`,title:`Drag to reorder`,onPointerDown:t=>V(t,e.id),onPointerMove:ie,onPointerUp:t=>H(t,e.id),onPointerCancel:B,className:`h-7 w-6 shrink-0 touch-none select-none cursor-grab rounded text-muted-foreground hover:bg-primary/10 hover:text-primary active:cursor-grabbing`,children:(0,$.jsx)(xt,{className:`mx-auto h-4 w-4`})}),(0,$.jsx)(Z,{ref:t=>{t&&e.id===ee.current&&(t.focus(),t.select(),ee.current=null)},placeholder:`Column name`,value:e.name,onChange:t=>re(e.id,{name:t.target.value}),onBlur:t=>R(e.id,{name:t.target.value}),className:`h-8 min-w-0 flex-1 text-xs font-bold bg-background/50 border-border/50 focus-visible:ring-1 shadow-sm transition-all`}),(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>M({isOpen:!0,title:`Delete Column`,message:`Are you sure you want to delete the column "${e.name}"?`,onConfirm:()=>{U(e.id),M(e=>({...e,isOpen:!1}))}}),className:`h-8 w-8 text-destructive/70 hover:text-destructive hover:bg-destructive/10 shrink-0`,title:`Delete column`,children:(0,$.jsx)(qt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:o(`grid gap-1`,I(e.type)?`grid-cols-[minmax(0,1fr)_3.75rem_3.75rem_2rem_2rem_2rem]`:c(e.type)?`grid-cols-[minmax(0,1fr)_3.75rem_2rem_2rem_2rem]`:`grid-cols-[minmax(0,1fr)_2rem_2rem_2rem]`),children:[(0,$.jsx)(Ti,{value:e.type,onValueChange:t=>R(e.id,{type:t},!0),className:`min-w-0`}),c(e.type)&&(0,$.jsx)(Z,{type:`number`,min:1,value:e.max_length??``,onChange:t=>re(e.id,{max_length:Fi(t.target.value)}),onBlur:t=>R(e.id,{max_length:Fi(t.target.value)}),placeholder:`Max`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`}),I(e.type)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{type:`number`,min:1,value:e.numeric_precision??``,onChange:t=>re(e.id,{numeric_precision:Fi(t.target.value)}),onBlur:t=>R(e.id,{numeric_precision:Fi(t.target.value)}),placeholder:`Prec`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`}),(0,$.jsx)(Z,{type:`number`,min:0,value:e.numeric_scale??``,onChange:t=>re(e.id,{numeric_scale:Fi(t.target.value)}),onBlur:t=>R(e.id,{numeric_scale:Fi(t.target.value)}),placeholder:`Scale`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`})]}),(0,$.jsx)(W,{variant:e.is_pk?`default`:`outline`,size:`icon`,onClick:()=>R(e.id,{is_pk:!e.is_pk},!0),className:o(`h-8 w-8 transition-all`,e.is_pk?`bg-yellow-500 hover:bg-yellow-600 text-white`:`text-muted-foreground hover:text-foreground bg-background/50`),title:`Primary Key`,children:(0,$.jsx)(mt,{className:`w-3.5 h-3.5`})}),(0,$.jsx)(W,{variant:e.is_nullable?`outline`:`default`,size:`icon`,onClick:()=>R(e.id,{is_nullable:!e.is_nullable},!0),className:o(`h-8 w-8 transition-all`,e.is_nullable?`text-muted-foreground hover:text-foreground bg-background/50`:`bg-primary hover:bg-primary/90 text-primary-foreground`),title:`Not Null`,children:e.is_nullable?(0,$.jsx)(It,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Te,{className:`w-3.5 h-3.5`})}),(0,$.jsxs)(_e,{open:m===e.id,onOpenChange:t=>h(t?e.id:null),children:[(0,$.jsx)(ge,{render:(0,$.jsx)(W,{type:`button`,variant:`outline`,size:`icon`,"aria-expanded":m===e.id,onMouseDown:()=>{O.current=!0,window.setTimeout(()=>{O.current=!1},0)},className:o(`h-8 w-8 transition-colors`,m===e.id?`border-primary bg-primary text-primary-foreground hover:bg-primary/90`:`text-muted-foreground hover:text-foreground bg-background/50`,e.comment&&m!==e.id&&`border-primary/60`),title:`Field attributes`,"aria-label":`Field attributes`,children:(0,$.jsx)(Et,{className:`w-3.5 h-3.5`})})}),(0,$.jsxs)(me,{align:`end`,side:`left`,className:`w-72 space-y-2`,children:[(0,$.jsx)(nr,{className:`text-xs font-semibold`,children:`Field Attributes`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(or,{checked:!!e.is_unique,onCheckedChange:t=>R(e.id,{is_unique:t===!0},!0)}),`Unique`]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(nr,{htmlFor:`default-${e.id}`,className:`text-xs text-muted-foreground`,children:`Default value`}),(0,$.jsx)(Z,{id:`default-${e.id}`,value:e.default_value??(e.is_nullable?`NULL`:``),onChange:t=>re(e.id,{default_value:t.target.value}),onBlur:t=>R(e.id,{default_value:t.target.value.trim()||null}),placeholder:`NULL, 0, CURRENT_TIMESTAMP, 'pending'`,className:`h-8 text-sm`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(nr,{htmlFor:`comment-${e.id}`,className:`text-xs text-muted-foreground`,children:`Comment`}),(0,$.jsx)(jn,{id:`comment-${e.id}`,value:e.comment||``,onChange:t=>re(e.id,{comment:t.target.value}),onBlur:t=>R(e.id,{comment:t.target.value.trim()}),placeholder:`Add a comment`,className:`min-h-20 resize-y text-sm`})]})]})]})]}),e.type===`ENUM`&&(0,$.jsx)(Z,{type:`text`,value:e.enum_values||``,onChange:t=>re(e.id,{enum_values:t.target.value}),onBlur:()=>N(u),placeholder:`Enum values: active, inactive...`,className:`h-8 text-[10px] bg-background/50 border-border/50`})]},e.id)),(0,$.jsx)(`div`,{ref:k})]})})]}),(0,$.jsx)(ut,{isOpen:j.isOpen,title:j.title,message:j.message,onConfirm:j.onConfirm,onCancel:()=>M(e=>({...e,isOpen:!1}))})]})}function Li({entity:e,floating:t,onTogglePin:n,onClose:r,onBackToExplorer:i}){let{handleEntityUpdate:a,deleteEntity:s,setSelectedNodeId:c}=tr(),l=t?{left:t.left,top:t.top,maxHeight:`calc(100% - ${t.top+12}px)`}:void 0;return(0,$.jsx)(`aside`,{"aria-label":`Table ${e.name}`,"data-side":t?.side,style:l,className:o(`nowheel nodrag flex flex-col overflow-hidden border bg-popover text-popover-foreground`,t?`absolute z-30 h-[min(36rem,calc(100%-1.5rem))] w-96 rounded-xl shadow-2xl`:`w-85 shrink-0 rounded-xl max-md:absolute max-md:inset-y-0 max-md:right-0 max-md:z-30 max-md:w-[min(21.25rem,100%)] max-md:shadow-xl`),children:(0,$.jsx)(Ii,{selectedEntity:e,onUpdateEntity:a,onBackToTables:i,dbmlReadOnly:!0,onDeleteEntity:e=>{s(e),c(null),r()},headerActions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:n,"aria-pressed":!t,"aria-label":t?`Pin the table editor beside the canvas`:`Unpin the table editor`,title:t?`Pin`:`Unpin`,children:t?(0,$.jsx)(ft,{className:`size-4`}):(0,$.jsx)(_t,{className:`size-4`})}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:r,"aria-label":`Close table editor`,title:`Close (Esc)`,children:(0,$.jsx)(It,{className:`size-4`})})]})},e.id)})}function Ri(e,t,n){if(!e.sliceDoc(t,n).includes(`{`))return null;let r=e.doc.toString(),i=``,a=!1,o=!1,s=[];for(let e=0;e<r.length;e++){let c=r[e],l=r[e+1];if(a)c===`
|
|
1
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{a as r,i,o as a,s as o}from"./createLucideIcon-DCn6SI1F.js";import{d as s}from"./chunk-BV7QT456-B3UxAK3W.js";import{A as c,C as l,Ct as u,D as d,Dt as f,E as p,F as m,M as h,N as g,O as _,Ot as v,P as y,S as b,St as x,T as S,Tt as C,_ as w,a as T,b as E,bt as D,c as O,ct as k,d as A,dt as ee,f as j,ft as M,g as N,h as P,ht as F,it as te,j as I,l as ne,lt as L,m as re,o as R,p as z,s as B,st as V,u as ie,ut as H,vt as U,w as ae,wt as oe,x as se,xt as ce,yt as le}from"./note-importer-mHEzGrVx.js";import{t as W}from"./button-CYI0LXM3.js";import{s as ue}from"./useField-E2Vk7I_Z.js";import{c as de,d as fe,l as pe,n as me,o as he,r as ge,t as _e}from"./popover-DcdaCTLH.js";import{a as G,d as ve,f as ye,l as be,r as xe,s as Se,t as Ce,u as we}from"./dropdown-menu-BoXeiuAZ.js";import{t as Te}from"./check-BwjD7EK2.js";import{r as Ee}from"./getPseudoElementBounds-BEHunO5c.js";import{A as De,Ct as Oe,D as ke,Et as K,O as q,P as Ae,Tt as je,Y as J,a as Me,at as Ne,i as Pe,k as Fe,n as Ie,ot as Le,r as Re,t as ze}from"./ERDComments-BN8ryun0.js";import{A as Be,C as Ve,D as He,E as Ue,O as We,S as Ge,T as Ke,_ as qe,b as Je,g as Ye,h as Xe,i as Ze,k as Qe,v as $e,w as et,x as tt,y as nt}from"./w3c-keyname-BAyKiYyI.js";import{n as rt,t as Y}from"./refresh-cw-DyBeWpoi.js";import{t as it}from"./chevron-left-D_Hf28gP.js";import{i as at,n as ot,o as st,s as ct,t as X}from"./select-CdQCv8yP.js";import{n as lt,t as ut}from"./ConfirmModal-pEN41Kyx.js";import{a as dt,c as ft,d as pt,f as mt,h as ht,i as gt,l as _t,m as vt,n as yt,o as bt,p as xt,s as St,t as Ct,u as wt}from"./erdActions-XEHrDkpE.js";import{r as Tt}from"./pen-tool-CoHyO7pC.js";import{t as Et}from"./ellipsis-CfqIMSId.js";import{a as Dt,i as Ot,o as kt,r as At,t as jt}from"./field-BXvmJTfd.js";import{n as Mt,r as Nt,t as Pt}from"./redo-2-CUB0gf4Y.js";import{t as Ft}from"./message-square-B1YYK_eY.js";import{_ as It,a as Lt,d as Rt,i as zt,l as Bt,n as Vt,o as Ht,s as Ut,t as Wt,v as Gt}from"./dialog-BIk9Y-3N.js";import{t as Kt}from"./sparkles-BTRhjhc4.js";import{t as qt}from"./trash-2-CV7XVyhd.js";import{C as Jt,a as Yt,c as Xt,i as Zt,l as Qt,n as $t,o as en,r as tn,s as nn,t as rn,u as an}from"./alert-dialog-DXnJdv-M.js";import{t as on}from"./undo-2-eBLOetyj.js";import{c as sn,n as cn,o as ln}from"./api-DuV0sTuY.js";import{t as Z}from"./input-CMgoax5D.js";import{C as un,D as dn,E as fn,S as pn,T as mn,_ as hn,b as gn,c as _n,d as vn,f as yn,g as bn,h as xn,l as Sn,m as Cn,n as wn,o as Tn,p as En,r as Dn,t as On,u as kn,v as An,w as jn,x as Mn,y as Nn}from"./useLeaveGuard-C4lXrsPo.js";import{A as Pn,C as Fn,D as In,E as Ln,G as Rn,S as zn,T as Bn,a as Vn,b as Hn,d as Un,f as Wn,i as Gn,j as Kn,k as qn,m as Jn,p as Yn,u as Xn,w as Zn,x as Qn,y as $n}from"./WorkspaceProvider-DkMvUEsL.js";import{t as er}from"./localPersistence-CGAJ2Ky5.js";import{n as tr}from"./WorkspaceContext-CitlpD55.js";import{t as nr}from"./label-CfaCFYRS.js";import{A as rr,B as ir,F as ar,H as or,I as sr,L as cr,M as lr,N as ur,R as dr,U as fr,Y as pr,k as mr,ln as hr,z as gr}from"./index-xLqjbUVL.js";/* empty css */var Q=e(t(),1),$=n(),_r=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``);function vr(e,t){return e.source===t.source&&e.target===t.target&&_r(e.sourceHandle)===_r(t.sourceHandle)&&_r(e.targetHandle)===_r(t.targetHandle)}function yr(e,t){let n=t?.nodes||{},r=new Set(e.flatMap(e=>(e.foreign_keys||[]).map(e=>`${e.ref_table}.${e.ref_column}`))),i=e.map((e,t)=>{let i=n[e.table_name]||{};return{id:e.table_name,type:`entity`,position:{x:i.x??t%4*280+50,y:i.y??Math.floor(t/4)*220+50},data:{id:e.table_name,name:e.table_name,x:i.x??0,y:i.y??0,color:i.color??`#6b7280`,columns:(e.columns||[]).map(t=>({...p(t,`${e.table_name}.${t.name}`),_is_fk:(e.foreign_keys||[]).some(e=>e.column===t.name),_is_ref:r.has(`${e.table_name}.${t.name}`)})),collapsed:i.collapsed??!1,hidden_columns:i.hidden_columns??[],note:i.note??``,isReadOnly:!0}}}),a=[],o=new Map(i.map(e=>[e.id,new Set(e.data.columns.map(e=>e.name))]));for(let n of e)for(let e of n.foreign_keys||[]){if(!o.get(n.table_name)?.has(e.column)||!o.get(e.ref_table)?.has(e.ref_column))continue;let r=`${n.table_name}.${e.column}->${e.ref_table}.${e.ref_column}`,i=t?.edgeHandles?.[r]||{};a.push({id:r,source:n.table_name,target:e.ref_table,sourceHandle:i.sourceHandle||`col-${n.table_name}.${e.column}-source`,targetHandle:i.targetHandle||`col-${e.ref_table}.${e.ref_column}-target`,type:`smoothstep`,data:{constraint_name:e.constraint_name,on_delete:e.on_delete,on_update:e.on_update}})}if(!Object.keys(n).length){let e=E(i,a);return{nodes:e,edges:se(e,a)}}return{nodes:i,edges:a}}function br(e,t,n,r){let i=Object.fromEntries(e.map(e=>[e.id,{x:e.position.x,y:e.position.y,color:e.data.color,collapsed:e.data.collapsed??!1,hidden_columns:e.data.hidden_columns??[],note:e.data.note??``}])),a=r&&Object.fromEntries(r.map(e=>[e.id,{sourceHandle:e.sourceHandle,targetHandle:e.targetHandle}]));return{...n,nodes:i,viewport:t,...a?{edgeHandles:a}:{},_type:`production_db_positions`}}var xr=`erd-production-db-tabs:`,Sr=new Map,Cr=new Map;function wr(e){let t=Sr.get(e);return t||(t=new Map,Sr.set(e,t),Sr.size>5&&Sr.delete(Sr.keys().next().value)),t}var Tr=e=>Cr.get(e),Er=(e,t)=>{Cr.set(e,t),Cr.size>5&&Cr.delete(Cr.keys().next().value)},Dr=e=>Cr.delete(e),Or=(e=``)=>({id:crypto.randomUUID(),enabled:!0,column:e,operator:`CONTAINS`,value:``,value2:``}),kr=(0,Q.createContext)(null),Ar=()=>(0,Q.useContext)(kr),jr=`erdbpro:notes-companion-edit-entity`,Mr=`!w-2 !h-2 !border-none cursor-crosshair opacity-0 transition-opacity duration-150 group-hover:!opacity-100 group-focus-within:!opacity-100`,Nr=(0,Q.memo)(({col:e,borderColor:t,typeColor:n,hideHandles:r,onDoubleClick:i})=>{let a=e._is_fk,s=e.diffState,c=(0,Q.useMemo)(()=>({top:`50%`,left:`-4px`,transform:`translate(-50%, -50%)`,backgroundColor:t,zIndex:50}),[t]),l=(0,Q.useMemo)(()=>({top:`50%`,right:`-4px`,transform:`translate(50%, -50%)`,backgroundColor:t,zIndex:50}),[t]),u=(0,Q.useMemo)(()=>s===`new`?`bg-emerald-500/10 hover:bg-emerald-500/15 border-b border-emerald-500/20`:s===`deleted`?`bg-red-500/10 hover:bg-red-500/15 line-through opacity-50 border-b border-red-500/20`:`border-border/50 hover:bg-muted`,[s]);return(0,$.jsxs)(`div`,{className:o(`erd-column-row group relative px-3 py-2 flex items-center justify-between transition-colors border-b last:border-b-0`,u),title:e.comment||void 0,onDoubleClick:i,children:[r?(0,$.jsxs)($.Fragment,{children:[e._is_ref&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`target`,position:C.Left,id:`col-${e.id}-target`,className:Mr,style:c}),(0,$.jsx)(M,{type:`target`,position:C.Right,id:`col-${e.id}-target-r`,className:Mr,style:l})]}),e._is_fk&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`source`,position:C.Left,id:`col-${e.id}-source-l`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Right,id:`col-${e.id}-source`,className:Mr,style:l})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(M,{type:`target`,position:C.Left,id:`col-${e.id}-target`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Left,id:`col-${e.id}-source-l`,className:Mr,style:c}),(0,$.jsx)(M,{type:`source`,position:C.Right,id:`col-${e.id}-source`,className:Mr,style:l}),(0,$.jsx)(M,{type:`target`,position:C.Right,id:`col-${e.id}-target-r`,className:Mr,style:l})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{className:o(`text-sm font-medium`,e.is_pk?`text-foreground`:`text-foreground/80`,s===`new`&&`text-emerald-400 font-semibold`,s===`deleted`&&`text-red-400/80 line-through`),children:s===`new`?`+ ${e.name}`:s===`deleted`?`- ${e.name}`:e.name})}),(0,$.jsxs)(`div`,{className:`flex flex-col items-end gap-0.5 max-w-35`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[11px] font-mono font-semibold`,style:{color:s===`new`?`#10b981`:s===`deleted`?`#ef4444`:n},children:d(e.type,e.max_length,e.numeric_precision,e.numeric_scale).toLowerCase()}),e.comment&&(0,$.jsx)(Ft,{className:`w-3 h-3 text-muted-foreground`}),(e.is_pk||a)&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.is_pk&&(0,$.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/40 uppercase tracking-tighter`,children:`pk`}),a&&(0,$.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/40 uppercase tracking-tighter`,children:`fk`})]})]}),e.type.toUpperCase()===`ENUM`&&e.enum_values&&(0,$.jsxs)(`span`,{className:`font-mono italic text-right leading-tight wrap-break-word max-w-full text-[8.5px] text-muted-foreground`,children:[`(`,e.enum_values,`)`]})]})]})}),Pr=(0,Q.memo)(({data:e,id:t,selected:n})=>{let r=Me(),{isReadOnly:i,duplicateEntity:a,sourceType:s,setSelectedNodeId:c}=Rn(),l=Ar(),u=!!e._notesCompanion,d=!u&&(s===`production_db`||!!e.isReadOnly),f=i||!!e.isDiffMode||d,[p,m]=(0,Q.useState)(!1),h=ce(),g=(0,Q.useMemo)(()=>e.columns.map(e=>`${e.id}-${e.name}-${e.sort_order}`).join(`,`),[e.columns]);(0,Q.useEffect)(()=>{h(t)},[t,g,h]);let _=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&(u?window.dispatchEvent(new CustomEvent(jr,{detail:{id:t}})):(c(t),l?.(t)))},[f,u,t,c,l]),v=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&m(!0)},[f]),y=(0,Q.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),!f&&a(t)},[f,a,t]),b=e=>{e.preventDefault(),e.stopPropagation(),window.dispatchEvent(new CustomEvent(Re,{detail:{type:`table`,id:t}}))},x=()=>{window.dispatchEvent(new CustomEvent(`deleteEntity`,{detail:t})),m(!1)},S=e.diffState,{borderColor:C,headerBg:w,typeColor:T}=(0,Q.useMemo)(()=>S===`new`?{borderColor:`#10b981`,headerBg:`rgba(16, 185, 129, 0.15)`,typeColor:`#10b981`}:S===`deleted`?{borderColor:`#ef4444`,headerBg:`rgba(239, 68, 68, 0.15)`,typeColor:`#ef4444`}:S===`modified`?{borderColor:`#f59e0b`,headerBg:`rgba(245, 158, 11, 0.15)`,typeColor:`#f59e0b`}:{borderColor:e.color,headerBg:`${e.color}20`,typeColor:e.color},[e.color,S]),E=(0,Q.useMemo)(()=>o(`bg-card text-foreground rounded-lg border-2 min-w-[220px] erd-node-container`,n&&`ring-2 ring-primary/50`,S===`new`&&`shadow-[0_0_20px_rgba(16,185,129,0.35)] border-emerald-500/50`,S===`deleted`&&`opacity-40 shadow-[0_0_15px_rgba(239,68,68,0.25)] border-red-500/50`,S===`modified`&&`shadow-[0_0_20px_rgba(245,158,11,0.3)] border-amber-500/50`),[n,S]),D=(0,Q.useMemo)(()=>[...e.columns].sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),[e.columns]),O=(!i||!!r)&&!u&&!d&&!e.isDiffMode,k=(0,$.jsxs)(`div`,{className:`relative`,children:[!e.isDiffMode&&(0,$.jsx)(`div`,{className:`absolute -right-1 -top-1 z-20`,children:(0,$.jsx)(ze,{anchor:{type:`table`,id:t}})}),(0,$.jsxs)(`div`,{className:E,style:{borderColor:C,overflow:`visible`},children:[(0,$.jsxs)(`div`,{className:`px-3 py-2 flex items-center justify-between border-b-2 cursor-pointer group/header`,style:{backgroundColor:w,borderColor:C},onDoubleClick:f?void 0:_,title:f?void 0:`Double-click to edit table`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Tt,{className:`w-4 h-4 transition-transform group-hover/header:rotate-12`,style:{color:C}}),(0,$.jsx)(`span`,{className:o(`font-bold text-sm tracking-wide uppercase`,S===`deleted`&&`line-through text-red-400`),children:e.name}),S===`new`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 rounded uppercase tracking-wider`,children:`NEW`}),S===`deleted`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-red-500/20 text-red-400 border border-red-500/30 rounded uppercase tracking-wider`,children:`DEL`}),S===`modified`&&(0,$.jsx)(`span`,{className:`px-1 py-0.5 text-[8px] font-bold bg-amber-500/20 text-amber-400 border border-amber-500/30 rounded uppercase tracking-wider`,children:`MOD`})]}),!u&&(!f||i&&!!r&&!e.isDiffMode&&!d)&&(0,$.jsxs)(Ce,{children:[(0,$.jsx)(ye,{className:`nodrag nopan p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors focus:outline-none`,onPointerDown:e=>e.stopPropagation(),onPointerUp:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),children:(0,$.jsx)(Et,{className:`w-4 h-4`})}),(0,$.jsxs)(xe,{align:`end`,className:`w-44 bg-popover border-border text-popover-foreground z-1000`,onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(G,{onClick:_,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(tt,{className:`w-4 h-4 mr-2`}),`Edit`]}),(0,$.jsxs)(G,{onClick:y,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(hr,{className:`w-4 h-4 mr-2`}),`Duplicate`]})]}),r&&(0,$.jsxs)(G,{onClick:b,className:`cursor-pointer hover:bg-muted focus:bg-muted`,children:[(0,$.jsx)(Ft,{className:`w-4 h-4 mr-2`}),`Comment`]}),!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Se,{className:`bg-border`}),(0,$.jsxs)(G,{onClick:v,className:`cursor-pointer text-destructive focus:text-destructive hover:bg-destructive/10 focus:bg-destructive/10`,children:[(0,$.jsx)(qt,{className:`w-4 h-4 mr-2`}),`Delete Table`]})]})]})]})]}),(0,$.jsx)(`div`,{className:o(`flex flex-col`,!f&&`cursor-pointer`),onDoubleClick:f?void 0:_,title:f?void 0:`Double-click to edit table`,children:D.map(e=>(0,$.jsx)(Nr,{col:e,borderColor:C,typeColor:T,hideHandles:d,onDoubleClick:f?void 0:_},e.id))})]})]});return(0,$.jsxs)($.Fragment,{children:[O?(0,$.jsxs)(ke,{children:[(0,$.jsx)(Ae,{className:`contents`,children:k}),(0,$.jsxs)(q,{className:`w-48`,children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Fe,{onClick:_,children:[(0,$.jsx)(tt,{"aria-hidden":`true`}),`Edit`]}),(0,$.jsxs)(Fe,{onClick:y,children:[(0,$.jsx)(hr,{"aria-hidden":`true`}),`Duplicate`]})]}),r&&(0,$.jsxs)(Fe,{onClick:b,children:[(0,$.jsx)(Ft,{"aria-hidden":`true`}),`Comment`]}),!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(De,{}),(0,$.jsxs)(Fe,{variant:`destructive`,onClick:v,children:[(0,$.jsx)(qt,{"aria-hidden":`true`}),`Delete`]})]})]})]}):k,(0,$.jsx)(rn,{open:p,onOpenChange:m,children:(0,$.jsxs)(Yt,{size:`sm`,className:`max-w-100`,children:[(0,$.jsxs)(Xt,{children:[(0,$.jsx)(Qt,{className:`bg-destructive/10`,children:(0,$.jsx)(Jt,{className:`w-5 h-5 text-destructive`})}),(0,$.jsx)(an,{children:`Delete Table`})]}),(0,$.jsx)(tn,{children:(0,$.jsxs)(en,{children:[`Are you sure you want to delete the table `,(0,$.jsx)(`strong`,{children:e.name}),`? This action cannot be undone.`]})}),(0,$.jsxs)(nn,{children:[(0,$.jsx)(Zt,{onClick:e=>{e.stopPropagation(),m(!1)},children:`Cancel`}),(0,$.jsx)($t,{onClick:e=>{e.stopPropagation(),x()},className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Delete`})]})]})})]})});function Fr(e){if(e.kind===`column`){let t=e.id.replace(/^column:/,``);return t.slice(0,t.lastIndexOf(`.`))}return e.kind===`relation`?e.label.split(`.`)[0]:e.label}function Ir(e){return e.kind===`column`?e.label.slice(e.label.lastIndexOf(`.`)+1):e.kind===`table`?`Table definition`:e.label}function Lr(e){if(e.kind===`table`)return`TABLE`;if(e.kind===`relation`)return`FK`;let t=e.proposed??e.current;return t&&`is_pk`in t?t.type:`—`}function Rr({diff:e,approvedIds:t,showChecklist:n,label:r,rejectLabel:i=`Reject All`,canMerge:a=!0,selectable:s=a,checklistTitle:c=`Select changes to merge:`,onApprovedIdsChange:l,onShowChecklistChange:u,onReject:d,onMerge:f}){let p=(0,Q.useMemo)(()=>e.changes.map(e=>e.id),[e.changes]),m=(0,Q.useMemo)(()=>{let t=new Map;for(let n of e.changes){let e=Fr(n);t.set(e,[...t.get(e)||[],n])}return[...t]},[e.changes]),h=(0,Q.useMemo)(()=>[`table`,`column`,`relation`].map(t=>{let n=e.changes.filter(e=>e.kind===t).length;return n?`${n} ${t}${n===1?``:`s`}`:null}).filter(Boolean).join(` · `),[e.changes]),g=t.length===p.length;return(0,$.jsxs)(`div`,{"data-pending-review":!0,className:`pointer-events-none absolute inset-x-0 bottom-4 z-50 flex flex-col items-center justify-center gap-2.5 px-3`,children:[n&&(0,$.jsxs)(`div`,{className:`pointer-events-auto w-[min(560px,100%)] rounded-2xl border bg-popover/95 p-4 shadow-2xl backdrop-blur-md`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider text-muted-foreground`,children:c}),s&&(0,$.jsx)(W,{variant:`link`,size:`xs`,onClick:()=>l(g?[]:p),children:g?`Unselect All`:`Select All`})]}),(0,$.jsx)(`div`,{className:`flex max-h-75 flex-col gap-3 overflow-y-auto pr-1 custom-scrollbar`,children:m.map(([e,n])=>(0,$.jsxs)(`section`,{className:`shrink-0 overflow-hidden rounded-lg border`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b bg-muted/50 px-3 py-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-semibold`,children:e}),(0,$.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[n.length,` change`,n.length===1?``:`s`]})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_minmax(72px,auto)_auto] gap-3 border-b px-3 py-1.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(`span`,{}),(0,$.jsx)(`span`,{children:`Column`}),(0,$.jsx)(`span`,{children:`Type`}),(0,$.jsx)(`span`,{children:`Change`})]}),(0,$.jsx)(`div`,{className:`divide-y divide-border`,children:n.map(e=>{let n=t.includes(e.id);return(0,$.jsxs)(`label`,{className:o(`grid cursor-pointer grid-cols-[auto_minmax(0,1fr)_minmax(72px,auto)_auto] items-center gap-3 px-3 py-2.5 transition-colors`,n?`bg-background text-foreground hover:bg-muted/50`:`bg-muted/20 text-muted-foreground hover:bg-muted/40`),children:[s?(0,$.jsx)(or,{checked:n,onCheckedChange:()=>l(n?t.filter(t=>t!==e.id):[...t,e.id]),className:`border-border bg-transparent data-checked:border-emerald-500 data-checked:bg-emerald-500`}):(0,$.jsx)(`span`,{className:`size-2 rounded-full bg-muted-foreground/50`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:Ir(e)}),(0,$.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:Lr(e)}),(0,$.jsx)(`span`,{className:o(`rounded border px-1.5 py-0.5 text-[10px] font-semibold uppercase`,e.state===`new`&&`border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`,e.state===`deleted`&&`border-destructive/30 bg-destructive/10 text-destructive`,e.state===`modified`&&`border-amber-500/30 bg-amber-500/10 text-amber-600 dark:text-amber-400`),children:e.state})]},e.id)})})]},e))})]}),(0,$.jsxs)(`div`,{className:`pointer-events-auto flex max-w-full items-center gap-2 overflow-x-auto rounded-2xl border bg-popover/95 p-2.5 shadow-2xl backdrop-blur-md no-scrollbar`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-1.5`,children:[r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`size-2 rounded-full bg-emerald-500`}),(0,$.jsx)(`span`,{className:`max-w-52 truncate text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:r}),(0,$.jsx)(dn,{orientation:`vertical`,className:`mx-1 h-4`})]}),(0,$.jsxs)(`div`,{className:`flex gap-2 text-[11px] font-bold`,children:[e.newCount>0&&(0,$.jsxs)(`span`,{className:`text-emerald-500`,children:[e.newCount,` New`]}),e.modifiedCount>0&&(0,$.jsxs)(`span`,{className:`text-amber-500`,children:[e.modifiedCount,` Mod`]}),e.deletedCount>0&&(0,$.jsxs)(`span`,{className:`text-destructive`,children:[e.deletedCount,` Del`]})]}),h&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:h})]}),(0,$.jsx)(dn,{orientation:`vertical`,className:`h-6`}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>u(!n),children:`Review Changes`}),(0,$.jsx)(W,{variant:`destructive`,onClick:d,children:i}),a&&(0,$.jsx)(W,{onClick:f,disabled:t.length===0,children:`Merge Selected`})]})]})]})}var zr=e=>e.trim().toLowerCase(),Br=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),Vr=(e,t)=>e.data.columns.find(e=>String(e.id)===Br(t));function Hr(e,t){let n=t.find(t=>t.id===e.source),r=t.find(t=>t.id===e.target);if(!n||!r)return null;let i=Vr(n,e.sourceHandle),a=Vr(r,e.targetHandle);return!i||!a?null:`${zr(n.data.name)}.${zr(i.name)}>${zr(r.data.name)}.${zr(a.name)}`}function Ur(e,t){return e.type.toLowerCase()!==t.type.toLowerCase()||!!e.is_pk!=!!t.is_pk||!!e.is_nullable!=!!t.is_nullable||!!e.is_unique!=!!t.is_unique||(e.default_value??null)!==(t.default_value??null)||(e.comment||``)!==(t.comment||``)||(e.max_length??null)!==(t.max_length??null)||(e.numeric_precision??null)!==(t.numeric_precision??null)||(e.numeric_scale??null)!==(t.numeric_scale??null)||(e.enum_name||``)!==(t.enum_name||``)||(e.enum_values||``)!==(t.enum_values||``)}function Wr(e){let t=t=>zr(e.data.columns.find(e=>String(e.id)===String(t))?.name||t);return JSON.stringify({comment:e.data.comment||``,constraints:(e.data.constraints||[]).map(e=>({kind:e.kind,name:e.name||``,columns:(e.column_ids||[]).map(t),expression:e.expression||``})).sort((e,t)=>JSON.stringify(e).localeCompare(JSON.stringify(t))),indexes:(e.data.indexes||[]).map(e=>({name:e.name||``,columns:e.column_ids.map(t),unique:!!e.is_unique,algorithm:e.algorithm||``})).sort((e,t)=>JSON.stringify(e).localeCompare(JSON.stringify(t)))})}function Gr(e,t){let n=(e,t)=>String(e.data?.[t]||``).toLowerCase();return(e.label||``)!==(t.label||``)||n(e,`on_delete`)!==n(t,`on_delete`)||n(e,`on_update`)!==n(t,`on_update`)||n(e,`constraint_name`)!==n(t,`constraint_name`)}function Kr(e,t,n,r){let i=[],a=new Map(e.map(e=>[zr(e.data.name),e])),o=new Map(n.map(e=>[zr(e.data.name),e])),s=new Set([...a.keys(),...o.keys()]),c=[];for(let e of s){let t=a.get(e),n=o.get(e),r=`table:${e}`;if(!t&&n){i.push({id:r,kind:`table`,state:`new`,label:n.data.name,proposed:n}),c.push({...n,data:{...n.data,diffState:`new`}});continue}if(t&&!n){i.push({id:r,kind:`table`,state:`deleted`,label:t.data.name,current:t}),c.push({...t,data:{...t.data,columns:t.data.columns.map(e=>({...e,diffState:`deleted`})),diffState:`deleted`}});continue}if(!t||!n)continue;let s=new Map(t.data.columns.map(e=>[zr(e.name),e])),l=new Map(n.data.columns.map(e=>[zr(e.name),e])),u=new Set([...s.keys(),...l.keys()]),d=Wr(t)!==Wr(n);d&&i.push({id:r,kind:`table`,state:`modified`,label:t.data.name,current:t,proposed:n});let f=[];for(let n of u){let r=s.get(n),a=l.get(n),o=`column:${e}.${n}`,c=`${t.data.name}.${r?.name||a?.name||n}`;!r&&a?(d=!0,i.push({id:o,kind:`column`,state:`new`,label:c,proposed:a}),f.push({...a,diffState:`new`})):r&&!a?(d=!0,i.push({id:o,kind:`column`,state:`deleted`,label:c,current:r}),f.push({...r,diffState:`deleted`})):r&&a&&Ur(r,a)?(d=!0,i.push({id:o,kind:`column`,state:`modified`,label:c,current:r,proposed:a}),f.push({...a,diffState:`new`})):r&&f.push(r)}c.push({...t,data:{...t.data,columns:f,diffState:d?`modified`:void 0}})}let l=new Map(t.flatMap(t=>{let n=Hr(t,e);return n?[[n,t]]:[]})),u=new Map(r.flatMap(e=>{let t=Hr(e,n);return t?[[t,e]]:[]})),d=new Set([...l.keys(),...u.keys()]);for(let e of d){let t=l.get(e),n=u.get(e),r=`relation:${e}`;!t&&n?i.push({id:r,kind:`relation`,state:`new`,label:e,proposed:n}):t&&!n?i.push({id:r,kind:`relation`,state:`deleted`,label:e,current:t}):t&&n&&Gr(t,n)&&i.push({id:r,kind:`relation`,state:`modified`,label:e,current:t,proposed:n})}return{nodes:c,edges:r,changes:i,newCount:i.filter(e=>e.state===`new`).length,modifiedCount:i.filter(e=>e.state===`modified`).length,deletedCount:i.filter(e=>e.state===`deleted`).length}}var qr=e=>e.trim().toLowerCase(),Jr=e=>e?.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``),Yr=(e,t,n)=>`col-${t}${e?.match(/-(source|target)(-(l|r))?$/)?.[0]||`-${n}`}`;function Xr(e,t,n){let r=t.find(t=>t.id===e.source),i=t.find(t=>t.id===e.target),a=r?.data.columns.find(t=>t.id===Jr(e.sourceHandle)),o=i?.data.columns.find(t=>t.id===Jr(e.targetHandle)),s=r&&n.find(e=>qr(e.data.name)===qr(r.data.name)),c=i&&n.find(e=>qr(e.data.name)===qr(i.data.name)),l=s&&a&&s.data.columns.find(e=>qr(e.name)===qr(a.name)),u=c&&o&&c.data.columns.find(e=>qr(e.name)===qr(o.name));return!s||!c||!l||!u?null:{...e,source:s.id,target:c.id,sourceHandle:Yr(e.sourceHandle,l.id,`source`),targetHandle:Yr(e.targetHandle,u.id,`target`)}}function Zr(e,t,n,r,i,a){let o=new Set(a),s=new Map(i.changes.map(e=>[e.id,e])),c=new Map(n.map(e=>[qr(e.data.name),e])),l=new Map(e.map(e=>[qr(e.data.name),e])),u=[];for(let[e,t]of l){let n=c.get(e),r=s.get(`table:${e}`);if(!n){r&&o.has(r.id)||u.push(t);continue}let i=!!r&&o.has(r.id),a=t.data.columns.flatMap(t=>{let r=qr(t.name),i=n.data.columns.find(e=>qr(e.name)===r),a=s.get(`column:${e}.${r}`);return i?[a&&o.has(a.id)?i:t]:a&&o.has(a.id)?[]:[t]});for(let r of n.data.columns){let n=qr(r.name);if(t.data.columns.some(e=>qr(e.name)===n))continue;let i=s.get(`column:${e}.${n}`);i&&o.has(i.id)&&a.push(r)}let l=new Set(a.map(e=>String(e.id))),d=(e=[])=>e.every(e=>l.has(String(e)));u.push({...t,data:{...t.data,...i?{comment:n.data.comment,constraints:(n.data.constraints||[]).filter(e=>d(e.column_ids)),indexes:(n.data.indexes||[]).filter(e=>d(e.column_ids))}:{},columns:a}})}for(let[e,t]of c){if(l.has(e))continue;let n=s.get(`table:${e}`);n&&o.has(n.id)&&u.push(t)}let d=t.filter(t=>Xr(t,e,u)),f=new Map(t.flatMap(t=>{let n=Hr(t,e);return n?[[n,t]]:[]}));for(let t of i.changes.filter(e=>e.kind===`relation`&&o.has(e.id))){let r=t.id.replace(/^relation:/,``);if(f.get(r)){let t=d.findIndex(t=>Hr(t,e)===r);t>=0&&d.splice(t,1)}if(t.state!==`deleted`&&t.proposed&&`source`in t.proposed){let e=Xr(t.proposed,n,u);e&&d.push(e)}}return{nodes:ae(u),edges:d}}function Qr(e,t){let[n,r]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),o=(0,Q.useRef)(e),s=(0,Q.useRef)(t);return o.current=e,s.current=t,(0,Q.useEffect)(()=>(r(!1),()=>{a.current?.abort(),a.current=null}),[e]),{sync:(0,Q.useCallback)(async()=>{if(!e||a.current)return;let t=new AbortController,n=ln();a.current=t;let c=()=>a.current===t&&o.current===e&&ln()===n&&!t.signal.aborted;r(!0);try{let n=await cn(`/api/catalogs/${e}/schema`,{method:`POST`,signal:t.signal}),r=await n.json();if(!c())return;if(!n.ok)throw Error(r.error||`Failed to sync schema`);if(!Array.isArray(r.schema))throw Error(`Invalid database schema response`);s.current(r)}catch(e){c()&&i.error(e instanceof Error?e.message:`Failed to sync schema`)}finally{a.current===t&&(a.current=null,r(!1))}},[e]),isSyncing:n}}function $r(e,t=[],n=null){let r=t.length>0,i=Math.max(0,...e.map(e=>e.zIndex??0)),a=i+1e3,o=i+1001;return e.map(e=>{let i=r&&t.some(t=>e.source===t||e.target===t),s=i||e.selected||e.id===n?`var(--edge-selected)`:`var(--edge-color)`,c=[e.className];return i?c.push(`edge-animated-active`):r&&c.push(`edge-dimmed`),{...e,...e.selected?{zIndex:a}:{},...e.id===n?{zIndex:o}:{},type:`smoothstep`,style:{...e.style,stroke:s,strokeWidth:2},markerEnd:{type:oe.Arrow,color:s,width:10,height:10},className:c.filter(Boolean).join(` `)}})}function ei(e){let t=[];for(let n of e){let e=t.at(-1),r=t.at(-2);(e?.x!==n.x||e.y!==n.y)&&(r&&e&&(r.x===e.x&&e.x===n.x||r.y===e.y&&e.y===n.y)&&t.pop(),t.push(n))}return t}function ti(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function ni(e,t,n=[]){let r=ei(e),i=r[t.segment],a=r[t.segment+1];if(!i||!a)return null;let o=Math.abs(a.x-i.x)+Math.abs(a.y-i.y),s=(i.y===a.y?t.width:t.height)/2+12;if(o<s*2)return null;let c=Math.min(1-s/o,Math.max(s/o,t.ratio)),l={x:i.x+(a.x-i.x)*c,y:i.y+(a.y-i.y)*c};return n.some(e=>ti(ri(l,t),e))?null:l}function ri(e,t){return{x:e.x-t.width/2-4,y:e.y-t.height/2-4,width:t.width+8,height:t.height+8}}function ii(e){let t=ei(e.points),n=Math.max(32,e.label.length*7+8);return t.slice(1).flatMap((e,r)=>{let i=t[r],a=Math.abs(e.x-i.x)+Math.abs(e.y-i.y),o=i.y===e.y?n:22,s=o/2+12;if(a<s*2)return[];let c=new Set([a/2,s,a-s]);for(let e=s;e<=a-s;e+=o+12)c.add(e);return[...c].sort((e,t)=>Math.abs(e-a/2)-Math.abs(t-a/2)).map(e=>({segment:r,ratio:e/a,width:n,height:22,shared:!1}))}).sort((e,n)=>Number(t[e.segment].x===t[e.segment+1].x)-Number(t[n.segment].x===t[n.segment+1].x))}function ai(e,t){let n=new Map,r=[],i=[];for(let a of[...e].sort((e,t)=>e.id.localeCompare(t.id))){let o=ii(a).filter(e=>{let n=ri(ni(a.points,e),e);return![...t,...r].some(e=>ti(n,e))}),s=o.find(t=>{let n=ri(ni(a.points,t),t);return!e.some(e=>e.id!==a.id&&e.points.slice(1).some((t,r)=>Jn(e.points[r],t,[n])))});s?(n.set(a.id,s),r.push(ri(ni(a.points,s),s))):o[0]&&i.push(a)}for(let e of i){let i=ii(e).find(n=>{let i=ri(ni(e.points,n),n);return![...t,...r].some(e=>ti(i,e))});i&&n.set(e.id,{...i,shared:!0})}return n}function oi(e,t,n){let r=t.get(e);return r?!r.shared||e===n:!1}var si=(0,Q.createContext)({anchors:new Map,activeId:null});function ci({nodes:e,edges:t,tables:n,activeId:r,children:i}){let{getInternalNode:a}=U(),o=(0,Q.useMemo)(()=>{let r=new Map(e.map(e=>[e.id,e])),i=e=>{let t=a(e),n=r.get(e);return t&&n?{...t,internals:{...t.internals,positionAbsolute:n.position}}:void 0};return ai(t.flatMap(e=>{if(e.label===void 0||e.label===null||e.label===``)return[];let t=i(e.source),r=i(e.target);if(!t||!r)return[];let a=f({id:e.id,sourceNode:t,targetNode:r,sourceHandle:e.sourceHandle??null,targetHandle:e.targetHandle??null,connectionMode:u.Strict});return a?[{id:e.id,label:String(e.label),points:Wn({x:a.sourceX,y:a.sourceY},{x:a.targetX,y:a.targetY},a.sourcePosition===C.Right,a.targetPosition===C.Right,n)}]:[]}),n)},[e,t,n,a]),s=(0,Q.useMemo)(()=>({anchors:o,activeId:r}),[o,r]);return(0,$.jsx)(si.Provider,{value:s,children:i})}var li=(0,Q.createContext)([]);function ui(e){let t=(0,Q.useContext)(li),n=(0,Q.useContext)(si),{getInternalNode:r}=U(),i=le(t=>!!(t.nodeLookup.get(e.source)?.dragging||t.nodeLookup.get(e.target)?.dragging)),{points:a,obstacles:o}=(0,Q.useMemo)(()=>{let n=[r(e.source),r(e.target)].flatMap(e=>e?[{id:e.id,...e.internals.positionAbsolute,...S(e)}]:[]),a=Xn(t,n);return{points:(i?Yn:Wn)({x:e.sourceX,y:e.sourceY},{x:e.targetX,y:e.targetY},e.sourcePosition===C.Right,e.targetPosition===C.Right,a),obstacles:a}},[e.source,e.target,e.sourceX,e.sourceY,e.targetX,e.targetY,e.sourcePosition,e.targetPosition,t,r,i]),s=Un(a),c=n.anchors.get(e.id),l=c?ni(a,c,o):null,u=l&&oi(e.id,n.anchors,n.activeId),d=n.activeId===e.id||e.selected;return(0,$.jsxs)(`g`,{className:d?`erd-edge-active`:void 0,children:[e.label!=null&&(0,$.jsx)(`title`,{children:String(e.label)}),(0,$.jsx)(L,{id:e.id,path:s,markerStart:e.markerStart,markerEnd:e.markerEnd,style:e.style,interactionWidth:e.interactionWidth,label:u?e.label:void 0,labelX:l?.x,labelY:l?.y,labelStyle:d?{...e.labelStyle,fill:`var(--edge-selected)`,fontWeight:600}:e.labelStyle,labelShowBg:e.labelShowBg,labelBgStyle:e.labelBgStyle})]})}function di(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e===t[n])}function fi({isReadOnly:e,isProductionDb:t,addEntity:n,onImportSQL:r,onAutoLayout:i,explorerOpen:a,explorerShortcut:s,onToggleExplorer:c,onOpenDBML:l,onOpenRepository:u,handleSync:d,isSyncing:f,handleExportImage:p,undo:m,redo:h,canUndo:g,canRedo:_}){let v=pr(),y=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent),b=`Undo (${y?`⌘Z`:`Ctrl+Z`})`,x=`Redo (${y?`⇧⌘Z`:`Ctrl+Y`})`,S=(e,t)=>v?t:(0,$.jsxs)(de,{children:[(0,$.jsx)(fe,{render:t.props.disabled?(0,$.jsx)(`span`,{className:`inline-flex`,children:t}):t}),(0,$.jsx)(pe,{side:`right`,children:e})]}),C=`h-9 px-3 border-border hover:bg-muted bg-muted/50 text-xs font-semibold cursor-pointer`,w=o(`size-3.5`,v&&`sm:mr-1.5`),T=e=>v&&(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:e});return(0,$.jsx)(`div`,{className:o(`absolute z-10 pointer-events-none flex`,v?`top-6 inset-x-0 justify-center px-3`:`top-4 left-4 bottom-28 items-start`),children:(0,$.jsxs)(`div`,{role:`group`,"aria-label":`ERD tools`,className:o(`flex gap-1.5 p-1.5 bg-background/95 backdrop-blur-md border border-border/50 rounded-2xl shadow-2xl pointer-events-auto no-scrollbar`,v?`items-center max-w-full overflow-x-auto`:`flex-col items-center max-h-full overflow-y-auto`),children:[S(`Explorer (${s.label})`,(0,$.jsxs)(W,{onClick:c,variant:a?`secondary`:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Explorer: tables and relationships`,"aria-pressed":a,"aria-keyshortcuts":t?void 0:s.ariaKeyShortcuts,className:v?C:void 0,children:[(0,$.jsx)(pt,{className:w}),T(`Explorer`)]})),!e&&(0,$.jsx)(`div`,{className:o(`bg-border shrink-0`,v?`w-px h-6 mx-0.5`:`h-px w-6 my-0.5`)}),!e&&S(`Add Table`,(0,$.jsxs)(W,{onClick:n,size:v?`sm`:`icon-lg`,"aria-label":`Add Table`,className:v?`h-9 px-3 sm:px-4 font-bold shadow-lg shadow-primary/20 cursor-pointer`:void 0,children:[(0,$.jsx)(he,{className:o(`size-4`,v&&`sm:mr-2`)}),T(`Add Table`)]})),!e&&S(`Import SQL`,(0,$.jsxs)(W,{onClick:r,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Import SQL`,className:v?C:void 0,children:[(0,$.jsx)(qe,{className:w}),T(`Import SQL`)]})),!t&&!e&&S(`DBML`,(0,$.jsxs)(W,{onClick:l,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`DBML`,className:v?C:void 0,children:[(0,$.jsx)(Tt,{className:w}),T(`DBML`)]})),!e&&!t&&sn()&&S(`Repository`,(0,$.jsxs)(W,{onClick:u,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Repository`,className:v?C:void 0,children:[(0,$.jsx)(et,{className:w}),T(`Repository`)]})),i&&(!e||t)&&S(`Auto Layout`,(0,$.jsxs)(W,{onClick:i,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Auto Layout`,className:v?C:void 0,children:[(0,$.jsx)(Nt,{className:w}),T(`Auto Layout`)]})),t&&S(f?`Syncing...`:`Sync`,(0,$.jsxs)(W,{onClick:d,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":f?`Syncing...`:`Sync`,disabled:f,className:v?`h-9 px-3 border-amber-500/50 hover:bg-amber-500/10 bg-amber-500/5 text-amber-600 dark:text-amber-400 text-xs font-semibold cursor-pointer`:void 0,children:[(0,$.jsx)(Y,{className:o(w,f&&`animate-spin`)}),T(f?`Syncing...`:`Sync`)]})),t&&S(`Export SVG`,(0,$.jsxs)(W,{onClick:p,variant:`outline`,size:v?`sm`:`icon-lg`,"aria-label":`Export SVG`,title:v?`Export SVG`:void 0,className:v?C:void 0,children:[(0,$.jsx)(Oe,{className:w}),T(`Export SVG`)]})),!e&&(0,$.jsxs)(`div`,{className:o(`flex gap-0.5`,v?`items-center ml-auto`:`flex-col items-center`),children:[S(b,(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:m,disabled:!g,"aria-label":b,title:v?b:void 0,className:v?`h-8 w-8 text-muted-foreground hover:text-foreground disabled:opacity-30`:void 0,children:(0,$.jsx)(on,{className:`size-4`})})),S(x,(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:h,disabled:!_,"aria-label":x,title:v?x:void 0,className:v?`h-8 w-8 text-muted-foreground hover:text-foreground disabled:opacity-30`:void 0,children:(0,$.jsx)(Pt,{className:`size-4`})}))]})]})})}var pi=e=>e?e.replace(/^col-/,``).replace(/-(source|target)(-(l|r))?$/,``):null;function mi(e,t){let n=pi(t),r=n?e.data.columns.find(e=>e.id===n):void 0;return{nodeId:e.id,table:e.data.name,column:r?.name??n??``,isPk:!!r?.is_pk}}function hi(e,t){let n=new Map(e.map(e=>[e.id,e])),r=a[1].shortLabel;return t.flatMap(e=>{let t=n.get(e.source),i=n.get(e.target);if(!t||!i)return[];let o=mi(t,e.sourceHandle),s=mi(i,e.targetHandle),[c,l]=o.isPk&&!s.isPk?[s,o]:[o,s],u=a.find(t=>t.shortLabel===e.label)?.shortLabel??r,d=String(e.data?.constraint_name??``).trim();return[{id:e.id,fromNodeId:c.nodeId,fromTable:c.table,fromColumn:c.column,toNodeId:l.nodeId,toTable:l.table,toColumn:l.column,type:u,...d?{constraintName:d}:{}}]})}function gi(e,t){let n=t.trim().toLowerCase();return e.filter(e=>!n||`${e.fromTable}.${e.fromColumn} ${e.toTable}.${e.toColumn}`.toLowerCase().includes(n)).sort((e,t)=>e.fromTable.localeCompare(t.fromTable)||e.fromColumn.localeCompare(t.fromColumn)||e.toTable.localeCompare(t.toTable))}function _i(e){(0,Q.useEffect)(()=>{e.current?.querySelector(`[aria-current="true"]`)?.scrollIntoView({block:`nearest`})},[e])}var vi=e=>`${e.fromTable}.${e.fromColumn} → ${e.toTable}.${e.toColumn}`;function yi({rows:e,search:t,onSearchChange:n,activeId:r,onSelect:i,onEdit:a}){let o=(0,Q.useMemo)(()=>gi(e,t),[e,t]),s=(0,Q.useRef)(null);return _i(s),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-3 border-b p-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Relationships`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a?`Find a relationship or edit its properties.`:`Find a relationship on the canvas.`})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Gt,{className:`absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(Z,{value:t,onChange:e=>n(e.target.value),placeholder:`Search tables or columns...`,className:`pl-9`,autoFocus:!0})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Showing `,o.length,` of `,e.length,` relationships`]})]}),(0,$.jsxs)(`div`,{ref:s,className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-2`,children:[o.map(e=>{let t=vi(e);return(0,$.jsxs)(`div`,{className:`group flex items-center gap-1 rounded-md border border-transparent px-1 hover:border-border hover:bg-muted/50 has-[[aria-current=true]]:bg-muted has-[[aria-current=true]]:shadow-[inset_2px_0_0_var(--primary)]`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),"aria-current":e.id===r?`true`:void 0,className:`flex min-w-0 flex-1 items-start gap-2 px-2 py-2.5 text-left`,title:`Show ${t}`,children:[(0,$.jsx)(Ve,{className:`mt-0.5 size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-mono text-xs font-medium`,children:t}),e.constraintName&&(0,$.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.constraintName})]}),(0,$.jsx)(fr,{variant:`outline`,className:`shrink-0 font-mono text-[10px]`,children:e.type})]}),a&&(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:()=>a(e.id),title:`Edit ${t}`,"aria-label":`Edit relationship ${t}`,children:(0,$.jsx)(tt,{className:`size-3.5`})})]},e.id)}),o.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-10 text-center text-sm text-muted-foreground`,children:e.length===0?`No relationships yet.`:`No matching relationships found.`})]})]})}function bi(e,t){let n=t.trim().toLowerCase();return e.filter(e=>!n||e.data.name.toLowerCase().includes(n)).sort((e,t)=>e.data.name.localeCompare(t.data.name))}function xi({nodes:e,search:t,onSearchChange:n,activeId:r,onSelect:i,onEdit:a}){let o=(0,Q.useMemo)(()=>bi(e,t),[e,t]),s=(0,Q.useRef)(null);return _i(s),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-3 border-b p-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Tables`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a?`Find a table or open its properties.`:`Find a table on the canvas.`})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Gt,{className:`absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(Z,{value:t,onChange:e=>n(e.target.value),placeholder:`Search tables...`,className:`pl-9`,autoFocus:!0})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Showing `,o.length,` of `,e.length,` tables`]})]}),(0,$.jsxs)(`div`,{ref:s,className:`min-h-0 flex-1 space-y-1 overflow-y-auto p-2`,children:[o.map(e=>(0,$.jsxs)(`div`,{className:`group flex items-center gap-1 rounded-md border border-transparent px-1 hover:border-border hover:bg-muted/50 has-[[aria-current=true]]:bg-muted has-[[aria-current=true]]:shadow-[inset_2px_0_0_var(--primary)]`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),"aria-current":e.id===r?`true`:void 0,className:`flex min-w-0 flex-1 items-center gap-2 px-2 py-2.5 text-left`,title:`Jump to ${e.data.name}`,children:[(0,$.jsx)(Mt,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e.data.name}),(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.data.columns.length})]}),a&&(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:()=>a(e.id),title:`Edit ${e.data.name} properties`,"aria-label":`Edit ${e.data.name} properties`,children:(0,$.jsx)(tt,{className:`size-3.5`})})]},e.id)),o.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-10 text-center text-sm text-muted-foreground`,children:`No matching tables found.`})]})]})}var Si={tab:`tables`,tableSearch:``,relationshipSearch:``,activeTableId:null,activeRelationshipId:null,editingEdgeId:null};function Ci({nodes:e,edges:t,state:n,onChange:r,editing:i,onHighlight:a,onClose:s,shortcutLabel:c}){let l=(0,Q.useMemo)(()=>hi(e,t),[e,t]),u=i&&n.editingEdgeId?t.find(e=>e.id===n.editingEdgeId)??null:null,d=u?l.find(e=>e.id===u.id):void 0;return(0,Q.useEffect)(()=>{let i={};n.editingEdgeId&&!t.some(e=>e.id===n.editingEdgeId)&&(i.editingEdgeId=null),n.activeRelationshipId&&!t.some(e=>e.id===n.activeRelationshipId)&&(i.activeRelationshipId=null),n.activeTableId&&!e.some(e=>e.id===n.activeTableId)&&(i.activeTableId=null),Object.keys(i).length&&r(i)},[n.editingEdgeId,n.activeRelationshipId,n.activeTableId,e,t,r]),(0,$.jsxs)(`aside`,{"aria-label":`Explorer`,className:o(`nowheel absolute left-[4.5rem] top-3 bottom-3 z-20 flex w-[300px] max-w-[calc(100%-5.5rem)] flex-col overflow-hidden rounded-xl border bg-popover text-popover-foreground shadow-2xl`,`max-md:left-2 max-md:right-2 max-md:top-20 max-md:w-auto max-md:max-w-none`),children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:`Explorer`}),(0,$.jsx)(mn,{children:c})]}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-sm`,onClick:s,"aria-label":`Close Explorer`,title:`Close Explorer`,children:(0,$.jsx)(It,{className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-b px-3 pt-2 pb-2`,children:(0,$.jsx)(rr,{value:n.tab,onValueChange:e=>r({tab:e}),className:`w-full`,children:(0,$.jsxs)(lr,{className:`w-full`,children:[(0,$.jsxs)(ur,{value:`tables`,children:[`Tables (`,e.length,`)`]}),(0,$.jsxs)(ur,{value:`relationships`,children:[`Relationships (`,l.length,`)`]})]})})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:n.tab===`tables`?(0,$.jsx)(xi,{nodes:e,search:n.tableSearch,onSearchChange:e=>r({tableSearch:e}),activeId:n.activeTableId,onSelect:e=>{r({activeTableId:e}),a({type:`table`,id:e})},onEdit:i?e=>{r({activeTableId:e}),i.onEditTable(e)}:void 0}):i&&u?(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`shrink-0 border-b px-4 py-3`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r({editingEdgeId:null}),className:`flex shrink-0 items-center gap-1 font-medium text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(rt,{className:`size-3.5`}),` Relationships`]}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`span`,{className:`truncate font-mono font-medium text-foreground`,title:d?vi(d):void 0,children:d?vi(d):`Relationship`})]})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-2`,children:(0,$.jsx)(_n,{selectedEdge:u,nodes:e,onUpdateEdge:i.onUpdateEdge,onFlipEdge:i.onFlipEdge,onDeleteEdge:i.onDeleteEdge})})]}):(0,$.jsx)(yi,{rows:l,search:n.relationshipSearch,onSearchChange:e=>r({relationshipSearch:e}),activeId:n.activeRelationshipId,onSelect:e=>{r({activeRelationshipId:e}),a({type:`relationship`,id:e})},onEdit:i?e=>{r({activeRelationshipId:e,editingEdgeId:e}),a({type:`relationship`,id:e})}:void 0})}),(0,$.jsx)(`p`,{className:`shrink-0 border-t px-3 py-2 text-[11px] text-muted-foreground`,children:i?`Click a row to highlight it on the canvas · ✎ to edit`:`Click a row to highlight it on the canvas`})]})}var wi=[...r].sort((e,t)=>e.localeCompare(t));function Ti({value:e,onValueChange:t,className:n}){return(0,$.jsx)(Xe,{value:e,onChange:t,items:wi,placeholder:`Type`,searchPlaceholder:`Search type...`,emptyMessage:`No types found`,className:n,getItemValue:e=>e,getItemLabel:e=>e,filterItem:(e,t)=>e.toLowerCase().includes(t.toLowerCase())})}var Ei=[{id:`sql`,label:`SQL`,formats:[{id:`mysql`,label:`MySQL`},{id:`postgresql`,label:`PostgreSQL`}]},{id:`laravel`,label:`Laravel`,formats:[{id:`laravel_migration`,label:`Migration`},{id:`laravel_model`,label:`Model`}]},{id:`goravel`,label:`Goravel`,formats:[{id:`goravel`,label:`Model`},{id:`goravel_migration`,label:`Migration`}]},{id:`typescript`,label:`TypeScript`,formats:[{id:`typescript`,label:`Interface`},{id:`zod`,label:`Zod`}]},{id:`prisma`,label:`Prisma`,formats:[{id:`prisma`,label:`Schema`}]}],Di={mysql:Fn,postgresql:Zn,laravel_migration:Qn,laravel_model:zn,goravel:Hn,goravel_migration:$n,typescript:Ln,zod:In,prisma:Bn},Oi={mysql:`sql`,postgresql:`sql`,laravel_migration:`php`,laravel_model:`php`,goravel:`go`,goravel_migration:`go`,typescript:`typescript`,zod:`typescript`,prisma:`prisma`},ki={mysql:`sql`,postgresql:`sql`,laravel_migration:`php`,laravel_model:`php`,goravel:`go`,goravel_migration:`go`,typescript:`ts`,zod:`ts`,prisma:`prisma`};function Ai({entity:e,mode:t,onUpdateEntity:n,dbmlReadOnly:r=!1}){let{resolvedTheme:i}=tr(),[a,s]=Q.useState(Ei[0].id),[c,l]=Q.useState(Ei[0].formats[0].id),[u,d]=Q.useState(!1),f=Q.useMemo(()=>({id:e.id,type:`entity`,position:{x:e.x,y:e.y},data:e}),[e]),p=Q.useMemo(()=>R([f],[]),[f]),[h,g]=Q.useState(p);Q.useEffect(()=>g(p),[e.id,p]);let _=Ei.find(e=>e.id===a)??Ei[0],v=Di[c](e),y=Oi[c]||`sql`,b=m(),x=Q.useMemo(()=>{if(!b)return{entity:null,error:`Loading the DBML parser…`};if(!h.trim())return{entity:null,error:`DBML cannot be empty.`};try{let t=T(h);if(t.nodes.length!==1)return{entity:null,error:`DBML must contain exactly one Table block.`};let n=t.nodes[0].data;return n.name===e.name?{entity:n,error:``}:{entity:null,error:`The table name must be exactly "${e.name}".`}}catch(e){return{entity:null,error:e instanceof Error?e.message:`Invalid DBML.`}}},[h,e,b]),S=Q.useMemo(()=>{if(t===`dbml`)return[En()];switch(y){case`sql`:return[En()];case`php`:return[vn()];case`go`:return[kn(),...Sn(i)];case`typescript`:case`prisma`:return[yn({typescript:!0})];default:return[]}},[y,t,i]),C=async()=>{await navigator.clipboard.writeText(t===`dbml`?p:v),d(!0),window.setTimeout(()=>d(!1),2e3)},w=()=>{let t=new Blob([v],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.name.toLowerCase()}_${c}.${ki[c]||`txt`}`,r.click(),URL.revokeObjectURL(n)},E=()=>{let t=x.entity;if(!t)return;let r=new Map(e.columns.map(e=>[e.name.toLowerCase(),e])),i=(e=[])=>e.map(e=>{let n=t.columns.find(t=>t.id===e);return n?r.get(n.name.toLowerCase())?.id??e:e}),a={...e,comment:t.comment,columns:t.columns.map((e,t)=>({...e,id:r.get(e.name.toLowerCase())?.id??crypto.randomUUID(),_is_fk:r.get(e.name.toLowerCase())?._is_fk,sort_order:t})),constraints:(t.constraints||[]).map(t=>({...t,entity_id:e.id,column_ids:i(t.column_ids)})),indexes:(t.indexes||[]).map(t=>({...t,entity_id:e.id,column_ids:i(t.column_ids)}))};n(a),g(R([{id:a.id,type:`entity`,position:{x:a.x,y:a.y},data:a}],[]))};if(t===`dbml`){let t=h!==p;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold`,children:`Table DBML`}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r?`Read only. Edit the full schema from DBML in the toolbar.`:`Only the DBML for “${e.name}” can be edited.`})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden bg-muted`,children:(0,$.jsx)(Cn,{value:r?p:h,onChange:g,editable:!r,readOnly:r,extensions:S,theme:i===`dark`?xn:void 0,height:`100%`,basicSetup:{lineNumbers:!0,foldGutter:!1},className:`h-full text-[13px] text-foreground/90`})}),r?(0,$.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-border bg-muted/20 p-3`,children:(0,$.jsxs)(W,{variant:`outline`,onClick:C,children:[u?(0,$.jsx)(Te,{className:`mr-2 size-3.5 text-green-500`}):(0,$.jsx)(hr,{className:`mr-2 size-3.5`}),u?`Copied`:`Copy`]})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-h-8 px-4 py-2 text-xs text-destructive`,children:x.error}),(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-border bg-muted/20 p-3`,children:[(0,$.jsx)(W,{variant:`outline`,onClick:()=>g(p),children:`Reset`}),(0,$.jsx)(W,{onClick:E,disabled:!!x.error||!t,children:`Apply DBML`})]})]})]})}return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 space-y-2 border-b border-border px-4 py-3`,children:[(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto`,children:Ei.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>{s(e.id),l(e.formats[0].id)},className:o(`rounded-md px-2.5 py-1.5 text-[11px] font-semibold whitespace-nowrap`,a===e.id?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e.label},e.id))}),(0,$.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto rounded-lg bg-muted p-1`,children:_.formats.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:o(`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-semibold whitespace-nowrap`,c===e.id?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:[(0,$.jsx)(Ue,{className:`size-3.5`}),e.label]},e.id))})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden bg-muted`,children:(0,$.jsx)(Cn,{value:v,extensions:S,theme:i===`dark`?xn:void 0,readOnly:!0,height:`100%`,basicSetup:{lineNumbers:!0,foldGutter:!1,highlightActiveLine:!1},className:`h-full text-[13px] text-foreground/90`})}),(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-border bg-muted/20 p-3`,children:[(0,$.jsxs)(W,{variant:`outline`,onClick:w,children:[(0,$.jsx)(Oe,{className:`mr-2 size-3.5`}),`Download`]}),(0,$.jsxs)(W,{variant:`outline`,onClick:C,children:[u?(0,$.jsx)(Te,{className:`mr-2 size-3.5 text-green-500`}):(0,$.jsx)(hr,{className:`mr-2 size-3.5`}),u?`Copied`:`Copy`]})]})]})}function ji(e,t,n,r){if(t===n)return null;let i=[...e].sort((e,t)=>(e.sort_order??0)-(t.sort_order??0)),a=i.find(e=>e.id===t);if(!a)return null;let o=i.filter(e=>e.id!==t),s=o.findIndex(e=>e.id===n);return s===-1?null:(o.splice(s+ +(r===`after`),0,a),o.map((e,t)=>({...e,sort_order:t})))}var Mi=[`#6366f1`,`#8b5cf6`,`#ec4899`,`#3b82f6`,`#10b981`,`#f59e0b`,`#ef4444`],Ni=255,Pi=[{name:`created_at`,type:`TIMESTAMP`,is_nullable:!1},{name:`updated_at`,type:`TIMESTAMP`,is_nullable:!1},{name:`deleted_at`,type:`TIMESTAMP`,is_nullable:!0}],Fi=e=>{let t=e.trim();if(!t)return null;let n=Number.parseInt(t,10);return Number.isFinite(n)&&n>=0?n:null};function Ii({selectedEntity:e,onUpdateEntity:t,onDeleteEntity:n,onBackToTables:r,propertiesOnly:a=!1,headerActions:s,dbmlReadOnly:l=!1}){let[u,d]=(0,Q.useState)(e),[f,p]=(0,Q.useState)(`properties`),[m,h]=(0,Q.useState)(null),[g,v]=(0,Q.useState)(Object.fromEntries(Pi.map(e=>[e.name,!0]))),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(null),T=(0,Q.useRef)(null),E=(0,Q.useRef)(null),D=(0,Q.useRef)(null),O=(0,Q.useRef)(!1),k=(0,Q.useRef)(null),A=(0,Q.useRef)(u?.columns?.length||0),ee=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=u?.columns?.length||0;e>A.current&&requestAnimationFrame(()=>{k.current?.scrollIntoView({behavior:`smooth`,block:`end`})}),A.current=e},[u?.columns?.length]);let[j,M]=(0,Q.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}});if((0,Q.useEffect)(()=>{e?.id!==u?.id&&d(e)},[e?.id]),!e||!u)return null;let N=(e,n=!1)=>{n?(D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{t(e,{immediate:!0})},300)):t(e)},P=e=>{d({...u,name:e})},F=e=>{let t={...u,color:e};d(t),N(t,!0)},te=()=>{let e=u.columns.reduce((e,t)=>Math.max(e,t.sort_order||0),-1),t={id:Math.random().toString(36).substring(2,11),name:`new_column`,type:`VARCHAR`,max_length:Ni,is_pk:!1,is_nullable:!0,default_value:`NULL`,sort_order:e+1},n={...u,columns:[...u.columns,t]};ee.current=t.id,d(n),N(n,!0)},ne=()=>{let e=new Set(u.columns.map(e=>e.name.toLowerCase())),t=Pi.filter(t=>g[t.name]&&!e.has(t.name));if(t.length===0){i.info(`Selected audit columns already exist or none were selected`);return}let n=u.columns.reduce((e,t)=>Math.max(e,t.sort_order||0),-1)+1,r=t.map((e,t)=>({id:crypto.randomUUID(),name:e.name,type:e.type,is_pk:!1,is_nullable:e.is_nullable,default_value:_(e.is_nullable?`NULL`:null,e.is_nullable),sort_order:n+t})),a={...u,columns:[...u.columns,...r]};ee.current=r[r.length-1].id,d(a),N(a,!0),b(!1),i.success(`${r.length} audit column${r.length===1?``:`s`} added`)},L=()=>{let e=u.columns.filter(e=>e.is_pk).sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),t=u.columns.filter(e=>!e.is_pk).sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)),n=[...e,...t].map((e,t)=>({...e,sort_order:t})),r={...u,columns:n};d(r),N(r,!0)},re=(e,t)=>{d({...u,columns:u.columns.map(n=>n.id===e?{...n,...t}:n)})},R=(e,t,n=!1)=>{if(O.current){O.current=!1;return}if(`name`in t&&typeof t.name==`string`){let n=t.name.trim();if(u.columns.some(t=>t.id!==e&&t.name.toLowerCase()===n.toLowerCase())){i.error(`Column name "${n}" already exists in this table`);let t=u.columns.find(t=>t.id===e);t&&d({...u,columns:u.columns.map(n=>n.id===e?t:n)});return}t={...t,name:n}}if(`type`in t){let n=u.columns.find(t=>t.id===e);t={...t,.../^varchar$/i.test(String(t.type))&&n?.max_length==null&&{max_length:Ni},...!c(t.type)&&{max_length:null},...!I(t.type)&&{numeric_precision:null,numeric_scale:null}}}let r={...u,columns:u.columns.map(n=>{if(n.id!==e)return n;let r={...n,...t},i=_(r.default_value,!!r.is_nullable);return r.is_nullable&&!i?{...r,default_value:`NULL`}:{...r,default_value:i}})};d(r),N(r,n)},z=e=>{let t={...u,columns:e};d(t),N(t,!0)},B=()=>{T.current=null,E.current=null,w(null),S(null)},V=(e,t)=>{e.button===0&&(e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId),T.current=t,S(t))},ie=e=>{if(!T.current)return;e.preventDefault();let t=document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-column-id]`),n=t?.dataset.columnId;if(!t||!n)return;let r=t.getBoundingClientRect(),i=e.clientY<r.top+r.height/2?`before`:`after`,a={id:n,position:i};E.current=a,w(e=>e?.id===n&&e.position===i?e:a)},H=(e,t)=>{e.preventDefault();let n=E.current,r=n&&ji(u.columns,t,n.id,n.position);r&&z(r),B()},U=e=>{let t={...u,columns:u.columns.filter(t=>t.id!==e)};d(t),N(t,!0)};return(0,$.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-background px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex min-w-0 items-center gap-2 text-xs`,children:[r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:r,className:`flex shrink-0 items-center gap-1 font-medium text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(rt,{className:`size-3.5`}),` Tables`]}),(0,$.jsx)(`span`,{className:`text-muted-foreground/50`,children:`/`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-foreground`,children:u.name})]}):(0,$.jsx)(`span`,{className:`truncate font-medium text-foreground`,children:u.name}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,className:`ml-auto shrink-0 text-destructive hover:bg-destructive/10 hover:text-destructive`,title:`Delete table`,"aria-label":`Delete table ${u.name}`,onClick:()=>M({isOpen:!0,title:`Delete Table`,message:`Are you sure you want to delete the table "${u.name}"? This action cannot be undone.`,onConfirm:()=>{D.current&&clearTimeout(D.current),n(u.id),M(e=>({...e,isOpen:!1}))}}),children:(0,$.jsx)(qt,{className:`size-4`})}),s]}),!a&&(0,$.jsx)(`div`,{className:`flex w-full gap-1 rounded-lg border border-border bg-muted p-1`,"aria-label":`Table editor sections`,children:[[`properties`,`Properties`],[`schema`,`Schema`],[`dbml`,`DBML`]].map(([e,t])=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":f===e,onClick:()=>p(e),className:o(`flex flex-1 items-center justify-center rounded-md px-3 py-2 text-xs font-semibold transition-colors`,f===e?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:bg-background/60 hover:text-foreground`),children:t},e))})]}),!a&&f!==`properties`?(0,$.jsx)(Ai,{entity:u,mode:f,dbmlReadOnly:l,onUpdateEntity:e=>{d(e),t(e)}}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`shrink-0 bg-background pt-6 px-6 pb-4 border-b border-border/50 shadow-sm z-10`,children:(0,$.jsxs)(`section`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:`Table Name`}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)($e,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground z-10`}),(0,$.jsx)(Z,{type:`text`,value:u.name,onChange:e=>P(e.target.value),onBlur:()=>N(u),className:`pl-10 h-10 transition-all focus:ring-1`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:`Theme Color`}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:[Mi.map(e=>(0,$.jsx)(`button`,{onClick:()=>F(e),className:o(`w-7 h-7 rounded-full border-2 transition-all shadow-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,u.color===e?`border-foreground scale-110 shadow-md`:`border-transparent hover:scale-105`),style:{backgroundColor:e}},e)),(0,$.jsx)(`label`,{className:o(`relative w-7 h-7 rounded-full border-2 transition-all shadow-sm cursor-pointer ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2`,Mi.includes(u.color)?`hover:scale-105`:`border-foreground scale-110 shadow-md`),style:{borderColor:Mi.includes(u.color)?u.color:void 0,backgroundColor:Mi.includes(u.color)?`transparent`:u.color},title:`Custom color`,children:(0,$.jsx)(Z,{type:`color`,value:u.color,onChange:e=>F(e.target.value),className:`absolute inset-0 h-full w-full cursor-pointer opacity-0`})})]})]})]})}),(0,$.jsxs)(`div`,{className:`shrink-0 flex items-center justify-between bg-popover/95 py-2 px-6 border-b border-border/50 z-10 shadow-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(nr,{className:`text-[10px] font-bold uppercase tracking-widest text-muted-foreground`,children:[`Columns (`,u.columns.length,`)`]}),(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:L,className:`h-6 w-6 text-muted-foreground hover:text-primary transition-colors`,title:`Normalize (PKs to top)`,children:(0,$.jsx)(Ye,{className:`w-3.5 h-3.5`})}),(0,$.jsxs)(_e,{open:y,onOpenChange:b,children:[(0,$.jsx)(ge,{render:(0,$.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-6 w-6 text-muted-foreground hover:text-primary`,title:`Generate audit columns`,"aria-label":`Generate audit columns`,children:(0,$.jsx)(ht,{className:`w-3.5 h-3.5`})})}),(0,$.jsxs)(me,{align:`start`,className:`w-56 space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold`,children:`Generate audit columns`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Add common timestamp fields.`})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:Pi.map(e=>{let t=u.columns.some(t=>t.name.toLowerCase()===e.name);return(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(or,{checked:g[e.name],disabled:t,onCheckedChange:t=>v(n=>({...n,[e.name]:t===!0}))}),(0,$.jsx)(`span`,{className:o(t&&`text-muted-foreground line-through`),children:e.name}),t&&(0,$.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`Exists`})]},e.name)})}),(0,$.jsx)(W,{type:`button`,size:`sm`,className:`w-full`,onClick:ne,children:`Generate selected`})]})]})]}),(0,$.jsx)(W,{onClick:te,className:`h-8 w-8 rounded-full shadow-sm hover:shadow-md transition-all bg-white text-black hover:bg-white/90`,size:`icon`,children:(0,$.jsx)(he,{className:`w-4 h-4`})})]}),(0,$.jsx)(`section`,{className:`flex-1 overflow-y-auto custom-scrollbar p-4 space-y-2 min-h-0`,children:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[[...u.columns].sort((e,t)=>(e.sort_order||0)-(t.sort_order||0)).map(e=>(0,$.jsxs)(Rt,{"data-column-id":e.id,className:o(`gap-1 p-2 bg-muted/10 border border-border/30 shadow-none hover:border-primary/30 transition-all`,x===e.id&&`opacity-50`,C?.id===e.id&&C.position===`before`&&`border-t-2 border-t-primary`,C?.id===e.id&&C.position===`after`&&`border-b-2 border-b-primary`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Drag ${e.name} to reorder`,title:`Drag to reorder`,onPointerDown:t=>V(t,e.id),onPointerMove:ie,onPointerUp:t=>H(t,e.id),onPointerCancel:B,className:`h-7 w-6 shrink-0 touch-none select-none cursor-grab rounded text-muted-foreground hover:bg-primary/10 hover:text-primary active:cursor-grabbing`,children:(0,$.jsx)(xt,{className:`mx-auto h-4 w-4`})}),(0,$.jsx)(Z,{ref:t=>{t&&e.id===ee.current&&(t.focus(),t.select(),ee.current=null)},placeholder:`Column name`,value:e.name,onChange:t=>re(e.id,{name:t.target.value}),onBlur:t=>R(e.id,{name:t.target.value}),className:`h-8 min-w-0 flex-1 text-xs font-bold bg-background/50 border-border/50 focus-visible:ring-1 shadow-sm transition-all`}),(0,$.jsx)(W,{variant:`ghost`,size:`icon`,onClick:()=>M({isOpen:!0,title:`Delete Column`,message:`Are you sure you want to delete the column "${e.name}"?`,onConfirm:()=>{U(e.id),M(e=>({...e,isOpen:!1}))}}),className:`h-8 w-8 text-destructive/70 hover:text-destructive hover:bg-destructive/10 shrink-0`,title:`Delete column`,children:(0,$.jsx)(qt,{className:`w-4 h-4`})})]}),(0,$.jsxs)(`div`,{className:o(`grid gap-1`,I(e.type)?`grid-cols-[minmax(0,1fr)_3.75rem_3.75rem_2rem_2rem_2rem]`:c(e.type)?`grid-cols-[minmax(0,1fr)_3.75rem_2rem_2rem_2rem]`:`grid-cols-[minmax(0,1fr)_2rem_2rem_2rem]`),children:[(0,$.jsx)(Ti,{value:e.type,onValueChange:t=>R(e.id,{type:t},!0),className:`min-w-0`}),c(e.type)&&(0,$.jsx)(Z,{type:`number`,min:1,value:e.max_length??``,onChange:t=>re(e.id,{max_length:Fi(t.target.value)}),onBlur:t=>R(e.id,{max_length:Fi(t.target.value)}),placeholder:`Max`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`}),I(e.type)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{type:`number`,min:1,value:e.numeric_precision??``,onChange:t=>re(e.id,{numeric_precision:Fi(t.target.value)}),onBlur:t=>R(e.id,{numeric_precision:Fi(t.target.value)}),placeholder:`Prec`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`}),(0,$.jsx)(Z,{type:`number`,min:0,value:e.numeric_scale??``,onChange:t=>re(e.id,{numeric_scale:Fi(t.target.value)}),onBlur:t=>R(e.id,{numeric_scale:Fi(t.target.value)}),placeholder:`Scale`,className:`h-8 px-2 text-[10px] bg-background/50 border-border/50`})]}),(0,$.jsx)(W,{variant:e.is_pk?`default`:`outline`,size:`icon`,onClick:()=>R(e.id,{is_pk:!e.is_pk},!0),className:o(`h-8 w-8 transition-all`,e.is_pk?`bg-yellow-500 hover:bg-yellow-600 text-white`:`text-muted-foreground hover:text-foreground bg-background/50`),title:`Primary Key`,children:(0,$.jsx)(mt,{className:`w-3.5 h-3.5`})}),(0,$.jsx)(W,{variant:e.is_nullable?`outline`:`default`,size:`icon`,onClick:()=>R(e.id,{is_nullable:!e.is_nullable},!0),className:o(`h-8 w-8 transition-all`,e.is_nullable?`text-muted-foreground hover:text-foreground bg-background/50`:`bg-primary hover:bg-primary/90 text-primary-foreground`),title:`Not Null`,children:e.is_nullable?(0,$.jsx)(It,{className:`w-3.5 h-3.5`}):(0,$.jsx)(Te,{className:`w-3.5 h-3.5`})}),(0,$.jsxs)(_e,{open:m===e.id,onOpenChange:t=>h(t?e.id:null),children:[(0,$.jsx)(ge,{render:(0,$.jsx)(W,{type:`button`,variant:`outline`,size:`icon`,"aria-expanded":m===e.id,onMouseDown:()=>{O.current=!0,window.setTimeout(()=>{O.current=!1},0)},className:o(`h-8 w-8 transition-colors`,m===e.id?`border-primary bg-primary text-primary-foreground hover:bg-primary/90`:`text-muted-foreground hover:text-foreground bg-background/50`,e.comment&&m!==e.id&&`border-primary/60`),title:`Field attributes`,"aria-label":`Field attributes`,children:(0,$.jsx)(Et,{className:`w-3.5 h-3.5`})})}),(0,$.jsxs)(me,{align:`end`,side:`left`,className:`w-72 space-y-2`,children:[(0,$.jsx)(nr,{className:`text-xs font-semibold`,children:`Field Attributes`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,$.jsx)(or,{checked:!!e.is_unique,onCheckedChange:t=>R(e.id,{is_unique:t===!0},!0)}),`Unique`]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(nr,{htmlFor:`default-${e.id}`,className:`text-xs text-muted-foreground`,children:`Default value`}),(0,$.jsx)(Z,{id:`default-${e.id}`,value:e.default_value??(e.is_nullable?`NULL`:``),onChange:t=>re(e.id,{default_value:t.target.value}),onBlur:t=>R(e.id,{default_value:t.target.value.trim()||null}),placeholder:`NULL, 0, CURRENT_TIMESTAMP, 'pending'`,className:`h-8 text-sm`})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(nr,{htmlFor:`comment-${e.id}`,className:`text-xs text-muted-foreground`,children:`Comment`}),(0,$.jsx)(jn,{id:`comment-${e.id}`,value:e.comment||``,onChange:t=>re(e.id,{comment:t.target.value}),onBlur:t=>R(e.id,{comment:t.target.value.trim()}),placeholder:`Add a comment`,className:`min-h-20 resize-y text-sm`})]})]})]})]}),e.type===`ENUM`&&(0,$.jsx)(Z,{type:`text`,value:e.enum_values||``,onChange:t=>re(e.id,{enum_values:t.target.value}),onBlur:()=>N(u),placeholder:`Enum values: active, inactive...`,className:`h-8 text-[10px] bg-background/50 border-border/50`})]},e.id)),(0,$.jsx)(`div`,{ref:k})]})})]}),(0,$.jsx)(ut,{isOpen:j.isOpen,title:j.title,message:j.message,onConfirm:j.onConfirm,onCancel:()=>M(e=>({...e,isOpen:!1}))})]})}function Li({entity:e,floating:t,onTogglePin:n,onClose:r,onBackToExplorer:i}){let{handleEntityUpdate:a,deleteEntity:s,setSelectedNodeId:c}=tr(),l=t?{left:t.left,top:t.top,maxHeight:`calc(100% - ${t.top+12}px)`}:void 0;return(0,$.jsx)(`aside`,{"aria-label":`Table ${e.name}`,"data-side":t?.side,style:l,className:o(`nowheel nodrag flex flex-col overflow-hidden border bg-popover text-popover-foreground`,t?`absolute z-30 h-[min(36rem,calc(100%-1.5rem))] w-96 rounded-xl shadow-2xl`:`w-85 shrink-0 rounded-xl max-md:absolute max-md:inset-y-0 max-md:right-0 max-md:z-30 max-md:w-[min(21.25rem,100%)] max-md:shadow-xl`),children:(0,$.jsx)(Ii,{selectedEntity:e,onUpdateEntity:a,onBackToTables:i,dbmlReadOnly:!0,onDeleteEntity:e=>{s(e),c(null),r()},headerActions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:n,"aria-pressed":!t,"aria-label":t?`Pin the table editor beside the canvas`:`Unpin the table editor`,title:t?`Pin`:`Unpin`,children:t?(0,$.jsx)(ft,{className:`size-4`}):(0,$.jsx)(_t,{className:`size-4`})}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon-xs`,onClick:r,"aria-label":`Close table editor`,title:`Close (Esc)`,children:(0,$.jsx)(It,{className:`size-4`})})]})},e.id)})}function Ri(e,t,n){if(!e.sliceDoc(t,n).includes(`{`))return null;let r=e.doc.toString(),i=``,a=!1,o=!1,s=[];for(let e=0;e<r.length;e++){let c=r[e],l=r[e+1];if(a)c===`
|
|
2
2
|
`&&(a=!1);else if(o)c===`*`&&l===`/`&&(o=!1,e++);else if(i){if(c===`\\`){e++;continue}c===i&&(i=``)}else if(c===`/`&&l===`*`)o=!0,e++;else if(c===`/`&&l===`/`||c===`-`&&l===`-`)a=!0,e++;else if(c===`"`||c===`'`||c==="`")i=c;else if(c===`{`&&s.push(e),c===`}`){let r=s.pop();if(r!==void 0&&r>=t&&r<=n&&e>n)return{from:r+1,to:e}}}return null}var zi=[{label:`Table`,type:`keyword`,detail:`table definition`},{label:`Ref`,type:`keyword`,detail:`relationship`},{label:`Enum`,type:`keyword`,detail:`enum definition`},{label:`TableGroup`,type:`keyword`,detail:`table group`},{label:`Note`,type:`keyword`,detail:`project note`},{label:`Indexes`,type:`keyword`,detail:`index block`}],Bi=[{label:`pk`,type:`keyword`,detail:`primary key`},{label:`unique`,type:`keyword`,detail:`unique constraint`},{label:`not null`,type:`keyword`,detail:`not null`},{label:`note`,type:`keyword`,detail:`column note: 'text'`},{label:`default`,type:`keyword`,detail:`default value`},{label:`increment`,type:`keyword`,detail:`auto-increment`},{label:`ref`,type:`keyword`,detail:`inline FK: > table.col`},{label:`headerColor`,type:`keyword`,detail:`table header color`}],Vi=r.map(e=>({label:e,type:`type`,detail:`column type`}));function Hi(e,t){let n=e.names.find(e=>e.toLowerCase()===t.toLowerCase());return n?{name:n,columns:e.cols.get(n)||[]}:null}function Ui(e,t,n,r=8){let i=e.lastIndexOf(`
|
|
3
3
|
`,Math.max(0,t-1))+1,a=e.indexOf(`
|
|
4
4
|
`,t),o=e.slice(i,a===-1?void 0:a),s=e.slice(i,t),c=s.match(/\w+$/)?.[0];if(!c)return[];let l=c.toLowerCase(),u=t-c.length,d=e=>e.filter(e=>e.label.toLowerCase().startsWith(l)).slice(0,r).map(e=>({...e,from:u,to:t})),f=s.slice(0,s.length-c.length).trimEnd(),p=!f||f.startsWith(`//`),m=/^\s/.test(o)&&!/^\s*(Table|Ref|Enum|TableGroup|Note|Indexes)\b/i.test(o),h=/^\s+"[^"]+"\s+\w*$/.test(s)||/^\s+\w+\s+\w*$/.test(s);if(/^\s*Ref:\s/i.test(o)){let e=s.replace(/^\s*Ref:\s*/,``);if(!/[><]/.test(e)){let t=e.match(/^(\w+)\.(\w*)$/);if(t){let e=Hi(n,t[1]);return e?d(e.columns.map(t=>({label:t,type:`property`,detail:e.name}))):[]}return d(n.names.map(e=>({label:e,type:`class`})))}}let g=s.match(/[><]\s*(\w+)\.(\w*)$/i);if(g){let e=Hi(n,g[1]);return e?d(e.columns.map(t=>({label:t,type:`property`,detail:e.name}))):[]}return/[><]\s*\w*$/i.test(s)?d(n.names.map(e=>({label:e,type:`class`}))):m&&h?d(Vi):/\[[^\]]*\w*$/.test(s)?d(Bi):p?d(zi):[]}var Wi=new Set(r.map(e=>e.toUpperCase()));function Gi(){return bn(async e=>{let t=e.state.doc,n=t.toString(),r=[],i=n.split(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{i as r}from"./createLucideIcon-DCn6SI1F.js";import{d as i,f as a}from"./chunk-BV7QT456-B3UxAK3W.js";import{_t as ee,b as te,gt as ne,mt as o,vt as s,x as c}from"./note-importer-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{i as r}from"./createLucideIcon-DCn6SI1F.js";import{d as i,f as a}from"./chunk-BV7QT456-B3UxAK3W.js";import{_t as ee,b as te,gt as ne,mt as o,vt as s,x as c}from"./note-importer-mHEzGrVx.js";import{r as l}from"./pen-tool-CoHyO7pC.js";import{n as u,o as d}from"./api-DuV0sTuY.js";import{l as re}from"./WorkspaceProvider-DkMvUEsL.js";import{n as ie}from"./WorkspaceContext-CitlpD55.js";import{D as ae,O as f}from"./index-xLqjbUVL.js";import{a as p,c as m,i as h,n as oe,o as se,r as ce,s as le,t as ue}from"./DataViewerModeToolbar-B88MzPD6.js";var g=e(t(),1),_=new Map;function de(e,t){let n=d(),r=JSON.stringify({data:t}),i=(_.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{if(d()!==n)throw Error(`Session changed; layout was not saved`);let t=await u(`/api/db-clients/${encodeURIComponent(e)}/layout`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:r});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error||`HTTP ${t.status}`)});_.set(e,i);let a=()=>{_.get(e)===i&&_.delete(e)};return i.then(a,a),i}var v=n();function y(){let{id:e}=i();return(0,v.jsx)(o,{children:(0,v.jsx)(b,{id:e})},e)}function b({id:e}){let[t,n]=a(),[i,o]=(0,g.useState)(null),[_,y]=(0,g.useState)(!0),[b,x]=(0,g.useState)(!1),[S,C]=(0,g.useState)(null),[w,fe]=(0,g.useState)(null),[pe,me]=(0,g.useState)(0),[T,E,he]=ee([]),[D,O,ge]=ne([]),[k,A]=(0,g.useState)(null),j=(0,g.useRef)({x:0,y:0,zoom:1}),M=(0,g.useRef)(null),N=(0,g.useRef)(null),P=(0,g.useRef)(0),F=(0,g.useRef)(null),I=(0,g.useRef)(null),L=(0,g.useRef)(D);L.current=D;let{setViewport:R,getViewport:z,getNodes:B,fitView:V}=s(),{handleExportImage:_e}=re(),{setBreadcrumbLabel:H,user:U}=ie(),W=t.get(`tab`),G=W===`erd`||W===`query`?W:`data`,K=(0,g.useRef)(G),q=(0,g.useRef)(!0);K.current=G,(0,g.useEffect)(()=>(q.current=!0,()=>{q.current=!1}),[]);let J=(0,g.useRef)(new Set([`data`]));J.current.add(G);let Y=Number(i?.catalog_id);M.current=i;let X=(0,g.useCallback)(e=>{n(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n},{replace:!0})},[n]),Z=(0,g.useCallback)(async()=>{if(!e)return;let t=++P.current;F.current?.abort();let n=new AbortController,r=d();F.current=n;let i=()=>P.current!==t||n.signal.aborted||d()!==r;y(!0);try{let t=await u(`/api/db-clients/${encodeURIComponent(e)}`,{signal:n.signal}),r=await t.json();if(i())return;if(!t.ok)throw Error(r.error||`Failed to load DB Client`);if(o(r),H(r.name),!Number(r.catalog_id)){E([]),O([]);return}}finally{i()||y(!1)}},[e,U?.id,H,O,E,R]);(0,g.useEffect)(()=>{if(_||G!==`erd`||!Y)return;let e=new AbortController,t=d(),n=null,i=()=>e.signal.aborted||d()!==t;return x(!0),(async()=>{try{let t=p(Y);if(!t){let n=await u(`/api/catalogs/${Y}/schema`,{method:`POST`,signal:e.signal});if(t=await n.json(),i())return;if(!n.ok)throw Error(t.error||`Failed to load database schema`);se(Y,t)}if(i()||I.current===t.schema)return;let r=M.current?.data,a=m(t.schema||[],r);I.current=t.schema,E(a.nodes),O(a.edges),C(t.dbType||null),r?.viewport&&(j.current=r.viewport,n=requestAnimationFrame(()=>R(r.viewport,{duration:0})))}catch(e){i()||r.error(e instanceof Error?e.message:`Failed to load database schema`)}finally{i()||x(!1)}})(),()=>{e.abort(),n!==null&&cancelAnimationFrame(n)}},[_,G,Y,U?.id,O,E,R]),(0,g.useEffect)(()=>{let e=setTimeout(()=>{let e=P.current+1;Z().catch(()=>{P.current===e&&o(null)})});return()=>{clearTimeout(e),F.current?.abort(),P.current+=1,H(null)}},[Z,H]),(0,g.useEffect)(()=>{let e=e=>{fe(e.detail?.table||null),me(e=>e+1),X(`query`)};return window.addEventListener(`db-connect-open-query`,e),()=>window.removeEventListener(`db-connect-open-query`,e)},[X]);let Q=(0,g.useCallback)(async(e=j.current,t=B(),n=L.current)=>{let i=M.current;if(!i)return;let a=le(t,e,i.data,n);M.current={...i,data:a},o(e=>e&&{...e,data:a}),await de(String(i.uid||i.id),a).catch(e=>{r.error(`ERD layout was not saved: ${e instanceof Error?e.message:`network error`}. Move a table to retry.`)})},[B]),$=(0,g.useCallback)(()=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,Q()},300)},[Q]),ve=(0,g.useCallback)((e,t)=>{j.current=t},[]),ye=(0,g.useCallback)((e,t)=>{j.current=t,e&&$()},[$]);(0,g.useEffect)(()=>()=>{N.current&&(clearTimeout(N.current),N.current=null,Q())},[e,Q]);let be=(0,g.useCallback)(()=>{let e=te(B(),L.current),t=c(e,L.current);E(e),O(t),Q(j.current,e,t),requestAnimationFrame(()=>{q.current&&K.current===`erd`&&V({padding:.2,duration:0}).then(()=>{if(q.current&&K.current===`erd`)return Q(z(),e,t)})})},[B,z,V,Q,E,O]),xe=(0,g.useCallback)((e,t,n)=>{Array.isArray(n?.schema)&&(I.current=n.schema),Q(j.current,e,t)},[Q]),Se=(0,g.useCallback)(e=>{let t=e=>e&&(e.endsWith(`-source`)?e.replace(/-source$/,`-source-l`):e.endsWith(`-source-l`)?e.replace(/-source-l$/,`-source`):e.endsWith(`-target`)?e.replace(/-target$/,`-target-r`):e.endsWith(`-target-r`)?e.replace(/-target-r$/,`-target`):e),n=D.map(n=>n.id===e?{...n,sourceHandle:t(n.sourceHandle),targetHandle:t(n.targetHandle)}:n);O(n),Q(j.current,B(),n)},[D,B,Q,O]);return _?(0,v.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Loading DB Client…`}):i?(0,v.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,v.jsx)(f,{currentView:`db-client`,currentFile:i}),(0,v.jsx)(ue,{activeMode:G,dbType:S,onModeChange:X}),Y?(0,v.jsx)(`div`,{className:G===`data`?`contents`:`hidden`,children:(0,v.jsx)(ce,{connectionId:Y,stateKey:`${i.uid}:${Y}`,onDbTypeChange:C,active:G===`data`})}):null,J.current.has(`query`)&&Y?(0,v.jsx)(`div`,{className:G===`query`?`contents`:`hidden`,children:(0,v.jsx)(oe,{connectionId:Y,dbClientId:Number(i.id),initialTable:w,openNonce:pe})}):null,J.current.has(`erd`)?(0,v.jsxs)(`div`,{className:G===`erd`?`contents`:`hidden`,children:[(0,v.jsx)(h,{nodes:T,edges:D,setNodes:E,setEdges:O,onNodesChange:he,onEdgesChange:ge,onConnect:()=>{},onNodeClick:()=>{},onPaneClick:()=>{},onMove:ve,onEdgeClick:(e,t)=>A(t.id),addEntity:()=>{},handleExportSQL:()=>{},handleExportImage:()=>_e(i.name),onAutoLayout:be,onDatabaseSchemaApplied:xe,isReadOnly:!0,isDbClient:!0,sourceConnectionId:Y,isActive:G===`erd`,onEdgeReconnect:e=>{Q(j.current,B(),e)},onNodeDragStop:$,onMoveEnd:ye,isLoading:b}),(0,v.jsx)(ae,{isOpen:!!k,onOpenChange:e=>{e||A(null)},selectedEdge:D.find(e=>e.id===k)||null,nodes:T,handleEdgeUpdate:()=>{},handleEdgeFlip:Se,deleteEdge:()=>{},moveOnly:!0})]}):null]}):(0,v.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center text-muted-foreground`,children:[(0,v.jsx)(l,{className:`mb-3 size-10 opacity-40`}),`DB Client not found`]})}export{y as DbClientEditorRoute};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{d as r,f as i,l as ee,u as te}from"./chunk-BV7QT456-B3UxAK3W.js";import{b as ne,x as re}from"./note-importer-
|
|
1
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{d as r,f as i,l as ee,u as te}from"./chunk-BV7QT456-B3UxAK3W.js";import{b as ne,x as re}from"./note-importer-mHEzGrVx.js";import{r as ie}from"./pen-tool-CoHyO7pC.js";import{r as ae}from"./WorkspaceProvider-DkMvUEsL.js";import{n as a}from"./WorkspaceContext-CitlpD55.js";import{O as o}from"./index-xLqjbUVL.js";import{i as s,n as c,r as l,t as u}from"./DataViewerModeToolbar-B88MzPD6.js";var d=e(t(),1),f=n();function p(){let e=a(),{activeTeamId:t}=te()||{},{id:n}=r(),p=ee(),{setNodes:m,isPublicView:h,publicData:g,activeDiagramId:_,activeDiagram:v,onNodesChange:oe,onEdgesChange:se,onConnect:ce,selectedNodeId:le,addEntity:ue,undo:de,redo:fe,canUndo:pe,canRedo:y,takeSnapshot:b,onNodeDragStop:x,onMoveEnd:S,handleNodeClick:C,handleNodeDoubleClick:w,handleEdgeClick:T,handlePaneClick:E,handleMove:D,handleWorkspaceExportSQL:O,handleWorkspaceExportImage:k,handleOpenImportModal:A,viewportRef:j,saveDiagram:M,triggerDebouncedSync:N,isERDItemLoading:P,handleDiagramSelect:F,isTeamScopeRefreshing:I,pendingErdDiffTrigger:L,extractColumnIdFromHandle:R,getRelationKey:me,dedupeEdgesByRelation:z}=e,{nodes:B,edges:V}=ae(),H=(0,d.useRef)(!1),[U,W]=i(),[he,ge]=(0,d.useState)(null),[_e,ve]=(0,d.useState)(0),[ye,be]=(0,d.useState)(null),G=(0,d.useMemo)(()=>!h&&(h?g:v)?.source_type===`production_db`,[h,g,v]);(0,d.useEffect)(()=>{G&&v&&p(`/db-client/${v.uid||v.id}`,{replace:!0})},[v,G,p]);let K=U.get(`tab`)||(G?`data`:`erd`),q=(0,d.useCallback)(e=>{W(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n},{replace:!0})},[W]);(0,d.useEffect)(()=>{G&&!U.get(`tab`)&&W(e=>{let t=new URLSearchParams(e);return t.set(`tab`,`data`),t},{replace:!0})},[G,W]),(0,d.useEffect)(()=>{let e=e=>{ge(e.detail?.table||null),ve(e=>e+1),q(`query`)};return window.addEventListener(`db-connect-open-query`,e),()=>window.removeEventListener(`db-connect-open-query`,e)},[q]);let xe=(0,d.useCallback)(()=>{if(!B||B.length===0)return;let t=ne(B,V),n=re(t,V);b?.(B,V),m(t),e.setEdges(n),M(t,n,j.current).then(()=>N()).catch(e=>console.error(`Error saving ERD auto-layout:`,e))},[B,V,m,e.setEdges,b,M,N,j]);(0,d.useEffect)(()=>{h||I||!n||H.current||(String(_)===n?H.current=!0:_||(H.current=!0,F(n)))},[n,_,h,I,F]);let J=(0,d.useMemo)(()=>{let e=(h?g:v)?.source_connection_id;return e==null?void 0:Number(e)},[h,g,v]);if(!h&&!_)return n&&!H.current?(0,f.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,f.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,f.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground animate-pulse`,children:`Loading diagram...`})]}):(0,f.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:(0,f.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Select a diagram to view`})});let Y=h?g:v,Se=h||G||e.isReadOnlyFile(v),X=`${Y?.uid||Y?.id||``}:${J||``}`,Z=v?.project_id??v?.projectId,Q=e.projects.find(e=>String(e.id)===String(Z)),$=Q?.team_id??Q?.teamId,Ce=!h&&!G&&!e.isGuest&&e.getFileAccessRole(Y)!==`viewer`&&Z&&$&&String($)===String(t)&&e.user?.id&&Y?.id?{projectId:String(Z),teamId:String(t),fileId:String(Y.uid??Y.id),userId:String(e.user.id)}:void 0;return!Y&&!h&&!P?(0,f.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,f.jsx)(ie,{className:`w-12 h-12 text-muted-foreground/40 mb-4`}),(0,f.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Diagram not found`}),(0,f.jsx)(`p`,{className:`text-xs text-muted-foreground/60 mt-1`,children:`This diagram may have been deleted or is no longer available.`})]}):!Y&&!h?(0,f.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,f.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,f.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground animate-pulse`,children:`Loading diagram...`})]}):G?(0,f.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-sm text-muted-foreground`,children:`Opening DB Client…`}):(0,f.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,f.jsx)(o,{currentView:G?`db-client`:`erd`}),G&&!h&&(0,f.jsx)(u,{activeMode:K,dbType:ye,onModeChange:q}),K===`data`&&G&&!h&&J?(0,f.jsx)(l,{connectionId:J,stateKey:X,onDbTypeChange:be},X):K===`query`&&G&&!h&&J&&Y?.id?(0,f.jsx)(c,{connectionId:J,dbClientId:Number(Y.id),initialTable:he,openNonce:_e}):(0,f.jsx)(s,{isLoading:P,nodes:B,edges:V,setNodes:e.setNodes,setEdges:e.setEdges,onNodesChange:oe,onEdgesChange:se,onConnect:ce,onNodeClick:C,onNodeDoubleClick:w,onEdgeClick:T,onPaneClick:E,onMove:D,addEntity:ue,onImportSQL:A,onAutoLayout:xe,handleExportSQL:O,handleExportImage:k,isReadOnly:Se,isDbClient:G,comments:Ce,sourceConnectionId:J,undo:de,redo:fe,canUndo:pe,canRedo:y,takeSnapshot:b,selectedNodeId:le,onNodeDragStop:x,onMoveEnd:S,initialViewport:j.current,saveDiagram:M,triggerDebouncedSync:N,pendingErdDiffTrigger:L,extractColumnIdFromHandle:R,getRelationKey:me,dedupeEdgesByRelation:z},h?g?.id:_)]})}export{p as DiagramEditorRoute};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DrawingsView-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{d as r,u as i}from"./chunk-BV7QT456-B3UxAK3W.js";import{t as a}from"./check-BwjD7EK2.js";import{t as o}from"./image-BbGqZ83-.js";import{t as s}from"./message-square-B1YYK_eY.js";import{t as c}from"./preload-helper-BLdHbfdN.js";import{n as l}from"./api-DuV0sTuY.js";import"./WorkspaceProvider-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DrawingsView-CUS2f0K3.js","assets/rolldown-runtime-BCiCTKAo.js","assets/jsx-runtime-Cl3nUQcN.js","assets/createLucideIcon-DCn6SI1F.js","assets/image-compression-su-JvgYP.js","assets/button-CYI0LXM3.js","assets/check-BwjD7EK2.js","assets/message-square-B1YYK_eY.js","assets/preload-helper-BLdHbfdN.js","assets/api-DuV0sTuY.js","assets/WorkspaceContext-CitlpD55.js","assets/extends-CvVTau-c.js","assets/index-xLqjbUVL.js","assets/chunk-BV7QT456-B3UxAK3W.js","assets/note-importer-mHEzGrVx.js","assets/src-C_gRsKqw.js","assets/value-CHmTzbgv.js","assets/useOpenInteractionType-BlKZ7jMy.js","assets/useField-E2Vk7I_Z.js","assets/popover-DcdaCTLH.js","assets/dropdown-menu-BoXeiuAZ.js","assets/getPseudoElementBounds-BEHunO5c.js","assets/CompositeList-BqU8Qax7.js","assets/useCompositeItem-DK528yJL.js","assets/ERDComments-BN8ryun0.js","assets/select-CdQCv8yP.js","assets/ConfirmModal-pEN41Kyx.js","assets/alert-dialog-DXnJdv-M.js","assets/ellipsis-CfqIMSId.js","assets/dialog-BIk9Y-3N.js","assets/trash-2-CV7XVyhd.js","assets/useAuth-splnWP_7.js","assets/w3c-keyname-BAyKiYyI.js","assets/input-CMgoax5D.js","assets/refresh-cw-DyBeWpoi.js","assets/chevron-left-D_Hf28gP.js","assets/pen-tool-CoHyO7pC.js","assets/field-BXvmJTfd.js","assets/hard-drive-Chd5URlA.js","assets/sparkles-BTRhjhc4.js","assets/useLeaveGuard-C4lXrsPo.js","assets/label-CfaCFYRS.js","assets/fileOwnership-CF3Bm_pU.js","assets/WorkspaceProvider-DkMvUEsL.js","assets/localPersistence-CGAJ2Ky5.js","assets/diagramVersioning-DlDBcvq6.js","assets/dist-js-CGfv5pu7.js","assets/core-5A5Ti_Rw.js","assets/index-CFRelQ4M.css","assets/Combination-V_AHx6qx.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{n as t,t as n}from"./jsx-runtime-Cl3nUQcN.js";import{d as r,u as i}from"./chunk-BV7QT456-B3UxAK3W.js";import{t as a}from"./check-BwjD7EK2.js";import{t as o}from"./image-BbGqZ83-.js";import{t as s}from"./message-square-B1YYK_eY.js";import{t as c}from"./preload-helper-BLdHbfdN.js";import{n as l}from"./api-DuV0sTuY.js";import"./WorkspaceProvider-DkMvUEsL.js";import{n as u}from"./WorkspaceContext-CitlpD55.js";import{O as d}from"./index-xLqjbUVL.js";var f=e(t(),1),p=n(),m=(0,f.createContext)(null),h=e=>`${e.type}:${e.id}`;function g({config:e,children:t}){let[n,r]=(0,f.useState)(new Map),i=(0,f.useRef)(0),a=`/api/projects/`+encodeURIComponent(e.projectId)+`/comments`,o=`feature_type=`+e.featureType+`&file_id=`+encodeURIComponent(e.fileId),s=(0,f.useCallback)(async()=>{let e=++i.current;try{let t=await l(a+`/markers?`+o),n=await t.json().catch(()=>({}));if(!t.ok)throw Error(n.error||`Could not load comment markers.`);let s=new Map;for(let e of n.markers||[]){let t={anchorType:e.anchorType??e.anchor_type,anchorId:String(e.anchorId??e.anchor_id),status:e.status===`resolved`?`resolved`:`open`,unreadCount:Number(e.unreadCount??e.unread_count??0)};s.set(h({type:t.anchorType,id:t.anchorId}),t)}e===i.current&&r(s)}catch{}},[a,o]);(0,f.useEffect)(()=>{r(new Map),s();let t=t=>{t.teamId&&t.teamId!==e.teamId||t.projectId&&String(t.projectId)!==e.projectId||s()},n=e=>t(e.detail||{}),a=e=>{let n=e.detail;n?.eventType===`cloud.workspace.sync`&&t(n)},o=e=>t(e.detail||{}),c=window.setInterval(()=>{document.visibilityState===`visible`&&s()},15e3);return window.addEventListener(`collaboration-updated`,n),window.addEventListener(`cloud-workspace-sync`,a),window.addEventListener(`cloud-live-sync-reconnected`,o),()=>{i.current++,window.clearInterval(c),window.removeEventListener(`collaboration-updated`,n),window.removeEventListener(`cloud-workspace-sync`,a),window.removeEventListener(`cloud-live-sync-reconnected`,o)}},[e,s]);let c=(0,f.useMemo)(()=>({config:e,markers:n}),[e,n]);return(0,p.jsx)(m.Provider,{value:c,children:t})}function _(){return(0,f.useContext)(m)}function v({anchor:e}){let t=_(),n=t?.markers.get(h(e));if(!t||!n)return null;let r=e.type===`shape`?`Flowchart shape`:`Drawing element`,i=n.status===`resolved`?`, resolved`:n.unreadCount?`, `+n.unreadCount+` unread`:``,o=n.status===`resolved`?`bg-foreground text-background`:`bg-sky-500 text-white dark:bg-sky-400 dark:text-slate-950`;return(0,p.jsx)(`button`,{type:`button`,className:`flex size-11 shrink-0 items-center justify-center rounded-full border-0 bg-transparent p-0 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-sky-500`,"aria-label":r+` comments`+i,title:r+` comments`+i,onPointerDown:e=>e.stopPropagation(),onClick:n=>{n.stopPropagation(),window.dispatchEvent(new CustomEvent(`project-comment-open-request`,{detail:{featureType:t.config.featureType,fileId:t.config.fileId,type:e.type,id:e.id}}))},children:(0,p.jsx)(`span`,{className:`flex size-5 items-center justify-center rounded-full px-1 text-[9px] font-bold leading-none shadow-sm `+o,children:n.status===`resolved`?(0,p.jsx)(a,{"aria-hidden":`true`,className:`size-2.5 stroke-[3]`}):n.unreadCount>0?n.unreadCount>3?`3+`:n.unreadCount:(0,p.jsx)(s,{"aria-hidden":`true`,className:`size-3`})})})}var y=f.lazy(()=>c(()=>import(`./DrawingsView-CUS2f0K3.js`).then(e=>({default:e.DrawingsView})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]))),b=!1;function x(){let e=u();i();let{id:t}=r(),{activeDrawing:n,activeDrawingId:a,saveDrawing:s,handleDrawingChange:c,deleteDrawing:l,isPublicView:m,isLoading:h,isDrawingItemLoading:_,handleDrawingSelect:v}=e,x=n?.project_id??n?.projectId,S=n?.uid??a,C=e.projects.find(e=>String(e.id)===String(x)),w=C?.team_id??C?.teamId,T=b,E=(0,f.useMemo)(()=>null,[T,e.user?.id,S,x,w]),D=(0,f.useRef)(!1);if((0,f.useEffect)(()=>{!m&&t&&(D.current||(String(a)===t?D.current=!0:a||(D.current=!0,v(t))))},[t,a,m,v]),!m&&!a)return t&&!D.current?(0,p.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,p.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,p.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground animate-pulse`,children:`Loading drawing...`})]}):(0,p.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:(0,p.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Select a drawing to view`})});if(!n&&!_)return(0,p.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,p.jsx)(o,{className:`w-12 h-12 text-muted-foreground/40 mb-4`}),(0,p.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Drawing not found`}),(0,p.jsx)(`p`,{className:`text-xs text-muted-foreground/60 mt-1`,children:`This drawing may have been deleted or is no longer available.`})]});if(!n)return(0,p.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center border rounded-xl bg-muted/10`,children:[(0,p.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,p.jsx)(`p`,{className:`mt-4 text-sm font-medium text-muted-foreground animate-pulse`,children:`Loading drawing...`})]});let O=(0,p.jsx)(y,{isLoading:_,activeDrawingId:m?null:a,activeDrawing:n,saveDrawing:s,handleDrawingChange:c,deleteDrawing:l,isReadOnly:m||e.isReadOnlyFile(n),commentsEnabled:T});return(0,p.jsxs)(`div`,{className:`flex flex-col flex-1 overflow-hidden`,children:[(0,p.jsx)(d,{currentView:`drawings`}),(0,p.jsx)(f.Suspense,{fallback:(0,p.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,p.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,p.jsx)(`div`,{className:`w-6 h-6 border-2 border-primary/30 border-t-primary rounded-full animate-spin`}),(0,p.jsx)(`span`,{className:`text-xs text-muted-foreground/60 animate-pulse`,children:`Loading drawing...`})]})}),children:E?(0,p.jsx)(g,{config:E,children:O},[E.projectId,E.teamId,E.featureType,E.fileId].join(`:`)):O})]})}export{x as DrawingEditorRoute,_ as n,v as t};
|