likec4 1.7.4 → 1.8.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.
@@ -4,6 +4,98 @@ import { createPortal } from "react-dom";
4
4
  function getDefaultExportFromCjs(x) {
5
5
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
6
6
  }
7
+ var withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
8
+ /**
9
+ * @license React
10
+ * use-sync-external-store-shim.production.min.js
11
+ *
12
+ * Copyright (c) Facebook, Inc. and its affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ */
17
+ var e = React__default;
18
+ function h$1(a, b) {
19
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
20
+ }
21
+ var k = typeof Object.is == "function" ? Object.is : h$1, l = e.useState, m = e.useEffect, n$1 = e.useLayoutEffect, p$1 = e.useDebugValue;
22
+ function q$1(a, b) {
23
+ var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
24
+ return n$1(function() {
25
+ c.value = d, c.getSnapshot = b, r$1(c) && g({ inst: c });
26
+ }, [a, d, b]), m(function() {
27
+ return r$1(c) && g({ inst: c }), a(function() {
28
+ r$1(c) && g({ inst: c });
29
+ });
30
+ }, [a]), p$1(d), d;
31
+ }
32
+ function r$1(a) {
33
+ var b = a.getSnapshot;
34
+ a = a.value;
35
+ try {
36
+ var d = b();
37
+ return !k(a, d);
38
+ } catch {
39
+ return !0;
40
+ }
41
+ }
42
+ function t$1(a, b) {
43
+ return b();
44
+ }
45
+ var u$1 = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t$1 : q$1;
46
+ useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u$1;
47
+ shim.exports;
48
+ shim.exports = useSyncExternalStoreShim_production_min;
49
+ var shimExports = shim.exports;
50
+ /**
51
+ * @license React
52
+ * use-sync-external-store-shim/with-selector.production.min.js
53
+ *
54
+ * Copyright (c) Facebook, Inc. and its affiliates.
55
+ *
56
+ * This source code is licensed under the MIT license found in the
57
+ * LICENSE file in the root directory of this source tree.
58
+ */
59
+ var h = React__default, n = shimExports;
60
+ function p(a, b) {
61
+ return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
62
+ }
63
+ var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
64
+ withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e2, l2, g) {
65
+ var c = t(null);
66
+ if (c.current === null) {
67
+ var f = { hasValue: !1, value: null };
68
+ c.current = f;
69
+ } else f = c.current;
70
+ c = v(function() {
71
+ function a2(a3) {
72
+ if (!c2) {
73
+ if (c2 = !0, d2 = a3, a3 = l2(a3), g !== void 0 && f.hasValue) {
74
+ var b2 = f.value;
75
+ if (g(b2, a3)) return k2 = b2;
76
+ }
77
+ return k2 = a3;
78
+ }
79
+ if (b2 = k2, q(d2, a3)) return b2;
80
+ var e3 = l2(a3);
81
+ return g !== void 0 && g(b2, e3) ? b2 : (d2 = a3, k2 = e3);
82
+ }
83
+ var c2 = !1, d2, k2, m2 = e2 === void 0 ? null : e2;
84
+ return [function() {
85
+ return a2(b());
86
+ }, m2 === null ? void 0 : function() {
87
+ return a2(m2());
88
+ }];
89
+ }, [b, e2, l2, g]);
90
+ var d = r(a, c[0], c[1]);
91
+ return u(function() {
92
+ f.hasValue = !0, f.value = d;
93
+ }, [d]), w(d), d;
94
+ };
95
+ withSelector.exports;
96
+ withSelector.exports = withSelector_production_min;
97
+ var withSelectorExports = withSelector.exports;
98
+ const useSyncExternalStoreExports = /* @__PURE__ */ getDefaultExportFromCjs(withSelectorExports);
7
99
  function cc(names) {
8
100
  if (typeof names == "string" || typeof names == "number") return "" + names;
9
101
  let out = "";
@@ -2155,7 +2247,7 @@ const errorMessages = {
2155
2247
  error006: () => "Can't create edge. An edge needs a source and a target.",
2156
2248
  error007: (id2) => `The old edge with id=${id2} does not exist.`,
2157
2249
  error009: (type) => `Marker type "${type}" doesn't exist.`,
2158
- error008: (handleType, { id: id2, sourceHandle, targetHandle }) => `Couldn't create edge for ${handleType} handle id: "${sourceHandle && targetHandle}", edge id: ${id2}.`,
2250
+ error008: (handleType, { id: id2, sourceHandle, targetHandle }) => `Couldn't create edge for ${handleType} handle id: "${handleType === "source" ? sourceHandle : targetHandle}", edge id: ${id2}.`,
2159
2251
  error010: () => "Handle: No node id found. Make sure to only use a Handle inside a custom Node.",
2160
2252
  error011: (edgeType) => `Edge type "${edgeType}" not found. Using fallback type "default".`,
2161
2253
  error012: (id2) => `Node with id "${id2}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,
@@ -2231,12 +2323,12 @@ const isEdgeBase = (element) => "id" in element && "source" in element && "targe
2231
2323
  width: rect.width / tScale,
2232
2324
  height: rect.height / tScale
2233
2325
  }, visibleNodes = [];
2234
- for (const [, node] of nodes) {
2235
- const { measured, selectable = !0, hidden = !1 } = node, width = measured.width ?? node.width ?? node.initialWidth ?? null, height = measured.height ?? node.height ?? node.initialHeight ?? null;
2326
+ for (const node of nodes.values()) {
2327
+ const { measured, selectable = !0, hidden = !1 } = node;
2236
2328
  if (excludeNonSelectableNodes && !selectable || hidden)
2237
2329
  continue;
2238
- const overlappingArea = getOverlappingArea(paneRect, nodeToRect(node)), notInitialized = width === null || height === null, partiallyVisible = partially && overlappingArea > 0, area = (width ?? 0) * (height ?? 0);
2239
- (notInitialized || partiallyVisible || overlappingArea >= area || node.dragging) && visibleNodes.push(node);
2330
+ const width = measured.width ?? node.width ?? node.initialWidth ?? null, height = measured.height ?? node.height ?? node.initialHeight ?? null, overlappingArea = getOverlappingArea(paneRect, nodeToRect(node)), area = (width ?? 0) * (height ?? 0), partiallyVisible = partially && overlappingArea > 0;
2331
+ (!node.internals.handleBounds || partiallyVisible || overlappingArea >= area || node.dragging) && visibleNodes.push(node);
2240
2332
  }
2241
2333
  return visibleNodes;
2242
2334
  }, getConnectedEdges = (nodes, edges) => {
@@ -2603,7 +2695,7 @@ function getEdgePosition(params) {
2603
2695
  const { sourceNode, targetNode } = params;
2604
2696
  if (!isNodeInitialized(sourceNode) || !isNodeInitialized(targetNode))
2605
2697
  return null;
2606
- const sourceHandleBounds = sourceNode.internals.handleBounds || toHandleBounds(sourceNode.handles), targetHandleBounds = targetNode.internals.handleBounds || toHandleBounds(targetNode.handles), sourceHandle = getHandle(sourceHandleBounds?.source ?? [], params.sourceHandle), targetHandle = getHandle(
2698
+ const sourceHandleBounds = sourceNode.internals.handleBounds || toHandleBounds(sourceNode.handles), targetHandleBounds = targetNode.internals.handleBounds || toHandleBounds(targetNode.handles), sourceHandle = getHandle$1(sourceHandleBounds?.source ?? [], params.sourceHandle), targetHandle = getHandle$1(
2607
2699
  // when connection type is loose we can define all handles as sources and connect source -> source
2608
2700
  params.connectionMode === ConnectionMode.Strict ? targetHandleBounds?.target ?? [] : (targetHandleBounds?.target ?? []).concat(targetHandleBounds?.source ?? []),
2609
2701
  params.targetHandle
@@ -2650,7 +2742,7 @@ function getHandlePosition(node, handle, fallbackPosition = Position.Left, cente
2650
2742
  return { x, y: y + height / 2 };
2651
2743
  }
2652
2744
  }
2653
- function getHandle(bounds, handleId) {
2745
+ function getHandle$1(bounds, handleId) {
2654
2746
  return bounds && (handleId ? bounds.find((d) => d.id === handleId) : bounds[0]) || null;
2655
2747
  }
2656
2748
  function getMarkerId(marker, id2) {
@@ -3008,46 +3100,44 @@ function XYDrag({ onNodeMouseDown, getStoreItems, onDragStart, onDrag, onDragSto
3008
3100
  destroy
3009
3101
  };
3010
3102
  }
3011
- function getHandles(node, handleBounds, type, currentHandle) {
3012
- let excludedHandle = null;
3013
- return [(handleBounds[type] || []).reduce((res, handle) => {
3014
- if (node.id === currentHandle.nodeId && type === currentHandle.handleType && handle.id === currentHandle.handleId)
3015
- excludedHandle = handle;
3016
- else {
3017
- const handleXY = getHandlePosition(node, handle, handle.position, !0);
3018
- res.push({ ...handle, ...handleXY });
3019
- }
3020
- return res;
3021
- }, []), excludedHandle];
3103
+ function getNodesWithinDistance(position, nodeLookup, distance2) {
3104
+ const nodes = [], rect = {
3105
+ x: position.x - distance2,
3106
+ y: position.y - distance2,
3107
+ width: distance2 * 2,
3108
+ height: distance2 * 2
3109
+ };
3110
+ for (const node of nodeLookup.values())
3111
+ getOverlappingArea(rect, nodeToRect(node)) > 0 && nodes.push(node);
3112
+ return nodes;
3022
3113
  }
3023
- function getClosestHandle(pos, connectionRadius, handleLookup) {
3114
+ const ADDITIONAL_DISTANCE = 250;
3115
+ function getClosestHandle(position, connectionRadius, nodeLookup, fromHandle) {
3024
3116
  let closestHandles = [], minDistance = 1 / 0;
3025
- for (const handle of handleLookup.values()) {
3026
- const distance2 = Math.sqrt(Math.pow(handle.x - pos.x, 2) + Math.pow(handle.y - pos.y, 2));
3027
- distance2 <= connectionRadius && (distance2 < minDistance ? closestHandles = [handle] : distance2 === minDistance && closestHandles.push(handle), minDistance = distance2);
3028
- }
3029
- return closestHandles.length ? closestHandles.length === 1 ? closestHandles[0] : (
3030
- // if multiple handles are layouted on top of each other we take the one with type = target because it's more likely that the user wants to connect to this one
3031
- closestHandles.find((handle) => handle.type === "target") || closestHandles[0]
3032
- ) : null;
3033
- }
3034
- function getHandleLookup({ nodeLookup, nodeId, handleId, handleType }) {
3035
- const connectionHandles = /* @__PURE__ */ new Map(), currentHandle = { nodeId, handleId, handleType };
3036
- let matchingHandle = null;
3037
- for (const node of nodeLookup.values())
3038
- if (node.internals.handleBounds) {
3039
- const [sourceHandles, excludedSource] = getHandles(node, node.internals.handleBounds, "source", currentHandle), [targetHandles, excludedTarget] = getHandles(node, node.internals.handleBounds, "target", currentHandle);
3040
- matchingHandle = matchingHandle || (excludedSource ?? excludedTarget), [...sourceHandles, ...targetHandles].forEach((handle) => connectionHandles.set(`${handle.nodeId}-${handle.type}-${handle.id}`, handle));
3041
- }
3042
- if (!matchingHandle) {
3043
- const node = nodeLookup.get(nodeId);
3044
- if (node?.internals.handleBounds) {
3045
- currentHandle.handleType = handleType === "source" ? "target" : "source";
3046
- const [, excluded] = getHandles(node, node.internals.handleBounds, currentHandle.handleType, currentHandle);
3047
- matchingHandle = excluded;
3117
+ const closeNodes = getNodesWithinDistance(position, nodeLookup, connectionRadius + ADDITIONAL_DISTANCE);
3118
+ for (const node of closeNodes) {
3119
+ const allHandles = [...node.internals.handleBounds?.source ?? [], ...node.internals.handleBounds?.target ?? []];
3120
+ for (const handle of allHandles) {
3121
+ if (fromHandle.nodeId === handle.nodeId && fromHandle.type === handle.type && fromHandle.id === handle.id)
3122
+ continue;
3123
+ const { x, y } = getHandlePosition(node, handle, handle.position, !0), distance2 = Math.sqrt(Math.pow(x - position.x, 2) + Math.pow(y - position.y, 2));
3124
+ distance2 > connectionRadius || (distance2 < minDistance ? (closestHandles = [{ ...handle, x, y }], minDistance = distance2) : distance2 === minDistance && closestHandles.push({ ...handle, x, y }));
3048
3125
  }
3049
3126
  }
3050
- return [connectionHandles, matchingHandle];
3127
+ if (!closestHandles.length)
3128
+ return null;
3129
+ if (closestHandles.length > 1) {
3130
+ const oppositeHandleType = fromHandle.type === "source" ? "target" : "source";
3131
+ return closestHandles.find((handle) => handle.type === oppositeHandleType) ?? closestHandles[0];
3132
+ }
3133
+ return closestHandles[0];
3134
+ }
3135
+ function getHandle(nodeId, handleType, handleId, nodeLookup, withAbsolutePosition = !1) {
3136
+ const node = nodeLookup.get(nodeId);
3137
+ if (!node)
3138
+ return null;
3139
+ const handles = node.internals.handleBounds?.[handleType], handle = (handleId ? handles?.find((h2) => h2.id === handleId) : handles?.[0]) ?? null;
3140
+ return handle && withAbsolutePosition ? { ...handle, ...getHandlePosition(node, handle, handle.position, !0) } : handle;
3051
3141
  }
3052
3142
  function getHandleType(edgeUpdaterType, handleDomNode) {
3053
3143
  return edgeUpdaterType || (handleDomNode?.classList.contains("target") ? "target" : handleDomNode?.classList.contains("source") ? "source" : null);
@@ -3063,13 +3153,10 @@ function onPointerDown(event, { connectionMode, connectionRadius, handleId, node
3063
3153
  const { x, y } = getEventPosition(event), clickedHandle = doc?.elementFromPoint(x, y), handleType = getHandleType(edgeUpdaterType, clickedHandle), containerBounds = domNode?.getBoundingClientRect();
3064
3154
  if (!containerBounds || !handleType)
3065
3155
  return;
3156
+ const fromHandleInternal = getHandle(nodeId, handleType, handleId, nodeLookup);
3157
+ if (!fromHandleInternal)
3158
+ return;
3066
3159
  let position = getEventPosition(event, containerBounds), autoPanStarted = !1, connection = null, isValid = !1, handleDomNode = null;
3067
- const [handleLookup, fromHandleInternal] = getHandleLookup({
3068
- nodeLookup,
3069
- nodeId,
3070
- handleId,
3071
- handleType
3072
- });
3073
3160
  function autoPan() {
3074
3161
  if (!autoPanOnConnect || !containerBounds)
3075
3162
  return;
@@ -3102,7 +3189,7 @@ function onPointerDown(event, { connectionMode, connectionRadius, handleId, node
3102
3189
  return;
3103
3190
  }
3104
3191
  const transform2 = getTransform();
3105
- position = getEventPosition(event2, containerBounds), closestHandle = getClosestHandle(pointToRendererPoint(position, transform2, !1, [1, 1]), connectionRadius, handleLookup), autoPanStarted || (autoPan(), autoPanStarted = !0);
3192
+ position = getEventPosition(event2, containerBounds), closestHandle = getClosestHandle(pointToRendererPoint(position, transform2, !1, [1, 1]), connectionRadius, nodeLookup, fromHandle), autoPanStarted || (autoPan(), autoPanStarted = !0);
3106
3193
  const result = isValidHandle(event2, {
3107
3194
  handle: closestHandle,
3108
3195
  connectionMode,
@@ -3113,7 +3200,7 @@ function onPointerDown(event, { connectionMode, connectionRadius, handleId, node
3113
3200
  doc,
3114
3201
  lib,
3115
3202
  flowId,
3116
- handleLookup
3203
+ nodeLookup
3117
3204
  });
3118
3205
  handleDomNode = result.handleDomNode, connection = result.connection, isValid = isConnectionValid(!!closestHandle, result.isValid);
3119
3206
  const newConnection2 = {
@@ -3125,14 +3212,19 @@ function onPointerDown(event, { connectionMode, connectionRadius, handleId, node
3125
3212
  toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
3126
3213
  toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId) : null
3127
3214
  };
3128
- isValid && closestHandle && previousConnection.toHandle && newConnection2.toHandle && previousConnection.toHandle.type === newConnection2.toHandle.type && previousConnection.toHandle.nodeId === newConnection2.toHandle.nodeId && previousConnection.toHandle.id === newConnection2.toHandle.id || (updateConnection(newConnection2), previousConnection = newConnection2);
3215
+ isValid && closestHandle && previousConnection.toHandle && newConnection2.toHandle && previousConnection.toHandle.type === newConnection2.toHandle.type && previousConnection.toHandle.nodeId === newConnection2.toHandle.nodeId && previousConnection.toHandle.id === newConnection2.toHandle.id && previousConnection.to.x === newConnection2.to.x && previousConnection.to.y === newConnection2.to.y || (updateConnection(newConnection2), previousConnection = newConnection2);
3129
3216
  }
3130
3217
  function onPointerUp(event2) {
3131
- (closestHandle || handleDomNode) && connection && isValid && onConnect?.(connection), onConnectEnd?.(event2), edgeUpdaterType && onReconnectEnd?.(event2), cancelConnection(), cancelAnimationFrame(autoPanId), autoPanStarted = !1, isValid = !1, connection = null, handleDomNode = null, doc.removeEventListener("mousemove", onPointerMove), doc.removeEventListener("mouseup", onPointerUp), doc.removeEventListener("touchmove", onPointerMove), doc.removeEventListener("touchend", onPointerUp);
3218
+ (closestHandle || handleDomNode) && connection && isValid && onConnect?.(connection);
3219
+ const { inProgress, ...connectionState } = previousConnection, finalConnectionState = {
3220
+ ...connectionState,
3221
+ toPosition: previousConnection.toHandle ? previousConnection.toPosition : null
3222
+ };
3223
+ onConnectEnd?.(event2, finalConnectionState), edgeUpdaterType && onReconnectEnd?.(event2, finalConnectionState), cancelConnection(), cancelAnimationFrame(autoPanId), autoPanStarted = !1, isValid = !1, connection = null, handleDomNode = null, doc.removeEventListener("mousemove", onPointerMove), doc.removeEventListener("mouseup", onPointerUp), doc.removeEventListener("touchmove", onPointerMove), doc.removeEventListener("touchend", onPointerUp);
3132
3224
  }
3133
3225
  doc.addEventListener("mousemove", onPointerMove), doc.addEventListener("mouseup", onPointerUp), doc.addEventListener("touchmove", onPointerMove), doc.addEventListener("touchend", onPointerUp);
3134
3226
  }
3135
- function isValidHandle(event, { handle, connectionMode, fromNodeId, fromHandleId, fromType, doc, lib, flowId, isValidConnection = alwaysValid, handleLookup }) {
3227
+ function isValidHandle(event, { handle, connectionMode, fromNodeId, fromHandleId, fromType, doc, lib, flowId, isValidConnection = alwaysValid, nodeLookup }) {
3136
3228
  const isTarget = fromType === "target", handleDomNode = handle ? doc.querySelector(`.${lib}-flow__handle[data-id="${flowId}-${handle?.nodeId}-${handle?.id}-${handle?.type}"]`) : null, { x, y } = getEventPosition(event), handleBelow = doc.elementFromPoint(x, y), handleToCheck = handleBelow?.classList.contains(`${lib}-flow__handle`) ? handleBelow : handleDomNode, result = {
3137
3229
  handleDomNode: handleToCheck,
3138
3230
  isValid: !1,
@@ -3141,7 +3233,7 @@ function isValidHandle(event, { handle, connectionMode, fromNodeId, fromHandleId
3141
3233
  };
3142
3234
  if (handleToCheck) {
3143
3235
  const handleType = getHandleType(void 0, handleToCheck), handleNodeId = handleToCheck.getAttribute("data-nodeid"), handleId = handleToCheck.getAttribute("data-handleid"), connectable = handleToCheck.classList.contains("connectable"), connectableEnd = handleToCheck.classList.contains("connectableend");
3144
- if (!handleNodeId)
3236
+ if (!handleNodeId || !handleType)
3145
3237
  return result;
3146
3238
  const connection = {
3147
3239
  source: isTarget ? handleNodeId : fromNodeId,
@@ -3151,11 +3243,7 @@ function isValidHandle(event, { handle, connectionMode, fromNodeId, fromHandleId
3151
3243
  };
3152
3244
  result.connection = connection;
3153
3245
  const isValid = connectable && connectableEnd && (connectionMode === ConnectionMode.Strict ? isTarget && handleType === "source" || !isTarget && handleType === "target" : handleNodeId !== fromNodeId || handleId !== fromHandleId);
3154
- result.isValid = isValid && isValidConnection(connection);
3155
- const toHandle = handleLookup?.get(`${handleNodeId}-${handleType}-${handleId}`);
3156
- toHandle && (result.toHandle = {
3157
- ...toHandle
3158
- });
3246
+ result.isValid = isValid && isValidConnection(connection), result.toHandle = getHandle(handleNodeId, handleType, handleId, nodeLookup, !1);
3159
3247
  }
3160
3248
  return result;
3161
3249
  }
@@ -3609,98 +3697,6 @@ function XYResizer({ domNode, nodeId, getStoreItems, onChange, onEnd }) {
3609
3697
  destroy
3610
3698
  };
3611
3699
  }
3612
- var withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
3613
- /**
3614
- * @license React
3615
- * use-sync-external-store-shim.production.min.js
3616
- *
3617
- * Copyright (c) Facebook, Inc. and its affiliates.
3618
- *
3619
- * This source code is licensed under the MIT license found in the
3620
- * LICENSE file in the root directory of this source tree.
3621
- */
3622
- var e = React__default;
3623
- function h$1(a, b) {
3624
- return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
3625
- }
3626
- var k = typeof Object.is == "function" ? Object.is : h$1, l = e.useState, m = e.useEffect, n$1 = e.useLayoutEffect, p$1 = e.useDebugValue;
3627
- function q$1(a, b) {
3628
- var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
3629
- return n$1(function() {
3630
- c.value = d, c.getSnapshot = b, r$1(c) && g({ inst: c });
3631
- }, [a, d, b]), m(function() {
3632
- return r$1(c) && g({ inst: c }), a(function() {
3633
- r$1(c) && g({ inst: c });
3634
- });
3635
- }, [a]), p$1(d), d;
3636
- }
3637
- function r$1(a) {
3638
- var b = a.getSnapshot;
3639
- a = a.value;
3640
- try {
3641
- var d = b();
3642
- return !k(a, d);
3643
- } catch {
3644
- return !0;
3645
- }
3646
- }
3647
- function t$1(a, b) {
3648
- return b();
3649
- }
3650
- var u$1 = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t$1 : q$1;
3651
- useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u$1;
3652
- shim.exports;
3653
- shim.exports = useSyncExternalStoreShim_production_min;
3654
- var shimExports = shim.exports;
3655
- /**
3656
- * @license React
3657
- * use-sync-external-store-shim/with-selector.production.min.js
3658
- *
3659
- * Copyright (c) Facebook, Inc. and its affiliates.
3660
- *
3661
- * This source code is licensed under the MIT license found in the
3662
- * LICENSE file in the root directory of this source tree.
3663
- */
3664
- var h = React__default, n = shimExports;
3665
- function p(a, b) {
3666
- return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
3667
- }
3668
- var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
3669
- withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e2, l2, g) {
3670
- var c = t(null);
3671
- if (c.current === null) {
3672
- var f = { hasValue: !1, value: null };
3673
- c.current = f;
3674
- } else f = c.current;
3675
- c = v(function() {
3676
- function a2(a3) {
3677
- if (!c2) {
3678
- if (c2 = !0, d2 = a3, a3 = l2(a3), g !== void 0 && f.hasValue) {
3679
- var b2 = f.value;
3680
- if (g(b2, a3)) return k2 = b2;
3681
- }
3682
- return k2 = a3;
3683
- }
3684
- if (b2 = k2, q(d2, a3)) return b2;
3685
- var e3 = l2(a3);
3686
- return g !== void 0 && g(b2, e3) ? b2 : (d2 = a3, k2 = e3);
3687
- }
3688
- var c2 = !1, d2, k2, m2 = e2 === void 0 ? null : e2;
3689
- return [function() {
3690
- return a2(b());
3691
- }, m2 === null ? void 0 : function() {
3692
- return a2(m2());
3693
- }];
3694
- }, [b, e2, l2, g]);
3695
- var d = r(a, c[0], c[1]);
3696
- return u(function() {
3697
- f.hasValue = !0, f.value = d;
3698
- }, [d]), w(d), d;
3699
- };
3700
- withSelector.exports;
3701
- withSelector.exports = withSelector_production_min;
3702
- var withSelectorExports = withSelector.exports;
3703
- const useSyncExternalStoreExports = /* @__PURE__ */ getDefaultExportFromCjs(withSelectorExports);
3704
3700
  var define_import_meta_env_default = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 };
3705
3701
  const createStoreImpl = (createState) => {
3706
3702
  let state;
@@ -3785,23 +3781,23 @@ const style = { display: "none" }, ariaLiveStyle = {
3785
3781
  overflow: "hidden",
3786
3782
  clip: "rect(0px, 0px, 0px, 0px)",
3787
3783
  clipPath: "inset(100%)"
3788
- }, ARIA_NODE_DESC_KEY = "react-flow__node-desc", ARIA_EDGE_DESC_KEY = "react-flow__edge-desc", ARIA_LIVE_MESSAGE = "react-flow__aria-live", selector$p = (s) => s.ariaLiveMessage;
3784
+ }, ARIA_NODE_DESC_KEY = "react-flow__node-desc", ARIA_EDGE_DESC_KEY = "react-flow__edge-desc", ARIA_LIVE_MESSAGE = "react-flow__aria-live", selector$o = (s) => s.ariaLiveMessage;
3789
3785
  function AriaLiveMessage({ rfId }) {
3790
- const ariaLiveMessage = useStore(selector$p);
3786
+ const ariaLiveMessage = useStore(selector$o);
3791
3787
  return jsx("div", { id: `${ARIA_LIVE_MESSAGE}-${rfId}`, "aria-live": "assertive", "aria-atomic": "true", style: ariaLiveStyle, children: ariaLiveMessage });
3792
3788
  }
3793
3789
  function A11yDescriptions({ rfId, disableKeyboardA11y }) {
3794
3790
  return jsxs(Fragment, { children: [jsxs("div", { id: `${ARIA_NODE_DESC_KEY}-${rfId}`, style, children: ["Press enter or space to select a node.", !disableKeyboardA11y && "You can then use the arrow keys to move the node around.", " Press delete to remove it and escape to cancel.", " "] }), jsx("div", { id: `${ARIA_EDGE_DESC_KEY}-${rfId}`, style, children: "Press enter or space to select an edge. You can then press delete to remove it or escape to cancel." }), !disableKeyboardA11y && jsx(AriaLiveMessage, { rfId })] });
3795
3791
  }
3796
- const selector$o = (s) => s.userSelectionActive ? "none" : "all";
3792
+ const selector$n = (s) => s.userSelectionActive ? "none" : "all";
3797
3793
  function Panel({ position = "top-left", children: children2, className, style: style2, ...rest }) {
3798
- const pointerEvents = useStore(selector$o), positionClasses = `${position}`.split("-");
3794
+ const pointerEvents = useStore(selector$n), positionClasses = `${position}`.split("-");
3799
3795
  return jsx("div", { className: cc(["react-flow__panel", className, ...positionClasses]), style: { ...style2, pointerEvents }, ...rest, children: children2 });
3800
3796
  }
3801
3797
  function Attribution({ proOptions, position = "bottom-right" }) {
3802
3798
  return proOptions?.hideAttribution ? null : jsx(Panel, { position, className: "react-flow__attribution", "data-message": "Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev", children: jsx("a", { href: "https://reactflow.dev", target: "_blank", rel: "noopener noreferrer", "aria-label": "React Flow attribution", children: "React Flow" }) });
3803
3799
  }
3804
- const selector$n = (s) => {
3800
+ const selector$m = (s) => {
3805
3801
  const selectedNodes = [], selectedEdges = [];
3806
3802
  for (const [, node] of s.nodeLookup)
3807
3803
  node.selected && selectedNodes.push(node.internals.userNode);
@@ -3813,7 +3809,7 @@ function areEqual(a, b) {
3813
3809
  return shallow$1(a.selectedNodes.map(selectId), b.selectedNodes.map(selectId)) && shallow$1(a.selectedEdges.map(selectId), b.selectedEdges.map(selectId));
3814
3810
  }
3815
3811
  function SelectionListenerInner({ onSelectionChange }) {
3816
- const store = useStoreApi(), { selectedNodes, selectedEdges } = useStore(selector$n, areEqual);
3812
+ const store = useStoreApi(), { selectedNodes, selectedEdges } = useStore(selector$m, areEqual);
3817
3813
  return useEffect(() => {
3818
3814
  const params = { nodes: selectedNodes, edges: selectedEdges };
3819
3815
  onSelectionChange?.(params), store.getState().onSelectionChangeHandlers.forEach((fn) => fn(params));
@@ -3880,7 +3876,7 @@ const defaultNodeOrigin = [0, 0], defaultViewport = { x: 0, y: 0, zoom: 1 }, rea
3880
3876
  "debug",
3881
3877
  "autoPanSpeed",
3882
3878
  "paneClickDistance"
3883
- ], fieldsToTrack = [...reactFlowFieldsToTrack, "rfId"], selector$m = (s) => ({
3879
+ ], fieldsToTrack = [...reactFlowFieldsToTrack, "rfId"], selector$l = (s) => ({
3884
3880
  setNodes: s.setNodes,
3885
3881
  setEdges: s.setEdges,
3886
3882
  setMinZoom: s.setMinZoom,
@@ -3904,7 +3900,7 @@ const defaultNodeOrigin = [0, 0], defaultViewport = { x: 0, y: 0, zoom: 1 }, rea
3904
3900
  paneClickDistance: 0
3905
3901
  };
3906
3902
  function StoreUpdater(props) {
3907
- const { setNodes, setEdges, setMinZoom, setMaxZoom, setTranslateExtent, setNodeExtent, reset, setDefaultNodesAndEdges, setPaneClickDistance } = useStore(selector$m, shallow$1), store = useStoreApi();
3903
+ const { setNodes, setEdges, setMinZoom, setMaxZoom, setTranslateExtent, setNodeExtent, reset, setDefaultNodesAndEdges, setPaneClickDistance } = useStore(selector$l, shallow$1), store = useStoreApi();
3908
3904
  useEffect(() => (setDefaultNodesAndEdges(props.defaultNodes, props.defaultEdges), () => {
3909
3905
  previousFields.current = initPrevValues, reset();
3910
3906
  }), []);
@@ -4188,9 +4184,9 @@ function useBatchContext() {
4188
4184
  throw new Error("useBatchContext must be used within a BatchProvider");
4189
4185
  return batchContext;
4190
4186
  }
4191
- const selector$l = (s) => !!s.panZoom;
4187
+ const selector$k = (s) => !!s.panZoom;
4192
4188
  function useReactFlow() {
4193
- const viewportHelper = useViewportHelper(), store = useStoreApi(), batchContext = useBatchContext(), viewportInitialized = useStore(selector$l), generalHelper = useMemo(() => {
4189
+ const viewportHelper = useViewportHelper(), store = useStoreApi(), batchContext = useBatchContext(), viewportInitialized = useStore(selector$k), generalHelper = useMemo(() => {
4194
4190
  const getInternalNode = (id2) => store.getState().nodeLookup.get(id2), setNodes = (payload) => {
4195
4191
  batchContext.nodeQueue.push(payload);
4196
4192
  }, setEdges = (payload) => {
@@ -4345,12 +4341,12 @@ const containerStyle = {
4345
4341
  height: "100%",
4346
4342
  top: 0,
4347
4343
  left: 0
4348
- }, selector$k = (s) => ({
4344
+ }, selector$j = (s) => ({
4349
4345
  userSelectionActive: s.userSelectionActive,
4350
4346
  lib: s.lib
4351
4347
  });
4352
4348
  function ZoomPane({ onPaneContextMenu, zoomOnScroll = !0, zoomOnPinch = !0, panOnScroll = !1, panOnScrollSpeed = 0.5, panOnScrollMode = PanOnScrollMode.Free, zoomOnDoubleClick = !0, panOnDrag = !0, defaultViewport: defaultViewport2, translateExtent, minZoom, maxZoom, zoomActivationKeyCode, preventScrolling = !0, children: children2, noWheelClassName, noPanClassName, onViewportChange, isControlledViewport, paneClickDistance }) {
4353
- const store = useStoreApi(), zoomPane = useRef(null), { userSelectionActive, lib } = useStore(selector$k, shallow$1), zoomActivationKeyPressed = useKeyPress(zoomActivationKeyCode), panZoom = useRef();
4349
+ const store = useStoreApi(), zoomPane = useRef(null), { userSelectionActive, lib } = useStore(selector$j, shallow$1), zoomActivationKeyPressed = useKeyPress(zoomActivationKeyCode), panZoom = useRef();
4354
4350
  return useResizeHandler(zoomPane), useEffect(() => {
4355
4351
  if (zoomPane.current) {
4356
4352
  panZoom.current = XYPanZoom({
@@ -4420,12 +4416,12 @@ function ZoomPane({ onPaneContextMenu, zoomOnScroll = !0, zoomOnPinch = !0, panO
4420
4416
  lib
4421
4417
  ]), jsx("div", { className: "react-flow__renderer", ref: zoomPane, style: containerStyle, children: children2 });
4422
4418
  }
4423
- const selector$j = (s) => ({
4419
+ const selector$i = (s) => ({
4424
4420
  userSelectionActive: s.userSelectionActive,
4425
4421
  userSelectionRect: s.userSelectionRect
4426
4422
  });
4427
4423
  function UserSelection() {
4428
- const { userSelectionActive, userSelectionRect } = useStore(selector$j, shallow$1);
4424
+ const { userSelectionActive, userSelectionRect } = useStore(selector$i, shallow$1);
4429
4425
  return userSelectionActive && userSelectionRect ? jsx("div", { className: "react-flow__selection react-flow__container", style: {
4430
4426
  width: userSelectionRect.width,
4431
4427
  height: userSelectionRect.height,
@@ -4434,13 +4430,13 @@ function UserSelection() {
4434
4430
  }
4435
4431
  const wrapHandler = (handler, containerRef) => (event) => {
4436
4432
  event.target === containerRef.current && handler?.(event);
4437
- }, selector$i = (s) => ({
4433
+ }, selector$h = (s) => ({
4438
4434
  userSelectionActive: s.userSelectionActive,
4439
4435
  elementsSelectable: s.elementsSelectable,
4440
4436
  dragging: s.paneDragging
4441
4437
  });
4442
4438
  function Pane({ isSelecting, selectionKeyPressed, selectionMode = SelectionMode.Full, panOnDrag, selectionOnDrag, onSelectionStart, onSelectionEnd, onPaneClick, onPaneContextMenu, onPaneScroll, onPaneMouseEnter, onPaneMouseMove, onPaneMouseLeave, children: children2 }) {
4443
- const container = useRef(null), store = useStoreApi(), prevSelectedNodesCount = useRef(0), prevSelectedEdgesCount = useRef(0), containerBounds = useRef(), edgeIdLookup = useRef(/* @__PURE__ */ new Map()), { userSelectionActive, elementsSelectable, dragging } = useStore(selector$i, shallow$1), hasActiveSelection = elementsSelectable && (isSelecting || userSelectionActive), selectionInProgress = useRef(!1), selectionStarted = useRef(!1), resetUserSelection = () => {
4439
+ const container = useRef(null), store = useStoreApi(), prevSelectedNodesCount = useRef(0), prevSelectedEdgesCount = useRef(0), containerBounds = useRef(), edgeIdLookup = useRef(/* @__PURE__ */ new Map()), { userSelectionActive, elementsSelectable, dragging } = useStore(selector$h, shallow$1), hasActiveSelection = elementsSelectable && (isSelecting || userSelectionActive), selectionInProgress = useRef(!1), selectionStarted = useRef(!1), resetUserSelection = () => {
4444
4440
  store.setState({ userSelectionActive: !1, userSelectionRect: null }), prevSelectedNodesCount.current = 0, prevSelectedEdgesCount.current = 0;
4445
4441
  }, onClick = (event) => {
4446
4442
  if (selectionInProgress.current) {
@@ -4513,8 +4509,8 @@ function Pane({ isSelecting, selectionKeyPressed, selectionMode = SelectionMode.
4513
4509
  event.target?.releasePointerCapture?.(event.pointerId);
4514
4510
  const { userSelectionRect } = store.getState();
4515
4511
  !userSelectionActive && userSelectionRect && event.target === container.current && onClick?.(event), prevSelectedNodesCount.current > 0 && store.setState({ nodesSelectionActive: !0 }), resetUserSelection(), onSelectionEnd?.(event), (selectionKeyPressed || selectionOnDrag) && (selectionInProgress.current = !1), selectionStarted.current = !1;
4516
- };
4517
- return jsxs("div", { className: cc(["react-flow__pane", { draggable: panOnDrag, dragging, selection: isSelecting }]), onClick: hasActiveSelection ? void 0 : wrapHandler(onClick, container), onContextMenu: wrapHandler(onContextMenu, container), onWheel: wrapHandler(onWheel, container), onPointerEnter: hasActiveSelection ? void 0 : onPaneMouseEnter, onPointerDown: hasActiveSelection ? onPointerDown2 : onPaneMouseMove, onPointerMove: hasActiveSelection ? onPointerMove : onPaneMouseMove, onPointerUp: hasActiveSelection ? onPointerUp : void 0, onPointerLeave: onPaneMouseLeave, ref: container, style: containerStyle, children: [children2, jsx(UserSelection, {})] });
4512
+ }, draggable = panOnDrag === !0 || Array.isArray(panOnDrag) && panOnDrag.includes(0);
4513
+ return jsxs("div", { className: cc(["react-flow__pane", { draggable, dragging, selection: isSelecting }]), onClick: hasActiveSelection ? void 0 : wrapHandler(onClick, container), onContextMenu: wrapHandler(onContextMenu, container), onWheel: wrapHandler(onWheel, container), onPointerEnter: hasActiveSelection ? void 0 : onPaneMouseEnter, onPointerDown: hasActiveSelection ? onPointerDown2 : onPaneMouseMove, onPointerMove: hasActiveSelection ? onPointerMove : onPaneMouseMove, onPointerUp: hasActiveSelection ? onPointerUp : void 0, onPointerLeave: onPaneMouseLeave, ref: container, style: containerStyle, children: [children2, jsx(UserSelection, {})] });
4518
4514
  }
4519
4515
  function handleNodeClick({ id: id2, store, unselect = !1, nodeRef }) {
4520
4516
  const { addSelectedNodes, unselectNodesAndEdges, multiSelectionActive, nodeLookup, onError } = store.getState(), node = nodeLookup.get(id2);
@@ -4587,7 +4583,7 @@ function useMoveSelectedNodes() {
4587
4583
  }
4588
4584
  const NodeIdContext = createContext(null), Provider = NodeIdContext.Provider;
4589
4585
  NodeIdContext.Consumer;
4590
- const useNodeId = () => useContext(NodeIdContext), selector$h = (s) => ({
4586
+ const useNodeId = () => useContext(NodeIdContext), selector$g = (s) => ({
4591
4587
  connectOnClick: s.connectOnClick,
4592
4588
  noPanClassName: s.noPanClassName,
4593
4589
  rfId: s.rfId
@@ -4603,7 +4599,7 @@ const useNodeId = () => useContext(NodeIdContext), selector$h = (s) => ({
4603
4599
  };
4604
4600
  };
4605
4601
  function HandleComponent({ type = "source", position = Position.Top, isValidConnection, isConnectable = !0, isConnectableStart = !0, isConnectableEnd = !0, id: id2, onConnect, children: children2, className, onMouseDown, onTouchStart, ...rest }, ref) {
4606
- const handleId = id2 || null, isTarget = type === "target", store = useStoreApi(), nodeId = useNodeId(), { connectOnClick, noPanClassName, rfId } = useStore(selector$h, shallow$1), { connectingFrom, connectingTo, clickConnecting, isPossibleEndHandle, connectionInProcess, valid } = useStore(connectingSelector(nodeId, handleId, type), shallow$1);
4602
+ const handleId = id2 || null, isTarget = type === "target", store = useStoreApi(), nodeId = useNodeId(), { connectOnClick, noPanClassName, rfId } = useStore(selector$g, shallow$1), { connectingFrom, connectingTo, clickConnecting, isPossibleEndHandle, connectionInProcess, valid } = useStore(connectingSelector(nodeId, handleId, type), shallow$1);
4607
4603
  nodeId || store.getState().onError?.("010", errorMessages.error010());
4608
4604
  const onConnectExtended = (params) => {
4609
4605
  const { defaultEdgeOptions, onConnect: onConnectAction, hasDefaultEdges } = store.getState(), edgeParams = {
@@ -4646,7 +4642,7 @@ function HandleComponent({ type = "source", position = Position.Top, isValidConn
4646
4642
  }
4647
4643
  isMouseTriggered ? onMouseDown?.(event) : onTouchStart?.(event);
4648
4644
  }, onClick = (event) => {
4649
- const { onClickConnectStart, onClickConnectEnd, connectionClickStartHandle, connectionMode, isValidConnection: isValidConnectionStore, lib, rfId: flowId } = store.getState();
4645
+ const { onClickConnectStart, onClickConnectEnd, connectionClickStartHandle, connectionMode, isValidConnection: isValidConnectionStore, lib, rfId: flowId, nodeLookup, connection: connectionState } = store.getState();
4650
4646
  if (!nodeId || !connectionClickStartHandle && !isConnectableStart)
4651
4647
  return;
4652
4648
  if (!connectionClickStartHandle) {
@@ -4666,9 +4662,12 @@ function HandleComponent({ type = "source", position = Position.Top, isValidConn
4666
4662
  isValidConnection: isValidConnectionHandler,
4667
4663
  flowId,
4668
4664
  doc,
4669
- lib
4665
+ lib,
4666
+ nodeLookup
4670
4667
  });
4671
- isValid && connection && onConnectExtended(connection), onClickConnectEnd?.(event), store.setState({ connectionClickStartHandle: null });
4668
+ isValid && connection && onConnectExtended(connection);
4669
+ const connectionClone = structuredClone(connectionState);
4670
+ delete connectionClone.inProgress, connectionClone.toPosition = connectionClone.toHandle ? connectionClone.toHandle.position : null, onClickConnectEnd?.(event, connectionClone), store.setState({ connectionClickStartHandle: null });
4672
4671
  };
4673
4672
  return jsx("div", { "data-handleid": handleId, "data-nodeid": nodeId, "data-handlepos": position, "data-id": `${rfId}-${nodeId}-${handleId}-${type}`, className: cc([
4674
4673
  "react-flow__handle",
@@ -4725,7 +4724,7 @@ function getNodeInlineStyleDimensions(node) {
4725
4724
  height: node.height ?? node.style?.height
4726
4725
  };
4727
4726
  }
4728
- const selector$g = (s) => {
4727
+ const selector$f = (s) => {
4729
4728
  const { width, height, x, y } = getInternalNodesBounds(s.nodeLookup, {
4730
4729
  filter: (node) => !!node.selected
4731
4730
  });
@@ -4737,7 +4736,7 @@ const selector$g = (s) => {
4737
4736
  };
4738
4737
  };
4739
4738
  function NodesSelection({ onSelectionContextMenu, noPanClassName, disableKeyboardA11y }) {
4740
- const store = useStoreApi(), { width, height, transformString, userSelectionActive } = useStore(selector$g, shallow$1), moveSelectedNodes = useMoveSelectedNodes(), nodeRef = useRef(null);
4739
+ const store = useStoreApi(), { width, height, transformString, userSelectionActive } = useStore(selector$f, shallow$1), moveSelectedNodes = useMoveSelectedNodes(), nodeRef = useRef(null);
4741
4740
  if (useEffect(() => {
4742
4741
  disableKeyboardA11y || nodeRef.current?.focus({
4743
4742
  preventScroll: !0
@@ -4762,19 +4761,19 @@ function NodesSelection({ onSelectionContextMenu, noPanClassName, disableKeyboar
4762
4761
  height
4763
4762
  } }) });
4764
4763
  }
4765
- const win = typeof window < "u" ? window : void 0, selector$f = (s) => ({ nodesSelectionActive: s.nodesSelectionActive, userSelectionActive: s.userSelectionActive });
4764
+ const win = typeof window < "u" ? window : void 0, selector$e = (s) => ({ nodesSelectionActive: s.nodesSelectionActive, userSelectionActive: s.userSelectionActive });
4766
4765
  function FlowRendererComponent({ children: children2, onPaneClick, onPaneMouseEnter, onPaneMouseMove, onPaneMouseLeave, onPaneContextMenu, onPaneScroll, paneClickDistance, deleteKeyCode, selectionKeyCode, selectionOnDrag, selectionMode, onSelectionStart, onSelectionEnd, multiSelectionKeyCode, panActivationKeyCode, zoomActivationKeyCode, elementsSelectable, zoomOnScroll, zoomOnPinch, panOnScroll: _panOnScroll, panOnScrollSpeed, panOnScrollMode, zoomOnDoubleClick, panOnDrag: _panOnDrag, defaultViewport: defaultViewport2, translateExtent, minZoom, maxZoom, preventScrolling, onSelectionContextMenu, noWheelClassName, noPanClassName, disableKeyboardA11y, onViewportChange, isControlledViewport }) {
4767
- const { nodesSelectionActive, userSelectionActive } = useStore(selector$f), selectionKeyPressed = useKeyPress(selectionKeyCode, { target: win }), panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: win }), panOnDrag = panActivationKeyPressed || _panOnDrag, panOnScroll = panActivationKeyPressed || _panOnScroll, _selectionOnDrag = selectionOnDrag && panOnDrag !== !0, isSelecting = selectionKeyPressed || userSelectionActive || _selectionOnDrag;
4766
+ const { nodesSelectionActive, userSelectionActive } = useStore(selector$e), selectionKeyPressed = useKeyPress(selectionKeyCode, { target: win }), panActivationKeyPressed = useKeyPress(panActivationKeyCode, { target: win }), panOnDrag = panActivationKeyPressed || _panOnDrag, panOnScroll = panActivationKeyPressed || _panOnScroll, _selectionOnDrag = selectionOnDrag && panOnDrag !== !0, isSelecting = selectionKeyPressed || userSelectionActive || _selectionOnDrag;
4768
4767
  return useGlobalKeyHandler({ deleteKeyCode, multiSelectionKeyCode }), jsx(ZoomPane, { onPaneContextMenu, elementsSelectable, zoomOnScroll, zoomOnPinch, panOnScroll, panOnScrollSpeed, panOnScrollMode, zoomOnDoubleClick, panOnDrag: !selectionKeyPressed && panOnDrag, defaultViewport: defaultViewport2, translateExtent, minZoom, maxZoom, zoomActivationKeyCode, preventScrolling, noWheelClassName, noPanClassName, onViewportChange, isControlledViewport, paneClickDistance, children: jsxs(Pane, { onSelectionStart, onSelectionEnd, onPaneClick, onPaneMouseEnter, onPaneMouseMove, onPaneMouseLeave, onPaneContextMenu, onPaneScroll, panOnDrag, isSelecting: !!isSelecting, selectionMode, selectionKeyPressed, selectionOnDrag: _selectionOnDrag, children: [children2, nodesSelectionActive && jsx(NodesSelection, { onSelectionContextMenu, noPanClassName, disableKeyboardA11y })] }) });
4769
4768
  }
4770
4769
  FlowRendererComponent.displayName = "FlowRenderer";
4771
- const FlowRenderer = memo(FlowRendererComponent), selector$e = (onlyRenderVisible) => (s) => onlyRenderVisible ? getNodesInside(s.nodeLookup, { x: 0, y: 0, width: s.width, height: s.height }, s.transform, !0).map((node) => node.id) : Array.from(s.nodeLookup.keys());
4770
+ const FlowRenderer = memo(FlowRendererComponent), selector$d = (onlyRenderVisible) => (s) => onlyRenderVisible ? getNodesInside(s.nodeLookup, { x: 0, y: 0, width: s.width, height: s.height }, s.transform, !0).map((node) => node.id) : Array.from(s.nodeLookup.keys());
4772
4771
  function useVisibleNodeIds(onlyRenderVisible) {
4773
- return useStore(useCallback(selector$e(onlyRenderVisible), [onlyRenderVisible]), shallow$1);
4772
+ return useStore(useCallback(selector$d(onlyRenderVisible), [onlyRenderVisible]), shallow$1);
4774
4773
  }
4775
- const selector$d = (s) => s.updateNodeInternals;
4774
+ const selector$c = (s) => s.updateNodeInternals;
4776
4775
  function useResizeObserver() {
4777
- const updateNodeInternals2 = useStore(selector$d), [resizeObserver] = useState(() => typeof ResizeObserver > "u" ? null : new ResizeObserver((entries) => {
4776
+ const updateNodeInternals2 = useStore(selector$c), [resizeObserver] = useState(() => typeof ResizeObserver > "u" ? null : new ResizeObserver((entries) => {
4778
4777
  const updates = /* @__PURE__ */ new Map();
4779
4778
  entries.forEach((entry) => {
4780
4779
  const id2 = entry.target.getAttribute("data-id");
@@ -4872,7 +4871,7 @@ function NodeWrapper({ id: id2, onClick, onMouseEnter, onMouseMove, onMouseLeave
4872
4871
  ...inlineDimensions
4873
4872
  }, "data-id": id2, "data-testid": `rf__node-${id2}`, onMouseEnter: onMouseEnterHandler, onMouseMove: onMouseMoveHandler, onMouseLeave: onMouseLeaveHandler, onContextMenu: onContextMenuHandler, onClick: onSelectNodeHandler, onDoubleClick: onDoubleClickHandler, onKeyDown: isFocusable ? onKeyDown : void 0, tabIndex: isFocusable ? 0 : void 0, role: isFocusable ? "button" : void 0, "aria-describedby": disableKeyboardA11y ? void 0 : `${ARIA_NODE_DESC_KEY}-${rfId}`, "aria-label": node.ariaLabel, children: jsx(Provider, { value: id2, children: jsx(NodeComponent, { id: id2, data: node.data, type: nodeType, positionAbsoluteX: clampedPosition.x, positionAbsoluteY: clampedPosition.y, selected: node.selected, selectable: isSelectable, draggable: isDraggable, deletable: node.deletable ?? !0, isConnectable, sourcePosition: node.sourcePosition, targetPosition: node.targetPosition, dragging, dragHandle: node.dragHandle, zIndex: internals.z, parentId: node.parentId, ...nodeDimensions }) }) });
4874
4873
  }
4875
- const selector$c = (s) => ({
4874
+ const selector$b = (s) => ({
4876
4875
  nodesDraggable: s.nodesDraggable,
4877
4876
  nodesConnectable: s.nodesConnectable,
4878
4877
  nodesFocusable: s.nodesFocusable,
@@ -4880,7 +4879,7 @@ const selector$c = (s) => ({
4880
4879
  onError: s.onError
4881
4880
  });
4882
4881
  function NodeRendererComponent(props) {
4883
- const { nodesDraggable, nodesConnectable, nodesFocusable, elementsSelectable, onError } = useStore(selector$c, shallow$1), nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements), resizeObserver = useResizeObserver();
4882
+ const { nodesDraggable, nodesConnectable, nodesFocusable, elementsSelectable, onError } = useStore(selector$b, shallow$1), nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements), resizeObserver = useResizeObserver();
4884
4883
  return jsx("div", { className: "react-flow__nodes", style: containerStyle, children: nodeIds.map((nodeId) => (
4885
4884
  // The split of responsibilities between NodeRenderer and
4886
4885
  // NodeComponentWrapper may appear weird. However, it’s designed to
@@ -5103,8 +5102,8 @@ function EdgeUpdateAnchors({ isReconnectable, reconnectRadius, edge, targetHandl
5103
5102
  return;
5104
5103
  const { autoPanOnConnect, domNode, isValidConnection, connectionMode, connectionRadius, lib, onConnectStart, onConnectEnd, cancelConnection, nodeLookup, rfId: flowId, panBy: panBy2, updateConnection } = store.getState(), nodeId = isSourceHandle ? edge.target : edge.source, handleId = (isSourceHandle ? targetHandleId : sourceHandleId) || null, handleType = isSourceHandle ? "target" : "source", isTarget = isSourceHandle;
5105
5104
  setReconnecting(!0), onReconnectStart?.(event, edge, handleType);
5106
- const _onReconnectEnd = (evt) => {
5107
- setReconnecting(!1), onReconnectEnd?.(evt, edge, handleType);
5105
+ const _onReconnectEnd = (evt, connectionState) => {
5106
+ setReconnecting(!1), onReconnectEnd?.(evt, edge, handleType, connectionState);
5108
5107
  }, onConnectEdge = (connection) => onReconnect?.(edge, connection);
5109
5108
  XYHandle.onPointerDown(event.nativeEvent, {
5110
5109
  autoPanOnConnect,
@@ -5200,7 +5199,7 @@ function EdgeWrapper({ id: id2, edgesFocusable, edgesReconnectable, elementsSele
5200
5199
  }
5201
5200
  ]), onClick: onEdgeClick, onDoubleClick: onEdgeDoubleClick, onContextMenu: onEdgeContextMenu, onMouseEnter: onEdgeMouseEnter, onMouseMove: onEdgeMouseMove, onMouseLeave: onEdgeMouseLeave, onKeyDown: isFocusable ? onKeyDown : void 0, tabIndex: isFocusable ? 0 : void 0, role: isFocusable ? "button" : "img", "data-id": id2, "data-testid": `rf__edge-${id2}`, "aria-label": edge.ariaLabel === null ? void 0 : edge.ariaLabel || `Edge from ${edge.source} to ${edge.target}`, "aria-describedby": isFocusable ? `${ARIA_EDGE_DESC_KEY}-${rfId}` : void 0, ref: edgeRef, children: [!reconnecting && jsx(EdgeComponent, { id: id2, source: edge.source, target: edge.target, type: edge.type, selected: edge.selected, animated: edge.animated, selectable: isSelectable, deletable: edge.deletable ?? !0, label: edge.label, labelStyle: edge.labelStyle, labelShowBg: edge.labelShowBg, labelBgStyle: edge.labelBgStyle, labelBgPadding: edge.labelBgPadding, labelBgBorderRadius: edge.labelBgBorderRadius, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data: edge.data, style: edge.style, sourceHandleId: edge.sourceHandle, targetHandleId: edge.targetHandle, markerStart: markerStartUrl, markerEnd: markerEndUrl, pathOptions: "pathOptions" in edge ? edge.pathOptions : void 0, interactionWidth: edge.interactionWidth }), isReconnectable && jsx(EdgeUpdateAnchors, { edge, isReconnectable, reconnectRadius, onReconnect, onReconnectStart, onReconnectEnd, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, setUpdateHover, setReconnecting, sourceHandleId: edge.sourceHandle, targetHandleId: edge.targetHandle })] }) });
5202
5201
  }
5203
- const selector$b = (s) => ({
5202
+ const selector$a = (s) => ({
5204
5203
  width: s.width,
5205
5204
  height: s.height,
5206
5205
  edgesFocusable: s.edgesFocusable,
@@ -5210,13 +5209,13 @@ const selector$b = (s) => ({
5210
5209
  onError: s.onError
5211
5210
  });
5212
5211
  function EdgeRendererComponent({ defaultMarkerColor, onlyRenderVisibleElements, rfId, edgeTypes, noPanClassName, onReconnect, onEdgeContextMenu, onEdgeMouseEnter, onEdgeMouseMove, onEdgeMouseLeave, onEdgeClick, reconnectRadius, onEdgeDoubleClick, onReconnectStart, onReconnectEnd, disableKeyboardA11y }) {
5213
- const { edgesFocusable, edgesReconnectable, elementsSelectable, onError } = useStore(selector$b, shallow$1), edgeIds = useVisibleEdgeIds(onlyRenderVisibleElements);
5212
+ const { edgesFocusable, edgesReconnectable, elementsSelectable, onError } = useStore(selector$a, shallow$1), edgeIds = useVisibleEdgeIds(onlyRenderVisibleElements);
5214
5213
  return jsxs("div", { className: "react-flow__edges", children: [jsx(MarkerDefinitions$1, { defaultColor: defaultMarkerColor, rfId }), edgeIds.map((id2) => jsx(EdgeWrapper, { id: id2, edgesFocusable, edgesReconnectable, elementsSelectable, noPanClassName, onReconnect, onContextMenu: onEdgeContextMenu, onMouseEnter: onEdgeMouseEnter, onMouseMove: onEdgeMouseMove, onMouseLeave: onEdgeMouseLeave, onClick: onEdgeClick, reconnectRadius, onDoubleClick: onEdgeDoubleClick, onReconnectStart, onReconnectEnd, rfId, onError, edgeTypes, disableKeyboardA11y }, id2))] });
5215
5214
  }
5216
5215
  EdgeRendererComponent.displayName = "EdgeRenderer";
5217
- const EdgeRenderer = memo(EdgeRendererComponent), selector$a = (s) => `translate(${s.transform[0]}px,${s.transform[1]}px) scale(${s.transform[2]})`;
5216
+ const EdgeRenderer = memo(EdgeRendererComponent), selector$9 = (s) => `translate(${s.transform[0]}px,${s.transform[1]}px) scale(${s.transform[2]})`;
5218
5217
  function Viewport({ children: children2 }) {
5219
- const transform2 = useStore(selector$a);
5218
+ const transform2 = useStore(selector$9);
5220
5219
  return jsx("div", { className: "react-flow__viewport xyflow__viewport react-flow__container", style: { transform: transform2 }, children: children2 });
5221
5220
  }
5222
5221
  function useOnInitHandler(onInit) {
@@ -5225,16 +5224,22 @@ function useOnInitHandler(onInit) {
5225
5224
  !isInitialized.current && rfInstance.viewportInitialized && onInit && (setTimeout(() => onInit(rfInstance), 1), isInitialized.current = !0);
5226
5225
  }, [onInit, rfInstance.viewportInitialized]);
5227
5226
  }
5228
- const selector$9 = (state) => state.panZoom?.syncViewport;
5227
+ const selector$8 = (state) => state.panZoom?.syncViewport;
5229
5228
  function useViewportSync(viewport) {
5230
- const syncViewport = useStore(selector$9), store = useStoreApi();
5229
+ const syncViewport = useStore(selector$8), store = useStoreApi();
5231
5230
  return useEffect(() => {
5232
5231
  viewport && (syncViewport?.(viewport), store.setState({ transform: [viewport.x, viewport.y, viewport.zoom] }));
5233
5232
  }, [viewport, syncViewport]), null;
5234
5233
  }
5235
- const selector$8 = (s) => s.connection.inProgress ? { ...s.connection, to: pointToRendererPoint(s.connection.to, s.transform) } : { ...s.connection };
5236
- function useConnection() {
5237
- return useStore(selector$8, shallow$1);
5234
+ function storeSelector$1(s) {
5235
+ return s.connection.inProgress ? { ...s.connection, to: pointToRendererPoint(s.connection.to, s.transform) } : { ...s.connection };
5236
+ }
5237
+ function getSelector(connectionSelector) {
5238
+ return storeSelector$1;
5239
+ }
5240
+ function useConnection(connectionSelector) {
5241
+ const combinedSelector = getSelector();
5242
+ return useStore(combinedSelector, shallow$1);
5238
5243
  }
5239
5244
  const selector$7 = (s) => ({
5240
5245
  nodesConnectable: s.nodesConnectable,
@@ -5391,16 +5396,19 @@ const GraphView = memo(GraphViewComponent), getInitialState = ({ nodes, edges, d
5391
5396
  // Every node gets registerd at a ResizeObserver. Whenever a node
5392
5397
  // changes its dimensions, this function is called to measure the
5393
5398
  // new dimensions and update the nodes.
5394
- updateNodeInternals: (updates) => {
5399
+ updateNodeInternals: (updates, params = { triggerFitView: !0 }) => {
5395
5400
  const { triggerNodeChanges, nodeLookup, parentLookup, fitViewOnInit, fitViewDone, fitViewOnInitOptions, domNode, nodeOrigin: nodeOrigin2, debug, fitViewSync } = get2(), { changes, updatedInternals } = updateNodeInternals(updates, nodeLookup, parentLookup, domNode, nodeOrigin2);
5396
- if (!updatedInternals)
5397
- return;
5398
- updateAbsolutePositions(nodeLookup, parentLookup, { nodeOrigin: nodeOrigin2 });
5399
- let nextFitViewDone = fitViewDone;
5400
- !fitViewDone && fitViewOnInit && (nextFitViewDone = fitViewSync({
5401
- ...fitViewOnInitOptions,
5402
- nodes: fitViewOnInitOptions?.nodes
5403
- })), set2({ fitViewDone: nextFitViewDone }), changes?.length > 0 && (debug && console.log("React Flow: trigger node changes", changes), triggerNodeChanges?.(changes));
5401
+ if (updatedInternals) {
5402
+ if (updateAbsolutePositions(nodeLookup, parentLookup, { nodeOrigin: nodeOrigin2 }), params.triggerFitView) {
5403
+ let nextFitViewDone = fitViewDone;
5404
+ !fitViewDone && fitViewOnInit && (nextFitViewDone = fitViewSync({
5405
+ ...fitViewOnInitOptions,
5406
+ nodes: fitViewOnInitOptions?.nodes
5407
+ })), set2({ fitViewDone: nextFitViewDone });
5408
+ } else
5409
+ set2({});
5410
+ changes?.length > 0 && (debug && console.log("React Flow: trigger node changes", changes), triggerNodeChanges?.(changes));
5411
+ }
5404
5412
  },
5405
5413
  updateNodePositions: (nodeDragItems, dragging = !1) => {
5406
5414
  const parentExpandChildren = [], changes = [];
@@ -5580,6 +5588,14 @@ function EdgeLabelRenderer({ children: children2 }) {
5580
5588
  const edgeLabelRenderer = useStore(selector$6);
5581
5589
  return edgeLabelRenderer ? createPortal(children2, edgeLabelRenderer) : null;
5582
5590
  }
5591
+ function useNodesState(initialNodes) {
5592
+ const [nodes, setNodes] = useState(initialNodes), onNodesChange = useCallback((changes) => setNodes((nds) => applyNodeChanges(changes, nds)), []);
5593
+ return [nodes, setNodes, onNodesChange];
5594
+ }
5595
+ function useEdgesState(initialEdges) {
5596
+ const [edges, setEdges] = useState(initialEdges), onEdgesChange = useCallback((changes) => setEdges((eds) => applyEdgeChanges(changes, eds)), []);
5597
+ return [edges, setEdges, onEdgesChange];
5598
+ }
5583
5599
  function useOnViewportChange({ onStart, onChange, onEnd }) {
5584
5600
  const store = useStoreApi();
5585
5601
  useEffect(() => {
@@ -5637,20 +5653,20 @@ function BackgroundComponent({
5637
5653
  // only used for lines and cross
5638
5654
  size,
5639
5655
  lineWidth = 1,
5640
- offset = 2,
5656
+ offset = 0,
5641
5657
  color: color2,
5642
5658
  bgColor,
5643
5659
  style: style2,
5644
5660
  className,
5645
5661
  patternClassName
5646
5662
  }) {
5647
- const ref = useRef(null), { transform: transform2, patternId } = useStore(selector$3, shallow$1), patternSize = size || defaultSize[variant], isDots = variant === BackgroundVariant.Dots, isCross = variant === BackgroundVariant.Cross, gapXY = Array.isArray(gap) ? gap : [gap, gap], scaledGap = [gapXY[0] * transform2[2] || 1, gapXY[1] * transform2[2] || 1], scaledSize = patternSize * transform2[2], patternDimensions = isCross ? [scaledSize, scaledSize] : scaledGap, patternOffset = isDots ? [scaledSize / offset, scaledSize / offset] : [patternDimensions[0] / offset, patternDimensions[1] / offset], _patternId = `${patternId}${id2 || ""}`;
5663
+ const ref = useRef(null), { transform: transform2, patternId } = useStore(selector$3, shallow$1), patternSize = size || defaultSize[variant], isDots = variant === BackgroundVariant.Dots, isCross = variant === BackgroundVariant.Cross, gapXY = Array.isArray(gap) ? gap : [gap, gap], scaledGap = [gapXY[0] * transform2[2] || 1, gapXY[1] * transform2[2] || 1], scaledSize = patternSize * transform2[2], offsetXY = Array.isArray(offset) ? offset : [offset, offset], scaledOffset = [offsetXY[0] * transform2[2] || 1, offsetXY[1] * transform2[2] || 1], patternDimensions = isCross ? [scaledSize, scaledSize] : scaledGap, _patternId = `${patternId}${id2 || ""}`;
5648
5664
  return jsxs("svg", { className: cc(["react-flow__background", className]), style: {
5649
5665
  ...style2,
5650
5666
  ...containerStyle,
5651
5667
  "--xy-background-color-props": bgColor,
5652
5668
  "--xy-background-pattern-color-props": color2
5653
- }, ref, "data-testid": "rf__background", children: [jsx("pattern", { id: _patternId, x: transform2[0] % scaledGap[0], y: transform2[1] % scaledGap[1], width: scaledGap[0], height: scaledGap[1], patternUnits: "userSpaceOnUse", patternTransform: `translate(-${patternOffset[0]},-${patternOffset[1]})`, children: isDots ? jsx(DotPattern, { radius: scaledSize / offset, className: patternClassName }) : jsx(LinePattern, { dimensions: patternDimensions, lineWidth, variant, className: patternClassName }) }), jsx("rect", { x: "0", y: "0", width: "100%", height: "100%", fill: `url(#${_patternId})` })] });
5669
+ }, ref, "data-testid": "rf__background", children: [jsx("pattern", { id: _patternId, x: transform2[0] % scaledGap[0], y: transform2[1] % scaledGap[1], width: scaledGap[0], height: scaledGap[1], patternUnits: "userSpaceOnUse", patternTransform: `translate(-${scaledOffset[0]},-${scaledOffset[1]})`, children: isDots ? jsx(DotPattern, { radius: scaledSize / 2, className: patternClassName }) : jsx(LinePattern, { dimensions: patternDimensions, lineWidth, variant, className: patternClassName }) }), jsx("rect", { x: "0", y: "0", width: "100%", height: "100%", fill: `url(#${_patternId})` })] });
5654
5670
  }
5655
5671
  BackgroundComponent.displayName = "Background";
5656
5672
  const Background = memo(BackgroundComponent);
@@ -5952,6 +5968,10 @@ export {
5952
5968
  index as m,
5953
5969
  useOnSelectionChange as n,
5954
5970
  BackgroundVariant as o,
5971
+ BaseEdge as p,
5972
+ useNodesState as q,
5973
+ useEdgesState as r,
5955
5974
  shallow$1 as s,
5956
- useReactFlow as u
5975
+ useReactFlow as u,
5976
+ withSelectorExports as w
5957
5977
  };