@locus-forge/locus-map 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +2 -2
- package/README.md +21 -6
- package/dist/assets/{abnfDiagram-VCTEODGH-BnTGKKaL.js → abnfDiagram-VCTEODGH-YtlnkH6t.js} +1 -1
- package/dist/assets/{ar-SA-G6X2FPQ2-LY3czoz9.js → ar-SA-G6X2FPQ2-BH5AlOAp.js} +1 -1
- package/dist/assets/{architectureDiagram-5GKGNRK7-BG9h9KRx.js → architectureDiagram-5GKGNRK7-DKYw7IM8.js} +1 -1
- package/dist/assets/{az-AZ-76LH7QW2-Brv6kuM6.js → az-AZ-76LH7QW2-DoI4xcyq.js} +1 -1
- package/dist/assets/{bg-BG-XCXSNQG7-tsQwwvMW.js → bg-BG-XCXSNQG7-CS9_2dp-.js} +1 -1
- package/dist/assets/{blockDiagram-I7D4REHJ-V9bUuR63.js → blockDiagram-I7D4REHJ-FelDwD1I.js} +1 -1
- package/dist/assets/{bn-BD-2XOGV67Q-0Cou5nNv.js → bn-BD-2XOGV67Q-CoIu5tTK.js} +1 -1
- package/dist/assets/{c4Diagram-7LVT6UL2-BmCtzbrY.js → c4Diagram-7LVT6UL2-Bh7h9IHP.js} +1 -1
- package/dist/assets/{ca-ES-6MX7JW3Y-pZF7WJUL.js → ca-ES-6MX7JW3Y-DAEHzf3H.js} +1 -1
- package/dist/assets/channel-DXsl7ag_.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-D2iTDmHh.js → chunk-2Q5K7J3B-CgUOCDxa.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CTxdXZIx.js → chunk-5VM5RSS4-B97oha-s.js} +1 -1
- package/dist/assets/{chunk-F27PBJKO-Hic1X1pm.js → chunk-F27PBJKO-BQGqI2Ej.js} +1 -1
- package/dist/assets/{chunk-IMKFNOWR-DhLW1JVb.js → chunk-IMKFNOWR-C_sOeFT_.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-_g5twKlC.js → chunk-JWPE2WC7-DG5n2owX.js} +1 -1
- package/dist/assets/{chunk-POPQ4Y6H-DMV4qmkd.js → chunk-POPQ4Y6H-Y-h3THrr.js} +1 -1
- package/dist/assets/{chunk-SVP7TREG-BWg83oEL.js → chunk-SVP7TREG-Dn6yBHtF.js} +1 -1
- package/dist/assets/{chunk-TICWLB2K-CPmkpa7J.js → chunk-TICWLB2K-Cb_yWOVI.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-KnXvIZ_8.js → chunk-XXDRQBXY-QE51OqTj.js} +1 -1
- package/dist/assets/classDiagram-ZZMXUADV-DLyWZtYF.js +1 -0
- package/dist/assets/classDiagram-v2-VYDZK3BY-Cb3mb68m.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-BChK_CGh.js → cose-bilkent-JH36ORCC-Bt7ZI9S1.js} +1 -1
- package/dist/assets/{cs-CZ-2BRQDIVT-CtAC2Qjy.js → cs-CZ-2BRQDIVT-BKZzkx2M.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-CdsltaMX.js → cynefin-OW5HDTMX-n6-BmECj.js} +1 -1
- package/dist/assets/{cynefinDiagram-5FMLGOSQ-bXvXX3Fx.js → cynefinDiagram-5FMLGOSQ-Bq2km1fZ.js} +1 -1
- package/dist/assets/{d3-scale-sM87TD1Z.js → d3-scale-C9oJHYFk.js} +1 -1
- package/dist/assets/{da-DK-5WZEPLOC-DyWwaclV.js → da-DK-5WZEPLOC-DWJm1_Yl.js} +1 -1
- package/dist/assets/{dagre-GXQ25YYZ-CTmiZZVO.js → dagre-GXQ25YYZ-D9EJj_nK.js} +1 -1
- package/dist/assets/{de-DE-XR44H4JA-BDXUBHki.js → de-DE-XR44H4JA-D-5dMJXD.js} +1 -1
- package/dist/assets/{diagram-S7CK7UJ4-Bm8Fy0R_.js → diagram-S7CK7UJ4-DX3qZf_H.js} +1 -1
- package/dist/assets/{diagram-UQ7AKVKN-BU_AmM_A.js → diagram-UQ7AKVKN-lODsxrZ9.js} +1 -1
- package/dist/assets/{diagram-VSXAHHWV-B78LUoXq.js → diagram-VSXAHHWV-B48xz8Xq.js} +1 -1
- package/dist/assets/{diagram-VX7I27RA-DNvWjMlf.js → diagram-VX7I27RA-Dms2AfBa.js} +1 -1
- package/dist/assets/{diagram-Z3DM3KII-DmFVt1fa.js → diagram-Z3DM3KII-BnwZBeJA.js} +1 -1
- package/dist/assets/{ebnfDiagram-PWID7BFC-CpDna0Jp.js → ebnfDiagram-PWID7BFC-OtcCvaIU.js} +1 -1
- package/dist/assets/{el-GR-BZB4AONW-CNhF7oN2.js → el-GR-BZB4AONW-BZVA3YVN.js} +1 -1
- package/dist/assets/{engines-a8mi_N6S.js → engines-DPbXorS1.js} +1 -1
- package/dist/assets/{erDiagram-RLTQ6QDP-BGD-9OAS.js → erDiagram-RLTQ6QDP-Cnh8Gn9f.js} +1 -1
- package/dist/assets/{es-ES-U4NZUMDT-DXMrJcKL.js → es-ES-U4NZUMDT-DKJIfS-2.js} +1 -1
- package/dist/assets/{eu-ES-A7QVB2H4-BTkMEwMi.js → eu-ES-A7QVB2H4-LHCF7lHc.js} +1 -1
- package/dist/assets/{fa-IR-HGAKTJCU-CgkknSS7.js → fa-IR-HGAKTJCU-CMtLvHxY.js} +1 -1
- package/dist/assets/{fi-FI-Z5N7JZ37-B1K83nId.js → fi-FI-Z5N7JZ37-CUIzm5UM.js} +1 -1
- package/dist/assets/{flowDiagram-HODETNUW-CjU1yR1F.js → flowDiagram-HODETNUW-lneiCvFi.js} +1 -1
- package/dist/assets/{fr-FR-RHASNOE6-CBFZBGMr.js → fr-FR-RHASNOE6-DTJ2WS73.js} +1 -1
- package/dist/assets/{ganttDiagram-EL5Y4UJY-bvb8BjSh.js → ganttDiagram-EL5Y4UJY-B2aJ2MDb.js} +1 -1
- package/dist/assets/{gitGraphDiagram-WWUBYQGX-DZXQ_x8t.js → gitGraphDiagram-WWUBYQGX-C74V3MFm.js} +1 -1
- package/dist/assets/{gl-ES-HMX3MZ6V-CON98Mma.js → gl-ES-HMX3MZ6V-BP8M0fQQ.js} +1 -1
- package/dist/assets/{he-IL-6SHJWFNN-CBoFaEdB.js → he-IL-6SHJWFNN-BMd-Q0PW.js} +1 -1
- package/dist/assets/{hi-IN-IWLTKZ5I-BJuoh3dl.js → hi-IN-IWLTKZ5I-Ct52OkX5.js} +1 -1
- package/dist/assets/{hu-HU-A5ZG7DT2-CQruu8XR.js → hu-HU-A5ZG7DT2-NfIL6Jfo.js} +1 -1
- package/dist/assets/{id-ID-SAP4L64H-VhaoENjR.js → id-ID-SAP4L64H-Osl6P1wb.js} +1 -1
- package/dist/assets/index-CyQSsku0.js +624 -0
- package/dist/assets/{index-CDNl17QJ.css → index-DR6sd54W.css} +1 -1
- package/dist/assets/{index-CboxqaL5.js → index-VfiAlFSM.js} +5 -5
- package/dist/assets/{infoDiagram-27XIBGKW-CM9Hap0f.js → infoDiagram-27XIBGKW-BjDMKD-X.js} +1 -1
- package/dist/assets/{ishikawaDiagram-5VMMS53U-i8pQztJI.js → ishikawaDiagram-5VMMS53U-DjrBmz8f.js} +1 -1
- package/dist/assets/{it-IT-JPQ66NNP-Dj9BkXfh.js → it-IT-JPQ66NNP-vT-EYZw5.js} +1 -1
- package/dist/assets/{ja-JP-DBVTYXUO-CB2BlfIS.js → ja-JP-DBVTYXUO-DexyPC4p.js} +1 -1
- package/dist/assets/{journeyDiagram-3NMN7TZE-PxcdqONT.js → journeyDiagram-3NMN7TZE-Bs5RL4Ef.js} +1 -1
- package/dist/assets/{kaa-6HZHGXH3-CLnR_zY5.js → kaa-6HZHGXH3-0BLUFlXY.js} +1 -1
- package/dist/assets/{kab-KAB-ZGHBKWFO-8TJr4nPf.js → kab-KAB-ZGHBKWFO-ByGN5_Fc.js} +1 -1
- package/dist/assets/{kanban-definition-UXKFOSKX-B2p5NBhO.js → kanban-definition-UXKFOSKX-DgcopnbA.js} +1 -1
- package/dist/assets/{kk-KZ-P5N5QNE5-5uZYjZ2e.js → kk-KZ-P5N5QNE5-DlK-wQWu.js} +1 -1
- package/dist/assets/{km-KH-HSX4SM5Z-D54aOpMd.js → km-KH-HSX4SM5Z-BZ75967_.js} +1 -1
- package/dist/assets/{ko-KR-MTYHY66A-Bnm0G6eo.js → ko-KR-MTYHY66A-C-copauZ.js} +1 -1
- package/dist/assets/{ku-TR-6OUDTVRD-CtGCn_eB.js → ku-TR-6OUDTVRD-CNqY-Uj4.js} +1 -1
- package/dist/assets/{layout-BBV3_Svw.js → layout-B8D2HGrb.js} +1 -1
- package/dist/assets/{lt-LT-XHIRWOB4-Bl8G0yv6.js → lt-LT-XHIRWOB4-BopE_XJX.js} +1 -1
- package/dist/assets/{lv-LV-5QDEKY6T-Cax93Eua.js → lv-LV-5QDEKY6T--7hU3JSZ.js} +1 -1
- package/dist/assets/{mindmap-definition-YA3MSWOX-CsOezwmE.js → mindmap-definition-YA3MSWOX-DYOVTEyE.js} +1 -1
- package/dist/assets/{mr-IN-CRQNXWMA-Br7GVyJH.js → mr-IN-CRQNXWMA-DydjVI2G.js} +1 -1
- package/dist/assets/{my-MM-5M5IBNSE-xC6lzTDV.js → my-MM-5M5IBNSE-D6ewM-EV.js} +1 -1
- package/dist/assets/{nb-NO-T6EIAALU-B0i5THqA.js → nb-NO-T6EIAALU--iqOwj15.js} +1 -1
- package/dist/assets/{nl-NL-IS3SIHDZ-CqYhUjP3.js → nl-NL-IS3SIHDZ-Bnhl_SmS.js} +1 -1
- package/dist/assets/{nn-NO-6E72VCQL-rpjr_9Z5.js → nn-NO-6E72VCQL-CIx7sLAQ.js} +1 -1
- package/dist/assets/{oc-FR-POXYY2M6-BlhQ99Ty.js → oc-FR-POXYY2M6-DWt5a8Ow.js} +1 -1
- package/dist/assets/{pa-IN-N4M65BXN-N2XbQgZ_.js → pa-IN-N4M65BXN-BW3LNure.js} +1 -1
- package/dist/assets/{pegDiagram-XKGWAZYB-C2iSJgYQ.js → pegDiagram-XKGWAZYB-ixSY_9-e.js} +1 -1
- package/dist/assets/{pica-DvYcrBvx.js → pica-Dn0N8xAP.js} +1 -1
- package/dist/assets/{pieDiagram-E7YTZNPT-CUjgOGBw.js → pieDiagram-E7YTZNPT-BbCRV6Qi.js} +1 -1
- package/dist/assets/{pl-PL-T2D74RX3-CnMxn1dA.js → pl-PL-T2D74RX3-7nXJ8SiV.js} +1 -1
- package/dist/assets/{pt-BR-5N22H2LF-Di-jnHb3.js → pt-BR-5N22H2LF-DKGGof4J.js} +1 -1
- package/dist/assets/{pt-PT-UZXXM6DQ-BaAKq8Sh.js → pt-PT-UZXXM6DQ-DCLEXuhk.js} +1 -1
- package/dist/assets/{quadrantDiagram-AXDQQJYC-DwwqgJXZ.js → quadrantDiagram-AXDQQJYC-Bvh_H4wg.js} +1 -1
- package/dist/assets/{railroadDiagram-O6MQD6OU-DyRgYGPF.js → railroadDiagram-O6MQD6OU-DHC3neQ8.js} +1 -1
- package/dist/assets/{requirementDiagram-BXWQKSXE-C3ixXeHJ.js → requirementDiagram-BXWQKSXE-DuCkl3u1.js} +1 -1
- package/dist/assets/{ro-RO-JPDTUUEW-BWrclVyo.js → ro-RO-JPDTUUEW-Cwf4k3Ou.js} +1 -1
- package/dist/assets/{ru-RU-B4JR7IUQ-_z0DINaG.js → ru-RU-B4JR7IUQ-sZF6fySs.js} +1 -1
- package/dist/assets/{sankeyDiagram-P5KCCOFB-mKpKYI_w.js → sankeyDiagram-P5KCCOFB-1ELTqwtI.js} +1 -1
- package/dist/assets/{sequenceDiagram-WJ2MYXX4-ZkNd0Wnj.js → sequenceDiagram-WJ2MYXX4-BK8Ou8Dz.js} +1 -1
- package/dist/assets/{si-LK-N5RQ5JYF-CdKOb383.js → si-LK-N5RQ5JYF-DmYhXIqO.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-hQLGO-0z.js → sizeCapture-INFHLROL-BKwx3lxX.js} +1 -1
- package/dist/assets/{sk-SK-C5VTKIMK-MHJC6ZIe.js → sk-SK-C5VTKIMK-BRLu35YX.js} +1 -1
- package/dist/assets/{sl-SI-NN7IZMDC-BF9YWbZx.js → sl-SI-NN7IZMDC-CMjfvJTr.js} +1 -1
- package/dist/assets/{stateDiagram-D77RDMKH-CRWj3j-B.js → stateDiagram-D77RDMKH-CDwJ9XLN.js} +1 -1
- package/dist/assets/stateDiagram-v2-MP3YSRHH-BZjKARGY.js +1 -0
- package/dist/assets/{subset-shared.chunk-DtxXjVIA.js → subset-shared.chunk-DngAvf0H.js} +1 -1
- package/dist/assets/{subset-worker.chunk-DONNSbUF.js → subset-worker.chunk-DkH_mqr5.js} +1 -1
- package/dist/assets/{sv-SE-XGPEYMSR-DkaTkfUY.js → sv-SE-XGPEYMSR-G4S06sbd.js} +1 -1
- package/dist/assets/{swimlanes-42K2YHIH-CFf6j7jO.js → swimlanes-42K2YHIH-Z9u8PDi-.js} +1 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-D0kM5xmS.js +8 -0
- package/dist/assets/{ta-IN-2NMHFXQM-BfxqXEDI.js → ta-IN-2NMHFXQM-DgBbCQ8S.js} +1 -1
- package/dist/assets/{th-TH-HPSO5L25-DT3vLA39.js → th-TH-HPSO5L25-o9u4fVfq.js} +1 -1
- package/dist/assets/{timeline-definition-24CTP7MA-BGP2Dq8M.js → timeline-definition-24CTP7MA-BNgrm1r_.js} +1 -1
- package/dist/assets/{tr-TR-DEFEU3FU-CdfsG7py.js → tr-TR-DEFEU3FU-BqqSdzoL.js} +1 -1
- package/dist/assets/{uk-UA-QMV73CPH-CZrQuC1S.js → uk-UA-QMV73CPH-Dna46aia.js} +1 -1
- package/dist/assets/{vennDiagram-4TSXK5OY-CaxGPIab.js → vennDiagram-4TSXK5OY-CHwUI40M.js} +1 -1
- package/dist/assets/{vi-VN-M7AON7JQ-DQJk1_KV.js → vi-VN-M7AON7JQ-CbKRBQPB.js} +1 -1
- package/dist/assets/{wardleyDiagram-VM6X3IG4-DQxQ-zXH.js → wardleyDiagram-VM6X3IG4-KB0xBjXX.js} +1 -1
- package/dist/assets/{xychartDiagram-S5SC5T6Z-DoxdZQ6R.js → xychartDiagram-S5SC5T6Z-B3LOQLL-.js} +1 -1
- package/dist/assets/{zh-CN-LNUGB5OW-DRVBfkOy.js → zh-CN-LNUGB5OW-BFjA6n_2.js} +1 -1
- package/dist/assets/{zh-HK-E62DVLB3-BJHrltss.js → zh-HK-E62DVLB3-BoTU6iS7.js} +1 -1
- package/dist/assets/{zh-TW-RAJ6MFWO-DpMZ5m2x.js → zh-TW-RAJ6MFWO-DB4kdpOS.js} +1 -1
- package/dist/index.html +2 -2
- package/docs/BUNDLE-FORMAT.md +18 -5
- package/docs/DIAGRAM-SOURCE.md +59 -12
- package/docs/LOCAL-DOCUMENT.md +42 -86
- package/docs/MODEL-CONTRACT.md +7 -4
- package/docs/PLANTUML-SOURCE.md +3 -2
- package/docs/VIEWER-LAUNCH.md +29 -22
- package/docs/VIEWER.md +93 -26
- package/docs/adr/ADR-002-2026-12-03-project-selector/ADR-002-2026-12-03-project-selector.md +1 -1
- package/docs/adr/ADR-005-2026-12-04-named-libraries/ADR-005-2026-12-04-named-libraries.md +1 -1
- package/docs/capabilities.json +21 -3
- package/package.json +2 -1
- package/scripts/build-map.mjs +1 -1
- package/scripts/lib/library-directory.mjs +1 -1
- package/scripts/lib/map-build-invocation.mjs +5 -1
- package/scripts/lib/map-viewer-server.mjs +195 -43
- package/scripts/lib/original-materials.mjs +1 -1
- package/scripts/lib/original-report-server.mjs +7 -3
- package/scripts/lib/project-catalog.mjs +264 -97
- package/scripts/lib/project-map-inputs.mjs +1 -1
- package/scripts/lib/project-registry.mjs +151 -47
- package/scripts/lib/sketch-publication.mjs +1 -1
- package/scripts/lib/task-map-build.mjs +1 -1
- package/scripts/lib/view-args.mjs +163 -0
- package/scripts/lib/workflow/reader-surface.mjs +29 -11
- package/scripts/locus-map.mjs +18 -23
- package/scripts/open-map.mjs +96 -51
- package/skills/README.md +2 -1
- package/skills/locus-map/SKILL.md +30 -26
- package/skills/locus-map/assets/artifact-handoff.md +2 -1
- package/skills/locus-map/references/build-environment.md +11 -7
- package/skills/locus-map/references/checks.md +16 -4
- package/skills/locus-map/references/component-checkpoint.md +35 -0
- package/skills/locus-map/references/draw-skill.md +2 -1
- package/skills/locus-map/references/folder.md +2 -2
- package/skills/locus-map/references/selection.md +36 -13
- package/skills/locus-map/references/task-maps.md +5 -0
- package/skills/locus-map/references/visual-composition.md +69 -0
- package/skills/locus-map-draft/SKILL.md +95 -0
- package/skills/locus-map-draft/assets/chosen-direction.md +47 -0
- package/skills/locus-map-draft/references/divergence-and-formats.md +78 -0
- package/skills/locus-map-primitives/SKILL.md +11 -10
- package/skills/locus-map-primitives/assets/batch/README.md +2 -2
- package/skills/locus-map-primitives/assets/batch/build.mjs +1 -1
- package/skills/locus-map-primitives/assets/batch/{project.json → topic.json} +13 -20
- package/skills/locus-map-primitives/references/card-presentation.md +57 -3
- package/skills/locus-map-primitives/references/reading-files.md +1 -1
- package/src/adapter/areas.js +1 -0
- package/src/adapter/semanticAdmission.js +118 -5
- package/src/authoring/buildDiagram.mjs +99 -19
- package/src/authoring/canvas-source-worker.mjs +96 -0
- package/src/authoring/canvasSource.mjs +41 -0
- package/src/authoring/diagramChecks.js +143 -1
- package/src/authoring/diagramSource.js +31 -5
- package/src/authoring/printPlantumlSource.js +13 -2
- package/src/authoring/readDetailsFiles.mjs +100 -19
- package/src/bundle/chain.js +129 -32
- package/src/bundle/chainBrowser.js +26 -2
- package/src/bundle/localDocument.mjs +87 -22
- package/src/bundle/localDocumentClient.js +5 -1
- package/src/bundle/projectClient.js +64 -21
- package/src/chain/validation.js +7 -1
- package/src/contract/readingMaterials.js +18 -2
- package/src/contract/readingTable.js +66 -0
- package/src/main.jsx +25 -1
- package/src/viewer/ControlIcon.jsx +3 -0
- package/src/viewer/DiagramViewer.jsx +70 -30
- package/src/viewer/EmbeddedExcalidrawEditor.jsx +305 -0
- package/src/viewer/HighlightOverlay.jsx +53 -25
- package/src/viewer/Inspector.jsx +109 -39
- package/src/viewer/ProjectLocation.jsx +25 -7
- package/src/viewer/ProjectRail.jsx +20 -7
- package/src/viewer/ProjectViewChainViewer.jsx +254 -83
- package/src/viewer/ReadingTable.jsx +151 -0
- package/src/viewer/SketchCanvas.jsx +133 -84
- package/src/viewer/ViewChainViewer.jsx +557 -57
- package/src/viewer/ViewerSettings.jsx +208 -0
- package/src/viewer/camera.js +50 -18
- package/src/viewer/chainEditorSession.js +160 -35
- package/src/viewer/chainInstallation.js +3 -3
- package/src/viewer/details/CanvasPreview.jsx +303 -0
- package/src/viewer/details/InspectorReadingSettings.jsx +50 -13
- package/src/viewer/details/ReadingFiles.jsx +32 -4
- package/src/viewer/details/details.css +65 -26
- package/src/viewer/diagramControls.css +1 -1
- package/src/viewer/fileError.js +53 -0
- package/src/viewer/geometry.js +12 -0
- package/src/viewer/inspectorPosition.js +54 -31
- package/src/viewer/projectContents.js +248 -55
- package/src/viewer/projectNavigation.js +27 -3
- package/src/viewer/readingTable.css +47 -0
- package/src/viewer/sketchSettling.js +71 -0
- package/src/viewer/useInspectorPosition.js +116 -35
- package/src/viewer/viewChain.css +92 -5
- package/src/viewer/viewer.css +23 -12
- package/dist/assets/channel-Dx9OTBrx.js +0 -1
- package/dist/assets/classDiagram-ZZMXUADV-Da4s894j.js +0 -1
- package/dist/assets/classDiagram-v2-VYDZK3BY--H9NrCfO.js +0 -1
- package/dist/assets/index-DBGHN_5E.js +0 -624
- package/dist/assets/stateDiagram-v2-MP3YSRHH-B2DcVJGG.js +0 -1
- package/dist/assets/swimlanesDiagram-VR7AAH4N-DO_W2uN2.js +0 -8
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { constants } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { randomUUID } from 'node:crypto';
|
|
5
|
-
import { loadChainBundle, loadChainBundleForRebuild } from './chain.js';
|
|
6
|
+
import { deriveSavedChain, loadChainBundle, loadChainBundleForRebuild } from './chain.js';
|
|
6
7
|
import { BUNDLE_LIMITS, canonicalJson } from './safety.js';
|
|
7
|
-
import { projectView } from '../adapter/chain.js';
|
|
8
|
-
import { inspectSavedSemanticScene } from '../adapter/semanticAdmission.js';
|
|
9
8
|
import { loadSketch } from './sketch.js';
|
|
10
9
|
|
|
11
10
|
export class DocumentError extends Error {
|
|
@@ -21,12 +20,28 @@ const fail = (code, message) => { throw new DocumentError(code, message); };
|
|
|
21
20
|
const identity = stat => `${stat.dev}:${stat.ino}`;
|
|
22
21
|
const stamp = stat => `${identity(stat)}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
|
|
23
22
|
|
|
24
|
-
function
|
|
23
|
+
function authoredChain(chain) {
|
|
24
|
+
const copy = structuredClone(chain);
|
|
25
|
+
for (const { page } of copy.views) {
|
|
26
|
+
if (!page) continue;
|
|
27
|
+
delete page.geometry;
|
|
28
|
+
for (const note of page.notes ?? []) delete note.groupOffset;
|
|
29
|
+
}
|
|
30
|
+
return copy;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function requireSameDocument(original, candidate) {
|
|
25
34
|
if (canonicalJson(original.model) !== canonicalJson(candidate.model)
|
|
26
|
-
|| canonicalJson(original.chain) !== canonicalJson(candidate.chain)
|
|
35
|
+
|| canonicalJson(authoredChain(original.chain)) !== canonicalJson(authoredChain(candidate.chain))
|
|
36
|
+
|| original.canvases.size !== candidate.canvases.size
|
|
27
37
|
|| original.assets.size !== candidate.assets.size) {
|
|
28
38
|
fail('DOCUMENT_SCOPE', 'The model and the view set must belong to the open document.');
|
|
29
39
|
}
|
|
40
|
+
for (const [id, canvas] of original.canvases) {
|
|
41
|
+
const next = candidate.canvases.get(id);
|
|
42
|
+
if (!next || next.format !== canvas.format) fail('DOCUMENT_SCOPE', 'The embedded canvases must belong to the open document.');
|
|
43
|
+
if (canvas.format === 'locus-map') await requireSameDocument(canvas.loaded, next.loaded);
|
|
44
|
+
}
|
|
30
45
|
for (const [key, asset] of original.assets) {
|
|
31
46
|
const next = candidate.assets.get(key);
|
|
32
47
|
if (!next || asset.mimeType !== next.mimeType || asset.path !== next.path
|
|
@@ -34,12 +49,14 @@ function requireSameDocument(original, candidate) {
|
|
|
34
49
|
fail('DOCUMENT_SCOPE', 'The asset content of the open document must not be changed.');
|
|
35
50
|
}
|
|
36
51
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
let expected;
|
|
53
|
+
try { expected = await deriveSavedChain(original.model, original.chain, candidate.scenes, original.scenes); }
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'SEMANTIC_DRIFT') fail(error.code, error.message);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
if (canonicalJson(expected) !== canonicalJson(candidate.chain)) {
|
|
59
|
+
fail('DOCUMENT_SCOPE', 'The page geometry and note offsets must match the saved scenes.');
|
|
43
60
|
}
|
|
44
61
|
}
|
|
45
62
|
|
|
@@ -154,15 +171,61 @@ export async function openLocalDocumentForComparison({ filePath, io = fs }) {
|
|
|
154
171
|
};
|
|
155
172
|
}
|
|
156
173
|
|
|
174
|
+
const lockRoles = new Set(['writer', 'viewer', 'build', 'task-build', 'sketch-create']);
|
|
175
|
+
const maxLockBytes = 4096;
|
|
176
|
+
const lockGraceMs = 5000;
|
|
177
|
+
const isoTimestamp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/u;
|
|
178
|
+
|
|
179
|
+
async function readLockInfo(io, lockPath, checkParents) {
|
|
180
|
+
await checkParents?.();
|
|
181
|
+
const link = await io.lstat(lockPath);
|
|
182
|
+
if (!link.isFile() || link.isSymbolicLink() || link.nlink !== 1 || link.size > maxLockBytes) return;
|
|
183
|
+
const handle = await io.open(lockPath, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
184
|
+
try {
|
|
185
|
+
const stat = await handle.stat();
|
|
186
|
+
if (!stat.isFile() || stat.nlink !== 1 || stamp(stat) !== stamp(link)) return;
|
|
187
|
+
const bytes = Buffer.alloc(stat.size);
|
|
188
|
+
let offset = 0;
|
|
189
|
+
while (offset < bytes.length) {
|
|
190
|
+
const { bytesRead } = await handle.read(bytes, offset, bytes.length - offset, offset);
|
|
191
|
+
if (!bytesRead) return;
|
|
192
|
+
offset += bytesRead;
|
|
193
|
+
}
|
|
194
|
+
const named = await io.lstat(lockPath);
|
|
195
|
+
if (named.nlink !== 1 || stamp(named) !== stamp(stat)) return;
|
|
196
|
+
await checkParents?.();
|
|
197
|
+
|
|
198
|
+
let parsed;
|
|
199
|
+
try { parsed = JSON.parse(bytes.toString('utf8')); }
|
|
200
|
+
catch { /* Unreadable metadata still leaves the document locked. */ }
|
|
201
|
+
const pid = Number.isInteger(parsed?.pid) && parsed.pid > 0 && parsed.pid <= 0x7fffffff ? parsed.pid : undefined;
|
|
202
|
+
const role = lockRoles.has(parsed?.role) ? parsed.role : undefined;
|
|
203
|
+
const timestamp = parsed?.createdAt;
|
|
204
|
+
const time = typeof timestamp === 'string' && isoTimestamp.test(timestamp) ? Date.parse(timestamp) : NaN;
|
|
205
|
+
const createdAt = Number.isFinite(time) ? new Date(time).toISOString() : stat.mtime.toISOString();
|
|
206
|
+
const host = parsed?.host;
|
|
207
|
+
const local = host === undefined || host === '' || host === os.hostname();
|
|
208
|
+
let stale = false;
|
|
209
|
+
if (pid !== undefined && local && Date.now() - stat.mtimeMs >= lockGraceMs) {
|
|
210
|
+
try { process.kill(pid, 0); }
|
|
211
|
+
catch (error) { stale = error.code === 'ESRCH'; }
|
|
212
|
+
}
|
|
213
|
+
return { pid, role, createdAt, stale };
|
|
214
|
+
} finally { await handle.close(); }
|
|
215
|
+
}
|
|
216
|
+
|
|
157
217
|
// Builders and editors must reserve the same file, including its first publication.
|
|
158
|
-
export async function acquireDocumentLock(filename, { io = fs, checkParents } = {}) {
|
|
218
|
+
export async function acquireDocumentLock(filename, { io = fs, checkParents, role = 'writer' } = {}) {
|
|
219
|
+
if (!lockRoles.has(role)) throw new TypeError(`Unsupported document lock role: ${String(role)}`);
|
|
159
220
|
await checkParents?.();
|
|
160
221
|
const lockPath = path.join(path.dirname(filename), `.${path.basename(filename)}.locus-map.lock`);
|
|
161
222
|
let handle;
|
|
162
223
|
try { handle = await io.open(lockPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o600); }
|
|
163
224
|
catch (error) {
|
|
164
|
-
if (error.code
|
|
165
|
-
|
|
225
|
+
if (error.code !== 'EEXIST') throw error;
|
|
226
|
+
const failure = new DocumentError('DOCUMENT_LOCKED', `The document is already open for writing. Close its view or finish the active build: ${lockPath}`);
|
|
227
|
+
failure.lock = await readLockInfo(io, lockPath, checkParents).catch(() => undefined);
|
|
228
|
+
throw failure;
|
|
166
229
|
}
|
|
167
230
|
let token;
|
|
168
231
|
const owned = async () => {
|
|
@@ -177,7 +240,9 @@ export async function acquireDocumentLock(filename, { io = fs, checkParents } =
|
|
|
177
240
|
try {
|
|
178
241
|
try {
|
|
179
242
|
token = identity(await handle.stat());
|
|
180
|
-
await handle.writeFile(JSON.stringify({
|
|
243
|
+
await handle.writeFile(JSON.stringify({
|
|
244
|
+
pid: process.pid, owner: randomUUID(), path: filename, host: os.hostname(), role, createdAt: new Date().toISOString(),
|
|
245
|
+
}));
|
|
181
246
|
}
|
|
182
247
|
finally { await handle.close(); }
|
|
183
248
|
} catch (error) { if (token) await release(); throw error; }
|
|
@@ -186,14 +251,14 @@ export async function acquireDocumentLock(filename, { io = fs, checkParents } =
|
|
|
186
251
|
} };
|
|
187
252
|
}
|
|
188
253
|
|
|
189
|
-
export async function openLocalDocument({ filePath, readOnly = false, io = fs, projectFile, modelId }) {
|
|
254
|
+
export async function openLocalDocument({ filePath, readOnly = false, io = fs, projectFile, modelId, role = 'viewer' }) {
|
|
190
255
|
const file = projectFile ?? await openStableDocumentFile({ filePath, io });
|
|
191
256
|
let original;
|
|
192
257
|
function checkModel(loaded) {
|
|
193
258
|
if (modelId !== undefined && loaded.model.id !== modelId) fail('MODEL_ID_MISMATCH', 'The document model does not match the project catalog.');
|
|
194
259
|
}
|
|
195
260
|
return openDocumentWriter(file, {
|
|
196
|
-
readOnly, io, projectFile,
|
|
261
|
+
readOnly, io, projectFile, role,
|
|
197
262
|
async load(text, { opening, identity: nextIdentity, previousIdentity }) {
|
|
198
263
|
const loaded = await loadChainBundle(text);
|
|
199
264
|
if (opening || (projectFile && modelId !== undefined)) {
|
|
@@ -202,12 +267,12 @@ export async function openLocalDocument({ filePath, readOnly = false, io = fs, p
|
|
|
202
267
|
} else if (!projectFile && nextIdentity === previousIdentity
|
|
203
268
|
&& loaded.model.id === original.model.id && loaded.chain.rootViewId === original.chain.rootViewId) {
|
|
204
269
|
original = loaded;
|
|
205
|
-
} else requireSameDocument(original, loaded);
|
|
270
|
+
} else await requireSameDocument(original, loaded);
|
|
206
271
|
return loaded.bundle;
|
|
207
272
|
},
|
|
208
273
|
async prepare(text) {
|
|
209
274
|
const candidate = await loadChainBundle(text);
|
|
210
|
-
requireSameDocument(original, candidate);
|
|
275
|
+
await requireSameDocument(original, candidate);
|
|
211
276
|
return candidate.bundle;
|
|
212
277
|
},
|
|
213
278
|
});
|
|
@@ -215,13 +280,13 @@ export async function openLocalDocument({ filePath, readOnly = false, io = fs, p
|
|
|
215
280
|
|
|
216
281
|
export function openSketchWriter(file, lock, io = fs) {
|
|
217
282
|
return openDocumentWriter(file, {
|
|
218
|
-
projectFile: file, io, readOnly: false, load: loadSketch, prepare: loadSketch, lock,
|
|
283
|
+
projectFile: file, io, readOnly: false, load: loadSketch, prepare: loadSketch, lock, role: 'viewer',
|
|
219
284
|
});
|
|
220
285
|
}
|
|
221
286
|
|
|
222
287
|
/** One file owner. The queue and revisions protect its clients;
|
|
223
288
|
* rename does not isolate from an uncoordinated external writer. */
|
|
224
|
-
async function openDocumentWriter(file, { readOnly, io, projectFile, load, prepare, lock }) {
|
|
289
|
+
async function openDocumentWriter(file, { readOnly, io, projectFile, load, prepare, lock, role }) {
|
|
225
290
|
const filename = file.path, directory = file.directory, readStable = file.read;
|
|
226
291
|
let closed = false;
|
|
227
292
|
let closing = false;
|
|
@@ -256,7 +321,7 @@ async function openDocumentWriter(file, { readOnly, io, projectFile, load, prepa
|
|
|
256
321
|
await checkPermissions(await readStable());
|
|
257
322
|
await file.checkParents();
|
|
258
323
|
}
|
|
259
|
-
lock ??= await acquireDocumentLock(filename, { io, checkParents: projectFile && file.checkParents });
|
|
324
|
+
lock ??= await acquireDocumentLock(filename, { io, checkParents: projectFile && file.checkParents, role });
|
|
260
325
|
}
|
|
261
326
|
const initial = await readStable();
|
|
262
327
|
const bundle = await load(initial.text, { opening: true });
|
|
@@ -22,7 +22,11 @@ export async function confirmDocumentSave({ text, send, read, validateResponse }
|
|
|
22
22
|
// After a possible effect, only a read is performed. Repeating the POST could overwrite a newer edit.
|
|
23
23
|
let actual;
|
|
24
24
|
try { actual = await read(); }
|
|
25
|
-
catch
|
|
25
|
+
catch (readError) {
|
|
26
|
+
const unconfirmed = failure('SAVE_UNCONFIRMED', 'The write outcome is unknown. Edits are preserved in the window; reopen the file to reconcile.');
|
|
27
|
+
unconfirmed.cause = readError ?? error;
|
|
28
|
+
throw unconfirmed;
|
|
29
|
+
}
|
|
26
30
|
if (actual.readOnly !== false) throw failure('SAVE_UNCONFIRMED', 'Write permission changed. Edits are preserved in the window; reopen the file to reconcile.');
|
|
27
31
|
if (canonicalJson(actual.bundle) !== desired) throw failure('SAVE_CONFLICT', 'The file content differs from the sent snapshot. Edits are preserved in the window; open the file again.');
|
|
28
32
|
return { ...actual, outcome: 'confirmed', reconciled: true };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isPortablePath, isReservedKey } from '../contract/safety.js';
|
|
2
|
-
import { isSketchPath, sketchFilename, sketchNameError, sketchView } from './sketch.js';
|
|
2
|
+
import { loadSketch, isSketchPath, sketchFilename, sketchNameError, sketchView } from './sketch.js';
|
|
3
3
|
import { canonicalJson } from './safety.js';
|
|
4
4
|
import { confirmDocumentSave, failure, originalMaterialOpener, validRevision } from './localDocumentClient.js';
|
|
5
5
|
|
|
@@ -20,9 +20,10 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
20
20
|
const capability = otherTokens.length ? null : token;
|
|
21
21
|
const bindings = new Map();
|
|
22
22
|
let catalogRequest = 0;
|
|
23
|
-
const endpoint = (suffix = '', map) => {
|
|
23
|
+
const endpoint = (suffix = '', map, extra) => {
|
|
24
24
|
const search = new URLSearchParams({ project: id });
|
|
25
25
|
if (map !== undefined) search.set('map', map);
|
|
26
|
+
if (extra) for (const [key, value] of Object.entries(extra)) if (value !== undefined) search.set(key, value);
|
|
26
27
|
return `${address.origin}/api/project${suffix}?${search}`;
|
|
27
28
|
};
|
|
28
29
|
const request = (url, options) => fetcher(url, { cache: 'no-store', redirect: 'error', ...options });
|
|
@@ -35,14 +36,55 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
35
36
|
return body;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
const
|
|
39
|
+
const lockRoles = new Set(['writer', 'viewer', 'build', 'task-build', 'sketch-create']);
|
|
40
|
+
const isoTimestamp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/u;
|
|
41
|
+
const sanitizeReadOnlyReason = (reason, readOnly) => {
|
|
42
|
+
if (reason === undefined) return undefined;
|
|
43
|
+
if (!readOnly) throw invalid();
|
|
44
|
+
if (typeof reason === 'string' && reason.trim()) return { message: reason };
|
|
45
|
+
if (!reason || typeof reason !== 'object' || Array.isArray(reason)
|
|
46
|
+
|| typeof reason.code !== 'string' || !reason.code.trim()
|
|
47
|
+
|| typeof reason.message !== 'string' || !reason.message.trim()) throw invalid();
|
|
48
|
+
let lock;
|
|
49
|
+
if (reason.lock && typeof reason.lock === 'object' && !Array.isArray(reason.lock)) {
|
|
50
|
+
const pid = Number.isInteger(reason.lock.pid) && reason.lock.pid > 0 && reason.lock.pid <= 0x7fffffff ? reason.lock.pid : undefined;
|
|
51
|
+
const role = lockRoles.has(reason.lock.role) ? reason.lock.role : undefined;
|
|
52
|
+
const createdAt = typeof reason.lock.createdAt === 'string' && isoTimestamp.test(reason.lock.createdAt)
|
|
53
|
+
&& Number.isFinite(Date.parse(reason.lock.createdAt)) ? reason.lock.createdAt : undefined;
|
|
54
|
+
const stale = typeof reason.lock.stale === 'boolean' ? reason.lock.stale : undefined;
|
|
55
|
+
if (pid !== undefined || role !== undefined || createdAt !== undefined || stale !== undefined) {
|
|
56
|
+
lock = { ...(pid !== undefined && { pid }), ...(role !== undefined && { role }),
|
|
57
|
+
...(createdAt !== undefined && { createdAt }), ...(stale !== undefined && { stale }) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { code: reason.code, message: reason.message, ...(lock && { lock }) };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const validateSketch = (value, map, { requireReadOnly = false } = {}) => {
|
|
39
64
|
if (value?.project !== id || value.map !== map || !isSketchPath(map) || value.relativePath !== map
|
|
40
|
-
|| value.kind !== 'sketch' || value.
|
|
41
|
-
||
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
|| value.kind !== 'sketch' || !validRevision(value.revision) || typeof value.readOnly !== 'boolean'
|
|
66
|
+
|| ((requireReadOnly || !capability) && value.readOnly !== true)) throw invalid();
|
|
67
|
+
const readOnlyReason = sanitizeReadOnlyReason(value.readOnlyReason, value.readOnly);
|
|
68
|
+
try {
|
|
69
|
+
return {
|
|
70
|
+
...value,
|
|
71
|
+
...(readOnlyReason !== undefined ? { readOnlyReason } : {}),
|
|
72
|
+
path: map,
|
|
73
|
+
bundle: loadSketch(canonicalJson(value.bundle)),
|
|
74
|
+
};
|
|
75
|
+
} catch { throw invalid(); }
|
|
44
76
|
};
|
|
45
77
|
|
|
78
|
+
function validateResponse(value, map, bound, { requireReadOnly = false } = {}) {
|
|
79
|
+
const modelId = value?.bundle?.model?.id;
|
|
80
|
+
if (value?.kind === 'sketch' || value?.project !== id || value.map !== map || !validPath(value.relativePath)
|
|
81
|
+
|| (bound?.path && value.relativePath !== bound.path) || !validRevision(value.revision)
|
|
82
|
+
|| typeof value.readOnly !== 'boolean' || ((requireReadOnly || !capability) && value.readOnly !== true)
|
|
83
|
+
|| !validId(modelId) || (bound?.modelId && modelId !== bound.modelId)) throw invalid();
|
|
84
|
+
const readOnlyReason = sanitizeReadOnlyReason(value.readOnlyReason, value.readOnly);
|
|
85
|
+
return { ...value, ...(readOnlyReason !== undefined ? { readOnlyReason } : {}), path: value.relativePath };
|
|
86
|
+
}
|
|
87
|
+
|
|
46
88
|
const unconfirmedCreate = () => failure('SKETCH_CREATE_UNCONFIRMED',
|
|
47
89
|
'The drawing may have been created. Check the saved drawing before retrying. Your edits are still open.');
|
|
48
90
|
async function readSketch(map) {
|
|
@@ -71,13 +113,14 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
71
113
|
if (sketch && Array.isArray(item?.views) && (item.views.length > 1 || item.views.some(view => view?.id !== sketchView))) throw invalid();
|
|
72
114
|
if (!mapIdValid || !modelIdValid || documents.has(item.id)
|
|
73
115
|
|| (item.relativePath !== undefined && !validMemberPath(item.relativePath))
|
|
116
|
+
|| (item.sourcePath !== undefined && !isPortablePath(item.sourcePath))
|
|
74
117
|
|| typeof item.title !== 'string' || !['available', 'unavailable'].includes(item.status)
|
|
75
118
|
|| !Array.isArray(item.views) || item.views.some(view => !validId(view?.id) || typeof view.title !== 'string'
|
|
76
119
|
|| typeof view.family !== 'string' || !Number.isInteger(view.depth) || view.depth < 0)) throw invalid();
|
|
77
120
|
const bound = bindings.get(item.id);
|
|
78
121
|
if (bound && ((!library && bound.modelId && bound.modelId !== item.modelId)
|
|
79
122
|
|| (bound.path && item.relativePath && bound.path !== item.relativePath))) throw invalid();
|
|
80
|
-
documents.set(item.id, { modelId: item.modelId, path: item.relativePath ?? bound?.path });
|
|
123
|
+
documents.set(item.id, { modelId: item.modelId, path: item.relativePath ?? bound?.path, kind: sketch ? 'sketch' : 'map' });
|
|
81
124
|
}
|
|
82
125
|
if (catalog.links.some(link => !validAddress(link?.from) || !validId(link.from.trigger) || !validAddress(link.to)
|
|
83
126
|
|| [link.sourceNodeLabel, link.targetNodeLabel].some(label => label !== undefined && typeof label !== 'string'))) throw invalid();
|
|
@@ -87,8 +130,16 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
87
130
|
}
|
|
88
131
|
return catalog;
|
|
89
132
|
},
|
|
90
|
-
async
|
|
91
|
-
|
|
133
|
+
async previewDocument(map) {
|
|
134
|
+
if (!validProjectDocumentId(map)) throw invalid();
|
|
135
|
+
const bound = bindings.get(map);
|
|
136
|
+
const value = await readResponse(await request(endpoint('/document', map), { method: 'GET' }));
|
|
137
|
+
const sketch = bound?.kind ? bound.kind === 'sketch' : value?.kind === 'sketch';
|
|
138
|
+
return sketch ? validateSketch(value, map, { requireReadOnly: true })
|
|
139
|
+
: validateResponse(value, map, bound, { requireReadOnly: true });
|
|
140
|
+
},
|
|
141
|
+
async openInZed(map, target) {
|
|
142
|
+
const response = await readResponse(await request(endpoint('/zed', map, target && target !== 'document' ? { target } : undefined), {
|
|
92
143
|
method: 'POST', headers: { 'X-Locus-Action': 'open-in-zed' },
|
|
93
144
|
}));
|
|
94
145
|
if (response?.opened !== true) throw invalid();
|
|
@@ -141,17 +192,9 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
141
192
|
const documentEndpoint = endpoint('/document', map);
|
|
142
193
|
const registered = bindings.get(map);
|
|
143
194
|
let bound = registered;
|
|
144
|
-
const validateResponse = value => {
|
|
145
|
-
const modelId = value?.bundle?.model?.id;
|
|
146
|
-
if (value?.kind === 'sketch' || value?.project !== id || value.map !== map || !validPath(value.relativePath)
|
|
147
|
-
|| (bound?.path && value.relativePath !== bound.path) || !validRevision(value.revision)
|
|
148
|
-
|| typeof value.readOnly !== 'boolean' || (!capability && !value.readOnly)
|
|
149
|
-
|| !validId(modelId) || (bound?.modelId && modelId !== bound.modelId)) throw invalid();
|
|
150
|
-
return { ...value, path: value.relativePath };
|
|
151
|
-
};
|
|
152
195
|
async function readWith(options, url = documentEndpoint) {
|
|
153
|
-
const result = validateResponse(await readResponse(await request(url, options)));
|
|
154
|
-
bound = { modelId: result.bundle.model.id, path: result.path };
|
|
196
|
+
const result = validateResponse(await readResponse(await request(url, options)), map, bound);
|
|
197
|
+
bound = { modelId: result.bundle.model.id, path: result.path, kind: 'map' };
|
|
155
198
|
if (bindings.get(map) === registered) bindings.set(map, bound);
|
|
156
199
|
return result;
|
|
157
200
|
}
|
|
@@ -160,7 +203,7 @@ export function createProjectClient({ url, fetcher = globalThis.fetch }) {
|
|
|
160
203
|
read: () => capability ? readWith({ method: 'POST', headers: auth }, endpoint('/open', map)) : readWith(),
|
|
161
204
|
save({ revision, text }) {
|
|
162
205
|
return confirmDocumentSave({
|
|
163
|
-
text, validateResponse,
|
|
206
|
+
text, validateResponse: value => validateResponse(value, map, bound),
|
|
164
207
|
read: () => readWith({ headers: auth }),
|
|
165
208
|
send: () => request(documentEndpoint, { method: 'POST', headers: {
|
|
166
209
|
...auth, 'Content-Type': 'application/json', 'X-Locus-Revision': revision,
|
package/src/chain/validation.js
CHANGED
|
@@ -7,6 +7,8 @@ import { PAGE_QUESTION_CHARACTERS } from '../contract/page.js';
|
|
|
7
7
|
import { validateLayoutHints } from '../contract/layoutHints.js';
|
|
8
8
|
import { readingTreeProblem } from '@locus-forge/locus-draw/source';
|
|
9
9
|
|
|
10
|
+
import { readingTableProblem } from '../contract/readingTable.js';
|
|
11
|
+
|
|
10
12
|
const ROOT_FIELDS = ['schemaVersion', 'rootViewId', 'views', 'links'];
|
|
11
13
|
const VIEW_FIELDS = ['id', 'title', 'family', 'nodeIds', 'edgeIds'];
|
|
12
14
|
const VIEW_OPTIONAL_FIELDS = ['layout', 'page'];
|
|
@@ -106,7 +108,7 @@ function inspectChain(input, modelInput) {
|
|
|
106
108
|
const viewRecords = [];
|
|
107
109
|
for (const [index, view] of (Array.isArray(chain.views) ? chain.views : []).slice(0, maxViews).entries()) {
|
|
108
110
|
const path = `/views/${index}`;
|
|
109
|
-
let projectable = exactRecord(view, path, [...VIEW_FIELDS, ...(structured ? ['maxNodes'] : []), ...(profiled ? ['presentationProfile'] : ['question'])], [...VIEW_OPTIONAL_FIELDS, 'question', ...(profiled ? ['readingTree'] : [])]);
|
|
111
|
+
let projectable = exactRecord(view, path, [...VIEW_FIELDS, ...(structured ? ['maxNodes'] : []), ...(profiled ? ['presentationProfile'] : ['question'])], [...VIEW_OPTIONAL_FIELDS, 'question', ...(profiled ? ['readingTree', 'readingTable'] : [])]);
|
|
110
112
|
if (!projectable) continue;
|
|
111
113
|
if (profiled && !isPresentationProfile(view.presentationProfile)) report('PRESENTATION_PROFILE', `${path}/presentationProfile`, `Choose one of: ${ALL_PRESENTATION_PROFILES.join(', ')}.`);
|
|
112
114
|
if ((model.presentationProfile === ARCHIMATE_PROFILE || view.presentationProfile === ARCHIMATE_PROFILE) && (view.presentationProfile !== model.presentationProfile || view.family !== 'semantic')) report('ARCHIMATE_PROFILE', path, 'ArchiMate views must retain the canonical profile and semantic layout.');
|
|
@@ -172,6 +174,10 @@ function inspectChain(input, modelInput) {
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
viewRecords.push({ view, path, projectable });
|
|
177
|
+
if (profiled && projectable && Object.hasOwn(view, 'readingTable')) {
|
|
178
|
+
const problem = readingTableProblem(view.readingTable, nodeList.ids);
|
|
179
|
+
if (problem) report('INVALID_READING_TABLE', path + '/readingTable', problem);
|
|
180
|
+
}
|
|
175
181
|
if (projectable && Object.hasOwn(view, 'readingTree')) {
|
|
176
182
|
const problem = view.family !== 'semantic' ? 'A reading tree requires a semantic view.'
|
|
177
183
|
: readingTreeProblem(view.readingTree, nodeList.ids, edgeList.ids.map(id => edges.get(id)));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { parseStoredMarkdown, readingTextLimit, readingTokenLimit } from './readingMarkdown.js';
|
|
2
2
|
import { isMarkdownText } from '@locus-forge/locus-draw/source';
|
|
3
|
-
import { isPortablePath, isReservedKey } from './safety.js';
|
|
3
|
+
import { isPlainText, isPortablePath, isReservedKey } from './safety.js';
|
|
4
4
|
|
|
5
5
|
export const hasHtmlOriginal = file => (file?.kind === 'report' || file?.kind === 'original')
|
|
6
6
|
&& typeof file.sourcePath === 'string' && /\.html?$/iu.test(file.sourcePath);
|
|
7
7
|
|
|
8
8
|
// Saved reports contain text, these inert elements, and references to bundle images.
|
|
9
9
|
export const reportTags = new Set('div p h1 h2 h3 h4 h5 h6 blockquote pre code strong em b i sub sup del ul ol li dl dt dd table caption thead tbody tfoot tr th td figure figcaption br hr'.split(' '));
|
|
10
|
-
export const readingLimits = Object.freeze({ files: 128, perItem: 12, nodes: 12000, depth: 20, text: readingTextLimit });
|
|
10
|
+
export const readingLimits = Object.freeze({ files: 128, canvases: 16, perItem: 12, nodes: 12000, depth: 20, text: readingTextLimit });
|
|
11
11
|
const object = v => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
12
12
|
const fields = (value, allowed) => object(value) && Object.keys(value).every(k => allowed.includes(k));
|
|
13
13
|
const id = s => typeof s === 'string' && /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(s) && !isReservedKey(s);
|
|
@@ -50,6 +50,7 @@ export function validateReadingMaterials(reading, model, report) {
|
|
|
50
50
|
}
|
|
51
51
|
return n.children.every(child => validNode(child, depth + 1));
|
|
52
52
|
}
|
|
53
|
+
const canvasIds = new Set();
|
|
53
54
|
for (const [key, f] of files) {
|
|
54
55
|
if (f?.kind === 'original') {
|
|
55
56
|
if (!id(key) || !used.has(key) || !fields(f, ['kind', 'sourcePath']) || !isPortablePath(f.sourcePath)) {
|
|
@@ -70,6 +71,13 @@ export function validateReadingMaterials(reading, model, report) {
|
|
|
70
71
|
valid = Boolean(parsed) && extendedMarkdownTokens <= readingTokenLimit;
|
|
71
72
|
characters += f.text.length;
|
|
72
73
|
}
|
|
74
|
+
} else if (valid && f.kind === 'canvas') {
|
|
75
|
+
valid = fields(f, ['kind', 'name', 'canvasId', 'format', 'title', 'sourceFormat', 'sourcePath'])
|
|
76
|
+
&& id(f.canvasId) && !canvasIds.has(f.canvasId) && canvasIds.size < readingLimits.canvases
|
|
77
|
+
&& ['locus-map', 'excalidraw'].includes(f.format)
|
|
78
|
+
&& typeof f.title === 'string' && Boolean(f.title.trim()) && f.title.length <= 256 && isPlainText(f.title)
|
|
79
|
+
&& (!own(f, 'sourceFormat') || ['mjs', 'puml', 'map-json', 'locus-map', 'excalidraw'].includes(f.sourceFormat));
|
|
80
|
+
canvasIds.add(f.canvasId);
|
|
73
81
|
} else if (valid) {
|
|
74
82
|
valid = f.kind === 'report' && fields(f,['kind','name','content','sourcePath']) && Array.isArray(f.content)
|
|
75
83
|
&& f.content.length > 0 && f.content.every(n => validNode(n, 0));
|
|
@@ -78,6 +86,14 @@ export function validateReadingMaterials(reading, model, report) {
|
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
export function readingCanvasEntries(model) {
|
|
90
|
+
return Object.entries(model?.reading?.files ?? {})
|
|
91
|
+
.filter(([, file]) => file?.kind === 'canvas')
|
|
92
|
+
.map(([id, { canvasId, format, title, name, sourceFormat, sourcePath }]) =>
|
|
93
|
+
({ id, canvasId, format, title, name, sourceFormat, sourcePath }))
|
|
94
|
+
.sort((a, b) => a.canvasId < b.canvasId ? -1 : Number(a.canvasId > b.canvasId));
|
|
95
|
+
}
|
|
96
|
+
|
|
81
97
|
export function projectReadingMaterials(reading, elements, assetIds) {
|
|
82
98
|
if (!reading) return;
|
|
83
99
|
const items = {}, files = {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { isPlainText, isReservedKey } from './safety.js';
|
|
2
|
+
|
|
3
|
+
const record = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
|
+
const keys = (value, allowed) => record(value) && Object.keys(value).every(key => allowed.includes(key));
|
|
5
|
+
const invisible = /[\u200b-\u200f\u202a-\u202e\u2060\u2063\u2066-\u2069\ufeff]/u;
|
|
6
|
+
const text = (value, limit) => isPlainText(value) && Boolean(value.trim()) && value.length <= limit && !invisible.test(value);
|
|
7
|
+
const list = (value, limit) => Array.isArray(value) && value.length >= 1 && value.length <= limit;
|
|
8
|
+
const stableId = id => typeof id === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(id) && !isReservedKey(id);
|
|
9
|
+
const tones = ['ok', 'bad', 'warn', 'info', 'neutral'];
|
|
10
|
+
|
|
11
|
+
function catalogProblem(items, columns) {
|
|
12
|
+
const ids = new Set();
|
|
13
|
+
for (const item of items) {
|
|
14
|
+
if (!keys(item, columns ? ['id', 'label', 'align'] : ['id', 'label']) || !stableId(item.id) || ids.has(item.id))
|
|
15
|
+
return 'Each entry needs a unique stable id and supported fields.';
|
|
16
|
+
if (!text(item.label, columns ? 120 : 64)) return 'Each entry needs a nonempty plain text label within the length limit.';
|
|
17
|
+
if ('align' in item && !['left', 'right'].includes(item.align)) return 'Choose left or right alignment.';
|
|
18
|
+
ids.add(item.id);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function validCell(value) {
|
|
24
|
+
if (typeof value === 'string') return text(value, 256);
|
|
25
|
+
return keys(value, ['text', 'subtext', 'tone']) && text(value.text, 256)
|
|
26
|
+
&& (!('subtext' in value) || text(value.subtext, 256))
|
|
27
|
+
&& (!('tone' in value) || tones.includes(value.tone));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function readingTableProblem(table, nodeIds) {
|
|
31
|
+
if (!keys(table, ['columns', 'rows', 'defaultMode', 'filters'])) return 'Expected a reading table with supported fields.';
|
|
32
|
+
if ('defaultMode' in table && !['table', 'canvas'].includes(table.defaultMode)) return 'Choose table or canvas for defaultMode.';
|
|
33
|
+
if (!list(table.columns, 8)) return 'Declare 1–8 columns.';
|
|
34
|
+
const columnProblem = catalogProblem(table.columns, true);
|
|
35
|
+
if (columnProblem) return 'Invalid columns. ' + columnProblem;
|
|
36
|
+
const columns = new Set(table.columns.map(column => column.id));
|
|
37
|
+
const filters = table.filters;
|
|
38
|
+
if ('filters' in table) {
|
|
39
|
+
if (!keys(filters, ['allLabel', 'options']) || !list(filters.options, 16)
|
|
40
|
+
|| ('allLabel' in filters && !text(filters.allLabel, 64))) return 'Declare 1–16 filter options and an optional plain text allLabel (at most 64 characters).';
|
|
41
|
+
const filterProblem = catalogProblem(filters.options, false);
|
|
42
|
+
if (filterProblem) return 'Invalid filters. ' + filterProblem;
|
|
43
|
+
}
|
|
44
|
+
const options = new Set(filters?.options.map(option => option.id));
|
|
45
|
+
if (!list(table.rows, 500)) return 'Declare 1–500 rows.';
|
|
46
|
+
const available = new Set(nodeIds);
|
|
47
|
+
for (const [index, row] of table.rows.entries()) {
|
|
48
|
+
const location = 'Row ' + (index + 1) + ': ';
|
|
49
|
+
if (!keys(row, ['nodeId', 'cells', 'filter', 'dividerBefore']) || !available.delete(row.nodeId))
|
|
50
|
+
return location + 'Use supported fields and a distinct nodeId from this view.';
|
|
51
|
+
if ('filter' in row && !options.has(row.filter)) return location + 'Unknown filter.';
|
|
52
|
+
if ('dividerBefore' in row && typeof row.dividerBefore !== 'boolean') return location + 'dividerBefore must be boolean.';
|
|
53
|
+
if (!record(row.cells) || !Object.keys(row.cells).length) return location + 'Declare at least one cell.';
|
|
54
|
+
for (const [id, cell] of Object.entries(row.cells)) {
|
|
55
|
+
if (!columns.has(id)) return location + 'Unknown column ' + id + '.';
|
|
56
|
+
if (!validCell(cell)) return location + 'Invalid text, subtext or tone in column ' + id + '.';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function validateReadingTable(table, nodeIds, path = '/readingTable') {
|
|
63
|
+
const message = readingTableProblem(table, nodeIds);
|
|
64
|
+
return message ? { valid: false, diagnostics: [{ code: 'INVALID_READING_TABLE', path, message }] }
|
|
65
|
+
: { valid: true, diagnostics: [] };
|
|
66
|
+
}
|
package/src/main.jsx
CHANGED
|
@@ -85,4 +85,28 @@ function readLaunch() {
|
|
|
85
85
|
return { documentClient, projectClient, workspace, initialUrl: address.href, initialError };
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
async function boot() {
|
|
89
|
+
const root = createRoot(document.getElementById('root'));
|
|
90
|
+
const launch = readLaunch();
|
|
91
|
+
if (!launch.projectClient && !launch.documentClient && !launch.initialError && !window.location.search) {
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch('/api/entry', { cache: 'no-store', redirect: 'error' });
|
|
94
|
+
if (response.ok) {
|
|
95
|
+
const entry = await response.json();
|
|
96
|
+
if (typeof entry?.project === 'string' && entry.project) {
|
|
97
|
+
const target = new URL('/', window.location.origin);
|
|
98
|
+
target.searchParams.set('project', entry.project);
|
|
99
|
+
if (typeof entry.workspace === 'string' && entry.workspace) {
|
|
100
|
+
target.hash = new URLSearchParams({ workspace: entry.workspace }).toString();
|
|
101
|
+
}
|
|
102
|
+
window.history.replaceState(window.history.state, '', target);
|
|
103
|
+
root.render(<App launch={readLaunch()} />);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch { /* No workspace entry endpoint; fall back to standalone file opener. */ }
|
|
108
|
+
}
|
|
109
|
+
root.render(<App launch={launch} />);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
boot();
|
|
@@ -13,6 +13,9 @@ const strokes = {
|
|
|
13
13
|
share: 'm9 15 6-6m-7 3-2 2a3.5 3.5 0 0 0 5 5l3-3m2-4 2-2a3.5 3.5 0 0 0-5-5l-3 3',
|
|
14
14
|
readable: 'm3 18 5-13 5 13M5 14h6m3-3c5-3 6 1 6 3v4m0-5c-7-1-7 7 0 3',
|
|
15
15
|
fit: 'M9 4H4v5m11-5h5v5M4 15v5h5m11-5v5h-5',
|
|
16
|
+
popout: 'M7 17 17 7M9 7h8v8',
|
|
17
|
+
settings: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm7.4-1.5a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V20a2 2 0 1 1-4 0v-.1a1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H4a2 2 0 1 1 0-4h.1a1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3h.1a1.6 1.6 0 0 0 1-1.5V4a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8v.1a1.6 1.6 0 0 0 1.5 1H20a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1Z',
|
|
18
|
+
source: 'm8 9-4 3 4 3m8-6 4 3-4 3m-5 2 2-10',
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export function ControlIcon({ name }) {
|