@uipath/apollo-react 7.15.2 → 7.15.4

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 (24) hide show
  1. package/dist/canvas/components/Edges/CanvasEdge.cjs +4 -2
  2. package/dist/canvas/components/Edges/CanvasEdge.d.ts.map +1 -1
  3. package/dist/canvas/components/Edges/CanvasEdge.js +4 -2
  4. package/dist/canvas/components/Edges/shared/hooks/useEdgeGeometry.cjs +8 -3
  5. package/dist/canvas/components/Edges/shared/hooks/useEdgeGeometry.d.ts +2 -0
  6. package/dist/canvas/components/Edges/shared/hooks/useEdgeGeometry.d.ts.map +1 -1
  7. package/dist/canvas/components/Edges/shared/hooks/useEdgeGeometry.js +9 -4
  8. package/dist/canvas/components/Edges/shared/hooks/useWaypointEditor.cjs +63 -37
  9. package/dist/canvas/components/Edges/shared/hooks/useWaypointEditor.d.ts +2 -0
  10. package/dist/canvas/components/Edges/shared/hooks/useWaypointEditor.d.ts.map +1 -1
  11. package/dist/canvas/components/Edges/shared/hooks/useWaypointEditor.js +64 -38
  12. package/dist/canvas/components/Edges/shared/waypoints.cjs +149 -5
  13. package/dist/canvas/components/Edges/shared/waypoints.d.ts +5 -0
  14. package/dist/canvas/components/Edges/shared/waypoints.d.ts.map +1 -1
  15. package/dist/canvas/components/Edges/shared/waypoints.js +133 -1
  16. package/dist/canvas/components/Guardrails/definitions-copy.cjs +1 -1
  17. package/dist/canvas/components/Guardrails/definitions-copy.js +1 -1
  18. package/dist/canvas/locales/en.cjs +1 -1
  19. package/dist/canvas/locales/en.d.ts.map +1 -1
  20. package/dist/canvas/locales/en.js +1 -1
  21. package/dist/canvas/locales/ru.cjs +1 -1
  22. package/dist/canvas/locales/ru.d.ts.map +1 -1
  23. package/dist/canvas/locales/ru.js +1 -1
  24. package/package.json +3 -3
@@ -88,6 +88,7 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ (0, external_react_namespaceObject.m
88
88
  });
89
89
  const routedWaypoints = data?.routedWaypoints ?? constants_cjs_namespaceObject.EMPTY_WAYPOINTS;
90
90
  const effectiveWaypoints = waypoints.length > 0 ? waypoints : routedWaypoints;
91
+ const autoRouted = data?.autoRouted ?? 0 === waypoints.length;
91
92
  const executionEnabled = !!data?.enableExecution;
92
93
  const toolbarEnabled = !!data?.enableToolbar && !isReadOnly;
93
94
  const previewEdge = (0, createPreviewNode_cjs_namespaceObject.isPreviewEdge)({
@@ -109,7 +110,7 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ (0, external_react_namespaceObject.m
109
110
  targetY,
110
111
  targetPosition,
111
112
  waypoints: effectiveWaypoints,
112
- autoRouted: data?.autoRouted ?? 0 === waypoints.length,
113
+ autoRouted,
113
114
  enableSegments: editingEnabled,
114
115
  hideArrowHead,
115
116
  enableLineJumps: !!data?.enableLineJumps
@@ -119,7 +120,8 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ (0, external_react_namespaceObject.m
119
120
  waypoints,
120
121
  pathPoints: geometry.pathPoints,
121
122
  enabled: editingEnabled,
122
- onChange: data?.onWaypointsChange
123
+ onChange: data?.onWaypointsChange,
124
+ buildPath: geometry.buildPath
123
125
  });
124
126
  const execution = (0, hooks_index_cjs_namespaceObject.useExecutionEdge)({
125
127
  edgeId: id,
@@ -1 +1 @@
1
- {"version":3,"file":"CanvasEdge.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/Edges/CanvasEdge.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAetD,eAAO,MAAM,UAAU,uDA2OF,CAAC"}
1
+ {"version":3,"file":"CanvasEdge.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/Edges/CanvasEdge.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAetD,eAAO,MAAM,UAAU,uDA6OF,CAAC"}
@@ -60,6 +60,7 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ memo(function({ id, selected, animat
60
60
  });
61
61
  const routedWaypoints = data?.routedWaypoints ?? EMPTY_WAYPOINTS;
62
62
  const effectiveWaypoints = waypoints.length > 0 ? waypoints : routedWaypoints;
63
+ const autoRouted = data?.autoRouted ?? 0 === waypoints.length;
63
64
  const executionEnabled = !!data?.enableExecution;
64
65
  const toolbarEnabled = !!data?.enableToolbar && !isReadOnly;
65
66
  const previewEdge = isPreviewEdge({
@@ -81,7 +82,7 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ memo(function({ id, selected, animat
81
82
  targetY,
82
83
  targetPosition,
83
84
  waypoints: effectiveWaypoints,
84
- autoRouted: data?.autoRouted ?? 0 === waypoints.length,
85
+ autoRouted,
85
86
  enableSegments: editingEnabled,
86
87
  hideArrowHead,
87
88
  enableLineJumps: !!data?.enableLineJumps
@@ -91,7 +92,8 @@ const CanvasEdge_CanvasEdge = /*#__PURE__*/ memo(function({ id, selected, animat
91
92
  waypoints,
92
93
  pathPoints: geometry.pathPoints,
93
94
  enabled: editingEnabled,
94
- onChange: data?.onWaypointsChange
95
+ onChange: data?.onWaypointsChange,
96
+ buildPath: geometry.buildPath
95
97
  });
96
98
  const execution = useExecutionEdge({
97
99
  edgeId: id,
@@ -38,17 +38,20 @@ function useEdgeGeometry(args) {
38
38
  const arrowOffset = external_constants_cjs_namespaceObject.ARROW_OFFSETS[targetPosition];
39
39
  const isWaypoint = 'waypoint' === routing;
40
40
  const isHandle = 'handle' === routing;
41
- const pathPoints = (0, external_react_namespaceObject.useMemo)(()=>isWaypoint ? (0, external_geometry_cjs_namespaceObject.buildPathVertices)(sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, waypoints, autoRouted) : EMPTY_VERTICES, [
42
- isWaypoint,
41
+ const buildPath = (0, external_react_namespaceObject.useCallback)((candidate)=>(0, external_geometry_cjs_namespaceObject.buildPathVertices)(sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, candidate, autoRouted), [
43
42
  sourceX,
44
43
  sourceY,
45
44
  sourcePosition,
46
45
  targetX,
47
46
  targetY,
48
47
  targetPosition,
49
- waypoints,
50
48
  autoRouted
51
49
  ]);
50
+ const pathPoints = (0, external_react_namespaceObject.useMemo)(()=>isWaypoint ? buildPath(waypoints) : EMPTY_VERTICES, [
51
+ isWaypoint,
52
+ buildPath,
53
+ waypoints
54
+ ]);
52
55
  const segments = (0, external_react_namespaceObject.useMemo)(()=>enableSegments ? (0, external_geometry_cjs_namespaceObject.extractSegments)(pathPoints) : EMPTY_SEGMENTS, [
53
56
  enableSegments,
54
57
  pathPoints
@@ -87,6 +90,7 @@ function useEdgeGeometry(args) {
87
90
  edgePath: handle.edgePath,
88
91
  pathPoints: EMPTY_VERTICES,
89
92
  segments: EMPTY_SEGMENTS,
93
+ buildPath,
90
94
  labelPoint,
91
95
  arrow
92
96
  };
@@ -94,6 +98,7 @@ function useEdgeGeometry(args) {
94
98
  edgePath: waypointPath,
95
99
  pathPoints,
96
100
  segments,
101
+ buildPath,
97
102
  labelPoint,
98
103
  arrow
99
104
  };
@@ -1,5 +1,6 @@
1
1
  import type { Position } from '../../../../xyflow/react.ts';
2
2
  import type { EdgeRouting, PathVertex, Point, Segment, Waypoint } from '../types';
3
+ import type { PathBuilder } from '../waypoints';
3
4
  export type UseEdgeGeometryArgs = {
4
5
  routing: EdgeRouting;
5
6
  edgeId: string;
@@ -24,6 +25,7 @@ export type EdgeGeometry = {
24
25
  pathPoints: PathVertex[];
25
26
  segments: Segment[];
26
27
  labelPoint: Point;
28
+ buildPath: PathBuilder;
27
29
  arrow: {
28
30
  angle: number;
29
31
  offset: Point;
@@ -1 +1 @@
1
- {"version":3,"file":"useEdgeGeometry.d.ts","sourceRoot":"","sources":["../../../../../../src/canvas/components/Edges/shared/hooks/useEdgeGeometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0CAA0C,CAAC;AAWzE,OAAO,KAAK,EAAE,WAAW,EAAE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ks/index.js";
3
3
  import { ARROW_ANGLE_MAP, ARROW_OFFSETS, EDGE_CONSTANTS } from "../constants.js";
4
4
  import { useEdgeLineJumps } from "../crossings/index.js";
@@ -10,17 +10,20 @@ function useEdgeGeometry(args) {
10
10
  const arrowOffset = ARROW_OFFSETS[targetPosition];
11
11
  const isWaypoint = 'waypoint' === routing;
12
12
  const isHandle = 'handle' === routing;
13
- const pathPoints = useMemo(()=>isWaypoint ? buildPathVertices(sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, waypoints, autoRouted) : EMPTY_VERTICES, [
14
- isWaypoint,
13
+ const buildPath = useCallback((candidate)=>buildPathVertices(sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, candidate, autoRouted), [
15
14
  sourceX,
16
15
  sourceY,
17
16
  sourcePosition,
18
17
  targetX,
19
18
  targetY,
20
19
  targetPosition,
21
- waypoints,
22
20
  autoRouted
23
21
  ]);
22
+ const pathPoints = useMemo(()=>isWaypoint ? buildPath(waypoints) : EMPTY_VERTICES, [
23
+ isWaypoint,
24
+ buildPath,
25
+ waypoints
26
+ ]);
24
27
  const segments = useMemo(()=>enableSegments ? extractSegments(pathPoints) : EMPTY_SEGMENTS, [
25
28
  enableSegments,
26
29
  pathPoints
@@ -59,6 +62,7 @@ function useEdgeGeometry(args) {
59
62
  edgePath: handle.edgePath,
60
63
  pathPoints: EMPTY_VERTICES,
61
64
  segments: EMPTY_SEGMENTS,
65
+ buildPath,
62
66
  labelPoint,
63
67
  arrow
64
68
  };
@@ -66,6 +70,7 @@ function useEdgeGeometry(args) {
66
70
  edgePath: waypointPath,
67
71
  pathPoints,
68
72
  segments,
73
+ buildPath,
69
74
  labelPoint,
70
75
  arrow
71
76
  };
@@ -32,7 +32,7 @@ const external_geometry_cjs_namespaceObject = require("../geometry.cjs");
32
32
  const external_waypoints_cjs_namespaceObject = require("../waypoints.cjs");
33
33
  const external_useEdgeWaypointWriter_cjs_namespaceObject = require("./useEdgeWaypointWriter.cjs");
34
34
  function useWaypointEditor(args) {
35
- const { edgeId, waypoints, pathPoints, enabled, onChange } = args;
35
+ const { edgeId, waypoints, pathPoints, enabled, onChange, buildPath } = args;
36
36
  const { screenToFlowPosition } = (0, react_cjs_namespaceObject.useReactFlow)();
37
37
  const writeWaypoints = (0, external_useEdgeWaypointWriter_cjs_namespaceObject.useEdgeWaypointWriter)(edgeId, onChange);
38
38
  const [dragState, setDragState] = (0, external_react_namespaceObject.useState)({
@@ -40,11 +40,14 @@ function useWaypointEditor(args) {
40
40
  });
41
41
  const dragStartRef = (0, external_react_namespaceObject.useRef)(null);
42
42
  const rafRef = (0, external_react_namespaceObject.useRef)(null);
43
+ const lastPointerRef = (0, external_react_namespaceObject.useRef)(null);
43
44
  const waypointsRef = (0, external_react_namespaceObject.useRef)(waypoints);
44
45
  const pathPointsRef = (0, external_react_namespaceObject.useRef)(pathPoints);
46
+ const buildPathRef = (0, external_react_namespaceObject.useRef)(buildPath);
45
47
  (0, external_react_namespaceObject.useEffect)(()=>{
46
48
  waypointsRef.current = waypoints;
47
49
  pathPointsRef.current = pathPoints;
50
+ buildPathRef.current = buildPath;
48
51
  });
49
52
  const updateWaypoints = (0, external_react_namespaceObject.useCallback)((next)=>{
50
53
  if ((0, external_waypoints_cjs_namespaceObject.waypointsEqual)(waypointsRef.current, next)) return;
@@ -54,31 +57,45 @@ function useWaypointEditor(args) {
54
57
  ]);
55
58
  (0, external_react_namespaceObject.useEffect)(()=>{
56
59
  if (!enabled || 'none' === dragState.type) return;
60
+ let lastTarget = null;
61
+ const computeDrag = (client, skipSameCell)=>{
62
+ const start = screenToFlowPosition(dragStartRef.current, {
63
+ snapToGrid: false
64
+ });
65
+ const current = screenToFlowPosition(client, {
66
+ snapToGrid: false
67
+ });
68
+ const delta = {
69
+ x: current.x - start.x,
70
+ y: current.y - start.y
71
+ };
72
+ if ('waypoint' === dragState.type) {
73
+ const { initialWaypoints, waypointIndex, initialPathPoints, mode } = dragState;
74
+ const initial = initialWaypoints[waypointIndex];
75
+ if (!initial) return null;
76
+ const target = (0, external_geometry_cjs_namespaceObject.snapPointToGrid)({
77
+ x: initial.x + delta.x,
78
+ y: initial.y + delta.y
79
+ });
80
+ if (skipSameCell && lastTarget?.x === target.x && lastTarget.y === target.y) return null;
81
+ lastTarget = target;
82
+ return 'corner' === mode ? (0, external_waypoints_cjs_namespaceObject.moveCornerWaypoint)(initialWaypoints, waypointIndex, target, initialPathPoints) : (0, external_waypoints_cjs_namespaceObject.moveWaypointConstrained)(initialWaypoints, waypointIndex, target, buildPathRef.current);
83
+ }
84
+ if ('segment' === dragState.type) return (0, external_waypoints_cjs_namespaceObject.moveSegmentByDelta)(dragState.initialWaypoints, dragState.segment, delta, dragState.initialPathPoints);
85
+ return null;
86
+ };
57
87
  const handleMouseMove = (e)=>{
58
88
  if (!dragStartRef.current) return;
89
+ const client = {
90
+ x: e.clientX,
91
+ y: e.clientY
92
+ };
93
+ lastPointerRef.current = client;
59
94
  if (null !== rafRef.current) cancelAnimationFrame(rafRef.current);
60
95
  rafRef.current = requestAnimationFrame(()=>{
61
- const start = screenToFlowPosition(dragStartRef.current, {
62
- snapToGrid: false
63
- });
64
- const current = screenToFlowPosition({
65
- x: e.clientX,
66
- y: e.clientY
67
- }, {
68
- snapToGrid: false
69
- });
70
- const delta = {
71
- x: current.x - start.x,
72
- y: current.y - start.y
73
- };
74
- if ('waypoint' === dragState.type) {
75
- const initial = dragState.initialWaypoints[dragState.waypointIndex];
76
- if (!initial) return;
77
- updateWaypoints((0, external_waypoints_cjs_namespaceObject.moveWaypoint)(dragState.initialWaypoints, dragState.waypointIndex, {
78
- x: initial.x + delta.x,
79
- y: initial.y + delta.y
80
- }));
81
- } else if ('segment' === dragState.type) updateWaypoints((0, external_waypoints_cjs_namespaceObject.moveSegmentByDelta)(dragState.initialWaypoints, dragState.segment, delta, dragState.initialPathPoints));
96
+ rafRef.current = null;
97
+ const next = computeDrag(client, true);
98
+ if (next) updateWaypoints(next);
82
99
  });
83
100
  };
84
101
  const handleMouseUp = ()=>{
@@ -86,10 +103,14 @@ function useWaypointEditor(args) {
86
103
  cancelAnimationFrame(rafRef.current);
87
104
  rafRef.current = null;
88
105
  }
106
+ const pointer = lastPointerRef.current;
107
+ const final = pointer && computeDrag(pointer, false);
108
+ if (final && !(0, external_waypoints_cjs_namespaceObject.waypointsEqual)(final, dragState.initialWaypoints)) updateWaypoints('waypoint' === dragState.type ? (0, external_waypoints_cjs_namespaceObject.normalizeWaypoints)(final, buildPathRef.current) : final);
89
109
  setDragState({
90
110
  type: 'none'
91
111
  });
92
112
  dragStartRef.current = null;
113
+ lastPointerRef.current = null;
93
114
  };
94
115
  window.addEventListener('mousemove', handleMouseMove);
95
116
  window.addEventListener('mouseup', handleMouseUp);
@@ -104,21 +125,30 @@ function useWaypointEditor(args) {
104
125
  updateWaypoints,
105
126
  screenToFlowPosition
106
127
  ]);
128
+ const beginDrag = (0, external_react_namespaceObject.useCallback)((e, state)=>{
129
+ e.stopPropagation();
130
+ e.preventDefault();
131
+ dragStartRef.current = {
132
+ x: e.clientX,
133
+ y: e.clientY
134
+ };
135
+ lastPointerRef.current = null;
136
+ setDragState(state);
137
+ }, []);
107
138
  const waypointHandlers = (0, external_react_namespaceObject.useMemo)(()=>({
108
139
  onMouseDown: (index, e)=>{
109
140
  if (!enabled) return;
110
- e.stopPropagation();
111
- e.preventDefault();
112
- dragStartRef.current = {
113
- x: e.clientX,
114
- y: e.clientY
115
- };
116
- setDragState({
141
+ const initialPathPoints = [
142
+ ...pathPointsRef.current
143
+ ];
144
+ beginDrag(e, {
117
145
  type: 'waypoint',
118
146
  waypointIndex: index,
119
147
  initialWaypoints: [
120
148
  ...waypointsRef.current
121
- ]
149
+ ],
150
+ initialPathPoints,
151
+ mode: (0, external_waypoints_cjs_namespaceObject.isCornerWaypoint)(initialPathPoints, index) ? 'corner' : 'run'
122
152
  });
123
153
  },
124
154
  onDoubleClick: (index)=>{
@@ -127,19 +157,14 @@ function useWaypointEditor(args) {
127
157
  }
128
158
  }), [
129
159
  enabled,
160
+ beginDrag,
130
161
  updateWaypoints
131
162
  ]);
132
163
  const segmentHandlers = (0, external_react_namespaceObject.useMemo)(()=>({
133
164
  onMouseDown: (segment, e)=>{
134
165
  if (!enabled) return;
135
- e.stopPropagation();
136
- e.preventDefault();
137
- dragStartRef.current = {
138
- x: e.clientX,
139
- y: e.clientY
140
- };
141
166
  const materialized = (0, external_waypoints_cjs_namespaceObject.materializePathWaypoints)(pathPointsRef.current, waypointsRef.current);
142
- setDragState({
167
+ beginDrag(e, {
143
168
  type: 'segment',
144
169
  segment,
145
170
  initialWaypoints: materialized,
@@ -161,6 +186,7 @@ function useWaypointEditor(args) {
161
186
  }
162
187
  }), [
163
188
  enabled,
189
+ beginDrag,
164
190
  screenToFlowPosition,
165
191
  updateWaypoints
166
192
  ]);
@@ -1,10 +1,12 @@
1
1
  import type { PathVertex, Segment, Waypoint } from '../types';
2
+ import { type PathBuilder } from '../waypoints';
2
3
  export type UseWaypointEditorArgs = {
3
4
  edgeId: string;
4
5
  waypoints: Waypoint[];
5
6
  pathPoints: PathVertex[];
6
7
  enabled: boolean;
7
8
  onChange?: (next: Waypoint[]) => void;
9
+ buildPath: PathBuilder;
8
10
  };
9
11
  export type WaypointHandlers = {
10
12
  onMouseDown: (index: number, e: React.MouseEvent) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"useWaypointEditor.d.ts","sourceRoot":"","sources":["../../../../../../src/canvas/components/Edges/shared/hooks/useWaypointEditor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAS,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAqBrE,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,UAAU,EAAE,UAAU,EAAE,CAAC;IAMzB,OAAO,EAAE,OAAO,CAAC;IAKjB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,QA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MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAC1D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;IAC7D,aAAa,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAC;CACpE,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,OAAO,CAAC;IAEpB,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAmBF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,cAAc,CAsL7E"}
@@ -1,10 +1,10 @@
1
1
  import { useReactFlow } from "../../../../xyflow/react.js";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { snapPointToGrid } from "../geometry.js";
4
- import { insertWaypoint, materializePathWaypoints, moveSegmentByDelta, moveWaypoint, removeWaypoint, waypointsEqual } from "../waypoints.js";
4
+ import { insertWaypoint, isCornerWaypoint, materializePathWaypoints, moveCornerWaypoint, moveSegmentByDelta, moveWaypointConstrained, normalizeWaypoints, removeWaypoint, waypointsEqual } from "../waypoints.js";
5
5
  import { useEdgeWaypointWriter } from "./useEdgeWaypointWriter.js";
6
6
  function useWaypointEditor(args) {
7
- const { edgeId, waypoints, pathPoints, enabled, onChange } = args;
7
+ const { edgeId, waypoints, pathPoints, enabled, onChange, buildPath } = args;
8
8
  const { screenToFlowPosition } = useReactFlow();
9
9
  const writeWaypoints = useEdgeWaypointWriter(edgeId, onChange);
10
10
  const [dragState, setDragState] = useState({
@@ -12,11 +12,14 @@ function useWaypointEditor(args) {
12
12
  });
13
13
  const dragStartRef = useRef(null);
14
14
  const rafRef = useRef(null);
15
+ const lastPointerRef = useRef(null);
15
16
  const waypointsRef = useRef(waypoints);
16
17
  const pathPointsRef = useRef(pathPoints);
18
+ const buildPathRef = useRef(buildPath);
17
19
  useEffect(()=>{
18
20
  waypointsRef.current = waypoints;
19
21
  pathPointsRef.current = pathPoints;
22
+ buildPathRef.current = buildPath;
20
23
  });
21
24
  const updateWaypoints = useCallback((next)=>{
22
25
  if (waypointsEqual(waypointsRef.current, next)) return;
@@ -26,31 +29,45 @@ function useWaypointEditor(args) {
26
29
  ]);
27
30
  useEffect(()=>{
28
31
  if (!enabled || 'none' === dragState.type) return;
32
+ let lastTarget = null;
33
+ const computeDrag = (client, skipSameCell)=>{
34
+ const start = screenToFlowPosition(dragStartRef.current, {
35
+ snapToGrid: false
36
+ });
37
+ const current = screenToFlowPosition(client, {
38
+ snapToGrid: false
39
+ });
40
+ const delta = {
41
+ x: current.x - start.x,
42
+ y: current.y - start.y
43
+ };
44
+ if ('waypoint' === dragState.type) {
45
+ const { initialWaypoints, waypointIndex, initialPathPoints, mode } = dragState;
46
+ const initial = initialWaypoints[waypointIndex];
47
+ if (!initial) return null;
48
+ const target = snapPointToGrid({
49
+ x: initial.x + delta.x,
50
+ y: initial.y + delta.y
51
+ });
52
+ if (skipSameCell && lastTarget?.x === target.x && lastTarget.y === target.y) return null;
53
+ lastTarget = target;
54
+ return 'corner' === mode ? moveCornerWaypoint(initialWaypoints, waypointIndex, target, initialPathPoints) : moveWaypointConstrained(initialWaypoints, waypointIndex, target, buildPathRef.current);
55
+ }
56
+ if ('segment' === dragState.type) return moveSegmentByDelta(dragState.initialWaypoints, dragState.segment, delta, dragState.initialPathPoints);
57
+ return null;
58
+ };
29
59
  const handleMouseMove = (e)=>{
30
60
  if (!dragStartRef.current) return;
61
+ const client = {
62
+ x: e.clientX,
63
+ y: e.clientY
64
+ };
65
+ lastPointerRef.current = client;
31
66
  if (null !== rafRef.current) cancelAnimationFrame(rafRef.current);
32
67
  rafRef.current = requestAnimationFrame(()=>{
33
- const start = screenToFlowPosition(dragStartRef.current, {
34
- snapToGrid: false
35
- });
36
- const current = screenToFlowPosition({
37
- x: e.clientX,
38
- y: e.clientY
39
- }, {
40
- snapToGrid: false
41
- });
42
- const delta = {
43
- x: current.x - start.x,
44
- y: current.y - start.y
45
- };
46
- if ('waypoint' === dragState.type) {
47
- const initial = dragState.initialWaypoints[dragState.waypointIndex];
48
- if (!initial) return;
49
- updateWaypoints(moveWaypoint(dragState.initialWaypoints, dragState.waypointIndex, {
50
- x: initial.x + delta.x,
51
- y: initial.y + delta.y
52
- }));
53
- } else if ('segment' === dragState.type) updateWaypoints(moveSegmentByDelta(dragState.initialWaypoints, dragState.segment, delta, dragState.initialPathPoints));
68
+ rafRef.current = null;
69
+ const next = computeDrag(client, true);
70
+ if (next) updateWaypoints(next);
54
71
  });
55
72
  };
56
73
  const handleMouseUp = ()=>{
@@ -58,10 +75,14 @@ function useWaypointEditor(args) {
58
75
  cancelAnimationFrame(rafRef.current);
59
76
  rafRef.current = null;
60
77
  }
78
+ const pointer = lastPointerRef.current;
79
+ const final = pointer && computeDrag(pointer, false);
80
+ if (final && !waypointsEqual(final, dragState.initialWaypoints)) updateWaypoints('waypoint' === dragState.type ? normalizeWaypoints(final, buildPathRef.current) : final);
61
81
  setDragState({
62
82
  type: 'none'
63
83
  });
64
84
  dragStartRef.current = null;
85
+ lastPointerRef.current = null;
65
86
  };
66
87
  window.addEventListener('mousemove', handleMouseMove);
67
88
  window.addEventListener('mouseup', handleMouseUp);
@@ -76,21 +97,30 @@ function useWaypointEditor(args) {
76
97
  updateWaypoints,
77
98
  screenToFlowPosition
78
99
  ]);
100
+ const beginDrag = useCallback((e, state)=>{
101
+ e.stopPropagation();
102
+ e.preventDefault();
103
+ dragStartRef.current = {
104
+ x: e.clientX,
105
+ y: e.clientY
106
+ };
107
+ lastPointerRef.current = null;
108
+ setDragState(state);
109
+ }, []);
79
110
  const waypointHandlers = useMemo(()=>({
80
111
  onMouseDown: (index, e)=>{
81
112
  if (!enabled) return;
82
- e.stopPropagation();
83
- e.preventDefault();
84
- dragStartRef.current = {
85
- x: e.clientX,
86
- y: e.clientY
87
- };
88
- setDragState({
113
+ const initialPathPoints = [
114
+ ...pathPointsRef.current
115
+ ];
116
+ beginDrag(e, {
89
117
  type: 'waypoint',
90
118
  waypointIndex: index,
91
119
  initialWaypoints: [
92
120
  ...waypointsRef.current
93
- ]
121
+ ],
122
+ initialPathPoints,
123
+ mode: isCornerWaypoint(initialPathPoints, index) ? 'corner' : 'run'
94
124
  });
95
125
  },
96
126
  onDoubleClick: (index)=>{
@@ -99,19 +129,14 @@ function useWaypointEditor(args) {
99
129
  }
100
130
  }), [
101
131
  enabled,
132
+ beginDrag,
102
133
  updateWaypoints
103
134
  ]);
104
135
  const segmentHandlers = useMemo(()=>({
105
136
  onMouseDown: (segment, e)=>{
106
137
  if (!enabled) return;
107
- e.stopPropagation();
108
- e.preventDefault();
109
- dragStartRef.current = {
110
- x: e.clientX,
111
- y: e.clientY
112
- };
113
138
  const materialized = materializePathWaypoints(pathPointsRef.current, waypointsRef.current);
114
- setDragState({
139
+ beginDrag(e, {
115
140
  type: 'segment',
116
141
  segment,
117
142
  initialWaypoints: materialized,
@@ -133,6 +158,7 @@ function useWaypointEditor(args) {
133
158
  }
134
159
  }), [
135
160
  enabled,
161
+ beginDrag,
136
162
  screenToFlowPosition,
137
163
  updateWaypoints
138
164
  ]);