@octanejs/xyflow 0.1.18 → 0.1.20
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/package.json +6 -6
- package/src/additional-components/Background/Background.tsrx +32 -26
- package/src/additional-components/Background/Patterns.tsrx +15 -11
- package/src/additional-components/Controls/ControlButton.tsrx +5 -5
- package/src/additional-components/Controls/Controls.tsrx +48 -44
- package/src/additional-components/Controls/Icons/FitView.tsrx +5 -5
- package/src/additional-components/Controls/Icons/Lock.tsrx +5 -5
- package/src/additional-components/Controls/Icons/Minus.tsrx +5 -3
- package/src/additional-components/Controls/Icons/Plus.tsrx +5 -3
- package/src/additional-components/Controls/Icons/Unlock.tsrx +5 -5
- package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +20 -17
- package/src/additional-components/MiniMap/MiniMap.tsrx +85 -86
- package/src/additional-components/MiniMap/MiniMapNode.tsrx +18 -16
- package/src/additional-components/MiniMap/MiniMapNodes.tsrx +47 -45
- package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +31 -30
- package/src/additional-components/NodeResizer/NodeResizer.tsrx +10 -10
- package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +32 -25
- package/src/components/A11yDescriptions/index.tsrx +23 -18
- package/src/components/Attribution/index.tsrx +11 -9
- package/src/components/BatchProvider/index.tsrx +8 -11
- package/src/components/ConnectionLine/index.tsrx +31 -27
- package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +38 -35
- package/src/components/EdgeWrapper/index.tsrx +155 -146
- package/src/components/Edges/BaseEdge.tsrx +16 -14
- package/src/components/Edges/BezierEdge.tsrx +47 -43
- package/src/components/Edges/EdgeAnchor.tsrx +13 -11
- package/src/components/Edges/EdgeText.tsrx +31 -26
- package/src/components/Edges/SimpleBezierEdge.tsrx +55 -44
- package/src/components/Edges/SmoothStepEdge.tsrx +49 -45
- package/src/components/Edges/StepEdge.tsrx +10 -7
- package/src/components/Edges/StraightEdge.tsrx +40 -36
- package/src/components/Handle/index.tsrx +73 -63
- package/src/components/NodeWrapper/index.tsrx +86 -72
- package/src/components/Nodes/DefaultNode.tsrx +7 -5
- package/src/components/Nodes/InputNode.tsrx +11 -7
- package/src/components/Nodes/OutputNode.tsrx +11 -7
- package/src/components/NodesSelection/index.tsrx +23 -22
- package/src/components/Panel/index.tsrx +17 -14
- package/src/components/ReactFlowProvider/index.tsrx +25 -23
- package/src/components/SelectionListener/index.tsrx +4 -2
- package/src/components/StoreUpdater/index.tsrx +43 -34
- package/src/components/UserSelection/index.tsrx +10 -8
- package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +34 -29
- package/src/container/EdgeRenderer/MarkerSymbols.tsrx +21 -17
- package/src/container/EdgeRenderer/index.tsrx +52 -49
- package/src/container/FlowRenderer/index.tsrx +67 -66
- package/src/container/GraphView/index.tsrx +98 -96
- package/src/container/NodeRenderer/index.tsrx +74 -71
- package/src/container/Pane/index.tsrx +69 -60
- package/src/container/ReactFlow/Wrapper.tsrx +23 -21
- package/src/container/ReactFlow/index.tsrx +158 -153
- package/src/container/Viewport/index.tsrx +13 -7
- package/src/container/ZoomPane/index.tsrx +28 -25
|
@@ -9,25 +9,24 @@ import { useResizeObserver } from './useResizeObserver';
|
|
|
9
9
|
import NodeWrapper from '../../components/NodeWrapper/index.tsrx';
|
|
10
10
|
import type { Node, ReactFlowState } from '../../types';
|
|
11
11
|
|
|
12
|
-
export type NodeRendererProps<NodeType extends Node> =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
>;
|
|
12
|
+
export type NodeRendererProps<NodeType extends Node> = Pick<
|
|
13
|
+
GraphViewProps<NodeType>,
|
|
14
|
+
| 'onNodeClick'
|
|
15
|
+
| 'onNodeDoubleClick'
|
|
16
|
+
| 'onNodeMouseEnter'
|
|
17
|
+
| 'onNodeMouseMove'
|
|
18
|
+
| 'onNodeMouseLeave'
|
|
19
|
+
| 'onNodeContextMenu'
|
|
20
|
+
| 'onlyRenderVisibleElements'
|
|
21
|
+
| 'noPanClassName'
|
|
22
|
+
| 'noDragClassName'
|
|
23
|
+
| 'rfId'
|
|
24
|
+
| 'disableKeyboardA11y'
|
|
25
|
+
| 'nodeExtent'
|
|
26
|
+
| 'nodeTypes'
|
|
27
|
+
| 'nodeClickDistance'
|
|
28
|
+
| 'nodesDraggable'
|
|
29
|
+
>;
|
|
31
30
|
|
|
32
31
|
const selector = (s: ReactFlowState) => ({
|
|
33
32
|
nodesConnectable: s.nodesConnectable,
|
|
@@ -44,58 +43,62 @@ function NodeRendererComponent<NodeType extends Node>(props: NodeRendererProps<N
|
|
|
44
43
|
const nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements);
|
|
45
44
|
const resizeObserver = useResizeObserver();
|
|
46
45
|
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
46
|
+
return (
|
|
47
|
+
<div className="react-flow__nodes" style={containerStyle}>
|
|
48
|
+
{nodeIds.map((nodeId) => {
|
|
49
|
+
return (
|
|
50
|
+
/*
|
|
51
|
+
* The split of responsibilities between NodeRenderer and
|
|
52
|
+
* NodeComponentWrapper may appear weird. However, it’s designed to
|
|
53
|
+
* minimize the cost of updates when individual nodes change.
|
|
54
|
+
*
|
|
55
|
+
* For example, when you’re dragging a single node, that node gets
|
|
56
|
+
* updated multiple times per second. If `NodeRenderer` were to update
|
|
57
|
+
* every time, it would have to re-run the `nodes.map()` loop every
|
|
58
|
+
* time. This gets pricey with hundreds of nodes, especially if every
|
|
59
|
+
* loop cycle does more than just rendering a JSX element!
|
|
60
|
+
*
|
|
61
|
+
* As a result of this choice, we took the following implementation
|
|
62
|
+
* decisions:
|
|
63
|
+
* - NodeRenderer subscribes *only* to node IDs – and therefore
|
|
64
|
+
* rerender *only* when visible nodes are added or removed.
|
|
65
|
+
* - NodeRenderer performs all operations the result of which can be
|
|
66
|
+
* shared between nodes (such as creating the `ResizeObserver`
|
|
67
|
+
* instance, or subscribing to `selector`). This means extra prop
|
|
68
|
+
* drilling into `NodeComponentWrapper`, but it means we need to run
|
|
69
|
+
* these operations only once – instead of once per node.
|
|
70
|
+
* - Any operations that you’d normally write inside `nodes.map` are
|
|
71
|
+
* moved into `NodeComponentWrapper`. This ensures they are
|
|
72
|
+
* memorized – so if `NodeRenderer` *has* to rerender, it only
|
|
73
|
+
* needs to regenerate the list of nodes, nothing else.
|
|
74
|
+
*/
|
|
75
|
+
<NodeWrapper
|
|
76
|
+
key={nodeId}
|
|
77
|
+
id={nodeId}
|
|
78
|
+
nodeTypes={props.nodeTypes}
|
|
79
|
+
nodeExtent={props.nodeExtent}
|
|
80
|
+
onClick={props.onNodeClick}
|
|
81
|
+
onMouseEnter={props.onNodeMouseEnter}
|
|
82
|
+
onMouseMove={props.onNodeMouseMove}
|
|
83
|
+
onMouseLeave={props.onNodeMouseLeave}
|
|
84
|
+
onContextMenu={props.onNodeContextMenu}
|
|
85
|
+
onDoubleClick={props.onNodeDoubleClick}
|
|
86
|
+
noDragClassName={props.noDragClassName}
|
|
87
|
+
noPanClassName={props.noPanClassName}
|
|
88
|
+
rfId={props.rfId}
|
|
89
|
+
disableKeyboardA11y={props.disableKeyboardA11y}
|
|
90
|
+
resizeObserver={resizeObserver}
|
|
91
|
+
nodesDraggable={props.nodesDraggable ?? true}
|
|
92
|
+
nodesConnectable={nodesConnectable}
|
|
93
|
+
nodesFocusable={nodesFocusable}
|
|
94
|
+
elementsSelectable={elementsSelectable}
|
|
95
|
+
nodeClickDistance={props.nodeClickDistance}
|
|
96
|
+
onError={onError}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
})}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
NodeRendererComponent.displayName = 'NodeRenderer';
|
|
@@ -25,31 +25,30 @@ import { useStore, useStoreApi } from '../../hooks/useStore';
|
|
|
25
25
|
import { getSelectionChanges } from '../../utils';
|
|
26
26
|
import type { ReactFlowProps, ReactFlowState } from '../../types';
|
|
27
27
|
|
|
28
|
-
type PaneProps =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
>;
|
|
28
|
+
type PaneProps = {
|
|
29
|
+
isSelecting: boolean;
|
|
30
|
+
selectionKeyPressed: boolean;
|
|
31
|
+
children: OctaneNode;
|
|
32
|
+
paneClickDistance: number;
|
|
33
|
+
} & Partial<
|
|
34
|
+
Pick<
|
|
35
|
+
ReactFlowProps,
|
|
36
|
+
| 'selectionMode'
|
|
37
|
+
| 'panOnDrag'
|
|
38
|
+
| 'autoPanOnSelection'
|
|
39
|
+
| 'onSelectionStart'
|
|
40
|
+
| 'onSelectionEnd'
|
|
41
|
+
| 'onPaneClick'
|
|
42
|
+
| 'onPaneContextMenu'
|
|
43
|
+
| 'onPaneScroll'
|
|
44
|
+
| 'onPaneMouseEnter'
|
|
45
|
+
| 'onPaneMouseMove'
|
|
46
|
+
| 'onPaneMouseLeave'
|
|
47
|
+
| 'selectionOnDrag'
|
|
48
|
+
>
|
|
49
|
+
>;
|
|
51
50
|
|
|
52
|
-
const wrapHandler = <EventType extends Event
|
|
51
|
+
const wrapHandler = <EventType extends Event>(
|
|
53
52
|
handler: EventHandler<EventType> | undefined,
|
|
54
53
|
containerRef: RefObject<HTMLDivElement | null>,
|
|
55
54
|
): EventHandler<EventType> => {
|
|
@@ -112,8 +111,9 @@ export function Pane({
|
|
|
112
111
|
// We prevent click events when the user let go of the selectionKey during a selection
|
|
113
112
|
// We also prevent click events when a connection is in progress
|
|
114
113
|
if (
|
|
115
|
-
selectionInProgress.current ||
|
|
116
|
-
|
|
114
|
+
selectionInProgress.current ||
|
|
115
|
+
connectionEndedOnPane.current ||
|
|
116
|
+
store.getState().connection.inProgress
|
|
117
117
|
) {
|
|
118
118
|
selectionInProgress.current = false;
|
|
119
119
|
connectionEndedOnPane.current = false;
|
|
@@ -160,10 +160,14 @@ export function Pane({
|
|
|
160
160
|
// if a child element has the 'nokey' class, we don't want to swallow the event and don't start a selection
|
|
161
161
|
const isNoKeyEvent =
|
|
162
162
|
!eventTargetIsContainer && !!(event.target as HTMLElement).closest('.nokey');
|
|
163
|
-
const isSelectionActive = selectionOnDrag && eventTargetIsContainer || selectionKeyPressed;
|
|
163
|
+
const isSelectionActive = (selectionOnDrag && eventTargetIsContainer) || selectionKeyPressed;
|
|
164
164
|
|
|
165
165
|
if (
|
|
166
|
-
isNoKeyEvent ||
|
|
166
|
+
isNoKeyEvent ||
|
|
167
|
+
!isSelecting ||
|
|
168
|
+
!isSelectionActive ||
|
|
169
|
+
event.button !== 0 ||
|
|
170
|
+
!event.isPrimary
|
|
167
171
|
) {
|
|
168
172
|
return;
|
|
169
173
|
}
|
|
@@ -226,13 +230,15 @@ export function Pane({
|
|
|
226
230
|
const prevSelectedNodeIds = selectedNodeIds.current;
|
|
227
231
|
const prevSelectedEdgeIds = selectedEdgeIds.current;
|
|
228
232
|
|
|
229
|
-
selectedNodeIds.current = new Set(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
selectedNodeIds.current = new Set(
|
|
234
|
+
getNodesInside(
|
|
235
|
+
nodeLookup,
|
|
236
|
+
nextUserSelectRect,
|
|
237
|
+
transform,
|
|
238
|
+
selectionMode === SelectionMode.Partial,
|
|
239
|
+
true,
|
|
240
|
+
).map((node) => node.id),
|
|
241
|
+
);
|
|
236
242
|
|
|
237
243
|
selectedEdgeIds.current = new Set();
|
|
238
244
|
const edgesSelectable = defaultEdgeOptions?.selectable ?? true;
|
|
@@ -343,12 +349,13 @@ export function Pane({
|
|
|
343
349
|
(event.target as Partial<Element>)?.releasePointerCapture?.(event.pointerId);
|
|
344
350
|
|
|
345
351
|
/*
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
352
|
+
* We only want to trigger click functions when in selection mode if
|
|
353
|
+
* the user did not move the mouse.
|
|
354
|
+
*/
|
|
349
355
|
if (
|
|
350
|
-
!userSelectionActive &&
|
|
351
|
-
|
|
356
|
+
!userSelectionActive &&
|
|
357
|
+
event.target === container.current &&
|
|
358
|
+
store.getState().userSelectionRect
|
|
352
359
|
) {
|
|
353
360
|
onClick?.(event);
|
|
354
361
|
}
|
|
@@ -374,24 +381,26 @@ export function Pane({
|
|
|
374
381
|
cleanupAutoPan();
|
|
375
382
|
};
|
|
376
383
|
|
|
377
|
-
const draggable = panOnDrag === true || Array.isArray(panOnDrag) && panOnDrag.includes(0);
|
|
378
|
-
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
384
|
+
const draggable = panOnDrag === true || (Array.isArray(panOnDrag) && panOnDrag.includes(0));
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
<div
|
|
388
|
+
className={cc(['react-flow__pane', { draggable, dragging, selection: isSelecting }])}
|
|
389
|
+
onClick={isSelectionEnabled ? undefined : wrapHandler(onClick, container)}
|
|
390
|
+
onContextMenu={wrapHandler(onContextMenu, container)}
|
|
391
|
+
onWheel={wrapHandler(onWheel, container)}
|
|
392
|
+
onPointerEnter={isSelectionEnabled ? undefined : onPaneMouseEnter}
|
|
393
|
+
onPointerMove={isSelectionEnabled ? onPointerMove : onPaneMouseMove}
|
|
394
|
+
onPointerUp={onPointerUp}
|
|
395
|
+
onPointerCancel={isSelectionEnabled ? onPointerCancel : undefined}
|
|
396
|
+
onPointerDownCapture={isSelectionEnabled ? onPointerDownCapture : undefined}
|
|
397
|
+
onClickCapture={isSelectionEnabled ? onClickCapture : undefined}
|
|
398
|
+
onPointerLeave={onPaneMouseLeave}
|
|
399
|
+
ref={container}
|
|
400
|
+
style={containerStyle}
|
|
401
|
+
>
|
|
402
|
+
{children}
|
|
403
|
+
<UserSelection />
|
|
404
|
+
</div>
|
|
405
|
+
);
|
|
397
406
|
}
|
|
@@ -40,27 +40,29 @@ export function Wrapper({
|
|
|
40
40
|
|
|
41
41
|
if (isWrapped) {
|
|
42
42
|
/*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return <>
|
|
47
|
-
{children}
|
|
48
|
-
</>;
|
|
43
|
+
* we need to wrap it with a fragment because it's not allowed for children to be a OctaneNode
|
|
44
|
+
* https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18051
|
|
45
|
+
*/
|
|
46
|
+
return <>{children}</>;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
49
|
+
return (
|
|
50
|
+
<ReactFlowProvider
|
|
51
|
+
initialNodes={nodes}
|
|
52
|
+
initialEdges={edges}
|
|
53
|
+
defaultNodes={defaultNodes}
|
|
54
|
+
defaultEdges={defaultEdges}
|
|
55
|
+
initialWidth={width}
|
|
56
|
+
initialHeight={height}
|
|
57
|
+
fitView={fitView}
|
|
58
|
+
initialFitViewOptions={fitViewOptions}
|
|
59
|
+
initialMinZoom={minZoom}
|
|
60
|
+
initialMaxZoom={maxZoom}
|
|
61
|
+
nodeOrigin={nodeOrigin}
|
|
62
|
+
nodeExtent={nodeExtent}
|
|
63
|
+
zIndexMode={zIndexMode}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</ReactFlowProvider>
|
|
67
|
+
);
|
|
66
68
|
}
|