@octanejs/xyflow 0.1.17 → 0.1.19

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.
Files changed (53) hide show
  1. package/package.json +6 -6
  2. package/src/additional-components/Background/Background.tsrx +32 -26
  3. package/src/additional-components/Background/Patterns.tsrx +15 -11
  4. package/src/additional-components/Controls/ControlButton.tsrx +5 -5
  5. package/src/additional-components/Controls/Controls.tsrx +48 -44
  6. package/src/additional-components/Controls/Icons/FitView.tsrx +5 -5
  7. package/src/additional-components/Controls/Icons/Lock.tsrx +5 -5
  8. package/src/additional-components/Controls/Icons/Minus.tsrx +5 -3
  9. package/src/additional-components/Controls/Icons/Plus.tsrx +5 -3
  10. package/src/additional-components/Controls/Icons/Unlock.tsrx +5 -5
  11. package/src/additional-components/EdgeToolbar/EdgeToolbar.tsrx +20 -17
  12. package/src/additional-components/MiniMap/MiniMap.tsrx +85 -86
  13. package/src/additional-components/MiniMap/MiniMapNode.tsrx +18 -16
  14. package/src/additional-components/MiniMap/MiniMapNodes.tsrx +47 -45
  15. package/src/additional-components/NodeResizer/NodeResizeControl.tsrx +31 -30
  16. package/src/additional-components/NodeResizer/NodeResizer.tsrx +10 -10
  17. package/src/additional-components/NodeToolbar/NodeToolbar.tsrx +32 -25
  18. package/src/components/A11yDescriptions/index.tsrx +23 -18
  19. package/src/components/Attribution/index.tsrx +11 -9
  20. package/src/components/BatchProvider/index.tsrx +8 -11
  21. package/src/components/ConnectionLine/index.tsrx +31 -27
  22. package/src/components/EdgeWrapper/EdgeUpdateAnchors.tsrx +38 -35
  23. package/src/components/EdgeWrapper/index.tsrx +155 -146
  24. package/src/components/Edges/BaseEdge.tsrx +16 -14
  25. package/src/components/Edges/BezierEdge.tsrx +47 -43
  26. package/src/components/Edges/EdgeAnchor.tsrx +13 -11
  27. package/src/components/Edges/EdgeText.tsrx +31 -26
  28. package/src/components/Edges/SimpleBezierEdge.tsrx +55 -44
  29. package/src/components/Edges/SmoothStepEdge.tsrx +49 -45
  30. package/src/components/Edges/StepEdge.tsrx +10 -7
  31. package/src/components/Edges/StraightEdge.tsrx +40 -36
  32. package/src/components/Handle/index.tsrx +73 -63
  33. package/src/components/NodeWrapper/index.tsrx +86 -72
  34. package/src/components/Nodes/DefaultNode.tsrx +7 -5
  35. package/src/components/Nodes/InputNode.tsrx +11 -7
  36. package/src/components/Nodes/OutputNode.tsrx +11 -7
  37. package/src/components/NodesSelection/index.tsrx +23 -22
  38. package/src/components/Panel/index.tsrx +17 -14
  39. package/src/components/ReactFlowProvider/index.tsrx +25 -23
  40. package/src/components/SelectionListener/index.tsrx +4 -2
  41. package/src/components/StoreUpdater/index.tsrx +43 -34
  42. package/src/components/UserSelection/index.tsrx +10 -8
  43. package/src/container/EdgeRenderer/MarkerDefinitions.tsrx +34 -29
  44. package/src/container/EdgeRenderer/MarkerSymbols.tsrx +21 -17
  45. package/src/container/EdgeRenderer/index.tsrx +52 -49
  46. package/src/container/FlowRenderer/index.tsrx +67 -66
  47. package/src/container/GraphView/index.tsrx +98 -96
  48. package/src/container/NodeRenderer/index.tsrx +74 -71
  49. package/src/container/Pane/index.tsrx +69 -60
  50. package/src/container/ReactFlow/Wrapper.tsrx +23 -21
  51. package/src/container/ReactFlow/index.tsrx +158 -153
  52. package/src/container/Viewport/index.tsrx +13 -7
  53. package/src/container/ZoomPane/index.tsrx +28 -25
@@ -51,7 +51,13 @@ export function getSimpleBezierPath({
51
51
  targetX,
52
52
  targetY,
53
53
  targetPosition = Position.Top,
54
- }: GetSimpleBezierPathParams): [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number] {
54
+ }: GetSimpleBezierPathParams): [
55
+ path: string,
56
+ labelX: number,
57
+ labelY: number,
58
+ offsetX: number,
59
+ offsetY: number,
60
+ ] {
55
61
  const [sourceControlX, sourceControlY] = getControl({
56
62
  pos: sourcePosition,
57
63
  x1: sourceX,
@@ -88,53 +94,57 @@ export function getSimpleBezierPath({
88
94
 
89
95
  function createSimpleBezierEdge(params: { isInternal: boolean }) {
90
96
  // eslint-disable-next-line react/display-name
91
- return memo(({
92
- id,
93
- sourceX,
94
- sourceY,
95
- targetX,
96
- targetY,
97
- sourcePosition,
98
- targetPosition,
99
- label,
100
- labelStyle,
101
- labelShowBg,
102
- labelBgStyle,
103
- labelBgPadding,
104
- labelBgBorderRadius,
105
- style,
106
- markerEnd,
107
- markerStart,
108
- interactionWidth,
109
- }: SimpleBezierEdgeProps) => {
110
- const [path, labelX, labelY] = getSimpleBezierPath({
97
+ return memo(
98
+ ({
99
+ id,
111
100
  sourceX,
112
101
  sourceY,
113
- sourcePosition,
114
102
  targetX,
115
103
  targetY,
104
+ sourcePosition,
116
105
  targetPosition,
117
- });
106
+ label,
107
+ labelStyle,
108
+ labelShowBg,
109
+ labelBgStyle,
110
+ labelBgPadding,
111
+ labelBgBorderRadius,
112
+ style,
113
+ markerEnd,
114
+ markerStart,
115
+ interactionWidth,
116
+ }: SimpleBezierEdgeProps) => {
117
+ const [path, labelX, labelY] = getSimpleBezierPath({
118
+ sourceX,
119
+ sourceY,
120
+ sourcePosition,
121
+ targetX,
122
+ targetY,
123
+ targetPosition,
124
+ });
118
125
 
119
- const _id = params.isInternal ? undefined : id;
126
+ const _id = params.isInternal ? undefined : id;
120
127
 
121
- return <BaseEdge
122
- id={_id}
123
- path={path}
124
- labelX={labelX}
125
- labelY={labelY}
126
- label={label}
127
- labelStyle={labelStyle}
128
- labelShowBg={labelShowBg}
129
- labelBgStyle={labelBgStyle}
130
- labelBgPadding={labelBgPadding}
131
- labelBgBorderRadius={labelBgBorderRadius}
132
- style={style}
133
- markerEnd={markerEnd}
134
- markerStart={markerStart}
135
- interactionWidth={interactionWidth}
136
- />;
137
- });
128
+ return (
129
+ <BaseEdge
130
+ id={_id}
131
+ path={path}
132
+ labelX={labelX}
133
+ labelY={labelY}
134
+ label={label}
135
+ labelStyle={labelStyle}
136
+ labelShowBg={labelShowBg}
137
+ labelBgStyle={labelBgStyle}
138
+ labelBgPadding={labelBgPadding}
139
+ labelBgBorderRadius={labelBgBorderRadius}
140
+ style={style}
141
+ markerEnd={markerEnd}
142
+ markerStart={markerStart}
143
+ interactionWidth={interactionWidth}
144
+ />
145
+ );
146
+ },
147
+ );
138
148
  }
139
149
 
140
150
  const SimpleBezierEdge = createSimpleBezierEdge({ isInternal: false });
@@ -142,9 +152,10 @@ const SimpleBezierEdgeInternal = createSimpleBezierEdge({ isInternal: true });
142
152
 
143
153
  (SimpleBezierEdge as typeof SimpleBezierEdge & { displayName?: string }).displayName =
144
154
  'SimpleBezierEdge';
145
- (SimpleBezierEdgeInternal as
146
- typeof SimpleBezierEdgeInternal & {
155
+ (
156
+ SimpleBezierEdgeInternal as typeof SimpleBezierEdgeInternal & {
147
157
  displayName?: string;
148
- }).displayName = 'SimpleBezierEdgeInternal';
158
+ }
159
+ ).displayName = 'SimpleBezierEdgeInternal';
149
160
 
150
161
  export { SimpleBezierEdge, SimpleBezierEdgeInternal };
@@ -6,57 +6,61 @@ import type { SmoothStepEdgeProps } from '../../types';
6
6
 
7
7
  function createSmoothStepEdge(params: { isInternal: boolean }) {
8
8
  // eslint-disable-next-line react/display-name
9
- return memo(({
10
- id,
11
- sourceX,
12
- sourceY,
13
- targetX,
14
- targetY,
15
- label,
16
- labelStyle,
17
- labelShowBg,
18
- labelBgStyle,
19
- labelBgPadding,
20
- labelBgBorderRadius,
21
- style,
22
- sourcePosition = Position.Bottom,
23
- targetPosition = Position.Top,
24
- markerEnd,
25
- markerStart,
26
- pathOptions,
27
- interactionWidth,
28
- }: SmoothStepEdgeProps) => {
29
- const [path, labelX, labelY] = getSmoothStepPath({
9
+ return memo(
10
+ ({
11
+ id,
30
12
  sourceX,
31
13
  sourceY,
32
- sourcePosition,
33
14
  targetX,
34
15
  targetY,
35
- targetPosition,
36
- borderRadius: pathOptions?.borderRadius,
37
- offset: pathOptions?.offset,
38
- stepPosition: pathOptions?.stepPosition,
39
- });
16
+ label,
17
+ labelStyle,
18
+ labelShowBg,
19
+ labelBgStyle,
20
+ labelBgPadding,
21
+ labelBgBorderRadius,
22
+ style,
23
+ sourcePosition = Position.Bottom,
24
+ targetPosition = Position.Top,
25
+ markerEnd,
26
+ markerStart,
27
+ pathOptions,
28
+ interactionWidth,
29
+ }: SmoothStepEdgeProps) => {
30
+ const [path, labelX, labelY] = getSmoothStepPath({
31
+ sourceX,
32
+ sourceY,
33
+ sourcePosition,
34
+ targetX,
35
+ targetY,
36
+ targetPosition,
37
+ borderRadius: pathOptions?.borderRadius,
38
+ offset: pathOptions?.offset,
39
+ stepPosition: pathOptions?.stepPosition,
40
+ });
40
41
 
41
- const _id = params.isInternal ? undefined : id;
42
+ const _id = params.isInternal ? undefined : id;
42
43
 
43
- return <BaseEdge
44
- id={_id}
45
- path={path}
46
- labelX={labelX}
47
- labelY={labelY}
48
- label={label}
49
- labelStyle={labelStyle}
50
- labelShowBg={labelShowBg}
51
- labelBgStyle={labelBgStyle}
52
- labelBgPadding={labelBgPadding}
53
- labelBgBorderRadius={labelBgBorderRadius}
54
- style={style}
55
- markerEnd={markerEnd}
56
- markerStart={markerStart}
57
- interactionWidth={interactionWidth}
58
- />;
59
- });
44
+ return (
45
+ <BaseEdge
46
+ id={_id}
47
+ path={path}
48
+ labelX={labelX}
49
+ labelY={labelY}
50
+ label={label}
51
+ labelStyle={labelStyle}
52
+ labelShowBg={labelShowBg}
53
+ labelBgStyle={labelBgStyle}
54
+ labelBgPadding={labelBgPadding}
55
+ labelBgBorderRadius={labelBgBorderRadius}
56
+ style={style}
57
+ markerEnd={markerEnd}
58
+ markerStart={markerStart}
59
+ interactionWidth={interactionWidth}
60
+ />
61
+ );
62
+ },
63
+ );
60
64
  }
61
65
 
62
66
  /**
@@ -8,13 +8,16 @@ function createStepEdge(params: { isInternal: boolean }) {
8
8
  return memo(({ id, ...props }: StepEdgeProps) => {
9
9
  const _id = params.isInternal ? undefined : id;
10
10
 
11
- return <SmoothStepEdge
12
- {...props}
13
- id={_id}
14
- pathOptions={useMemo(() => ({ borderRadius: 0, offset: props.pathOptions?.offset }), [
15
- props.pathOptions?.offset,
16
- ])}
17
- />;
11
+ return (
12
+ <SmoothStepEdge
13
+ {...props}
14
+ id={_id}
15
+ pathOptions={useMemo(
16
+ () => ({ borderRadius: 0, offset: props.pathOptions?.offset }),
17
+ [props.pathOptions?.offset],
18
+ )}
19
+ />
20
+ );
18
21
  });
19
22
  }
20
23
 
@@ -6,44 +6,48 @@ import type { StraightEdgeProps } from '../../types';
6
6
 
7
7
  function createStraightEdge(params: { isInternal: boolean }) {
8
8
  // eslint-disable-next-line react/display-name
9
- return memo(({
10
- id,
11
- sourceX,
12
- sourceY,
13
- targetX,
14
- targetY,
15
- label,
16
- labelStyle,
17
- labelShowBg,
18
- labelBgStyle,
19
- labelBgPadding,
20
- labelBgBorderRadius,
21
- style,
22
- markerEnd,
23
- markerStart,
24
- interactionWidth,
25
- }: StraightEdgeProps) => {
26
- const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY });
9
+ return memo(
10
+ ({
11
+ id,
12
+ sourceX,
13
+ sourceY,
14
+ targetX,
15
+ targetY,
16
+ label,
17
+ labelStyle,
18
+ labelShowBg,
19
+ labelBgStyle,
20
+ labelBgPadding,
21
+ labelBgBorderRadius,
22
+ style,
23
+ markerEnd,
24
+ markerStart,
25
+ interactionWidth,
26
+ }: StraightEdgeProps) => {
27
+ const [path, labelX, labelY] = getStraightPath({ sourceX, sourceY, targetX, targetY });
27
28
 
28
- const _id = params.isInternal ? undefined : id;
29
+ const _id = params.isInternal ? undefined : id;
29
30
 
30
- return <BaseEdge
31
- id={_id}
32
- path={path}
33
- labelX={labelX}
34
- labelY={labelY}
35
- label={label}
36
- labelStyle={labelStyle}
37
- labelShowBg={labelShowBg}
38
- labelBgStyle={labelBgStyle}
39
- labelBgPadding={labelBgPadding}
40
- labelBgBorderRadius={labelBgBorderRadius}
41
- style={style}
42
- markerEnd={markerEnd}
43
- markerStart={markerStart}
44
- interactionWidth={interactionWidth}
45
- />;
46
- });
31
+ return (
32
+ <BaseEdge
33
+ id={_id}
34
+ path={path}
35
+ labelX={labelX}
36
+ labelY={labelY}
37
+ label={label}
38
+ labelStyle={labelStyle}
39
+ labelShowBg={labelShowBg}
40
+ labelBgStyle={labelBgStyle}
41
+ labelBgPadding={labelBgPadding}
42
+ labelBgBorderRadius={labelBgBorderRadius}
43
+ style={style}
44
+ markerEnd={markerEnd}
45
+ markerStart={markerStart}
46
+ interactionWidth={interactionWidth}
47
+ />
48
+ );
49
+ },
50
+ );
47
51
  }
48
52
 
49
53
  /**
@@ -33,8 +33,8 @@ import { addEdge } from '../../utils/edges';
33
33
  /**
34
34
  * @expand
35
35
  */
36
- export type HandleProps =
37
- HandlePropsSystem & Omit<HTMLAttributes<HTMLDivElement>, 'id'> & {
36
+ export type HandleProps = HandlePropsSystem &
37
+ Omit<HTMLAttributes<HTMLDivElement>, 'id'> & {
38
38
  /** Callback called when connection is made */
39
39
  onConnect?: OnConnect;
40
40
  };
@@ -54,33 +54,35 @@ const idleConnectingState = {
54
54
  valid: false,
55
55
  };
56
56
 
57
- const connectingSelector = (nodeId: string | null, handleId: string | null, type: HandleType) => (
58
- state: ReactFlowState,
59
- ) => {
60
- const { connectionClickStartHandle: clickHandle, connectionMode, connection } = state;
61
- const { fromHandle, toHandle, isValid } = connection;
57
+ const connectingSelector =
58
+ (nodeId: string | null, handleId: string | null, type: HandleType) => (state: ReactFlowState) => {
59
+ const { connectionClickStartHandle: clickHandle, connectionMode, connection } = state;
60
+ const { fromHandle, toHandle, isValid } = connection;
62
61
 
63
- if (!fromHandle && !clickHandle) {
64
- return idleConnectingState;
65
- }
62
+ if (!fromHandle && !clickHandle) {
63
+ return idleConnectingState;
64
+ }
66
65
 
67
- const connectingTo =
68
- toHandle?.nodeId === nodeId && toHandle?.id === handleId && toHandle?.type === type;
66
+ const connectingTo =
67
+ toHandle?.nodeId === nodeId && toHandle?.id === handleId && toHandle?.type === type;
69
68
 
70
- return {
71
- connectingFrom: fromHandle?.nodeId === nodeId && fromHandle?.id === handleId &&
72
- fromHandle?.type === type,
73
- connectingTo,
74
- clickConnecting: clickHandle?.nodeId === nodeId && clickHandle?.id === handleId &&
75
- clickHandle?.type === type,
76
- isPossibleEndHandle: connectionMode === ConnectionMode.Strict
77
- ? fromHandle?.type !== type
78
- : nodeId !== fromHandle?.nodeId || handleId !== fromHandle?.id,
79
- connectionInProcess: !!fromHandle,
80
- clickConnectionInProcess: !!clickHandle,
81
- valid: connectingTo && isValid,
69
+ return {
70
+ connectingFrom:
71
+ fromHandle?.nodeId === nodeId && fromHandle?.id === handleId && fromHandle?.type === type,
72
+ connectingTo,
73
+ clickConnecting:
74
+ clickHandle?.nodeId === nodeId &&
75
+ clickHandle?.id === handleId &&
76
+ clickHandle?.type === type,
77
+ isPossibleEndHandle:
78
+ connectionMode === ConnectionMode.Strict
79
+ ? fromHandle?.type !== type
80
+ : nodeId !== fromHandle?.nodeId || handleId !== fromHandle?.id,
81
+ connectionInProcess: !!fromHandle,
82
+ clickConnectionInProcess: !!clickHandle,
83
+ valid: connectingTo && isValid,
84
+ };
82
85
  };
83
- };
84
86
 
85
87
  function HandleComponent(
86
88
  {
@@ -144,8 +146,8 @@ function HandleComponent(
144
146
 
145
147
  if (
146
148
  isConnectableStart &&
147
- (isMouseTriggered && (event as ReactMouseEvent<HTMLDivElement>).button === 0 ||
148
- !isMouseTriggered)
149
+ ((isMouseTriggered && (event as ReactMouseEvent<HTMLDivElement>).button === 0) ||
150
+ !isMouseTriggered)
149
151
  ) {
150
152
  const currentStore = store.getState();
151
153
  const fallbackIsValidConnection: NonNullable<HandleProps['isValidConnection']> = (...args) =>
@@ -197,7 +199,7 @@ function HandleComponent(
197
199
  connection: connectionState,
198
200
  } = store.getState();
199
201
 
200
- if (!nodeId || !connectionClickStartHandle && !isConnectableStart) {
202
+ if (!nodeId || (!connectionClickStartHandle && !isConnectableStart)) {
201
203
  return;
202
204
  }
203
205
 
@@ -243,41 +245,49 @@ function HandleComponent(
243
245
  store.setState({ connectionClickStartHandle: null });
244
246
  };
245
247
 
246
- return <div
247
- data-handleid={handleId}
248
- data-nodeid={nodeId}
249
- data-handlepos={position}
250
- data-id={`${rfId}-${nodeId}-${handleId}-${type}`}
251
- className={cc([
252
- 'react-flow__handle',
253
- `react-flow__handle-${position}`,
254
- 'nodrag',
255
- noPanClassName,
256
- className,
257
- {
258
- source: !isTarget,
259
- target: isTarget,
260
- connectable: isConnectable,
261
- connectablestart: isConnectableStart,
262
- connectableend: isConnectableEnd,
263
- clickconnecting: clickConnecting,
264
- connectingfrom: connectingFrom,
265
- connectingto: connectingTo,
266
- valid,
267
- /*
268
- * shows where you can start a connection from
269
- * and where you can end it while connecting
270
- */
271
- connectionindicator: isConnectable && (!connectionInProcess || isPossibleEndHandle) &&
272
- (connectionInProcess || clickConnectionInProcess ? isConnectableEnd : isConnectableStart),
273
- },
274
- ])}
275
- onMouseDown={onPointerDown}
276
- onTouchStart={onPointerDown}
277
- onClick={connectOnClick ? onClick : undefined}
278
- ref={ref}
279
- {...rest}
280
- >{children}</div>;
248
+ return (
249
+ <div
250
+ data-handleid={handleId}
251
+ data-nodeid={nodeId}
252
+ data-handlepos={position}
253
+ data-id={`${rfId}-${nodeId}-${handleId}-${type}`}
254
+ className={cc([
255
+ 'react-flow__handle',
256
+ `react-flow__handle-${position}`,
257
+ 'nodrag',
258
+ noPanClassName,
259
+ className,
260
+ {
261
+ source: !isTarget,
262
+ target: isTarget,
263
+ connectable: isConnectable,
264
+ connectablestart: isConnectableStart,
265
+ connectableend: isConnectableEnd,
266
+ clickconnecting: clickConnecting,
267
+ connectingfrom: connectingFrom,
268
+ connectingto: connectingTo,
269
+ valid,
270
+ /*
271
+ * shows where you can start a connection from
272
+ * and where you can end it while connecting
273
+ */
274
+ connectionindicator:
275
+ isConnectable &&
276
+ (!connectionInProcess || isPossibleEndHandle) &&
277
+ (connectionInProcess || clickConnectionInProcess
278
+ ? isConnectableEnd
279
+ : isConnectableStart),
280
+ },
281
+ ])}
282
+ onMouseDown={onPointerDown}
283
+ onTouchStart={onPointerDown}
284
+ onClick={connectOnClick ? onClick : undefined}
285
+ ref={ref}
286
+ {...rest}
287
+ >
288
+ {children}
289
+ </div>
290
+ );
281
291
  }
282
292
 
283
293
  /**