@redvars/peacock 4.0.0 → 4.1.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-BMumJpkW.js} +6 -3
- package/dist/BaseField-BMumJpkW.js.map +1 -0
- package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-mWdyYv27.js} +6 -3
- package/dist/BaseInput-mWdyYv27.js.map +1 -0
- package/dist/accordion.js.map +1 -1
- package/dist/ai-badge.js +2 -2
- 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-CvLVSjuy.js} +4 -2
- package/dist/base-progress-CvLVSjuy.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 +3 -3
- package/dist/calendar.js +2 -2
- package/dist/canvas-base-BTQMEVn_.js +788 -0
- package/dist/canvas-base-BTQMEVn_.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-DM1FC_XT.js} +3 -2
- package/dist/cartesian-chart-DM1FC_XT.js.map +1 -0
- package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-B6fa4Lll.js} +2 -2
- package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-B6fa4Lll.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-Dhxuw_Mw.js +833 -0
- package/dist/chart-base-Dhxuw_Mw.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-message.js +2 -2
- package/dist/chat-thread.js +2 -2
- package/dist/checkbox-group.js +4 -4
- package/dist/checkbox.js +4 -4
- package/dist/chip-set.js +3 -3
- package/dist/chip.js +4 -4
- package/dist/circular-progress.js +3 -3
- package/dist/citation.js +2 -2
- package/dist/code-editor.js +5 -4
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +2 -2
- package/dist/color-field.js +5 -5
- package/dist/color-picker.js +2 -2
- package/dist/command-palette.js +2 -2
- package/dist/comment-composer.js +5 -5
- 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 +5 -5
- package/dist/custom-elements-jsdocs.json +2115 -336
- package/dist/custom-elements.json +19483 -615
- package/dist/date-field.js +6 -6
- package/dist/date-picker.js +4 -2
- package/dist/date-picker.js.map +1 -1
- package/dist/date-range-field.js +6 -6
- package/dist/datetime-field.js +6 -6
- 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-2r11KySs.js +2029 -0
- package/dist/diagram-2r11KySs.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 +2 -2
- package/dist/discussion-comment.js +2 -2
- package/dist/discussion.js +5 -5
- package/dist/{document-editor-BO7QPbO5.js → document-editor-BnEugM3E.js} +2 -2
- package/dist/{document-editor-BO7QPbO5.js.map → document-editor-BnEugM3E.js.map} +1 -1
- package/dist/document-editor.js +3 -3
- package/dist/draft-card.js +2 -2
- 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 +37 -15
- 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 +2 -2
- package/dist/{generative-view-DmtpDobn.js → generative-view-BgOcLRXr.js} +13 -13
- package/dist/generative-view-BgOcLRXr.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 +5 -5
- 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-Cp43HjJl.js} +2 -2
- package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-Cp43HjJl.js.map} +1 -1
- package/dist/icon-button.js +4 -4
- package/dist/image.js +2 -2
- package/dist/index.js +37 -18
- package/dist/index.js.map +1 -1
- package/dist/inline-edit.js +2 -2
- package/dist/input.js +4 -4
- 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 +2 -2
- package/dist/list-item.js +2 -2
- package/dist/list.js +2 -2
- package/dist/listbox.js +3 -3
- package/dist/loader-full.js +13 -13
- package/dist/loader.js +44 -15
- package/dist/loader.js.map +1 -1
- package/dist/markdown-editor.js +5 -5
- 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 +6 -5
- 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.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 +2 -2
- package/dist/number-field.js +6 -5
- 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 +5 -5
- package/dist/password-rules.js +2 -2
- package/dist/phone-field.js +5 -5
- package/dist/{picker-field-B4DtcJfL.js → picker-field-dTlIMAQn.js} +3 -3
- package/dist/{picker-field-B4DtcJfL.js.map → picker-field-dTlIMAQn.js.map} +1 -1
- package/dist/pin-input.js +5 -5
- package/dist/presence-indicator.js +2 -2
- package/dist/prompt-input.js +5 -5
- package/dist/radio-group.js +1 -0
- package/dist/radio-group.js.map +1 -1
- package/dist/radio.js +5 -5
- package/dist/radio.js.map +1 -1
- package/dist/rating.js +5 -4
- package/dist/rating.js.map +1 -1
- package/dist/redvars-loader.js +2 -2
- package/dist/relative-time.js +2 -2
- package/dist/resizable-panels.js +2 -2
- package/dist/{rich-text-input-DLICqof1.js → rich-text-input-DM_BOzgk.js} +3 -3
- package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-DM_BOzgk.js.map} +1 -1
- package/dist/ripple.js +2 -0
- package/dist/ripple.js.map +1 -1
- package/dist/{schema-hMt-NRLk.js → schema-B8g30A_n.js} +2 -2
- package/dist/{schema-hMt-NRLk.js.map → schema-B8g30A_n.js.map} +1 -1
- package/dist/search.js +4 -4
- package/dist/segmented-button-group.js +1 -1
- package/dist/select.js +7 -7
- package/dist/side-sheet.js +2 -2
- package/dist/signature-pad.js +5 -4
- package/dist/signature-pad.js.map +1 -1
- package/dist/slider.js +5 -4
- package/dist/slider.js.map +1 -1
- package/dist/snackbar.js +2 -2
- package/dist/sparkline.js +2 -2
- package/dist/split-button.js +2 -2
- 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 +149 -0
- package/dist/src/__internal/toggle-base.d.ts +8 -0
- package/dist/src/__internal/utils/deprecate.d.ts +3 -3
- package/dist/src/accordion/accordion.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 +15 -2
- package/dist/src/input/BaseField.d.ts +3 -0
- package/dist/src/input/BaseInput.d.ts +3 -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/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 +1 -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-BJPuhKJk.js} +163 -1
- package/dist/{strings-DmbqMTfs.js.map → strings-BJPuhKJk.js.map} +1 -1
- package/dist/sub-menu.js +2 -2
- package/dist/svg.js +2 -2
- package/dist/switch.js +5 -4
- package/dist/switch.js.map +1 -1
- package/dist/tab.js +1 -0
- package/dist/tab.js.map +1 -1
- package/dist/table.js +2 -2
- 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 +7 -5
- package/dist/textarea.js.map +1 -1
- package/dist/time-field.js +6 -6
- 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-BlaHalfS.js} +19 -3
- package/dist/toggle-base-BlaHalfS.js.map +1 -0
- package/dist/tour.js +2 -2
- package/dist/transfer-list.js +5 -4
- 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 +5 -5
- package/dist/user-menu.js +2 -2
- 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 +2 -2
- package/package.json +1 -1
- package/readme.md +44 -2
- package/src/LoaderUtils.ts +9 -2
- 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 +201 -0
- 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/accordion/accordion.ts +1 -0
- package/src/button/base-button/base-button.ts +2 -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/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 +121 -2
- package/src/input/BaseField.ts +3 -0
- package/src/input/BaseInput.ts +3 -0
- package/src/loader.ts +25 -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/switch/switch.ts +1 -0
- 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 +1 -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/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,1170 @@
|
|
|
1
|
+
import { html, nothing, svg, type PropertyValues } from 'lit';
|
|
2
|
+
import { property, query, state } from 'lit/decorators.js';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
|
+
import { repeat } from 'lit/directives/repeat.js';
|
|
5
|
+
import IndividualComponent from '@/IndividualComponent.js';
|
|
6
|
+
import { DiagramCanvasElement } from '@/__internal/diagram/canvas-base.js';
|
|
7
|
+
import { MeasureController } from '@/__internal/diagram/measure-controller.js';
|
|
8
|
+
import { boundsOf, roundedPath } from '@/__internal/diagram/geometry.js';
|
|
9
|
+
import { History } from '@/__internal/diagram/history.js';
|
|
10
|
+
import {
|
|
11
|
+
easeOutCubic,
|
|
12
|
+
prefersReducedMotion,
|
|
13
|
+
tween,
|
|
14
|
+
} from '@/__internal/diagram/motion.js';
|
|
15
|
+
import type { DiagramOverview } from '@/__internal/diagram/host.js';
|
|
16
|
+
import type {
|
|
17
|
+
DiagramPoint,
|
|
18
|
+
DiagramRect,
|
|
19
|
+
DiagramView,
|
|
20
|
+
DiagramViewportDetail,
|
|
21
|
+
} from '@/__internal/diagram/types.js';
|
|
22
|
+
import {
|
|
23
|
+
layoutTree,
|
|
24
|
+
linkPoints,
|
|
25
|
+
type LayoutInput,
|
|
26
|
+
type LayoutOptions,
|
|
27
|
+
} from './tree-chart-layout.js';
|
|
28
|
+
import styles from './tree-chart.scss';
|
|
29
|
+
|
|
30
|
+
export type TreeChartOrientation = 'vertical' | 'horizontal';
|
|
31
|
+
|
|
32
|
+
export type TreeChartAccent =
|
|
33
|
+
| 'primary'
|
|
34
|
+
| 'tertiary'
|
|
35
|
+
| 'blue'
|
|
36
|
+
| 'green'
|
|
37
|
+
| 'orange'
|
|
38
|
+
| 'purple'
|
|
39
|
+
| 'red'
|
|
40
|
+
| 'yellow'
|
|
41
|
+
| 'neutral';
|
|
42
|
+
|
|
43
|
+
/** One box in the tree. Items refer to their parent, so rows from a database work as they are. */
|
|
44
|
+
export interface TreeChartItem {
|
|
45
|
+
id: string;
|
|
46
|
+
/** The parent's id; leave it out (or point it at a missing id) for a root. */
|
|
47
|
+
parentId?: string | null;
|
|
48
|
+
headline: string;
|
|
49
|
+
supportingText?: string;
|
|
50
|
+
/** An image URL for the avatar. Without it, and without `icon`, the avatar shows initials. */
|
|
51
|
+
avatar?: string;
|
|
52
|
+
/** Material Symbols name, shown in a tinted tile instead of an avatar. */
|
|
53
|
+
icon?: string;
|
|
54
|
+
accent?: TreeChartAccent;
|
|
55
|
+
/** A short chip, such as a department. */
|
|
56
|
+
badge?: string;
|
|
57
|
+
/** Has children that are not loaded yet: expanding it fires `expand` so you can add them. */
|
|
58
|
+
hasChildren?: boolean;
|
|
59
|
+
/** Starts collapsed. */
|
|
60
|
+
collapsed?: boolean;
|
|
61
|
+
/** Your own data, kept with the item. */
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type TreeChartChangeReason = 'move' | 'add' | 'remove' | 'undo' | 'redo';
|
|
66
|
+
|
|
67
|
+
/** Detail of `change`. */
|
|
68
|
+
export interface TreeChartChangeDetail {
|
|
69
|
+
items: TreeChartItem[];
|
|
70
|
+
reason: TreeChartChangeReason;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Detail of `select`, `expand` and `collapse`. */
|
|
74
|
+
export interface TreeChartItemDetail {
|
|
75
|
+
id: string;
|
|
76
|
+
item: TreeChartItem;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Detail of `reparent`. */
|
|
80
|
+
export interface TreeChartReparentDetail {
|
|
81
|
+
id: string;
|
|
82
|
+
parentId: string | null;
|
|
83
|
+
previousParentId: string | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Detail of `add`. */
|
|
87
|
+
export interface TreeChartAddDetail {
|
|
88
|
+
/** The parent the new item gets. */
|
|
89
|
+
parentId: string | null;
|
|
90
|
+
/** Whether it was added below (`child`) or beside (`sibling`) the item `of`. */
|
|
91
|
+
position: 'child' | 'sibling';
|
|
92
|
+
of: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Detail of `delete`. */
|
|
96
|
+
export interface TreeChartDeleteDetail {
|
|
97
|
+
ids: string[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Detail of `viewport-change`. */
|
|
101
|
+
export type TreeChartViewportDetail = DiagramViewportDetail;
|
|
102
|
+
|
|
103
|
+
const DEFAULT_SIZE = { width: 240, height: 72 };
|
|
104
|
+
|
|
105
|
+
/** Below this zoom a fitted tree is hard to read, so it starts at its root instead. */
|
|
106
|
+
const MIN_FIT_ZOOM = 0.5;
|
|
107
|
+
|
|
108
|
+
const DRAG_THRESHOLD = 5;
|
|
109
|
+
|
|
110
|
+
const INTERACTIVE = 'button, a, input, wc-icon-button, wc-button';
|
|
111
|
+
|
|
112
|
+
const LAYOUT: Omit<LayoutOptions, 'orientation' | 'compact'> = {
|
|
113
|
+
siblingGap: 32,
|
|
114
|
+
levelGap: 64,
|
|
115
|
+
stackGap: 12,
|
|
116
|
+
stackIndent: 20,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @label Tree chart
|
|
121
|
+
* @tag wc-tree-chart
|
|
122
|
+
* @rawTag tree-chart
|
|
123
|
+
* @summary A hierarchy laid out as a tidy tree on an infinite canvas: org charts, taxonomies, sitemaps, decision trees.
|
|
124
|
+
*
|
|
125
|
+
* @overview
|
|
126
|
+
* <p>Set <code>items</code> to a flat list where each item names its <code>parentId</code>; the chart lays
|
|
127
|
+
* the tree out with each card's real size. Top to bottom by default, or left to right with
|
|
128
|
+
* <code>orientation="horizontal"</code>. <code>compact</code> stacks teams with no further levels in a
|
|
129
|
+
* column under their manager, which keeps wide organisations narrow.</p>
|
|
130
|
+
* <p>A card shows an avatar (or an <code>icon</code>), a headline, supporting text and a
|
|
131
|
+
* <code>badge</code>. Put your own card in <code>slot="item:<id>"</code>. The chip under a card
|
|
132
|
+
* shows how many items are below it and expands or collapses them (<code>expand</code> and
|
|
133
|
+
* <code>collapse</code> fire). For lazy loading, give an item <code>hasChildren</code> and add its
|
|
134
|
+
* children when it fires <code>expand</code>; it shows a spinner until they arrive.</p>
|
|
135
|
+
* <p><code>search(text)</code> expands the way to every match, highlights the path from the root and
|
|
136
|
+
* dims the rest, and zooms to the first match; <code>clearSearch()</code> undoes it.</p>
|
|
137
|
+
* <p>With <code>editable</code>, drag a card onto another to change its parent (never into its own
|
|
138
|
+
* branch), add an item below or beside with the buttons on a card, and delete with Delete, which
|
|
139
|
+
* moves the item's children up to its parent. <code>reparent</code>, <code>add</code> and
|
|
140
|
+
* <code>delete</code> fire first and can be canceled; every edit then fires <code>change</code> with the
|
|
141
|
+
* new <code>items</code>. Undo with Ctrl+Z. Expanding, collapsing and edits glide.</p>
|
|
142
|
+
* <p>The tree follows the WAI-ARIA tree pattern with one tab stop. In a vertical chart Up goes to the
|
|
143
|
+
* parent, Down to the first child, Left and Right to siblings (mirrored in right-to-left); a
|
|
144
|
+
* horizontal chart turns the keys. Home and End go to the first and last item, <code>*</code> expands
|
|
145
|
+
* all siblings, Enter selects and Shift + Enter expands or collapses. The canvas is infinite like
|
|
146
|
+
* <code>wc-diagram</code>, with the <code>controls</code> and <code>minimap</code> slots.</p>
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```html
|
|
150
|
+
* <wc-tree-chart id="org" style="height: 500px"></wc-tree-chart>
|
|
151
|
+
* <script>
|
|
152
|
+
* document.getElementById('org').items = [
|
|
153
|
+
* { id: 'ceo', headline: 'Sarah Jenkins', supportingText: 'CEO' },
|
|
154
|
+
* { id: 'cto', parentId: 'ceo', headline: 'Michael Chen', supportingText: 'CTO', badge: 'Engineering' },
|
|
155
|
+
* { id: 'cpo', parentId: 'ceo', headline: 'Elena Rostova', supportingText: 'CPO', badge: 'Product' }
|
|
156
|
+
* ];
|
|
157
|
+
* </script>
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @slot controls - A `wc-diagram-controls`, shown at the bottom start corner.
|
|
161
|
+
* @slot minimap - A `wc-diagram-minimap`, shown at the bottom end corner.
|
|
162
|
+
* @slot item:<id> - Custom content for the item with that id, in place of the built-in card.
|
|
163
|
+
*
|
|
164
|
+
* @fires {CustomEvent<TreeChartItemDetail>} select - An item was chosen with a click, Enter or Space. Detail contains `{ id, item }`.
|
|
165
|
+
* @fires {CustomEvent<TreeChartItemDetail>} expand - An item was expanded. Add its children now when they load lazily. Detail contains `{ id, item }`.
|
|
166
|
+
* @fires {CustomEvent<TreeChartItemDetail>} collapse - An item was collapsed. Detail contains `{ id, item }`.
|
|
167
|
+
* @fires {CustomEvent<TreeChartReparentDetail>} reparent - Before a dragged item gets a new parent. Cancel it to keep it where it was. Detail contains `{ id, parentId, previousParentId }`.
|
|
168
|
+
* @fires {CustomEvent<TreeChartAddDetail>} add - Before a new item is added with a card's buttons. Cancel it to add the item your own way. Detail contains `{ parentId, position, of }`.
|
|
169
|
+
* @fires {CustomEvent<TreeChartDeleteDetail>} delete - Before an item is removed. Cancel it to keep it. Detail contains `{ ids }`.
|
|
170
|
+
* @fires {CustomEvent<TreeChartChangeDetail>} change - After every edit. Detail contains `{ items, reason }`.
|
|
171
|
+
* @fires {CustomEvent<TreeChartViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
|
|
172
|
+
*
|
|
173
|
+
* @cssprop --tree-chart-connector-color - Colour of connectors. Defaults to a mix of primary and outline-variant.
|
|
174
|
+
* @cssprop --tree-chart-background - Canvas background. Defaults to surface-container-lowest.
|
|
175
|
+
* @tags data
|
|
176
|
+
*/
|
|
177
|
+
@IndividualComponent
|
|
178
|
+
export class TreeChart extends DiagramCanvasElement {
|
|
179
|
+
// ── Static
|
|
180
|
+
|
|
181
|
+
static styles = [styles];
|
|
182
|
+
|
|
183
|
+
// ── Properties
|
|
184
|
+
|
|
185
|
+
/** The items, each naming its parent. Replaced with a new array, never mutated, on every edit. */
|
|
186
|
+
@property({ attribute: false })
|
|
187
|
+
items: TreeChartItem[] = [];
|
|
188
|
+
|
|
189
|
+
/** Lays the tree out top to bottom or left to right. */
|
|
190
|
+
@property({ type: String, reflect: true })
|
|
191
|
+
orientation: TreeChartOrientation = 'vertical';
|
|
192
|
+
|
|
193
|
+
/** Stacks children that have no children of their own in a column (vertical charts). */
|
|
194
|
+
@property({ type: Boolean, reflect: true })
|
|
195
|
+
compact = false;
|
|
196
|
+
|
|
197
|
+
/** Id of the selected item. */
|
|
198
|
+
@property({ type: String, reflect: true })
|
|
199
|
+
selected = '';
|
|
200
|
+
|
|
201
|
+
// ── State
|
|
202
|
+
|
|
203
|
+
@state()
|
|
204
|
+
private _collapsed = new Set<string>();
|
|
205
|
+
|
|
206
|
+
@state()
|
|
207
|
+
private _loading = new Set<string>();
|
|
208
|
+
|
|
209
|
+
@state()
|
|
210
|
+
private _focusId = '';
|
|
211
|
+
|
|
212
|
+
@state()
|
|
213
|
+
private _matches = new Set<string>();
|
|
214
|
+
|
|
215
|
+
@state()
|
|
216
|
+
private _path = new Set<string>();
|
|
217
|
+
|
|
218
|
+
@state()
|
|
219
|
+
private _drag?: { id: string; x: number; y: number; target?: string };
|
|
220
|
+
|
|
221
|
+
@state()
|
|
222
|
+
private _announcement = '';
|
|
223
|
+
|
|
224
|
+
// ── Private fields
|
|
225
|
+
|
|
226
|
+
@query('.tc-viewport')
|
|
227
|
+
private readonly _viewportEl?: HTMLElement;
|
|
228
|
+
|
|
229
|
+
private readonly measure = new MeasureController(this, {
|
|
230
|
+
elements: () => this.nodeElements(),
|
|
231
|
+
fallback: DEFAULT_SIZE,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
private readonly history = new History<TreeChartItem[]>();
|
|
235
|
+
|
|
236
|
+
private readonly handledKeys = new WeakSet<Event>();
|
|
237
|
+
|
|
238
|
+
private byId = new Map<string, TreeChartItem>();
|
|
239
|
+
|
|
240
|
+
private childMap = new Map<string, string[]>();
|
|
241
|
+
|
|
242
|
+
private roots: string[] = [];
|
|
243
|
+
|
|
244
|
+
private seenCollapsed = new Set<string>();
|
|
245
|
+
|
|
246
|
+
/** Laid-out positions from the last render. */
|
|
247
|
+
private positions = new Map<string, DiagramPoint>();
|
|
248
|
+
|
|
249
|
+
private stacked = new Set<string>();
|
|
250
|
+
|
|
251
|
+
private overrides = new Map<string, DiagramPoint>();
|
|
252
|
+
|
|
253
|
+
private glideFrom?: { positions: Map<string, DiagramPoint>; anchor?: string };
|
|
254
|
+
|
|
255
|
+
private stopGlide?: () => void;
|
|
256
|
+
|
|
257
|
+
private pendingZoom?: string;
|
|
258
|
+
|
|
259
|
+
private nodeDrag?: {
|
|
260
|
+
pointerId: number;
|
|
261
|
+
startX: number;
|
|
262
|
+
startY: number;
|
|
263
|
+
id: string;
|
|
264
|
+
element: HTMLElement;
|
|
265
|
+
moved: boolean;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// ── Lifecycle
|
|
269
|
+
|
|
270
|
+
disconnectedCallback() {
|
|
271
|
+
super.disconnectedCallback();
|
|
272
|
+
this.stopGlide?.();
|
|
273
|
+
this.endDrag(false);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
protected willUpdate(changed: PropertyValues<this>) {
|
|
277
|
+
super.willUpdate(changed);
|
|
278
|
+
if (changed.has('items')) this.indexItems();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
protected updated(changed: PropertyValues<this>) {
|
|
282
|
+
this.playGlide();
|
|
283
|
+
if (this.pendingZoom) {
|
|
284
|
+
const id = this.pendingZoom;
|
|
285
|
+
this.pendingZoom = undefined;
|
|
286
|
+
this.zoomTo(id);
|
|
287
|
+
}
|
|
288
|
+
super.updated(changed);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ── Public API
|
|
292
|
+
|
|
293
|
+
/** Whether `undo()` has something to undo. */
|
|
294
|
+
get canUndo(): boolean {
|
|
295
|
+
return this.history.canUndo;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Whether `redo()` has something to redo. */
|
|
299
|
+
get canRedo(): boolean {
|
|
300
|
+
return this.history.canRedo;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
undo() {
|
|
304
|
+
const previous = this.history.undo(this.items);
|
|
305
|
+
if (previous) this.commit(previous, 'undo', false);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
redo() {
|
|
309
|
+
const next = this.history.redo(this.items);
|
|
310
|
+
if (next) this.commit(next, 'redo', false);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** Forgets the undo and redo history. */
|
|
314
|
+
clearHistory() {
|
|
315
|
+
this.history.clear();
|
|
316
|
+
this.listeners.notify();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
expand(id: string) {
|
|
320
|
+
const item = this.byId.get(id);
|
|
321
|
+
if (!item || !this._collapsed.has(id)) {
|
|
322
|
+
if (item?.hasChildren && !this.childMap.get(id)?.length)
|
|
323
|
+
this.requestChildren(item);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
this.glide(() => {
|
|
327
|
+
const next = new Set(this._collapsed);
|
|
328
|
+
next.delete(id);
|
|
329
|
+
this._collapsed = next;
|
|
330
|
+
}, id);
|
|
331
|
+
if (item.hasChildren && !this.childMap.get(id)?.length)
|
|
332
|
+
this.requestChildren(item);
|
|
333
|
+
else this.emit<TreeChartItemDetail>('expand', { id, item });
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
collapse(id: string) {
|
|
337
|
+
const item = this.byId.get(id);
|
|
338
|
+
if (!item || this._collapsed.has(id) || !this.hasKids(id)) return;
|
|
339
|
+
this.glide(() => {
|
|
340
|
+
const next = new Set(this._collapsed);
|
|
341
|
+
next.add(id);
|
|
342
|
+
this._collapsed = next;
|
|
343
|
+
}, id);
|
|
344
|
+
this.emit<TreeChartItemDetail>('collapse', { id, item });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Expands every item. */
|
|
348
|
+
expandAll() {
|
|
349
|
+
this.glide(() => {
|
|
350
|
+
this._collapsed = new Set();
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Highlights the items whose headline, supporting text or badge contains `text`, expands the way
|
|
356
|
+
* to them, dims the rest and zooms to the first. Returns the ids of the matches.
|
|
357
|
+
*/
|
|
358
|
+
search(text: string): string[] {
|
|
359
|
+
const needle = text.trim().toLowerCase();
|
|
360
|
+
if (!needle) {
|
|
361
|
+
this.clearSearch();
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
const matches = this.items
|
|
365
|
+
.filter(i =>
|
|
366
|
+
[i.headline, i.supportingText, i.badge].some(v =>
|
|
367
|
+
v?.toLowerCase().includes(needle),
|
|
368
|
+
),
|
|
369
|
+
)
|
|
370
|
+
.map(i => i.id);
|
|
371
|
+
const path = new Set<string>();
|
|
372
|
+
const collapsed = new Set(this._collapsed);
|
|
373
|
+
for (const id of matches) {
|
|
374
|
+
let cursor: string | undefined = id;
|
|
375
|
+
while (cursor) {
|
|
376
|
+
path.add(cursor);
|
|
377
|
+
const parent = this.parentOf(cursor);
|
|
378
|
+
if (parent) collapsed.delete(parent);
|
|
379
|
+
cursor = parent;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
this._collapsed = collapsed;
|
|
383
|
+
this._matches = new Set(matches);
|
|
384
|
+
this._path = path;
|
|
385
|
+
this.announce(this.i18n.t('treeChartMatches')(matches.length));
|
|
386
|
+
const [first] = matches;
|
|
387
|
+
if (first) this.pendingZoom = first;
|
|
388
|
+
return matches;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
clearSearch() {
|
|
392
|
+
this._matches = new Set();
|
|
393
|
+
this._path = new Set();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Selects an item, fires `select`, and brings it into view. */
|
|
397
|
+
selectItem(id: string) {
|
|
398
|
+
const item = this.byId.get(id);
|
|
399
|
+
if (!item) return;
|
|
400
|
+
this.select(item);
|
|
401
|
+
this.focusItem(id);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Moves keyboard focus to an item and pans it into view. */
|
|
405
|
+
focusItem(id: string) {
|
|
406
|
+
this._focusId = id;
|
|
407
|
+
this.updateComplete.then(() => {
|
|
408
|
+
this.nodeElement(id)?.focus({ preventScroll: true });
|
|
409
|
+
this.keepInView(id);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// ── Canvas hooks
|
|
414
|
+
|
|
415
|
+
protected viewportElement() {
|
|
416
|
+
return this._viewportEl;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
protected contentBounds(): DiagramRect | undefined {
|
|
420
|
+
return boundsOf([...this.positions.keys()].map(id => this.rectOf(id)));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
protected selectionRects(): DiagramRect[] {
|
|
424
|
+
return this.selected && this.positions.has(this.selected)
|
|
425
|
+
? [this.rectOf(this.selected)]
|
|
426
|
+
: [];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
protected itemRect(id: string): DiagramRect | undefined {
|
|
430
|
+
return this.positions.has(id) ? this.rectOf(id) : undefined;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
protected firstItemRect(): DiagramRect | undefined {
|
|
434
|
+
return this.roots[0] && this.positions.has(this.roots[0])
|
|
435
|
+
? this.rectOf(this.roots[0])
|
|
436
|
+
: undefined;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
protected overviewItems(): DiagramOverview['items'] {
|
|
440
|
+
return [...this.positions.keys()].map(id => ({
|
|
441
|
+
...this.rectOf(id),
|
|
442
|
+
selected: id === this.selected,
|
|
443
|
+
}));
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
protected isBackground(target: EventTarget | null): boolean {
|
|
447
|
+
const el = target as Element | null;
|
|
448
|
+
if (!el) return false;
|
|
449
|
+
return (
|
|
450
|
+
el === this._viewportEl ||
|
|
451
|
+
['tc-world', 'tc-links', 'tc-nodes'].some(c => el.classList?.contains(c))
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
protected onBackgroundClick() {
|
|
456
|
+
this.selected = '';
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** Fits the tree, or shows its root at 50% when fitting it all would be too small to read. */
|
|
460
|
+
protected computeStartView(): DiagramView {
|
|
461
|
+
if (this.startView || this.startPosition !== 'fit')
|
|
462
|
+
return super.computeStartView();
|
|
463
|
+
const bounds = this.contentBounds();
|
|
464
|
+
const first = this.firstItemRect();
|
|
465
|
+
if (!bounds || !first) return super.computeStartView();
|
|
466
|
+
const fitted = this.viewport.viewForRect(bounds, this.padding);
|
|
467
|
+
if (fitted.zoom >= MIN_FIT_ZOOM) return fitted;
|
|
468
|
+
const zoom = MIN_FIT_ZOOM;
|
|
469
|
+
const { width, height } = this.viewport.size();
|
|
470
|
+
return this.orientation === 'vertical'
|
|
471
|
+
? {
|
|
472
|
+
zoom,
|
|
473
|
+
x: width / 2 - (first.x + first.width / 2) * zoom,
|
|
474
|
+
y: this.padding - first.y * zoom,
|
|
475
|
+
}
|
|
476
|
+
: {
|
|
477
|
+
zoom,
|
|
478
|
+
x: this.padding - first.x * zoom,
|
|
479
|
+
y: height / 2 - (first.y + first.height / 2) * zoom,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ── Private methods: data
|
|
484
|
+
|
|
485
|
+
private indexItems() {
|
|
486
|
+
this.byId = new Map(this.items.map(i => [i.id, i]));
|
|
487
|
+
this.childMap = new Map();
|
|
488
|
+
this.roots = [];
|
|
489
|
+
for (const item of this.items) {
|
|
490
|
+
const parent =
|
|
491
|
+
item.parentId && this.byId.has(item.parentId)
|
|
492
|
+
? item.parentId
|
|
493
|
+
: undefined;
|
|
494
|
+
if (parent) {
|
|
495
|
+
const list = this.childMap.get(parent) ?? [];
|
|
496
|
+
list.push(item.id);
|
|
497
|
+
this.childMap.set(parent, list);
|
|
498
|
+
} else {
|
|
499
|
+
this.roots.push(item.id);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
let collapsed: Set<string> | undefined;
|
|
503
|
+
for (const item of this.items) {
|
|
504
|
+
if (item.collapsed && !this.seenCollapsed.has(item.id)) {
|
|
505
|
+
this.seenCollapsed.add(item.id);
|
|
506
|
+
collapsed = collapsed ?? new Set(this._collapsed);
|
|
507
|
+
collapsed.add(item.id);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (collapsed) this._collapsed = collapsed;
|
|
511
|
+
if (this._loading.size) {
|
|
512
|
+
const loading = new Set(
|
|
513
|
+
[...this._loading].filter(
|
|
514
|
+
id =>
|
|
515
|
+
this.byId.get(id)?.hasChildren && !this.childMap.get(id)?.length,
|
|
516
|
+
),
|
|
517
|
+
);
|
|
518
|
+
if (loading.size !== this._loading.size) this._loading = loading;
|
|
519
|
+
}
|
|
520
|
+
if (this.selected && !this.byId.has(this.selected)) this.selected = '';
|
|
521
|
+
this.measure.retain(new Set(this.byId.keys()));
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
private parentOf(id: string): string | undefined {
|
|
525
|
+
const p = this.byId.get(id)?.parentId;
|
|
526
|
+
return p && this.byId.has(p) ? p : undefined;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
private hasKids(id: string): boolean {
|
|
530
|
+
return !!this.childMap.get(id)?.length || !!this.byId.get(id)?.hasChildren;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** Whether `id` is `ancestor` or below it. */
|
|
534
|
+
private isWithin(id: string, ancestor: string): boolean {
|
|
535
|
+
let cursor: string | undefined = id;
|
|
536
|
+
while (cursor) {
|
|
537
|
+
if (cursor === ancestor) return true;
|
|
538
|
+
cursor = this.parentOf(cursor);
|
|
539
|
+
}
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
private requestChildren(item: TreeChartItem) {
|
|
544
|
+
const next = new Set(this._loading);
|
|
545
|
+
next.add(item.id);
|
|
546
|
+
this._loading = next;
|
|
547
|
+
this.emit<TreeChartItemDetail>('expand', { id: item.id, item });
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
private commit(
|
|
551
|
+
next: TreeChartItem[],
|
|
552
|
+
reason: TreeChartChangeReason,
|
|
553
|
+
record = true,
|
|
554
|
+
) {
|
|
555
|
+
if (record) this.history.push(this.items);
|
|
556
|
+
this.glide(() => {
|
|
557
|
+
this.items = next;
|
|
558
|
+
});
|
|
559
|
+
this.emit<TreeChartChangeDetail>('change', { items: next, reason });
|
|
560
|
+
this.listeners.notify();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
private announce(message: string) {
|
|
564
|
+
this._announcement = '';
|
|
565
|
+
requestAnimationFrame(() => {
|
|
566
|
+
this._announcement = message;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
private select(item: TreeChartItem) {
|
|
571
|
+
this.selected = item.id;
|
|
572
|
+
this.emit<TreeChartItemDetail>('select', { id: item.id, item });
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
private uniqueId(base: string): string {
|
|
576
|
+
if (!this.byId.has(base)) return base;
|
|
577
|
+
let i = 2;
|
|
578
|
+
while (this.byId.has(`${base}-${i}`)) i += 1;
|
|
579
|
+
return `${base}-${i}`;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
private reparent(id: string, parentId: string | null) {
|
|
583
|
+
const item = this.byId.get(id);
|
|
584
|
+
if (!item || (parentId && this.isWithin(parentId, id))) return;
|
|
585
|
+
const previousParentId = this.parentOf(id) ?? null;
|
|
586
|
+
if (previousParentId === parentId) return;
|
|
587
|
+
const allowed = this.emit<TreeChartReparentDetail>(
|
|
588
|
+
'reparent',
|
|
589
|
+
{ id, parentId, previousParentId },
|
|
590
|
+
true,
|
|
591
|
+
);
|
|
592
|
+
if (!allowed) return;
|
|
593
|
+
if (parentId && this._collapsed.has(parentId)) {
|
|
594
|
+
const next = new Set(this._collapsed);
|
|
595
|
+
next.delete(parentId);
|
|
596
|
+
this._collapsed = next;
|
|
597
|
+
}
|
|
598
|
+
this.commit(
|
|
599
|
+
this.items.map(i => (i.id === id ? { ...i, parentId } : i)),
|
|
600
|
+
'move',
|
|
601
|
+
);
|
|
602
|
+
const parent = parentId ? this.byId.get(parentId) : undefined;
|
|
603
|
+
this.announce(
|
|
604
|
+
this.i18n.t('treeChartMoved')(item.headline, parent?.headline ?? ''),
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
private add(of: string, position: 'child' | 'sibling') {
|
|
609
|
+
const parentId = position === 'child' ? of : (this.parentOf(of) ?? null);
|
|
610
|
+
const allowed = this.emit<TreeChartAddDetail>(
|
|
611
|
+
'add',
|
|
612
|
+
{ parentId, position, of },
|
|
613
|
+
true,
|
|
614
|
+
);
|
|
615
|
+
if (!allowed) return;
|
|
616
|
+
const item: TreeChartItem = {
|
|
617
|
+
id: this.uniqueId('item'),
|
|
618
|
+
parentId,
|
|
619
|
+
headline: this.i18n.t('treeChartNewItem'),
|
|
620
|
+
};
|
|
621
|
+
const at = this.items.findIndex(i => i.id === of);
|
|
622
|
+
const next = [
|
|
623
|
+
...this.items.slice(0, at + 1),
|
|
624
|
+
item,
|
|
625
|
+
...this.items.slice(at + 1),
|
|
626
|
+
];
|
|
627
|
+
if (parentId && this._collapsed.has(parentId)) {
|
|
628
|
+
const collapsed = new Set(this._collapsed);
|
|
629
|
+
collapsed.delete(parentId);
|
|
630
|
+
this._collapsed = collapsed;
|
|
631
|
+
}
|
|
632
|
+
this.commit(next, 'add');
|
|
633
|
+
this.selected = item.id;
|
|
634
|
+
this.emit<TreeChartItemDetail>('select', { id: item.id, item });
|
|
635
|
+
this.focusItem(item.id);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Removes an item; its children move up to its parent. */
|
|
639
|
+
private removeItem(id: string) {
|
|
640
|
+
const item = this.byId.get(id);
|
|
641
|
+
if (!item) return;
|
|
642
|
+
if (!this.emit<TreeChartDeleteDetail>('delete', { ids: [id] }, true))
|
|
643
|
+
return;
|
|
644
|
+
const parentId = this.parentOf(id) ?? null;
|
|
645
|
+
const siblings = parentId
|
|
646
|
+
? (this.childMap.get(parentId) ?? [])
|
|
647
|
+
: this.roots;
|
|
648
|
+
const neighbour =
|
|
649
|
+
siblings[siblings.indexOf(id) + 1] ??
|
|
650
|
+
siblings[siblings.indexOf(id) - 1] ??
|
|
651
|
+
parentId;
|
|
652
|
+
this.commit(
|
|
653
|
+
this.items
|
|
654
|
+
.filter(i => i.id !== id)
|
|
655
|
+
.map(i => (i.parentId === id ? { ...i, parentId } : i)),
|
|
656
|
+
'remove',
|
|
657
|
+
);
|
|
658
|
+
this.announce(this.i18n.t('treeChartRemoved')(item.headline));
|
|
659
|
+
if (neighbour) this.focusItem(neighbour);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// ── Private methods: layout and motion
|
|
663
|
+
|
|
664
|
+
private layout() {
|
|
665
|
+
const nodes = new Map<string, LayoutInput>();
|
|
666
|
+
const visit = (id: string) => {
|
|
667
|
+
const kids = this._collapsed.has(id) ? [] : (this.childMap.get(id) ?? []);
|
|
668
|
+
nodes.set(id, { id, children: kids });
|
|
669
|
+
kids.forEach(visit);
|
|
670
|
+
};
|
|
671
|
+
this.roots.forEach(visit);
|
|
672
|
+
const result = layoutTree(this.roots, nodes, id => this.measure.size(id), {
|
|
673
|
+
...LAYOUT,
|
|
674
|
+
orientation: this.orientation,
|
|
675
|
+
compact: this.compact,
|
|
676
|
+
});
|
|
677
|
+
this.positions = result.positions;
|
|
678
|
+
this.stacked = result.stacked;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
private positionOf(id: string): DiagramPoint {
|
|
682
|
+
return this.overrides.get(id) ?? this.positions.get(id) ?? { x: 0, y: 0 };
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
private rectOf(id: string): DiagramRect {
|
|
686
|
+
const p = this.positionOf(id);
|
|
687
|
+
const s = this.measure.size(id);
|
|
688
|
+
return { x: p.x, y: p.y, width: s.width, height: s.height };
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** Runs a change and glides items from where they were; new items grow out of `anchor`. */
|
|
692
|
+
private glide(change: () => void, anchor?: string) {
|
|
693
|
+
if (!prefersReducedMotion() && this.positions.size) {
|
|
694
|
+
this.glideFrom = { positions: new Map(this.positions), anchor };
|
|
695
|
+
}
|
|
696
|
+
change();
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
private playGlide() {
|
|
700
|
+
const from = this.glideFrom;
|
|
701
|
+
this.glideFrom = undefined;
|
|
702
|
+
if (!from) return;
|
|
703
|
+
this.stopGlide?.();
|
|
704
|
+
const to = new Map(this.positions);
|
|
705
|
+
const start = new Map<string, DiagramPoint>();
|
|
706
|
+
for (const [id, target] of to) {
|
|
707
|
+
let origin = from.positions.get(id);
|
|
708
|
+
if (!origin) {
|
|
709
|
+
// New items start at their nearest visible ancestor, or the anchor.
|
|
710
|
+
let cursor = this.parentOf(id);
|
|
711
|
+
while (cursor && !from.positions.has(cursor))
|
|
712
|
+
cursor = this.parentOf(cursor);
|
|
713
|
+
origin = from.positions.get(cursor ?? from.anchor ?? '') ?? target;
|
|
714
|
+
}
|
|
715
|
+
if (origin.x !== target.x || origin.y !== target.y) start.set(id, origin);
|
|
716
|
+
}
|
|
717
|
+
if (!start.size) return;
|
|
718
|
+
this.stopGlide = tween({
|
|
719
|
+
duration: 320,
|
|
720
|
+
easing: easeOutCubic,
|
|
721
|
+
onUpdate: p => {
|
|
722
|
+
for (const [id, origin] of start) {
|
|
723
|
+
const target = to.get(id) ?? origin;
|
|
724
|
+
this.overrides.set(id, {
|
|
725
|
+
x: origin.x + (target.x - origin.x) * p,
|
|
726
|
+
y: origin.y + (target.y - origin.y) * p,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
this.requestUpdate();
|
|
730
|
+
},
|
|
731
|
+
onDone: () => {
|
|
732
|
+
this.overrides.clear();
|
|
733
|
+
this.stopGlide = undefined;
|
|
734
|
+
this.requestUpdate();
|
|
735
|
+
},
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
private keepInView(id: string) {
|
|
740
|
+
const r = this.itemRect(id);
|
|
741
|
+
if (!r) return;
|
|
742
|
+
const v = this.viewport.visibleRect();
|
|
743
|
+
const inside =
|
|
744
|
+
r.x >= v.x &&
|
|
745
|
+
r.y >= v.y &&
|
|
746
|
+
r.x + r.width <= v.x + v.width &&
|
|
747
|
+
r.y + r.height <= v.y + v.height;
|
|
748
|
+
if (!inside) this.centerOn(r.x + r.width / 2, r.y + r.height / 2);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// ── Private methods: nodes
|
|
752
|
+
|
|
753
|
+
private nodeElements(): [string, HTMLElement][] {
|
|
754
|
+
const out: [string, HTMLElement][] = [];
|
|
755
|
+
this.renderRoot.querySelectorAll<HTMLElement>('.tc-node').forEach(el => {
|
|
756
|
+
if (el.dataset.id) out.push([el.dataset.id, el]);
|
|
757
|
+
});
|
|
758
|
+
return out;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
private nodeElement(id: string): HTMLElement | null {
|
|
762
|
+
return this.renderRoot.querySelector<HTMLElement>(
|
|
763
|
+
`.tc-node[data-id="${CSS.escape(id)}"]`,
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/** Visible items in reading order. */
|
|
768
|
+
private visibleOrder(): string[] {
|
|
769
|
+
const out: string[] = [];
|
|
770
|
+
const visit = (id: string) => {
|
|
771
|
+
out.push(id);
|
|
772
|
+
if (!this._collapsed.has(id))
|
|
773
|
+
(this.childMap.get(id) ?? []).forEach(visit);
|
|
774
|
+
};
|
|
775
|
+
this.roots.forEach(visit);
|
|
776
|
+
return out;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
private siblingsOf(id: string): string[] {
|
|
780
|
+
const parent = this.parentOf(id);
|
|
781
|
+
return parent ? (this.childMap.get(parent) ?? []) : this.roots;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private onNodeKeyDown(event: KeyboardEvent, item: TreeChartItem) {
|
|
785
|
+
if (event.target !== event.currentTarget) return;
|
|
786
|
+
const handled = (fn: () => void) => {
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
this.handledKeys.add(event);
|
|
789
|
+
fn();
|
|
790
|
+
};
|
|
791
|
+
const { key } = event;
|
|
792
|
+
const vertical = this.orientation === 'vertical';
|
|
793
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
794
|
+
// The keys that point "back" and "forward" along a row, mirrored in right-to-left pages.
|
|
795
|
+
const back = rtl ? 'ArrowRight' : 'ArrowLeft';
|
|
796
|
+
const forward = rtl ? 'ArrowLeft' : 'ArrowRight';
|
|
797
|
+
const toParent = vertical ? 'ArrowUp' : back;
|
|
798
|
+
const toChild = vertical ? 'ArrowDown' : forward;
|
|
799
|
+
const prevSibling = vertical ? back : 'ArrowUp';
|
|
800
|
+
const nextSibling = vertical ? forward : 'ArrowDown';
|
|
801
|
+
const siblings = this.siblingsOf(item.id);
|
|
802
|
+
const at = siblings.indexOf(item.id);
|
|
803
|
+
const order = this.visibleOrder();
|
|
804
|
+
const firstChild = this._collapsed.has(item.id)
|
|
805
|
+
? undefined
|
|
806
|
+
: this.childMap.get(item.id)?.[0];
|
|
807
|
+
if (key === 'Enter' && event.shiftKey) {
|
|
808
|
+
handled(() =>
|
|
809
|
+
this._collapsed.has(item.id)
|
|
810
|
+
? this.expand(item.id)
|
|
811
|
+
: this.collapse(item.id),
|
|
812
|
+
);
|
|
813
|
+
} else if (key === 'Enter' || key === ' ') {
|
|
814
|
+
handled(() => this.select(item));
|
|
815
|
+
} else if (key === toParent && this.parentOf(item.id)) {
|
|
816
|
+
handled(() => this.focusItem(this.parentOf(item.id) ?? item.id));
|
|
817
|
+
} else if (key === toChild && firstChild) {
|
|
818
|
+
handled(() => this.focusItem(firstChild));
|
|
819
|
+
} else if (key === toChild && this._collapsed.has(item.id)) {
|
|
820
|
+
handled(() => this.expand(item.id));
|
|
821
|
+
} else if (key === prevSibling && siblings[at - 1]) {
|
|
822
|
+
handled(() => this.focusItem(siblings[at - 1]));
|
|
823
|
+
} else if (key === nextSibling && siblings[at + 1]) {
|
|
824
|
+
handled(() => this.focusItem(siblings[at + 1]));
|
|
825
|
+
} else if (key === 'Home' && order[0]) {
|
|
826
|
+
handled(() => this.focusItem(order[0]));
|
|
827
|
+
} else if (key === 'End' && order.length) {
|
|
828
|
+
handled(() => this.focusItem(order[order.length - 1]));
|
|
829
|
+
} else if (key === '*') {
|
|
830
|
+
handled(() => siblings.forEach(id => this.expand(id)));
|
|
831
|
+
} else if (
|
|
832
|
+
(key === 'Delete' || key === 'Backspace') &&
|
|
833
|
+
this.editable &&
|
|
834
|
+
!this.readonly
|
|
835
|
+
) {
|
|
836
|
+
handled(() => this.removeItem(item.id));
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
private onViewportKeyDown = (event: KeyboardEvent) => {
|
|
841
|
+
if (event.defaultPrevented || this.handledKeys.has(event)) return;
|
|
842
|
+
const mod = event.ctrlKey || event.metaKey;
|
|
843
|
+
const key = event.key.toLowerCase();
|
|
844
|
+
const editing = this.editable && !this.readonly;
|
|
845
|
+
if (mod && key === 'z' && editing) {
|
|
846
|
+
event.preventDefault();
|
|
847
|
+
if (event.shiftKey) this.redo();
|
|
848
|
+
else this.undo();
|
|
849
|
+
} else if (mod && key === 'y' && editing) {
|
|
850
|
+
event.preventDefault();
|
|
851
|
+
this.redo();
|
|
852
|
+
} else if (key === 'escape') {
|
|
853
|
+
event.preventDefault();
|
|
854
|
+
this.selected = '';
|
|
855
|
+
this.clearSearch();
|
|
856
|
+
} else this.handleCanvasKey(event);
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
private onNodePointerDown(event: PointerEvent, item: TreeChartItem) {
|
|
860
|
+
if (event.button !== 0 || this.viewport.spaceHeld) return;
|
|
861
|
+
const origin = event.composedPath()[0];
|
|
862
|
+
if (origin instanceof Element && origin.closest(INTERACTIVE)) return;
|
|
863
|
+
event.stopPropagation();
|
|
864
|
+
const element = event.currentTarget as HTMLElement;
|
|
865
|
+
element.focus({ preventScroll: true });
|
|
866
|
+
this._focusId = item.id;
|
|
867
|
+
this.nodeDrag = {
|
|
868
|
+
pointerId: event.pointerId,
|
|
869
|
+
startX: event.clientX,
|
|
870
|
+
startY: event.clientY,
|
|
871
|
+
id: item.id,
|
|
872
|
+
element,
|
|
873
|
+
moved: false,
|
|
874
|
+
};
|
|
875
|
+
try {
|
|
876
|
+
element.setPointerCapture(event.pointerId);
|
|
877
|
+
} catch {
|
|
878
|
+
// Synthetic pointers cannot be captured.
|
|
879
|
+
}
|
|
880
|
+
element.addEventListener('pointermove', this.onDragMove);
|
|
881
|
+
element.addEventListener('pointerup', this.onDragUp);
|
|
882
|
+
element.addEventListener('pointercancel', this.onDragCancel);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
private onDragMove = (event: PointerEvent) => {
|
|
886
|
+
const drag = this.nodeDrag;
|
|
887
|
+
if (
|
|
888
|
+
!drag ||
|
|
889
|
+
event.pointerId !== drag.pointerId ||
|
|
890
|
+
!this.editable ||
|
|
891
|
+
this.readonly
|
|
892
|
+
)
|
|
893
|
+
return;
|
|
894
|
+
if (
|
|
895
|
+
!drag.moved &&
|
|
896
|
+
Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) <
|
|
897
|
+
DRAG_THRESHOLD
|
|
898
|
+
) {
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
drag.moved = true;
|
|
902
|
+
const vr = this._viewportEl?.getBoundingClientRect();
|
|
903
|
+
const point = this.viewport.toCanvas(event.clientX, event.clientY);
|
|
904
|
+
let target: string | undefined;
|
|
905
|
+
for (const id of this.positions.keys()) {
|
|
906
|
+
const r = this.rectOf(id);
|
|
907
|
+
if (
|
|
908
|
+
id !== drag.id &&
|
|
909
|
+
point.x >= r.x &&
|
|
910
|
+
point.x <= r.x + r.width &&
|
|
911
|
+
point.y >= r.y &&
|
|
912
|
+
point.y <= r.y + r.height &&
|
|
913
|
+
!this.isWithin(id, drag.id)
|
|
914
|
+
) {
|
|
915
|
+
target = id;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
this._drag = {
|
|
919
|
+
id: drag.id,
|
|
920
|
+
x: event.clientX - (vr?.left ?? 0),
|
|
921
|
+
y: event.clientY - (vr?.top ?? 0),
|
|
922
|
+
target,
|
|
923
|
+
};
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
private onDragUp = (event: PointerEvent) => {
|
|
927
|
+
if (!this.nodeDrag || event.pointerId !== this.nodeDrag.pointerId) return;
|
|
928
|
+
this.endDrag(true);
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
private onDragCancel = () => {
|
|
932
|
+
this.endDrag(false);
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
private endDrag(commit: boolean) {
|
|
936
|
+
const drag = this.nodeDrag;
|
|
937
|
+
if (!drag) return;
|
|
938
|
+
this.nodeDrag = undefined;
|
|
939
|
+
const target = this._drag?.target;
|
|
940
|
+
this._drag = undefined;
|
|
941
|
+
drag.element.removeEventListener('pointermove', this.onDragMove);
|
|
942
|
+
drag.element.removeEventListener('pointerup', this.onDragUp);
|
|
943
|
+
drag.element.removeEventListener('pointercancel', this.onDragCancel);
|
|
944
|
+
try {
|
|
945
|
+
if (drag.element.hasPointerCapture(drag.pointerId)) {
|
|
946
|
+
drag.element.releasePointerCapture(drag.pointerId);
|
|
947
|
+
}
|
|
948
|
+
} catch {
|
|
949
|
+
// The pointer is already gone.
|
|
950
|
+
}
|
|
951
|
+
if (!commit) return;
|
|
952
|
+
const item = this.byId.get(drag.id);
|
|
953
|
+
if (!item) return;
|
|
954
|
+
if (!drag.moved) this.select(item);
|
|
955
|
+
else if (target) this.reparent(drag.id, target);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// ── Render
|
|
959
|
+
|
|
960
|
+
private renderNode(id: string, focusId: string) {
|
|
961
|
+
const item = this.byId.get(id);
|
|
962
|
+
if (!item) return nothing;
|
|
963
|
+
const p = this.positionOf(id);
|
|
964
|
+
const kids = this.childMap.get(id) ?? [];
|
|
965
|
+
const expandable = this.hasKids(id);
|
|
966
|
+
const collapsed =
|
|
967
|
+
this._collapsed.has(id) || (!!item.hasChildren && !kids.length);
|
|
968
|
+
const loading = this._loading.has(id);
|
|
969
|
+
const siblings = this.siblingsOf(id);
|
|
970
|
+
let depth = 1;
|
|
971
|
+
for (let c = this.parentOf(id); c; c = this.parentOf(c)) depth += 1;
|
|
972
|
+
const searching = this._path.size > 0;
|
|
973
|
+
const editing = this.editable && !this.readonly;
|
|
974
|
+
const avatar = item.icon
|
|
975
|
+
? html`<span class=${`tc-tile accent-${item.accent ?? 'primary'}`}
|
|
976
|
+
><wc-icon name=${item.icon}></wc-icon
|
|
977
|
+
></span>`
|
|
978
|
+
: html`<wc-avatar
|
|
979
|
+
size="sm"
|
|
980
|
+
name=${item.headline}
|
|
981
|
+
src=${item.avatar ?? nothing}
|
|
982
|
+
></wc-avatar>`;
|
|
983
|
+
return html`<div
|
|
984
|
+
class=${classMap({
|
|
985
|
+
'tc-node': true,
|
|
986
|
+
'is-selected': this.selected === id,
|
|
987
|
+
'is-match': this._matches.has(id),
|
|
988
|
+
'is-dim': searching && !this._path.has(id),
|
|
989
|
+
'is-dragging': this._drag?.id === id,
|
|
990
|
+
'is-drop': this._drag?.target === id,
|
|
991
|
+
})}
|
|
992
|
+
data-id=${id}
|
|
993
|
+
role="treeitem"
|
|
994
|
+
aria-level=${depth}
|
|
995
|
+
aria-setsize=${siblings.length}
|
|
996
|
+
aria-posinset=${siblings.indexOf(id) + 1}
|
|
997
|
+
aria-expanded=${expandable ? String(!collapsed) : nothing}
|
|
998
|
+
aria-selected=${this.selected === id ? 'true' : 'false'}
|
|
999
|
+
aria-busy=${loading ? 'true' : nothing}
|
|
1000
|
+
aria-label=${[item.headline, item.supportingText, item.badge]
|
|
1001
|
+
.filter(Boolean)
|
|
1002
|
+
.join(', ')}
|
|
1003
|
+
tabindex=${focusId === id ? '0' : '-1'}
|
|
1004
|
+
style="left: ${p.x}px; top: ${p.y}px;"
|
|
1005
|
+
@pointerdown=${(e: PointerEvent) => this.onNodePointerDown(e, item)}
|
|
1006
|
+
@keydown=${(e: KeyboardEvent) => this.onNodeKeyDown(e, item)}
|
|
1007
|
+
@focus=${() => {
|
|
1008
|
+
this._focusId = id;
|
|
1009
|
+
}}
|
|
1010
|
+
>
|
|
1011
|
+
<slot name=${`item:${id}`}>
|
|
1012
|
+
<div class="tc-card">
|
|
1013
|
+
${avatar}
|
|
1014
|
+
<span class="tc-text">
|
|
1015
|
+
<span class="tc-headline">${item.headline}</span>
|
|
1016
|
+
${item.supportingText
|
|
1017
|
+
? html`<span class="tc-sub">${item.supportingText}</span>`
|
|
1018
|
+
: nothing}
|
|
1019
|
+
</span>
|
|
1020
|
+
${item.badge
|
|
1021
|
+
? html`<span class="tc-badge">${item.badge}</span>`
|
|
1022
|
+
: nothing}
|
|
1023
|
+
</div>
|
|
1024
|
+
</slot>
|
|
1025
|
+
${expandable
|
|
1026
|
+
? html`<button
|
|
1027
|
+
class="tc-count"
|
|
1028
|
+
type="button"
|
|
1029
|
+
tabindex="-1"
|
|
1030
|
+
aria-label=${collapsed
|
|
1031
|
+
? this.i18n.t('treeChartExpand')(item.headline, kids.length)
|
|
1032
|
+
: this.i18n.t('treeChartCollapse')(item.headline)}
|
|
1033
|
+
@click=${() => (collapsed ? this.expand(id) : this.collapse(id))}
|
|
1034
|
+
>
|
|
1035
|
+
${loading
|
|
1036
|
+
? html`<wc-icon
|
|
1037
|
+
class="tc-spin"
|
|
1038
|
+
name="progress_activity"
|
|
1039
|
+
></wc-icon>`
|
|
1040
|
+
: html`${kids.length ? kids.length : nothing}<wc-icon
|
|
1041
|
+
name=${collapsed
|
|
1042
|
+
? 'keyboard_arrow_down'
|
|
1043
|
+
: 'keyboard_arrow_up'}
|
|
1044
|
+
></wc-icon>`}
|
|
1045
|
+
</button>`
|
|
1046
|
+
: nothing}
|
|
1047
|
+
${editing
|
|
1048
|
+
? html`<span class="tc-actions">
|
|
1049
|
+
<button
|
|
1050
|
+
type="button"
|
|
1051
|
+
tabindex="-1"
|
|
1052
|
+
title=${this.i18n.t('treeChartAddChild')}
|
|
1053
|
+
aria-label=${this.i18n.t('treeChartAddChild')}
|
|
1054
|
+
@click=${() => this.add(id, 'child')}
|
|
1055
|
+
>
|
|
1056
|
+
<wc-icon name="subdirectory_arrow_right"></wc-icon>
|
|
1057
|
+
</button>
|
|
1058
|
+
${this.parentOf(id)
|
|
1059
|
+
? html`<button
|
|
1060
|
+
type="button"
|
|
1061
|
+
tabindex="-1"
|
|
1062
|
+
title=${this.i18n.t('treeChartAddSibling')}
|
|
1063
|
+
aria-label=${this.i18n.t('treeChartAddSibling')}
|
|
1064
|
+
@click=${() => this.add(id, 'sibling')}
|
|
1065
|
+
>
|
|
1066
|
+
<wc-icon name="add"></wc-icon>
|
|
1067
|
+
</button>`
|
|
1068
|
+
: nothing}
|
|
1069
|
+
</span>`
|
|
1070
|
+
: nothing}
|
|
1071
|
+
</div>`;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
private renderLinks(shown: Set<string>) {
|
|
1075
|
+
const searching = this._path.size > 0;
|
|
1076
|
+
const out = [];
|
|
1077
|
+
for (const id of this.positions.keys()) {
|
|
1078
|
+
const parent = this.parentOf(id);
|
|
1079
|
+
if (
|
|
1080
|
+
parent &&
|
|
1081
|
+
this.positions.has(parent) &&
|
|
1082
|
+
(shown.has(id) || shown.has(parent))
|
|
1083
|
+
) {
|
|
1084
|
+
const points = linkPoints(this.rectOf(parent), this.rectOf(id), {
|
|
1085
|
+
...LAYOUT,
|
|
1086
|
+
orientation: this.orientation,
|
|
1087
|
+
stacked: this.stacked.has(parent),
|
|
1088
|
+
});
|
|
1089
|
+
const onPath = this._path.has(id) && this._path.has(parent);
|
|
1090
|
+
out.push(
|
|
1091
|
+
svg`<path class=${classMap({ 'tc-link': true, 'is-path': onPath, 'is-dim': searching && !onPath })} d=${roundedPath(points, 14)}></path>`,
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return out;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
protected render() {
|
|
1099
|
+
this.layout();
|
|
1100
|
+
const { x, y, zoom } = this.viewport.view;
|
|
1101
|
+
const order = this.visibleOrder();
|
|
1102
|
+
const focusId =
|
|
1103
|
+
this._focusId && this.positions.has(this._focusId)
|
|
1104
|
+
? this._focusId
|
|
1105
|
+
: order[0];
|
|
1106
|
+
const shown = new Set(
|
|
1107
|
+
order.filter(
|
|
1108
|
+
id =>
|
|
1109
|
+
this.nearView(this.rectOf(id)) ||
|
|
1110
|
+
id === focusId ||
|
|
1111
|
+
id === this.selected,
|
|
1112
|
+
),
|
|
1113
|
+
);
|
|
1114
|
+
const dragged = this._drag ? this.byId.get(this._drag.id) : undefined;
|
|
1115
|
+
return html`
|
|
1116
|
+
<div
|
|
1117
|
+
class=${classMap({
|
|
1118
|
+
'tc-viewport': true,
|
|
1119
|
+
'is-panning': this.viewport.panning,
|
|
1120
|
+
'is-space': this.viewport.spaceHeld,
|
|
1121
|
+
'is-dragging': !!this._drag,
|
|
1122
|
+
})}
|
|
1123
|
+
tabindex="0"
|
|
1124
|
+
role="region"
|
|
1125
|
+
aria-label=${this.label || this.i18n.t('treeChartLabel')}
|
|
1126
|
+
aria-describedby="instructions"
|
|
1127
|
+
style=${this.gridStyle()}
|
|
1128
|
+
@keydown=${this.onViewportKeyDown}
|
|
1129
|
+
>
|
|
1130
|
+
<div
|
|
1131
|
+
class="tc-world"
|
|
1132
|
+
style="transform: translate(${x}px, ${y}px) scale(${zoom});"
|
|
1133
|
+
>
|
|
1134
|
+
<svg class="tc-links" width="1" height="1" aria-hidden="true">
|
|
1135
|
+
${this.renderLinks(shown)}
|
|
1136
|
+
</svg>
|
|
1137
|
+
<div
|
|
1138
|
+
class="tc-nodes"
|
|
1139
|
+
role="tree"
|
|
1140
|
+
aria-label=${this.label || this.i18n.t('treeChartLabel')}
|
|
1141
|
+
>
|
|
1142
|
+
${repeat(
|
|
1143
|
+
order.filter(id => shown.has(id)),
|
|
1144
|
+
id => id,
|
|
1145
|
+
id => this.renderNode(id, focusId),
|
|
1146
|
+
)}
|
|
1147
|
+
</div>
|
|
1148
|
+
</div>
|
|
1149
|
+
${dragged && this._drag
|
|
1150
|
+
? html`<div
|
|
1151
|
+
class="tc-ghost"
|
|
1152
|
+
style="left: ${this._drag.x}px; top: ${this._drag.y}px;"
|
|
1153
|
+
>
|
|
1154
|
+
${dragged.headline}
|
|
1155
|
+
</div>`
|
|
1156
|
+
: nothing}
|
|
1157
|
+
${this.renderBackToContent()}
|
|
1158
|
+
<div class="slot-controls"><slot name="controls"></slot></div>
|
|
1159
|
+
<div class="slot-minimap"><slot name="minimap"></slot></div>
|
|
1160
|
+
<div id="instructions" hidden>
|
|
1161
|
+
${this.i18n.t('diagramInstructions')}
|
|
1162
|
+
</div>
|
|
1163
|
+
<div class="sr-only" aria-live="polite">${this._announcement}</div>
|
|
1164
|
+
</div>
|
|
1165
|
+
`;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// Cards are measured after they render and laid out from those sizes, so a second update is expected.
|
|
1170
|
+
TreeChart.disableWarning?.('change-in-update');
|