@zonsh/ui 0.0.0 → 0.4.1
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/LICENSE +43 -0
- package/README.md +81 -1
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +31 -0
- package/dist/components/breadcrumb.js +37 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +179 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +109 -0
- package/dist/components/carousel.js +231 -0
- package/dist/components/chart.d.ts +189 -0
- package/dist/components/chart.js +323 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +55 -0
- package/dist/components/code-block.js +100 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +107 -0
- package/dist/components/color-picker.js +428 -0
- package/dist/components/combobox.d.ts +99 -0
- package/dist/components/combobox.js +172 -0
- package/dist/components/command.d.ts +132 -0
- package/dist/components/command.js +257 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +36 -0
- package/dist/components/conversation.js +303 -0
- package/dist/components/copy-button.d.ts +55 -0
- package/dist/components/copy-button.js +133 -0
- package/dist/components/data-table.d.ts +235 -0
- package/dist/components/data-table.js +655 -0
- package/dist/components/date-picker.d.ts +160 -0
- package/dist/components/date-picker.js +338 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +95 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +69 -0
- package/dist/components/drawer.js +79 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +34 -0
- package/dist/components/field.js +81 -0
- package/dist/components/file-drop.d.ts +77 -0
- package/dist/components/file-drop.js +258 -0
- package/dist/components/filter-bar.d.ts +153 -0
- package/dist/components/filter-bar.js +334 -0
- package/dist/components/form.d.ts +35 -0
- package/dist/components/form.js +56 -0
- package/dist/components/graph.d.ts +146 -0
- package/dist/components/graph.js +825 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +138 -0
- package/dist/components/input-group.js +312 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +50 -0
- package/dist/components/kbd.js +45 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +140 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +59 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +27 -0
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +55 -0
- package/dist/components/number-field.js +164 -0
- package/dist/components/otp-field.d.ts +48 -0
- package/dist/components/otp-field.js +102 -0
- package/dist/components/pagination.d.ts +37 -0
- package/dist/components/pagination.js +81 -0
- package/dist/components/pdf-viewer.d.ts +134 -0
- package/dist/components/pdf-viewer.js +996 -0
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +25 -0
- package/dist/components/prompt-input.d.ts +156 -0
- package/dist/components/prompt-input.js +415 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +46 -0
- package/dist/components/reasoning.js +73 -0
- package/dist/components/resizable.d.ts +47 -0
- package/dist/components/resizable.js +44 -0
- package/dist/components/response.d.ts +41 -0
- package/dist/components/response.js +566 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +71 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +163 -0
- package/dist/components/sidebar.js +505 -0
- package/dist/components/site-header.d.ts +93 -0
- package/dist/components/site-header.js +121 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +131 -0
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +40 -0
- package/dist/components/sources.js +42 -0
- package/dist/components/spinner.d.ts +48 -0
- package/dist/components/spinner.js +75 -0
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +172 -0
- package/dist/components/table.js +895 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +56 -0
- package/dist/components/tags-input.js +271 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +55 -0
- package/dist/components/theme.js +120 -0
- package/dist/components/time-field.d.ts +70 -0
- package/dist/components/time-field.js +450 -0
- package/dist/components/timeline.d.ts +92 -0
- package/dist/components/timeline.js +108 -0
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +88 -0
- package/dist/components/toast.js +205 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +63 -0
- package/dist/components/tool-call.js +68 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +649 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +284 -0
- package/dist/components/video-player.js +1392 -0
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +94 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +18 -0
- package/dist/lib/code-highlight.js +174 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +209 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +38 -0
- package/dist/lib/platform.js +75 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +596 -0
- package/dist/lib/theme-script.d.ts +31 -0
- package/dist/lib/theme-script.js +49 -0
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +203 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +207 -0
- package/dist/styles/material.css +317 -0
- package/dist/styles/parts/ai.css +361 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +774 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +340 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +424 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/tokens.css +299 -0
- package/dist/vite.d.ts +66 -0
- package/dist/vite.js +29 -0
- package/package.json +183 -5
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { applyEdgeChanges, applyNodeChanges, Background, BackgroundVariant, BaseEdge, ConnectionLineType, EdgeLabelRenderer, getSmoothStepPath, getStraightPath, getViewportForBounds, Handle, MiniMap, Panel, Position, ReactFlow, ReactFlowProvider, useInternalNode, useReactFlow, } from "@xyflow/react";
|
|
4
|
+
import { ArrowLeftRightIcon, CircleDotIcon, MaximizeIcon, MinusIcon, PencilIcon, PlusIcon, Trash2Icon, WandSparklesIcon, } from "lucide-react";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { cn } from "../lib/cn.js";
|
|
7
|
+
import { cssDuration } from "../lib/motion.js";
|
|
8
|
+
import { LANE_HEADER, lanes, layered, network, dragSimulation, } from "../lib/graph-layout.js";
|
|
9
|
+
import { Avatar } from "./avatar.js";
|
|
10
|
+
import { useMessages } from "./locale.js";
|
|
11
|
+
import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuGroupLabel, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger, } from "./context-menu.js";
|
|
12
|
+
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "./toolbar.js";
|
|
13
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
14
|
+
/** Networks of up to this many nodes settle live around a dragged node. */
|
|
15
|
+
const LIVE_DRAG_MAX = 300;
|
|
16
|
+
const newNodes = {
|
|
17
|
+
task: "New step",
|
|
18
|
+
start: "Start",
|
|
19
|
+
end: "End",
|
|
20
|
+
event: "Event",
|
|
21
|
+
gateway: "Decide?",
|
|
22
|
+
note: "A note",
|
|
23
|
+
person: "New person",
|
|
24
|
+
entity: "New node",
|
|
25
|
+
group: "Group",
|
|
26
|
+
};
|
|
27
|
+
const kindNames = {
|
|
28
|
+
task: "Step",
|
|
29
|
+
start: "Start",
|
|
30
|
+
end: "End",
|
|
31
|
+
event: "Event",
|
|
32
|
+
gateway: "Decision",
|
|
33
|
+
note: "Note",
|
|
34
|
+
person: "Person",
|
|
35
|
+
entity: "Node",
|
|
36
|
+
group: "Group",
|
|
37
|
+
};
|
|
38
|
+
const defaultMessages = {
|
|
39
|
+
nodeLabel: "Node label",
|
|
40
|
+
edgeLabel: "Edge label",
|
|
41
|
+
newNode: (kind) => newNodes[kind],
|
|
42
|
+
kind: (kind) => kindNames[kind],
|
|
43
|
+
addHere: "Add here",
|
|
44
|
+
tidy: "Tidy up",
|
|
45
|
+
fit: "Fit to view",
|
|
46
|
+
zoomIn: "Zoom in",
|
|
47
|
+
zoomOut: "Zoom out",
|
|
48
|
+
addNode: "Add a node",
|
|
49
|
+
rename: "Rename",
|
|
50
|
+
delete: "Delete",
|
|
51
|
+
renameLabel: "Rename label",
|
|
52
|
+
addLabel: "Add a label",
|
|
53
|
+
reverse: "Reverse direction",
|
|
54
|
+
removeConnection: "Remove connection",
|
|
55
|
+
enterKey: "Enter",
|
|
56
|
+
deleteKey: "Del",
|
|
57
|
+
connection: (from, to, directed) => `${from} ${directed ? "to" : "and"} ${to}`,
|
|
58
|
+
controls: "Graph",
|
|
59
|
+
minimap: "Map of the graph",
|
|
60
|
+
// React Flow's own words.
|
|
61
|
+
nodeHelp: "Press enter or space to select a node. Press delete to remove it and escape to cancel.",
|
|
62
|
+
edgeHelp: "Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.",
|
|
63
|
+
handle: "Handle",
|
|
64
|
+
moved: (direction, x, y) => `Moved selected node ${direction}. New position, x: ${x}, y: ${y}`,
|
|
65
|
+
};
|
|
66
|
+
const GraphContext = React.createContext(null);
|
|
67
|
+
const useGraph = () => React.useContext(GraphContext);
|
|
68
|
+
const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
69
|
+
const kindOf = (n, layout) => n.kind ?? (layout === "network" ? "entity" : "task");
|
|
70
|
+
const edgeKindOf = (e, layout) => e.kind ?? (layout === "network" ? "relation" : "flow");
|
|
71
|
+
const isDirected = (e, layout) => {
|
|
72
|
+
if (e.directed != null)
|
|
73
|
+
return e.directed;
|
|
74
|
+
const kind = edgeKindOf(e, layout);
|
|
75
|
+
return layout !== "tree" && (kind === "flow" || kind === "message");
|
|
76
|
+
};
|
|
77
|
+
/** The box each kind is drawn in. Labels of events and gateways sit below it, outside. */
|
|
78
|
+
function sizeOf(n, layout) {
|
|
79
|
+
switch (kindOf(n, layout)) {
|
|
80
|
+
case "start":
|
|
81
|
+
case "end":
|
|
82
|
+
case "event":
|
|
83
|
+
return { width: 40, height: 40 };
|
|
84
|
+
case "gateway":
|
|
85
|
+
return { width: 44, height: 44 };
|
|
86
|
+
case "person":
|
|
87
|
+
return { width: 136, height: 96 };
|
|
88
|
+
case "entity":
|
|
89
|
+
return { width: Math.round(clamp(n.label.length * 7.4 + (n.icon ? 58 : 34), 84, 240)), height: 36 };
|
|
90
|
+
case "note":
|
|
91
|
+
return { width: 184, height: 52 };
|
|
92
|
+
case "group":
|
|
93
|
+
return { width: n.size?.width ?? 0, height: n.size?.height ?? 0 };
|
|
94
|
+
default:
|
|
95
|
+
return {
|
|
96
|
+
width: Math.round(clamp(n.label.length * 7.6 + (n.icon ? 66 : 40), 148, 264)),
|
|
97
|
+
height: n.meta ? 60 : 46,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Places every node: kept where positioned, else laid out. Groups come first, as React Flow needs. */
|
|
102
|
+
function build(value, layout, direction) {
|
|
103
|
+
const { nodes, edges } = value;
|
|
104
|
+
const kept = layout === "none" || nodes.every((n) => n.position);
|
|
105
|
+
const groupIds = nodes.filter((n) => kindOf(n, layout) === "group").map((n) => n.id);
|
|
106
|
+
// Swimlanes: a flow whose every step sits in a top-level group.
|
|
107
|
+
const laneMode = layout === "flow" &&
|
|
108
|
+
groupIds.length > 0 &&
|
|
109
|
+
nodes.every((n) => (groupIds.includes(n.id) ? !n.parent : n.parent && groupIds.includes(n.parent)));
|
|
110
|
+
const groups = new Set(nodes.filter((n) => kindOf(n, layout) === "group").map((n) => n.id));
|
|
111
|
+
const boxes = nodes
|
|
112
|
+
.filter((n) => !(layout === "network" && groups.has(n.id)))
|
|
113
|
+
.map((n) => ({
|
|
114
|
+
id: n.id,
|
|
115
|
+
...sizeOf(n, layout),
|
|
116
|
+
...(n.parent && groups.has(n.parent) && layout !== "network" ? { parent: n.parent } : {}),
|
|
117
|
+
...(n.position && layout === "network" ? { fixed: n.position } : {}),
|
|
118
|
+
}));
|
|
119
|
+
let placed;
|
|
120
|
+
if (kept) {
|
|
121
|
+
placed = new Map();
|
|
122
|
+
for (const n of nodes)
|
|
123
|
+
placed.set(n.id, { ...(n.position ?? { x: 0, y: 0 }), ...(n.size ?? {}) });
|
|
124
|
+
// A group positioned by hand without a size wraps its children.
|
|
125
|
+
for (const g of groups) {
|
|
126
|
+
if (nodes.find((n) => n.id === g)?.size)
|
|
127
|
+
continue;
|
|
128
|
+
const children = nodes.filter((n) => n.parent === g);
|
|
129
|
+
let w = 160;
|
|
130
|
+
let h = 96;
|
|
131
|
+
for (const c of children) {
|
|
132
|
+
const s = sizeOf(c, layout);
|
|
133
|
+
w = Math.max(w, (c.position?.x ?? 0) + s.width + 20);
|
|
134
|
+
h = Math.max(h, (c.position?.y ?? 0) + s.height + 20);
|
|
135
|
+
}
|
|
136
|
+
placed.set(g, { ...placed.get(g), width: w, height: h });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (laneMode) {
|
|
140
|
+
placed = lanes(boxes, [...groups], edges, direction);
|
|
141
|
+
}
|
|
142
|
+
else if (layout === "network") {
|
|
143
|
+
placed = network(boxes, edges);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
placed = layered(boxes, edges, layout === "tree" ? "tree" : "flow", direction);
|
|
147
|
+
}
|
|
148
|
+
const absolute = (id) => placed.get(id) ?? { x: 0, y: 0 };
|
|
149
|
+
const flowNodes = [];
|
|
150
|
+
const ordered = [...nodes].sort((a, b) => Number(groups.has(b.id)) - Number(groups.has(a.id)));
|
|
151
|
+
for (const n of ordered) {
|
|
152
|
+
if (layout === "network" && groups.has(n.id))
|
|
153
|
+
continue;
|
|
154
|
+
const p = absolute(n.id);
|
|
155
|
+
const parent = n.parent && groups.has(n.parent) && layout !== "network" ? n.parent : undefined;
|
|
156
|
+
const size = groups.has(n.id) ? { width: p.width ?? 0, height: p.height ?? 0 } : sizeOf(n, layout);
|
|
157
|
+
// Laid out, positions are absolute: make a child's relative to its group.
|
|
158
|
+
const position = parent && !kept ? { x: p.x - absolute(parent).x, y: p.y - absolute(parent).y } : { x: p.x, y: p.y };
|
|
159
|
+
flowNodes.push({
|
|
160
|
+
id: n.id,
|
|
161
|
+
type: groups.has(n.id) ? "zon-group" : "zon",
|
|
162
|
+
position,
|
|
163
|
+
data: groups.has(n.id) && laneMode ? { node: n, lane: direction } : { node: n },
|
|
164
|
+
width: size.width,
|
|
165
|
+
height: size.height,
|
|
166
|
+
...(parent ? { parentId: parent, extent: "parent" } : {}),
|
|
167
|
+
...(groups.has(n.id) ? { selectable: true, zIndex: -1 } : {}),
|
|
168
|
+
ariaLabel: describeNode(n, layout),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const ids = new Set(flowNodes.map((n) => n.id));
|
|
172
|
+
const flowEdges = edges
|
|
173
|
+
.filter((e) => ids.has(e.source) && ids.has(e.target))
|
|
174
|
+
.map((e, i) => ({
|
|
175
|
+
id: e.id ?? `${e.source}->${e.target}#${i}`,
|
|
176
|
+
source: e.source,
|
|
177
|
+
target: e.target,
|
|
178
|
+
type: "zon",
|
|
179
|
+
data: { edge: e },
|
|
180
|
+
animated: e.animated,
|
|
181
|
+
ariaLabel: `${e.label ? `${e.label}: ` : ""}${labelOf(nodes, e.source)} to ${labelOf(nodes, e.target)}`,
|
|
182
|
+
}));
|
|
183
|
+
return { nodes: flowNodes, edges: flowEdges };
|
|
184
|
+
}
|
|
185
|
+
const labelOf = (nodes, id) => nodes.find((n) => n.id === id)?.label ?? id;
|
|
186
|
+
function describeNode(n, layout) {
|
|
187
|
+
const kind = kindOf(n, layout);
|
|
188
|
+
const what = kind === "start"
|
|
189
|
+
? "start"
|
|
190
|
+
: kind === "end"
|
|
191
|
+
? "end"
|
|
192
|
+
: kind === "gateway"
|
|
193
|
+
? `${n.gateway ?? "exclusive"} gateway`
|
|
194
|
+
: kind === "event"
|
|
195
|
+
? "event"
|
|
196
|
+
: kind === "group"
|
|
197
|
+
? "group"
|
|
198
|
+
: "";
|
|
199
|
+
return [n.label, what, n.meta].filter(Boolean).join(", ");
|
|
200
|
+
}
|
|
201
|
+
/** The value a consumer sees: their nodes and edges, with positions (and sizes for groups). */
|
|
202
|
+
function toValue(nodes, edges) {
|
|
203
|
+
return {
|
|
204
|
+
nodes: nodes.map((n) => {
|
|
205
|
+
const out = {
|
|
206
|
+
...n.data.node,
|
|
207
|
+
position: { x: Math.round(n.position.x), y: Math.round(n.position.y) },
|
|
208
|
+
};
|
|
209
|
+
if (n.type === "zon-group")
|
|
210
|
+
out.size = { width: Math.round(n.width ?? 0), height: Math.round(n.height ?? 0) };
|
|
211
|
+
return out;
|
|
212
|
+
}),
|
|
213
|
+
edges: edges.map((e) => ({ ...e.data.edge, id: e.id })),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/* ── Nodes ─────────────────────────────────────────────────────────────────── */
|
|
217
|
+
/** The handles a node is connected by: before and after it, in the direction of the flow. */
|
|
218
|
+
function Handles() {
|
|
219
|
+
const { direction } = useGraph();
|
|
220
|
+
const down = direction === "down";
|
|
221
|
+
return (_jsxs(_Fragment, { children: [_jsx(Handle, { type: "target", position: down ? Position.Top : Position.Left }), _jsx(Handle, { type: "source", position: down ? Position.Bottom : Position.Right })] }));
|
|
222
|
+
}
|
|
223
|
+
/** A label that turns into a field while it is being renamed. */
|
|
224
|
+
function Label({ kind, id, value, className, }) {
|
|
225
|
+
const { editing, setEditing, rename, text } = useGraph();
|
|
226
|
+
const active = editing?.kind === kind && editing.id === id;
|
|
227
|
+
const [draft, setDraft] = React.useState(value);
|
|
228
|
+
React.useEffect(() => setDraft(value), [value, active]);
|
|
229
|
+
if (!active)
|
|
230
|
+
return (_jsx("span", { "data-slot": "graph-label", className: cn("min-w-0 truncate", className), title: value, children: value }));
|
|
231
|
+
const done = (commit) => {
|
|
232
|
+
if (commit && draft.trim() && draft !== value)
|
|
233
|
+
rename(kind, id, draft.trim());
|
|
234
|
+
setEditing(null);
|
|
235
|
+
};
|
|
236
|
+
return (_jsx("input", {
|
|
237
|
+
// nodrag / nopan: typing and selecting text never moves the canvas.
|
|
238
|
+
className: cn("nodrag nopan min-w-0 border-0 bg-transparent p-0 text-inherit outline-none", className), "aria-label": kind === "node" ? text.nodeLabel : text.edgeLabel, autoFocus: true, value: draft, size: Math.max(4, draft.length), onChange: (event) => setDraft(event.currentTarget.value), onFocus: (event) => event.currentTarget.select(), onBlur: () => done(true), onKeyDown: (event) => {
|
|
239
|
+
event.stopPropagation();
|
|
240
|
+
if (event.key === "Enter")
|
|
241
|
+
done(true);
|
|
242
|
+
if (event.key === "Escape")
|
|
243
|
+
done(false);
|
|
244
|
+
} }));
|
|
245
|
+
}
|
|
246
|
+
const glyph = { exclusive: "×", parallel: "+", inclusive: "○" };
|
|
247
|
+
function NodeView({ id, data }) {
|
|
248
|
+
const { layout } = useGraph();
|
|
249
|
+
const n = data.node;
|
|
250
|
+
const kind = kindOf(n, layout);
|
|
251
|
+
const state = { "data-dim": data.dim ? "" : undefined, "data-lit": data.lit ? "" : undefined };
|
|
252
|
+
// Shapes whose name sits under them: events and gateways.
|
|
253
|
+
if (kind === "start" || kind === "end" || kind === "event" || kind === "gateway") {
|
|
254
|
+
return (_jsxs("div", { "data-slot": "graph-node", "data-kind": kind, ...state, className: "relative size-full", children: [_jsx(Handles, {}), _jsx("div", { "data-slot": "graph-shape", className: "grid size-full place-items-center", children: kind === "gateway" && (_jsx("span", { className: "font-mono text-[18px] leading-none text-foreground", children: glyph[n.gateway ?? "exclusive"] })) }), _jsx("div", { className: "pointer-events-none absolute top-full left-1/2 mt-2 w-max max-w-40 -translate-x-1/2 text-center font-mono text-[11px] leading-tight text-muted-foreground", children: _jsx(Label, { kind: "node", id: id, value: n.label, className: "pointer-events-auto" }) })] }));
|
|
255
|
+
}
|
|
256
|
+
if (kind === "note") {
|
|
257
|
+
return (_jsxs("div", { "data-slot": "graph-node", "data-kind": "note", ...state, className: "flex size-full items-center ps-3 text-[13px] leading-snug text-muted-foreground", children: [_jsx(Handles, {}), _jsx(Label, { kind: "node", id: id, value: n.label, className: "line-clamp-2 whitespace-normal" })] }));
|
|
258
|
+
}
|
|
259
|
+
if (kind === "person") {
|
|
260
|
+
return (_jsxs("div", { "data-slot": "graph-node", "data-kind": "person", ...state, className: "flex size-full flex-col items-center gap-1.5 pt-1 text-center", children: [_jsx(Handles, {}), _jsx(Avatar, { "data-slot": "graph-avatar", src: n.image, name: n.label, size: "lg" }), _jsxs("div", { className: "flex w-full min-w-0 flex-col items-center gap-0.5", children: [_jsx(Label, { kind: "node", id: id, value: n.label, className: "max-w-full text-[13px] font-medium text-foreground" }), n.meta && (_jsx("span", { className: "max-w-full truncate font-mono text-[11px] text-muted-foreground", children: n.meta }))] })] }));
|
|
261
|
+
}
|
|
262
|
+
return (_jsxs("div", { "data-slot": "graph-node", "data-kind": kind, ...state, className: cn("flex size-full min-w-0 items-center gap-2.5 material-raised text-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground", kind === "entity" ? "rounded-full px-3.5 text-[13px]" : "rounded-button px-3.5 text-[14px]"), children: [_jsx(Handles, {}), n.icon, _jsxs("div", { className: "flex min-w-0 flex-col", children: [_jsx(Label, { kind: "node", id: id, value: n.label, className: "leading-tight" }), n.meta && kind === "task" && (_jsx("span", { className: "mt-1 truncate font-mono text-[11px] leading-none text-muted-foreground", children: n.meta }))] })] }));
|
|
263
|
+
}
|
|
264
|
+
function GroupView({ id, data }) {
|
|
265
|
+
// A swimlane: a band with its name in a strip at the start, set along the flow.
|
|
266
|
+
if (data.lane) {
|
|
267
|
+
const down = data.lane === "down";
|
|
268
|
+
return (_jsx("div", { "data-slot": "graph-group", "data-lane": data.lane, className: cn("flex size-full border border-field-edge", down ? "flex-col" : "flex-row"), children: _jsx("div", { className: cn("flex shrink-0 items-center justify-center border-field-edge eyebrow text-[10px]", down ? "w-full border-b" : "h-full border-e"), style: down ? { height: LANE_HEADER } : { width: LANE_HEADER }, children: _jsx("span", { className: down ? "" : "rotate-180 [writing-mode:vertical-rl]", children: _jsx(Label, { kind: "node", id: id, value: data.node.label }) }) }) }));
|
|
269
|
+
}
|
|
270
|
+
return (_jsx("div", { "data-slot": "graph-group", "data-dim": data.dim ? "" : undefined, className: "size-full border border-dashed border-field-edge", children: _jsx("div", { className: "px-3 pt-2.5 eyebrow text-[10px]", children: _jsx(Label, { kind: "node", id: id, value: data.node.label }) }) }));
|
|
271
|
+
}
|
|
272
|
+
/** A path through points with each corner rounded: the route of an edge that goes back. */
|
|
273
|
+
function roundedPath(points, radius = 12) {
|
|
274
|
+
let d = `M${points[0].x},${points[0].y}`;
|
|
275
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
276
|
+
const prev = points[i - 1];
|
|
277
|
+
const at = points[i];
|
|
278
|
+
const next = points[i + 1];
|
|
279
|
+
const inLen = Math.hypot(at.x - prev.x, at.y - prev.y);
|
|
280
|
+
const outLen = Math.hypot(next.x - at.x, next.y - at.y);
|
|
281
|
+
const r = Math.min(radius, inLen / 2, outLen / 2);
|
|
282
|
+
const a = {
|
|
283
|
+
x: at.x - ((at.x - prev.x) / (inLen || 1)) * r,
|
|
284
|
+
y: at.y - ((at.y - prev.y) / (inLen || 1)) * r,
|
|
285
|
+
};
|
|
286
|
+
const b = {
|
|
287
|
+
x: at.x + ((next.x - at.x) / (outLen || 1)) * r,
|
|
288
|
+
y: at.y + ((next.y - at.y) / (outLen || 1)) * r,
|
|
289
|
+
};
|
|
290
|
+
d += ` L${a.x},${a.y} Q${at.x},${at.y} ${b.x},${b.y}`;
|
|
291
|
+
}
|
|
292
|
+
const last = points.at(-1);
|
|
293
|
+
return `${d} L${last.x},${last.y}`;
|
|
294
|
+
}
|
|
295
|
+
/** The box a node is drawn in, in flow coordinates. */
|
|
296
|
+
function boundsOf(node) {
|
|
297
|
+
const { x, y } = node.internals.positionAbsolute;
|
|
298
|
+
return { x, y, w: node.measured.width ?? node.width ?? 0, h: node.measured.height ?? node.height ?? 0 };
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* The box around top-level nodes, from their own positions and sizes: what React Flow's
|
|
302
|
+
* `getNodesBounds` gives without its node lookup, without the warning it logs (in development)
|
|
303
|
+
* on every such call.
|
|
304
|
+
*/
|
|
305
|
+
function boxAround(nodes) {
|
|
306
|
+
if (!nodes.length)
|
|
307
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
308
|
+
const x = Math.min(...nodes.map((n) => n.position.x));
|
|
309
|
+
const y = Math.min(...nodes.map((n) => n.position.y));
|
|
310
|
+
const right = Math.max(...nodes.map((n) => n.position.x + (n.width ?? 0)));
|
|
311
|
+
const bottom = Math.max(...nodes.map((n) => n.position.y + (n.height ?? 0)));
|
|
312
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
313
|
+
}
|
|
314
|
+
/* ── Edges ─────────────────────────────────────────────────────────────────── */
|
|
315
|
+
/** Where the line from a node's centre towards a point leaves the node: a circle or a box. */
|
|
316
|
+
function exit(node, toward, layout) {
|
|
317
|
+
const w = node.measured.width ?? node.width ?? 0;
|
|
318
|
+
const h = node.measured.height ?? node.height ?? 0;
|
|
319
|
+
const { x, y } = node.internals.positionAbsolute;
|
|
320
|
+
const kind = kindOf(node.data.node, layout);
|
|
321
|
+
// A person is joined at their avatar, the circle at the top of the node.
|
|
322
|
+
const cx = x + w / 2;
|
|
323
|
+
const cy = kind === "person" ? y + 24 : y + h / 2;
|
|
324
|
+
const dx = toward.x - cx;
|
|
325
|
+
const dy = toward.y - cy;
|
|
326
|
+
const len = Math.hypot(dx, dy) || 1;
|
|
327
|
+
const round = kind === "person" || kind === "start" || kind === "end" || kind === "event";
|
|
328
|
+
const reach = round
|
|
329
|
+
? kind === "person"
|
|
330
|
+
? 20
|
|
331
|
+
: w / 2
|
|
332
|
+
: Math.min(w / 2 / (Math.abs(dx) / len || 1e-6), h / 2 / (Math.abs(dy) / len || 1e-6));
|
|
333
|
+
const gap = 5;
|
|
334
|
+
return { x: cx + (dx / len) * (reach + gap), y: cy + (dy / len) * (reach + gap), cx, cy };
|
|
335
|
+
}
|
|
336
|
+
function EdgeView(props) {
|
|
337
|
+
const { layout, markers, direction, editing } = useGraph();
|
|
338
|
+
const { id, source, target, data } = props;
|
|
339
|
+
const s = useInternalNode(source);
|
|
340
|
+
const t = useInternalNode(target);
|
|
341
|
+
const edge = data.edge;
|
|
342
|
+
const kind = edgeKindOf(edge, layout);
|
|
343
|
+
const floating = layout === "network" || layout === "none";
|
|
344
|
+
let path;
|
|
345
|
+
let labelX;
|
|
346
|
+
let labelY;
|
|
347
|
+
if (floating && s && t) {
|
|
348
|
+
const sc = exit(s, { x: 0, y: 0 }, layout);
|
|
349
|
+
const tc = exit(t, { x: 0, y: 0 }, layout);
|
|
350
|
+
const a = exit(s, { x: tc.cx, y: tc.cy }, layout);
|
|
351
|
+
const b = exit(t, { x: sc.cx, y: sc.cy }, layout);
|
|
352
|
+
[path, labelX, labelY] = getStraightPath({ sourceX: a.x, sourceY: a.y, targetX: b.x, targetY: b.y });
|
|
353
|
+
}
|
|
354
|
+
else if (s &&
|
|
355
|
+
t &&
|
|
356
|
+
(direction === "down" ? props.targetY < props.sourceY + 8 : props.targetX < props.sourceX + 8)) {
|
|
357
|
+
// An edge that goes back against the flow: around the outside of both nodes, not through
|
|
358
|
+
// the ones between them — below a flow that runs right, beside one that runs down.
|
|
359
|
+
const a = boundsOf(s);
|
|
360
|
+
const b = boundsOf(t);
|
|
361
|
+
const out = 18;
|
|
362
|
+
if (direction === "down") {
|
|
363
|
+
const side = Math.max(a.x + a.w, b.x + b.w) + 32;
|
|
364
|
+
const points = [
|
|
365
|
+
{ x: props.sourceX, y: props.sourceY },
|
|
366
|
+
{ x: props.sourceX, y: props.sourceY + out },
|
|
367
|
+
{ x: side, y: props.sourceY + out },
|
|
368
|
+
{ x: side, y: props.targetY - out },
|
|
369
|
+
{ x: props.targetX, y: props.targetY - out },
|
|
370
|
+
{ x: props.targetX, y: props.targetY },
|
|
371
|
+
];
|
|
372
|
+
path = roundedPath(points);
|
|
373
|
+
labelX = side;
|
|
374
|
+
labelY = (props.sourceY + props.targetY) / 2;
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const below = Math.max(a.y + a.h, b.y + b.h) + 32;
|
|
378
|
+
const points = [
|
|
379
|
+
{ x: props.sourceX, y: props.sourceY },
|
|
380
|
+
{ x: props.sourceX + out, y: props.sourceY },
|
|
381
|
+
{ x: props.sourceX + out, y: below },
|
|
382
|
+
{ x: props.targetX - out, y: below },
|
|
383
|
+
{ x: props.targetX - out, y: props.targetY },
|
|
384
|
+
{ x: props.targetX, y: props.targetY },
|
|
385
|
+
];
|
|
386
|
+
path = roundedPath(points);
|
|
387
|
+
labelX = (props.sourceX + props.targetX) / 2;
|
|
388
|
+
labelY = below;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
[path, labelX, labelY] = getSmoothStepPath({
|
|
393
|
+
sourceX: props.sourceX,
|
|
394
|
+
sourceY: props.sourceY,
|
|
395
|
+
sourcePosition: props.sourcePosition,
|
|
396
|
+
targetX: props.targetX,
|
|
397
|
+
targetY: props.targetY,
|
|
398
|
+
targetPosition: props.targetPosition,
|
|
399
|
+
borderRadius: 12,
|
|
400
|
+
offset: 16,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
const directed = isDirected(edge, layout);
|
|
404
|
+
const marker = directed ? `url(#${markers}-${data?.lit || props.selected ? "lit" : "rest"})` : undefined;
|
|
405
|
+
return (_jsxs(_Fragment, { children: [_jsx(BaseEdge, { id: id, path: path, markerEnd: marker, interactionWidth: 18, "data-kind": kind, className: "zon-graph-edge", "data-dim": data?.dim ? "" : undefined,
|
|
406
|
+
"data-lit": data?.lit || props.selected ? "" : undefined }), (edge.label || (editing?.kind === "edge" && editing.id === id)) && (_jsx(EdgeLabelRenderer, { children: _jsx("div", { "data-slot": "graph-edge-label", "data-edge": id, "data-dim": data?.dim ? "" : undefined, "data-lit": data?.lit || props.selected ? "" : undefined, className: "nodrag nopan pointer-events-auto absolute", style: { transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }, children: _jsx(Label, { kind: "edge", id: id, value: edge.label ?? "" }) }) }))] }));
|
|
407
|
+
}
|
|
408
|
+
/** What the canvas menu offers to add, by layout. */
|
|
409
|
+
const addable = {
|
|
410
|
+
flow: ["task", "gateway", "event", "start", "end", "note"],
|
|
411
|
+
tree: ["person", "task"],
|
|
412
|
+
network: ["entity", "person"],
|
|
413
|
+
none: ["task", "entity", "person", "note"],
|
|
414
|
+
};
|
|
415
|
+
const nodeTypes = { zon: NodeView, "zon-group": GroupView };
|
|
416
|
+
const edgeTypes = { zon: EdgeView };
|
|
417
|
+
/**
|
|
418
|
+
* Graph — things and how they connect, on a canvas that pans and zooms: a flow of steps (BPMN
|
|
419
|
+
* tasks, events and gateways), an org chart or tree, or a network of relations (people, shows,
|
|
420
|
+
* systems). Pass `nodes` and `edges`; the layout places them — layered for flows and trees, by
|
|
421
|
+
* forces for networks — or keeps the positions you give.
|
|
422
|
+
*
|
|
423
|
+
* Hover or select a node to light up its connections. In a network, drag a node and its
|
|
424
|
+
* neighbours follow. With `editable`, it is a small diagram editor that reports every change
|
|
425
|
+
* through `onChange`. It needs `@xyflow/react`, `@dagrejs/dagre` and `d3-force`, and is
|
|
426
|
+
* imported from `@zonsh/ui/graph`. The rule people break: a hairball. Past a few dozen nodes,
|
|
427
|
+
* show a part of the graph, or group it.
|
|
428
|
+
*/
|
|
429
|
+
export function Graph(props) {
|
|
430
|
+
return (_jsx(ReactFlowProvider, { children: _jsx(GraphCanvas, { ...props }) }));
|
|
431
|
+
}
|
|
432
|
+
function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", direction: directionProp, editable = false, onChange, onSelect, newNodeKind, minimap = false, controls = true, background = "dots", variant = "region", labels, className, ...props }) {
|
|
433
|
+
const text = useMessages("graph", defaultMessages, labels);
|
|
434
|
+
const textRef = React.useRef(text);
|
|
435
|
+
textRef.current = text;
|
|
436
|
+
const ariaLabelConfig = React.useMemo(() => ({
|
|
437
|
+
"node.a11yDescription.default": text.nodeHelp,
|
|
438
|
+
"edge.a11yDescription.default": text.edgeHelp,
|
|
439
|
+
"node.a11yDescription.ariaLiveMessage": ({ direction, x, y, }) => text.moved(direction, x, y),
|
|
440
|
+
"handle.ariaLabel": text.handle,
|
|
441
|
+
"minimap.ariaLabel": text.minimap,
|
|
442
|
+
}), [text]);
|
|
443
|
+
const direction = directionProp ?? (layout === "tree" ? "down" : "right");
|
|
444
|
+
const flow = useReactFlow();
|
|
445
|
+
const markers = React.useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
446
|
+
const frame = React.useRef(null);
|
|
447
|
+
const describedBy = `${markers}-connections`;
|
|
448
|
+
const [state, setState] = React.useState(() => build({ nodes: nodesProp, edges: edgesProp }, layout, direction));
|
|
449
|
+
const latest = React.useRef(state);
|
|
450
|
+
latest.current = state;
|
|
451
|
+
// The value last sent out: when it comes back as props, it is not laid out again.
|
|
452
|
+
const sent = React.useRef(null);
|
|
453
|
+
React.useEffect(() => {
|
|
454
|
+
if (sent.current && sent.current.nodes === nodesProp && sent.current.edges === edgesProp)
|
|
455
|
+
return;
|
|
456
|
+
setState(build({ nodes: nodesProp, edges: edgesProp }, layout, direction));
|
|
457
|
+
requestAnimationFrame(() => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 0 }));
|
|
458
|
+
}, [nodesProp, edgesProp, layout, direction, flow]);
|
|
459
|
+
const emit = React.useCallback((next) => {
|
|
460
|
+
if (!onChange)
|
|
461
|
+
return;
|
|
462
|
+
const value = toValue(next.nodes, next.edges);
|
|
463
|
+
sent.current = value;
|
|
464
|
+
onChange(value);
|
|
465
|
+
}, [onChange]);
|
|
466
|
+
/* Light up what the pointer or the selection is on, and its neighbours. */
|
|
467
|
+
const [hovered, setHovered] = React.useState(null);
|
|
468
|
+
const [selected, setSelected] = React.useState([]);
|
|
469
|
+
const focus = hovered ? [hovered] : selected;
|
|
470
|
+
const shown = React.useMemo(() => {
|
|
471
|
+
if (!focus.length)
|
|
472
|
+
return state;
|
|
473
|
+
const lit = new Set(focus);
|
|
474
|
+
const litEdges = new Set();
|
|
475
|
+
for (const e of state.edges) {
|
|
476
|
+
if (lit.has(e.source) || lit.has(e.target)) {
|
|
477
|
+
litEdges.add(e.id);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const near = new Set(focus);
|
|
481
|
+
for (const e of state.edges)
|
|
482
|
+
if (litEdges.has(e.id))
|
|
483
|
+
near.add(e.source).add(e.target);
|
|
484
|
+
return {
|
|
485
|
+
nodes: state.nodes.map((n) => n.type === "zon-group" ? n : { ...n, data: { ...n.data, dim: !near.has(n.id), lit: lit.has(n.id) } }),
|
|
486
|
+
edges: state.edges.map((e) => ({
|
|
487
|
+
...e,
|
|
488
|
+
data: { ...e.data, dim: !litEdges.has(e.id), lit: litEdges.has(e.id) },
|
|
489
|
+
})),
|
|
490
|
+
};
|
|
491
|
+
}, [state, focus.join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
492
|
+
/* Editing. */
|
|
493
|
+
const [editing, setEditing] = React.useState(null);
|
|
494
|
+
const rename = React.useCallback((kind, id, label) => {
|
|
495
|
+
const s = latest.current;
|
|
496
|
+
const next = kind === "node"
|
|
497
|
+
? {
|
|
498
|
+
...s,
|
|
499
|
+
nodes: s.nodes.map((n) => n.id === id ? { ...n, data: { ...n.data, node: { ...n.data.node, label } } } : n),
|
|
500
|
+
}
|
|
501
|
+
: {
|
|
502
|
+
...s,
|
|
503
|
+
edges: s.edges.map((e) => e.id === id ? { ...e, data: { ...e.data, edge: { ...e.data.edge, label } } } : e),
|
|
504
|
+
};
|
|
505
|
+
setState(next);
|
|
506
|
+
emit(next);
|
|
507
|
+
}, [emit]);
|
|
508
|
+
const onNodesChange = React.useCallback((changes) => {
|
|
509
|
+
// Removing a node removes its edges with it.
|
|
510
|
+
const gone = new Set(changes.filter((c) => c.type === "remove").map((c) => c.id));
|
|
511
|
+
if (gone.size) {
|
|
512
|
+
const s = latest.current;
|
|
513
|
+
const next = {
|
|
514
|
+
nodes: applyNodeChanges(changes, s.nodes),
|
|
515
|
+
edges: s.edges.filter((e) => !gone.has(e.source) && !gone.has(e.target)),
|
|
516
|
+
};
|
|
517
|
+
setState(next);
|
|
518
|
+
emit(next);
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
// Moves, sizes and selection apply to the newest state: while a network settles, the
|
|
522
|
+
// simulation moves the other nodes in the same frames as the drag.
|
|
523
|
+
setState((prev) => {
|
|
524
|
+
const next = { ...prev, nodes: applyNodeChanges(changes, prev.nodes) };
|
|
525
|
+
latest.current = next;
|
|
526
|
+
return next;
|
|
527
|
+
});
|
|
528
|
+
}, [emit]);
|
|
529
|
+
const onEdgesChange = React.useCallback((changes) => {
|
|
530
|
+
const s = latest.current;
|
|
531
|
+
const next = { ...s, edges: applyEdgeChanges(changes, s.edges) };
|
|
532
|
+
setState(next);
|
|
533
|
+
if (changes.some((c) => c.type === "remove"))
|
|
534
|
+
emit(next);
|
|
535
|
+
}, [emit]);
|
|
536
|
+
const onConnect = React.useCallback((c) => {
|
|
537
|
+
if (!c.source || !c.target || c.source === c.target)
|
|
538
|
+
return;
|
|
539
|
+
const s = latest.current;
|
|
540
|
+
const edge = { source: c.source, target: c.target };
|
|
541
|
+
const id = `${c.source}->${c.target}#${Date.now().toString(36)}`;
|
|
542
|
+
const next = {
|
|
543
|
+
...s,
|
|
544
|
+
edges: [...s.edges, { id, source: c.source, target: c.target, type: "zon", data: { edge } }],
|
|
545
|
+
};
|
|
546
|
+
setState(next);
|
|
547
|
+
emit(next);
|
|
548
|
+
}, [emit]);
|
|
549
|
+
// A connection let go anywhere on another node — not only on its handle — connects to it.
|
|
550
|
+
const onConnectEnd = React.useCallback((event, state) => {
|
|
551
|
+
if (state.isValid || !state.fromNode)
|
|
552
|
+
return;
|
|
553
|
+
const point = "changedTouches" in event ? event.changedTouches[0] : event;
|
|
554
|
+
if (!point)
|
|
555
|
+
return;
|
|
556
|
+
const target = document
|
|
557
|
+
.elementFromPoint(point.clientX, point.clientY)
|
|
558
|
+
?.closest(".react-flow__node");
|
|
559
|
+
const id = target?.dataset.id;
|
|
560
|
+
if (!id || id === state.fromNode.id)
|
|
561
|
+
return;
|
|
562
|
+
const from = state.fromNode.id;
|
|
563
|
+
onConnect(state.fromHandle?.type === "target"
|
|
564
|
+
? { source: id, target: from, sourceHandle: null, targetHandle: null }
|
|
565
|
+
: { source: from, target: id, sourceHandle: null, targetHandle: null });
|
|
566
|
+
}, [onConnect]);
|
|
567
|
+
const addNode = React.useCallback((at, as) => {
|
|
568
|
+
const s = latest.current;
|
|
569
|
+
const kind = as ?? newNodeKind ?? (layout === "network" ? "entity" : "task");
|
|
570
|
+
const node = {
|
|
571
|
+
id: `n${Date.now().toString(36)}`,
|
|
572
|
+
label: textRef.current.newNode(kind),
|
|
573
|
+
kind,
|
|
574
|
+
};
|
|
575
|
+
const size = sizeOf(node, layout);
|
|
576
|
+
// Without a point, the middle of what is in view.
|
|
577
|
+
const box = frame.current?.getBoundingClientRect();
|
|
578
|
+
const center = at ??
|
|
579
|
+
flow.screenToFlowPosition({
|
|
580
|
+
x: box ? box.left + box.width / 2 : window.innerWidth / 2,
|
|
581
|
+
y: box ? box.top + box.height / 2 : window.innerHeight / 2,
|
|
582
|
+
});
|
|
583
|
+
const flowNode = {
|
|
584
|
+
id: node.id,
|
|
585
|
+
type: "zon",
|
|
586
|
+
position: { x: center.x - size.width / 2, y: center.y - size.height / 2 },
|
|
587
|
+
data: { node },
|
|
588
|
+
width: size.width,
|
|
589
|
+
height: size.height,
|
|
590
|
+
selected: true,
|
|
591
|
+
ariaLabel: node.label,
|
|
592
|
+
};
|
|
593
|
+
const next = { ...s, nodes: [...s.nodes.map((n) => ({ ...n, selected: false })), flowNode] };
|
|
594
|
+
setState(next);
|
|
595
|
+
emit(next);
|
|
596
|
+
setEditing({ kind: "node", id: node.id });
|
|
597
|
+
}, [emit, flow, layout, newNodeKind]);
|
|
598
|
+
/*
|
|
599
|
+
* Tidying moves the nodes to their new places, so you can follow where each one goes: they
|
|
600
|
+
* glide from where they stand, the connections following every frame, and the camera moves on
|
|
601
|
+
* the same clock to where it will frame the result — one movement, not a move and then a zoom. A Web Animation keeps the time and the eased progress, so slow motion slows it and
|
|
602
|
+
* reduced motion (a 0 --duration) jumps. Tidying again, or grabbing a node, stops it where it is.
|
|
603
|
+
*/
|
|
604
|
+
const tidying = React.useRef(null);
|
|
605
|
+
React.useEffect(() => () => tidying.current?.stop(), []);
|
|
606
|
+
const tidy = React.useCallback(() => {
|
|
607
|
+
tidying.current?.stop();
|
|
608
|
+
const from = latest.current;
|
|
609
|
+
const value = toValue(from.nodes, from.edges);
|
|
610
|
+
const next = build({ nodes: value.nodes.map(({ position: _p, size: _s, ...n }) => n), edges: value.edges }, layout, direction);
|
|
611
|
+
const el = frame.current;
|
|
612
|
+
const duration = el ? cssDuration(el) * 3 : 0;
|
|
613
|
+
// Without motion (reduced motion) the camera jumps too.
|
|
614
|
+
const fit = () => requestAnimationFrame(() => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: duration ? 280 : 0 }));
|
|
615
|
+
if (!el || !duration) {
|
|
616
|
+
setState(next);
|
|
617
|
+
emit(next);
|
|
618
|
+
fit();
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
const start = new Map(from.nodes.map((n) => [n.id, n.position]));
|
|
622
|
+
// Where the camera will frame the tidied graph (top-level nodes: lanes hold their own).
|
|
623
|
+
const pane = el.querySelector(".react-flow");
|
|
624
|
+
const camera0 = flow.getViewport();
|
|
625
|
+
const camera1 = pane
|
|
626
|
+
? getViewportForBounds(boxAround(next.nodes.filter((n) => !n.parentId)), pane.clientWidth, pane.clientHeight, 0.2, 1.15, 0.18)
|
|
627
|
+
: null;
|
|
628
|
+
const ease = getComputedStyle(el).getPropertyValue("--ease").trim() || "ease-out";
|
|
629
|
+
// No keyframes: the animation only keeps the clock; its progress places the nodes.
|
|
630
|
+
const clock = el.animate([], { duration, easing: ease });
|
|
631
|
+
let raf = 0;
|
|
632
|
+
const place = (progress) => {
|
|
633
|
+
if (camera1)
|
|
634
|
+
void flow.setViewport({
|
|
635
|
+
x: camera0.x + (camera1.x - camera0.x) * progress,
|
|
636
|
+
y: camera0.y + (camera1.y - camera0.y) * progress,
|
|
637
|
+
zoom: camera0.zoom + (camera1.zoom - camera0.zoom) * progress,
|
|
638
|
+
});
|
|
639
|
+
setState({
|
|
640
|
+
...next,
|
|
641
|
+
nodes: next.nodes.map((n) => {
|
|
642
|
+
const a = start.get(n.id) ?? n.position;
|
|
643
|
+
return {
|
|
644
|
+
...n,
|
|
645
|
+
position: { x: a.x + (n.position.x - a.x) * progress, y: a.y + (n.position.y - a.y) * progress },
|
|
646
|
+
};
|
|
647
|
+
}),
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
const step = () => {
|
|
651
|
+
place(clock.effect?.getComputedTiming().progress ?? 1);
|
|
652
|
+
raf = requestAnimationFrame(step);
|
|
653
|
+
};
|
|
654
|
+
raf = requestAnimationFrame(step);
|
|
655
|
+
const end = () => {
|
|
656
|
+
cancelAnimationFrame(raf);
|
|
657
|
+
tidying.current = null;
|
|
658
|
+
};
|
|
659
|
+
clock.onfinish = () => {
|
|
660
|
+
end();
|
|
661
|
+
place(1);
|
|
662
|
+
setState(next);
|
|
663
|
+
emit(next);
|
|
664
|
+
if (!camera1)
|
|
665
|
+
fit();
|
|
666
|
+
};
|
|
667
|
+
tidying.current = {
|
|
668
|
+
stop: () => {
|
|
669
|
+
clock.onfinish = null;
|
|
670
|
+
clock.cancel();
|
|
671
|
+
end();
|
|
672
|
+
emit(latest.current);
|
|
673
|
+
},
|
|
674
|
+
};
|
|
675
|
+
}, [direction, emit, flow, layout]);
|
|
676
|
+
/* Networks: a dragged node pulls its neighbours along, and the rest settles around it. */
|
|
677
|
+
const physics = React.useRef(null);
|
|
678
|
+
const reduce = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
679
|
+
const onNodeDragStart = React.useCallback((_, node) => {
|
|
680
|
+
tidying.current?.stop();
|
|
681
|
+
// A network of hundreds of nodes moves only the node dragged: settling it live would take
|
|
682
|
+
// longer than a frame at every frame.
|
|
683
|
+
if (layout !== "network" || reduce() || latest.current.nodes.length > LIVE_DRAG_MAX)
|
|
684
|
+
return;
|
|
685
|
+
// A drag that starts while the last one settles takes over from it: one simulation at a time.
|
|
686
|
+
physics.current?.stop();
|
|
687
|
+
physics.current = null;
|
|
688
|
+
const s = latest.current;
|
|
689
|
+
const boxes = s.nodes.map((n) => ({
|
|
690
|
+
id: n.id,
|
|
691
|
+
width: n.width ?? 0,
|
|
692
|
+
height: n.height ?? 0,
|
|
693
|
+
fixed: n.position,
|
|
694
|
+
}));
|
|
695
|
+
const { simulation, sim } = dragSimulation(boxes, s.edges.map((e) => ({ source: e.source, target: e.target })), node.id);
|
|
696
|
+
// Held, the graph stays warm so the neighbours keep up with the pointer.
|
|
697
|
+
simulation.alpha(0.3).alphaTarget(0.3);
|
|
698
|
+
let frame = 0;
|
|
699
|
+
const sizes = new Map(s.nodes.map((n) => [n.id, { w: n.width ?? 0, h: n.height ?? 0 }]));
|
|
700
|
+
const byId = new Map(sim.map((d) => [d.id, d]));
|
|
701
|
+
const held = new Set([node.id]);
|
|
702
|
+
const step = () => {
|
|
703
|
+
simulation.tick();
|
|
704
|
+
setState((prev) => {
|
|
705
|
+
const next = {
|
|
706
|
+
...prev,
|
|
707
|
+
nodes: prev.nodes.map((n) => {
|
|
708
|
+
const d = byId.get(n.id);
|
|
709
|
+
if (!d || held.has(n.id))
|
|
710
|
+
return n;
|
|
711
|
+
const box = sizes.get(n.id);
|
|
712
|
+
return { ...n, position: { x: (d.x ?? 0) - box.w / 2, y: (d.y ?? 0) - box.h / 2 } };
|
|
713
|
+
}),
|
|
714
|
+
};
|
|
715
|
+
latest.current = next;
|
|
716
|
+
return next;
|
|
717
|
+
});
|
|
718
|
+
if (simulation.alpha() > simulation.alphaMin())
|
|
719
|
+
frame = requestAnimationFrame(step);
|
|
720
|
+
else
|
|
721
|
+
physics.current = null;
|
|
722
|
+
};
|
|
723
|
+
frame = requestAnimationFrame(step);
|
|
724
|
+
physics.current = {
|
|
725
|
+
stop: () => {
|
|
726
|
+
cancelAnimationFrame(frame);
|
|
727
|
+
simulation.stop();
|
|
728
|
+
},
|
|
729
|
+
fix: (id, x, y) => {
|
|
730
|
+
const d = byId.get(id);
|
|
731
|
+
const box = sizes.get(id);
|
|
732
|
+
if (d) {
|
|
733
|
+
d.fx = x + box.w / 2;
|
|
734
|
+
d.fy = y + box.h / 2;
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
release: () => {
|
|
738
|
+
// Let go, the node stays where it was dropped and the rest settles around it.
|
|
739
|
+
held.clear();
|
|
740
|
+
simulation.alphaTarget(0);
|
|
741
|
+
},
|
|
742
|
+
};
|
|
743
|
+
}, [layout]);
|
|
744
|
+
const onNodeDrag = React.useCallback((_, node) => {
|
|
745
|
+
physics.current?.fix(node.id, node.position.x, node.position.y);
|
|
746
|
+
}, []);
|
|
747
|
+
const onNodeDragStop = React.useCallback(() => {
|
|
748
|
+
physics.current?.release();
|
|
749
|
+
// Report once the graph has come to rest (or at once, without the physics).
|
|
750
|
+
const wait = () => {
|
|
751
|
+
if (physics.current)
|
|
752
|
+
requestAnimationFrame(wait);
|
|
753
|
+
else
|
|
754
|
+
emit(latest.current);
|
|
755
|
+
};
|
|
756
|
+
wait();
|
|
757
|
+
}, [emit]);
|
|
758
|
+
React.useEffect(() => () => physics.current?.stop(), []);
|
|
759
|
+
const onSelectionChange = React.useCallback(({ nodes, edges }) => {
|
|
760
|
+
setSelected(nodes.filter((n) => n.type !== "zon-group").map((n) => n.id));
|
|
761
|
+
onSelect?.({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) });
|
|
762
|
+
}, [onSelect]);
|
|
763
|
+
const context = React.useMemo(() => ({ text, layout, direction, editable, markers, editing, setEditing, rename }), [text, layout, direction, editable, markers, editing, rename]);
|
|
764
|
+
/* The context menu: what was right-clicked. */
|
|
765
|
+
const [target, setTarget] = React.useState(null);
|
|
766
|
+
const pick = (event) => {
|
|
767
|
+
const el = event.target;
|
|
768
|
+
// Fields, the controls and the map keep the browser's own menu.
|
|
769
|
+
if (el.closest("input, textarea, .react-flow__panel, .react-flow__minimap")) {
|
|
770
|
+
event.stopPropagation();
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
const node = el.closest(".react-flow__node");
|
|
774
|
+
const edge = el.closest(".react-flow__edge, [data-slot='graph-edge-label']");
|
|
775
|
+
if (node?.dataset.id)
|
|
776
|
+
setTarget({
|
|
777
|
+
type: node.classList.contains("react-flow__node-zon-group") ? "group" : "node",
|
|
778
|
+
id: node.dataset.id,
|
|
779
|
+
});
|
|
780
|
+
else if (edge) {
|
|
781
|
+
const id = edge.dataset.id ?? edge.dataset.edge;
|
|
782
|
+
if (id)
|
|
783
|
+
setTarget({ type: "edge", id });
|
|
784
|
+
}
|
|
785
|
+
else
|
|
786
|
+
setTarget({ type: "pane", at: flow.screenToFlowPosition({ x: event.clientX, y: event.clientY }) });
|
|
787
|
+
};
|
|
788
|
+
const removeNode = (id) => onNodesChange([{ type: "remove", id }]);
|
|
789
|
+
const removeEdge = (id) => onEdgesChange([{ type: "remove", id }]);
|
|
790
|
+
const reverse = (id) => {
|
|
791
|
+
const s = latest.current;
|
|
792
|
+
const next = {
|
|
793
|
+
...s,
|
|
794
|
+
edges: s.edges.map((e) => e.id === id
|
|
795
|
+
? {
|
|
796
|
+
...e,
|
|
797
|
+
source: e.target,
|
|
798
|
+
target: e.source,
|
|
799
|
+
data: { ...e.data, edge: { ...e.data.edge, source: e.target, target: e.source } },
|
|
800
|
+
}
|
|
801
|
+
: e),
|
|
802
|
+
};
|
|
803
|
+
setState(next);
|
|
804
|
+
emit(next);
|
|
805
|
+
};
|
|
806
|
+
const targetEdge = target?.type === "edge" ? state.edges.find((e) => e.id === target.id) : undefined;
|
|
807
|
+
const stepped = layout === "flow" || layout === "tree";
|
|
808
|
+
const nodeLabels = React.useMemo(() => new Map(state.nodes.map((n) => [n.id, n.data.node.label])), [state.nodes]);
|
|
809
|
+
const canvas = (_jsxs(ReactFlow, { nodes: shown.nodes, edges: shown.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: editable ? onConnect : undefined, onConnectEnd: editable ? onConnectEnd : undefined, onNodeMouseEnter: (_, n) => n.type !== "zon-group" && setHovered(n.id), onNodeMouseLeave: () => setHovered(null), onNodeDragStart: onNodeDragStart, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop, onSelectionChange: onSelectionChange, nodesConnectable: editable, edgesReconnectable: false, deleteKeyCode: editable ? ["Backspace", "Delete"] : null, connectionLineType: stepped ? ConnectionLineType.SmoothStep : ConnectionLineType.Straight, fitView: true, fitViewOptions: { padding: 0.18, maxZoom: 1.15 }, minZoom: 0.2, maxZoom: 2, proOptions: { hideAttribution: true }, ariaLabelConfig: ariaLabelConfig, "aria-describedby": describedBy, children: [background !== "none" && (_jsx(Background, { variant: background === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Dots, gap: background === "lines" ? 32 : 20, size: 1 })), minimap && (_jsx(MiniMap, { position: "bottom-right", style: { width: 152, height: 100 }, pannable: true, zoomable: true, nodeBorderRadius: 4, ariaLabel: text.minimap })), controls && (_jsx(Panel, { position: "bottom-left", children: _jsx(GraphControls, { text: text, editable: editable, tidy: layout === "none" ? undefined : tidy, add: () => addNode() }) }))] }));
|
|
810
|
+
return (_jsx(GraphContext.Provider, { value: context, children: _jsxs("div", { ref: frame, "data-slot": "graph", "data-layout": layout, "data-editable": editable ? "" : undefined, className: cn("relative h-[min(40rem,80svh)] w-full overflow-hidden", variant === "card" ? "surface-card [--card-padding:0]" : "surface-container", className), onKeyDown: (event) => {
|
|
811
|
+
// Editable: Enter on a focused node opens its label.
|
|
812
|
+
const node = event.target.closest(".react-flow__node");
|
|
813
|
+
if (!editable || event.key !== "Enter" || !node?.dataset.id || editing)
|
|
814
|
+
return;
|
|
815
|
+
event.preventDefault();
|
|
816
|
+
setEditing({ kind: "node", id: node.dataset.id });
|
|
817
|
+
}, ...props, children: [_jsx("svg", { "aria-hidden": true, className: "absolute size-0", children: _jsx("defs", { children: ["rest", "lit"].map((tone) => (_jsx("marker", { id: `${markers}-${tone}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M1 1.5 L9 5 L1 8.5 Z", "data-tone": tone, className: "zon-graph-arrow" }) }, tone))) }) }), editable ? (_jsxs(ContextMenu, { children: [_jsx(ContextMenuTrigger, { className: "absolute inset-0", onContextMenuCapture: pick, children: canvas }), _jsxs(ContextMenuContent, { children: [target?.type === "pane" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuGroup, { children: [_jsx(ContextMenuGroupLabel, { children: text.addHere }), addable[layout].map((kind) => (_jsxs(ContextMenuItem, { onClick: () => addNode(target.at, kind), children: [_jsx(PlusIcon, {}), text.kind(kind)] }, kind)))] }), _jsx(ContextMenuSeparator, {}), layout !== "none" && (_jsxs(ContextMenuItem, { onClick: tidy, children: [_jsx(WandSparklesIcon, {}), text.tidy] })), _jsxs(ContextMenuItem, { onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: [_jsx(MaximizeIcon, {}), text.fit] })] })), (target?.type === "node" || target?.type === "group") && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "node", id: target.id }), children: [_jsx(PencilIcon, {}), text.rename, _jsx(ContextMenuShortcut, { children: text.enterKey })] }), target.type === "node" && (_jsxs(_Fragment, { children: [_jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeNode(target.id), children: [_jsx(Trash2Icon, {}), text.delete, _jsx(ContextMenuShortcut, { children: text.deleteKey })] })] }))] })), target?.type === "edge" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "edge", id: target.id }), children: [_jsx(PencilIcon, {}), targetEdge?.data?.edge.label ? text.renameLabel : text.addLabel] }), targetEdge && isDirected(targetEdge.data.edge, layout) && (_jsxs(ContextMenuItem, { onClick: () => reverse(target.id), children: [_jsx(ArrowLeftRightIcon, {}), text.reverse] })), _jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeEdge(target.id), children: [_jsx(Trash2Icon, {}), text.removeConnection, _jsx(ContextMenuShortcut, { children: text.deleteKey })] })] }))] })] })) : (canvas), _jsx("ul", { id: describedBy, className: "sr-only", children: state.edges.map((e) => (_jsxs("li", { children: [text.connection(nodeLabels.get(e.source) ?? e.source, nodeLabels.get(e.target) ?? e.target, isDirected(e.data.edge, layout)), e.data.edge.label ? `: ${e.data.edge.label}` : ""] }, e.id))) })] }) }));
|
|
818
|
+
}
|
|
819
|
+
function ControlButton({ label, onClick, children, }) {
|
|
820
|
+
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": label, onClick: onClick }), children: children }), _jsx(TooltipContent, { side: "top", children: label })] }));
|
|
821
|
+
}
|
|
822
|
+
function GraphControls({ text, editable, tidy, add, }) {
|
|
823
|
+
const flow = useReactFlow();
|
|
824
|
+
return (_jsxs(Toolbar, { "aria-label": text.controls, "data-slot": "graph-controls", children: [_jsxs(ToolbarGroup, { children: [_jsx(ControlButton, { label: text.zoomIn, onClick: () => void flow.zoomIn({ duration: 200 }), children: _jsx(PlusIcon, {}) }), _jsx(ControlButton, { label: text.zoomOut, onClick: () => void flow.zoomOut({ duration: 200 }), children: _jsx(MinusIcon, {}) }), _jsx(ControlButton, { label: text.fit, onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: _jsx(MaximizeIcon, {}) })] }), (editable || tidy) && _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [editable && (_jsx(ControlButton, { label: text.addNode, onClick: add, children: _jsx(CircleDotIcon, {}) })), tidy && (_jsx(ControlButton, { label: text.tidy, onClick: tidy, children: _jsx(WandSparklesIcon, {}) }))] })] }));
|
|
825
|
+
}
|