@redvars/peacock 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BaseField-CAog9TIc.js → BaseField-_unSNU5x.js} +43 -4
- package/dist/BaseField-_unSNU5x.js.map +1 -0
- package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-DtZH0fPJ.js} +7 -4
- package/dist/BaseInput-DtZH0fPJ.js.map +1 -0
- package/dist/accordion.js.map +1 -1
- package/dist/ai-badge.js +32 -6
- package/dist/ai-badge.js.map +1 -1
- package/dist/ai-summary.js +2 -2
- package/dist/alert.js +2 -2
- package/dist/anchor-nav.js +2 -2
- package/dist/app-shell.js +2 -2
- package/dist/assistant-panel.js +2 -2
- package/dist/assistant-step.js +2 -2
- package/dist/assistant-steps.js +2 -2
- package/dist/avatar-group.js +2 -2
- package/dist/banner.js +2 -2
- package/dist/{base-button-Do2TUy8M.js → base-button-BJMGMcMv.js} +3 -1
- package/dist/base-button-BJMGMcMv.js.map +1 -0
- package/dist/{base-progress-BiLlZVHJ.js → base-progress-D7Nmfh1s.js} +4 -2
- package/dist/base-progress-D7Nmfh1s.js.map +1 -0
- package/dist/bottom-sheet.js +2 -2
- package/dist/breadcrumb.js +2 -2
- package/dist/button-group.js +4 -4
- package/dist/button.js +14 -8
- package/dist/button.js.map +1 -1
- package/dist/calendar.js +2 -2
- package/dist/canvas-base-CWQ4rQ2s.js +788 -0
- package/dist/canvas-base-CWQ4rQ2s.js.map +1 -0
- package/dist/canvas-link-CtgsALq4.js +54 -0
- package/dist/canvas-link-CtgsALq4.js.map +1 -0
- package/dist/{cartesian-chart-C-f1frt0.js → cartesian-chart-CS5yRLfE.js} +3 -2
- package/dist/cartesian-chart-CS5yRLfE.js.map +1 -0
- package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-CO30uFQZ.js} +2 -2
- package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-CO30uFQZ.js.map} +1 -1
- package/dist/cb-group.js +3 -3
- package/dist/cb-rule.js +3 -3
- package/dist/chart-area.js +5 -4
- package/dist/chart-area.js.map +1 -1
- package/dist/chart-bar.js +5 -4
- package/dist/chart-bar.js.map +1 -1
- package/dist/chart-base-C_XKVyhf.js +833 -0
- package/dist/chart-base-C_XKVyhf.js.map +1 -0
- package/dist/chart-doughnut.js +4 -3
- package/dist/chart-doughnut.js.map +1 -1
- package/dist/chart-line.js +5 -4
- package/dist/chart-line.js.map +1 -1
- package/dist/chart-pie.js +4 -3
- package/dist/chart-pie.js.map +1 -1
- package/dist/chat-event.js +152 -0
- package/dist/chat-event.js.map +1 -0
- package/dist/chat-message.js +195 -19
- package/dist/chat-message.js.map +1 -1
- package/dist/chat-thread.js +26 -9
- package/dist/chat-thread.js.map +1 -1
- package/dist/checkbox-group.js +5 -5
- package/dist/checkbox.js +5 -5
- package/dist/chip-set.js +4 -4
- package/dist/chip.js +4 -4
- package/dist/circular-progress.js +3 -3
- package/dist/citation.js +2 -2
- package/dist/code-editor.js +6 -5
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -2
- package/dist/color-field.js +6 -6
- package/dist/color-picker.js +2 -2
- package/dist/command-palette.js +2 -2
- package/dist/comment-composer.js +6 -6
- package/dist/condition-builder.js +3 -3
- package/dist/confirm-dialog.js +2 -2
- package/dist/copy-button.js +2 -2
- package/dist/currency-field.js +6 -6
- package/dist/custom-elements-jsdocs.json +2330 -397
- package/dist/custom-elements.json +20464 -542
- package/dist/date-field.js +7 -7
- package/dist/date-picker.js +4 -2
- package/dist/date-picker.js.map +1 -1
- package/dist/date-range-field.js +7 -7
- package/dist/datetime-field.js +7 -7
- package/dist/dependency-map-layout-5KUueabk.js +1390 -0
- package/dist/dependency-map-layout-5KUueabk.js.map +1 -0
- package/dist/dependency-map.js +1605 -0
- package/dist/dependency-map.js.map +1 -0
- package/dist/description-item.js +2 -2
- package/dist/description-list.js +2 -2
- package/dist/diagram-Va096vj9.js +2029 -0
- package/dist/diagram-Va096vj9.js.map +1 -0
- package/dist/diagram-controls.js +345 -0
- package/dist/diagram-controls.js.map +1 -0
- package/dist/diagram-minimap.js +216 -0
- package/dist/diagram-minimap.js.map +1 -0
- package/dist/diagram.js +20 -0
- package/dist/diagram.js.map +1 -0
- package/dist/diff-viewer.js +2 -2
- package/dist/discussion-activity.js +4 -4
- package/dist/discussion-comment.js +4 -4
- package/dist/{discussion-time-BegaYfhf.js → discussion-time-DqykqvNy.js} +2 -2
- package/dist/{discussion-time-BegaYfhf.js.map → discussion-time-DqykqvNy.js.map} +1 -1
- package/dist/discussion.js +8 -8
- package/dist/{document-editor-BO7QPbO5.js → document-editor-Dc8JeFVB.js} +2 -2
- package/dist/{document-editor-BO7QPbO5.js.map → document-editor-Dc8JeFVB.js.map} +1 -1
- package/dist/document-editor.js +3 -3
- package/dist/draft-card.js +14 -4
- package/dist/draft-card.js.map +1 -1
- package/dist/dropdown-button.js +3 -2
- package/dist/dropdown-button.js.map +1 -1
- package/dist/erd.js +2021 -0
- package/dist/erd.js.map +1 -0
- package/dist/fab.js +4 -4
- package/dist/field.js +257 -43
- package/dist/field.js.map +1 -1
- package/dist/file-upload.js +38 -16
- package/dist/file-upload.js.map +1 -1
- package/dist/filter-bar.js +2 -2
- package/dist/flow.js +27 -970
- package/dist/flow.js.map +1 -1
- package/dist/focus-ring.js +2 -0
- package/dist/focus-ring.js.map +1 -1
- package/dist/{form-associated-D3Tn33s_.js → form-associated-BHbg72PG.js} +3 -1
- package/dist/{form-associated-D3Tn33s_.js.map → form-associated-BHbg72PG.js.map} +1 -1
- package/dist/{form-submitter-DWwv6K9-.js → form-submitter-beG1CXAn.js} +7 -1
- package/dist/{form-submitter-DWwv6K9-.js.map → form-submitter-beG1CXAn.js.map} +1 -1
- package/dist/form.js +3 -3
- package/dist/{generative-view-DmtpDobn.js → generative-view-BKlcuujw.js} +13 -13
- package/dist/generative-view-BKlcuujw.js.map +1 -0
- package/dist/generative-view.js +3 -3
- package/dist/geometry-INg82Lxq.js +305 -0
- package/dist/geometry-INg82Lxq.js.map +1 -0
- package/dist/history-YbTSQZHj.js +45 -0
- package/dist/history-YbTSQZHj.js.map +1 -0
- package/dist/host-CZK7xhzh.js +40 -0
- package/dist/host-CZK7xhzh.js.map +1 -0
- package/dist/html-editor.js +6 -6
- package/dist/{hyperlink-DhE9RlVS.js → hyperlink-DycWPKwU.js} +10 -1
- package/dist/hyperlink-DycWPKwU.js.map +1 -0
- package/dist/{i18n-controller-urcQKYGe.js → i18n-controller-DJHsE1YH.js} +2 -2
- package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-DJHsE1YH.js.map} +1 -1
- package/dist/icon-button.js +11 -9
- package/dist/icon-button.js.map +1 -1
- package/dist/image.js +2 -2
- package/dist/index.js +42 -22
- package/dist/index.js.map +1 -1
- package/dist/inline-edit.js +2 -2
- package/dist/input.js +5 -5
- package/dist/json-viewer.js +2 -2
- package/dist/kanban.js +2 -2
- package/dist/kbd.js +2 -2
- package/dist/linear-progress.js +3 -3
- package/dist/link-button.js +9 -7
- package/dist/link-button.js.map +1 -1
- package/dist/list-item.js +2 -2
- package/dist/list.js +2 -2
- package/dist/listbox.js +4 -4
- package/dist/loader-full.js +17 -16
- package/dist/loader-full.js.map +1 -1
- package/dist/loader.js +51 -18
- package/dist/loader.js.map +1 -1
- package/dist/markdown-editor.js +6 -6
- package/dist/markers-BFmh1OCz.js +46 -0
- package/dist/markers-BFmh1OCz.js.map +1 -0
- package/dist/measure-controller-Dmc5hZKg.js +89 -0
- package/dist/measure-controller-Dmc5hZKg.js.map +1 -0
- package/dist/mention-input.js +7 -6
- package/dist/mention-input.js.map +1 -1
- package/dist/menu-item.js +3 -2
- package/dist/menu-item.js.map +1 -1
- package/dist/{menu-trigger-controller-DyLpTxM7.js → menu-trigger-controller-CEJq1ugC.js} +11 -14
- package/dist/menu-trigger-controller-CEJq1ugC.js.map +1 -0
- package/dist/menu.js +2 -2
- package/dist/modal.js +2 -2
- package/dist/navigation-bar.js +2 -2
- package/dist/navigation-drawer.js +2 -2
- package/dist/navigation-rail.js +2 -2
- package/dist/notification-center.js +3 -3
- package/dist/number-field.js +7 -6
- package/dist/number-field.js.map +1 -1
- package/dist/option.js +2 -2
- package/dist/page-header.js +2 -2
- package/dist/pagination.js +2 -2
- package/dist/password-field.js +6 -6
- package/dist/password-rules.js +2 -2
- package/dist/phone-field.js +6 -6
- package/dist/{picker-field-B4DtcJfL.js → picker-field-CUI05sWc.js} +3 -3
- package/dist/{picker-field-B4DtcJfL.js.map → picker-field-CUI05sWc.js.map} +1 -1
- package/dist/pin-input.js +6 -6
- package/dist/presence-indicator.js +2 -2
- package/dist/prompt-input.js +6 -6
- package/dist/radio-group.js +2 -1
- package/dist/radio-group.js.map +1 -1
- package/dist/radio.js +6 -6
- package/dist/radio.js.map +1 -1
- package/dist/rating.js +6 -5
- package/dist/rating.js.map +1 -1
- package/dist/redvars-loader.js +2 -2
- package/dist/{relative-time-BVQXLuHm.js → relative-time-BNxqvEbg.js} +13 -2
- package/dist/relative-time-BNxqvEbg.js.map +1 -0
- package/dist/relative-time.js +3 -3
- package/dist/resizable-panels.js +2 -2
- package/dist/{rich-text-input-DLICqof1.js → rich-text-input-N_hqnXej.js} +3 -3
- package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-N_hqnXej.js.map} +1 -1
- package/dist/ripple.js +2 -0
- package/dist/ripple.js.map +1 -1
- package/dist/{schema-hMt-NRLk.js → schema-Dy0z-80u.js} +2 -2
- package/dist/{schema-hMt-NRLk.js.map → schema-Dy0z-80u.js.map} +1 -1
- package/dist/search.js +5 -5
- package/dist/segmented-button-group.js +1 -1
- package/dist/select.js +8 -8
- package/dist/side-sheet.js +2 -2
- package/dist/signature-pad.js +6 -5
- package/dist/signature-pad.js.map +1 -1
- package/dist/slider.js +6 -5
- package/dist/slider.js.map +1 -1
- package/dist/snackbar.js +2 -2
- package/dist/sparkline.js +2 -2
- package/dist/split-button.js +109 -21
- package/dist/split-button.js.map +1 -1
- package/dist/src/__internal/ai/suggestion-controller.d.ts +2 -0
- package/dist/src/__internal/diagram/canvas-base.d.ts +105 -0
- package/dist/src/__internal/diagram/canvas-link.d.ts +21 -0
- package/dist/src/__internal/diagram/geometry.d.ts +49 -0
- package/dist/src/__internal/diagram/history.d.ts +17 -0
- package/dist/src/__internal/diagram/host.d.ts +45 -0
- package/dist/src/__internal/diagram/markers.d.ts +16 -0
- package/dist/src/__internal/diagram/measure-controller.d.ts +32 -0
- package/dist/src/__internal/diagram/motion.d.ts +22 -0
- package/dist/src/__internal/diagram/selection.d.ts +20 -0
- package/dist/src/__internal/diagram/types.d.ts +39 -0
- package/dist/src/__internal/diagram/viewport-controller.d.ts +89 -0
- package/dist/src/__internal/i18n/strings.d.ts +155 -0
- package/dist/src/__internal/menu-trigger-controller.d.ts +11 -8
- package/dist/src/__internal/toggle-base.d.ts +8 -0
- package/dist/src/__internal/utils/deprecate.d.ts +3 -3
- package/dist/src/__internal/utils/relative-time.d.ts +5 -0
- package/dist/src/accordion/accordion.d.ts +1 -0
- package/dist/src/ai-badge/ai-badge.d.ts +8 -0
- package/dist/src/button/button/button.d.ts +4 -0
- package/dist/src/chat-message/chat-message.d.ts +51 -10
- package/dist/src/chat-message/index.d.ts +1 -1
- package/dist/src/chat-thread/chat-event.d.ts +37 -0
- package/dist/src/chat-thread/chat-thread.d.ts +7 -4
- package/dist/src/chat-thread/index.d.ts +1 -0
- package/dist/src/code-editor/code-editor.d.ts +1 -0
- package/dist/src/date-picker/date-picker.d.ts +2 -0
- package/dist/src/dependency-map/dependency-map-layout.d.ts +48 -0
- package/dist/src/dependency-map/dependency-map.d.ts +241 -0
- package/dist/src/dependency-map/index.d.ts +2 -0
- package/dist/src/diagram/diagram.d.ts +300 -0
- package/dist/src/diagram/flow.d.ts +53 -0
- package/dist/src/diagram/index.d.ts +4 -0
- package/dist/src/diagram-controls/diagram-controls.d.ts +46 -0
- package/dist/src/diagram-controls/index.d.ts +1 -0
- package/dist/src/diagram-minimap/diagram-minimap.d.ts +39 -0
- package/dist/src/diagram-minimap/index.d.ts +1 -0
- package/dist/src/erd/erd-layout.d.ts +27 -0
- package/dist/src/erd/erd.d.ts +266 -0
- package/dist/src/erd/index.d.ts +2 -0
- package/dist/src/field/field.d.ts +38 -1
- package/dist/src/file-upload/file-upload.d.ts +3 -1
- package/dist/src/focus-ring/focus-ring.d.ts +2 -0
- package/dist/src/index.d.ts +17 -4
- package/dist/src/input/BaseField.d.ts +15 -1
- package/dist/src/input/BaseInput.d.ts +4 -0
- package/dist/src/menu/menu-item/menu-item.d.ts +1 -0
- package/dist/src/number-field/number-field.d.ts +4 -0
- package/dist/src/progress/base-progress.d.ts +3 -0
- package/dist/src/radio/radio-group.d.ts +1 -0
- package/dist/src/rating/rating.d.ts +1 -0
- package/dist/src/ripple/ripple.d.ts +2 -0
- package/dist/src/signature-pad/signature-pad.d.ts +1 -0
- package/dist/src/slider/slider.d.ts +1 -0
- package/dist/src/split-button/split-button.d.ts +7 -2
- package/dist/src/switch/switch.d.ts +1 -0
- package/dist/src/tabs/tab.d.ts +2 -0
- package/dist/src/tabs/tabs.d.ts +1 -0
- package/dist/src/textarea/textarea.d.ts +3 -0
- package/dist/src/time-picker/time-picker.d.ts +2 -0
- package/dist/src/transfer-list/transfer-list.d.ts +1 -0
- package/dist/src/tree-chart/index.d.ts +2 -0
- package/dist/src/tree-chart/tree-chart-layout.d.ts +49 -0
- package/dist/src/tree-chart/tree-chart.d.ts +221 -0
- package/dist/src/workflow/index.d.ts +2 -0
- package/dist/src/workflow/workflow-format.d.ts +5 -0
- package/dist/src/workflow/workflow-model.d.ts +194 -0
- package/dist/src/workflow/workflow.d.ts +313 -0
- package/dist/src/workflow-timeline/index.d.ts +1 -0
- package/dist/src/workflow-timeline/workflow-timeline.d.ts +41 -0
- package/dist/stat.js +2 -2
- package/dist/status-indicator.js +2 -2
- package/dist/step.js +2 -2
- package/dist/stepper.js +2 -2
- package/dist/{strings-DmbqMTfs.js → strings-DnYjGbbc.js} +169 -1
- package/dist/{strings-DmbqMTfs.js.map → strings-DnYjGbbc.js.map} +1 -1
- package/dist/sub-menu.js +2 -2
- package/dist/{suggestion-controller-CW17adxd.js → suggestion-controller-7YRQqkaI.js} +3 -1
- package/dist/{suggestion-controller-CW17adxd.js.map → suggestion-controller-7YRQqkaI.js.map} +1 -1
- package/dist/svg.js +2 -2
- package/dist/switch.js +6 -5
- package/dist/switch.js.map +1 -1
- package/dist/tab.js +1 -0
- package/dist/tab.js.map +1 -1
- package/dist/table.js +50 -11
- package/dist/table.js.map +1 -1
- package/dist/tabs.js +1 -0
- package/dist/tabs.js.map +1 -1
- package/dist/test/diagram-controls.test.d.ts +1 -0
- package/dist/test/diagram-geometry.test.d.ts +1 -0
- package/dist/test/diagram.test.d.ts +1 -0
- package/dist/test/erd.test.d.ts +1 -0
- package/dist/test/toggle-label.test.d.ts +1 -0
- package/dist/test/tree-chart.test.d.ts +1 -0
- package/dist/test/workflow-debug.test.d.ts +1 -0
- package/dist/test/workflow.test.d.ts +1 -0
- package/dist/textarea.js +13 -6
- package/dist/textarea.js.map +1 -1
- package/dist/time-field.js +7 -7
- package/dist/time-picker.js +4 -2
- package/dist/time-picker.js.map +1 -1
- package/dist/timeline-item.js +2 -2
- package/dist/timeline.js +2 -2
- package/dist/{toggle-base-BQO5pjrU.js → toggle-base-CXmFSp3b.js} +19 -3
- package/dist/toggle-base-CXmFSp3b.js.map +1 -0
- package/dist/tour.js +2 -2
- package/dist/transfer-list.js +6 -5
- package/dist/transfer-list.js.map +1 -1
- package/dist/{chart-base-B-gOg2Di.js → transform-CxeQFXXB.js} +9 -839
- package/dist/transform-CxeQFXXB.js.map +1 -0
- package/dist/tree-chart.js +1986 -0
- package/dist/tree-chart.js.map +1 -0
- package/dist/tree-item.js +2 -2
- package/dist/tree.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/typing-indicator.js +2 -2
- package/dist/url-field.js +6 -6
- package/dist/user-menu.js +3 -3
- package/dist/virtual-list.js +2 -2
- package/dist/workflow-format-BsyveyeC.js +34 -0
- package/dist/workflow-format-BsyveyeC.js.map +1 -0
- package/dist/workflow-model-CauduOG2.js +330 -0
- package/dist/workflow-model-CauduOG2.js.map +1 -0
- package/dist/workflow-timeline.js +354 -0
- package/dist/workflow-timeline.js.map +1 -0
- package/dist/workflow.js +3337 -0
- package/dist/workflow.js.map +1 -0
- package/dist/workspace-switcher.js +3 -3
- package/package.json +1 -1
- package/readme.md +44 -2
- package/src/LoaderUtils.ts +9 -2
- package/src/__internal/ai/suggestion-controller.ts +3 -1
- package/src/__internal/diagram/canvas-base.ts +410 -0
- package/src/__internal/diagram/canvas-link.ts +66 -0
- package/src/__internal/diagram/geometry.ts +372 -0
- package/src/__internal/diagram/history.ts +49 -0
- package/src/__internal/diagram/host.ts +76 -0
- package/src/__internal/diagram/markers.ts +56 -0
- package/src/__internal/diagram/measure-controller.ts +104 -0
- package/src/__internal/diagram/motion.ts +89 -0
- package/src/__internal/diagram/selection.ts +69 -0
- package/src/__internal/diagram/types.ts +56 -0
- package/src/__internal/diagram/viewport-controller.ts +494 -0
- package/src/__internal/i18n/strings.ts +207 -0
- package/src/__internal/menu-trigger-controller.ts +11 -15
- package/src/__internal/mixins/field.ts +3 -0
- package/src/__internal/mixins/form-associated.ts +2 -0
- package/src/__internal/mixins/form-submitter.ts +6 -0
- package/src/__internal/mixins/hyperlink.ts +10 -0
- package/src/__internal/toggle-base.ts +16 -0
- package/src/__internal/utils/deprecate.ts +5 -4
- package/src/__internal/utils/relative-time.ts +20 -0
- package/src/accordion/accordion.ts +1 -0
- package/src/ai-badge/ai-badge.scss +8 -0
- package/src/ai-badge/ai-badge.ts +21 -4
- package/src/button/base-button/base-button.ts +2 -0
- package/src/button/button/button-base.scss +9 -2
- package/src/button/button/button-layers.scss +3 -1
- package/src/button/button/button.ts +4 -0
- package/src/chat-message/chat-message.scss +72 -0
- package/src/chat-message/chat-message.ts +137 -18
- package/src/chat-message/index.ts +1 -0
- package/src/chat-thread/chat-event.scss +36 -0
- package/src/chat-thread/chat-event.ts +79 -0
- package/src/chat-thread/chat-thread.scss +4 -1
- package/src/chat-thread/chat-thread.ts +22 -6
- package/src/chat-thread/index.ts +1 -0
- package/src/code-editor/code-editor.ts +1 -0
- package/src/date-picker/date-picker.ts +2 -0
- package/src/dependency-map/dependency-map-layout.ts +505 -0
- package/src/dependency-map/dependency-map.scss +626 -0
- package/src/dependency-map/dependency-map.ts +1280 -0
- package/src/dependency-map/index.ts +16 -0
- package/src/diagram/diagram.scss +513 -0
- package/src/diagram/diagram.ts +1852 -0
- package/src/diagram/flow.ts +81 -0
- package/src/diagram/index.ts +44 -0
- package/src/diagram-controls/diagram-controls.scss +68 -0
- package/src/diagram-controls/diagram-controls.ts +255 -0
- package/src/diagram-controls/index.ts +1 -0
- package/src/diagram-minimap/diagram-minimap.scss +41 -0
- package/src/diagram-minimap/diagram-minimap.ts +149 -0
- package/src/diagram-minimap/index.ts +1 -0
- package/src/draft-card/draft-card.scss +16 -2
- package/src/dropdown-button/dropdown-button.ts +2 -1
- package/src/erd/erd-layout.ts +92 -0
- package/src/erd/erd.scss +636 -0
- package/src/erd/erd.ts +1728 -0
- package/src/erd/index.ts +17 -0
- package/src/field/field.scss +197 -23
- package/src/field/field.ts +109 -16
- package/src/file-upload/file-upload.scss +37 -10
- package/src/file-upload/file-upload.ts +3 -1
- package/src/focus-ring/focus-ring.ts +2 -0
- package/src/generative-view/catalog.generated.ts +12 -11
- package/src/index.ts +123 -3
- package/src/input/BaseField.ts +45 -2
- package/src/input/BaseInput.ts +4 -1
- package/src/loader.ts +29 -0
- package/src/mention-input/mention-input.scss +2 -0
- package/src/menu/menu-item/menu-item.ts +1 -0
- package/src/number-field/number-field.ts +4 -0
- package/src/progress/base-progress.ts +3 -0
- package/src/radio/radio-group.ts +1 -0
- package/src/radio/radio.ts +1 -1
- package/src/rating/rating.ts +1 -0
- package/src/ripple/ripple.ts +2 -0
- package/src/signature-pad/signature-pad.ts +1 -0
- package/src/slider/slider.ts +1 -0
- package/src/split-button/split-button-colors.scss +9 -0
- package/src/split-button/split-button-sizes.scss +32 -5
- package/src/split-button/split-button.scss +61 -8
- package/src/split-button/split-button.ts +15 -8
- package/src/switch/switch.ts +1 -0
- package/src/table/table.scss +57 -9
- package/src/table/table.ts +3 -1
- package/src/tabs/tab.ts +2 -0
- package/src/tabs/tabs.ts +1 -0
- package/src/textarea/textarea.scss +2 -0
- package/src/textarea/textarea.ts +8 -0
- package/src/time-picker/time-picker.ts +2 -0
- package/src/transfer-list/transfer-list.ts +1 -0
- package/src/tree-chart/index.ts +13 -0
- package/src/tree-chart/tree-chart-layout.ts +185 -0
- package/src/tree-chart/tree-chart.scss +377 -0
- package/src/tree-chart/tree-chart.ts +1170 -0
- package/src/workflow/index.ts +35 -0
- package/src/workflow/workflow-format.ts +29 -0
- package/src/workflow/workflow-model.ts +583 -0
- package/src/workflow/workflow.scss +1164 -0
- package/src/workflow/workflow.ts +2674 -0
- package/src/workflow-timeline/index.ts +1 -0
- package/src/workflow-timeline/workflow-timeline.scss +128 -0
- package/src/workflow-timeline/workflow-timeline.ts +238 -0
- package/dist/BaseField-CAog9TIc.js.map +0 -1
- package/dist/BaseInput-CcMfg1Y2.js.map +0 -1
- package/dist/base-button-Do2TUy8M.js.map +0 -1
- package/dist/base-progress-BiLlZVHJ.js.map +0 -1
- package/dist/cartesian-chart-C-f1frt0.js.map +0 -1
- package/dist/chart-base-B-gOg2Di.js.map +0 -1
- package/dist/generative-view-DmtpDobn.js.map +0 -1
- package/dist/hyperlink-DhE9RlVS.js.map +0 -1
- package/dist/menu-trigger-controller-DyLpTxM7.js.map +0 -1
- package/dist/relative-time-BVQXLuHm.js.map +0 -1
- package/dist/src/flow/flow.d.ts +0 -178
- package/dist/src/flow/index.d.ts +0 -2
- package/dist/toggle-base-BQO5pjrU.js.map +0 -1
- package/src/button/button-group/readme.md +0 -23
- package/src/flow/flow.scss +0 -215
- package/src/flow/flow.ts +0 -958
- package/src/flow/index.ts +0 -10
- /package/dist/test/{flow.test.d.ts → dependency-map.test.d.ts} +0 -0
|
@@ -0,0 +1,2029 @@
|
|
|
1
|
+
import { i, _ as __decorate, I as IndividualComponent, A, b, w } from './IndividualComponent-BK7XZjE2.js';
|
|
2
|
+
import { n } from './property-B2TG3KEE.js';
|
|
3
|
+
import { r } from './state-BCeDVCI9.js';
|
|
4
|
+
import { e } from './query-CHb9Ft_d.js';
|
|
5
|
+
import { e as e$1 } from './class-map-NDIkZErE.js';
|
|
6
|
+
import { c } from './repeat-D_ERDRYT.js';
|
|
7
|
+
import { D as DiagramCanvasElement, p as prefersReducedMotion, a as animateOut, t as tween, b as easeOutCubic } from './canvas-base-CWQ4rQ2s.js';
|
|
8
|
+
import { M as MeasureController } from './measure-controller-Dmc5hZKg.js';
|
|
9
|
+
import { c as rectFromPoints, a as rectsIntersect, b as boundsOf, d as anchorOnRect, e as edgeGeometry, n as nearestInDirection, i as inflateRect, O as OPPOSITE_SIDE } from './geometry-INg82Lxq.js';
|
|
10
|
+
import { m as markerShapes, a as markerTransform, b as markerInset } from './markers-BFmh1OCz.js';
|
|
11
|
+
import { H as History } from './history-YbTSQZHj.js';
|
|
12
|
+
|
|
13
|
+
const warned = new Set();
|
|
14
|
+
/**
|
|
15
|
+
* Logs a deprecation warning once per page for each distinct message.
|
|
16
|
+
*
|
|
17
|
+
* Renamed or removed APIs keep working until the next major version and call this so consumers
|
|
18
|
+
* see what to migrate (ADR-030001). Pass the component tag, the old API and its replacement.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* deprecate('wc-example', '`old-name`', '`new-name`');
|
|
22
|
+
*/
|
|
23
|
+
function deprecate(tag, oldApi, replacement, removedIn = '5.0') {
|
|
24
|
+
const message = replacement
|
|
25
|
+
? `[peacock] ${tag}: ${oldApi} is deprecated and will be removed in ${removedIn}. Use ${replacement} instead.`
|
|
26
|
+
: `[peacock] ${tag}: ${oldApi} is deprecated and will be removed in ${removedIn}.`;
|
|
27
|
+
if (warned.has(message))
|
|
28
|
+
return;
|
|
29
|
+
warned.add(message);
|
|
30
|
+
// eslint-disable-next-line no-console
|
|
31
|
+
console.warn(message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A set of selected nodes and edges, kept apart by kind so ids may repeat across kinds. */
|
|
35
|
+
class DiagramSelection {
|
|
36
|
+
constructor(onChange = () => undefined) {
|
|
37
|
+
this.keys = new Set();
|
|
38
|
+
this.onChange = onChange;
|
|
39
|
+
}
|
|
40
|
+
static key(kind, id) {
|
|
41
|
+
return `${kind}:${id}`;
|
|
42
|
+
}
|
|
43
|
+
get size() {
|
|
44
|
+
return this.keys.size;
|
|
45
|
+
}
|
|
46
|
+
has(kind, id) {
|
|
47
|
+
return this.keys.has(DiagramSelection.key(kind, id));
|
|
48
|
+
}
|
|
49
|
+
ids(kind) {
|
|
50
|
+
const prefix = `${kind}:`;
|
|
51
|
+
return [...this.keys]
|
|
52
|
+
.filter(k => k.startsWith(prefix))
|
|
53
|
+
.map(k => k.slice(prefix.length));
|
|
54
|
+
}
|
|
55
|
+
/** Replaces the selection. */
|
|
56
|
+
set(items) {
|
|
57
|
+
const next = new Set(items.map(i => DiagramSelection.key(i.kind, i.id)));
|
|
58
|
+
if (next.size === this.keys.size &&
|
|
59
|
+
[...next].every(k => this.keys.has(k))) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.keys = next;
|
|
63
|
+
this.onChange();
|
|
64
|
+
}
|
|
65
|
+
toggle(kind, id) {
|
|
66
|
+
const key = DiagramSelection.key(kind, id);
|
|
67
|
+
if (this.keys.has(key))
|
|
68
|
+
this.keys.delete(key);
|
|
69
|
+
else
|
|
70
|
+
this.keys.add(key);
|
|
71
|
+
this.onChange();
|
|
72
|
+
}
|
|
73
|
+
/** Drops ids that no longer exist. */
|
|
74
|
+
retain(kind, existing) {
|
|
75
|
+
let changed = false;
|
|
76
|
+
for (const id of this.ids(kind)) {
|
|
77
|
+
if (!existing.has(id)) {
|
|
78
|
+
this.keys.delete(DiagramSelection.key(kind, id));
|
|
79
|
+
changed = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (changed)
|
|
83
|
+
this.onChange();
|
|
84
|
+
}
|
|
85
|
+
clear() {
|
|
86
|
+
if (this.keys.size === 0)
|
|
87
|
+
return;
|
|
88
|
+
this.keys.clear();
|
|
89
|
+
this.onChange();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var css_248z = i`* {
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
-webkit-tap-highlight-color: transparent;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.screen-reader-only {
|
|
99
|
+
position: absolute !important;
|
|
100
|
+
inline-size: 1px !important;
|
|
101
|
+
block-size: 1px !important;
|
|
102
|
+
padding: 0 !important;
|
|
103
|
+
margin: -1px !important;
|
|
104
|
+
overflow: hidden !important;
|
|
105
|
+
clip-path: inset(50%) !important;
|
|
106
|
+
white-space: nowrap !important;
|
|
107
|
+
border: 0 !important;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
[hidden] {
|
|
111
|
+
display: none !important;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@media (forced-colors: active) {
|
|
115
|
+
.selected,
|
|
116
|
+
[aria-selected=true],
|
|
117
|
+
[aria-pressed=true],
|
|
118
|
+
[aria-checked=true],
|
|
119
|
+
[aria-current]:not([aria-current=false]) {
|
|
120
|
+
outline: 2px solid Highlight;
|
|
121
|
+
outline-offset: -2px;
|
|
122
|
+
}
|
|
123
|
+
.disabled,
|
|
124
|
+
[aria-disabled=true] {
|
|
125
|
+
color: GrayText;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
:host {
|
|
129
|
+
display: block;
|
|
130
|
+
position: relative;
|
|
131
|
+
inline-size: 100%;
|
|
132
|
+
block-size: 100%;
|
|
133
|
+
min-block-size: 200px;
|
|
134
|
+
overflow: hidden;
|
|
135
|
+
--diagram-background: var(
|
|
136
|
+
--flow-background,
|
|
137
|
+
var(--color-surface-container-lowest, #fbfbfd)
|
|
138
|
+
);
|
|
139
|
+
--diagram-dot-color: var(
|
|
140
|
+
--flow-dot-color,
|
|
141
|
+
var(--color-outline-variant, #c5c6cb)
|
|
142
|
+
);
|
|
143
|
+
--diagram-line-color: var(
|
|
144
|
+
--flow-line-color,
|
|
145
|
+
color-mix(
|
|
146
|
+
in srgb,
|
|
147
|
+
var(--color-primary, #005faf) 45%,
|
|
148
|
+
var(--color-outline-variant, #c5c6cb)
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
--diagram-hover-color: var(--flow-hover-color, var(--color-primary, #005faf));
|
|
152
|
+
--diagram-port-size: var(--flow-port-size, 10px);
|
|
153
|
+
--diagram-node-background: var(
|
|
154
|
+
--flow-node-background,
|
|
155
|
+
var(--color-surface-container-lowest, #fff)
|
|
156
|
+
);
|
|
157
|
+
--diagram-node-border: var(
|
|
158
|
+
--flow-node-border,
|
|
159
|
+
var(--color-outline-variant, #c5c6cb)
|
|
160
|
+
);
|
|
161
|
+
--diagram-node-shadow: var(--flow-node-shadow, var(--elevation-level1));
|
|
162
|
+
--diagram-node-active-shadow: var(
|
|
163
|
+
--flow-node-active-shadow,
|
|
164
|
+
var(--elevation-level3)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Canvas coordinates are physical x/y and do not mirror in right-to-left layouts. */
|
|
169
|
+
/* stylelint-disable property-disallowed-list */
|
|
170
|
+
.diagram-viewport {
|
|
171
|
+
position: absolute;
|
|
172
|
+
inset: 0;
|
|
173
|
+
overflow: hidden;
|
|
174
|
+
background-color: var(--diagram-background);
|
|
175
|
+
background-image: radial-gradient(var(--diagram-dot-color) 1px, transparent 1.2px);
|
|
176
|
+
border: 1px solid var(--color-outline-variant);
|
|
177
|
+
border-radius: var(--shape-corner-large);
|
|
178
|
+
cursor: default;
|
|
179
|
+
touch-action: none;
|
|
180
|
+
outline: none;
|
|
181
|
+
container-type: inline-size;
|
|
182
|
+
container-name: diagram;
|
|
183
|
+
}
|
|
184
|
+
.diagram-viewport:focus-visible {
|
|
185
|
+
box-shadow: inset 0 0 0 2px var(--color-primary);
|
|
186
|
+
}
|
|
187
|
+
.diagram-viewport.is-space, .diagram-viewport.is-space .diagram-node {
|
|
188
|
+
cursor: grab;
|
|
189
|
+
}
|
|
190
|
+
.diagram-viewport.is-panning, .diagram-viewport.is-panning .diagram-node {
|
|
191
|
+
cursor: grabbing;
|
|
192
|
+
}
|
|
193
|
+
.diagram-viewport.is-connecting {
|
|
194
|
+
cursor: crosshair;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.diagram-world {
|
|
198
|
+
position: absolute;
|
|
199
|
+
left: 0;
|
|
200
|
+
top: 0;
|
|
201
|
+
transform-origin: 0 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.diagram-svg {
|
|
205
|
+
position: absolute;
|
|
206
|
+
left: 0;
|
|
207
|
+
top: 0;
|
|
208
|
+
overflow: visible;
|
|
209
|
+
pointer-events: none;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.diagram-edge-group {
|
|
213
|
+
pointer-events: auto;
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
outline: none;
|
|
216
|
+
color: var(--_edge-color, var(--diagram-line-color));
|
|
217
|
+
}
|
|
218
|
+
.diagram-edge-group:hover, .diagram-edge-group.is-selected, .diagram-edge-group:focus-visible {
|
|
219
|
+
color: var(--_edge-color, var(--diagram-hover-color));
|
|
220
|
+
}
|
|
221
|
+
.diagram-edge-group.is-colored:hover .diagram-edge, .diagram-edge-group.is-selected .diagram-edge, .diagram-edge-group:focus-visible .diagram-edge {
|
|
222
|
+
stroke-width: 3.5;
|
|
223
|
+
}
|
|
224
|
+
.diagram-edge-group:hover .diagram-edge {
|
|
225
|
+
stroke-width: 3;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.diagram-edge-hit {
|
|
229
|
+
fill: none;
|
|
230
|
+
stroke: transparent;
|
|
231
|
+
stroke-width: 16;
|
|
232
|
+
pointer-events: stroke;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.diagram-edge {
|
|
236
|
+
fill: none;
|
|
237
|
+
stroke: currentcolor;
|
|
238
|
+
stroke-width: 2;
|
|
239
|
+
stroke-linecap: round;
|
|
240
|
+
stroke-linejoin: round;
|
|
241
|
+
pointer-events: none;
|
|
242
|
+
transition: stroke-width 150ms ease;
|
|
243
|
+
}
|
|
244
|
+
.diagram-edge.variant-dashed {
|
|
245
|
+
stroke-dasharray: 6 6;
|
|
246
|
+
}
|
|
247
|
+
.diagram-edge.variant-animated-dashed {
|
|
248
|
+
stroke-dasharray: 6 6;
|
|
249
|
+
animation: diagram-dash 1s linear infinite;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.diagram-marker {
|
|
253
|
+
stroke: currentcolor;
|
|
254
|
+
stroke-width: 2;
|
|
255
|
+
stroke-linecap: round;
|
|
256
|
+
stroke-linejoin: round;
|
|
257
|
+
pointer-events: none;
|
|
258
|
+
}
|
|
259
|
+
.diagram-marker.fill-solid {
|
|
260
|
+
fill: currentcolor;
|
|
261
|
+
}
|
|
262
|
+
.diagram-marker.fill-surface {
|
|
263
|
+
fill: var(--diagram-background);
|
|
264
|
+
}
|
|
265
|
+
.diagram-marker.fill-none {
|
|
266
|
+
fill: none;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.diagram-edge-preview {
|
|
270
|
+
fill: none;
|
|
271
|
+
stroke: var(--diagram-hover-color);
|
|
272
|
+
stroke-width: 2;
|
|
273
|
+
stroke-dasharray: 6 6;
|
|
274
|
+
stroke-linecap: round;
|
|
275
|
+
animation: diagram-dash 1s linear infinite;
|
|
276
|
+
}
|
|
277
|
+
.diagram-edge-preview.is-snapped {
|
|
278
|
+
stroke-dasharray: none;
|
|
279
|
+
animation: none;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.diagram-guide {
|
|
283
|
+
stroke: var(--color-error, #ba1a1a);
|
|
284
|
+
stroke-width: 1;
|
|
285
|
+
stroke-dasharray: 4 3;
|
|
286
|
+
vector-effect: non-scaling-stroke;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.diagram-edge-label {
|
|
290
|
+
position: absolute;
|
|
291
|
+
transform: translate(-50%, -50%);
|
|
292
|
+
padding: 2px 10px;
|
|
293
|
+
white-space: nowrap;
|
|
294
|
+
font-size: 12px;
|
|
295
|
+
font-weight: 500;
|
|
296
|
+
line-height: 18px;
|
|
297
|
+
color: var(--color-on-surface-variant);
|
|
298
|
+
background: var(--diagram-node-background);
|
|
299
|
+
border: 1px solid var(--color-outline-variant);
|
|
300
|
+
border-radius: var(--shape-corner-full);
|
|
301
|
+
cursor: pointer;
|
|
302
|
+
z-index: 4;
|
|
303
|
+
}
|
|
304
|
+
.diagram-edge-label.is-selected {
|
|
305
|
+
color: var(--diagram-hover-color);
|
|
306
|
+
border-color: var(--diagram-hover-color);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.edge-end {
|
|
310
|
+
position: absolute;
|
|
311
|
+
inline-size: 14px;
|
|
312
|
+
block-size: 14px;
|
|
313
|
+
margin: -7px 0 0 -7px;
|
|
314
|
+
border-radius: 50%;
|
|
315
|
+
background: var(--diagram-hover-color);
|
|
316
|
+
box-shadow: 0 0 0 3px var(--diagram-background);
|
|
317
|
+
cursor: grab;
|
|
318
|
+
z-index: 12;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.diagram-nodes {
|
|
322
|
+
pointer-events: none;
|
|
323
|
+
}
|
|
324
|
+
.diagram-nodes > * {
|
|
325
|
+
pointer-events: auto;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.diagram-node {
|
|
329
|
+
position: absolute;
|
|
330
|
+
display: inline-flex;
|
|
331
|
+
align-items: center;
|
|
332
|
+
justify-content: center;
|
|
333
|
+
background: var(--diagram-node-background);
|
|
334
|
+
border: 1px solid var(--diagram-node-border);
|
|
335
|
+
box-shadow: var(--diagram-node-shadow);
|
|
336
|
+
border-radius: var(--shape-corner-large);
|
|
337
|
+
min-inline-size: 150px;
|
|
338
|
+
min-block-size: 64px;
|
|
339
|
+
cursor: grab;
|
|
340
|
+
user-select: none;
|
|
341
|
+
touch-action: none;
|
|
342
|
+
z-index: 5;
|
|
343
|
+
transition: box-shadow 150ms ease, border-color 150ms ease;
|
|
344
|
+
}
|
|
345
|
+
.diagram-node.is-dragging {
|
|
346
|
+
cursor: grabbing;
|
|
347
|
+
box-shadow: var(--diagram-node-active-shadow);
|
|
348
|
+
border-color: var(--diagram-hover-color);
|
|
349
|
+
z-index: 6;
|
|
350
|
+
}
|
|
351
|
+
.diagram-node.is-selected {
|
|
352
|
+
border-color: var(--diagram-hover-color);
|
|
353
|
+
box-shadow: 0 0 0 2px var(--diagram-hover-color), var(--diagram-node-shadow);
|
|
354
|
+
}
|
|
355
|
+
.diagram-node.is-locked {
|
|
356
|
+
cursor: default;
|
|
357
|
+
}
|
|
358
|
+
.diagram-node:focus-visible {
|
|
359
|
+
outline: 2px solid var(--color-primary);
|
|
360
|
+
outline-offset: 3px;
|
|
361
|
+
}
|
|
362
|
+
.diagram-node.intent-danger {
|
|
363
|
+
border-color: var(--color-error);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.diagram-node-content {
|
|
367
|
+
inline-size: 100%;
|
|
368
|
+
block-size: 100%;
|
|
369
|
+
padding: 12px 16px;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
.diagram-node-default-card {
|
|
373
|
+
display: flex;
|
|
374
|
+
align-items: center;
|
|
375
|
+
gap: 12px;
|
|
376
|
+
inline-size: 100%;
|
|
377
|
+
block-size: 100%;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.diagram-node-icon {
|
|
381
|
+
display: inline-flex;
|
|
382
|
+
align-items: center;
|
|
383
|
+
justify-content: center;
|
|
384
|
+
flex: none;
|
|
385
|
+
inline-size: 40px;
|
|
386
|
+
block-size: 40px;
|
|
387
|
+
border-radius: var(--shape-corner-medium);
|
|
388
|
+
background: var(--color-primary-container);
|
|
389
|
+
--icon-color: var(--color-on-primary-container);
|
|
390
|
+
--icon-size: 1.25rem;
|
|
391
|
+
}
|
|
392
|
+
.intent-info .diagram-node-icon {
|
|
393
|
+
background: var(--color-blue-container);
|
|
394
|
+
--icon-color: var(--color-on-blue-container);
|
|
395
|
+
}
|
|
396
|
+
.intent-success .diagram-node-icon {
|
|
397
|
+
background: var(--color-green-container);
|
|
398
|
+
--icon-color: var(--color-on-green-container);
|
|
399
|
+
}
|
|
400
|
+
.intent-warning .diagram-node-icon {
|
|
401
|
+
background: var(--color-yellow-container);
|
|
402
|
+
--icon-color: var(--color-on-yellow-container);
|
|
403
|
+
}
|
|
404
|
+
.intent-danger .diagram-node-icon {
|
|
405
|
+
background: var(--color-error-container);
|
|
406
|
+
--icon-color: var(--color-on-error-container);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
.diagram-node-text {
|
|
410
|
+
display: flex;
|
|
411
|
+
flex-direction: column;
|
|
412
|
+
min-inline-size: 0;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
.diagram-node-title {
|
|
416
|
+
font-family: inherit;
|
|
417
|
+
font-size: 14px;
|
|
418
|
+
font-weight: 500;
|
|
419
|
+
color: var(--color-on-surface);
|
|
420
|
+
white-space: nowrap;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.diagram-node-supporting {
|
|
424
|
+
font-size: 12px;
|
|
425
|
+
color: var(--color-on-surface-variant);
|
|
426
|
+
white-space: nowrap;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
.diagram-node-custom {
|
|
430
|
+
background: transparent;
|
|
431
|
+
border-color: transparent;
|
|
432
|
+
box-shadow: none;
|
|
433
|
+
min-inline-size: 0;
|
|
434
|
+
min-block-size: 0;
|
|
435
|
+
}
|
|
436
|
+
.diagram-node-custom.is-selected {
|
|
437
|
+
box-shadow: 0 0 0 2px var(--diagram-hover-color);
|
|
438
|
+
}
|
|
439
|
+
.diagram-node-custom .diagram-node-content {
|
|
440
|
+
padding: 0;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.handle {
|
|
444
|
+
position: absolute;
|
|
445
|
+
inline-size: var(--diagram-port-size);
|
|
446
|
+
block-size: var(--diagram-port-size);
|
|
447
|
+
border-radius: 50%;
|
|
448
|
+
background: var(--diagram-node-background);
|
|
449
|
+
border: 2px solid var(--diagram-line-color);
|
|
450
|
+
z-index: 10;
|
|
451
|
+
cursor: crosshair;
|
|
452
|
+
touch-action: none;
|
|
453
|
+
transition: transform 150ms cubic-bezier(0.2, 0, 0, 1), background-color 150ms ease, border-color 150ms ease;
|
|
454
|
+
}
|
|
455
|
+
.handle::after {
|
|
456
|
+
content: "";
|
|
457
|
+
position: absolute;
|
|
458
|
+
inset: -8px;
|
|
459
|
+
border-radius: 50%;
|
|
460
|
+
}
|
|
461
|
+
.handle:hover, .handle.is-snap {
|
|
462
|
+
transform: scale(1.5);
|
|
463
|
+
background-color: var(--diagram-hover-color);
|
|
464
|
+
border-color: var(--diagram-hover-color);
|
|
465
|
+
}
|
|
466
|
+
.handle.is-candidate {
|
|
467
|
+
border-color: var(--diagram-hover-color);
|
|
468
|
+
}
|
|
469
|
+
.handle.is-ripple {
|
|
470
|
+
animation: diagram-ripple 500ms ease-out;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.handle-position-left {
|
|
474
|
+
left: calc(var(--diagram-port-size) / -2 - 1px);
|
|
475
|
+
top: calc(var(--_offset, 50%) - var(--diagram-port-size) / 2);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
.handle-position-right {
|
|
479
|
+
right: calc(var(--diagram-port-size) / -2 - 1px);
|
|
480
|
+
top: calc(var(--_offset, 50%) - var(--diagram-port-size) / 2);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
.handle-position-top {
|
|
484
|
+
top: calc(var(--diagram-port-size) / -2 - 1px);
|
|
485
|
+
left: calc(var(--_offset, 50%) - var(--diagram-port-size) / 2);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
.handle-position-bottom {
|
|
489
|
+
bottom: calc(var(--diagram-port-size) / -2 - 1px);
|
|
490
|
+
left: calc(var(--_offset, 50%) - var(--diagram-port-size) / 2);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
.diagram-marquee {
|
|
494
|
+
position: absolute;
|
|
495
|
+
border: 1px solid var(--diagram-hover-color);
|
|
496
|
+
background: color-mix(in srgb, var(--diagram-hover-color) 10%, transparent);
|
|
497
|
+
border-radius: var(--shape-corner-extra-small);
|
|
498
|
+
pointer-events: none;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.back-to-content {
|
|
502
|
+
position: absolute;
|
|
503
|
+
left: 50%;
|
|
504
|
+
bottom: 24px;
|
|
505
|
+
transform: translateX(-50%);
|
|
506
|
+
box-shadow: var(--elevation-level2);
|
|
507
|
+
border-radius: var(--shape-corner-full);
|
|
508
|
+
z-index: 20;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
.slot-controls,
|
|
512
|
+
.slot-minimap {
|
|
513
|
+
position: absolute;
|
|
514
|
+
bottom: 16px;
|
|
515
|
+
z-index: 20;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.slot-controls {
|
|
519
|
+
left: 16px;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.slot-minimap {
|
|
523
|
+
right: 16px;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
@container diagram (max-width: 480px) {
|
|
527
|
+
.slot-minimap {
|
|
528
|
+
display: none;
|
|
529
|
+
}
|
|
530
|
+
.slot-controls {
|
|
531
|
+
left: 8px;
|
|
532
|
+
bottom: 8px;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/* stylelint-enable property-disallowed-list */
|
|
536
|
+
.sr-only {
|
|
537
|
+
position: absolute;
|
|
538
|
+
inline-size: 1px;
|
|
539
|
+
block-size: 1px;
|
|
540
|
+
padding: 0;
|
|
541
|
+
margin: -1px;
|
|
542
|
+
overflow: hidden;
|
|
543
|
+
clip-path: inset(50%);
|
|
544
|
+
white-space: nowrap;
|
|
545
|
+
border: 0;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
@keyframes diagram-dash {
|
|
549
|
+
to {
|
|
550
|
+
stroke-dashoffset: -24;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
@keyframes diagram-ripple {
|
|
554
|
+
0% {
|
|
555
|
+
box-shadow: 0 0 0 0 color-mix(in srgb, var(--diagram-hover-color) 50%, transparent);
|
|
556
|
+
}
|
|
557
|
+
100% {
|
|
558
|
+
box-shadow: 0 0 0 12px transparent;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
@media (prefers-reduced-motion: reduce) {
|
|
562
|
+
.diagram-edge.variant-animated-dashed,
|
|
563
|
+
.diagram-edge-preview,
|
|
564
|
+
.handle.is-ripple {
|
|
565
|
+
animation: none;
|
|
566
|
+
}
|
|
567
|
+
.diagram-node,
|
|
568
|
+
.handle,
|
|
569
|
+
.diagram-edge {
|
|
570
|
+
transition: none;
|
|
571
|
+
}
|
|
572
|
+
}`;
|
|
573
|
+
|
|
574
|
+
/** Canvas pixels an arrow key moves the focused node; matches the dot grid. */
|
|
575
|
+
const KEY_STEP = 20;
|
|
576
|
+
/** Canvas pixels Shift + arrow key moves the focused node. */
|
|
577
|
+
const LARGE_KEY_STEP = 100;
|
|
578
|
+
/** Pointer travel, in screen pixels, before a press on a node becomes a drag. */
|
|
579
|
+
const DRAG_THRESHOLD = 3;
|
|
580
|
+
/** Screen pixels within which a dragged connection snaps to a port. */
|
|
581
|
+
const SNAP_DISTANCE = 28;
|
|
582
|
+
/** Screen pixels within which a dragged node snaps to another node's edge or centre. */
|
|
583
|
+
const GUIDE_DISTANCE = 6;
|
|
584
|
+
/** Size assumed for a node before it has been measured. */
|
|
585
|
+
const DEFAULT_SIZE = { width: 150, height: 70 };
|
|
586
|
+
/** Screen pixels rendered beyond the viewport, so panning does not reveal empty space. */
|
|
587
|
+
const CULL_MARGIN = 200;
|
|
588
|
+
/** Elements inside a node that handle their own pointer and keyboard input. */
|
|
589
|
+
const INTERACTIVE = '.handle, button, input, select, textarea, a, [contenteditable], wc-button, wc-icon-button, wc-input, wc-select, wc-checkbox, wc-switch, wc-link';
|
|
590
|
+
/** Shared between diagrams on a page, like the system clipboard. */
|
|
591
|
+
let clipboard;
|
|
592
|
+
/**
|
|
593
|
+
* @label Diagram
|
|
594
|
+
* @tag wc-diagram
|
|
595
|
+
* @rawTag diagram
|
|
596
|
+
* @summary An infinite canvas of nodes and connections that the person pans, zooms and edits, for state machines, process maps and node editors.
|
|
597
|
+
*
|
|
598
|
+
* @overview
|
|
599
|
+
* <p>Set <code>nodes</code> and <code>edges</code> as properties. A node shows a built-in card with
|
|
600
|
+
* <code>headline</code>, <code>supportingText</code> and <code>icon</code>, or your own content in an
|
|
601
|
+
* element with <code>slot="node:<id>"</code>. Nodes connect through <code>ports</code> on their
|
|
602
|
+
* sides; edges are drawn as rounded elbows by default (<code>connector</code>), with an optional label
|
|
603
|
+
* and markers at each end.</p>
|
|
604
|
+
* <p>The canvas is infinite: drag the background, hold Space and drag, use the middle button or a
|
|
605
|
+
* trackpad to pan, and hold Ctrl or Command and scroll, or pinch, to zoom. It opens at
|
|
606
|
+
* <code>start-position</code> (<code>fit</code>, <code>origin</code> or <code>first</code>) or at an exact
|
|
607
|
+
* <code>start-view</code>; Home or <code>home()</code> flies back there, Shift+1 or <code>fit()</code> fits
|
|
608
|
+
* all content, and a "Back to content" button appears when everything is out of view. Read and set
|
|
609
|
+
* the camera with <code>view</code>, and save it from <code>viewport-change</code>. Add
|
|
610
|
+
* <code>wc-diagram-controls</code> and <code>wc-diagram-minimap</code> in the <code>controls</code> and
|
|
611
|
+
* <code>minimap</code> slots.</p>
|
|
612
|
+
* <p>By default nodes can be dragged and connections drawn; the diagram fires <code>node-drag-end</code>
|
|
613
|
+
* and <code>connect</code> and leaves edges to you. <code>editable</code> turns it into a full editor:
|
|
614
|
+
* it adds the edge on <code>connect</code> unless you cancel the event, selects edges, draws a marquee
|
|
615
|
+
* with Shift + drag, moves several nodes at once, snaps to other nodes (and to the grid with
|
|
616
|
+
* <code>snap-to-grid</code>), deletes with Delete, copies and pastes, and undoes with Ctrl+Z. Every
|
|
617
|
+
* committed edit fires <code>change</code>. <code>readonly</code> keeps everything in place.</p>
|
|
618
|
+
* <p>The diagram never mutates the objects you pass: edits assign new <code>nodes</code> and
|
|
619
|
+
* <code>edges</code> arrays. Each node is focusable and named by its headline. Arrow keys move the
|
|
620
|
+
* focused node by 20px (Shift: 100px), Alt + arrow moves focus to the nearest node in that
|
|
621
|
+
* direction, and Enter or Space selects it. Arrow keys follow the canvas axes and are not mirrored in
|
|
622
|
+
* right-to-left layouts.</p>
|
|
623
|
+
* <p>This component was called <code>wc-flow</code> before 4.0. That tag still works as a
|
|
624
|
+
* deprecated alias until 5.0.</p>
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```html
|
|
628
|
+
* <wc-diagram id="my-diagram" style="height: 400px">
|
|
629
|
+
* <wc-diagram-controls slot="controls"></wc-diagram-controls>
|
|
630
|
+
* <wc-diagram-minimap slot="minimap"></wc-diagram-minimap>
|
|
631
|
+
* </wc-diagram>
|
|
632
|
+
* <script>
|
|
633
|
+
* const diagram = document.getElementById('my-diagram');
|
|
634
|
+
* diagram.nodes = [
|
|
635
|
+
* { id: 'new', position: { x: 0, y: 0 }, headline: 'New', icon: 'fiber_new' },
|
|
636
|
+
* { id: 'done', position: { x: 300, y: 0 }, headline: 'Done', icon: 'task_alt' }
|
|
637
|
+
* ];
|
|
638
|
+
* diagram.edges = [{ id: 'e1', source: 'new', target: 'done', label: 'finish' }];
|
|
639
|
+
* </script>
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @slot controls - A `wc-diagram-controls`, shown at the bottom start corner.
|
|
643
|
+
* @slot minimap - A `wc-diagram-minimap`, shown at the bottom end corner.
|
|
644
|
+
* @slot node:<id> - Custom content for the node with that id, in place of the built-in card.
|
|
645
|
+
*
|
|
646
|
+
* @fires {CustomEvent<DiagramNodeMoveDetail>} node-drag - While a node is dragged. Detail contains `{ id, position }`.
|
|
647
|
+
* @fires {CustomEvent<DiagramNodeMoveDetail>} node-drag-end - Once when a drag ends, and after each keyboard move. Detail contains `{ id, position }`.
|
|
648
|
+
* @fires {CustomEvent<DiagramSelectDetail>} select - A node or edge was chosen with a click, Enter or Space. Detail contains `{ id, kind, node, edge }`.
|
|
649
|
+
* @fires {CustomEvent<DiagramConnectDetail>} connect - A connection was dragged onto a port. With `editable`, the diagram adds the edge unless the event is canceled. Detail contains `{ source, target, sourceHandle, targetHandle }`.
|
|
650
|
+
* @fires {CustomEvent<DiagramDeleteDetail>} delete - Before nodes and edges are deleted with `editable`. Cancel it to keep them. Detail contains `{ nodes, edges }` (ids).
|
|
651
|
+
* @fires {CustomEvent<DiagramChangeDetail>} change - After a committed edit. Detail contains `{ nodes, edges, reason }`.
|
|
652
|
+
* @fires {CustomEvent<DiagramViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
|
|
653
|
+
*
|
|
654
|
+
* @cssprop --diagram-background - Canvas background. Defaults to surface-container-lowest.
|
|
655
|
+
* @cssprop --diagram-dot-color - Colour of the grid dots. Defaults to outline-variant.
|
|
656
|
+
* @cssprop --diagram-line-color - Colour of edges at rest. Defaults to a mix of primary and outline-variant.
|
|
657
|
+
* @cssprop --diagram-hover-color - Colour of hovered and selected edges, ports and nodes. Defaults to primary.
|
|
658
|
+
* @cssprop --diagram-port-size - Diameter of a port ring. Defaults to 10px.
|
|
659
|
+
* @cssprop --diagram-node-background - Background of the built-in card.
|
|
660
|
+
* @tags data
|
|
661
|
+
*/
|
|
662
|
+
let Diagram = class Diagram extends DiagramCanvasElement {
|
|
663
|
+
constructor() {
|
|
664
|
+
// ── Static
|
|
665
|
+
super(...arguments);
|
|
666
|
+
// ── Properties
|
|
667
|
+
/** Nodes to draw. Replaced with a new array, never mutated, when the person edits. */
|
|
668
|
+
this.nodes = [];
|
|
669
|
+
/** Connections between node ports. */
|
|
670
|
+
this.edges = [];
|
|
671
|
+
/** Id of the selected node or edge. With several selected, the last one chosen. */
|
|
672
|
+
this.selected = '';
|
|
673
|
+
/** How edges without a `type` are drawn. */
|
|
674
|
+
this.connector = 'elbow';
|
|
675
|
+
/** Snaps dragged nodes to the grid (`grid-size`). */
|
|
676
|
+
this.snapToGrid = false;
|
|
677
|
+
this._guides = [];
|
|
678
|
+
this._draggingIds = [];
|
|
679
|
+
this._announcement = '';
|
|
680
|
+
this._ripple = '';
|
|
681
|
+
this.selection = new DiagramSelection(() => this.requestUpdate());
|
|
682
|
+
this.history = new History();
|
|
683
|
+
this.measure = new MeasureController(this, {
|
|
684
|
+
elements: () => this.nodeElements(),
|
|
685
|
+
fallback: DEFAULT_SIZE,
|
|
686
|
+
});
|
|
687
|
+
this.pasteCount = 0;
|
|
688
|
+
this.focusedId = '';
|
|
689
|
+
this.positionOverrides = new Map();
|
|
690
|
+
/** Key events a node or edge already handled, so the canvas does not act on them again. */
|
|
691
|
+
this.handledKeys = new WeakSet();
|
|
692
|
+
this.connectionFrame = 0;
|
|
693
|
+
this.onNodePointerMove = (event) => {
|
|
694
|
+
const drag = this.nodeDrag;
|
|
695
|
+
if (!drag || event.pointerId !== drag.pointerId || !drag.movable)
|
|
696
|
+
return;
|
|
697
|
+
const { zoom } = this.viewport.view;
|
|
698
|
+
const dx = (event.clientX - drag.startX) / zoom;
|
|
699
|
+
const dy = (event.clientY - drag.startY) / zoom;
|
|
700
|
+
if (!drag.moved && Math.hypot(dx * zoom, dy * zoom) < DRAG_THRESHOLD)
|
|
701
|
+
return;
|
|
702
|
+
if (!drag.moved) {
|
|
703
|
+
drag.moved = true;
|
|
704
|
+
this._draggingIds = drag.ids;
|
|
705
|
+
}
|
|
706
|
+
const origin = drag.origins.get(drag.primary) ?? { x: 0, y: 0 };
|
|
707
|
+
let next = { x: origin.x + dx, y: origin.y + dy };
|
|
708
|
+
if (this.snapToGrid) {
|
|
709
|
+
next = {
|
|
710
|
+
x: Math.round(next.x / this.gridSize) * this.gridSize,
|
|
711
|
+
y: Math.round(next.y / this.gridSize) * this.gridSize,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
const aligned = this.editable
|
|
715
|
+
? this.alignToOthers(drag.primary, next, new Set(drag.ids))
|
|
716
|
+
: { position: next, guides: [] };
|
|
717
|
+
next = aligned.position;
|
|
718
|
+
this._guides = aligned.guides;
|
|
719
|
+
const delta = { x: next.x - origin.x, y: next.y - origin.y };
|
|
720
|
+
const moved = new Map();
|
|
721
|
+
for (const id of drag.ids) {
|
|
722
|
+
const o = drag.origins.get(id);
|
|
723
|
+
if (o)
|
|
724
|
+
moved.set(id, { x: o.x + delta.x, y: o.y + delta.y });
|
|
725
|
+
}
|
|
726
|
+
this.moveNodes(moved);
|
|
727
|
+
this.emit('node-drag', {
|
|
728
|
+
id: drag.primary,
|
|
729
|
+
position: next,
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
this.onNodePointerUp = (event) => {
|
|
733
|
+
if (!this.nodeDrag || event.pointerId !== this.nodeDrag.pointerId)
|
|
734
|
+
return;
|
|
735
|
+
this.endNodeDrag(true);
|
|
736
|
+
};
|
|
737
|
+
this.onViewportKeyDown = (event) => {
|
|
738
|
+
if (event.defaultPrevented || this.handledKeys.has(event))
|
|
739
|
+
return;
|
|
740
|
+
const origin = event.composedPath()[0];
|
|
741
|
+
if (origin instanceof HTMLElement &&
|
|
742
|
+
origin.matches('input, textarea, select, [contenteditable], [contenteditable] *')) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const mod = event.ctrlKey || event.metaKey;
|
|
746
|
+
const key = event.key.toLowerCase();
|
|
747
|
+
const handled = (fn) => {
|
|
748
|
+
event.preventDefault();
|
|
749
|
+
fn();
|
|
750
|
+
};
|
|
751
|
+
if (mod && key === 'z' && this.editable) {
|
|
752
|
+
handled(() => (event.shiftKey ? this.redo() : this.undo()));
|
|
753
|
+
}
|
|
754
|
+
else if (mod && key === 'y' && this.editable) {
|
|
755
|
+
handled(() => this.redo());
|
|
756
|
+
}
|
|
757
|
+
else if (mod && key === 'a' && this.editable) {
|
|
758
|
+
handled(() => this.selectAll());
|
|
759
|
+
}
|
|
760
|
+
else if (mod && key === 'c' && this.editable) {
|
|
761
|
+
handled(() => this.copySelection());
|
|
762
|
+
}
|
|
763
|
+
else if (mod && key === 'v' && this.editable) {
|
|
764
|
+
handled(() => this.paste());
|
|
765
|
+
}
|
|
766
|
+
else if (mod && key === 'd' && this.editable) {
|
|
767
|
+
handled(() => {
|
|
768
|
+
this.copySelection();
|
|
769
|
+
this.paste();
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
else if ((key === 'delete' || key === 'backspace') && this.editable) {
|
|
773
|
+
handled(() => this.deleteSelection());
|
|
774
|
+
}
|
|
775
|
+
else if (key === 'escape') {
|
|
776
|
+
handled(() => {
|
|
777
|
+
this.cancelConnection();
|
|
778
|
+
this.clearSelection();
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
else {
|
|
782
|
+
this.handleCanvasKey(event);
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
this.onConnectionPointerMove = (event) => {
|
|
786
|
+
const c = this._connection;
|
|
787
|
+
if (!c || event.pointerId !== this.connectionDrag?.pointerId)
|
|
788
|
+
return;
|
|
789
|
+
const goal = this.viewport.toCanvas(event.clientX, event.clientY);
|
|
790
|
+
const snap = this.findSnap(goal);
|
|
791
|
+
const target = snap?.point ?? goal;
|
|
792
|
+
if (prefersReducedMotion()) {
|
|
793
|
+
this._connection = { ...c, snap, pointer: target };
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
// A short spring so the preview line follows the pointer smoothly.
|
|
797
|
+
this._connection = { ...c, snap };
|
|
798
|
+
const step = () => {
|
|
799
|
+
const cur = this._connection;
|
|
800
|
+
if (!cur)
|
|
801
|
+
return;
|
|
802
|
+
const dx = target.x - cur.pointer.x;
|
|
803
|
+
const dy = target.y - cur.pointer.y;
|
|
804
|
+
const done = Math.hypot(dx, dy) < 0.5;
|
|
805
|
+
this._connection = {
|
|
806
|
+
...cur,
|
|
807
|
+
pointer: done
|
|
808
|
+
? target
|
|
809
|
+
: { x: cur.pointer.x + dx * 0.45, y: cur.pointer.y + dy * 0.45 },
|
|
810
|
+
};
|
|
811
|
+
this.connectionFrame = done ? 0 : requestAnimationFrame(step);
|
|
812
|
+
};
|
|
813
|
+
cancelAnimationFrame(this.connectionFrame);
|
|
814
|
+
this.connectionFrame = requestAnimationFrame(step);
|
|
815
|
+
};
|
|
816
|
+
this.onConnectionPointerUp = (event) => {
|
|
817
|
+
const c = this._connection;
|
|
818
|
+
if (!c || event.pointerId !== this.connectionDrag?.pointerId)
|
|
819
|
+
return;
|
|
820
|
+
const snap = this.findSnap(this.viewport.toCanvas(event.clientX, event.clientY)) ??
|
|
821
|
+
c.snap;
|
|
822
|
+
this.cancelConnection();
|
|
823
|
+
if (!snap)
|
|
824
|
+
return;
|
|
825
|
+
if (c.mode === 'new') {
|
|
826
|
+
this.connect(c.fixedNode, c.fixedPort.id, snap.nodeId, snap.port.id);
|
|
827
|
+
}
|
|
828
|
+
else if (c.edgeId) {
|
|
829
|
+
this.reconnect(c.edgeId, c.end, snap.nodeId, snap.port.id);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
this.onConnectionPointerCancel = () => {
|
|
833
|
+
this.cancelConnection();
|
|
834
|
+
};
|
|
835
|
+
this.onMarqueeMove = (event) => {
|
|
836
|
+
const drag = this.marqueeDrag;
|
|
837
|
+
const m = this._marquee;
|
|
838
|
+
if (!drag || !m || event.pointerId !== drag.pointerId)
|
|
839
|
+
return;
|
|
840
|
+
const end = {
|
|
841
|
+
x: event.clientX - drag.origin.x,
|
|
842
|
+
y: event.clientY - drag.origin.y,
|
|
843
|
+
};
|
|
844
|
+
this._marquee = { ...m, end };
|
|
845
|
+
const { x, y, zoom } = this.viewport.view;
|
|
846
|
+
const screen = rectFromPoints(m.start, end);
|
|
847
|
+
const canvas = {
|
|
848
|
+
x: (screen.x - x) / zoom,
|
|
849
|
+
y: (screen.y - y) / zoom,
|
|
850
|
+
width: screen.width / zoom,
|
|
851
|
+
height: screen.height / zoom,
|
|
852
|
+
};
|
|
853
|
+
this.selection.set(this.nodes
|
|
854
|
+
.filter(n => rectsIntersect(this.nodeRect(n), canvas))
|
|
855
|
+
.map(n => ({ kind: 'node', id: n.id })));
|
|
856
|
+
};
|
|
857
|
+
this.onMarqueeUp = (event) => {
|
|
858
|
+
if (event.pointerId !== this.marqueeDrag?.pointerId)
|
|
859
|
+
return;
|
|
860
|
+
this.endMarquee();
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
// ── Lifecycle
|
|
864
|
+
disconnectedCallback() {
|
|
865
|
+
super.disconnectedCallback();
|
|
866
|
+
this.endNodeDrag(false);
|
|
867
|
+
this.cancelConnection();
|
|
868
|
+
this.endMarquee();
|
|
869
|
+
this.stopRestoreTween?.();
|
|
870
|
+
cancelAnimationFrame(this.connectionFrame);
|
|
871
|
+
clearTimeout(this.rippleTimer);
|
|
872
|
+
}
|
|
873
|
+
willUpdate(changed) {
|
|
874
|
+
super.willUpdate(changed);
|
|
875
|
+
if (changed.has('nodes')) {
|
|
876
|
+
this.warnLegacyNodes();
|
|
877
|
+
this.selection.retain('node', new Set(this.nodes.map(n => n.id)));
|
|
878
|
+
this.measure.retain(new Set(this.nodes.map(n => n.id)));
|
|
879
|
+
}
|
|
880
|
+
if (changed.has('edges')) {
|
|
881
|
+
if (this.edges.some(e => e.type === 'smoothstep')) {
|
|
882
|
+
deprecate(this.localName, 'edge `type: "smoothstep"`', '`type: "elbow"`');
|
|
883
|
+
}
|
|
884
|
+
this.selection.retain('edge', new Set(this.edges.map(e => e.id)));
|
|
885
|
+
}
|
|
886
|
+
if (changed.has('selected'))
|
|
887
|
+
this.syncSelectedProperty();
|
|
888
|
+
}
|
|
889
|
+
// ── Public API
|
|
890
|
+
/** Whether `undo()` has something to undo. */
|
|
891
|
+
get canUndo() {
|
|
892
|
+
return this.history.canUndo;
|
|
893
|
+
}
|
|
894
|
+
/** Whether `redo()` has something to redo. */
|
|
895
|
+
get canRedo() {
|
|
896
|
+
return this.history.canRedo;
|
|
897
|
+
}
|
|
898
|
+
/** Ids of the selected nodes. */
|
|
899
|
+
get selectedNodes() {
|
|
900
|
+
return this.selection.ids('node');
|
|
901
|
+
}
|
|
902
|
+
/** Ids of the selected edges. */
|
|
903
|
+
get selectedEdges() {
|
|
904
|
+
return this.selection.ids('edge');
|
|
905
|
+
}
|
|
906
|
+
undo() {
|
|
907
|
+
const previous = this.history.undo(this.snapshot());
|
|
908
|
+
if (previous)
|
|
909
|
+
this.restore(previous, 'undo');
|
|
910
|
+
}
|
|
911
|
+
redo() {
|
|
912
|
+
const next = this.history.redo(this.snapshot());
|
|
913
|
+
if (next)
|
|
914
|
+
this.restore(next, 'redo');
|
|
915
|
+
}
|
|
916
|
+
/** Forgets the undo and redo history, for example after saving. */
|
|
917
|
+
clearHistory() {
|
|
918
|
+
this.history.clear();
|
|
919
|
+
this.listeners.notify();
|
|
920
|
+
}
|
|
921
|
+
/** Selects every node and edge. */
|
|
922
|
+
selectAll() {
|
|
923
|
+
this.selection.set([
|
|
924
|
+
...this.nodes.map(n => ({ kind: 'node', id: n.id })),
|
|
925
|
+
...this.edges.map(e => ({ kind: 'edge', id: e.id })),
|
|
926
|
+
]);
|
|
927
|
+
}
|
|
928
|
+
/** Deletes the selected nodes and edges (and edges attached to deleted nodes). Needs `editable`. */
|
|
929
|
+
deleteSelection() {
|
|
930
|
+
if (!this.editable)
|
|
931
|
+
return;
|
|
932
|
+
const nodeIds = this.selection
|
|
933
|
+
.ids('node')
|
|
934
|
+
.filter(id => !this.nodes.find(n => n.id === id)?.locked);
|
|
935
|
+
const nodeSet = new Set(nodeIds);
|
|
936
|
+
const edgeIds = new Set(this.selection.ids('edge'));
|
|
937
|
+
for (const e of this.edges) {
|
|
938
|
+
if (nodeSet.has(e.source) || nodeSet.has(e.target))
|
|
939
|
+
edgeIds.add(e.id);
|
|
940
|
+
}
|
|
941
|
+
if (nodeSet.size === 0 && edgeIds.size === 0)
|
|
942
|
+
return;
|
|
943
|
+
const allowed = this.emit('delete', { nodes: nodeIds, edges: [...edgeIds] }, true);
|
|
944
|
+
if (!allowed)
|
|
945
|
+
return;
|
|
946
|
+
const before = this.snapshot();
|
|
947
|
+
const leaving = nodeIds
|
|
948
|
+
.map(id => this.nodeElement(id))
|
|
949
|
+
.filter((el) => !!el);
|
|
950
|
+
animateOut(leaving, () => {
|
|
951
|
+
this.history.push(before);
|
|
952
|
+
this.nodes = this.nodes.filter(n => !nodeSet.has(n.id));
|
|
953
|
+
this.edges = this.edges.filter(e => !edgeIds.has(e.id));
|
|
954
|
+
this.selection.clear();
|
|
955
|
+
this.selected = '';
|
|
956
|
+
this.announce(this.i18n.t('diagramDeleted')(nodeSet.size + edgeIds.size));
|
|
957
|
+
this.emitChange('delete');
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
// ── Canvas hooks
|
|
961
|
+
viewportElement() {
|
|
962
|
+
return this._viewportEl;
|
|
963
|
+
}
|
|
964
|
+
overviewItems() {
|
|
965
|
+
return this.nodes.map(n => ({
|
|
966
|
+
...this.nodeRect(n),
|
|
967
|
+
selected: this.selection.has('node', n.id),
|
|
968
|
+
}));
|
|
969
|
+
}
|
|
970
|
+
itemRect(id) {
|
|
971
|
+
const node = this.nodes.find(n => n.id === id);
|
|
972
|
+
return node ? this.nodeRect(node) : undefined;
|
|
973
|
+
}
|
|
974
|
+
firstItemRect() {
|
|
975
|
+
return this.nodes[0] ? this.nodeRect(this.nodes[0]) : undefined;
|
|
976
|
+
}
|
|
977
|
+
onBackgroundPointerDown(event) {
|
|
978
|
+
return this.startMarquee(event);
|
|
979
|
+
}
|
|
980
|
+
onBackgroundClick() {
|
|
981
|
+
this.clearSelection();
|
|
982
|
+
}
|
|
983
|
+
// ── Private methods: data
|
|
984
|
+
emitChange(reason) {
|
|
985
|
+
this.emit('change', {
|
|
986
|
+
nodes: this.nodes,
|
|
987
|
+
edges: this.edges,
|
|
988
|
+
reason,
|
|
989
|
+
});
|
|
990
|
+
this.listeners.notify();
|
|
991
|
+
}
|
|
992
|
+
snapshot() {
|
|
993
|
+
return { nodes: this.nodes, edges: this.edges };
|
|
994
|
+
}
|
|
995
|
+
announce(message) {
|
|
996
|
+
this._announcement = '';
|
|
997
|
+
requestAnimationFrame(() => {
|
|
998
|
+
this._announcement = message;
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
warnLegacyNodes() {
|
|
1002
|
+
for (const node of this.nodes) {
|
|
1003
|
+
if (node.inputs || node.outputs) {
|
|
1004
|
+
deprecate(this.localName, 'node `inputs` and `outputs`', '`ports`');
|
|
1005
|
+
}
|
|
1006
|
+
if (node.data instanceof HTMLElement || node.data?.element) {
|
|
1007
|
+
deprecate(this.localName, 'an element in node `data`', 'an element with `slot="node:<id>"`');
|
|
1008
|
+
}
|
|
1009
|
+
else if (node.data && 'label' in node.data && !node.headline) {
|
|
1010
|
+
deprecate(this.localName, 'node `data.label`', '`headline`');
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
/** Keeps the selection in step when the app sets `selected`. */
|
|
1015
|
+
syncSelectedProperty() {
|
|
1016
|
+
const id = this.selected;
|
|
1017
|
+
if (!id) {
|
|
1018
|
+
if (this.selection.size)
|
|
1019
|
+
this.selection.clear();
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const kind = this.nodes.some(n => n.id === id) ? 'node' : 'edge';
|
|
1023
|
+
if (!this.selection.has(kind, id))
|
|
1024
|
+
this.selection.set([{ kind, id }]);
|
|
1025
|
+
}
|
|
1026
|
+
nodePosition(node) {
|
|
1027
|
+
return this.positionOverrides.get(node.id) ?? node.position;
|
|
1028
|
+
}
|
|
1029
|
+
nodeRect(node) {
|
|
1030
|
+
const { x, y } = this.nodePosition(node);
|
|
1031
|
+
const size = this.measure.size(node.id);
|
|
1032
|
+
return { x, y, width: size.width, height: size.height };
|
|
1033
|
+
}
|
|
1034
|
+
contentBounds() {
|
|
1035
|
+
return boundsOf(this.nodes.map(n => this.nodeRect(n)));
|
|
1036
|
+
}
|
|
1037
|
+
selectionRects() {
|
|
1038
|
+
const nodeIds = new Set(this.selection.ids('node'));
|
|
1039
|
+
const edgeIds = new Set(this.selection.ids('edge'));
|
|
1040
|
+
for (const e of this.edges) {
|
|
1041
|
+
if (edgeIds.has(e.id)) {
|
|
1042
|
+
nodeIds.add(e.source);
|
|
1043
|
+
nodeIds.add(e.target);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
return this.nodes.filter(n => nodeIds.has(n.id)).map(n => this.nodeRect(n));
|
|
1047
|
+
}
|
|
1048
|
+
nodeLabel(node) {
|
|
1049
|
+
if (node.headline)
|
|
1050
|
+
return node.headline;
|
|
1051
|
+
if (node.data instanceof HTMLElement) {
|
|
1052
|
+
return node.data.getAttribute('aria-label') || node.id;
|
|
1053
|
+
}
|
|
1054
|
+
const label = node.data?.label;
|
|
1055
|
+
return typeof label === 'string' && label ? label : node.id;
|
|
1056
|
+
}
|
|
1057
|
+
legacyElement(node) {
|
|
1058
|
+
if (node.data instanceof HTMLElement)
|
|
1059
|
+
return node.data;
|
|
1060
|
+
const el = node.data?.element;
|
|
1061
|
+
return el instanceof HTMLElement ? el : undefined;
|
|
1062
|
+
}
|
|
1063
|
+
resolvePorts(node) {
|
|
1064
|
+
let ports;
|
|
1065
|
+
if (node.ports?.length) {
|
|
1066
|
+
ports = node.ports.map(p => ({ ...p, type: p.type ?? 'both' }));
|
|
1067
|
+
}
|
|
1068
|
+
else {
|
|
1069
|
+
const inputs = node.inputs ?? ['left'];
|
|
1070
|
+
const outputs = node.outputs ?? ['right'];
|
|
1071
|
+
ports = [
|
|
1072
|
+
...inputs.map(side => ({ id: side, side, type: 'target' })),
|
|
1073
|
+
...outputs.map(side => ({ id: side, side, type: 'source' })),
|
|
1074
|
+
];
|
|
1075
|
+
}
|
|
1076
|
+
const bySide = new Map();
|
|
1077
|
+
const counts = new Map();
|
|
1078
|
+
for (const p of ports)
|
|
1079
|
+
counts.set(p.side, (counts.get(p.side) ?? 0) + 1);
|
|
1080
|
+
return ports.map(p => {
|
|
1081
|
+
const i = bySide.get(p.side) ?? 0;
|
|
1082
|
+
bySide.set(p.side, i + 1);
|
|
1083
|
+
const n = counts.get(p.side) ?? 1;
|
|
1084
|
+
return { ...p, offset: p.offset ?? (i + 1) / (n + 1) };
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
findPort(node, id, role) {
|
|
1088
|
+
const ports = this.resolvePorts(node);
|
|
1089
|
+
const capable = (p) => p.type === 'both' || p.type === role;
|
|
1090
|
+
return ((id
|
|
1091
|
+
? (ports.find(p => p.id === id) ??
|
|
1092
|
+
ports.find(p => p.side === id && capable(p)))
|
|
1093
|
+
: undefined) ??
|
|
1094
|
+
ports.find(capable) ??
|
|
1095
|
+
ports[0] ?? {
|
|
1096
|
+
id: role === 'source' ? 'right' : 'left',
|
|
1097
|
+
side: role === 'source' ? 'right' : 'left',
|
|
1098
|
+
type: role,
|
|
1099
|
+
offset: 0.5,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
portPoint(node, port) {
|
|
1103
|
+
return anchorOnRect(this.nodeRect(node), port.side, port.offset);
|
|
1104
|
+
}
|
|
1105
|
+
edgeRender(edge, byId) {
|
|
1106
|
+
const source = byId.get(edge.source);
|
|
1107
|
+
const target = byId.get(edge.target);
|
|
1108
|
+
if (!source || !target)
|
|
1109
|
+
return undefined;
|
|
1110
|
+
const sp = this.findPort(source, edge.sourceHandle, 'source');
|
|
1111
|
+
const tp = this.findPort(target, edge.targetHandle, 'target');
|
|
1112
|
+
const start = this.portPoint(source, sp);
|
|
1113
|
+
const end = this.portPoint(target, tp);
|
|
1114
|
+
let kind = this.connector;
|
|
1115
|
+
if (edge.type === 'smoothstep')
|
|
1116
|
+
kind = 'elbow';
|
|
1117
|
+
else if (edge.type)
|
|
1118
|
+
kind = edge.type;
|
|
1119
|
+
const markerStart = edge.markerStart ?? 'none';
|
|
1120
|
+
const markerEnd = edge.markerEnd ?? 'arrow';
|
|
1121
|
+
const geometry = edgeGeometry(kind, start, sp.side, end, tp.side, {
|
|
1122
|
+
startInset: markerInset(markerStart),
|
|
1123
|
+
endInset: markerInset(markerEnd),
|
|
1124
|
+
});
|
|
1125
|
+
return { edge, geometry, start, end, markerStart, markerEnd };
|
|
1126
|
+
}
|
|
1127
|
+
uniqueId(base, taken) {
|
|
1128
|
+
if (!taken.has(base))
|
|
1129
|
+
return base;
|
|
1130
|
+
let i = 2;
|
|
1131
|
+
while (taken.has(`${base}-${i}`))
|
|
1132
|
+
i += 1;
|
|
1133
|
+
return `${base}-${i}`;
|
|
1134
|
+
}
|
|
1135
|
+
isBackground(target) {
|
|
1136
|
+
const el = target;
|
|
1137
|
+
if (!el)
|
|
1138
|
+
return false;
|
|
1139
|
+
return (el === this._viewportEl ||
|
|
1140
|
+
(el.classList?.contains('diagram-world') ?? false) ||
|
|
1141
|
+
(el.classList?.contains('diagram-svg') ?? false) ||
|
|
1142
|
+
(el.classList?.contains('diagram-nodes') ?? false));
|
|
1143
|
+
}
|
|
1144
|
+
// ── Private methods: selection
|
|
1145
|
+
clearSelection() {
|
|
1146
|
+
this.selection.clear();
|
|
1147
|
+
this.selected = '';
|
|
1148
|
+
}
|
|
1149
|
+
selectNode(node, additive = false) {
|
|
1150
|
+
if (additive && this.editable) {
|
|
1151
|
+
this.selection.toggle('node', node.id);
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
this.selection.set([{ kind: 'node', id: node.id }]);
|
|
1155
|
+
}
|
|
1156
|
+
this.selected = node.id;
|
|
1157
|
+
this.emit('select', {
|
|
1158
|
+
id: node.id,
|
|
1159
|
+
kind: 'node',
|
|
1160
|
+
node,
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
selectEdge(edge, additive = false) {
|
|
1164
|
+
if (additive && this.editable) {
|
|
1165
|
+
this.selection.toggle('edge', edge.id);
|
|
1166
|
+
}
|
|
1167
|
+
else {
|
|
1168
|
+
this.selection.set([{ kind: 'edge', id: edge.id }]);
|
|
1169
|
+
}
|
|
1170
|
+
this.selected = edge.id;
|
|
1171
|
+
this.emit('select', {
|
|
1172
|
+
id: edge.id,
|
|
1173
|
+
kind: 'edge',
|
|
1174
|
+
edge,
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
// ── Private methods: node dragging
|
|
1178
|
+
nodeElements() {
|
|
1179
|
+
const out = [];
|
|
1180
|
+
this.renderRoot
|
|
1181
|
+
.querySelectorAll('.diagram-node')
|
|
1182
|
+
.forEach(el => {
|
|
1183
|
+
const { id } = el.dataset;
|
|
1184
|
+
if (id)
|
|
1185
|
+
out.push([id, el]);
|
|
1186
|
+
});
|
|
1187
|
+
return out;
|
|
1188
|
+
}
|
|
1189
|
+
nodeElement(id) {
|
|
1190
|
+
return this.renderRoot.querySelector(`.diagram-node[data-id="${CSS.escape(id)}"]`);
|
|
1191
|
+
}
|
|
1192
|
+
onNodePointerDown(event, node) {
|
|
1193
|
+
if (event.button !== 0 || this.viewport.spaceHeld)
|
|
1194
|
+
return;
|
|
1195
|
+
const target = event.composedPath()[0];
|
|
1196
|
+
if (target instanceof Element && target.closest(INTERACTIVE))
|
|
1197
|
+
return;
|
|
1198
|
+
event.preventDefault();
|
|
1199
|
+
const element = event.currentTarget;
|
|
1200
|
+
element.focus({ preventScroll: true });
|
|
1201
|
+
this.stopRestoreTween?.();
|
|
1202
|
+
const additive = event.shiftKey || event.metaKey || event.ctrlKey;
|
|
1203
|
+
const ids = this.editable && this.selection.has('node', node.id) && !additive
|
|
1204
|
+
? this.selection
|
|
1205
|
+
.ids('node')
|
|
1206
|
+
.filter(id => !this.nodes.find(n => n.id === id)?.locked)
|
|
1207
|
+
: [node.id];
|
|
1208
|
+
this.nodeDrag = {
|
|
1209
|
+
pointerId: event.pointerId,
|
|
1210
|
+
startX: event.clientX,
|
|
1211
|
+
startY: event.clientY,
|
|
1212
|
+
primary: node.id,
|
|
1213
|
+
ids: ids.includes(node.id) ? ids : [node.id],
|
|
1214
|
+
origins: new Map(this.nodes
|
|
1215
|
+
.filter(n => ids.includes(n.id) || n.id === node.id)
|
|
1216
|
+
.map(n => [n.id, { ...n.position }])),
|
|
1217
|
+
before: this.snapshot(),
|
|
1218
|
+
moved: false,
|
|
1219
|
+
movable: !this.readonly && !node.locked,
|
|
1220
|
+
additive,
|
|
1221
|
+
element,
|
|
1222
|
+
};
|
|
1223
|
+
try {
|
|
1224
|
+
element.setPointerCapture(event.pointerId);
|
|
1225
|
+
}
|
|
1226
|
+
catch {
|
|
1227
|
+
// Synthetic or already released pointers cannot be captured.
|
|
1228
|
+
}
|
|
1229
|
+
element.addEventListener('pointermove', this.onNodePointerMove);
|
|
1230
|
+
element.addEventListener('pointerup', this.onNodePointerUp);
|
|
1231
|
+
element.addEventListener('pointercancel', this.onNodePointerUp);
|
|
1232
|
+
}
|
|
1233
|
+
/** Ends the press on a node: a drag commits the move, a press without movement selects. */
|
|
1234
|
+
endNodeDrag(notify) {
|
|
1235
|
+
const drag = this.nodeDrag;
|
|
1236
|
+
if (!drag)
|
|
1237
|
+
return;
|
|
1238
|
+
this.nodeDrag = undefined;
|
|
1239
|
+
this._draggingIds = [];
|
|
1240
|
+
this._guides = [];
|
|
1241
|
+
const { element } = drag;
|
|
1242
|
+
element.removeEventListener('pointermove', this.onNodePointerMove);
|
|
1243
|
+
element.removeEventListener('pointerup', this.onNodePointerUp);
|
|
1244
|
+
element.removeEventListener('pointercancel', this.onNodePointerUp);
|
|
1245
|
+
try {
|
|
1246
|
+
if (element.hasPointerCapture(drag.pointerId)) {
|
|
1247
|
+
element.releasePointerCapture(drag.pointerId);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
catch {
|
|
1251
|
+
// The pointer is already gone.
|
|
1252
|
+
}
|
|
1253
|
+
if (!notify)
|
|
1254
|
+
return;
|
|
1255
|
+
if (drag.moved) {
|
|
1256
|
+
const node = this.nodes.find(n => n.id === drag.primary);
|
|
1257
|
+
if (!node)
|
|
1258
|
+
return;
|
|
1259
|
+
this.history.push(drag.before);
|
|
1260
|
+
this.emit('node-drag-end', {
|
|
1261
|
+
id: drag.primary,
|
|
1262
|
+
position: { ...node.position },
|
|
1263
|
+
});
|
|
1264
|
+
this.emitChange('move');
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
const node = this.nodes.find(n => n.id === drag.primary);
|
|
1268
|
+
if (node)
|
|
1269
|
+
this.selectNode(node, drag.additive);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
/** Replaces moved nodes with new objects and assigns a new `nodes` array. */
|
|
1273
|
+
moveNodes(positions) {
|
|
1274
|
+
this.nodes = this.nodes.map(node => {
|
|
1275
|
+
const p = positions.get(node.id);
|
|
1276
|
+
return p ? { ...node, position: { x: p.x, y: p.y } } : node;
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
/** Snaps a dragged node's edges or centre to nearby nodes and returns guide lines to draw. */
|
|
1280
|
+
alignToOthers(id, position, moving) {
|
|
1281
|
+
const size = this.measure.size(id);
|
|
1282
|
+
const threshold = GUIDE_DISTANCE / this.viewport.view.zoom;
|
|
1283
|
+
const visible = this.viewport.visibleRect();
|
|
1284
|
+
const others = this.nodes
|
|
1285
|
+
.filter(n => !moving.has(n.id))
|
|
1286
|
+
.map(n => this.nodeRect(n))
|
|
1287
|
+
.filter(r => rectsIntersect(r, visible));
|
|
1288
|
+
const mine = (p) => ({
|
|
1289
|
+
xs: [p.x, p.x + size.width / 2, p.x + size.width],
|
|
1290
|
+
ys: [p.y, p.y + size.height / 2, p.y + size.height],
|
|
1291
|
+
});
|
|
1292
|
+
let bestX;
|
|
1293
|
+
let bestY;
|
|
1294
|
+
const m = mine(position);
|
|
1295
|
+
for (const r of others) {
|
|
1296
|
+
for (const ox of [r.x, r.x + r.width / 2, r.x + r.width]) {
|
|
1297
|
+
for (const mx of m.xs) {
|
|
1298
|
+
const d = ox - mx;
|
|
1299
|
+
if (Math.abs(d) < threshold &&
|
|
1300
|
+
(!bestX || Math.abs(d) < Math.abs(bestX.delta))) {
|
|
1301
|
+
bestX = { delta: d, line: ox, rect: r };
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
for (const oy of [r.y, r.y + r.height / 2, r.y + r.height]) {
|
|
1306
|
+
for (const my of m.ys) {
|
|
1307
|
+
const d = oy - my;
|
|
1308
|
+
if (Math.abs(d) < threshold &&
|
|
1309
|
+
(!bestY || Math.abs(d) < Math.abs(bestY.delta))) {
|
|
1310
|
+
bestY = { delta: d, line: oy, rect: r };
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
const next = {
|
|
1316
|
+
x: position.x + (bestX?.delta ?? 0),
|
|
1317
|
+
y: position.y + (bestY?.delta ?? 0),
|
|
1318
|
+
};
|
|
1319
|
+
const guides = [];
|
|
1320
|
+
if (bestX) {
|
|
1321
|
+
const top = Math.min(bestX.rect.y, next.y) - 16;
|
|
1322
|
+
const bottom = Math.max(bestX.rect.y + bestX.rect.height, next.y + size.height) + 16;
|
|
1323
|
+
guides.push({ x1: bestX.line, y1: top, x2: bestX.line, y2: bottom });
|
|
1324
|
+
}
|
|
1325
|
+
if (bestY) {
|
|
1326
|
+
const left = Math.min(bestY.rect.x, next.x) - 16;
|
|
1327
|
+
const right = Math.max(bestY.rect.x + bestY.rect.width, next.x + size.width) + 16;
|
|
1328
|
+
guides.push({ x1: left, y1: bestY.line, x2: right, y2: bestY.line });
|
|
1329
|
+
}
|
|
1330
|
+
return { position: next, guides };
|
|
1331
|
+
}
|
|
1332
|
+
// ── Private methods: keyboard
|
|
1333
|
+
onNodeKeyDown(event, node) {
|
|
1334
|
+
// Keys typed into controls inside a custom node are theirs.
|
|
1335
|
+
if (event.target !== event.currentTarget)
|
|
1336
|
+
return;
|
|
1337
|
+
const { key } = event;
|
|
1338
|
+
if (key === 'Enter' || key === ' ') {
|
|
1339
|
+
this.markHandled(event);
|
|
1340
|
+
this.selectNode(node, event.shiftKey);
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
if ((key === 'Delete' || key === 'Backspace') && this.editable) {
|
|
1344
|
+
this.markHandled(event);
|
|
1345
|
+
if (!this.selection.has('node', node.id)) {
|
|
1346
|
+
this.selection.set([{ kind: 'node', id: node.id }]);
|
|
1347
|
+
}
|
|
1348
|
+
this.deleteSelection();
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
const dir = {
|
|
1352
|
+
ArrowLeft: 'left',
|
|
1353
|
+
ArrowRight: 'right',
|
|
1354
|
+
ArrowUp: 'up',
|
|
1355
|
+
ArrowDown: 'down',
|
|
1356
|
+
}[key];
|
|
1357
|
+
if (!dir)
|
|
1358
|
+
return;
|
|
1359
|
+
this.markHandled(event);
|
|
1360
|
+
if (event.altKey) {
|
|
1361
|
+
const from = this.nodeRect(node);
|
|
1362
|
+
const next = nearestInDirection(from, this.nodes
|
|
1363
|
+
.filter(n => n.id !== node.id)
|
|
1364
|
+
.map(n => ({ node: n, rect: this.nodeRect(n) })), dir);
|
|
1365
|
+
if (next)
|
|
1366
|
+
this.focusNode(next.node.id);
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (this.readonly || node.locked)
|
|
1370
|
+
return;
|
|
1371
|
+
const step = event.shiftKey ? LARGE_KEY_STEP : KEY_STEP;
|
|
1372
|
+
const offset = {
|
|
1373
|
+
left: { x: -step, y: 0 },
|
|
1374
|
+
right: { x: step, y: 0 },
|
|
1375
|
+
up: { x: 0, y: -step },
|
|
1376
|
+
down: { x: 0, y: step },
|
|
1377
|
+
}[dir];
|
|
1378
|
+
const ids = this.editable && this.selection.has('node', node.id)
|
|
1379
|
+
? this.selection
|
|
1380
|
+
.ids('node')
|
|
1381
|
+
.filter(id => !this.nodes.find(n => n.id === id)?.locked)
|
|
1382
|
+
: [node.id];
|
|
1383
|
+
const before = this.snapshot();
|
|
1384
|
+
const moved = new Map();
|
|
1385
|
+
for (const n of this.nodes) {
|
|
1386
|
+
if (ids.includes(n.id)) {
|
|
1387
|
+
moved.set(n.id, {
|
|
1388
|
+
x: n.position.x + offset.x,
|
|
1389
|
+
y: n.position.y + offset.y,
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
this.moveNodes(moved);
|
|
1394
|
+
this.history.push(before);
|
|
1395
|
+
const position = moved.get(node.id) ?? node.position;
|
|
1396
|
+
this.emit('node-drag-end', {
|
|
1397
|
+
id: node.id,
|
|
1398
|
+
position,
|
|
1399
|
+
});
|
|
1400
|
+
this.announce(this.i18n.t('diagramMoved')(this.nodeLabel(node), String(Math.round(position.x)), String(Math.round(position.y))));
|
|
1401
|
+
this.emitChange('move');
|
|
1402
|
+
this.keepInView(node.id);
|
|
1403
|
+
}
|
|
1404
|
+
onEdgeKeyDown(event, edge) {
|
|
1405
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
1406
|
+
this.markHandled(event);
|
|
1407
|
+
this.selectEdge(edge, event.shiftKey);
|
|
1408
|
+
}
|
|
1409
|
+
else if ((event.key === 'Delete' || event.key === 'Backspace') &&
|
|
1410
|
+
this.editable) {
|
|
1411
|
+
this.markHandled(event);
|
|
1412
|
+
if (!this.selection.has('edge', edge.id)) {
|
|
1413
|
+
this.selection.set([{ kind: 'edge', id: edge.id }]);
|
|
1414
|
+
}
|
|
1415
|
+
this.deleteSelection();
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
markHandled(event) {
|
|
1419
|
+
event.preventDefault();
|
|
1420
|
+
this.handledKeys.add(event);
|
|
1421
|
+
}
|
|
1422
|
+
focusNode(id) {
|
|
1423
|
+
this.focusedId = id;
|
|
1424
|
+
this.keepInView(id, true);
|
|
1425
|
+
this.updateComplete.then(() => this.nodeElement(id)?.focus({ preventScroll: true }));
|
|
1426
|
+
}
|
|
1427
|
+
/** Pans so the node is in view, when it is not. */
|
|
1428
|
+
keepInView(id, animate = false) {
|
|
1429
|
+
const node = this.nodes.find(n => n.id === id);
|
|
1430
|
+
if (!node)
|
|
1431
|
+
return;
|
|
1432
|
+
const r = this.nodeRect(node);
|
|
1433
|
+
const visible = inflateRect(this.viewport.visibleRect(), -20 / this.viewport.view.zoom);
|
|
1434
|
+
const inside = r.x >= visible.x &&
|
|
1435
|
+
r.y >= visible.y &&
|
|
1436
|
+
r.x + r.width <= visible.x + visible.width &&
|
|
1437
|
+
r.y + r.height <= visible.y + visible.height;
|
|
1438
|
+
if (inside)
|
|
1439
|
+
return;
|
|
1440
|
+
const view = this.viewport.viewCentering({
|
|
1441
|
+
x: r.x + r.width / 2,
|
|
1442
|
+
y: r.y + r.height / 2,
|
|
1443
|
+
});
|
|
1444
|
+
if (animate)
|
|
1445
|
+
this.viewport.animateTo(view, 300);
|
|
1446
|
+
else
|
|
1447
|
+
this.viewport.setView(view);
|
|
1448
|
+
}
|
|
1449
|
+
// ── Private methods: copy and paste
|
|
1450
|
+
copySelection() {
|
|
1451
|
+
const ids = new Set(this.selection.ids('node'));
|
|
1452
|
+
if (!ids.size)
|
|
1453
|
+
return;
|
|
1454
|
+
clipboard = {
|
|
1455
|
+
nodes: this.nodes.filter(n => ids.has(n.id)),
|
|
1456
|
+
edges: this.edges.filter(e => ids.has(e.source) && ids.has(e.target)),
|
|
1457
|
+
};
|
|
1458
|
+
this.pasteCount = 0;
|
|
1459
|
+
}
|
|
1460
|
+
paste() {
|
|
1461
|
+
if (!clipboard || !this.editable)
|
|
1462
|
+
return;
|
|
1463
|
+
this.pasteCount += 1;
|
|
1464
|
+
const offset = 40 * this.pasteCount;
|
|
1465
|
+
const takenNodes = new Set(this.nodes.map(n => n.id));
|
|
1466
|
+
const takenEdges = new Set(this.edges.map(e => e.id));
|
|
1467
|
+
const idMap = new Map();
|
|
1468
|
+
const nodes = clipboard.nodes.map(n => {
|
|
1469
|
+
const id = this.uniqueId(`${n.id}-copy`, takenNodes);
|
|
1470
|
+
takenNodes.add(id);
|
|
1471
|
+
idMap.set(n.id, id);
|
|
1472
|
+
return {
|
|
1473
|
+
...n,
|
|
1474
|
+
id,
|
|
1475
|
+
position: { x: n.position.x + offset, y: n.position.y + offset },
|
|
1476
|
+
};
|
|
1477
|
+
});
|
|
1478
|
+
const edges = clipboard.edges.map(e => {
|
|
1479
|
+
const id = this.uniqueId(`${e.id}-copy`, takenEdges);
|
|
1480
|
+
takenEdges.add(id);
|
|
1481
|
+
return {
|
|
1482
|
+
...e,
|
|
1483
|
+
id,
|
|
1484
|
+
source: idMap.get(e.source) ?? e.source,
|
|
1485
|
+
target: idMap.get(e.target) ?? e.target,
|
|
1486
|
+
};
|
|
1487
|
+
});
|
|
1488
|
+
this.history.push(this.snapshot());
|
|
1489
|
+
this.nodes = [...this.nodes, ...nodes];
|
|
1490
|
+
this.edges = [...this.edges, ...edges];
|
|
1491
|
+
this.selection.set([
|
|
1492
|
+
...nodes.map(n => ({ kind: 'node', id: n.id })),
|
|
1493
|
+
...edges.map(e => ({ kind: 'edge', id: e.id })),
|
|
1494
|
+
]);
|
|
1495
|
+
this.announce(this.i18n.t('diagramPasted')(nodes.length + edges.length));
|
|
1496
|
+
this.emitChange('paste');
|
|
1497
|
+
}
|
|
1498
|
+
// ── Private methods: undo
|
|
1499
|
+
/** Restores a snapshot; nodes that moved glide to their restored places. */
|
|
1500
|
+
restore(snapshot, reason) {
|
|
1501
|
+
this.stopRestoreTween?.();
|
|
1502
|
+
const from = new Map(this.nodes.map(n => [n.id, { ...n.position }]));
|
|
1503
|
+
this.nodes = snapshot.nodes;
|
|
1504
|
+
this.edges = snapshot.edges;
|
|
1505
|
+
const moving = snapshot.nodes.filter(n => {
|
|
1506
|
+
const f = from.get(n.id);
|
|
1507
|
+
return f && (f.x !== n.position.x || f.y !== n.position.y);
|
|
1508
|
+
});
|
|
1509
|
+
if (moving.length && !prefersReducedMotion()) {
|
|
1510
|
+
this.stopRestoreTween = tween({
|
|
1511
|
+
duration: 260,
|
|
1512
|
+
easing: easeOutCubic,
|
|
1513
|
+
onUpdate: p => {
|
|
1514
|
+
for (const n of moving) {
|
|
1515
|
+
const f = from.get(n.id);
|
|
1516
|
+
if (f) {
|
|
1517
|
+
this.positionOverrides.set(n.id, {
|
|
1518
|
+
x: f.x + (n.position.x - f.x) * p,
|
|
1519
|
+
y: f.y + (n.position.y - f.y) * p,
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
this.requestUpdate();
|
|
1524
|
+
},
|
|
1525
|
+
onDone: () => {
|
|
1526
|
+
this.positionOverrides.clear();
|
|
1527
|
+
this.stopRestoreTween = undefined;
|
|
1528
|
+
this.requestUpdate();
|
|
1529
|
+
},
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
this.selection.retain('node', new Set(snapshot.nodes.map(n => n.id)));
|
|
1533
|
+
this.selection.retain('edge', new Set(snapshot.edges.map(e => e.id)));
|
|
1534
|
+
this.emitChange(reason);
|
|
1535
|
+
}
|
|
1536
|
+
// ── Private methods: connections
|
|
1537
|
+
onPortPointerDown(event, node, port) {
|
|
1538
|
+
if (event.button !== 0 || this.viewport.spaceHeld)
|
|
1539
|
+
return;
|
|
1540
|
+
event.stopPropagation();
|
|
1541
|
+
event.preventDefault();
|
|
1542
|
+
if (this.readonly || port.type === 'target')
|
|
1543
|
+
return;
|
|
1544
|
+
const point = this.portPoint(node, port);
|
|
1545
|
+
this.beginConnectionDrag(event, {
|
|
1546
|
+
mode: 'new',
|
|
1547
|
+
end: 'target',
|
|
1548
|
+
fixedNode: node.id,
|
|
1549
|
+
fixedPort: port,
|
|
1550
|
+
fixedPoint: point,
|
|
1551
|
+
pointer: point,
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
startReconnect(event, edge, end) {
|
|
1555
|
+
if (event.button !== 0)
|
|
1556
|
+
return;
|
|
1557
|
+
event.stopPropagation();
|
|
1558
|
+
event.preventDefault();
|
|
1559
|
+
const byId = new Map(this.nodes.map(n => [n.id, n]));
|
|
1560
|
+
const render = this.edgeRender(edge, byId);
|
|
1561
|
+
const fixedNode = byId.get(end === 'target' ? edge.source : edge.target);
|
|
1562
|
+
if (!render || !fixedNode)
|
|
1563
|
+
return;
|
|
1564
|
+
const fixedPort = this.findPort(fixedNode, end === 'target' ? edge.sourceHandle : edge.targetHandle, end === 'target' ? 'source' : 'target');
|
|
1565
|
+
this.beginConnectionDrag(event, {
|
|
1566
|
+
mode: 'reconnect',
|
|
1567
|
+
edgeId: edge.id,
|
|
1568
|
+
end,
|
|
1569
|
+
fixedNode: fixedNode.id,
|
|
1570
|
+
fixedPort,
|
|
1571
|
+
fixedPoint: end === 'target' ? render.start : render.end,
|
|
1572
|
+
pointer: end === 'target' ? render.end : render.start,
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
beginConnectionDrag(event, connection) {
|
|
1576
|
+
const element = event.currentTarget;
|
|
1577
|
+
this._connection = connection;
|
|
1578
|
+
this.connectionDrag = { pointerId: event.pointerId, element };
|
|
1579
|
+
try {
|
|
1580
|
+
element.setPointerCapture(event.pointerId);
|
|
1581
|
+
}
|
|
1582
|
+
catch {
|
|
1583
|
+
// Synthetic or already released pointers cannot be captured.
|
|
1584
|
+
}
|
|
1585
|
+
element.addEventListener('pointermove', this.onConnectionPointerMove);
|
|
1586
|
+
element.addEventListener('pointerup', this.onConnectionPointerUp);
|
|
1587
|
+
element.addEventListener('pointercancel', this.onConnectionPointerCancel);
|
|
1588
|
+
}
|
|
1589
|
+
/** The nearest port that can take the moving end, within snapping distance. */
|
|
1590
|
+
findSnap(point) {
|
|
1591
|
+
const c = this._connection;
|
|
1592
|
+
if (!c)
|
|
1593
|
+
return undefined;
|
|
1594
|
+
const role = c.end === 'target' ? 'target' : 'source';
|
|
1595
|
+
const limit = SNAP_DISTANCE / this.viewport.view.zoom;
|
|
1596
|
+
let best;
|
|
1597
|
+
const probe = { ...point, width: 0.01, height: 0.01 };
|
|
1598
|
+
for (const node of this.nodes.filter(n => n.id !== c.fixedNode)) {
|
|
1599
|
+
const rect = this.nodeRect(node);
|
|
1600
|
+
const inside = rectsIntersect(rect, probe);
|
|
1601
|
+
if (inside || rectsIntersect(inflateRect(rect, limit), probe)) {
|
|
1602
|
+
const ports = this.resolvePorts(node).filter(port => port.type === 'both' || port.type === role);
|
|
1603
|
+
for (const port of ports) {
|
|
1604
|
+
const p = this.portPoint(node, port);
|
|
1605
|
+
const d = Math.hypot(p.x - point.x, p.y - point.y);
|
|
1606
|
+
if ((inside || d <= limit) && (!best || d < best.d)) {
|
|
1607
|
+
best = { nodeId: node.id, port, point: p, d };
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
return best
|
|
1613
|
+
? { nodeId: best.nodeId, port: best.port, point: best.point }
|
|
1614
|
+
: undefined;
|
|
1615
|
+
}
|
|
1616
|
+
/** Stops drawing a connection and releases its pointer. */
|
|
1617
|
+
cancelConnection() {
|
|
1618
|
+
const drag = this.connectionDrag;
|
|
1619
|
+
this.connectionDrag = undefined;
|
|
1620
|
+
this._connection = undefined;
|
|
1621
|
+
cancelAnimationFrame(this.connectionFrame);
|
|
1622
|
+
this.connectionFrame = 0;
|
|
1623
|
+
if (!drag)
|
|
1624
|
+
return;
|
|
1625
|
+
const { element } = drag;
|
|
1626
|
+
element.removeEventListener('pointermove', this.onConnectionPointerMove);
|
|
1627
|
+
element.removeEventListener('pointerup', this.onConnectionPointerUp);
|
|
1628
|
+
element.removeEventListener('pointercancel', this.onConnectionPointerCancel);
|
|
1629
|
+
try {
|
|
1630
|
+
if (element.hasPointerCapture(drag.pointerId)) {
|
|
1631
|
+
element.releasePointerCapture(drag.pointerId);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
catch {
|
|
1635
|
+
// The pointer is already gone.
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
connect(source, sourceHandle, target, targetHandle) {
|
|
1639
|
+
if (source === target)
|
|
1640
|
+
return;
|
|
1641
|
+
const detail = { source, target, sourceHandle, targetHandle };
|
|
1642
|
+
const allowed = this.emit('connect', detail, true);
|
|
1643
|
+
this.ripple(target, targetHandle);
|
|
1644
|
+
if (!this.editable || !allowed)
|
|
1645
|
+
return;
|
|
1646
|
+
const duplicate = this.edges.some(e => e.source === source &&
|
|
1647
|
+
e.target === target &&
|
|
1648
|
+
(e.sourceHandle ?? '') === sourceHandle &&
|
|
1649
|
+
(e.targetHandle ?? '') === targetHandle);
|
|
1650
|
+
if (duplicate)
|
|
1651
|
+
return;
|
|
1652
|
+
const id = this.uniqueId(`${source}-${target}`, new Set(this.edges.map(e => e.id)));
|
|
1653
|
+
this.history.push(this.snapshot());
|
|
1654
|
+
this.edges = [...this.edges, { id, ...detail }];
|
|
1655
|
+
const byId = new Map(this.nodes.map(n => [n.id, n]));
|
|
1656
|
+
const from = byId.get(source);
|
|
1657
|
+
const to = byId.get(target);
|
|
1658
|
+
if (from && to) {
|
|
1659
|
+
this.announce(this.i18n.t('diagramConnected')(this.nodeLabel(from), this.nodeLabel(to)));
|
|
1660
|
+
}
|
|
1661
|
+
this.emitChange('connect');
|
|
1662
|
+
}
|
|
1663
|
+
reconnect(edgeId, end, nodeId, portId) {
|
|
1664
|
+
const edge = this.edges.find(e => e.id === edgeId);
|
|
1665
|
+
if (!edge || !this.editable)
|
|
1666
|
+
return;
|
|
1667
|
+
const next = end === 'target'
|
|
1668
|
+
? { ...edge, target: nodeId, targetHandle: portId }
|
|
1669
|
+
: { ...edge, source: nodeId, sourceHandle: portId };
|
|
1670
|
+
if (next.source === next.target)
|
|
1671
|
+
return;
|
|
1672
|
+
this.history.push(this.snapshot());
|
|
1673
|
+
this.edges = this.edges.map(e => (e.id === edgeId ? next : e));
|
|
1674
|
+
this.ripple(nodeId, portId);
|
|
1675
|
+
this.emitChange('reconnect');
|
|
1676
|
+
}
|
|
1677
|
+
ripple(nodeId, portId) {
|
|
1678
|
+
clearTimeout(this.rippleTimer);
|
|
1679
|
+
this._ripple = `${nodeId}\u0000${portId}`;
|
|
1680
|
+
this.rippleTimer = setTimeout(() => {
|
|
1681
|
+
this._ripple = '';
|
|
1682
|
+
}, 500);
|
|
1683
|
+
}
|
|
1684
|
+
// ── Private methods: edges and marquee
|
|
1685
|
+
onEdgePointerDown(event, edge) {
|
|
1686
|
+
if (event.button !== 0 || this.viewport.spaceHeld)
|
|
1687
|
+
return;
|
|
1688
|
+
event.stopPropagation();
|
|
1689
|
+
this.selectEdge(edge, event.shiftKey || event.metaKey || event.ctrlKey);
|
|
1690
|
+
}
|
|
1691
|
+
startMarquee(event) {
|
|
1692
|
+
if (!this.editable || !event.shiftKey)
|
|
1693
|
+
return false;
|
|
1694
|
+
const element = this._viewportEl;
|
|
1695
|
+
if (!element)
|
|
1696
|
+
return false;
|
|
1697
|
+
event.preventDefault();
|
|
1698
|
+
const rect = element.getBoundingClientRect();
|
|
1699
|
+
const point = { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
1700
|
+
this._marquee = { start: point, end: point };
|
|
1701
|
+
this.marqueeDrag = { pointerId: event.pointerId, element, origin: rect };
|
|
1702
|
+
try {
|
|
1703
|
+
element.setPointerCapture(event.pointerId);
|
|
1704
|
+
}
|
|
1705
|
+
catch {
|
|
1706
|
+
// Synthetic pointers cannot be captured.
|
|
1707
|
+
}
|
|
1708
|
+
element.addEventListener('pointermove', this.onMarqueeMove);
|
|
1709
|
+
element.addEventListener('pointerup', this.onMarqueeUp);
|
|
1710
|
+
element.addEventListener('pointercancel', this.onMarqueeUp);
|
|
1711
|
+
return true;
|
|
1712
|
+
}
|
|
1713
|
+
endMarquee() {
|
|
1714
|
+
const drag = this.marqueeDrag;
|
|
1715
|
+
this.marqueeDrag = undefined;
|
|
1716
|
+
this._marquee = undefined;
|
|
1717
|
+
if (!drag)
|
|
1718
|
+
return;
|
|
1719
|
+
drag.element.removeEventListener('pointermove', this.onMarqueeMove);
|
|
1720
|
+
drag.element.removeEventListener('pointerup', this.onMarqueeUp);
|
|
1721
|
+
drag.element.removeEventListener('pointercancel', this.onMarqueeUp);
|
|
1722
|
+
try {
|
|
1723
|
+
if (drag.element.hasPointerCapture(drag.pointerId)) {
|
|
1724
|
+
drag.element.releasePointerCapture(drag.pointerId);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
catch {
|
|
1728
|
+
// The pointer is already gone.
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
// ── Render helpers
|
|
1732
|
+
renderNodeContent(node) {
|
|
1733
|
+
const legacy = this.legacyElement(node);
|
|
1734
|
+
if (legacy)
|
|
1735
|
+
return legacy;
|
|
1736
|
+
return b `<slot name=${`node:${node.id}`}>
|
|
1737
|
+
<div class="diagram-node-default-card">
|
|
1738
|
+
${node.icon
|
|
1739
|
+
? b `<span class="diagram-node-icon"
|
|
1740
|
+
><wc-icon name=${node.icon}></wc-icon
|
|
1741
|
+
></span>`
|
|
1742
|
+
: A}
|
|
1743
|
+
<span class="diagram-node-text">
|
|
1744
|
+
<span class="diagram-node-title">${this.nodeLabel(node)}</span>
|
|
1745
|
+
${node.supportingText
|
|
1746
|
+
? b `<span class="diagram-node-supporting"
|
|
1747
|
+
>${node.supportingText}</span
|
|
1748
|
+
>`
|
|
1749
|
+
: A}
|
|
1750
|
+
</span>
|
|
1751
|
+
</div>
|
|
1752
|
+
</slot>`;
|
|
1753
|
+
}
|
|
1754
|
+
renderNode(node, slotted) {
|
|
1755
|
+
const selected = this.selection.has('node', node.id);
|
|
1756
|
+
const position = this.nodePosition(node);
|
|
1757
|
+
const custom = !!this.legacyElement(node) || slotted.has(node.id);
|
|
1758
|
+
const connecting = !!this._connection;
|
|
1759
|
+
return b `
|
|
1760
|
+
<div
|
|
1761
|
+
class=${e$1({
|
|
1762
|
+
'diagram-node': true,
|
|
1763
|
+
'diagram-node-custom': custom,
|
|
1764
|
+
'is-dragging': this._draggingIds.includes(node.id),
|
|
1765
|
+
'is-selected': selected,
|
|
1766
|
+
'is-locked': !!node.locked,
|
|
1767
|
+
[`intent-${node.intent}`]: !!node.intent,
|
|
1768
|
+
})}
|
|
1769
|
+
data-id=${node.id}
|
|
1770
|
+
role="group"
|
|
1771
|
+
aria-roledescription=${this.i18n.t('diagramNode')}
|
|
1772
|
+
tabindex="0"
|
|
1773
|
+
aria-label=${this.nodeLabel(node)}
|
|
1774
|
+
aria-current=${selected ? 'true' : A}
|
|
1775
|
+
style="left: ${position.x}px; top: ${position.y}px;"
|
|
1776
|
+
@pointerdown=${(e) => this.onNodePointerDown(e, node)}
|
|
1777
|
+
@keydown=${(e) => this.onNodeKeyDown(e, node)}
|
|
1778
|
+
@focus=${() => {
|
|
1779
|
+
this.focusedId = node.id;
|
|
1780
|
+
}}
|
|
1781
|
+
>
|
|
1782
|
+
${this.resolvePorts(node).map(port => {
|
|
1783
|
+
const isSnap = this._connection?.snap?.nodeId === node.id &&
|
|
1784
|
+
this._connection.snap.port.id === port.id;
|
|
1785
|
+
const canTake = connecting &&
|
|
1786
|
+
this._connection?.fixedNode !== node.id &&
|
|
1787
|
+
(port.type === 'both' ||
|
|
1788
|
+
port.type ===
|
|
1789
|
+
(this._connection?.end === 'target' ? 'target' : 'source'));
|
|
1790
|
+
return b `<div
|
|
1791
|
+
class=${e$1({
|
|
1792
|
+
handle: true,
|
|
1793
|
+
'handle-input': port.type !== 'source',
|
|
1794
|
+
'handle-output': port.type !== 'target',
|
|
1795
|
+
[`handle-position-${port.side}`]: true,
|
|
1796
|
+
'is-snap': isSnap,
|
|
1797
|
+
'is-candidate': canTake,
|
|
1798
|
+
'is-ripple': this._ripple === `${node.id}\u0000${port.id}`,
|
|
1799
|
+
})}
|
|
1800
|
+
data-node-id=${node.id}
|
|
1801
|
+
data-port=${port.id}
|
|
1802
|
+
data-position=${port.side}
|
|
1803
|
+
style="--_offset: ${port.offset * 100}%"
|
|
1804
|
+
title=${port.label ?? A}
|
|
1805
|
+
@pointerdown=${(e) => this.onPortPointerDown(e, node, port)}
|
|
1806
|
+
></div>`;
|
|
1807
|
+
})}
|
|
1808
|
+
<div class="diagram-node-content">${this.renderNodeContent(node)}</div>
|
|
1809
|
+
</div>
|
|
1810
|
+
`;
|
|
1811
|
+
}
|
|
1812
|
+
renderMarkers(render) {
|
|
1813
|
+
const out = [];
|
|
1814
|
+
for (const [marker, at, angle] of [
|
|
1815
|
+
[render.markerEnd, render.end, render.geometry.endAngle],
|
|
1816
|
+
[render.markerStart, render.start, render.geometry.startAngle],
|
|
1817
|
+
]) {
|
|
1818
|
+
for (const shape of markerShapes(marker)) {
|
|
1819
|
+
out.push(w `<path class="diagram-marker fill-${shape.fill}" d=${shape.d} transform=${markerTransform(at, angle)}></path>`);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return out;
|
|
1823
|
+
}
|
|
1824
|
+
renderEdge(render, labels) {
|
|
1825
|
+
const { edge, geometry } = render;
|
|
1826
|
+
const selected = this.selection.has('edge', edge.id);
|
|
1827
|
+
const variant = edge.variant ?? 'solid';
|
|
1828
|
+
return w `
|
|
1829
|
+
<g
|
|
1830
|
+
class=${e$1({
|
|
1831
|
+
'diagram-edge-group': true,
|
|
1832
|
+
'is-selected': selected,
|
|
1833
|
+
'is-colored': !!edge.color,
|
|
1834
|
+
})}
|
|
1835
|
+
data-id=${edge.id}
|
|
1836
|
+
style=${edge.color ? `--_edge-color: ${edge.color}` : A}
|
|
1837
|
+
tabindex=${this.editable ? '0' : A}
|
|
1838
|
+
role=${this.editable ? 'button' : A}
|
|
1839
|
+
aria-label=${this.editable ? (labels.get(edge.id) ?? edge.id) : A}
|
|
1840
|
+
aria-pressed=${this.editable ? String(selected) : A}
|
|
1841
|
+
@pointerdown=${(e) => this.onEdgePointerDown(e, edge)}
|
|
1842
|
+
@keydown=${(e) => this.onEdgeKeyDown(e, edge)}
|
|
1843
|
+
>
|
|
1844
|
+
<path class="diagram-edge-hit" d=${geometry.d}></path>
|
|
1845
|
+
<path
|
|
1846
|
+
class=${e$1({
|
|
1847
|
+
'diagram-edge': true,
|
|
1848
|
+
'variant-dashed': variant === 'dashed' || variant === 'animated-dashed',
|
|
1849
|
+
'variant-animated-dashed': variant === 'animated-dashed',
|
|
1850
|
+
})}
|
|
1851
|
+
d=${geometry.d}
|
|
1852
|
+
></path>
|
|
1853
|
+
${this.renderMarkers(render)}
|
|
1854
|
+
</g>
|
|
1855
|
+
`;
|
|
1856
|
+
}
|
|
1857
|
+
renderConnectionPreview() {
|
|
1858
|
+
const c = this._connection;
|
|
1859
|
+
if (!c)
|
|
1860
|
+
return A;
|
|
1861
|
+
const movingSide = c.snap?.port.side ?? OPPOSITE_SIDE[c.fixedPort.side];
|
|
1862
|
+
const g = c.end === 'target'
|
|
1863
|
+
? edgeGeometry(this.connector, c.fixedPoint, c.fixedPort.side, c.pointer, movingSide)
|
|
1864
|
+
: edgeGeometry(this.connector, c.pointer, movingSide, c.fixedPoint, c.fixedPort.side);
|
|
1865
|
+
return w `<path class=${e$1({ 'diagram-edge-preview': true, 'is-snapped': !!c.snap })} d=${g.d}></path>`;
|
|
1866
|
+
}
|
|
1867
|
+
// ── Render
|
|
1868
|
+
render() {
|
|
1869
|
+
const { x, y, zoom } = this.viewport.view;
|
|
1870
|
+
const { width, height } = this.viewport.size();
|
|
1871
|
+
const cull = this.startApplied && width > 0 && height > 0;
|
|
1872
|
+
const visible = inflateRect(this.viewport.visibleRect(), CULL_MARGIN / zoom);
|
|
1873
|
+
const byId = new Map(this.nodes.map(n => [n.id, n]));
|
|
1874
|
+
const rects = new Map(this.nodes.map(n => [n.id, this.nodeRect(n)]));
|
|
1875
|
+
const keep = (n) => {
|
|
1876
|
+
if (!cull)
|
|
1877
|
+
return true;
|
|
1878
|
+
const r = rects.get(n.id);
|
|
1879
|
+
return ((r && rectsIntersect(r, visible)) ||
|
|
1880
|
+
this.selection.has('node', n.id) ||
|
|
1881
|
+
this.focusedId === n.id ||
|
|
1882
|
+
this._draggingIds.includes(n.id));
|
|
1883
|
+
};
|
|
1884
|
+
const shownNodes = this.nodes.filter(keep);
|
|
1885
|
+
const edgeLabels = new Map();
|
|
1886
|
+
const shownEdges = [];
|
|
1887
|
+
const edgeInView = (edge) => {
|
|
1888
|
+
const a = rects.get(edge.source);
|
|
1889
|
+
const b = rects.get(edge.target);
|
|
1890
|
+
if (!a || !b)
|
|
1891
|
+
return false;
|
|
1892
|
+
return !cull || rectsIntersect(boundsOf([a, b]), visible);
|
|
1893
|
+
};
|
|
1894
|
+
for (const edge of this.edges.filter(edgeInView)) {
|
|
1895
|
+
const render = this.edgeRender(edge, byId);
|
|
1896
|
+
if (render)
|
|
1897
|
+
shownEdges.push(render);
|
|
1898
|
+
const from = byId.get(edge.source);
|
|
1899
|
+
const to = byId.get(edge.target);
|
|
1900
|
+
edgeLabels.set(edge.id, this.i18n.t('diagramEdgeLabel')(from ? this.nodeLabel(from) : edge.source, to ? this.nodeLabel(to) : edge.target, edge.label));
|
|
1901
|
+
}
|
|
1902
|
+
const slotted = new Set();
|
|
1903
|
+
for (const child of Array.from(this.children)) {
|
|
1904
|
+
const slot = child.getAttribute('slot');
|
|
1905
|
+
if (slot?.startsWith('node:'))
|
|
1906
|
+
slotted.add(slot.slice(5));
|
|
1907
|
+
}
|
|
1908
|
+
const selectedEdges = this.editable
|
|
1909
|
+
? shownEdges.filter(r => this.selection.has('edge', r.edge.id))
|
|
1910
|
+
: [];
|
|
1911
|
+
const marquee = this._marquee
|
|
1912
|
+
? rectFromPoints(this._marquee.start, this._marquee.end)
|
|
1913
|
+
: undefined;
|
|
1914
|
+
return b `
|
|
1915
|
+
<div
|
|
1916
|
+
class=${e$1({
|
|
1917
|
+
'diagram-viewport': true,
|
|
1918
|
+
'is-panning': this.viewport.panning,
|
|
1919
|
+
'is-space': this.viewport.spaceHeld,
|
|
1920
|
+
'is-connecting': !!this._connection,
|
|
1921
|
+
})}
|
|
1922
|
+
tabindex="0"
|
|
1923
|
+
role="region"
|
|
1924
|
+
aria-label=${this.label || this.i18n.t('diagramLabel')}
|
|
1925
|
+
aria-describedby="instructions"
|
|
1926
|
+
style=${this.gridStyle()}
|
|
1927
|
+
@keydown=${this.onViewportKeyDown}
|
|
1928
|
+
>
|
|
1929
|
+
<div
|
|
1930
|
+
class="diagram-world"
|
|
1931
|
+
style="transform: translate(${x}px, ${y}px) scale(${zoom});"
|
|
1932
|
+
>
|
|
1933
|
+
<svg class="diagram-svg" width="1" height="1" aria-hidden="true">
|
|
1934
|
+
${shownEdges.map(r => this.renderEdge(r, edgeLabels))}
|
|
1935
|
+
${this.renderConnectionPreview()}
|
|
1936
|
+
${this._guides.map(g => w `<line class="diagram-guide" x1=${g.x1} y1=${g.y1} x2=${g.x2} y2=${g.y2}></line>`)}
|
|
1937
|
+
</svg>
|
|
1938
|
+
<div class="diagram-nodes" @slotchange=${() => this.requestUpdate()}>
|
|
1939
|
+
${c(shownNodes, node => node.id, node => this.renderNode(node, slotted))}
|
|
1940
|
+
</div>
|
|
1941
|
+
${shownEdges
|
|
1942
|
+
.filter(r => r.edge.label)
|
|
1943
|
+
.map(r => b `<div
|
|
1944
|
+
class=${e$1({
|
|
1945
|
+
'diagram-edge-label': true,
|
|
1946
|
+
'is-selected': this.selection.has('edge', r.edge.id),
|
|
1947
|
+
})}
|
|
1948
|
+
style="left: ${r.geometry.mid.x}px; top: ${r.geometry.mid
|
|
1949
|
+
.y}px;"
|
|
1950
|
+
@pointerdown=${(e) => this.onEdgePointerDown(e, r.edge)}
|
|
1951
|
+
>
|
|
1952
|
+
${r.edge.label}
|
|
1953
|
+
</div>`)}
|
|
1954
|
+
${selectedEdges.map(r => b `
|
|
1955
|
+
<div
|
|
1956
|
+
class="edge-end"
|
|
1957
|
+
style="left: ${r.start.x}px; top: ${r.start.y}px;"
|
|
1958
|
+
@pointerdown=${(e) => this.startReconnect(e, r.edge, 'source')}
|
|
1959
|
+
></div>
|
|
1960
|
+
<div
|
|
1961
|
+
class="edge-end"
|
|
1962
|
+
style="left: ${r.end.x}px; top: ${r.end.y}px;"
|
|
1963
|
+
@pointerdown=${(e) => this.startReconnect(e, r.edge, 'target')}
|
|
1964
|
+
></div>
|
|
1965
|
+
`)}
|
|
1966
|
+
</div>
|
|
1967
|
+
${marquee
|
|
1968
|
+
? b `<div
|
|
1969
|
+
class="diagram-marquee"
|
|
1970
|
+
style="left: ${marquee.x}px; top: ${marquee.y}px; width: ${marquee.width}px; height: ${marquee.height}px;"
|
|
1971
|
+
></div>`
|
|
1972
|
+
: A}
|
|
1973
|
+
${this.renderBackToContent()}
|
|
1974
|
+
<div class="slot-controls"><slot name="controls"></slot></div>
|
|
1975
|
+
<div class="slot-minimap"><slot name="minimap"></slot></div>
|
|
1976
|
+
<div id="instructions" hidden>
|
|
1977
|
+
${this.i18n.t('diagramInstructions')}
|
|
1978
|
+
</div>
|
|
1979
|
+
<div class="sr-only" aria-live="polite">${this._announcement}</div>
|
|
1980
|
+
</div>
|
|
1981
|
+
`;
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1984
|
+
Diagram.styles = [css_248z];
|
|
1985
|
+
__decorate([
|
|
1986
|
+
n({ type: Array })
|
|
1987
|
+
], Diagram.prototype, "nodes", void 0);
|
|
1988
|
+
__decorate([
|
|
1989
|
+
n({ type: Array })
|
|
1990
|
+
], Diagram.prototype, "edges", void 0);
|
|
1991
|
+
__decorate([
|
|
1992
|
+
n({ type: String, reflect: true })
|
|
1993
|
+
], Diagram.prototype, "selected", void 0);
|
|
1994
|
+
__decorate([
|
|
1995
|
+
n({ type: String, reflect: true })
|
|
1996
|
+
], Diagram.prototype, "connector", void 0);
|
|
1997
|
+
__decorate([
|
|
1998
|
+
n({ type: Boolean, attribute: 'snap-to-grid' })
|
|
1999
|
+
], Diagram.prototype, "snapToGrid", void 0);
|
|
2000
|
+
__decorate([
|
|
2001
|
+
r()
|
|
2002
|
+
], Diagram.prototype, "_connection", void 0);
|
|
2003
|
+
__decorate([
|
|
2004
|
+
r()
|
|
2005
|
+
], Diagram.prototype, "_marquee", void 0);
|
|
2006
|
+
__decorate([
|
|
2007
|
+
r()
|
|
2008
|
+
], Diagram.prototype, "_guides", void 0);
|
|
2009
|
+
__decorate([
|
|
2010
|
+
r()
|
|
2011
|
+
], Diagram.prototype, "_draggingIds", void 0);
|
|
2012
|
+
__decorate([
|
|
2013
|
+
r()
|
|
2014
|
+
], Diagram.prototype, "_announcement", void 0);
|
|
2015
|
+
__decorate([
|
|
2016
|
+
r()
|
|
2017
|
+
], Diagram.prototype, "_ripple", void 0);
|
|
2018
|
+
__decorate([
|
|
2019
|
+
e('.diagram-viewport')
|
|
2020
|
+
], Diagram.prototype, "_viewportEl", void 0);
|
|
2021
|
+
Diagram = __decorate([
|
|
2022
|
+
IndividualComponent
|
|
2023
|
+
], Diagram);
|
|
2024
|
+
// Nodes are measured after they render and the camera is placed from those sizes, so a second
|
|
2025
|
+
// update right after the first is expected. Lit warns about that in development builds.
|
|
2026
|
+
Diagram.disableWarning?.('change-in-update');
|
|
2027
|
+
|
|
2028
|
+
export { Diagram as D, deprecate as d };
|
|
2029
|
+
//# sourceMappingURL=diagram-Va096vj9.js.map
|