@octanejs/xyflow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/package.json +69 -0
- package/src/additional-components/Background/Background.tsrx +144 -0
- package/src/additional-components/Background/Patterns.tsrx +32 -0
- package/src/additional-components/Background/index.tsrx +2 -0
- package/src/additional-components/Background/types.ts +60 -0
- package/src/additional-components/Controls/ControlButton.tsrx +34 -0
- package/src/additional-components/Controls/Controls.tsrx +148 -0
- package/src/additional-components/Controls/Icons/FitView.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Lock.tsrx +7 -0
- package/src/additional-components/Controls/Icons/Minus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Plus.tsrx +5 -0
- package/src/additional-components/Controls/Icons/Unlock.tsrx +7 -0
- package/src/additional-components/Controls/index.tsrx +3 -0
- package/src/additional-components/Controls/types.ts +68 -0
- package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +79 -0
- package/src/additional-components/EdgeToolbar/index.tsrx +2 -0
- package/src/additional-components/EdgeToolbar/types.ts +14 -0
- package/src/additional-components/MiniMap/MiniMap.tsrx +249 -0
- package/src/additional-components/MiniMap/MiniMapNode.tsrx +43 -0
- package/src/additional-components/MiniMap/MiniMapNodes.tsrx +136 -0
- package/src/additional-components/MiniMap/index.ts +3 -0
- package/src/additional-components/MiniMap/types.ts +139 -0
- package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +250 -0
- package/src/additional-components/NodeResizer/NodeResizer.tsrx +102 -0
- package/src/additional-components/NodeResizer/index.ts +4 -0
- package/src/additional-components/NodeResizer/types.ts +122 -0
- package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +141 -0
- package/src/additional-components/NodeToolbar/NodeToolbarPortal.tsrx +17 -0
- package/src/additional-components/NodeToolbar/index.tsrx +2 -0
- package/src/additional-components/NodeToolbar/types.ts +32 -0
- package/src/additional-components/index.ts +6 -0
- package/src/components/A11yDescriptions/index.tsrx +58 -0
- package/src/components/Attribution/index.tsrx +31 -0
- package/src/components/BatchProvider/index.tsrx +122 -0
- package/src/components/BatchProvider/types.ts +7 -0
- package/src/components/BatchProvider/useQueue.ts +62 -0
- package/src/components/ConnectionLine/index.tsrx +140 -0
- package/src/components/EdgeLabelRenderer/index.tsrx +62 -0
- package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +151 -0
- package/src/components/EdgeWrapper/index.tsrx +274 -0
- package/src/components/EdgeWrapper/utils.ts +26 -0
- package/src/components/Edges/BaseEdge.tsrx +76 -0
- package/src/components/Edges/BezierEdge.tsrx +94 -0
- package/src/components/Edges/EdgeAnchor.tsrx +54 -0
- package/src/components/Edges/EdgeText.tsrx +97 -0
- package/src/components/Edges/SimpleBezierEdge.tsrx +150 -0
- package/src/components/Edges/SmoothStepEdge.tsrx +96 -0
- package/src/components/Edges/StepEdge.tsrx +55 -0
- package/src/components/Edges/StraightEdge.tsrx +81 -0
- package/src/components/Edges/index.ts +11 -0
- package/src/components/Handle/index.tsrx +314 -0
- package/src/components/NodeWrapper/index.tsrx +259 -0
- package/src/components/NodeWrapper/useNodeObserver.ts +79 -0
- package/src/components/NodeWrapper/utils.tsrx +40 -0
- package/src/components/Nodes/DefaultNode.tsrx +17 -0
- package/src/components/Nodes/GroupNode.tsrx +3 -0
- package/src/components/Nodes/InputNode.tsrx +13 -0
- package/src/components/Nodes/OutputNode.tsrx +13 -0
- package/src/components/Nodes/utils.ts +45 -0
- package/src/components/NodesSelection/index.tsrx +103 -0
- package/src/components/Panel/index.tsrx +34 -0
- package/src/components/ReactFlowProvider/index.tsrx +128 -0
- package/src/components/SelectionListener/index.tsrx +73 -0
- package/src/components/StoreUpdater/index.tsrx +173 -0
- package/src/components/UserSelection/index.tsrx +27 -0
- package/src/components/ViewportPortal/index.tsrx +42 -0
- package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +87 -0
- package/src/container/EdgeRenderer/MarkerSymbols.tsrx +60 -0
- package/src/container/EdgeRenderer/index.tsrx +98 -0
- package/src/container/FlowRenderer/index.tsrx +146 -0
- package/src/container/GraphView/index.tsrx +212 -0
- package/src/container/GraphView/useNodeOrEdgeTypesWarning.ts +39 -0
- package/src/container/GraphView/useStylesLoadedWarning.ts +26 -0
- package/src/container/NodeRenderer/index.tsrx +103 -0
- package/src/container/NodeRenderer/useResizeObserver.ts +38 -0
- package/src/container/Pane/index.tsrx +397 -0
- package/src/container/ReactFlow/Wrapper.tsrx +66 -0
- package/src/container/ReactFlow/index.tsrx +352 -0
- package/src/container/ReactFlow/init-values.ts +4 -0
- package/src/container/Viewport/index.tsrx +52 -0
- package/src/container/ZoomPane/index.tsrx +159 -0
- package/src/contexts/HandleConfigContext.tsrx +38 -0
- package/src/contexts/NodeIdContext.ts +39 -0
- package/src/contexts/StoreContext.ts +8 -0
- package/src/custom.d.ts +13 -0
- package/src/hooks/slot.ts +22 -0
- package/src/hooks/useColorModeClass.ts +50 -0
- package/src/hooks/useConnection.ts +69 -0
- package/src/hooks/useDrag.ts +95 -0
- package/src/hooks/useEdges.ts +32 -0
- package/src/hooks/useGlobalKeyHandler.ts +55 -0
- package/src/hooks/useHandleConnections.ts +77 -0
- package/src/hooks/useInternalNode.ts +47 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +5 -0
- package/src/hooks/useKeyPress.ts +217 -0
- package/src/hooks/useMoveSelectedNodes.ts +82 -0
- package/src/hooks/useNodeConnections.ts +86 -0
- package/src/hooks/useNodes.ts +33 -0
- package/src/hooks/useNodesData.ts +66 -0
- package/src/hooks/useNodesEdgesState.ts +138 -0
- package/src/hooks/useNodesInitialized.ts +74 -0
- package/src/hooks/useOnEdgesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnInitHandler.ts +27 -0
- package/src/hooks/useOnNodesChangeMiddleware.ts +46 -0
- package/src/hooks/useOnSelectionChange.ts +78 -0
- package/src/hooks/useOnViewportChange.ts +68 -0
- package/src/hooks/useReactFlow.ts +347 -0
- package/src/hooks/useResizeHandler.ts +54 -0
- package/src/hooks/useStore.ts +58 -0
- package/src/hooks/useUpdateNodeInternals.ts +73 -0
- package/src/hooks/useViewport.ts +48 -0
- package/src/hooks/useViewportHelper.ts +103 -0
- package/src/hooks/useViewportSync.ts +33 -0
- package/src/hooks/useVisibleEdgeIds.ts +52 -0
- package/src/hooks/useVisibleNodeIds.ts +36 -0
- package/src/index.ts +151 -0
- package/src/react-shim.ts +93 -0
- package/src/store/index.ts +516 -0
- package/src/store/initialState.ts +162 -0
- package/src/styles/base.css +516 -0
- package/src/styles/style.css +648 -0
- package/src/styles/utils.ts +9 -0
- package/src/types/component-props.ts +716 -0
- package/src/types/edges.ts +312 -0
- package/src/types/general.ts +239 -0
- package/src/types/index.ts +6 -0
- package/src/types/instance.ts +265 -0
- package/src/types/nodes.ts +144 -0
- package/src/types/store.ts +198 -0
- package/src/utils/changes.ts +329 -0
- package/src/utils/edges.ts +34 -0
- package/src/utils/general.ts +72 -0
- package/src/utils/index.ts +3 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { memo, type OctaneNode } from 'octane';
|
|
2
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
3
|
+
|
|
4
|
+
import { useStore } from '../../hooks/useStore';
|
|
5
|
+
import { useGlobalKeyHandler } from '../../hooks/useGlobalKeyHandler';
|
|
6
|
+
import { useKeyPress } from '../../hooks/useKeyPress';
|
|
7
|
+
import { GraphViewProps } from '../GraphView/index.tsrx';
|
|
8
|
+
import { ZoomPane } from '../ZoomPane/index.tsrx';
|
|
9
|
+
import { Pane } from '../Pane/index.tsrx';
|
|
10
|
+
import { NodesSelection } from '../../components/NodesSelection/index.tsrx';
|
|
11
|
+
import type { ReactFlowState, Node } from '../../types';
|
|
12
|
+
|
|
13
|
+
export type FlowRendererProps<NodeType extends Node = Node> =
|
|
14
|
+
Omit<
|
|
15
|
+
GraphViewProps<NodeType>,
|
|
16
|
+
| 'snapToGrid'
|
|
17
|
+
| 'nodeTypes'
|
|
18
|
+
| 'edgeTypes'
|
|
19
|
+
| 'snapGrid'
|
|
20
|
+
| 'connectionLineType'
|
|
21
|
+
| 'connectionLineContainerStyle'
|
|
22
|
+
| 'arrowHeadColor'
|
|
23
|
+
| 'onlyRenderVisibleElements'
|
|
24
|
+
| 'selectNodesOnDrag'
|
|
25
|
+
| 'defaultMarkerColor'
|
|
26
|
+
| 'rfId'
|
|
27
|
+
| 'nodeClickDistance'
|
|
28
|
+
> & {
|
|
29
|
+
isControlledViewport: boolean;
|
|
30
|
+
children: OctaneNode;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const win =
|
|
34
|
+
typeof window !== 'undefined' ? window : undefined;
|
|
35
|
+
|
|
36
|
+
const selector = (s: ReactFlowState) => {
|
|
37
|
+
return {
|
|
38
|
+
nodesSelectionActive: s.nodesSelectionActive,
|
|
39
|
+
userSelectionActive: s.userSelectionActive,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function FlowRendererComponent<NodeType extends Node = Node>({
|
|
44
|
+
children,
|
|
45
|
+
onPaneClick,
|
|
46
|
+
onPaneMouseEnter,
|
|
47
|
+
onPaneMouseMove,
|
|
48
|
+
onPaneMouseLeave,
|
|
49
|
+
onPaneContextMenu,
|
|
50
|
+
onPaneScroll,
|
|
51
|
+
paneClickDistance,
|
|
52
|
+
deleteKeyCode,
|
|
53
|
+
selectionKeyCode,
|
|
54
|
+
selectionOnDrag,
|
|
55
|
+
selectionMode,
|
|
56
|
+
onSelectionStart,
|
|
57
|
+
onSelectionEnd,
|
|
58
|
+
multiSelectionKeyCode,
|
|
59
|
+
panActivationKeyCode,
|
|
60
|
+
zoomActivationKeyCode,
|
|
61
|
+
elementsSelectable,
|
|
62
|
+
zoomOnScroll,
|
|
63
|
+
zoomOnPinch,
|
|
64
|
+
panOnScroll: _panOnScroll,
|
|
65
|
+
panOnScrollSpeed,
|
|
66
|
+
panOnScrollMode,
|
|
67
|
+
zoomOnDoubleClick,
|
|
68
|
+
panOnDrag: _panOnDrag,
|
|
69
|
+
autoPanOnSelection,
|
|
70
|
+
defaultViewport,
|
|
71
|
+
translateExtent,
|
|
72
|
+
minZoom,
|
|
73
|
+
maxZoom,
|
|
74
|
+
preventScrolling,
|
|
75
|
+
onSelectionContextMenu,
|
|
76
|
+
noWheelClassName,
|
|
77
|
+
noPanClassName,
|
|
78
|
+
disableKeyboardA11y,
|
|
79
|
+
onViewportChange,
|
|
80
|
+
isControlledViewport,
|
|
81
|
+
}: FlowRendererProps<NodeType>) {
|
|
82
|
+
const { nodesSelectionActive, userSelectionActive } = useStore(selector, shallow);
|
|
83
|
+
const selectionKeyPressed = useKeyPress(selectionKeyCode, { target: win });
|
|
84
|
+
const panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: win });
|
|
85
|
+
|
|
86
|
+
const panOnDrag = panActivationKeyPressed || _panOnDrag;
|
|
87
|
+
const panOnScroll = panActivationKeyPressed || _panOnScroll;
|
|
88
|
+
const _selectionOnDrag = selectionOnDrag && panOnDrag !== true;
|
|
89
|
+
const isSelecting = selectionKeyPressed || userSelectionActive || _selectionOnDrag;
|
|
90
|
+
|
|
91
|
+
useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode });
|
|
92
|
+
|
|
93
|
+
return <ZoomPane
|
|
94
|
+
onPaneContextMenu={onPaneContextMenu}
|
|
95
|
+
elementsSelectable={elementsSelectable}
|
|
96
|
+
zoomOnScroll={zoomOnScroll}
|
|
97
|
+
zoomOnPinch={zoomOnPinch}
|
|
98
|
+
panOnScroll={panOnScroll}
|
|
99
|
+
panOnScrollSpeed={panOnScrollSpeed}
|
|
100
|
+
panOnScrollMode={panOnScrollMode}
|
|
101
|
+
zoomOnDoubleClick={zoomOnDoubleClick}
|
|
102
|
+
panOnDrag={!selectionKeyPressed && panOnDrag}
|
|
103
|
+
defaultViewport={defaultViewport}
|
|
104
|
+
translateExtent={translateExtent}
|
|
105
|
+
minZoom={minZoom}
|
|
106
|
+
maxZoom={maxZoom}
|
|
107
|
+
zoomActivationKeyCode={zoomActivationKeyCode}
|
|
108
|
+
preventScrolling={preventScrolling}
|
|
109
|
+
noWheelClassName={noWheelClassName}
|
|
110
|
+
noPanClassName={noPanClassName}
|
|
111
|
+
onViewportChange={onViewportChange}
|
|
112
|
+
isControlledViewport={isControlledViewport}
|
|
113
|
+
paneClickDistance={paneClickDistance}
|
|
114
|
+
selectionOnDrag={_selectionOnDrag}
|
|
115
|
+
>
|
|
116
|
+
<Pane
|
|
117
|
+
onSelectionStart={onSelectionStart}
|
|
118
|
+
onSelectionEnd={onSelectionEnd}
|
|
119
|
+
onPaneClick={onPaneClick}
|
|
120
|
+
onPaneMouseEnter={onPaneMouseEnter}
|
|
121
|
+
onPaneMouseMove={onPaneMouseMove}
|
|
122
|
+
onPaneMouseLeave={onPaneMouseLeave}
|
|
123
|
+
onPaneContextMenu={onPaneContextMenu}
|
|
124
|
+
onPaneScroll={onPaneScroll}
|
|
125
|
+
panOnDrag={panOnDrag}
|
|
126
|
+
autoPanOnSelection={autoPanOnSelection}
|
|
127
|
+
isSelecting={!!isSelecting}
|
|
128
|
+
selectionMode={selectionMode}
|
|
129
|
+
selectionKeyPressed={selectionKeyPressed}
|
|
130
|
+
paneClickDistance={paneClickDistance}
|
|
131
|
+
selectionOnDrag={_selectionOnDrag}
|
|
132
|
+
>
|
|
133
|
+
{children}
|
|
134
|
+
{nodesSelectionActive &&
|
|
135
|
+
<NodesSelection
|
|
136
|
+
onSelectionContextMenu={onSelectionContextMenu}
|
|
137
|
+
noPanClassName={noPanClassName}
|
|
138
|
+
disableKeyboardA11y={disableKeyboardA11y}
|
|
139
|
+
/>}
|
|
140
|
+
</Pane>
|
|
141
|
+
</ZoomPane>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
FlowRendererComponent.displayName = 'FlowRenderer';
|
|
145
|
+
|
|
146
|
+
export const FlowRenderer = memo(FlowRendererComponent) as typeof FlowRendererComponent;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { memo } from 'octane';
|
|
2
|
+
|
|
3
|
+
import { FlowRenderer } from '../FlowRenderer/index.tsrx';
|
|
4
|
+
import { NodeRenderer } from '../NodeRenderer/index.tsrx';
|
|
5
|
+
import { EdgeRenderer } from '../EdgeRenderer/index.tsrx';
|
|
6
|
+
import { Viewport } from '../Viewport/index.tsrx';
|
|
7
|
+
import { useOnInitHandler } from '../../hooks/useOnInitHandler';
|
|
8
|
+
import { useViewportSync } from '../../hooks/useViewportSync';
|
|
9
|
+
import { ConnectionLineWrapper } from '../../components/ConnectionLine/index.tsrx';
|
|
10
|
+
import { useNodeOrEdgeTypesWarning } from './useNodeOrEdgeTypesWarning';
|
|
11
|
+
import type { Edge, Node, ReactFlowProps } from '../../types';
|
|
12
|
+
import { useStylesLoadedWarning } from './useStylesLoadedWarning';
|
|
13
|
+
|
|
14
|
+
export type GraphViewProps<NodeType extends Node = Node, EdgeType extends Edge = Edge> =
|
|
15
|
+
Omit<
|
|
16
|
+
ReactFlowProps<NodeType, EdgeType>,
|
|
17
|
+
| 'onSelectionChange'
|
|
18
|
+
| 'nodes'
|
|
19
|
+
| 'edges'
|
|
20
|
+
| 'onMove'
|
|
21
|
+
| 'onMoveStart'
|
|
22
|
+
| 'onMoveEnd'
|
|
23
|
+
| 'elevateEdgesOnSelect'
|
|
24
|
+
> & Required<
|
|
25
|
+
Pick<
|
|
26
|
+
ReactFlowProps<NodeType, EdgeType>,
|
|
27
|
+
| 'selectionKeyCode'
|
|
28
|
+
| 'deleteKeyCode'
|
|
29
|
+
| 'multiSelectionKeyCode'
|
|
30
|
+
| 'connectionLineType'
|
|
31
|
+
| 'onlyRenderVisibleElements'
|
|
32
|
+
| 'translateExtent'
|
|
33
|
+
| 'minZoom'
|
|
34
|
+
| 'maxZoom'
|
|
35
|
+
| 'defaultMarkerColor'
|
|
36
|
+
| 'noDragClassName'
|
|
37
|
+
| 'noWheelClassName'
|
|
38
|
+
| 'noPanClassName'
|
|
39
|
+
| 'defaultViewport'
|
|
40
|
+
| 'disableKeyboardA11y'
|
|
41
|
+
| 'paneClickDistance'
|
|
42
|
+
| 'nodeClickDistance'
|
|
43
|
+
>
|
|
44
|
+
> & {
|
|
45
|
+
rfId: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function GraphViewComponent<NodeType extends Node = Node, EdgeType extends Edge = Edge>({
|
|
49
|
+
nodeTypes,
|
|
50
|
+
edgeTypes,
|
|
51
|
+
onInit,
|
|
52
|
+
onNodeClick,
|
|
53
|
+
onEdgeClick,
|
|
54
|
+
onNodeDoubleClick,
|
|
55
|
+
onEdgeDoubleClick,
|
|
56
|
+
onNodeMouseEnter,
|
|
57
|
+
onNodeMouseMove,
|
|
58
|
+
onNodeMouseLeave,
|
|
59
|
+
onNodeContextMenu,
|
|
60
|
+
onSelectionContextMenu,
|
|
61
|
+
onSelectionStart,
|
|
62
|
+
onSelectionEnd,
|
|
63
|
+
connectionLineType,
|
|
64
|
+
connectionLineStyle,
|
|
65
|
+
connectionLineComponent,
|
|
66
|
+
connectionLineContainerStyle,
|
|
67
|
+
selectionKeyCode,
|
|
68
|
+
selectionOnDrag,
|
|
69
|
+
selectionMode,
|
|
70
|
+
multiSelectionKeyCode,
|
|
71
|
+
panActivationKeyCode,
|
|
72
|
+
zoomActivationKeyCode,
|
|
73
|
+
deleteKeyCode,
|
|
74
|
+
onlyRenderVisibleElements,
|
|
75
|
+
elementsSelectable,
|
|
76
|
+
defaultViewport,
|
|
77
|
+
translateExtent,
|
|
78
|
+
minZoom,
|
|
79
|
+
maxZoom,
|
|
80
|
+
preventScrolling,
|
|
81
|
+
defaultMarkerColor,
|
|
82
|
+
zoomOnScroll,
|
|
83
|
+
zoomOnPinch,
|
|
84
|
+
panOnScroll,
|
|
85
|
+
panOnScrollSpeed,
|
|
86
|
+
panOnScrollMode,
|
|
87
|
+
zoomOnDoubleClick,
|
|
88
|
+
panOnDrag,
|
|
89
|
+
autoPanOnSelection,
|
|
90
|
+
onPaneClick,
|
|
91
|
+
onPaneMouseEnter,
|
|
92
|
+
onPaneMouseMove,
|
|
93
|
+
onPaneMouseLeave,
|
|
94
|
+
onPaneScroll,
|
|
95
|
+
onPaneContextMenu,
|
|
96
|
+
paneClickDistance,
|
|
97
|
+
nodeClickDistance,
|
|
98
|
+
onEdgeContextMenu,
|
|
99
|
+
onEdgeMouseEnter,
|
|
100
|
+
onEdgeMouseMove,
|
|
101
|
+
onEdgeMouseLeave,
|
|
102
|
+
reconnectRadius,
|
|
103
|
+
onReconnect,
|
|
104
|
+
onReconnectStart,
|
|
105
|
+
onReconnectEnd,
|
|
106
|
+
noDragClassName,
|
|
107
|
+
noWheelClassName,
|
|
108
|
+
noPanClassName,
|
|
109
|
+
disableKeyboardA11y,
|
|
110
|
+
nodeExtent,
|
|
111
|
+
rfId,
|
|
112
|
+
viewport,
|
|
113
|
+
onViewportChange,
|
|
114
|
+
nodesDraggable,
|
|
115
|
+
}: GraphViewProps<NodeType, EdgeType>) {
|
|
116
|
+
useNodeOrEdgeTypesWarning(nodeTypes);
|
|
117
|
+
useNodeOrEdgeTypesWarning(edgeTypes);
|
|
118
|
+
useStylesLoadedWarning();
|
|
119
|
+
|
|
120
|
+
useOnInitHandler(onInit);
|
|
121
|
+
useViewportSync(viewport);
|
|
122
|
+
|
|
123
|
+
return <FlowRenderer
|
|
124
|
+
onPaneClick={onPaneClick}
|
|
125
|
+
onPaneMouseEnter={onPaneMouseEnter}
|
|
126
|
+
onPaneMouseMove={onPaneMouseMove}
|
|
127
|
+
onPaneMouseLeave={onPaneMouseLeave}
|
|
128
|
+
onPaneContextMenu={onPaneContextMenu}
|
|
129
|
+
onPaneScroll={onPaneScroll}
|
|
130
|
+
paneClickDistance={paneClickDistance}
|
|
131
|
+
deleteKeyCode={deleteKeyCode}
|
|
132
|
+
selectionKeyCode={selectionKeyCode}
|
|
133
|
+
selectionOnDrag={selectionOnDrag}
|
|
134
|
+
selectionMode={selectionMode}
|
|
135
|
+
onSelectionStart={onSelectionStart}
|
|
136
|
+
onSelectionEnd={onSelectionEnd}
|
|
137
|
+
multiSelectionKeyCode={multiSelectionKeyCode}
|
|
138
|
+
panActivationKeyCode={panActivationKeyCode}
|
|
139
|
+
zoomActivationKeyCode={zoomActivationKeyCode}
|
|
140
|
+
elementsSelectable={elementsSelectable}
|
|
141
|
+
zoomOnScroll={zoomOnScroll}
|
|
142
|
+
zoomOnPinch={zoomOnPinch}
|
|
143
|
+
zoomOnDoubleClick={zoomOnDoubleClick}
|
|
144
|
+
panOnScroll={panOnScroll}
|
|
145
|
+
panOnScrollSpeed={panOnScrollSpeed}
|
|
146
|
+
panOnScrollMode={panOnScrollMode}
|
|
147
|
+
panOnDrag={panOnDrag}
|
|
148
|
+
autoPanOnSelection={autoPanOnSelection}
|
|
149
|
+
defaultViewport={defaultViewport}
|
|
150
|
+
translateExtent={translateExtent}
|
|
151
|
+
minZoom={minZoom}
|
|
152
|
+
maxZoom={maxZoom}
|
|
153
|
+
onSelectionContextMenu={onSelectionContextMenu}
|
|
154
|
+
preventScrolling={preventScrolling}
|
|
155
|
+
noDragClassName={noDragClassName}
|
|
156
|
+
noWheelClassName={noWheelClassName}
|
|
157
|
+
noPanClassName={noPanClassName}
|
|
158
|
+
disableKeyboardA11y={disableKeyboardA11y}
|
|
159
|
+
onViewportChange={onViewportChange}
|
|
160
|
+
isControlledViewport={!!viewport}
|
|
161
|
+
>
|
|
162
|
+
<Viewport>
|
|
163
|
+
<EdgeRenderer
|
|
164
|
+
edgeTypes={edgeTypes}
|
|
165
|
+
onEdgeClick={onEdgeClick}
|
|
166
|
+
onEdgeDoubleClick={onEdgeDoubleClick}
|
|
167
|
+
onReconnect={onReconnect}
|
|
168
|
+
onReconnectStart={onReconnectStart}
|
|
169
|
+
onReconnectEnd={onReconnectEnd}
|
|
170
|
+
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
|
171
|
+
onEdgeContextMenu={onEdgeContextMenu}
|
|
172
|
+
onEdgeMouseEnter={onEdgeMouseEnter}
|
|
173
|
+
onEdgeMouseMove={onEdgeMouseMove}
|
|
174
|
+
onEdgeMouseLeave={onEdgeMouseLeave}
|
|
175
|
+
reconnectRadius={reconnectRadius}
|
|
176
|
+
defaultMarkerColor={defaultMarkerColor}
|
|
177
|
+
noPanClassName={noPanClassName}
|
|
178
|
+
disableKeyboardA11y={disableKeyboardA11y}
|
|
179
|
+
rfId={rfId}
|
|
180
|
+
/>
|
|
181
|
+
<ConnectionLineWrapper
|
|
182
|
+
style={connectionLineStyle}
|
|
183
|
+
type={connectionLineType}
|
|
184
|
+
component={connectionLineComponent}
|
|
185
|
+
containerStyle={connectionLineContainerStyle}
|
|
186
|
+
/>
|
|
187
|
+
<div className="react-flow__edgelabel-renderer" />
|
|
188
|
+
<NodeRenderer
|
|
189
|
+
nodeTypes={nodeTypes}
|
|
190
|
+
onNodeClick={onNodeClick}
|
|
191
|
+
onNodeDoubleClick={onNodeDoubleClick}
|
|
192
|
+
onNodeMouseEnter={onNodeMouseEnter}
|
|
193
|
+
onNodeMouseMove={onNodeMouseMove}
|
|
194
|
+
onNodeMouseLeave={onNodeMouseLeave}
|
|
195
|
+
onNodeContextMenu={onNodeContextMenu}
|
|
196
|
+
nodeClickDistance={nodeClickDistance}
|
|
197
|
+
onlyRenderVisibleElements={onlyRenderVisibleElements}
|
|
198
|
+
noPanClassName={noPanClassName}
|
|
199
|
+
noDragClassName={noDragClassName}
|
|
200
|
+
disableKeyboardA11y={disableKeyboardA11y}
|
|
201
|
+
nodeExtent={nodeExtent}
|
|
202
|
+
rfId={rfId}
|
|
203
|
+
nodesDraggable={nodesDraggable}
|
|
204
|
+
/>
|
|
205
|
+
<div className="react-flow__viewport-portal" />
|
|
206
|
+
</Viewport>
|
|
207
|
+
</FlowRenderer>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
GraphViewComponent.displayName = 'GraphView';
|
|
211
|
+
|
|
212
|
+
export const GraphView = memo(GraphViewComponent) as typeof GraphViewComponent;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'octane';
|
|
2
|
+
import { errorMessages } from '@xyflow/system';
|
|
3
|
+
|
|
4
|
+
import { useStoreApi } from '../../hooks/useStore';
|
|
5
|
+
import type { EdgeTypes, NodeTypes } from '../../types';
|
|
6
|
+
|
|
7
|
+
// Kept module-local so browser consumers do not need `@types/node`.
|
|
8
|
+
declare const process: { env: { NODE_ENV?: string } };
|
|
9
|
+
|
|
10
|
+
const emptyTypes = {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This hook warns the user if nodeTypes or edgeTypes changed.
|
|
14
|
+
* It is only used in development mode.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function useNodeOrEdgeTypesWarning(nodeOrEdgeTypes?: NodeTypes): void;
|
|
19
|
+
export function useNodeOrEdgeTypesWarning(nodeOrEdgeTypes?: EdgeTypes): void;
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
export function useNodeOrEdgeTypesWarning(nodeOrEdgeTypes: any = emptyTypes): any {
|
|
22
|
+
const typesRef = useRef(nodeOrEdgeTypes);
|
|
23
|
+
const store = useStoreApi();
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (process.env.NODE_ENV === 'development') {
|
|
27
|
+
const usedKeys = new Set([...Object.keys(typesRef.current), ...Object.keys(nodeOrEdgeTypes)]);
|
|
28
|
+
|
|
29
|
+
for (const key of usedKeys) {
|
|
30
|
+
if (typesRef.current[key] !== nodeOrEdgeTypes[key]) {
|
|
31
|
+
store.getState().onError?.('002', errorMessages['error002']());
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
typesRef.current = nodeOrEdgeTypes;
|
|
37
|
+
}
|
|
38
|
+
}, [nodeOrEdgeTypes]);
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'octane';
|
|
2
|
+
import { errorMessages } from '@xyflow/system';
|
|
3
|
+
|
|
4
|
+
import { useStoreApi } from '../../hooks/useStore';
|
|
5
|
+
|
|
6
|
+
// Kept module-local so browser consumers do not need `@types/node`.
|
|
7
|
+
declare const process: { env: { NODE_ENV?: string } };
|
|
8
|
+
|
|
9
|
+
export function useStylesLoadedWarning() {
|
|
10
|
+
const store = useStoreApi();
|
|
11
|
+
const checked = useRef(false);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (process.env.NODE_ENV === 'development') {
|
|
15
|
+
if (!checked.current) {
|
|
16
|
+
const pane = document.querySelector('.react-flow__pane');
|
|
17
|
+
|
|
18
|
+
if (pane && !(window.getComputedStyle(pane).zIndex === '1')) {
|
|
19
|
+
store.getState().onError?.('013', errorMessages['error013']('react'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
checked.current = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, []);
|
|
26
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { memo } from 'octane';
|
|
2
|
+
import { shallow } from '@octanejs/zustand/shallow';
|
|
3
|
+
|
|
4
|
+
import { useVisibleNodeIds } from '../../hooks/useVisibleNodeIds';
|
|
5
|
+
import { useStore } from '../../hooks/useStore';
|
|
6
|
+
import { containerStyle } from '../../styles/utils';
|
|
7
|
+
import { GraphViewProps } from '../GraphView/index.tsrx';
|
|
8
|
+
import { useResizeObserver } from './useResizeObserver';
|
|
9
|
+
import NodeWrapper from '../../components/NodeWrapper/index.tsrx';
|
|
10
|
+
import type { Node, ReactFlowState } from '../../types';
|
|
11
|
+
|
|
12
|
+
export type NodeRendererProps<NodeType extends Node> =
|
|
13
|
+
Pick<
|
|
14
|
+
GraphViewProps<NodeType>,
|
|
15
|
+
| 'onNodeClick'
|
|
16
|
+
| 'onNodeDoubleClick'
|
|
17
|
+
| 'onNodeMouseEnter'
|
|
18
|
+
| 'onNodeMouseMove'
|
|
19
|
+
| 'onNodeMouseLeave'
|
|
20
|
+
| 'onNodeContextMenu'
|
|
21
|
+
| 'onlyRenderVisibleElements'
|
|
22
|
+
| 'noPanClassName'
|
|
23
|
+
| 'noDragClassName'
|
|
24
|
+
| 'rfId'
|
|
25
|
+
| 'disableKeyboardA11y'
|
|
26
|
+
| 'nodeExtent'
|
|
27
|
+
| 'nodeTypes'
|
|
28
|
+
| 'nodeClickDistance'
|
|
29
|
+
| 'nodesDraggable'
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
const selector = (s: ReactFlowState) => ({
|
|
33
|
+
nodesConnectable: s.nodesConnectable,
|
|
34
|
+
nodesFocusable: s.nodesFocusable,
|
|
35
|
+
elementsSelectable: s.elementsSelectable,
|
|
36
|
+
onError: s.onError,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function NodeRendererComponent<NodeType extends Node>(props: NodeRendererProps<NodeType>) {
|
|
40
|
+
const { nodesConnectable, nodesFocusable, elementsSelectable, onError } = useStore(
|
|
41
|
+
selector,
|
|
42
|
+
shallow,
|
|
43
|
+
);
|
|
44
|
+
const nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements);
|
|
45
|
+
const resizeObserver = useResizeObserver();
|
|
46
|
+
|
|
47
|
+
return <div className="react-flow__nodes" style={containerStyle}>{nodeIds.map((nodeId) => {
|
|
48
|
+
return (
|
|
49
|
+
/*
|
|
50
|
+
* The split of responsibilities between NodeRenderer and
|
|
51
|
+
* NodeComponentWrapper may appear weird. However, it’s designed to
|
|
52
|
+
* minimize the cost of updates when individual nodes change.
|
|
53
|
+
*
|
|
54
|
+
* For example, when you’re dragging a single node, that node gets
|
|
55
|
+
* updated multiple times per second. If `NodeRenderer` were to update
|
|
56
|
+
* every time, it would have to re-run the `nodes.map()` loop every
|
|
57
|
+
* time. This gets pricey with hundreds of nodes, especially if every
|
|
58
|
+
* loop cycle does more than just rendering a JSX element!
|
|
59
|
+
*
|
|
60
|
+
* As a result of this choice, we took the following implementation
|
|
61
|
+
* decisions:
|
|
62
|
+
* - NodeRenderer subscribes *only* to node IDs – and therefore
|
|
63
|
+
* rerender *only* when visible nodes are added or removed.
|
|
64
|
+
* - NodeRenderer performs all operations the result of which can be
|
|
65
|
+
* shared between nodes (such as creating the `ResizeObserver`
|
|
66
|
+
* instance, or subscribing to `selector`). This means extra prop
|
|
67
|
+
* drilling into `NodeComponentWrapper`, but it means we need to run
|
|
68
|
+
* these operations only once – instead of once per node.
|
|
69
|
+
* - Any operations that you’d normally write inside `nodes.map` are
|
|
70
|
+
* moved into `NodeComponentWrapper`. This ensures they are
|
|
71
|
+
* memorized – so if `NodeRenderer` *has* to rerender, it only
|
|
72
|
+
* needs to regenerate the list of nodes, nothing else.
|
|
73
|
+
*/
|
|
74
|
+
<NodeWrapper
|
|
75
|
+
key={nodeId}
|
|
76
|
+
id={nodeId}
|
|
77
|
+
nodeTypes={props.nodeTypes}
|
|
78
|
+
nodeExtent={props.nodeExtent}
|
|
79
|
+
onClick={props.onNodeClick}
|
|
80
|
+
onMouseEnter={props.onNodeMouseEnter}
|
|
81
|
+
onMouseMove={props.onNodeMouseMove}
|
|
82
|
+
onMouseLeave={props.onNodeMouseLeave}
|
|
83
|
+
onContextMenu={props.onNodeContextMenu}
|
|
84
|
+
onDoubleClick={props.onNodeDoubleClick}
|
|
85
|
+
noDragClassName={props.noDragClassName}
|
|
86
|
+
noPanClassName={props.noPanClassName}
|
|
87
|
+
rfId={props.rfId}
|
|
88
|
+
disableKeyboardA11y={props.disableKeyboardA11y}
|
|
89
|
+
resizeObserver={resizeObserver}
|
|
90
|
+
nodesDraggable={props.nodesDraggable ?? true}
|
|
91
|
+
nodesConnectable={nodesConnectable}
|
|
92
|
+
nodesFocusable={nodesFocusable}
|
|
93
|
+
elementsSelectable={elementsSelectable}
|
|
94
|
+
nodeClickDistance={props.nodeClickDistance}
|
|
95
|
+
onError={onError}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
})}</div>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NodeRendererComponent.displayName = 'NodeRenderer';
|
|
102
|
+
|
|
103
|
+
export const NodeRenderer = memo(NodeRendererComponent) as typeof NodeRendererComponent;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useEffect, useState } from 'octane';
|
|
2
|
+
|
|
3
|
+
import { ReactFlowState } from '../../types';
|
|
4
|
+
import { useStore } from '../../hooks/useStore';
|
|
5
|
+
import { InternalNodeUpdate } from '@xyflow/system';
|
|
6
|
+
|
|
7
|
+
const selector = (s: ReactFlowState) => s.updateNodeInternals;
|
|
8
|
+
|
|
9
|
+
export function useResizeObserver() {
|
|
10
|
+
const updateNodeInternals = useStore(selector);
|
|
11
|
+
const [resizeObserver] = useState(() => {
|
|
12
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return new ResizeObserver((entries: ResizeObserverEntry[]) => {
|
|
17
|
+
const updates = new Map<string, InternalNodeUpdate>();
|
|
18
|
+
entries.forEach((entry: ResizeObserverEntry) => {
|
|
19
|
+
const id = entry.target.getAttribute('data-id') as string;
|
|
20
|
+
updates.set(id, {
|
|
21
|
+
id,
|
|
22
|
+
nodeElement: entry.target as HTMLDivElement,
|
|
23
|
+
force: true,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
updateNodeInternals(updates);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
resizeObserver?.disconnect();
|
|
34
|
+
};
|
|
35
|
+
}, [resizeObserver]);
|
|
36
|
+
|
|
37
|
+
return resizeObserver;
|
|
38
|
+
}
|