@avis-studio/engine 0.0.0-stage → 0.1.0-beta.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/README.md +193 -2
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/dist/a11y/focus.d.ts +60 -0
- package/dist/a11y/focus.js +222 -0
- package/dist/a11y/index.d.ts +2 -0
- package/dist/a11y/index.js +4 -0
- package/dist/a11y/semantics.d.ts +37 -0
- package/dist/a11y/semantics.js +88 -0
- package/dist/commands/builtins.d.ts +88 -0
- package/dist/commands/builtins.js +362 -0
- package/dist/commands/command.d.ts +23 -0
- package/dist/commands/command.js +20 -0
- package/dist/commands/draft.d.ts +33 -0
- package/dist/commands/draft.js +96 -0
- package/dist/commands/history.d.ts +34 -0
- package/dist/commands/history.js +80 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/patch.d.ts +24 -0
- package/dist/commands/patch.js +44 -0
- package/dist/commands/transaction.d.ts +16 -0
- package/dist/commands/transaction.js +39 -0
- package/dist/core/diagnostics.d.ts +23 -0
- package/dist/core/diagnostics.js +23 -0
- package/dist/core/disposable.d.ts +14 -0
- package/dist/core/disposable.js +51 -0
- package/dist/core/engine.d.ts +108 -0
- package/dist/core/engine.js +323 -0
- package/dist/core/event-bus.d.ts +10 -0
- package/dist/core/event-bus.js +33 -0
- package/dist/core/ids.d.ts +13 -0
- package/dist/core/ids.js +6 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +7 -0
- package/dist/core/plugin.d.ts +20 -0
- package/dist/core/plugin.js +47 -0
- package/dist/core/services.d.ts +14 -0
- package/dist/core/services.js +20 -0
- package/dist/devtools/index.d.ts +1 -0
- package/dist/devtools/index.js +2 -0
- package/dist/devtools/panel.d.ts +39 -0
- package/dist/devtools/panel.js +100 -0
- package/dist/dom/a11y-layer.d.ts +32 -0
- package/dist/dom/a11y-layer.js +358 -0
- package/dist/dom/anchor.d.ts +34 -0
- package/dist/dom/anchor.js +35 -0
- package/dist/dom/index.d.ts +6 -0
- package/dist/dom/index.js +8 -0
- package/dist/dom/menu.d.ts +24 -0
- package/dist/dom/menu.js +122 -0
- package/dist/dom/overlays.d.ts +29 -0
- package/dist/dom/overlays.js +82 -0
- package/dist/dom/paint/collect.d.ts +8 -0
- package/dist/dom/paint/collect.js +589 -0
- package/dist/dom/paint/css.d.ts +86 -0
- package/dist/dom/paint/css.js +526 -0
- package/dist/dom/paint/draw.d.ts +16 -0
- package/dist/dom/paint/draw.js +413 -0
- package/dist/dom/paint/ghost.d.ts +2 -0
- package/dist/dom/paint/ghost.js +8 -0
- package/dist/dom/paint/index.d.ts +6 -0
- package/dist/dom/paint/index.js +9 -0
- package/dist/dom/paint/text.d.ts +26 -0
- package/dist/dom/paint/text.js +209 -0
- package/dist/dom/paint/types.d.ts +174 -0
- package/dist/dom/paint/types.js +7 -0
- package/dist/dom/paint/watch.d.ts +10 -0
- package/dist/dom/paint/watch.js +109 -0
- package/dist/dom/position.d.ts +37 -0
- package/dist/dom/position.js +125 -0
- package/dist/dom/text-editor.d.ts +27 -0
- package/dist/dom/text-editor.js +128 -0
- package/dist/events/event.d.ts +122 -0
- package/dist/events/event.js +130 -0
- package/dist/events/eventer.d.ts +24 -0
- package/dist/events/eventer.js +83 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.js +3 -0
- package/dist/events/interaction.d.ts +43 -0
- package/dist/events/interaction.js +203 -0
- package/dist/geometry/anchors.d.ts +14 -0
- package/dist/geometry/anchors.js +13 -0
- package/dist/geometry/bounds.d.ts +16 -0
- package/dist/geometry/bounds.js +42 -0
- package/dist/geometry/curves.d.ts +39 -0
- package/dist/geometry/curves.js +68 -0
- package/dist/geometry/index.d.ts +6 -0
- package/dist/geometry/index.js +6 -0
- package/dist/geometry/matrix.d.ts +22 -0
- package/dist/geometry/matrix.js +56 -0
- package/dist/geometry/spaces.d.ts +22 -0
- package/dist/geometry/spaces.js +28 -0
- package/dist/geometry/vec2.d.ts +12 -0
- package/dist/geometry/vec2.js +10 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +22 -0
- package/dist/interaction/behaviors.d.ts +10 -0
- package/dist/interaction/behaviors.js +744 -0
- package/dist/interaction/controller.d.ts +180 -0
- package/dist/interaction/controller.js +269 -0
- package/dist/interaction/hit-test.d.ts +45 -0
- package/dist/interaction/hit-test.js +119 -0
- package/dist/interaction/index.d.ts +4 -0
- package/dist/interaction/index.js +7 -0
- package/dist/interaction/web-input.d.ts +13 -0
- package/dist/interaction/web-input.js +172 -0
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +2 -0
- package/dist/layout/layout.d.ts +27 -0
- package/dist/layout/layout.js +266 -0
- package/dist/react/canvas/graph.d.ts +83 -0
- package/dist/react/canvas/graph.js +89 -0
- package/dist/react/canvas/hooks.d.ts +42 -0
- package/dist/react/canvas/hooks.js +78 -0
- package/dist/react/canvas/index.d.ts +35 -0
- package/dist/react/canvas/index.js +8 -0
- package/dist/react/components.d.ts +55 -0
- package/dist/react/components.js +197 -0
- package/dist/react/context.d.ts +4 -0
- package/dist/react/context.js +9 -0
- package/dist/react/flow/api/LICENSE +21 -0
- package/dist/react/flow/api/externals.d.ts +12 -0
- package/dist/react/flow/api/react/additional-components/Background/Background.d.ts +7 -0
- package/dist/react/flow/api/react/additional-components/Background/Patterns.d.ts +17 -0
- package/dist/react/flow/api/react/additional-components/Background/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/Background/types.d.ts +25 -0
- package/dist/react/flow/api/react/additional-components/Controls/ControlButton.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/Controls/Controls.d.ts +7 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/FitView.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Lock.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Minus.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Plus.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/Icons/Unlock.d.ts +1 -0
- package/dist/react/flow/api/react/additional-components/Controls/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/Controls/types.d.ts +20 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/EdgeToolbar.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/EdgeToolbar/types.d.ts +6 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMap.d.ts +8 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNode.d.ts +4 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/MiniMapNodes.d.ts +5 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/MiniMap/types.d.ts +44 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizeControl.d.ts +5 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/NodeResizer.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/index.d.ts +3 -0
- package/dist/react/flow/api/react/additional-components/NodeResizer/types.d.ts +32 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbar.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/NodeToolbarPortal.d.ts +4 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/index.d.ts +2 -0
- package/dist/react/flow/api/react/additional-components/NodeToolbar/types.d.ts +9 -0
- package/dist/react/flow/api/react/additional-components/index.d.ts +6 -0
- package/dist/react/flow/api/react/components/A11yDescriptions/index.d.ts +7 -0
- package/dist/react/flow/api/react/components/Attribution/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/BatchProvider/index.d.ts +10 -0
- package/dist/react/flow/api/react/components/BatchProvider/types.d.ts +6 -0
- package/dist/react/flow/api/react/components/BatchProvider/useQueue.d.ts +2 -0
- package/dist/react/flow/api/react/components/ConnectionLine/index.d.ts +11 -0
- package/dist/react/flow/api/react/components/EdgeLabelRenderer/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/EdgeUpdateAnchors.d.ts +14 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/EdgeWrapper/utils.d.ts +11 -0
- package/dist/react/flow/api/react/components/Edges/BaseEdge.d.ts +2 -0
- package/dist/react/flow/api/react/components/Edges/BezierEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/EdgeAnchor.d.ts +13 -0
- package/dist/react/flow/api/react/components/Edges/EdgeText.d.ts +7 -0
- package/dist/react/flow/api/react/components/Edges/SimpleBezierEdge.d.ts +20 -0
- package/dist/react/flow/api/react/components/Edges/SmoothStepEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/StepEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/StraightEdge.d.ts +4 -0
- package/dist/react/flow/api/react/components/Edges/index.d.ts +5 -0
- package/dist/react/flow/api/react/components/Handle/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/NodeWrapper/index.d.ts +4 -0
- package/dist/react/flow/api/react/components/NodeWrapper/useNodeObserver.d.ts +7 -0
- package/dist/react/flow/api/react/components/NodeWrapper/utils.d.ts +8 -0
- package/dist/react/flow/api/react/components/Nodes/DefaultNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/GroupNode.d.ts +1 -0
- package/dist/react/flow/api/react/components/Nodes/InputNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/OutputNode.d.ts +2 -0
- package/dist/react/flow/api/react/components/Nodes/utils.d.ts +12 -0
- package/dist/react/flow/api/react/components/NodesSelection/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/Panel/index.d.ts +8 -0
- package/dist/react/flow/api/react/components/ReactFlowProvider/index.d.ts +20 -0
- package/dist/react/flow/api/react/components/SelectionListener/index.d.ts +6 -0
- package/dist/react/flow/api/react/components/StoreUpdater/index.d.ts +67 -0
- package/dist/react/flow/api/react/components/UserSelection/index.d.ts +1 -0
- package/dist/react/flow/api/react/components/ViewportPortal/index.d.ts +4 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/MarkerDefinitions.d.ts +9 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/MarkerSymbols.d.ts +8 -0
- package/dist/react/flow/api/react/container/EdgeRenderer/index.d.ts +12 -0
- package/dist/react/flow/api/react/container/FlowRenderer/index.d.ts +13 -0
- package/dist/react/flow/api/react/container/GraphView/index.d.ts +10 -0
- package/dist/react/flow/api/react/container/GraphView/useNodeOrEdgeTypesWarning.d.ts +3 -0
- package/dist/react/flow/api/react/container/GraphView/useStylesLoadedWarning.d.ts +1 -0
- package/dist/react/flow/api/react/container/NodeRenderer/index.d.ts +9 -0
- package/dist/react/flow/api/react/container/NodeRenderer/useResizeObserver.d.ts +1 -0
- package/dist/react/flow/api/react/container/Pane/index.d.ts +10 -0
- package/dist/react/flow/api/react/container/ReactFlow/Wrapper.d.ts +19 -0
- package/dist/react/flow/api/react/container/ReactFlow/index.d.ts +3 -0
- package/dist/react/flow/api/react/container/ReactFlow/init-values.d.ts +3 -0
- package/dist/react/flow/api/react/container/Viewport/index.d.ts +6 -0
- package/dist/react/flow/api/react/container/ZoomPane/index.d.ts +7 -0
- package/dist/react/flow/api/react/contexts/HandleConfigContext.d.ts +11 -0
- package/dist/react/flow/api/react/contexts/NodeIdContext.d.ts +5 -0
- package/dist/react/flow/api/react/contexts/StoreContext.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useColorModeClass.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useConnection.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useDrag.d.ts +12 -0
- package/dist/react/flow/api/react/hooks/useEdges.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useGlobalKeyHandler.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useHandleConnections.d.ts +10 -0
- package/dist/react/flow/api/react/hooks/useInternalNode.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useKeyPress.d.ts +7 -0
- package/dist/react/flow/api/react/hooks/useMoveSelectedNodes.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useNodeConnections.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useNodes.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useNodesData.d.ts +4 -0
- package/dist/react/flow/api/react/hooks/useNodesEdgesState.d.ts +12 -0
- package/dist/react/flow/api/react/hooks/useNodesInitialized.d.ts +4 -0
- package/dist/react/flow/api/react/hooks/useOnEdgesChangeMiddleware.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useOnInitHandler.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useOnNodesChangeMiddleware.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useOnSelectionChange.d.ts +5 -0
- package/dist/react/flow/api/react/hooks/useOnViewportChange.d.ts +7 -0
- package/dist/react/flow/api/react/hooks/useReactFlow.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useResizeHandler.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useStore.d.ts +8 -0
- package/dist/react/flow/api/react/hooks/useUpdateNodeInternals.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useViewport.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useViewportHelper.d.ts +3 -0
- package/dist/react/flow/api/react/hooks/useViewportSync.d.ts +2 -0
- package/dist/react/flow/api/react/hooks/useVisibleEdgeIds.d.ts +1 -0
- package/dist/react/flow/api/react/hooks/useVisibleNodeIds.d.ts +1 -0
- package/dist/react/flow/api/react/index.d.ts +41 -0
- package/dist/react/flow/api/react/store/index.d.ts +18 -0
- package/dist/react/flow/api/react/store/initialState.d.ts +18 -0
- package/dist/react/flow/api/react/styles/utils.d.ts +2 -0
- package/dist/react/flow/api/react/types/component-props.d.ts +127 -0
- package/dist/react/flow/api/react/types/edges.d.ts +111 -0
- package/dist/react/flow/api/react/types/general.d.ts +53 -0
- package/dist/react/flow/api/react/types/index.d.ts +6 -0
- package/dist/react/flow/api/react/types/instance.d.ts +64 -0
- package/dist/react/flow/api/react/types/nodes.d.ts +41 -0
- package/dist/react/flow/api/react/types/store.d.ts +114 -0
- package/dist/react/flow/api/react/utils/changes.d.ts +15 -0
- package/dist/react/flow/api/react/utils/edges.d.ts +3 -0
- package/dist/react/flow/api/react/utils/general.d.ts +5 -0
- package/dist/react/flow/api/react/utils/index.d.ts +3 -0
- package/dist/react/flow/api/system/constants.d.ts +43 -0
- package/dist/react/flow/api/system/index.d.ts +8 -0
- package/dist/react/flow/api/system/types/changes.d.ts +48 -0
- package/dist/react/flow/api/system/types/edges.d.ts +72 -0
- package/dist/react/flow/api/system/types/general.d.ts +175 -0
- package/dist/react/flow/api/system/types/handles.d.ts +21 -0
- package/dist/react/flow/api/system/types/index.d.ts +7 -0
- package/dist/react/flow/api/system/types/nodes.d.ts +89 -0
- package/dist/react/flow/api/system/types/panzoom.d.ts +58 -0
- package/dist/react/flow/api/system/types/utils.d.ts +46 -0
- package/dist/react/flow/api/system/utils/attribution.d.ts +1 -0
- package/dist/react/flow/api/system/utils/connections.d.ts +4 -0
- package/dist/react/flow/api/system/utils/dom.d.ts +20 -0
- package/dist/react/flow/api/system/utils/edge-toolbar.d.ts +1 -0
- package/dist/react/flow/api/system/utils/edges/bezier-edge.d.ts +40 -0
- package/dist/react/flow/api/system/utils/edges/general.d.ts +44 -0
- package/dist/react/flow/api/system/utils/edges/index.d.ts +5 -0
- package/dist/react/flow/api/system/utils/edges/positions.d.ts +16 -0
- package/dist/react/flow/api/system/utils/edges/smoothstep-edge.d.ts +21 -0
- package/dist/react/flow/api/system/utils/edges/straight-edge.d.ts +13 -0
- package/dist/react/flow/api/system/utils/general.d.ts +56 -0
- package/dist/react/flow/api/system/utils/graph.d.ts +45 -0
- package/dist/react/flow/api/system/utils/index.d.ts +12 -0
- package/dist/react/flow/api/system/utils/marker.d.ts +8 -0
- package/dist/react/flow/api/system/utils/node-toolbar.d.ts +2 -0
- package/dist/react/flow/api/system/utils/shallow-node-data.d.ts +4 -0
- package/dist/react/flow/api/system/utils/store.d.ts +33 -0
- package/dist/react/flow/api/system/utils/types.d.ts +7 -0
- package/dist/react/flow/api/system/xydrag/XYDrag.d.ts +56 -0
- package/dist/react/flow/api/system/xydrag/index.d.ts +1 -0
- package/dist/react/flow/api/system/xydrag/utils.d.ts +22 -0
- package/dist/react/flow/api/system/xyhandle/XYHandle.d.ts +2 -0
- package/dist/react/flow/api/system/xyhandle/index.d.ts +1 -0
- package/dist/react/flow/api/system/xyhandle/types.d.ts +49 -0
- package/dist/react/flow/api/system/xyhandle/utils.d.ts +9 -0
- package/dist/react/flow/api/system/xyminimap/index.d.ts +27 -0
- package/dist/react/flow/api/system/xypanzoom/XYPanZoom.d.ts +11 -0
- package/dist/react/flow/api/system/xypanzoom/eventhandler.d.ts +45 -0
- package/dist/react/flow/api/system/xypanzoom/filter.d.ts +15 -0
- package/dist/react/flow/api/system/xypanzoom/index.d.ts +1 -0
- package/dist/react/flow/api/system/xypanzoom/utils.d.ts +8 -0
- package/dist/react/flow/api/system/xyresizer/XYResizer.d.ts +51 -0
- package/dist/react/flow/api/system/xyresizer/index.d.ts +2 -0
- package/dist/react/flow/api/system/xyresizer/types.d.ts +26 -0
- package/dist/react/flow/api/system/xyresizer/utils.d.ts +41 -0
- package/dist/react/flow/components.d.ts +148 -0
- package/dist/react/flow/components.js +526 -0
- package/dist/react/flow/configuration.d.ts +6 -0
- package/dist/react/flow/configuration.js +27 -0
- package/dist/react/flow/drag.d.ts +14 -0
- package/dist/react/flow/drag.js +273 -0
- package/dist/react/flow/extras.d.ts +155 -0
- package/dist/react/flow/extras.js +317 -0
- package/dist/react/flow/handle.d.ts +21 -0
- package/dist/react/flow/handle.js +149 -0
- package/dist/react/flow/hooks.d.ts +47 -0
- package/dist/react/flow/hooks.js +131 -0
- package/dist/react/flow/index.d.ts +78 -0
- package/dist/react/flow/index.js +73 -0
- package/dist/react/flow/queries.d.ts +20 -0
- package/dist/react/flow/queries.js +30 -0
- package/dist/react/flow/react-flow.d.ts +73 -0
- package/dist/react/flow/react-flow.js +1445 -0
- package/dist/react/flow/resize.d.ts +30 -0
- package/dist/react/flow/resize.js +49 -0
- package/dist/react/flow/store.d.ts +412 -0
- package/dist/react/flow/store.js +713 -0
- package/dist/react/flow/style.css +630 -0
- package/dist/react/flow/style.css.d.ts +2 -0
- package/dist/react/flow/system.d.ts +146 -0
- package/dist/react/flow/system.js +300 -0
- package/dist/react/flow/types.d.ts +131 -0
- package/dist/react/flow/types.js +1 -0
- package/dist/react/flow/utils.d.ts +77 -0
- package/dist/react/flow/utils.js +285 -0
- package/dist/react/hooks.d.ts +14 -0
- package/dist/react/hooks.js +44 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +5 -0
- package/dist/render/backend.d.ts +26 -0
- package/dist/render/backend.js +5 -0
- package/dist/render/canvas2d/backend.d.ts +7 -0
- package/dist/render/canvas2d/backend.js +122 -0
- package/dist/render/canvas2d/index.d.ts +1 -0
- package/dist/render/canvas2d/index.js +2 -0
- package/dist/render/color.d.ts +9 -0
- package/dist/render/color.js +69 -0
- package/dist/render/commands.d.ts +69 -0
- package/dist/render/commands.js +1 -0
- package/dist/render/display-list.d.ts +65 -0
- package/dist/render/display-list.js +316 -0
- package/dist/render/images.d.ts +35 -0
- package/dist/render/images.js +83 -0
- package/dist/render/index.d.ts +14 -0
- package/dist/render/index.js +16 -0
- package/dist/render/painters.d.ts +35 -0
- package/dist/render/painters.js +109 -0
- package/dist/render/renderer.d.ts +70 -0
- package/dist/render/renderer.js +162 -0
- package/dist/render/scene-index.d.ts +21 -0
- package/dist/render/scene-index.js +64 -0
- package/dist/render/text.d.ts +8 -0
- package/dist/render/text.js +100 -0
- package/dist/render/theme.d.ts +21 -0
- package/dist/render/theme.js +33 -0
- package/dist/render/ui.d.ts +63 -0
- package/dist/render/ui.js +188 -0
- package/dist/render/webgl2/atlas.d.ts +36 -0
- package/dist/render/webgl2/atlas.js +93 -0
- package/dist/render/webgl2/backend.d.ts +19 -0
- package/dist/render/webgl2/backend.js +338 -0
- package/dist/render/webgl2/index.d.ts +2 -0
- package/dist/render/webgl2/index.js +3 -0
- package/dist/render/webgl2/shaders.d.ts +6 -0
- package/dist/render/webgl2/shaders.js +112 -0
- package/dist/render/webgpu/index.d.ts +1 -0
- package/dist/render/webgpu/index.js +3 -0
- package/dist/scene/builtins.d.ts +25 -0
- package/dist/scene/builtins.js +60 -0
- package/dist/scene/dirty.d.ts +11 -0
- package/dist/scene/dirty.js +10 -0
- package/dist/scene/index.d.ts +5 -0
- package/dist/scene/index.js +5 -0
- package/dist/scene/record.d.ts +40 -0
- package/dist/scene/record.js +12 -0
- package/dist/scene/scene-graph.d.ts +58 -0
- package/dist/scene/scene-graph.js +178 -0
- package/dist/scene/schema.d.ts +27 -0
- package/dist/scene/schema.js +32 -0
- package/dist/sdk/create-avis.d.ts +109 -0
- package/dist/sdk/create-avis.js +162 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +2 -0
- package/dist/serialization/format.d.ts +46 -0
- package/dist/serialization/format.js +20 -0
- package/dist/serialization/index.d.ts +3 -0
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/migrate.d.ts +7 -0
- package/dist/serialization/migrate.js +54 -0
- package/dist/serialization/serialize.d.ts +10 -0
- package/dist/serialization/serialize.js +114 -0
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.js +2 -0
- package/dist/state/selector.d.ts +6 -0
- package/dist/state/selector.js +29 -0
- package/dist/state/store.d.ts +91 -0
- package/dist/state/store.js +102 -0
- package/dist/style/computed.d.ts +84 -0
- package/dist/style/computed.js +296 -0
- package/dist/style/index.d.ts +6 -0
- package/dist/style/index.js +8 -0
- package/dist/style/style-engine.d.ts +33 -0
- package/dist/style/style-engine.js +113 -0
- package/dist/style/tokens.d.ts +49 -0
- package/dist/style/tokens.js +142 -0
- package/dist/style/utilities.d.ts +34 -0
- package/dist/style/utilities.js +341 -0
- package/dist/style/values.d.ts +30 -0
- package/dist/style/values.js +361 -0
- package/dist/style/variants.d.ts +38 -0
- package/dist/style/variants.js +55 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +1 -0
- package/dist/sync/save-queue.d.ts +24 -0
- package/dist/sync/save-queue.js +88 -0
- package/dist/wasm/index.d.ts +2 -0
- package/dist/wasm/index.js +2 -0
- package/dist/wasm/load.d.ts +7 -0
- package/dist/wasm/load.js +47 -0
- package/dist/wasm/pkg/avis_engine_wasm.d.ts +84 -0
- package/dist/wasm/pkg/avis_engine_wasm.js +339 -0
- package/dist/wasm/pkg/avis_engine_wasm_bg.wasm +0 -0
- package/dist/wasm/reference.d.ts +38 -0
- package/dist/wasm/reference.js +174 -0
- package/package.json +76 -4
|
@@ -0,0 +1,1445 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* <ReactFlowProvider> and <ReactFlow>, rebuilt on the AVIS Engine side with
|
|
4
|
+
* React Flow v12's DOM (class names, data-id, the viewport transform), so
|
|
5
|
+
* its stylesheet and the app's DOM queries keep working:
|
|
6
|
+
*
|
|
7
|
+
* .avis-flow > .avis-flow__renderer > .avis-flow__pane > .avis-flow__viewport
|
|
8
|
+
* > .avis-flow__edges, .avis-flow__edgelabel-renderer, .avis-flow__nodes > .avis-flow__node[data-id], .avis-flow__viewport-portal
|
|
9
|
+
*
|
|
10
|
+
* It renders the nodes and edges that aren't hidden, measures them (sizes
|
|
11
|
+
* and handle boxes, written back with 'dimensions' changes as React Flow
|
|
12
|
+
* does), pans and zooms (wheel, pan buttons, Space), handles the Delete
|
|
13
|
+
* key and the multi-selection key, and fits the view once at the start.
|
|
14
|
+
* Pointer gestures on nodes (drag, select, connect) are the app's canvas
|
|
15
|
+
* engine's; this layer doesn't run React Flow's own.
|
|
16
|
+
*/
|
|
17
|
+
import { memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
18
|
+
import { adoptNodes, createFlowStore, createInstance, disposeFlowViewport, fitView, selectionChanges } from "./store.js";
|
|
19
|
+
import { NodeIdContext, StoreContext, useConnection, useStore } from "./hooks.js";
|
|
20
|
+
import { BaseEdge, Handle } from "./components.js";
|
|
21
|
+
import { getBezierPath, getSimpleBezierPath, getSmoothStepPath, getStraightPath } from "./utils.js";
|
|
22
|
+
import { attachDrag } from "./drag.js";
|
|
23
|
+
import { SelectionListener } from "./extras.js";
|
|
24
|
+
import { onHandlePointerDown } from "./handle.js";
|
|
25
|
+
import { defaultAriaLabels, hasClassWithin, reportFlowError } from "./configuration.js";
|
|
26
|
+
import { calcAutoPan, calculateNodePosition, getConnectionStatus, getEventPosition, getHandlePosition, getNodesInside, getOverlappingArea, nodeToRect, pointToRendererPoint, rendererPointToPoint, selectedNodesBounds, } from "./system.js";
|
|
27
|
+
export function ReactFlowProvider({ children }) {
|
|
28
|
+
const [value] = useState(() => {
|
|
29
|
+
const store = createFlowStore();
|
|
30
|
+
return Object.assign(store, { instance: createInstance(store) });
|
|
31
|
+
});
|
|
32
|
+
return _jsx(StoreContext.Provider, { value: value, children: children });
|
|
33
|
+
}
|
|
34
|
+
const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
35
|
+
/** Props copied into the store as React Flow's StoreUpdater does. */
|
|
36
|
+
const STORE_PROPS = [
|
|
37
|
+
"onNodesChange",
|
|
38
|
+
"onEdgesChange",
|
|
39
|
+
"onBeforeDelete",
|
|
40
|
+
"onNodesDelete",
|
|
41
|
+
"onEdgesDelete",
|
|
42
|
+
"onDelete",
|
|
43
|
+
"onNodeDragStart",
|
|
44
|
+
"onNodeDrag",
|
|
45
|
+
"onNodeDragStop",
|
|
46
|
+
"onSelectionDragStart",
|
|
47
|
+
"onSelectionDragStop",
|
|
48
|
+
"onConnectStart",
|
|
49
|
+
"onConnect",
|
|
50
|
+
"onConnectEnd",
|
|
51
|
+
"isValidConnection",
|
|
52
|
+
"onViewportChange",
|
|
53
|
+
"onMove",
|
|
54
|
+
"onMoveStart",
|
|
55
|
+
"onMoveEnd",
|
|
56
|
+
"onSelectionDrag",
|
|
57
|
+
"onEdgeDoubleClick",
|
|
58
|
+
"onEdgeMouseEnter",
|
|
59
|
+
"onEdgeMouseMove",
|
|
60
|
+
"onEdgeMouseLeave",
|
|
61
|
+
"onPaneContextMenu",
|
|
62
|
+
"onPaneScroll",
|
|
63
|
+
"onPaneMouseEnter",
|
|
64
|
+
"onPaneMouseMove",
|
|
65
|
+
"onPaneMouseLeave",
|
|
66
|
+
"onSelectionContextMenu",
|
|
67
|
+
"onClickConnectStart",
|
|
68
|
+
"onClickConnectEnd",
|
|
69
|
+
"onReconnect",
|
|
70
|
+
"onReconnectStart",
|
|
71
|
+
"onReconnectEnd",
|
|
72
|
+
"nodeExtent",
|
|
73
|
+
"nodeOrigin",
|
|
74
|
+
"defaultEdgeOptions",
|
|
75
|
+
"edgesFocusable",
|
|
76
|
+
"autoPanOnNodeDrag",
|
|
77
|
+
"autoPanOnConnect",
|
|
78
|
+
"autoPanSpeed",
|
|
79
|
+
"nodeClickDistance",
|
|
80
|
+
"disableKeyboardA11y",
|
|
81
|
+
"autoPanOnNodeFocus",
|
|
82
|
+
"elevateEdgesOnSelect",
|
|
83
|
+
"defaultMarkerColor",
|
|
84
|
+
"elementsSelectable",
|
|
85
|
+
"nodesDraggable",
|
|
86
|
+
"nodesConnectable",
|
|
87
|
+
"nodesFocusable",
|
|
88
|
+
"selectNodesOnDrag",
|
|
89
|
+
"snapToGrid",
|
|
90
|
+
"snapGrid",
|
|
91
|
+
"nodeDragThreshold",
|
|
92
|
+
"connectionDragThreshold",
|
|
93
|
+
"connectionRadius",
|
|
94
|
+
"connectionMode",
|
|
95
|
+
"elevateNodesOnSelect",
|
|
96
|
+
"onNodeClick",
|
|
97
|
+
"onNodeDoubleClick",
|
|
98
|
+
"onNodeContextMenu",
|
|
99
|
+
"onNodeMouseEnter",
|
|
100
|
+
"onNodeMouseMove",
|
|
101
|
+
"onNodeMouseLeave",
|
|
102
|
+
"onEdgeClick",
|
|
103
|
+
"onEdgeContextMenu",
|
|
104
|
+
"onPaneClick",
|
|
105
|
+
"onSelectionStart",
|
|
106
|
+
"onSelectionEnd",
|
|
107
|
+
"connectOnClick",
|
|
108
|
+
"translateExtent",
|
|
109
|
+
"noDragClassName",
|
|
110
|
+
"noPanClassName",
|
|
111
|
+
"noWheelClassName",
|
|
112
|
+
"edgesReconnectable",
|
|
113
|
+
"reconnectRadius",
|
|
114
|
+
"ariaLabelConfig",
|
|
115
|
+
"zIndexMode",
|
|
116
|
+
"onError",
|
|
117
|
+
"debug",
|
|
118
|
+
];
|
|
119
|
+
const DEFAULTS = {
|
|
120
|
+
elementsSelectable: true,
|
|
121
|
+
nodesDraggable: true,
|
|
122
|
+
nodesConnectable: true,
|
|
123
|
+
nodesFocusable: true,
|
|
124
|
+
selectNodesOnDrag: true,
|
|
125
|
+
snapToGrid: false,
|
|
126
|
+
snapGrid: [15, 15],
|
|
127
|
+
nodeDragThreshold: 1,
|
|
128
|
+
connectionDragThreshold: 1,
|
|
129
|
+
connectionRadius: 20,
|
|
130
|
+
connectionMode: "strict",
|
|
131
|
+
elevateNodesOnSelect: true,
|
|
132
|
+
edgesFocusable: true,
|
|
133
|
+
autoPanOnNodeDrag: true,
|
|
134
|
+
autoPanOnConnect: true,
|
|
135
|
+
autoPanSpeed: 15,
|
|
136
|
+
nodeClickDistance: 0,
|
|
137
|
+
elevateEdgesOnSelect: false,
|
|
138
|
+
defaultMarkerColor: "#b1b1b7",
|
|
139
|
+
noDragClassName: "nodrag", noPanClassName: "nopan", noWheelClassName: "nowheel",
|
|
140
|
+
edgesReconnectable: true, reconnectRadius: 10,
|
|
141
|
+
translateExtent: [[-Infinity, -Infinity], [Infinity, Infinity]],
|
|
142
|
+
ariaLabelConfig: defaultAriaLabels,
|
|
143
|
+
zIndexMode: "auto",
|
|
144
|
+
};
|
|
145
|
+
export function ReactFlow(props) {
|
|
146
|
+
const context = useContext(StoreContext);
|
|
147
|
+
if (!context) {
|
|
148
|
+
return (_jsx(ReactFlowProvider, { children: _jsx(ReactFlow, { ...props }) }));
|
|
149
|
+
}
|
|
150
|
+
return _jsx(Flow, { ...props });
|
|
151
|
+
}
|
|
152
|
+
const NO_NODES = [];
|
|
153
|
+
const NO_EDGES = [];
|
|
154
|
+
function Flow(props) {
|
|
155
|
+
const store = useContext(StoreContext);
|
|
156
|
+
const instance = store.instance;
|
|
157
|
+
const rootRef = useRef(null);
|
|
158
|
+
const nodes = props.nodes ?? props.defaultNodes ?? NO_NODES;
|
|
159
|
+
const edges = props.edges ?? props.defaultEdges ?? NO_EDGES;
|
|
160
|
+
// Props → store, as React Flow's StoreUpdater: only the props that
|
|
161
|
+
// changed since the last render are written (what others put in the
|
|
162
|
+
// store meanwhile stays).
|
|
163
|
+
const previousProps = useRef(null);
|
|
164
|
+
// useEffect, as React Flow's StoreUpdater: after paint, batched.
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const before = previousProps.current;
|
|
167
|
+
const next = {};
|
|
168
|
+
for (const key of [...STORE_PROPS, "minZoom", "maxZoom"]) {
|
|
169
|
+
const value = key === "ariaLabelConfig" ? props.ariaLabelConfig ?? defaultAriaLabels : props[key] ?? DEFAULTS[key];
|
|
170
|
+
if (value === undefined && (key === "minZoom" || key === "maxZoom"))
|
|
171
|
+
continue;
|
|
172
|
+
if (!before || before[key] !== value)
|
|
173
|
+
next[key] = value;
|
|
174
|
+
}
|
|
175
|
+
previousProps.current = Object.fromEntries([...STORE_PROPS, "minZoom", "maxZoom"].map((key) => [key, props[key] ?? DEFAULTS[key]]));
|
|
176
|
+
if (next.ariaLabelConfig)
|
|
177
|
+
next.ariaLabelConfig = { ...defaultAriaLabels, ...next.ariaLabelConfig };
|
|
178
|
+
if (Object.keys(next).length) {
|
|
179
|
+
store.setState(next);
|
|
180
|
+
if ("zIndexMode" in next || "nodeOrigin" in next || "elevateNodesOnSelect" in next)
|
|
181
|
+
store.getState().setNodes(store.getState().nodes);
|
|
182
|
+
if ("translateExtent" in next || "minZoom" in next || "maxZoom" in next)
|
|
183
|
+
store.getState().setTransform(store.getState().transform);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
if (store.getState().nodes !== nodes)
|
|
188
|
+
store.getState().setNodes(nodes);
|
|
189
|
+
}, [store, nodes]);
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (store.getState().edges !== edges)
|
|
192
|
+
store.getState().setEdges(edges);
|
|
193
|
+
}, [store, edges]);
|
|
194
|
+
// Uncontrolled graphs apply changes in the store, with optional callbacks.
|
|
195
|
+
useLayoutEffect(() => {
|
|
196
|
+
store.setState({
|
|
197
|
+
hasDefaultNodes: props.nodes === undefined && props.defaultNodes !== undefined,
|
|
198
|
+
hasDefaultEdges: props.edges === undefined && props.defaultEdges !== undefined,
|
|
199
|
+
});
|
|
200
|
+
}, [store, props.nodes, props.defaultNodes, props.edges, props.defaultEdges]);
|
|
201
|
+
// The root: domNode, its size, the default viewport.
|
|
202
|
+
useLayoutEffect(() => {
|
|
203
|
+
const root = rootRef.current;
|
|
204
|
+
store.setState({ domNode: root, forceMeasure: (ids) => measurerOf(store).force(ids) });
|
|
205
|
+
if (props.defaultViewport) {
|
|
206
|
+
const { x, y, zoom } = props.defaultViewport;
|
|
207
|
+
store.getState().setTransform([x, y, zoom]);
|
|
208
|
+
}
|
|
209
|
+
const measure = () => {
|
|
210
|
+
const rect = root.getBoundingClientRect();
|
|
211
|
+
if (rect.width !== store.getState().width || rect.height !== store.getState().height) {
|
|
212
|
+
store.setState({ width: rect.width, height: rect.height });
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
measure();
|
|
216
|
+
const observer = new ResizeObserver(measure);
|
|
217
|
+
observer.observe(root);
|
|
218
|
+
props.onInit?.(instance);
|
|
219
|
+
return () => {
|
|
220
|
+
observer.disconnect();
|
|
221
|
+
disposeFlowViewport(store);
|
|
222
|
+
store.getState().connectionCleanup?.();
|
|
223
|
+
store.setState({ domNode: null });
|
|
224
|
+
};
|
|
225
|
+
// Once, as React Flow.
|
|
226
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
227
|
+
}, [store]);
|
|
228
|
+
const controlledViewport = props.viewport;
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
if (controlledViewport)
|
|
231
|
+
store.getState().setTransform([controlledViewport.x, controlledViewport.y, controlledViewport.zoom]);
|
|
232
|
+
}, [store, controlledViewport]);
|
|
233
|
+
// fitView once, when the nodes have sizes.
|
|
234
|
+
const fitOptions = useRef(props.fitViewOptions);
|
|
235
|
+
useLayoutEffect(() => {
|
|
236
|
+
fitOptions.current = props.fitViewOptions;
|
|
237
|
+
});
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (!props.fitView)
|
|
240
|
+
return;
|
|
241
|
+
const tryFit = () => {
|
|
242
|
+
const s = store.getState();
|
|
243
|
+
if (s.fitViewDone || !s.width || !s.nodes.length)
|
|
244
|
+
return;
|
|
245
|
+
// As xyflow's queued fitView: wait until every shown node is measured.
|
|
246
|
+
for (const node of s.nodeLookup.values())
|
|
247
|
+
if (!node.hidden && !(node.measured.width && node.measured.height))
|
|
248
|
+
return;
|
|
249
|
+
void fitView(store, { ...fitOptions.current, duration: 0 }).then((ok) => {
|
|
250
|
+
if (ok)
|
|
251
|
+
store.setState({ fitViewDone: true });
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
tryFit();
|
|
255
|
+
return store.subscribe(tryFit);
|
|
256
|
+
}, [store, props.fitView]);
|
|
257
|
+
usePanZoom(store, rootRef, props);
|
|
258
|
+
useKeys(store, instance, props);
|
|
259
|
+
const transform = useStore((s) => s.transform);
|
|
260
|
+
const colorModeClass = useColorModeClass(props.colorMode ?? "light");
|
|
261
|
+
const rfId = props.id ?? "1";
|
|
262
|
+
useLayoutEffect(() => {
|
|
263
|
+
if (store.getState().rfId !== rfId)
|
|
264
|
+
store.setState({ rfId });
|
|
265
|
+
}, [store, rfId]);
|
|
266
|
+
const viewportStyle = useMemo(() => ({ transform: `translate(${transform[0]}px,${transform[1]}px) scale(${transform[2]})` }), [transform]);
|
|
267
|
+
return (_jsxs("div", { ref: rootRef, ...domProps(props), className: `avis-flow${props.className ? ` ${props.className}` : ""} ${colorModeClass}`, "data-testid": "rf__wrapper", style: { ...props.style, width: "100%", height: "100%", overflow: "hidden", position: "relative", zIndex: 0 }, role: "application", children: [_jsx("div", { className: "avis-flow__renderer", style: CONTAINER, children: _jsx(Pane, { ...props, children: _jsxs("div", { className: "avis-flow__viewport avis-flow__container", style: viewportStyle, children: [_jsx(Edges, { edgeTypes: props.edgeTypes, onlyVisible: Boolean(props.onlyRenderVisibleElements), mounted: props.mountEdges !== false }), _jsx(ConnectionLineWrapper, { type: props.connectionLineType, style: props.connectionLineStyle, component: props.connectionLineComponent, containerStyle: props.connectionLineContainerStyle }), _jsx("div", { className: "avis-flow__edgelabel-renderer" }), _jsx(Nodes, { nodeTypes: props.nodeTypes, onlyVisible: Boolean(props.onlyRenderVisibleElements), mountNode: props.mountNode }), _jsx("div", { className: "avis-flow__viewport-portal" })] }) }) }), _jsx(SelectionListener, { onSelectionChange: props.onSelectionChange }), props.children, _jsx(A11yDescriptions, { rfId: rfId, disableKeyboardA11y: Boolean(props.disableKeyboardA11y) })] }));
|
|
268
|
+
}
|
|
269
|
+
const CONTAINER = { position: "absolute", width: "100%", height: "100%", top: 0, left: 0 };
|
|
270
|
+
/** React Flow's hidden descriptions and live region (its texts, swapped as it ships them). */
|
|
271
|
+
function A11yDescriptions({ rfId, disableKeyboardA11y }) {
|
|
272
|
+
const message = useStore((s) => s.ariaLiveMessage);
|
|
273
|
+
const labels = useStore((s) => s.ariaLabelConfig);
|
|
274
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { id: `avis-flow__node-desc-${rfId}`, style: { display: "none" }, children: disableKeyboardA11y ? labels["node.a11yDescription.keyboardDisabled"] : labels["node.a11yDescription.default"] }), _jsx("div", { id: `avis-flow__edge-desc-${rfId}`, style: { display: "none" }, children: labels["edge.a11yDescription.default"] }), !disableKeyboardA11y ? (_jsx("div", { id: `avis-flow__aria-live-${rfId}`, "aria-live": "assertive", "aria-atomic": "true", style: { position: "absolute", width: 1, height: 1, margin: -1, border: 0, padding: 0, overflow: "hidden", clip: "rect(0px, 0px, 0px, 0px)", clipPath: "inset(100%)" }, children: message })) : null] }));
|
|
275
|
+
}
|
|
276
|
+
/** React Flow's own props: everything else goes onto the root element, as React Flow spreads `rest`. */
|
|
277
|
+
const FLOW_PROP = /^on(Node|Nodes|Edge|Edges|Connect|ClickConnect|Init|Move|Selection|Pane|Delete|BeforeDelete|Reconnect|Error|ViewportChange)/;
|
|
278
|
+
function domProps(props) {
|
|
279
|
+
const out = {};
|
|
280
|
+
for (const [key, value] of Object.entries(props)) {
|
|
281
|
+
if (/^on[A-Z]/.test(key) ? !FLOW_PROP.test(key) : key === "id" || key === "role" || key === "tabIndex" || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
282
|
+
out[key] = value;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
// ---- the pane: clicks, menus and the selection box (React Flow's Pane) -------------
|
|
288
|
+
const win = typeof window !== "undefined" ? window : undefined;
|
|
289
|
+
/** Whether one of the keys is held (React Flow's useKeyPress, for plain keys). */
|
|
290
|
+
function useKeyPressed(keys) {
|
|
291
|
+
const [pressed, setPressed] = useState(false);
|
|
292
|
+
const key = keys === null || keys === undefined ? "" : Array.isArray(keys) ? keys.join("\u0000") : keys;
|
|
293
|
+
useEffect(() => {
|
|
294
|
+
if (!key || !win)
|
|
295
|
+
return;
|
|
296
|
+
const list = key.split("\u0000");
|
|
297
|
+
const typing = (target) => isInput(target);
|
|
298
|
+
const down = (event) => {
|
|
299
|
+
if (typing(event.target))
|
|
300
|
+
return;
|
|
301
|
+
if (list.includes(event.key) || list.includes(event.code))
|
|
302
|
+
setPressed(true);
|
|
303
|
+
};
|
|
304
|
+
const up = (event) => {
|
|
305
|
+
if (list.includes(event.key) || list.includes(event.code))
|
|
306
|
+
setPressed(false);
|
|
307
|
+
};
|
|
308
|
+
const reset = () => setPressed(false);
|
|
309
|
+
win.addEventListener("keydown", down);
|
|
310
|
+
win.addEventListener("keyup", up);
|
|
311
|
+
win.addEventListener("blur", reset);
|
|
312
|
+
win.addEventListener("contextmenu", reset);
|
|
313
|
+
return () => {
|
|
314
|
+
win.removeEventListener("keydown", down);
|
|
315
|
+
win.removeEventListener("keyup", up);
|
|
316
|
+
win.removeEventListener("blur", reset);
|
|
317
|
+
win.removeEventListener("contextmenu", reset);
|
|
318
|
+
};
|
|
319
|
+
}, [key]);
|
|
320
|
+
return Boolean(key) && pressed;
|
|
321
|
+
}
|
|
322
|
+
const sameSet = (a, b) => a.size === b.size && [...a].every((v) => b.has(v));
|
|
323
|
+
function Pane(props) {
|
|
324
|
+
const store = useContext(StoreContext);
|
|
325
|
+
const container = useRef(null);
|
|
326
|
+
const bounds = useRef(null);
|
|
327
|
+
const selectedNodeIds = useRef(new Set());
|
|
328
|
+
const selectedEdgeIds = useRef(new Set());
|
|
329
|
+
const connectionEndedOnPane = useRef(false);
|
|
330
|
+
const selectionInProgress = useRef(false);
|
|
331
|
+
const position = useRef({ x: 0, y: 0 });
|
|
332
|
+
const autoPanId = useRef(0);
|
|
333
|
+
const autoPanStarted = useRef(false);
|
|
334
|
+
const userSelectionActive = useStore((s) => s.userSelectionActive);
|
|
335
|
+
const elementsSelectable = useStore((s) => s.elementsSelectable);
|
|
336
|
+
const dragging = useStore((s) => s.paneDragging);
|
|
337
|
+
const nodesSelectionActive = useStore((s) => s.nodesSelectionActive);
|
|
338
|
+
const selectionKeyPressed = useKeyPressed(props.selectionKeyCode === undefined ? "Shift" : props.selectionKeyCode);
|
|
339
|
+
const panActivationKeyPressed = useKeyPressed(props.panActivationKeyCode === undefined ? " " : props.panActivationKeyCode);
|
|
340
|
+
const panOnDrag = panActivationKeyPressed || (props.panOnDrag ?? true);
|
|
341
|
+
const selectionOnDrag = Boolean(props.selectionOnDrag) && panOnDrag !== true;
|
|
342
|
+
const isSelecting = selectionKeyPressed || userSelectionActive || selectionOnDrag;
|
|
343
|
+
const isSelectionEnabled = elementsSelectable && isSelecting;
|
|
344
|
+
const selectionMode = props.selectionMode ?? "full";
|
|
345
|
+
const paneClickDistance = props.paneClickDistance ?? 1;
|
|
346
|
+
// The pan-zoom reads these (React Flow hands ZoomPane `panOnDrag: !selectionKeyPressed && panOnDrag`).
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
store.setState({ selectionKeyPressed, selectionOnDragActive: selectionOnDrag });
|
|
349
|
+
}, [store, selectionKeyPressed, selectionOnDrag]);
|
|
350
|
+
const onClick = (event) => {
|
|
351
|
+
if (selectionInProgress.current || connectionEndedOnPane.current || store.getState().connection.inProgress) {
|
|
352
|
+
selectionInProgress.current = false;
|
|
353
|
+
connectionEndedOnPane.current = false;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
;
|
|
357
|
+
store.getState().onPaneClick?.(event);
|
|
358
|
+
store.getState().resetSelectedElements();
|
|
359
|
+
store.setState({ nodesSelectionActive: false });
|
|
360
|
+
};
|
|
361
|
+
const onContextMenu = (event) => {
|
|
362
|
+
if (Array.isArray(panOnDrag) && panOnDrag.includes(2)) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
;
|
|
367
|
+
store.getState().onPaneContextMenu?.(event);
|
|
368
|
+
};
|
|
369
|
+
// React Flow's wrapHandler: only presses on the pane itself (the handler's own element).
|
|
370
|
+
const own = (handler) => handler ? (event) => (event.target === event.currentTarget ? handler(event) : undefined) : undefined;
|
|
371
|
+
const onClickCapture = (event) => {
|
|
372
|
+
if (selectionInProgress.current) {
|
|
373
|
+
event.stopPropagation();
|
|
374
|
+
selectionInProgress.current = false;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const onPointerDownCapture = (event) => {
|
|
378
|
+
if (event.pointerType === "touch" && panOnDrag !== false && !selectionKeyPressed)
|
|
379
|
+
return;
|
|
380
|
+
const { domNode, transform } = store.getState();
|
|
381
|
+
bounds.current = domNode?.getBoundingClientRect() ?? null;
|
|
382
|
+
if (!bounds.current)
|
|
383
|
+
return;
|
|
384
|
+
const onContainer = event.target === container.current;
|
|
385
|
+
const noKey = !onContainer && Boolean(event.target.closest(".nokey"));
|
|
386
|
+
const active = (selectionOnDrag && onContainer) || selectionKeyPressed;
|
|
387
|
+
if (noKey || !isSelecting || !active || event.button !== 0 || !event.isPrimary)
|
|
388
|
+
return;
|
|
389
|
+
event.target.setPointerCapture?.(event.pointerId);
|
|
390
|
+
selectionInProgress.current = false;
|
|
391
|
+
const { x, y } = getEventPosition(event.nativeEvent, bounds.current);
|
|
392
|
+
const start = pointToRendererPoint({ x, y }, transform);
|
|
393
|
+
store.setState({ userSelectionRect: { width: 0, height: 0, startX: start.x, startY: start.y, x, y } });
|
|
394
|
+
if (!onContainer) {
|
|
395
|
+
event.stopPropagation();
|
|
396
|
+
event.preventDefault();
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
const commit = (mouseX, mouseY) => {
|
|
400
|
+
const s = store.getState();
|
|
401
|
+
const rect = s.userSelectionRect;
|
|
402
|
+
if (!rect)
|
|
403
|
+
return;
|
|
404
|
+
const screenStart = rendererPointToPoint({ x: rect.startX, y: rect.startY }, s.transform);
|
|
405
|
+
const next = {
|
|
406
|
+
startX: rect.startX,
|
|
407
|
+
startY: rect.startY,
|
|
408
|
+
x: mouseX < screenStart.x ? mouseX : screenStart.x,
|
|
409
|
+
y: mouseY < screenStart.y ? mouseY : screenStart.y,
|
|
410
|
+
width: Math.abs(mouseX - screenStart.x),
|
|
411
|
+
height: Math.abs(mouseY - screenStart.y),
|
|
412
|
+
};
|
|
413
|
+
const prevNodes = selectedNodeIds.current;
|
|
414
|
+
const prevEdges = selectedEdgeIds.current;
|
|
415
|
+
selectedNodeIds.current = new Set(getNodesInside(s.nodeLookup, next, s.transform, selectionMode === "partial", true).map((n) => n.id));
|
|
416
|
+
selectedEdgeIds.current = new Set();
|
|
417
|
+
const edgesSelectable = s.defaultEdgeOptions?.selectable ?? true;
|
|
418
|
+
for (const edge of s.edges) {
|
|
419
|
+
if ((selectedNodeIds.current.has(edge.source) || selectedNodeIds.current.has(edge.target)) && (edge.selectable ?? edgesSelectable)) {
|
|
420
|
+
selectedEdgeIds.current.add(edge.id);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (!sameSet(prevNodes, selectedNodeIds.current))
|
|
424
|
+
s.triggerNodeChanges(selectionChanges(s.nodeLookup.values(), selectedNodeIds.current, true));
|
|
425
|
+
if (!sameSet(prevEdges, selectedEdgeIds.current))
|
|
426
|
+
s.triggerEdgeChanges(selectionChanges(s.edgeLookup.values(), selectedEdgeIds.current));
|
|
427
|
+
store.setState({ userSelectionRect: next, userSelectionActive: true, nodesSelectionActive: false });
|
|
428
|
+
};
|
|
429
|
+
const cleanupAutoPan = () => {
|
|
430
|
+
cancelAnimationFrame(autoPanId.current);
|
|
431
|
+
autoPanId.current = 0;
|
|
432
|
+
autoPanStarted.current = false;
|
|
433
|
+
};
|
|
434
|
+
const autoPan = () => {
|
|
435
|
+
if (props.autoPanOnSelection === false || !bounds.current)
|
|
436
|
+
return;
|
|
437
|
+
const [x, y] = calcAutoPan(position.current, bounds.current, store.getState().autoPanSpeed);
|
|
438
|
+
const panned = store.getState().panBy({ x, y });
|
|
439
|
+
if (selectionInProgress.current && panned)
|
|
440
|
+
commit(position.current.x, position.current.y);
|
|
441
|
+
autoPanId.current = requestAnimationFrame(autoPan);
|
|
442
|
+
};
|
|
443
|
+
useEffect(() => () => cancelAnimationFrame(autoPanId.current), []);
|
|
444
|
+
const onPointerMove = (event) => {
|
|
445
|
+
const s = store.getState();
|
|
446
|
+
const rect = s.userSelectionRect;
|
|
447
|
+
if (!bounds.current || !rect)
|
|
448
|
+
return;
|
|
449
|
+
const { x, y } = getEventPosition(event.nativeEvent, bounds.current);
|
|
450
|
+
position.current = { x, y };
|
|
451
|
+
const screenStart = rendererPointToPoint({ x: rect.startX, y: rect.startY }, s.transform);
|
|
452
|
+
if (!selectionInProgress.current) {
|
|
453
|
+
const required = selectionKeyPressed ? 0 : paneClickDistance;
|
|
454
|
+
if (Math.hypot(x - screenStart.x, y - screenStart.y) <= required)
|
|
455
|
+
return;
|
|
456
|
+
s.resetSelectedElements();
|
|
457
|
+
s.onSelectionStart?.(event);
|
|
458
|
+
}
|
|
459
|
+
selectionInProgress.current = true;
|
|
460
|
+
if (!autoPanStarted.current) {
|
|
461
|
+
autoPan();
|
|
462
|
+
autoPanStarted.current = true;
|
|
463
|
+
}
|
|
464
|
+
commit(x, y);
|
|
465
|
+
};
|
|
466
|
+
const onPointerUp = (event) => {
|
|
467
|
+
if (!isSelectionEnabled) {
|
|
468
|
+
if (event.target === container.current && store.getState().connection.inProgress)
|
|
469
|
+
connectionEndedOnPane.current = true;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (event.button !== 0)
|
|
473
|
+
return;
|
|
474
|
+
event.target.releasePointerCapture?.(event.pointerId);
|
|
475
|
+
if (!userSelectionActive && event.target === container.current && store.getState().userSelectionRect)
|
|
476
|
+
onClick(event);
|
|
477
|
+
store.setState({ userSelectionActive: false, userSelectionRect: null });
|
|
478
|
+
if (selectionInProgress.current) {
|
|
479
|
+
;
|
|
480
|
+
store.getState().onSelectionEnd?.(event);
|
|
481
|
+
store.setState({ nodesSelectionActive: selectedNodeIds.current.size > 0 });
|
|
482
|
+
}
|
|
483
|
+
cleanupAutoPan();
|
|
484
|
+
};
|
|
485
|
+
const onPointerCancel = (event) => {
|
|
486
|
+
;
|
|
487
|
+
event.target.releasePointerCapture?.(event.pointerId);
|
|
488
|
+
cleanupAutoPan();
|
|
489
|
+
};
|
|
490
|
+
const draggable = panOnDrag === true || (Array.isArray(panOnDrag) && panOnDrag.includes(0));
|
|
491
|
+
const handlers = store.getState();
|
|
492
|
+
return (_jsxs("div", { ref: container, className: `avis-flow__pane${draggable ? " draggable" : ""}${dragging ? " dragging" : ""}${isSelecting ? " selection" : ""}`, style: CONTAINER, onClick: isSelectionEnabled ? undefined : (event) => event.target === event.currentTarget && onClick(event), onContextMenu: (event) => event.target === event.currentTarget && onContextMenu(event), onWheel: own(props.onPaneScroll), onPointerEnter: isSelectionEnabled ? undefined : props.onPaneMouseEnter, onPointerMove: isSelectionEnabled ? onPointerMove : props.onPaneMouseMove, onPointerUp: onPointerUp, onPointerCancel: isSelectionEnabled ? onPointerCancel : undefined, onPointerDownCapture: isSelectionEnabled ? onPointerDownCapture : undefined, onClickCapture: isSelectionEnabled ? onClickCapture : undefined, onPointerLeave: props.onPaneMouseLeave ?? undefined, children: [props.children, nodesSelectionActive ? _jsx(NodesSelection, { onSelectionContextMenu: handlers.onSelectionContextMenu }) : null, _jsx(UserSelection, {})] }));
|
|
493
|
+
}
|
|
494
|
+
function UserSelection() {
|
|
495
|
+
const active = useStore((s) => s.userSelectionActive);
|
|
496
|
+
const rect = useStore((s) => s.userSelectionRect);
|
|
497
|
+
if (!active || !rect)
|
|
498
|
+
return null;
|
|
499
|
+
return (_jsx("div", { className: "avis-flow__selection avis-flow__container", style: { width: rect.width, height: rect.height, transform: `translate(${rect.x}px, ${rect.y}px)` } }));
|
|
500
|
+
}
|
|
501
|
+
/** React Flow's NodesSelection: the box around a box-selected group; dragging it drags them all. */
|
|
502
|
+
function NodesSelection({ onSelectionContextMenu }) {
|
|
503
|
+
const store = useContext(StoreContext);
|
|
504
|
+
const box = useStore((s) => {
|
|
505
|
+
const b = selectedNodesBounds(s.nodeLookup);
|
|
506
|
+
return { b, active: s.userSelectionActive, t: s.transform };
|
|
507
|
+
}, (a, b) => a.active === b.active &&
|
|
508
|
+
a.t === b.t &&
|
|
509
|
+
a.b?.x === b.b?.x &&
|
|
510
|
+
a.b?.y === b.b?.y &&
|
|
511
|
+
a.b?.width === b.b?.width &&
|
|
512
|
+
a.b?.height === b.b?.height);
|
|
513
|
+
const ref = useRef(null);
|
|
514
|
+
const shouldRender = !box.active && box.b !== null;
|
|
515
|
+
useEffect(() => {
|
|
516
|
+
ref.current?.focus({ preventScroll: true });
|
|
517
|
+
}, []);
|
|
518
|
+
useEffect(() => {
|
|
519
|
+
const element = ref.current;
|
|
520
|
+
if (!shouldRender || !element)
|
|
521
|
+
return;
|
|
522
|
+
return attachDrag(store, { domNode: element });
|
|
523
|
+
}, [store, shouldRender]);
|
|
524
|
+
if (!shouldRender || !box.b)
|
|
525
|
+
return null;
|
|
526
|
+
const [tx, ty, k] = box.t;
|
|
527
|
+
return (_jsx("div", { className: "avis-flow__nodesselection avis-flow__container nopan", style: { transform: `translate(${tx}px,${ty}px) scale(${k}) translate(${box.b.x}px,${box.b.y}px)` }, children: _jsx("div", { ref: ref, className: "avis-flow__nodesselection-rect", tabIndex: -1, onContextMenu: onSelectionContextMenu
|
|
528
|
+
? (event) => onSelectionContextMenu(event, store.getState().nodes.filter((n) => n.selected))
|
|
529
|
+
: undefined, onKeyDown: (event) => {
|
|
530
|
+
if (ARROWS[event.key]) {
|
|
531
|
+
event.preventDefault();
|
|
532
|
+
moveSelectedNodes(store, ARROWS[event.key], event.shiftKey ? 4 : 1);
|
|
533
|
+
}
|
|
534
|
+
}, style: { width: box.b.width, height: box.b.height } }) }));
|
|
535
|
+
}
|
|
536
|
+
// ---- the connection line -------------------------------------------------------------
|
|
537
|
+
function ConnectionLineWrapper({ type = "default", style, component: Custom, containerStyle, }) {
|
|
538
|
+
const nodesConnectable = useStore((s) => s.nodesConnectable);
|
|
539
|
+
const width = useStore((s) => s.width);
|
|
540
|
+
const height = useStore((s) => s.height);
|
|
541
|
+
const connection = useConnection();
|
|
542
|
+
if (!(width && nodesConnectable && connection.inProgress))
|
|
543
|
+
return null;
|
|
544
|
+
const status = getConnectionStatus(connection.isValid);
|
|
545
|
+
const { from, to, fromPosition, toPosition } = connection;
|
|
546
|
+
let line;
|
|
547
|
+
if (Custom) {
|
|
548
|
+
line = (_jsx(Custom, { connectionLineType: type, connectionLineStyle: style, fromNode: connection.fromNode, fromHandle: connection.fromHandle, fromX: from.x, fromY: from.y, toX: to.x, toY: to.y, fromPosition: fromPosition, toPosition: toPosition, connectionStatus: status, toNode: connection.toNode, toHandle: connection.toHandle, pointer: connection.pointer }));
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
const params = { sourceX: from.x, sourceY: from.y, sourcePosition: fromPosition, targetX: to.x, targetY: to.y, targetPosition: toPosition };
|
|
552
|
+
const [path] = type === "default"
|
|
553
|
+
? getBezierPath(params)
|
|
554
|
+
: type === "step"
|
|
555
|
+
? getSmoothStepPath({ ...params, borderRadius: 0 })
|
|
556
|
+
: type === "smoothstep"
|
|
557
|
+
? getSmoothStepPath(params)
|
|
558
|
+
: getStraightPath(params);
|
|
559
|
+
line = _jsx("path", { d: path, fill: "none", className: "avis-flow__connection-path", style: style });
|
|
560
|
+
}
|
|
561
|
+
return (_jsx("svg", { style: { position: "absolute", top: 0, left: 0, overflow: "visible", pointerEvents: "none", ...containerStyle }, width: width, height: height, className: "avis-flow__connectionline avis-flow__container", children: _jsx("g", { className: `avis-flow__connection${status ? ` ${status}` : ""}`, children: line }) }));
|
|
562
|
+
}
|
|
563
|
+
// ---- nodes -------------------------------------------------------------------------
|
|
564
|
+
const sameIds = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
565
|
+
function Nodes({ nodeTypes, onlyVisible, mountNode }) {
|
|
566
|
+
// xyflow's useVisibleNodeIds: with onlyRenderVisibleElements, the nodes
|
|
567
|
+
// (partly) in view, and the unmeasured ones so they get measured.
|
|
568
|
+
const select = useCallback((s) => {
|
|
569
|
+
const ids = onlyVisible ? getNodesInside(s.nodeLookup, { x: 0, y: 0, width: s.width, height: s.height }, s.transform, true).map((n) => n.id) : s.visibleNodeIds;
|
|
570
|
+
if (!mountNode)
|
|
571
|
+
return ids;
|
|
572
|
+
return ids.filter((id) => {
|
|
573
|
+
const node = s.nodeLookup.get(id);
|
|
574
|
+
return Boolean(node && mountNode(node.internals.userNode));
|
|
575
|
+
});
|
|
576
|
+
}, [onlyVisible, mountNode]);
|
|
577
|
+
const visible = useStore(select, sameIds);
|
|
578
|
+
return (_jsx("div", { className: "avis-flow__nodes", style: { position: "absolute", width: "100%", height: "100%", top: 0, left: 0 }, children: visible.map((id) => (_jsx(NodeWrapper, { id: id, nodeTypes: nodeTypes }, id))) }));
|
|
579
|
+
}
|
|
580
|
+
// React Flow's built-in node types.
|
|
581
|
+
function InputNode({ data, isConnectable, sourcePosition = "bottom" }) {
|
|
582
|
+
return (_jsxs(_Fragment, { children: [data?.label, _jsx(Handle, { type: "source", position: sourcePosition, isConnectable: isConnectable })] }));
|
|
583
|
+
}
|
|
584
|
+
function DefaultNode({ data, isConnectable, targetPosition = "top", sourcePosition = "bottom" }) {
|
|
585
|
+
return (_jsxs(_Fragment, { children: [_jsx(Handle, { type: "target", position: targetPosition, isConnectable: isConnectable }), data?.label, _jsx(Handle, { type: "source", position: sourcePosition, isConnectable: isConnectable })] }));
|
|
586
|
+
}
|
|
587
|
+
function OutputNode({ data, isConnectable, targetPosition = "top" }) {
|
|
588
|
+
return (_jsxs(_Fragment, { children: [_jsx(Handle, { type: "target", position: targetPosition, isConnectable: isConnectable }), data?.label] }));
|
|
589
|
+
}
|
|
590
|
+
function GroupNode() {
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
const BUILTIN_NODES = { input: InputNode, default: DefaultNode, output: OutputNode, group: GroupNode };
|
|
594
|
+
/** Handle boxes inside a node element, in its own units (xyflow's getHandleBounds). */
|
|
595
|
+
/** xyflow's getHandleBounds: every `.source` / `.target` element in the node, relative to it, at the DOM's zoom. */
|
|
596
|
+
function measureHandles(element, nodeId) {
|
|
597
|
+
const viewport = element.closest(".avis-flow__viewport");
|
|
598
|
+
const zoom = viewport ? new DOMMatrixReadOnly(getComputedStyle(viewport).transform).m22 || 1 : 1;
|
|
599
|
+
const nodeRect = element.getBoundingClientRect();
|
|
600
|
+
const bounds = (type) => {
|
|
601
|
+
const handles = element.querySelectorAll(`.${type}`);
|
|
602
|
+
if (!handles.length)
|
|
603
|
+
return null;
|
|
604
|
+
return [...handles].map((handle) => {
|
|
605
|
+
const rect = handle.getBoundingClientRect();
|
|
606
|
+
return {
|
|
607
|
+
id: handle.getAttribute("data-handleid"),
|
|
608
|
+
type,
|
|
609
|
+
nodeId,
|
|
610
|
+
position: handle.getAttribute("data-handlepos"),
|
|
611
|
+
x: (rect.left - nodeRect.left) / zoom,
|
|
612
|
+
y: (rect.top - nodeRect.top) / zoom,
|
|
613
|
+
width: handle.offsetWidth,
|
|
614
|
+
height: handle.offsetHeight,
|
|
615
|
+
};
|
|
616
|
+
});
|
|
617
|
+
};
|
|
618
|
+
return { source: bounds("source"), target: bounds("target") };
|
|
619
|
+
}
|
|
620
|
+
const measurers = new WeakMap();
|
|
621
|
+
/**
|
|
622
|
+
* xyflow's useResizeObserver + updateNodeInternals: every node element is
|
|
623
|
+
* watched by one ResizeObserver; whatever changed in a frame is measured and
|
|
624
|
+
* written back in one store update and one batch of 'dimensions' changes
|
|
625
|
+
* (a node at a time made adding hundreds of nodes quadratic).
|
|
626
|
+
*/
|
|
627
|
+
function measurerOf(store) {
|
|
628
|
+
const existing = measurers.get(store);
|
|
629
|
+
if (existing)
|
|
630
|
+
return existing;
|
|
631
|
+
const elements = new Map();
|
|
632
|
+
const ids = new WeakMap();
|
|
633
|
+
const removed = new Set();
|
|
634
|
+
let removeQueued = false;
|
|
635
|
+
const flush = (changed) => {
|
|
636
|
+
const s = store.getState();
|
|
637
|
+
const sizes = new Map(s.measuredSizes);
|
|
638
|
+
const handles = new Map(s.measuredHandles);
|
|
639
|
+
const changes = [];
|
|
640
|
+
let any = false;
|
|
641
|
+
for (const id of changed) {
|
|
642
|
+
const element = elements.get(id);
|
|
643
|
+
if (!element || !element.isConnected)
|
|
644
|
+
continue;
|
|
645
|
+
const width = element.offsetWidth;
|
|
646
|
+
const height = element.offsetHeight;
|
|
647
|
+
if (!width && !height)
|
|
648
|
+
continue;
|
|
649
|
+
any = true;
|
|
650
|
+
sizes.set(id, { width, height });
|
|
651
|
+
handles.set(id, measureHandles(element, id));
|
|
652
|
+
const user = s.nodeLookup.get(id)?.internals.userNode;
|
|
653
|
+
if (user && (user.measured?.width !== width || user.measured?.height !== height)) {
|
|
654
|
+
changes.push({ type: "dimensions", id, dimensions: { width, height } });
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (!any)
|
|
658
|
+
return;
|
|
659
|
+
store.setState((now) => {
|
|
660
|
+
const next = { ...now, measuredSizes: sizes, measuredHandles: handles };
|
|
661
|
+
return { measuredSizes: sizes, measuredHandles: handles, nodeLookup: adoptNodes(next, now.nodes) };
|
|
662
|
+
});
|
|
663
|
+
if (changes.length)
|
|
664
|
+
store.getState().triggerNodeChanges(changes);
|
|
665
|
+
};
|
|
666
|
+
const observer = typeof ResizeObserver === "undefined"
|
|
667
|
+
? null
|
|
668
|
+
: new ResizeObserver((entries) => {
|
|
669
|
+
const changed = new Set();
|
|
670
|
+
for (const entry of entries) {
|
|
671
|
+
const id = ids.get(entry.target);
|
|
672
|
+
if (id !== undefined)
|
|
673
|
+
changed.add(id);
|
|
674
|
+
}
|
|
675
|
+
flush(changed);
|
|
676
|
+
});
|
|
677
|
+
const measurer = {
|
|
678
|
+
observe(id, element) {
|
|
679
|
+
removed.delete(id);
|
|
680
|
+
elements.set(id, element);
|
|
681
|
+
ids.set(element, id);
|
|
682
|
+
// The observer reports a newly watched element's size in the next frame, with the others.
|
|
683
|
+
if (observer)
|
|
684
|
+
observer.observe(element);
|
|
685
|
+
else
|
|
686
|
+
flush([id]);
|
|
687
|
+
},
|
|
688
|
+
unobserve(id, element) {
|
|
689
|
+
observer?.unobserve(element);
|
|
690
|
+
if (elements.get(id) !== element)
|
|
691
|
+
return;
|
|
692
|
+
elements.delete(id);
|
|
693
|
+
removed.add(id);
|
|
694
|
+
if (removeQueued)
|
|
695
|
+
return;
|
|
696
|
+
removeQueued = true;
|
|
697
|
+
queueMicrotask(() => {
|
|
698
|
+
removeQueued = false;
|
|
699
|
+
if (!removed.size)
|
|
700
|
+
return;
|
|
701
|
+
const s = store.getState();
|
|
702
|
+
const sizes = new Map(s.measuredSizes);
|
|
703
|
+
const handles = new Map(s.measuredHandles);
|
|
704
|
+
for (const id of removed) {
|
|
705
|
+
if (elements.has(id))
|
|
706
|
+
continue;
|
|
707
|
+
sizes.delete(id);
|
|
708
|
+
handles.delete(id);
|
|
709
|
+
}
|
|
710
|
+
removed.clear();
|
|
711
|
+
store.setState({ measuredSizes: sizes, measuredHandles: handles });
|
|
712
|
+
});
|
|
713
|
+
},
|
|
714
|
+
force(list) {
|
|
715
|
+
flush(list);
|
|
716
|
+
},
|
|
717
|
+
};
|
|
718
|
+
measurers.set(store, measurer);
|
|
719
|
+
return measurer;
|
|
720
|
+
}
|
|
721
|
+
const NodeWrapper = memo(function NodeWrapper({ id, nodeTypes }) {
|
|
722
|
+
const store = useContext(StoreContext);
|
|
723
|
+
const node = useStore((s) => s.nodeLookup.get(id));
|
|
724
|
+
const options = useStore((s) => [s.nodesDraggable, s.elementsSelectable, s.nodesConnectable, s.nodesFocusable], (a, b) => a.every((v, i) => v === b[i]));
|
|
725
|
+
const ref = useRef(null);
|
|
726
|
+
// Sizes and handles from the DOM, written back as React Flow's 'dimensions'
|
|
727
|
+
// changes: one shared ResizeObserver per flow, flushed in one batch.
|
|
728
|
+
useLayoutEffect(() => {
|
|
729
|
+
const element = ref.current;
|
|
730
|
+
if (!element)
|
|
731
|
+
return;
|
|
732
|
+
const measurer = measurerOf(store);
|
|
733
|
+
measurer.observe(id, element);
|
|
734
|
+
return () => measurer.unobserve(id, element);
|
|
735
|
+
}, [store, id]);
|
|
736
|
+
if (!node)
|
|
737
|
+
return null;
|
|
738
|
+
return _jsx(NodeView, { id: id, node: node, options: options, nodeTypes: nodeTypes, nodeRef: ref });
|
|
739
|
+
});
|
|
740
|
+
const ARROWS = {
|
|
741
|
+
ArrowUp: { x: 0, y: -1 },
|
|
742
|
+
ArrowDown: { x: 0, y: 1 },
|
|
743
|
+
ArrowLeft: { x: -1, y: 0 },
|
|
744
|
+
ArrowRight: { x: 1, y: 0 },
|
|
745
|
+
};
|
|
746
|
+
/** xyflow's handleNodeClick: select it, or unselect it (Escape, or ⌘-click when selected). */
|
|
747
|
+
export function handleNodeClick(store, id, unselect = false, nodeRef) {
|
|
748
|
+
const { addSelectedNodes, unselectNodesAndEdges, multiSelectionActive, nodeLookup } = store.getState();
|
|
749
|
+
const node = nodeLookup.get(id);
|
|
750
|
+
if (!node)
|
|
751
|
+
return;
|
|
752
|
+
store.setState({ nodesSelectionActive: false });
|
|
753
|
+
if (!node.selected) {
|
|
754
|
+
addSelectedNodes([id]);
|
|
755
|
+
}
|
|
756
|
+
else if (unselect || (node.selected && multiSelectionActive)) {
|
|
757
|
+
unselectNodesAndEdges({ nodes: [node], edges: [] });
|
|
758
|
+
requestAnimationFrame(() => nodeRef?.current?.blur());
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/** xyflow's useMoveSelectedNodes: arrows move the selected, draggable nodes. */
|
|
762
|
+
function moveSelectedNodes(store, direction, factor) {
|
|
763
|
+
const { snapToGrid, snapGrid, nodesDraggable, nodeLookup, triggerNodeChanges } = store.getState();
|
|
764
|
+
const dx = direction.x * (snapToGrid ? snapGrid[0] : 5) * factor;
|
|
765
|
+
const dy = direction.y * (snapToGrid ? snapGrid[1] : 5) * factor;
|
|
766
|
+
const changes = [];
|
|
767
|
+
for (const node of nodeLookup.values()) {
|
|
768
|
+
const draggable = node.draggable || (nodesDraggable && node.draggable === undefined);
|
|
769
|
+
if (!node.selected || !draggable)
|
|
770
|
+
continue;
|
|
771
|
+
let parentId = node.parentId;
|
|
772
|
+
let selectedAncestor = false;
|
|
773
|
+
const seen = new Set();
|
|
774
|
+
while (parentId && !seen.has(parentId)) {
|
|
775
|
+
seen.add(parentId);
|
|
776
|
+
const parent = nodeLookup.get(parentId);
|
|
777
|
+
if (parent?.selected) {
|
|
778
|
+
selectedAncestor = true;
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
parentId = parent?.parentId;
|
|
782
|
+
}
|
|
783
|
+
if (selectedAncestor)
|
|
784
|
+
continue;
|
|
785
|
+
let x = node.internals.positionAbsolute.x + dx;
|
|
786
|
+
let y = node.internals.positionAbsolute.y + dy;
|
|
787
|
+
if (snapToGrid) {
|
|
788
|
+
x = snapGrid[0] * Math.round(x / snapGrid[0]);
|
|
789
|
+
y = snapGrid[1] * Math.round(y / snapGrid[1]);
|
|
790
|
+
}
|
|
791
|
+
const state = store.getState();
|
|
792
|
+
const { position } = calculateNodePosition({ nodeId: node.id, nextPosition: { x, y }, nodeLookup, nodeExtent: state.nodeExtent, nodeOrigin: state.nodeOrigin });
|
|
793
|
+
changes.push({ type: "position", id: node.id, position, dragging: false });
|
|
794
|
+
}
|
|
795
|
+
let out = changes;
|
|
796
|
+
for (const middleware of store.getState().onNodesChangeMiddlewareMap.values())
|
|
797
|
+
out = middleware(out);
|
|
798
|
+
triggerNodeChanges(out);
|
|
799
|
+
}
|
|
800
|
+
function inlineDimensions(node) {
|
|
801
|
+
const style = (node.style ?? {});
|
|
802
|
+
const out = {};
|
|
803
|
+
const width = node.measured === undefined ? (node.width ?? node.initialWidth ?? style.width) : (node.width ?? style.width);
|
|
804
|
+
const height = node.measured === undefined ? (node.height ?? node.initialHeight ?? style.height) : (node.height ?? style.height);
|
|
805
|
+
if (width !== undefined)
|
|
806
|
+
out.width = width;
|
|
807
|
+
if (height !== undefined)
|
|
808
|
+
out.height = height;
|
|
809
|
+
return out;
|
|
810
|
+
}
|
|
811
|
+
const isInput = (target) => {
|
|
812
|
+
const el = target;
|
|
813
|
+
return Boolean(el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) || el.closest?.(".nokey")));
|
|
814
|
+
};
|
|
815
|
+
function NodeView({ id, node, options, nodeTypes, nodeRef }) {
|
|
816
|
+
const store = useContext(StoreContext);
|
|
817
|
+
const handlers = useStore((s) => ({
|
|
818
|
+
onClick: s.onNodeClick,
|
|
819
|
+
onDoubleClick: s.onNodeDoubleClick,
|
|
820
|
+
onContextMenu: s.onNodeContextMenu,
|
|
821
|
+
onMouseEnter: s.onNodeMouseEnter,
|
|
822
|
+
onMouseMove: s.onNodeMouseMove,
|
|
823
|
+
onMouseLeave: s.onNodeMouseLeave,
|
|
824
|
+
}), (a, b) => Object.keys(a).every((k) => a[k] === b[k]));
|
|
825
|
+
const isParent = useStore((s) => s.parentIds.has(id));
|
|
826
|
+
const user = node.internals.userNode;
|
|
827
|
+
// xyflow: an unknown type falls back to the default node.
|
|
828
|
+
const known = nodeTypes?.[user.type || "default"] ?? BUILTIN_NODES[user.type || "default"];
|
|
829
|
+
const type = known ? user.type || "default" : "default";
|
|
830
|
+
const Component = (known ?? nodeTypes?.default ?? BUILTIN_NODES.default);
|
|
831
|
+
const [draggableAll, selectableAll, connectableAll, focusableAll] = options;
|
|
832
|
+
const draggable = Boolean(user.draggable || (draggableAll && user.draggable === undefined));
|
|
833
|
+
const selectable = Boolean(user.selectable || (selectableAll && user.selectable === undefined));
|
|
834
|
+
const connectable = Boolean(user.connectable || (connectableAll && user.connectable === undefined));
|
|
835
|
+
const focusable = Boolean(user.focusable || (focusableAll && user.focusable === undefined));
|
|
836
|
+
const userCopy = () => ({ ...node.internals.userNode });
|
|
837
|
+
// xyflow's useDrag (XYDrag on the node's element).
|
|
838
|
+
const [dragging, setDragging] = useState(false);
|
|
839
|
+
const dragHandle = user.dragHandle;
|
|
840
|
+
const noDragClassName = useStore((s) => s.noDragClassName ?? "nodrag");
|
|
841
|
+
const noPanClassName = useStore((s) => s.noPanClassName ?? "nopan");
|
|
842
|
+
useEffect(() => {
|
|
843
|
+
if (!known)
|
|
844
|
+
reportFlowError(store, "003", `Node type "${user.type}" not found. Using default type.`);
|
|
845
|
+
}, [store, known, user.type]);
|
|
846
|
+
const nodeClickDistance = useStore((s) => s.nodeClickDistance);
|
|
847
|
+
const dragDisabled = Boolean(user.hidden) || !draggable;
|
|
848
|
+
useEffect(() => {
|
|
849
|
+
const element = nodeRef.current;
|
|
850
|
+
if (dragDisabled || !element)
|
|
851
|
+
return;
|
|
852
|
+
return attachDrag(store, {
|
|
853
|
+
domNode: element,
|
|
854
|
+
nodeId: id,
|
|
855
|
+
isSelectable: selectable,
|
|
856
|
+
noDragClassName,
|
|
857
|
+
handleSelector: dragHandle,
|
|
858
|
+
nodeClickDistance,
|
|
859
|
+
onNodeMouseDown: (nodeId) => handleNodeClick(store, nodeId, false, nodeRef),
|
|
860
|
+
onDragStart: () => setDragging(true),
|
|
861
|
+
onDragStop: () => setDragging(false),
|
|
862
|
+
});
|
|
863
|
+
}, [store, id, dragDisabled, selectable, dragHandle, nodeClickDistance, nodeRef, noDragClassName]);
|
|
864
|
+
const onClick = (event) => {
|
|
865
|
+
const { selectNodesOnDrag, nodeDragThreshold } = store.getState();
|
|
866
|
+
if (selectable && (!selectNodesOnDrag || !draggable || nodeDragThreshold > 0))
|
|
867
|
+
handleNodeClick(store, id, false, nodeRef);
|
|
868
|
+
handlers.onClick?.(event, userCopy());
|
|
869
|
+
};
|
|
870
|
+
const rfId = useStore((s) => s.rfId);
|
|
871
|
+
const disableKeyboardA11y = useStore((s) => Boolean(s.disableKeyboardA11y));
|
|
872
|
+
const onKeyDown = (event) => {
|
|
873
|
+
if (isInput(event.nativeEvent.target) || disableKeyboardA11y)
|
|
874
|
+
return;
|
|
875
|
+
if (["Enter", " ", "Escape"].includes(event.key) && selectable) {
|
|
876
|
+
event.preventDefault();
|
|
877
|
+
event.stopPropagation();
|
|
878
|
+
handleNodeClick(store, id, event.key === "Escape", nodeRef);
|
|
879
|
+
}
|
|
880
|
+
else if (draggable && node.selected && ARROWS[event.key]) {
|
|
881
|
+
event.preventDefault();
|
|
882
|
+
const direction = event.key.replace("Arrow", "").toLowerCase();
|
|
883
|
+
store.setState({
|
|
884
|
+
ariaLiveMessage: store.getState().ariaLabelConfig["node.a11yDescription.ariaLiveMessage"]({ direction, x: ~~node.internals.positionAbsolute.x, y: ~~node.internals.positionAbsolute.y }),
|
|
885
|
+
});
|
|
886
|
+
moveSelectedNodes(store, ARROWS[event.key], event.shiftKey ? 4 : 1);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
// xyflow: a keyboard-focused node outside the view is centred.
|
|
890
|
+
const onFocus = () => {
|
|
891
|
+
if (disableKeyboardA11y || !nodeRef.current?.matches(":focus-visible"))
|
|
892
|
+
return;
|
|
893
|
+
const { transform, width, height, autoPanOnNodeFocus } = store.getState();
|
|
894
|
+
if (!autoPanOnNodeFocus)
|
|
895
|
+
return;
|
|
896
|
+
const inView = getNodesInside(new Map([[id, node]]), { x: 0, y: 0, width, height }, transform, true).length > 0;
|
|
897
|
+
if (!inView) {
|
|
898
|
+
const w = node.measured.width ?? node.width ?? 0;
|
|
899
|
+
const h = node.measured.height ?? node.height ?? 0;
|
|
900
|
+
void store.instance.setCenter(node.internals.positionAbsolute.x + w / 2, node.internals.positionAbsolute.y + h / 2, { zoom: transform[2] });
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
const hasPointerEvents = selectable || draggable || handlers.onClick || handlers.onMouseEnter || handlers.onMouseMove || handlers.onMouseLeave;
|
|
904
|
+
const { x, y } = node.internals.positionAbsolute;
|
|
905
|
+
const hasSize = Boolean(node.measured.width && node.measured.height);
|
|
906
|
+
const className = [
|
|
907
|
+
"avis-flow__node",
|
|
908
|
+
`avis-flow__node-${type}`,
|
|
909
|
+
draggable ? noPanClassName : "",
|
|
910
|
+
user.className ?? "",
|
|
911
|
+
node.selected ? "selected" : "",
|
|
912
|
+
selectable ? "selectable" : "",
|
|
913
|
+
isParent ? "parent" : "",
|
|
914
|
+
draggable ? "draggable" : "",
|
|
915
|
+
dragging ? "dragging" : "",
|
|
916
|
+
]
|
|
917
|
+
.filter(Boolean)
|
|
918
|
+
.join(" ");
|
|
919
|
+
const style = {
|
|
920
|
+
zIndex: node.internals.z,
|
|
921
|
+
transform: `translate(${x}px,${y}px)`,
|
|
922
|
+
pointerEvents: hasPointerEvents ? "all" : "none",
|
|
923
|
+
visibility: hasSize ? "visible" : "hidden",
|
|
924
|
+
...user.style,
|
|
925
|
+
// xyflow's getNodeInlineStyleDimensions (after the node's style).
|
|
926
|
+
...inlineDimensions(user),
|
|
927
|
+
};
|
|
928
|
+
return (_jsx("div", { ref: nodeRef, className: className, "data-id": id, "data-testid": `rf__node-${id}`, style: style, onMouseEnter: handlers.onMouseEnter ? (event) => handlers.onMouseEnter?.(event, userCopy()) : undefined, onMouseMove: handlers.onMouseMove ? (event) => handlers.onMouseMove?.(event, userCopy()) : undefined, onMouseLeave: handlers.onMouseLeave ? (event) => handlers.onMouseLeave?.(event, userCopy()) : undefined, onContextMenu: handlers.onContextMenu ? (event) => handlers.onContextMenu?.(event, userCopy()) : undefined, onClick: onClick, onDoubleClick: handlers.onDoubleClick ? (event) => handlers.onDoubleClick?.(event, userCopy()) : undefined, onKeyDown: focusable ? onKeyDown : undefined, tabIndex: focusable ? 0 : undefined, role: user.ariaRole ?? (focusable ? "group" : undefined), "aria-roledescription": "node", "aria-describedby": disableKeyboardA11y ? undefined : `avis-flow__node-desc-${rfId}`, "aria-label": user.ariaLabel, onFocus: focusable ? onFocus : undefined, ...user.domAttributes, children: _jsx(NodeIdContext.Provider, { value: id, children: _jsx(Component, { id: id, data: user.data, type: type, selected: Boolean(node.selected), dragging: dragging, zIndex: node.internals.z, isConnectable: connectable, selectable: selectable, draggable: draggable, deletable: user.deletable ?? true, positionAbsoluteX: x, positionAbsoluteY: y,
|
|
929
|
+
// xyflow's getNodeDimensions: measured, then width, then initialWidth.
|
|
930
|
+
width: user.measured?.width ?? user.width ?? user.initialWidth ?? 0, height: user.measured?.height ?? user.height ?? user.initialHeight ?? 0, sourcePosition: user.sourcePosition, targetPosition: user.targetPosition, dragHandle: user.dragHandle, parentId: user.parentId }) }) }));
|
|
931
|
+
}
|
|
932
|
+
/** React Flow's built-in edges (internal: their paths carry no id). */
|
|
933
|
+
function builtinEdge(pathOf, internal = true) {
|
|
934
|
+
return memo(function BuiltinEdge(props) {
|
|
935
|
+
const [path, labelX, labelY] = pathOf(props);
|
|
936
|
+
return (_jsx(BaseEdge, { id: internal ? undefined : props.id, path: path, labelX: labelX, labelY: labelY, label: props.label, labelStyle: props.labelStyle, labelShowBg: props.labelShowBg, labelBgStyle: props.labelBgStyle, labelBgPadding: props.labelBgPadding, labelBgBorderRadius: props.labelBgBorderRadius, style: props.style, markerEnd: props.markerEnd, markerStart: props.markerStart, interactionWidth: props.interactionWidth }));
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
export const BezierEdge = builtinEdge((p) => getBezierPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", curvature: p.pathOptions?.curvature }), false);
|
|
940
|
+
export const StraightEdge = builtinEdge((p) => getStraightPath(p), false);
|
|
941
|
+
export const StepEdge = builtinEdge((p) => getSmoothStepPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", borderRadius: 0, offset: p.pathOptions?.offset, stepPosition: p.pathOptions?.stepPosition }), false);
|
|
942
|
+
export const SmoothStepEdge = builtinEdge((p) => getSmoothStepPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", borderRadius: p.pathOptions?.borderRadius, offset: p.pathOptions?.offset, stepPosition: p.pathOptions?.stepPosition }), false);
|
|
943
|
+
export const SimpleBezierEdge = builtinEdge((p) => getSimpleBezierPath(p), false);
|
|
944
|
+
const BUILTIN_EDGES = {
|
|
945
|
+
default: builtinEdge((p) => getBezierPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", curvature: p.pathOptions?.curvature })),
|
|
946
|
+
straight: builtinEdge((p) => getStraightPath(p)),
|
|
947
|
+
step: builtinEdge((p) => getSmoothStepPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", borderRadius: 0, offset: p.pathOptions?.offset, stepPosition: p.pathOptions?.stepPosition })),
|
|
948
|
+
smoothstep: builtinEdge((p) => getSmoothStepPath({ ...p, sourcePosition: p.sourcePosition ?? "bottom", targetPosition: p.targetPosition ?? "top", borderRadius: p.pathOptions?.borderRadius, offset: p.pathOptions?.offset, stepPosition: p.pathOptions?.stepPosition })),
|
|
949
|
+
simplebezier: builtinEdge((p) => getSimpleBezierPath(p)),
|
|
950
|
+
};
|
|
951
|
+
const isNodeInitialized = (node) => Boolean(node.internals.handleBounds || node.handles?.length) && Boolean(node.measured.width || node.width || node.initialWidth);
|
|
952
|
+
const handleBoundsOf = (node) => node.internals.handleBounds ??
|
|
953
|
+
(node.handles
|
|
954
|
+
? {
|
|
955
|
+
source: node.handles.filter((h) => h.type === "source").map((h) => ({ ...h, nodeId: node.id, width: h.width ?? 1, height: h.height ?? 1 })),
|
|
956
|
+
target: node.handles.filter((h) => h.type === "target").map((h) => ({ ...h, nodeId: node.id, width: h.width ?? 1, height: h.height ?? 1 })),
|
|
957
|
+
}
|
|
958
|
+
: null);
|
|
959
|
+
const pickHandle = (bounds, id) => (!id ? bounds[0] : bounds.find((h) => h.id === id)) ?? null;
|
|
960
|
+
/** xyflow's getEdgePosition: both ends at their handles, or nothing (an edge to a missing handle isn't drawn). */
|
|
961
|
+
function edgePosition(source, target, sourceHandle, targetHandle, connectionMode) {
|
|
962
|
+
if (!isNodeInitialized(source) || !isNodeInitialized(target))
|
|
963
|
+
return null;
|
|
964
|
+
const sb = handleBoundsOf(source);
|
|
965
|
+
const tb = handleBoundsOf(target);
|
|
966
|
+
const from = pickHandle(sb?.source ?? [], sourceHandle);
|
|
967
|
+
const to = pickHandle(connectionMode === "strict" ? (tb?.target ?? []) : [...(tb?.target ?? []), ...(tb?.source ?? [])], targetHandle);
|
|
968
|
+
if (!from || !to)
|
|
969
|
+
return null;
|
|
970
|
+
const sourcePosition = from.position || "bottom";
|
|
971
|
+
const targetPosition = to.position || "top";
|
|
972
|
+
return {
|
|
973
|
+
from: { ...getHandlePosition(source, from, sourcePosition), position: sourcePosition },
|
|
974
|
+
to: { ...getHandlePosition(target, to, targetPosition), position: targetPosition },
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
/** xyflow's isEdgeVisible: the box of its two nodes overlaps the view. */
|
|
978
|
+
function edgeInView(source, target, width, height, [tx, ty, k]) {
|
|
979
|
+
const a = nodeToRect(source);
|
|
980
|
+
const b = nodeToRect(target);
|
|
981
|
+
const x = Math.min(a.x, b.x);
|
|
982
|
+
const y = Math.min(a.y, b.y);
|
|
983
|
+
let x2 = Math.max(a.x + a.width, b.x + b.width);
|
|
984
|
+
let y2 = Math.max(a.y + a.height, b.y + b.height);
|
|
985
|
+
if (x === x2)
|
|
986
|
+
x2 += 1;
|
|
987
|
+
if (y === y2)
|
|
988
|
+
y2 += 1;
|
|
989
|
+
return getOverlappingArea({ x: -tx / k, y: -ty / k, width: width / k, height: height / k }, { x, y, width: x2 - x, height: y2 - y }) > 0;
|
|
990
|
+
}
|
|
991
|
+
function EdgeReconnect({ edge, from, to }) {
|
|
992
|
+
const store = useContext(StoreContext);
|
|
993
|
+
const enabled = useStore(s => edge.reconnectable ?? s.edgesReconnectable ?? true);
|
|
994
|
+
const reconnect = useStore(s => s.onReconnect);
|
|
995
|
+
const radius = useStore(s => s.reconnectRadius ?? 10);
|
|
996
|
+
const cancel = useRef(undefined);
|
|
997
|
+
useEffect(() => () => cancel.current?.(), []);
|
|
998
|
+
if (!enabled || !reconnect)
|
|
999
|
+
return null;
|
|
1000
|
+
const start = (moving) => (event) => {
|
|
1001
|
+
if ("button" in event && event.button !== 0)
|
|
1002
|
+
return;
|
|
1003
|
+
event.stopPropagation();
|
|
1004
|
+
const state = store.getState();
|
|
1005
|
+
const fixed = moving === "source" ? "target" : "source";
|
|
1006
|
+
const nodeId = fixed === "source" ? edge.source : edge.target;
|
|
1007
|
+
const handleId = (fixed === "source" ? edge.sourceHandle : edge.targetHandle) ?? null;
|
|
1008
|
+
state.onReconnectStart?.(event.nativeEvent, edge, moving);
|
|
1009
|
+
cancel.current = onHandlePointerDown(event.nativeEvent, {
|
|
1010
|
+
store, handleDomNode: event.currentTarget, nodeId, handleId, isTarget: fixed === "target", edgeUpdaterType: fixed,
|
|
1011
|
+
onConnect: connection => store.getState().onReconnect?.(edge, connection),
|
|
1012
|
+
isValidConnection: connection => store.getState().isValidConnection?.(connection) ?? true,
|
|
1013
|
+
onEnd: (e, finalState) => store.getState().onReconnectEnd?.(e, edge, moving, finalState),
|
|
1014
|
+
});
|
|
1015
|
+
};
|
|
1016
|
+
return _jsx(_Fragment, { children: ["source", "target"].filter(type => enabled === true || enabled === type).map(type => {
|
|
1017
|
+
const p = type === "source" ? from : to;
|
|
1018
|
+
// Sit outside the node's handle: the node DOM otherwise intercepts the press.
|
|
1019
|
+
const x = p.x + (p.position === "left" ? -radius : p.position === "right" ? radius : 0);
|
|
1020
|
+
const y = p.y + (p.position === "top" ? -radius : p.position === "bottom" ? radius : 0);
|
|
1021
|
+
return _jsx("circle", { className: `avis-flow__edgeupdater avis-flow__edgeupdater-${type}`, cx: x, cy: y, r: radius, fill: "transparent", stroke: "transparent", style: { pointerEvents: "all", cursor: "move", touchAction: "none" }, onMouseDown: start(type), onTouchStart: start(type) }, type);
|
|
1022
|
+
}) });
|
|
1023
|
+
}
|
|
1024
|
+
function Edges({ edgeTypes, onlyVisible, mounted = true }) {
|
|
1025
|
+
const store = useContext(StoreContext);
|
|
1026
|
+
const edges = useStore((s) => s.edges);
|
|
1027
|
+
// nodeLookup keeps its identity; the nodes array changes with every update.
|
|
1028
|
+
useStore((s) => s.nodes);
|
|
1029
|
+
// Initial DOM measurement can precede the uncontrolled change handler.
|
|
1030
|
+
// Handles are replaced independently of nodes/the mutable lookup Map.
|
|
1031
|
+
useStore((s) => s.measuredHandles);
|
|
1032
|
+
const lookup = useStore((s) => s.nodeLookup);
|
|
1033
|
+
const defaults = useStore((s) => s.defaultEdgeOptions);
|
|
1034
|
+
const elementsSelectable = useStore((s) => s.elementsSelectable);
|
|
1035
|
+
const edgesFocusable = useStore((s) => s.edgesFocusable);
|
|
1036
|
+
const disableKeyboardA11y = useStore(s => Boolean(s.disableKeyboardA11y));
|
|
1037
|
+
const connectionMode = useStore((s) => s.connectionMode);
|
|
1038
|
+
const handlers = useStore((s) => ({
|
|
1039
|
+
onClick: s.onEdgeClick,
|
|
1040
|
+
onDoubleClick: s.onEdgeDoubleClick,
|
|
1041
|
+
onContextMenu: s.onEdgeContextMenu,
|
|
1042
|
+
onMouseEnter: s.onEdgeMouseEnter,
|
|
1043
|
+
onMouseMove: s.onEdgeMouseMove,
|
|
1044
|
+
onMouseLeave: s.onEdgeMouseLeave,
|
|
1045
|
+
}), (x, y) => Object.keys(x).every((k) => x[k] === y[k]));
|
|
1046
|
+
const inView = useStore(useCallback((s) => {
|
|
1047
|
+
if (!onlyVisible)
|
|
1048
|
+
return null;
|
|
1049
|
+
const ids = [];
|
|
1050
|
+
if (s.width && s.height) {
|
|
1051
|
+
for (const edge of s.edges) {
|
|
1052
|
+
const source = s.nodeLookup.get(edge.source);
|
|
1053
|
+
const target = s.nodeLookup.get(edge.target);
|
|
1054
|
+
if (source && target && edgeInView(source, target, s.width, s.height, s.transform))
|
|
1055
|
+
ids.push(edge.id);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return ids;
|
|
1059
|
+
}, [onlyVisible]), (a, b) => a === b || (a !== null && b !== null && sameIds(a, b)));
|
|
1060
|
+
const rfId = useStore((s) => s.rfId);
|
|
1061
|
+
const elevateEdgesOnSelect = useStore((s) => Boolean(s.elevateEdgesOnSelect));
|
|
1062
|
+
const zIndexMode = useStore(s => s.zIndexMode);
|
|
1063
|
+
const noPanClassName = useStore(s => s.noPanClassName ?? "nopan");
|
|
1064
|
+
const defaultMarkerColor = useStore((s) => s.defaultMarkerColor ?? "#b1b1b7");
|
|
1065
|
+
const onError = useStore(s => s.onError);
|
|
1066
|
+
useEffect(() => {
|
|
1067
|
+
for (const edge of edges) {
|
|
1068
|
+
if (!lookup.has(edge.source) || !lookup.has(edge.target))
|
|
1069
|
+
reportFlowError(store, "008", `Cannot create edge "${edge.id}": source or target node is missing.`);
|
|
1070
|
+
if (edge.type && !BUILTIN_EDGES[edge.type] && !edgeTypes?.[edge.type])
|
|
1071
|
+
reportFlowError(store, "011", `Edge type "${edge.type}" not found. Using default type.`);
|
|
1072
|
+
}
|
|
1073
|
+
}, [store, edges, lookup, edgeTypes, onError]);
|
|
1074
|
+
const shown = inView ? new Set(inView) : null;
|
|
1075
|
+
const visible = mounted ? edges.filter((edge) => !shown || shown.has(edge.id)) : [];
|
|
1076
|
+
return (_jsxs("div", { className: "avis-flow__edges", children: [_jsx(MarkerDefinitions, { rfId: rfId, defaultColor: defaultMarkerColor }), visible.map((stored) => {
|
|
1077
|
+
const edge = defaults ? { ...defaults, ...stored } : stored;
|
|
1078
|
+
const source = lookup.get(edge.source);
|
|
1079
|
+
const target = lookup.get(edge.target);
|
|
1080
|
+
if (edge.hidden || !source || !target)
|
|
1081
|
+
return null;
|
|
1082
|
+
const ends = edgePosition(source, target, edge.sourceHandle, edge.targetHandle, connectionMode);
|
|
1083
|
+
if (!ends)
|
|
1084
|
+
return null;
|
|
1085
|
+
const { from, to } = ends;
|
|
1086
|
+
// xyflow: an unknown type falls back to the default edge.
|
|
1087
|
+
const type = edge.type || "default";
|
|
1088
|
+
const Component = (edgeTypes?.[type] ?? BUILTIN_EDGES[type] ?? edgeTypes?.default ?? BUILTIN_EDGES.default);
|
|
1089
|
+
const selectable = Boolean(edge.selectable || (elementsSelectable && edge.selectable === undefined));
|
|
1090
|
+
const focusable = Boolean(edge.focusable || (edgesFocusable && edge.focusable === undefined));
|
|
1091
|
+
const copy = () => ({ ...edge });
|
|
1092
|
+
// xyflow's EdgeWrapper click: select it (⌘-click a selected one unselects it).
|
|
1093
|
+
const onClick = (event) => {
|
|
1094
|
+
const { addSelectedEdges, unselectNodesAndEdges, multiSelectionActive } = store.getState();
|
|
1095
|
+
if (selectable) {
|
|
1096
|
+
store.setState({ nodesSelectionActive: false });
|
|
1097
|
+
if (edge.selected && multiSelectionActive) {
|
|
1098
|
+
unselectNodesAndEdges({ nodes: [], edges: [edge] });
|
|
1099
|
+
event.currentTarget.blur();
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
addSelectedEdges([edge.id]);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
handlers.onClick?.(event, edge);
|
|
1106
|
+
};
|
|
1107
|
+
const onKeyDown = (event) => {
|
|
1108
|
+
if (disableKeyboardA11y || event.target !== event.currentTarget)
|
|
1109
|
+
return;
|
|
1110
|
+
if (!["Enter", " ", "Escape"].includes(event.key) || !selectable)
|
|
1111
|
+
return;
|
|
1112
|
+
event.preventDefault();
|
|
1113
|
+
event.stopPropagation();
|
|
1114
|
+
const { unselectNodesAndEdges, addSelectedEdges } = store.getState();
|
|
1115
|
+
if (event.key === "Escape") {
|
|
1116
|
+
event.currentTarget.blur();
|
|
1117
|
+
unselectNodesAndEdges({ edges: [edge] });
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
addSelectedEdges([edge.id]);
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
const className = [
|
|
1124
|
+
"avis-flow__edge",
|
|
1125
|
+
`avis-flow__edge-${edge.type ?? "default"}`,
|
|
1126
|
+
edge.className ?? "",
|
|
1127
|
+
noPanClassName,
|
|
1128
|
+
edge.selected ? "selected" : "",
|
|
1129
|
+
edge.animated ? "animated" : "",
|
|
1130
|
+
!selectable && !handlers.onClick ? "inactive" : "",
|
|
1131
|
+
selectable ? "selectable" : "",
|
|
1132
|
+
]
|
|
1133
|
+
.filter(Boolean)
|
|
1134
|
+
.join(" ");
|
|
1135
|
+
const sourceZ = zIndexMode === "auto" && source.parentId || (zIndexMode !== "manual" && elevateEdgesOnSelect && source.selected) ? source.internals.z : 0;
|
|
1136
|
+
const targetZ = zIndexMode === "auto" && target.parentId || (zIndexMode !== "manual" && elevateEdgesOnSelect && target.selected) ? target.internals.z : 0;
|
|
1137
|
+
const zIndex = (zIndexMode !== "manual" && elevateEdgesOnSelect && edge.selected ? (edge.zIndex ?? 0) + 1000 : (edge.zIndex ?? 0)) + Math.max(sourceZ, targetZ);
|
|
1138
|
+
const markerStart = edge.markerStart ? `url('#${markerId(edge.markerStart, rfId)}')` : undefined;
|
|
1139
|
+
const markerEnd = edge.markerEnd ? `url('#${markerId(edge.markerEnd, rfId)}')` : undefined;
|
|
1140
|
+
return (_jsx("svg", { style: { zIndex }, children: _jsxs("g", { className: className, "data-id": edge.id, "data-testid": `rf__edge-${edge.id}`, style: { zIndex: edge.zIndex }, onClick: onClick, onDoubleClick: handlers.onDoubleClick ? (event) => handlers.onDoubleClick?.(event, copy()) : undefined, onContextMenu: handlers.onContextMenu ? (event) => handlers.onContextMenu?.(event, copy()) : undefined, onMouseEnter: handlers.onMouseEnter ? (event) => handlers.onMouseEnter?.(event, copy()) : undefined, onMouseMove: handlers.onMouseMove ? (event) => handlers.onMouseMove?.(event, copy()) : undefined, onMouseLeave: handlers.onMouseLeave ? (event) => handlers.onMouseLeave?.(event, copy()) : undefined, onKeyDown: focusable ? onKeyDown : undefined, tabIndex: focusable ? 0 : undefined, role: edge.ariaRole ?? (focusable ? "group" : "img"), "aria-roledescription": "edge", "aria-label": edge.ariaLabel === null ? undefined : (edge.ariaLabel || `Edge from ${edge.source} to ${edge.target}`), "aria-describedby": focusable ? `avis-flow__edge-desc-${rfId}` : undefined, ...edge.domAttributes, children: [_jsx(Component, { id: edge.id, source: edge.source, target: edge.target, sourceHandleId: edge.sourceHandle ?? null, targetHandleId: edge.targetHandle ?? null, sourceX: from.x, sourceY: from.y, targetX: to.x, targetY: to.y, sourcePosition: from.position, targetPosition: to.position, data: edge.data, selected: Boolean(edge.selected), selectable: selectable, deletable: edge.deletable ?? true, animated: Boolean(edge.animated), style: edge.style, markerEnd: markerEnd, markerStart: markerStart, label: edge.label, labelStyle: edge.labelStyle, labelShowBg: edge.labelShowBg, labelBgStyle: edge.labelBgStyle, labelBgPadding: edge.labelBgPadding, labelBgBorderRadius: edge.labelBgBorderRadius, pathOptions: "pathOptions" in edge ? edge.pathOptions : undefined, interactionWidth: edge.interactionWidth, type: edge.type }), _jsx(EdgeReconnect, { edge: edge, from: from, to: to })] }) }, edge.id));
|
|
1141
|
+
})] }));
|
|
1142
|
+
}
|
|
1143
|
+
/** xyflow's getMarkerId: a marker object's id, from its sorted keys. */
|
|
1144
|
+
function markerId(marker, id) {
|
|
1145
|
+
if (!marker)
|
|
1146
|
+
return "";
|
|
1147
|
+
if (typeof marker === "string")
|
|
1148
|
+
return marker;
|
|
1149
|
+
return `${id ? `${id}__` : ""}${Object.keys(marker)
|
|
1150
|
+
.sort()
|
|
1151
|
+
.map((key) => `${key}=${marker[key]}`)
|
|
1152
|
+
.join("&")}`;
|
|
1153
|
+
}
|
|
1154
|
+
/** React Flow's MarkerDefinitions: one <marker> per distinct marker object on the edges. */
|
|
1155
|
+
function MarkerDefinitions({ rfId, defaultColor }) {
|
|
1156
|
+
const edges = useStore((s) => s.edges);
|
|
1157
|
+
const defaults = useStore((s) => s.defaultEdgeOptions);
|
|
1158
|
+
const markers = useMemo(() => {
|
|
1159
|
+
const ids = new Set();
|
|
1160
|
+
const out = [];
|
|
1161
|
+
for (const edge of edges) {
|
|
1162
|
+
for (const marker of [edge.markerStart || defaults?.markerStart, edge.markerEnd || defaults?.markerEnd]) {
|
|
1163
|
+
if (marker && typeof marker === "object") {
|
|
1164
|
+
const id = markerId(marker, rfId);
|
|
1165
|
+
if (!ids.has(id)) {
|
|
1166
|
+
out.push({ id, color: marker.color || defaultColor, ...marker });
|
|
1167
|
+
ids.add(id);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
1173
|
+
}, [edges, defaults, rfId, defaultColor]);
|
|
1174
|
+
if (!markers.length)
|
|
1175
|
+
return null;
|
|
1176
|
+
return (_jsx("svg", { className: "avis-flow__marker", "aria-hidden": "true", children: _jsx("defs", { children: markers.map(({ id, type, color, width = 12.5, height = 12.5, markerUnits = "strokeWidth", strokeWidth = 1, orient = "auto-start-reverse" }) => type === "arrow" || type === "arrowclosed" ? (_jsx("marker", { className: "avis-flow__arrowhead", id: id, markerWidth: `${width}`, markerHeight: `${height}`, viewBox: "-10 -10 20 20", markerUnits: markerUnits, orient: orient, refX: "0", refY: "0", children: _jsx("polyline", { className: type, style: { strokeWidth, ...(color ? (type === "arrow" ? { stroke: color } : { stroke: color, fill: color }) : {}) }, strokeLinecap: "round", strokeLinejoin: "round", fill: type === "arrow" ? "none" : undefined, points: type === "arrow" ? "-5,-4 0,0 -5,4" : "-5,-4 0,0 -5,4 -5,-4" }) }, id)) : null) }) }));
|
|
1177
|
+
}
|
|
1178
|
+
// ---- pan and zoom (React Flow's d3-zoom) --------------------------------------------
|
|
1179
|
+
const PANE_BLOCKERS = ".avis-flow__node, .avis-flow__panel, .avis-flow__node-toolbar, .avis-flow__handle, .avis-flow__resize-control, .avis-flow__minimap";
|
|
1180
|
+
function usePanZoom(store, rootRef, props) {
|
|
1181
|
+
const latest = useRef(props);
|
|
1182
|
+
useLayoutEffect(() => {
|
|
1183
|
+
latest.current = props;
|
|
1184
|
+
});
|
|
1185
|
+
useEffect(() => {
|
|
1186
|
+
const root = rootRef.current;
|
|
1187
|
+
if (!root)
|
|
1188
|
+
return;
|
|
1189
|
+
let space = false;
|
|
1190
|
+
let zoomKey = false;
|
|
1191
|
+
const blocked = (target) => target.closest(PANE_BLOCKERS) || hasClassWithin(target, store.getState().noPanClassName ?? "nopan", root);
|
|
1192
|
+
const touches = new Map();
|
|
1193
|
+
let pinch = null;
|
|
1194
|
+
const touchGeometry = () => {
|
|
1195
|
+
const [a, b] = [...touches.values()];
|
|
1196
|
+
return a && b ? { distance: Math.hypot(a.x - b.x, a.y - b.y), x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 } : null;
|
|
1197
|
+
};
|
|
1198
|
+
let pan = null;
|
|
1199
|
+
let suppressMenu = false;
|
|
1200
|
+
const panButtons = () => {
|
|
1201
|
+
const panOnDrag = latest.current.panOnDrag ?? true;
|
|
1202
|
+
if (panOnDrag === true)
|
|
1203
|
+
return [0, 1, 2];
|
|
1204
|
+
if (panOnDrag === false)
|
|
1205
|
+
return [];
|
|
1206
|
+
return panOnDrag;
|
|
1207
|
+
};
|
|
1208
|
+
const onWheel = (event) => {
|
|
1209
|
+
const target = event.target;
|
|
1210
|
+
if (!root.contains(target))
|
|
1211
|
+
return;
|
|
1212
|
+
if (hasClassWithin(target, store.getState().noWheelClassName ?? "nowheel", root)) {
|
|
1213
|
+
if (event.ctrlKey)
|
|
1214
|
+
event.preventDefault();
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const p = latest.current;
|
|
1218
|
+
const s = store.getState();
|
|
1219
|
+
const rect = root.getBoundingClientRect();
|
|
1220
|
+
const zoomGesture = event.ctrlKey || event.metaKey;
|
|
1221
|
+
if (!p.panOnScroll && p.preventScrolling === false && !zoomGesture)
|
|
1222
|
+
return;
|
|
1223
|
+
if (zoomGesture ? p.zoomOnPinch === false : !zoomKey && !p.panOnScroll && p.zoomOnScroll === false)
|
|
1224
|
+
return;
|
|
1225
|
+
event.preventDefault();
|
|
1226
|
+
const [tx, ty, k] = s.transform;
|
|
1227
|
+
if (!zoomGesture && !zoomKey && p.panOnScroll) {
|
|
1228
|
+
const normalize = event.deltaMode === 1 ? 20 : 1;
|
|
1229
|
+
let dx = event.deltaX * normalize;
|
|
1230
|
+
let dy = event.deltaY * normalize;
|
|
1231
|
+
if (!isMac && event.shiftKey) {
|
|
1232
|
+
dx = event.deltaY * normalize;
|
|
1233
|
+
dy = 0;
|
|
1234
|
+
}
|
|
1235
|
+
if (p.panOnScrollMode === "vertical")
|
|
1236
|
+
dx = 0;
|
|
1237
|
+
if (p.panOnScrollMode === "horizontal")
|
|
1238
|
+
dy = 0;
|
|
1239
|
+
const speed = p.panOnScrollSpeed ?? 0.5;
|
|
1240
|
+
s.setTransform([tx - dx * speed, ty - dy * speed, k], event);
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
// d3-zoom's wheel delta (pinches come as Ctrl + wheel).
|
|
1244
|
+
const delta = -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
|
|
1245
|
+
const zoom = Math.min(s.maxZoom, Math.max(s.minZoom, k * 2 ** delta));
|
|
1246
|
+
const px = event.clientX - rect.left;
|
|
1247
|
+
const py = event.clientY - rect.top;
|
|
1248
|
+
s.setTransform([px - ((px - tx) / k) * zoom, py - ((py - ty) / k) * zoom, zoom], event);
|
|
1249
|
+
};
|
|
1250
|
+
const onPointerDown = (event) => {
|
|
1251
|
+
const target = event.target;
|
|
1252
|
+
if (!root.contains(target) || blocked(target))
|
|
1253
|
+
return;
|
|
1254
|
+
if (event.pointerType === "touch") {
|
|
1255
|
+
touches.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1256
|
+
const geo = touchGeometry();
|
|
1257
|
+
if (geo && latest.current.zoomOnPinch !== false) {
|
|
1258
|
+
const rect = root.getBoundingClientRect(), [x, y, zoom] = store.getState().transform;
|
|
1259
|
+
pinch = { distance: geo.distance, zoom, worldX: (geo.x - rect.left - x) / zoom, worldY: (geo.y - rect.top - y) / zoom };
|
|
1260
|
+
pan = null;
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
if (!target.closest(".avis-flow__pane"))
|
|
1265
|
+
return;
|
|
1266
|
+
if (store.getState().selectionKeyPressed)
|
|
1267
|
+
return;
|
|
1268
|
+
const buttons = panButtons();
|
|
1269
|
+
const allowed = buttons.includes(event.button) || (space && event.button === 0);
|
|
1270
|
+
if (!allowed)
|
|
1271
|
+
return;
|
|
1272
|
+
// No pointer capture (d3-zoom takes none): other listeners, such as a
|
|
1273
|
+
// context menu trigger, still get the pointer's events.
|
|
1274
|
+
pan = { x: event.clientX, y: event.clientY, button: event.button, moved: false, pointerId: event.pointerId };
|
|
1275
|
+
};
|
|
1276
|
+
const onPointerMove = (event) => {
|
|
1277
|
+
if (touches.has(event.pointerId))
|
|
1278
|
+
touches.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
1279
|
+
const geo = pinch && touchGeometry();
|
|
1280
|
+
if (pinch && geo) {
|
|
1281
|
+
const rect = root.getBoundingClientRect(), state = store.getState();
|
|
1282
|
+
const zoom = Math.max(state.minZoom, Math.min(state.maxZoom, pinch.zoom * geo.distance / (pinch.distance || 1)));
|
|
1283
|
+
state.setTransform([geo.x - rect.left - pinch.worldX * zoom, geo.y - rect.top - pinch.worldY * zoom, zoom], event);
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (!pan || event.pointerId !== pan.pointerId)
|
|
1287
|
+
return;
|
|
1288
|
+
const dx = event.clientX - pan.x;
|
|
1289
|
+
const dy = event.clientY - pan.y;
|
|
1290
|
+
if (!dx && !dy)
|
|
1291
|
+
return;
|
|
1292
|
+
pan.x = event.clientX;
|
|
1293
|
+
pan.y = event.clientY;
|
|
1294
|
+
if (!pan.moved)
|
|
1295
|
+
store.setState({ paneDragging: true });
|
|
1296
|
+
pan.moved = true;
|
|
1297
|
+
store.getState().panBy({ x: dx, y: dy }, event);
|
|
1298
|
+
};
|
|
1299
|
+
const onPointerUp = (event) => {
|
|
1300
|
+
touches.delete(event.pointerId);
|
|
1301
|
+
if (touches.size < 2)
|
|
1302
|
+
pinch = null;
|
|
1303
|
+
if (!pan || event.pointerId !== pan.pointerId)
|
|
1304
|
+
return;
|
|
1305
|
+
if (pan.button === 2 && pan.moved)
|
|
1306
|
+
suppressMenu = true;
|
|
1307
|
+
// xyflow's pan-zoom end: a right press that pans (panOnDrag has 2) and
|
|
1308
|
+
// didn't move is the pane's context menu.
|
|
1309
|
+
const panOnDrag = latest.current.panOnDrag;
|
|
1310
|
+
if (pan.button === 2 && !pan.moved && Array.isArray(panOnDrag) && panOnDrag.includes(2)) {
|
|
1311
|
+
;
|
|
1312
|
+
store.getState().onPaneContextMenu?.(event);
|
|
1313
|
+
}
|
|
1314
|
+
if (pan.moved)
|
|
1315
|
+
store.setState({ paneDragging: false });
|
|
1316
|
+
pan = null;
|
|
1317
|
+
};
|
|
1318
|
+
const onContextMenu = (event) => {
|
|
1319
|
+
if (suppressMenu) {
|
|
1320
|
+
suppressMenu = false;
|
|
1321
|
+
event.preventDefault();
|
|
1322
|
+
event.stopPropagation();
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
const onDoubleClick = (event) => {
|
|
1326
|
+
const target = event.target;
|
|
1327
|
+
if (latest.current.zoomOnDoubleClick === false || blocked(target) || !target.closest(".avis-flow__pane"))
|
|
1328
|
+
return;
|
|
1329
|
+
const s = store.getState();
|
|
1330
|
+
const rect = root.getBoundingClientRect();
|
|
1331
|
+
const [tx, ty, k] = s.transform;
|
|
1332
|
+
const zoom = Math.min(s.maxZoom, Math.max(s.minZoom, k * (event.shiftKey ? 0.5 : 2)));
|
|
1333
|
+
const px = event.clientX - rect.left;
|
|
1334
|
+
const py = event.clientY - rect.top;
|
|
1335
|
+
s.setTransform([px - ((px - tx) / k) * zoom, py - ((py - ty) / k) * zoom, zoom], event);
|
|
1336
|
+
};
|
|
1337
|
+
const typing = (target) => {
|
|
1338
|
+
const el = target;
|
|
1339
|
+
return Boolean(el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName)));
|
|
1340
|
+
};
|
|
1341
|
+
const onKeyDown = (event) => {
|
|
1342
|
+
if (typing(event.target))
|
|
1343
|
+
return;
|
|
1344
|
+
if (latest.current.panActivationKeyCode !== null && keyList(latest.current.panActivationKeyCode, [" "]).some(k => k === event.key || k === event.code))
|
|
1345
|
+
space = true;
|
|
1346
|
+
if (keyList(latest.current.zoomActivationKeyCode, [isMac ? "Meta" : "Control"]).some(k => k === event.key || k === event.code))
|
|
1347
|
+
zoomKey = true;
|
|
1348
|
+
};
|
|
1349
|
+
const onKeyUp = (event) => {
|
|
1350
|
+
if (keyList(latest.current.panActivationKeyCode, [" "]).some(k => k === event.key || k === event.code))
|
|
1351
|
+
space = false;
|
|
1352
|
+
if (keyList(latest.current.zoomActivationKeyCode, [isMac ? "Meta" : "Control"]).some(k => k === event.key || k === event.code))
|
|
1353
|
+
zoomKey = false;
|
|
1354
|
+
};
|
|
1355
|
+
const reset = () => { space = false; zoomKey = false; pan = null; pinch = null; touches.clear(); store.setState({ paneDragging: false }); };
|
|
1356
|
+
window.addEventListener("blur", reset);
|
|
1357
|
+
root.addEventListener("wheel", onWheel, { passive: false });
|
|
1358
|
+
root.addEventListener("pointerdown", onPointerDown);
|
|
1359
|
+
window.addEventListener("pointermove", onPointerMove);
|
|
1360
|
+
window.addEventListener("pointerup", onPointerUp);
|
|
1361
|
+
window.addEventListener("pointercancel", onPointerUp);
|
|
1362
|
+
root.addEventListener("contextmenu", onContextMenu, true);
|
|
1363
|
+
root.addEventListener("dblclick", onDoubleClick);
|
|
1364
|
+
window.addEventListener("keydown", onKeyDown);
|
|
1365
|
+
window.addEventListener("keyup", onKeyUp);
|
|
1366
|
+
return () => {
|
|
1367
|
+
window.removeEventListener("blur", reset);
|
|
1368
|
+
root.removeEventListener("wheel", onWheel);
|
|
1369
|
+
root.removeEventListener("pointerdown", onPointerDown);
|
|
1370
|
+
window.removeEventListener("pointermove", onPointerMove);
|
|
1371
|
+
window.removeEventListener("pointerup", onPointerUp);
|
|
1372
|
+
window.removeEventListener("pointercancel", onPointerUp);
|
|
1373
|
+
root.removeEventListener("contextmenu", onContextMenu, true);
|
|
1374
|
+
root.removeEventListener("dblclick", onDoubleClick);
|
|
1375
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
1376
|
+
window.removeEventListener("keyup", onKeyUp);
|
|
1377
|
+
};
|
|
1378
|
+
}, [store, rootRef]);
|
|
1379
|
+
}
|
|
1380
|
+
// ---- keys: Delete and the multi-selection key ---------------------------------------
|
|
1381
|
+
const keyList = (value, fallback) => value === null ? [] : value === undefined ? fallback : Array.isArray(value) ? value : [value];
|
|
1382
|
+
function useKeys(store, instance, props) {
|
|
1383
|
+
const latest = useRef(props);
|
|
1384
|
+
useLayoutEffect(() => {
|
|
1385
|
+
latest.current = props;
|
|
1386
|
+
});
|
|
1387
|
+
useEffect(() => {
|
|
1388
|
+
const activate = (event) => {
|
|
1389
|
+
store.setState({ keyboardActive: !!store.getState().domNode?.contains(event.target) });
|
|
1390
|
+
};
|
|
1391
|
+
const typing = (target) => {
|
|
1392
|
+
const el = target;
|
|
1393
|
+
return Boolean(el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName) || el.closest?.(".nokey")));
|
|
1394
|
+
};
|
|
1395
|
+
const multiKeys = () => keyList(latest.current.multiSelectionKeyCode, [isMac ? "Meta" : "Control"]);
|
|
1396
|
+
const onKeyDown = (event) => {
|
|
1397
|
+
if (multiKeys().includes(event.key))
|
|
1398
|
+
store.setState({ multiSelectionActive: true });
|
|
1399
|
+
if (typing(event.target))
|
|
1400
|
+
return;
|
|
1401
|
+
const deleteKeys = keyList(latest.current.deleteKeyCode, ["Backspace"]);
|
|
1402
|
+
if (!deleteKeys.includes(event.key) || event.metaKey || event.ctrlKey || event.altKey)
|
|
1403
|
+
return;
|
|
1404
|
+
const s = store.getState();
|
|
1405
|
+
if (!s.domNode?.contains(event.target) && !s.keyboardActive)
|
|
1406
|
+
return;
|
|
1407
|
+
const nodes = s.nodes.filter((n) => n.selected);
|
|
1408
|
+
const edges = s.edges.filter((e) => e.selected);
|
|
1409
|
+
if (!nodes.length && !edges.length)
|
|
1410
|
+
return;
|
|
1411
|
+
void instance.deleteElements({ nodes, edges });
|
|
1412
|
+
store.setState({ nodesSelectionActive: false });
|
|
1413
|
+
};
|
|
1414
|
+
const onKeyUp = (event) => {
|
|
1415
|
+
if (multiKeys().includes(event.key))
|
|
1416
|
+
store.setState({ multiSelectionActive: false });
|
|
1417
|
+
};
|
|
1418
|
+
const onBlur = () => store.setState({ multiSelectionActive: false });
|
|
1419
|
+
window.addEventListener("keydown", onKeyDown);
|
|
1420
|
+
window.addEventListener("keyup", onKeyUp);
|
|
1421
|
+
window.addEventListener("blur", onBlur);
|
|
1422
|
+
window.addEventListener("pointerdown", activate, true);
|
|
1423
|
+
return () => {
|
|
1424
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
1425
|
+
window.removeEventListener("keyup", onKeyUp);
|
|
1426
|
+
window.removeEventListener("blur", onBlur);
|
|
1427
|
+
window.removeEventListener("pointerdown", activate, true);
|
|
1428
|
+
};
|
|
1429
|
+
}, [store, instance]);
|
|
1430
|
+
}
|
|
1431
|
+
const darkQuery = () => (typeof window !== "undefined" && window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null);
|
|
1432
|
+
/** React Flow's `colorMode` class on the root ("light" by default; "system" follows the OS). */
|
|
1433
|
+
function useColorModeClass(colorMode) {
|
|
1434
|
+
const [system, setSystem] = useState(() => (darkQuery()?.matches ? "dark" : "light"));
|
|
1435
|
+
useEffect(() => {
|
|
1436
|
+
if (colorMode !== "system")
|
|
1437
|
+
return;
|
|
1438
|
+
const query = darkQuery();
|
|
1439
|
+
const update = () => setSystem(query?.matches ? "dark" : "light");
|
|
1440
|
+
update();
|
|
1441
|
+
query?.addEventListener("change", update);
|
|
1442
|
+
return () => query?.removeEventListener("change", update);
|
|
1443
|
+
}, [colorMode]);
|
|
1444
|
+
return colorMode === "system" ? system : colorMode;
|
|
1445
|
+
}
|