@uipath/apollo-react 6.27.0 → 6.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/components/BaseCanvas/BaseCanvas.cjs +27 -3
- package/dist/canvas/components/BaseCanvas/BaseCanvas.d.ts.map +1 -1
- package/dist/canvas/components/BaseCanvas/BaseCanvas.hooks.cjs +21 -3
- package/dist/canvas/components/BaseCanvas/BaseCanvas.hooks.d.ts +1 -0
- package/dist/canvas/components/BaseCanvas/BaseCanvas.hooks.d.ts.map +1 -1
- package/dist/canvas/components/BaseCanvas/BaseCanvas.hooks.js +18 -3
- package/dist/canvas/components/BaseCanvas/BaseCanvas.js +28 -4
- package/dist/canvas/components/BaseCanvas/BaseCanvas.stories.fixtures.cjs +87 -0
- package/dist/canvas/components/BaseCanvas/BaseCanvas.stories.fixtures.d.ts +4 -0
- package/dist/canvas/components/BaseCanvas/BaseCanvas.stories.fixtures.d.ts.map +1 -0
- package/dist/canvas/components/BaseCanvas/BaseCanvas.stories.fixtures.js +53 -0
- package/dist/canvas/components/BaseCanvas/BaseCanvas.types.d.ts.map +1 -1
- package/dist/canvas/components/BaseCanvas/ReadOnlyNodesContext.cjs +30 -3
- package/dist/canvas/components/BaseCanvas/ReadOnlyNodesContext.d.ts +3 -0
- package/dist/canvas/components/BaseCanvas/ReadOnlyNodesContext.d.ts.map +1 -1
- package/dist/canvas/components/BaseCanvas/ReadOnlyNodesContext.js +21 -3
- package/dist/canvas/components/BaseCanvas/index.cjs +43 -32
- package/dist/canvas/components/BaseCanvas/index.d.ts +1 -1
- package/dist/canvas/components/BaseCanvas/index.d.ts.map +1 -1
- package/dist/canvas/components/BaseCanvas/index.js +2 -2
- package/dist/canvas/components/BaseCanvas/useReadOnlyConnectionCallbacks.cjs +87 -0
- package/dist/canvas/components/BaseCanvas/useReadOnlyConnectionCallbacks.d.ts +13 -0
- package/dist/canvas/components/BaseCanvas/useReadOnlyConnectionCallbacks.d.ts.map +1 -0
- package/dist/canvas/components/BaseCanvas/useReadOnlyConnectionCallbacks.js +53 -0
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.cjs +21 -3
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.d.ts.map +1 -1
- package/dist/canvas/components/Toolbar/EdgeToolbar/useEdgeToolbarState.js +21 -3
- package/dist/canvas/styles/tailwind.canvas.css +1 -1
- package/dist/canvas/utils/createPreviewGraph.cjs +13 -8
- package/dist/canvas/utils/createPreviewGraph.d.ts +5 -2
- package/dist/canvas/utils/createPreviewGraph.d.ts.map +1 -1
- package/dist/canvas/utils/createPreviewGraph.js +13 -8
- package/package.json +1 -1
|
@@ -36,13 +36,15 @@ const external_CanvasBackground_cjs_namespaceObject = require("./CanvasBackgroun
|
|
|
36
36
|
const external_CanvasProviders_cjs_namespaceObject = require("./CanvasProviders.cjs");
|
|
37
37
|
const external_PanShortcutTeachingUI_cjs_namespaceObject = require("./PanShortcutTeachingUI.cjs");
|
|
38
38
|
const external_ReadOnlyNodesContext_cjs_namespaceObject = require("./ReadOnlyNodesContext.cjs");
|
|
39
|
+
const external_useReadOnlyConnectionCallbacks_cjs_namespaceObject = require("./useReadOnlyConnectionCallbacks.cjs");
|
|
39
40
|
const BaseCanvasInnerComponent = (props)=>{
|
|
40
41
|
const { innerRef, fitViewOptions: fitViewOptionsProps, ...canvasProps } = props;
|
|
41
42
|
const fitViewOptions = fitViewOptionsProps ?? external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.fitViewOptions;
|
|
42
|
-
const { nodes = [], edges = [], nodeTypes, edgeTypes, children, mode = 'view', readOnlyNodeIds, showBackground = true, backgroundColor = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.color, backgroundSecondaryColor = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.bgColor, backgroundVariant = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.variant, backgroundGap = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.gap, backgroundSize = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.size, isDarkMode, locale, minZoom = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.zoom.min, maxZoom = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.zoom.max, defaultViewport = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.defaultViewport, defaultEdgeOptions = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.edge, stickyNoteOptions, onNodesChange, onEdgesChange, onConnect, onConnectStart, onConnectEnd, onNodeClick, onNodeDragStart, onNodeDrag, onNodeDragStop, onPaneClick, onInit, onSelectionChange, onBeforeDelete, proOptions = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.pro, connectionMode = react_cjs_namespaceObject.ConnectionMode.Loose, connectionLineComponent, connectionLineStyle, deleteKeyCode = null, selectNodesOnDrag = true, nodesDraggable = true, nodesConnectable = true, elementsSelectable = true, onlyRenderVisibleElements = true, zoomOnDoubleClick = true, snapToGrid = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.snapToGrid, snapGrid = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.snapGrid, initialAutoLayout, maintainNodesInView, onToolbarAction, breakpoints, panShortcutTeachingUIMessage = 'Hold Space and drag to pan around the canvas!', ...reactFlowProps } = canvasProps;
|
|
43
|
+
const { nodes = [], edges = [], nodeTypes, edgeTypes, children, mode = 'view', readOnlyNodeIds, showBackground = true, backgroundColor = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.color, backgroundSecondaryColor = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.bgColor, backgroundVariant = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.variant, backgroundGap = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.gap, backgroundSize = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.background.size, isDarkMode, locale, minZoom = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.zoom.min, maxZoom = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.zoom.max, defaultViewport = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.defaultViewport, defaultEdgeOptions = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.edge, stickyNoteOptions, onNodesChange, onEdgesChange, onConnect, onReconnect, onReconnectStart, onReconnectEnd, onConnectStart, onConnectEnd, isValidConnection, onNodeClick, onNodeDragStart, onNodeDrag, onNodeDragStop, onPaneClick, onInit, onSelectionChange, onBeforeDelete, proOptions = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.pro, connectionMode = react_cjs_namespaceObject.ConnectionMode.Loose, connectionLineComponent, connectionLineStyle, deleteKeyCode = null, selectNodesOnDrag = true, nodesDraggable = true, nodesConnectable = true, elementsSelectable = true, onlyRenderVisibleElements = true, zoomOnDoubleClick = true, snapToGrid = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.snapToGrid, snapGrid = external_BaseCanvas_constants_cjs_namespaceObject.BASE_CANVAS_DEFAULTS.snapGrid, initialAutoLayout, maintainNodesInView, onToolbarAction, breakpoints, panShortcutTeachingUIMessage = 'Hold Space and drag to pan around the canvas!', ...reactFlowProps } = canvasProps;
|
|
43
44
|
const isInteractive = 'readonly' !== mode;
|
|
44
45
|
const isDesignMode = 'design' === mode;
|
|
45
46
|
const stableReadOnlyNodeIds = (0, external_ReadOnlyNodesContext_cjs_namespaceObject.useStableNodeIdSet)(readOnlyNodeIds);
|
|
47
|
+
const readOnlyEdgeIds = (0, external_BaseCanvas_hooks_cjs_namespaceObject.useReadOnlyEdgeIds)(edges, stableReadOnlyNodeIds);
|
|
46
48
|
const guardedBeforeDelete = (0, external_BaseCanvas_hooks_cjs_namespaceObject.useReadOnlyBeforeDelete)(stableReadOnlyNodeIds, onBeforeDelete);
|
|
47
49
|
const handleNodesChange = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
48
50
|
if (!onNodesChange || 0 === stableReadOnlyNodeIds.size) return onNodesChange;
|
|
@@ -55,6 +57,24 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
55
57
|
onNodesChange,
|
|
56
58
|
stableReadOnlyNodeIds
|
|
57
59
|
]);
|
|
60
|
+
const handleEdgesChange = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
61
|
+
if (!onEdgesChange || 0 === readOnlyEdgeIds.size) return onEdgesChange;
|
|
62
|
+
const guarded = (changes)=>{
|
|
63
|
+
const allowed = changes.filter((change)=>'remove' === change.type ? !readOnlyEdgeIds.has(change.id) : true);
|
|
64
|
+
if (allowed.length > 0) onEdgesChange(allowed);
|
|
65
|
+
};
|
|
66
|
+
return guarded;
|
|
67
|
+
}, [
|
|
68
|
+
onEdgesChange,
|
|
69
|
+
readOnlyEdgeIds
|
|
70
|
+
]);
|
|
71
|
+
const { guardedIsValidConnection, guardedOnConnect, guardedOnReconnect, guardedOnReconnectEnd } = (0, external_useReadOnlyConnectionCallbacks_cjs_namespaceObject.useReadOnlyConnectionCallbacks)({
|
|
72
|
+
readOnlyNodeIds: stableReadOnlyNodeIds,
|
|
73
|
+
isValidConnection,
|
|
74
|
+
onConnect,
|
|
75
|
+
onReconnect,
|
|
76
|
+
onReconnectEnd
|
|
77
|
+
});
|
|
58
78
|
const [reactFlowInstance, setReactFlowInstance] = (0, external_react_namespaceObject.useState)();
|
|
59
79
|
const { isReady } = (0, external_BaseCanvas_hooks_cjs_namespaceObject.useAutoLayout)(nodes, initialAutoLayout, fitViewOptions);
|
|
60
80
|
const { ensureNodesInView, ensureAllNodesInView, centerNode } = (0, external_BaseCanvas_hooks_cjs_namespaceObject.useEnsureNodesInView)();
|
|
@@ -96,6 +116,7 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
96
116
|
colorMode: '',
|
|
97
117
|
nodes: nodes,
|
|
98
118
|
edges: edges,
|
|
119
|
+
isValidConnection: guardedIsValidConnection,
|
|
99
120
|
nodeTypes: nodeTypes,
|
|
100
121
|
edgeTypes: edgeTypes,
|
|
101
122
|
fitViewOptions: fitViewOptions,
|
|
@@ -121,9 +142,12 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
121
142
|
panOnDrag: isInteractive ? external_BaseCanvas_constants_cjs_namespaceObject.PAN_ON_DRAG : false,
|
|
122
143
|
onInit: handleInit,
|
|
123
144
|
onNodesChange: isInteractive ? handleNodesChange : void 0,
|
|
124
|
-
onEdgesChange: isInteractive ?
|
|
145
|
+
onEdgesChange: isInteractive ? handleEdgesChange : void 0,
|
|
125
146
|
onBeforeDelete: guardedBeforeDelete,
|
|
126
|
-
onConnect: isDesignMode ?
|
|
147
|
+
onConnect: isDesignMode ? guardedOnConnect : void 0,
|
|
148
|
+
onReconnect: isDesignMode ? guardedOnReconnect : void 0,
|
|
149
|
+
onReconnectStart: isDesignMode ? onReconnectStart : void 0,
|
|
150
|
+
onReconnectEnd: isDesignMode ? guardedOnReconnectEnd : void 0,
|
|
127
151
|
onConnectStart: isDesignMode ? onConnectStart : void 0,
|
|
128
152
|
onConnectEnd: isDesignMode ? onConnectEnd : void 0,
|
|
129
153
|
onNodeClick: isInteractive ? onNodeClick : void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCanvas.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,IAAI,EACJ,IAAI,EAEL,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAIL,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseCanvas.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,IAAI,EACJ,IAAI,EAEL,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAIL,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAC;AAUf,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAwQzE,eAAO,MAAM,UAAU,EAKjB,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,IAAI,EAC/D,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG;IAC3C,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;CACpD,KACE,YAAY,CAAC"}
|
|
@@ -28,11 +28,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
useMaintainNodesInView: ()=>useMaintainNodesInView,
|
|
29
29
|
useEnsureNodesInView: ()=>useEnsureNodesInView,
|
|
30
30
|
useReadOnlyBeforeDelete: ()=>useReadOnlyBeforeDelete,
|
|
31
|
+
useReadOnlyEdgeIds: ()=>useReadOnlyEdgeIds,
|
|
31
32
|
useFitView: ()=>useFitView
|
|
32
33
|
});
|
|
33
34
|
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
|
|
34
35
|
const external_react_namespaceObject = require("react");
|
|
35
36
|
const external_BaseCanvas_constants_cjs_namespaceObject = require("./BaseCanvas.constants.cjs");
|
|
37
|
+
const external_ReadOnlyNodesContext_cjs_namespaceObject = require("./ReadOnlyNodesContext.cjs");
|
|
38
|
+
const external_set_utils_cjs_namespaceObject = require("./set-utils.cjs");
|
|
36
39
|
const waitForNodeMeasurements = (getNodes)=>new Promise((resolve)=>{
|
|
37
40
|
const startTime = Date.now();
|
|
38
41
|
const timeoutInMs = 500;
|
|
@@ -254,12 +257,14 @@ function useReadOnlyBeforeDelete(readOnlyNodeIds, onBeforeDelete) {
|
|
|
254
257
|
const vetoedNodeIds = new Set();
|
|
255
258
|
const deletedNodeIds = new Set();
|
|
256
259
|
for (const node of candidate.nodes)(readOnlyNodeIds.has(node.id) ? vetoedNodeIds : deletedNodeIds).add(node.id);
|
|
257
|
-
if (0 === vetoedNodeIds.size) return candidate;
|
|
258
260
|
const touchesVetoedNode = (edge)=>vetoedNodeIds.has(edge.source) || vetoedNodeIds.has(edge.target);
|
|
259
261
|
const touchesDeletedNode = (edge)=>deletedNodeIds.has(edge.source) || deletedNodeIds.has(edge.target);
|
|
262
|
+
const isFrozen = (edge)=>(0, external_ReadOnlyNodesContext_cjs_namespaceObject.isConnectionReadOnly)(readOnlyNodeIds, edge.source, edge.target);
|
|
263
|
+
const keptEdges = candidate.edges.filter((edge)=>!isFrozen(edge) && (!touchesVetoedNode(edge) || touchesDeletedNode(edge)));
|
|
264
|
+
if (0 === vetoedNodeIds.size && keptEdges.length === candidate.edges.length) return candidate;
|
|
260
265
|
return {
|
|
261
266
|
nodes: candidate.nodes.filter((node)=>!vetoedNodeIds.has(node.id)),
|
|
262
|
-
edges:
|
|
267
|
+
edges: keptEdges
|
|
263
268
|
};
|
|
264
269
|
};
|
|
265
270
|
}, [
|
|
@@ -267,17 +272,30 @@ function useReadOnlyBeforeDelete(readOnlyNodeIds, onBeforeDelete) {
|
|
|
267
272
|
onBeforeDelete
|
|
268
273
|
]);
|
|
269
274
|
}
|
|
275
|
+
function useReadOnlyEdgeIds(edges, readOnlyNodeIds) {
|
|
276
|
+
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
277
|
+
if (0 === readOnlyNodeIds.size) return external_set_utils_cjs_namespaceObject.EMPTY_SET;
|
|
278
|
+
const frozen = new Set();
|
|
279
|
+
for (const edge of edges)if ((0, external_ReadOnlyNodesContext_cjs_namespaceObject.isConnectionReadOnly)(readOnlyNodeIds, edge.source, edge.target)) frozen.add(edge.id);
|
|
280
|
+
return 0 === frozen.size ? external_set_utils_cjs_namespaceObject.EMPTY_SET : frozen;
|
|
281
|
+
}, [
|
|
282
|
+
edges,
|
|
283
|
+
readOnlyNodeIds
|
|
284
|
+
]);
|
|
285
|
+
}
|
|
270
286
|
exports.useAutoLayout = __webpack_exports__.useAutoLayout;
|
|
271
287
|
exports.useEnsureNodesInView = __webpack_exports__.useEnsureNodesInView;
|
|
272
288
|
exports.useFitView = __webpack_exports__.useFitView;
|
|
273
289
|
exports.useMaintainNodesInView = __webpack_exports__.useMaintainNodesInView;
|
|
274
290
|
exports.useReadOnlyBeforeDelete = __webpack_exports__.useReadOnlyBeforeDelete;
|
|
291
|
+
exports.useReadOnlyEdgeIds = __webpack_exports__.useReadOnlyEdgeIds;
|
|
275
292
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
276
293
|
"useAutoLayout",
|
|
277
294
|
"useEnsureNodesInView",
|
|
278
295
|
"useFitView",
|
|
279
296
|
"useMaintainNodesInView",
|
|
280
|
-
"useReadOnlyBeforeDelete"
|
|
297
|
+
"useReadOnlyBeforeDelete",
|
|
298
|
+
"useReadOnlyEdgeIds"
|
|
281
299
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
282
300
|
Object.defineProperty(exports, '__esModule', {
|
|
283
301
|
value: true
|
|
@@ -13,4 +13,5 @@ export declare const useEnsureNodesInView: () => {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const useMaintainNodesInView: (nodeIds?: string[], fitViewOptions?: BaseCanvasFitViewOptions) => void;
|
|
15
15
|
export declare function useReadOnlyBeforeDelete<NodeType extends Node, EdgeType extends Edge>(readOnlyNodeIds: ReadonlySet<string>, onBeforeDelete: OnBeforeDelete<NodeType, EdgeType> | undefined): OnBeforeDelete<NodeType, EdgeType> | undefined;
|
|
16
|
+
export declare function useReadOnlyEdgeIds<EdgeType extends Edge>(edges: EdgeType[], readOnlyNodeIds: ReadonlySet<string>): ReadonlySet<string>;
|
|
16
17
|
//# sourceMappingURL=BaseCanvas.hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCanvas.hooks.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAI3F,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseCanvas.hooks.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAI3F,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAuB7F,eAAO,MAAM,aAAa,GACxB,OAAO,IAAI,EAAE,GAAG,SAAS,EACzB,oBAAoB,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAC9C,iBAAiB,wBAAwB;;CA+E1C,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,QAAQ,IAAI,EAAE,EACd,QAAQ,MAAM,EACd,iBAAiB,wBAAwB;;CAgC1C,CAAC;AAEF,eAAO,MAAM,oBAAoB;iCAInB,MAAM,EAAE,YAAY,wBAAwB;qCA4B3C,wBAAwB;yBAqB1B,MAAM,YAAY,wBAAwB;CAgCtD,CAAC;AAqCF,eAAO,MAAM,sBAAsB,GACjC,UAAU,MAAM,EAAE,EAClB,iBAAiB,wBAAwB,SAuE1C,CAAC;AA2BF,wBAAgB,uBAAuB,CAAC,QAAQ,SAAS,IAAI,EAAE,QAAQ,SAAS,IAAI,EAClF,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,EACpC,cAAc,EAAE,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,SAAS,GAC7D,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,SAAS,CAqChD;AAMD,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,IAAI,EACtD,KAAK,EAAE,QAAQ,EAAE,EACjB,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,GACnC,WAAW,CAAC,MAAM,CAAC,CAWrB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useReactFlow, useStoreApi } from "../../xyflow/react.js";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { BASE_CANVAS_DEFAULTS, FIT_VIEW_DELAY_MS } from "./BaseCanvas.constants.js";
|
|
4
|
+
import { isConnectionReadOnly } from "./ReadOnlyNodesContext.js";
|
|
5
|
+
import { EMPTY_SET } from "./set-utils.js";
|
|
4
6
|
const waitForNodeMeasurements = (getNodes)=>new Promise((resolve)=>{
|
|
5
7
|
const startTime = Date.now();
|
|
6
8
|
const timeoutInMs = 500;
|
|
@@ -222,12 +224,14 @@ function useReadOnlyBeforeDelete(readOnlyNodeIds, onBeforeDelete) {
|
|
|
222
224
|
const vetoedNodeIds = new Set();
|
|
223
225
|
const deletedNodeIds = new Set();
|
|
224
226
|
for (const node of candidate.nodes)(readOnlyNodeIds.has(node.id) ? vetoedNodeIds : deletedNodeIds).add(node.id);
|
|
225
|
-
if (0 === vetoedNodeIds.size) return candidate;
|
|
226
227
|
const touchesVetoedNode = (edge)=>vetoedNodeIds.has(edge.source) || vetoedNodeIds.has(edge.target);
|
|
227
228
|
const touchesDeletedNode = (edge)=>deletedNodeIds.has(edge.source) || deletedNodeIds.has(edge.target);
|
|
229
|
+
const isFrozen = (edge)=>isConnectionReadOnly(readOnlyNodeIds, edge.source, edge.target);
|
|
230
|
+
const keptEdges = candidate.edges.filter((edge)=>!isFrozen(edge) && (!touchesVetoedNode(edge) || touchesDeletedNode(edge)));
|
|
231
|
+
if (0 === vetoedNodeIds.size && keptEdges.length === candidate.edges.length) return candidate;
|
|
228
232
|
return {
|
|
229
233
|
nodes: candidate.nodes.filter((node)=>!vetoedNodeIds.has(node.id)),
|
|
230
|
-
edges:
|
|
234
|
+
edges: keptEdges
|
|
231
235
|
};
|
|
232
236
|
};
|
|
233
237
|
}, [
|
|
@@ -235,4 +239,15 @@ function useReadOnlyBeforeDelete(readOnlyNodeIds, onBeforeDelete) {
|
|
|
235
239
|
onBeforeDelete
|
|
236
240
|
]);
|
|
237
241
|
}
|
|
238
|
-
|
|
242
|
+
function useReadOnlyEdgeIds(edges, readOnlyNodeIds) {
|
|
243
|
+
return useMemo(()=>{
|
|
244
|
+
if (0 === readOnlyNodeIds.size) return EMPTY_SET;
|
|
245
|
+
const frozen = new Set();
|
|
246
|
+
for (const edge of edges)if (isConnectionReadOnly(readOnlyNodeIds, edge.source, edge.target)) frozen.add(edge.id);
|
|
247
|
+
return 0 === frozen.size ? EMPTY_SET : frozen;
|
|
248
|
+
}, [
|
|
249
|
+
edges,
|
|
250
|
+
readOnlyNodeIds
|
|
251
|
+
]);
|
|
252
|
+
}
|
|
253
|
+
export { useAutoLayout, useEnsureNodesInView, useFitView, useMaintainNodesInView, useReadOnlyBeforeDelete, useReadOnlyEdgeIds };
|
|
@@ -3,18 +3,20 @@ import { ConnectionMode, ReactFlow } from "../../xyflow/react.js";
|
|
|
3
3
|
import { forwardRef, memo, useCallback, useImperativeHandle, useMemo, useState } from "react";
|
|
4
4
|
import { useToolbarActionStore } from "../../hooks/ToolbarActionContext.js";
|
|
5
5
|
import { BASE_CANVAS_DEFAULTS, PAN_ON_DRAG } from "./BaseCanvas.constants.js";
|
|
6
|
-
import { useAutoLayout, useEnsureNodesInView, useMaintainNodesInView, useReadOnlyBeforeDelete } from "./BaseCanvas.hooks.js";
|
|
6
|
+
import { useAutoLayout, useEnsureNodesInView, useMaintainNodesInView, useReadOnlyBeforeDelete, useReadOnlyEdgeIds } from "./BaseCanvas.hooks.js";
|
|
7
7
|
import { CanvasBackground } from "./CanvasBackground.js";
|
|
8
8
|
import { CanvasProviders } from "./CanvasProviders.js";
|
|
9
9
|
import { PanShortcutTeachingUI } from "./PanShortcutTeachingUI.js";
|
|
10
10
|
import { useStableNodeIdSet } from "./ReadOnlyNodesContext.js";
|
|
11
|
+
import { useReadOnlyConnectionCallbacks } from "./useReadOnlyConnectionCallbacks.js";
|
|
11
12
|
const BaseCanvasInnerComponent = (props)=>{
|
|
12
13
|
const { innerRef, fitViewOptions: fitViewOptionsProps, ...canvasProps } = props;
|
|
13
14
|
const fitViewOptions = fitViewOptionsProps ?? BASE_CANVAS_DEFAULTS.fitViewOptions;
|
|
14
|
-
const { nodes = [], edges = [], nodeTypes, edgeTypes, children, mode = 'view', readOnlyNodeIds, showBackground = true, backgroundColor = BASE_CANVAS_DEFAULTS.background.color, backgroundSecondaryColor = BASE_CANVAS_DEFAULTS.background.bgColor, backgroundVariant = BASE_CANVAS_DEFAULTS.background.variant, backgroundGap = BASE_CANVAS_DEFAULTS.background.gap, backgroundSize = BASE_CANVAS_DEFAULTS.background.size, isDarkMode, locale, minZoom = BASE_CANVAS_DEFAULTS.zoom.min, maxZoom = BASE_CANVAS_DEFAULTS.zoom.max, defaultViewport = BASE_CANVAS_DEFAULTS.defaultViewport, defaultEdgeOptions = BASE_CANVAS_DEFAULTS.edge, stickyNoteOptions, onNodesChange, onEdgesChange, onConnect, onConnectStart, onConnectEnd, onNodeClick, onNodeDragStart, onNodeDrag, onNodeDragStop, onPaneClick, onInit, onSelectionChange, onBeforeDelete, proOptions = BASE_CANVAS_DEFAULTS.pro, connectionMode = ConnectionMode.Loose, connectionLineComponent, connectionLineStyle, deleteKeyCode = null, selectNodesOnDrag = true, nodesDraggable = true, nodesConnectable = true, elementsSelectable = true, onlyRenderVisibleElements = true, zoomOnDoubleClick = true, snapToGrid = BASE_CANVAS_DEFAULTS.snapToGrid, snapGrid = BASE_CANVAS_DEFAULTS.snapGrid, initialAutoLayout, maintainNodesInView, onToolbarAction, breakpoints, panShortcutTeachingUIMessage = 'Hold Space and drag to pan around the canvas!', ...reactFlowProps } = canvasProps;
|
|
15
|
+
const { nodes = [], edges = [], nodeTypes, edgeTypes, children, mode = 'view', readOnlyNodeIds, showBackground = true, backgroundColor = BASE_CANVAS_DEFAULTS.background.color, backgroundSecondaryColor = BASE_CANVAS_DEFAULTS.background.bgColor, backgroundVariant = BASE_CANVAS_DEFAULTS.background.variant, backgroundGap = BASE_CANVAS_DEFAULTS.background.gap, backgroundSize = BASE_CANVAS_DEFAULTS.background.size, isDarkMode, locale, minZoom = BASE_CANVAS_DEFAULTS.zoom.min, maxZoom = BASE_CANVAS_DEFAULTS.zoom.max, defaultViewport = BASE_CANVAS_DEFAULTS.defaultViewport, defaultEdgeOptions = BASE_CANVAS_DEFAULTS.edge, stickyNoteOptions, onNodesChange, onEdgesChange, onConnect, onReconnect, onReconnectStart, onReconnectEnd, onConnectStart, onConnectEnd, isValidConnection, onNodeClick, onNodeDragStart, onNodeDrag, onNodeDragStop, onPaneClick, onInit, onSelectionChange, onBeforeDelete, proOptions = BASE_CANVAS_DEFAULTS.pro, connectionMode = ConnectionMode.Loose, connectionLineComponent, connectionLineStyle, deleteKeyCode = null, selectNodesOnDrag = true, nodesDraggable = true, nodesConnectable = true, elementsSelectable = true, onlyRenderVisibleElements = true, zoomOnDoubleClick = true, snapToGrid = BASE_CANVAS_DEFAULTS.snapToGrid, snapGrid = BASE_CANVAS_DEFAULTS.snapGrid, initialAutoLayout, maintainNodesInView, onToolbarAction, breakpoints, panShortcutTeachingUIMessage = 'Hold Space and drag to pan around the canvas!', ...reactFlowProps } = canvasProps;
|
|
15
16
|
const isInteractive = 'readonly' !== mode;
|
|
16
17
|
const isDesignMode = 'design' === mode;
|
|
17
18
|
const stableReadOnlyNodeIds = useStableNodeIdSet(readOnlyNodeIds);
|
|
19
|
+
const readOnlyEdgeIds = useReadOnlyEdgeIds(edges, stableReadOnlyNodeIds);
|
|
18
20
|
const guardedBeforeDelete = useReadOnlyBeforeDelete(stableReadOnlyNodeIds, onBeforeDelete);
|
|
19
21
|
const handleNodesChange = useMemo(()=>{
|
|
20
22
|
if (!onNodesChange || 0 === stableReadOnlyNodeIds.size) return onNodesChange;
|
|
@@ -27,6 +29,24 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
27
29
|
onNodesChange,
|
|
28
30
|
stableReadOnlyNodeIds
|
|
29
31
|
]);
|
|
32
|
+
const handleEdgesChange = useMemo(()=>{
|
|
33
|
+
if (!onEdgesChange || 0 === readOnlyEdgeIds.size) return onEdgesChange;
|
|
34
|
+
const guarded = (changes)=>{
|
|
35
|
+
const allowed = changes.filter((change)=>'remove' === change.type ? !readOnlyEdgeIds.has(change.id) : true);
|
|
36
|
+
if (allowed.length > 0) onEdgesChange(allowed);
|
|
37
|
+
};
|
|
38
|
+
return guarded;
|
|
39
|
+
}, [
|
|
40
|
+
onEdgesChange,
|
|
41
|
+
readOnlyEdgeIds
|
|
42
|
+
]);
|
|
43
|
+
const { guardedIsValidConnection, guardedOnConnect, guardedOnReconnect, guardedOnReconnectEnd } = useReadOnlyConnectionCallbacks({
|
|
44
|
+
readOnlyNodeIds: stableReadOnlyNodeIds,
|
|
45
|
+
isValidConnection,
|
|
46
|
+
onConnect,
|
|
47
|
+
onReconnect,
|
|
48
|
+
onReconnectEnd
|
|
49
|
+
});
|
|
30
50
|
const [reactFlowInstance, setReactFlowInstance] = useState();
|
|
31
51
|
const { isReady } = useAutoLayout(nodes, initialAutoLayout, fitViewOptions);
|
|
32
52
|
const { ensureNodesInView, ensureAllNodesInView, centerNode } = useEnsureNodesInView();
|
|
@@ -68,6 +88,7 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
68
88
|
colorMode: '',
|
|
69
89
|
nodes: nodes,
|
|
70
90
|
edges: edges,
|
|
91
|
+
isValidConnection: guardedIsValidConnection,
|
|
71
92
|
nodeTypes: nodeTypes,
|
|
72
93
|
edgeTypes: edgeTypes,
|
|
73
94
|
fitViewOptions: fitViewOptions,
|
|
@@ -93,9 +114,12 @@ const BaseCanvasInnerComponent = (props)=>{
|
|
|
93
114
|
panOnDrag: isInteractive ? PAN_ON_DRAG : false,
|
|
94
115
|
onInit: handleInit,
|
|
95
116
|
onNodesChange: isInteractive ? handleNodesChange : void 0,
|
|
96
|
-
onEdgesChange: isInteractive ?
|
|
117
|
+
onEdgesChange: isInteractive ? handleEdgesChange : void 0,
|
|
97
118
|
onBeforeDelete: guardedBeforeDelete,
|
|
98
|
-
onConnect: isDesignMode ?
|
|
119
|
+
onConnect: isDesignMode ? guardedOnConnect : void 0,
|
|
120
|
+
onReconnect: isDesignMode ? guardedOnReconnect : void 0,
|
|
121
|
+
onReconnectStart: isDesignMode ? onReconnectStart : void 0,
|
|
122
|
+
onReconnectEnd: isDesignMode ? guardedOnReconnectEnd : void 0,
|
|
99
123
|
onConnectStart: isDesignMode ? onConnectStart : void 0,
|
|
100
124
|
onConnectEnd: isDesignMode ? onConnectEnd : void 0,
|
|
101
125
|
onNodeClick: isInteractive ? onNodeClick : void 0,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createConnectionComparisonNodes: ()=>createConnectionComparisonNodes
|
|
28
|
+
});
|
|
29
|
+
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
|
|
30
|
+
const index_cjs_namespaceObject = require("../../storybook-utils/index.cjs");
|
|
31
|
+
function createConnectionComparisonNodes() {
|
|
32
|
+
return [
|
|
33
|
+
(0, index_cjs_namespaceObject.createNode)({
|
|
34
|
+
id: 'connection-source',
|
|
35
|
+
type: 'uipath.blank-node',
|
|
36
|
+
position: {
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0
|
|
39
|
+
},
|
|
40
|
+
display: {
|
|
41
|
+
label: 'Submit expense'
|
|
42
|
+
},
|
|
43
|
+
handleConfigurations: [
|
|
44
|
+
{
|
|
45
|
+
position: react_cjs_namespaceObject.Position.Right,
|
|
46
|
+
handles: [
|
|
47
|
+
{
|
|
48
|
+
id: `out-${react_cjs_namespaceObject.Position.Right}`,
|
|
49
|
+
type: 'source',
|
|
50
|
+
handleType: 'output'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}),
|
|
56
|
+
(0, index_cjs_namespaceObject.createNode)({
|
|
57
|
+
id: 'connection-target',
|
|
58
|
+
type: 'uipath.blank-node',
|
|
59
|
+
position: {
|
|
60
|
+
x: 320,
|
|
61
|
+
y: 0
|
|
62
|
+
},
|
|
63
|
+
display: {
|
|
64
|
+
label: 'Review expense'
|
|
65
|
+
},
|
|
66
|
+
handleConfigurations: [
|
|
67
|
+
{
|
|
68
|
+
position: react_cjs_namespaceObject.Position.Left,
|
|
69
|
+
handles: [
|
|
70
|
+
{
|
|
71
|
+
id: `in-${react_cjs_namespaceObject.Position.Left}`,
|
|
72
|
+
type: 'target',
|
|
73
|
+
handleType: 'input'
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
})
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
exports.createConnectionComparisonNodes = __webpack_exports__.createConnectionComparisonNodes;
|
|
82
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
83
|
+
"createConnectionComparisonNodes"
|
|
84
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
|
+
Object.defineProperty(exports, '__esModule', {
|
|
86
|
+
value: true
|
|
87
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseCanvas.stories.fixtures.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.stories.fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAGrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,wBAAgB,+BAA+B,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,CAuCtE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Position } from "../../xyflow/react.js";
|
|
2
|
+
import { createNode } from "../../storybook-utils/index.js";
|
|
3
|
+
function createConnectionComparisonNodes() {
|
|
4
|
+
return [
|
|
5
|
+
createNode({
|
|
6
|
+
id: 'connection-source',
|
|
7
|
+
type: 'uipath.blank-node',
|
|
8
|
+
position: {
|
|
9
|
+
x: 0,
|
|
10
|
+
y: 0
|
|
11
|
+
},
|
|
12
|
+
display: {
|
|
13
|
+
label: 'Submit expense'
|
|
14
|
+
},
|
|
15
|
+
handleConfigurations: [
|
|
16
|
+
{
|
|
17
|
+
position: Position.Right,
|
|
18
|
+
handles: [
|
|
19
|
+
{
|
|
20
|
+
id: `out-${Position.Right}`,
|
|
21
|
+
type: 'source',
|
|
22
|
+
handleType: 'output'
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}),
|
|
28
|
+
createNode({
|
|
29
|
+
id: 'connection-target',
|
|
30
|
+
type: 'uipath.blank-node',
|
|
31
|
+
position: {
|
|
32
|
+
x: 320,
|
|
33
|
+
y: 0
|
|
34
|
+
},
|
|
35
|
+
display: {
|
|
36
|
+
label: 'Review expense'
|
|
37
|
+
},
|
|
38
|
+
handleConfigurations: [
|
|
39
|
+
{
|
|
40
|
+
position: Position.Left,
|
|
41
|
+
handles: [
|
|
42
|
+
{
|
|
43
|
+
id: `in-${Position.Left}`,
|
|
44
|
+
type: 'target',
|
|
45
|
+
handleType: 'input'
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
})
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
export { createConnectionComparisonNodes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCanvas.types.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,IAAI,EACJ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAMtF,MAAM,WAAW,wBAAwB;IAOvC,OAAO,CAAC,EACJ,MAAM,GACN;QACE,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAON,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,IAAI,CACzF,SAAQ,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAe1C,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseCanvas.types.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/BaseCanvas.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,IAAI,EACJ,IAAI,EACJ,iBAAiB,EACjB,cAAc,EACf,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAMtF,MAAM,WAAW,wBAAwB;IAOvC,OAAO,CAAC,EACJ,MAAM,GACN;QACE,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAON,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,IAAI,CACzF,SAAQ,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAe1C,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;IAiCtC,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,MAAM,EAAE,CAAC;IAM1D,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAO5C,QAAQ,CAAC,EAAE,SAAS,CAAC;IAOrB,cAAc,CAAC,EAAE,OAAO,CAAC;IAKzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAKzB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAOlC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAOtC,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAcxB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAkB/C,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAM/B,4BAA4B,CAAC,EAAE,MAAM,CAAC;IAUtC,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAK1C,eAAe,CAAC,EAAE,oBAAoB,CAAC;IAMvC,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAW1B,UAAU,CAAC,EAAE,OAAO,CAAC;IAOrB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAMD,MAAM,WAAW,wBAAwB;IAKvC,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAMlB,OAAO,CAAC,EAAE,MAAM,CAAC;IAMjB,OAAO,CAAC,EAAE,MAAM,CAAC;IAOjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AASD,MAAM,WAAW,aAAa,CAAC,QAAQ,SAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,IAAI;IAgBvF,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAa/E,oBAAoB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAiB/D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAyBrE,SAAS,EAAE,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC;CAC9D"}
|
|
@@ -24,9 +24,12 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
useStableNodeIdSet: ()=>useStableNodeIdSet,
|
|
28
|
+
isConnectionReadOnly: ()=>isConnectionReadOnly,
|
|
27
29
|
useIsNodeReadOnly: ()=>useIsNodeReadOnly,
|
|
28
30
|
ReadOnlyNodesProvider: ()=>ReadOnlyNodesProvider,
|
|
29
|
-
|
|
31
|
+
useIsConnectionReadOnly: ()=>useIsConnectionReadOnly,
|
|
32
|
+
useReadOnlyConnectionCheck: ()=>useReadOnlyConnectionCheck
|
|
30
33
|
});
|
|
31
34
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
32
35
|
const external_react_namespaceObject = require("react");
|
|
@@ -35,8 +38,8 @@ const external_set_utils_cjs_namespaceObject = require("./set-utils.cjs");
|
|
|
35
38
|
class ReadOnlyNodesStore {
|
|
36
39
|
ids;
|
|
37
40
|
listeners = new Map();
|
|
38
|
-
constructor(
|
|
39
|
-
this.ids = 0 ===
|
|
41
|
+
constructor(initialIds = external_set_utils_cjs_namespaceObject.EMPTY_SET){
|
|
42
|
+
this.ids = 0 === initialIds.size ? external_set_utils_cjs_namespaceObject.EMPTY_SET : new Set(initialIds);
|
|
40
43
|
}
|
|
41
44
|
subscribe(nodeId, listener) {
|
|
42
45
|
let nodeListeners = this.listeners.get(nodeId);
|
|
@@ -53,6 +56,9 @@ class ReadOnlyNodesStore {
|
|
|
53
56
|
isReadOnly(nodeId) {
|
|
54
57
|
return this.ids.has(nodeId);
|
|
55
58
|
}
|
|
59
|
+
isConnectionReadOnly(source, target) {
|
|
60
|
+
return isConnectionReadOnly(this.ids, source, target);
|
|
61
|
+
}
|
|
56
62
|
update(next) {
|
|
57
63
|
const prev = this.ids;
|
|
58
64
|
if ((0, external_set_utils_cjs_namespaceObject.setsEqual)(prev, next)) return;
|
|
@@ -73,6 +79,10 @@ function useStableNodeIdSet(ids) {
|
|
|
73
79
|
if (!(0, external_set_utils_cjs_namespaceObject.setsEqual)(ref.current, next)) ref.current = 0 === next.size ? external_set_utils_cjs_namespaceObject.EMPTY_SET : new Set(next);
|
|
74
80
|
return ref.current;
|
|
75
81
|
}
|
|
82
|
+
function isConnectionReadOnly(readOnlyNodeIds, source, target) {
|
|
83
|
+
if (0 === readOnlyNodeIds.size || !source || !target) return false;
|
|
84
|
+
return readOnlyNodeIds.has(source) && readOnlyNodeIds.has(target);
|
|
85
|
+
}
|
|
76
86
|
const ReadOnlyNodesProvider = ({ children, readOnlyNodeIds })=>{
|
|
77
87
|
const storeRef = (0, external_react_namespaceObject.useRef)(void 0);
|
|
78
88
|
if (!storeRef.current) storeRef.current = new ReadOnlyNodesStore(readOnlyNodeIds);
|
|
@@ -98,12 +108,29 @@ function useIsNodeReadOnly(nodeId) {
|
|
|
98
108
|
]);
|
|
99
109
|
return (0, external_react_namespaceObject.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
100
110
|
}
|
|
111
|
+
function useIsConnectionReadOnly(source, target) {
|
|
112
|
+
const sourceReadOnly = useIsNodeReadOnly(source ?? '');
|
|
113
|
+
const targetReadOnly = useIsNodeReadOnly(target ?? '');
|
|
114
|
+
return !!source && !!target && sourceReadOnly && targetReadOnly;
|
|
115
|
+
}
|
|
116
|
+
function useReadOnlyConnectionCheck() {
|
|
117
|
+
const store = (0, external_react_namespaceObject.useContext)(ReadOnlyNodesContext);
|
|
118
|
+
return (0, external_react_namespaceObject.useCallback)((source, target)=>store?.isConnectionReadOnly(source, target) ?? false, [
|
|
119
|
+
store
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
101
122
|
exports.ReadOnlyNodesProvider = __webpack_exports__.ReadOnlyNodesProvider;
|
|
123
|
+
exports.isConnectionReadOnly = __webpack_exports__.isConnectionReadOnly;
|
|
124
|
+
exports.useIsConnectionReadOnly = __webpack_exports__.useIsConnectionReadOnly;
|
|
102
125
|
exports.useIsNodeReadOnly = __webpack_exports__.useIsNodeReadOnly;
|
|
126
|
+
exports.useReadOnlyConnectionCheck = __webpack_exports__.useReadOnlyConnectionCheck;
|
|
103
127
|
exports.useStableNodeIdSet = __webpack_exports__.useStableNodeIdSet;
|
|
104
128
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
105
129
|
"ReadOnlyNodesProvider",
|
|
130
|
+
"isConnectionReadOnly",
|
|
131
|
+
"useIsConnectionReadOnly",
|
|
106
132
|
"useIsNodeReadOnly",
|
|
133
|
+
"useReadOnlyConnectionCheck",
|
|
107
134
|
"useStableNodeIdSet"
|
|
108
135
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
109
136
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
export declare function useStableNodeIdSet(ids: ReadonlySet<string> | readonly string[] | undefined): ReadonlySet<string>;
|
|
3
|
+
export declare function isConnectionReadOnly(readOnlyNodeIds: ReadonlySet<string>, source: string | null | undefined, target: string | null | undefined): boolean;
|
|
3
4
|
export declare const ReadOnlyNodesProvider: React.FC<React.PropsWithChildren<{
|
|
4
5
|
readOnlyNodeIds?: ReadonlySet<string>;
|
|
5
6
|
}>>;
|
|
6
7
|
export declare function useIsNodeReadOnly(nodeId: string): boolean;
|
|
8
|
+
export declare function useIsConnectionReadOnly(source: string | null | undefined, target: string | null | undefined): boolean;
|
|
9
|
+
export declare function useReadOnlyConnectionCheck(): (source: string | null | undefined, target: string | null | undefined) => boolean;
|
|
7
10
|
//# sourceMappingURL=ReadOnlyNodesContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReadOnlyNodesContext.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/ReadOnlyNodesContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ReadOnlyNodesContext.d.ts","sourceRoot":"","sources":["../../../../src/canvas/components/BaseCanvas/ReadOnlyNodesContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AA8F/B,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GACvD,WAAW,CAAC,MAAM,CAAC,CASrB;AAMD,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,EACpC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAChC,OAAO,CAGT;AAMD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAC1C,KAAK,CAAC,iBAAiB,CAAC;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC,CAoBnE,CAAC;AAOF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAUzD;AAMD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAChC,OAAO,CAIT;AAMD,wBAAgB,0BAA0B,aAI7B,MAAM,GAAG,IAAI,GAAG,SAAS,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,aAIxE"}
|
|
@@ -5,8 +5,8 @@ import { EMPTY_SET, setsEqual } from "./set-utils.js";
|
|
|
5
5
|
class ReadOnlyNodesStore {
|
|
6
6
|
ids;
|
|
7
7
|
listeners = new Map();
|
|
8
|
-
constructor(
|
|
9
|
-
this.ids = 0 ===
|
|
8
|
+
constructor(initialIds = EMPTY_SET){
|
|
9
|
+
this.ids = 0 === initialIds.size ? EMPTY_SET : new Set(initialIds);
|
|
10
10
|
}
|
|
11
11
|
subscribe(nodeId, listener) {
|
|
12
12
|
let nodeListeners = this.listeners.get(nodeId);
|
|
@@ -23,6 +23,9 @@ class ReadOnlyNodesStore {
|
|
|
23
23
|
isReadOnly(nodeId) {
|
|
24
24
|
return this.ids.has(nodeId);
|
|
25
25
|
}
|
|
26
|
+
isConnectionReadOnly(source, target) {
|
|
27
|
+
return isConnectionReadOnly(this.ids, source, target);
|
|
28
|
+
}
|
|
26
29
|
update(next) {
|
|
27
30
|
const prev = this.ids;
|
|
28
31
|
if (setsEqual(prev, next)) return;
|
|
@@ -43,6 +46,10 @@ function useStableNodeIdSet(ids) {
|
|
|
43
46
|
if (!setsEqual(ref.current, next)) ref.current = 0 === next.size ? EMPTY_SET : new Set(next);
|
|
44
47
|
return ref.current;
|
|
45
48
|
}
|
|
49
|
+
function isConnectionReadOnly(readOnlyNodeIds, source, target) {
|
|
50
|
+
if (0 === readOnlyNodeIds.size || !source || !target) return false;
|
|
51
|
+
return readOnlyNodeIds.has(source) && readOnlyNodeIds.has(target);
|
|
52
|
+
}
|
|
46
53
|
const ReadOnlyNodesProvider = ({ children, readOnlyNodeIds })=>{
|
|
47
54
|
const storeRef = useRef(void 0);
|
|
48
55
|
if (!storeRef.current) storeRef.current = new ReadOnlyNodesStore(readOnlyNodeIds);
|
|
@@ -68,4 +75,15 @@ function useIsNodeReadOnly(nodeId) {
|
|
|
68
75
|
]);
|
|
69
76
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
70
77
|
}
|
|
71
|
-
|
|
78
|
+
function useIsConnectionReadOnly(source, target) {
|
|
79
|
+
const sourceReadOnly = useIsNodeReadOnly(source ?? '');
|
|
80
|
+
const targetReadOnly = useIsNodeReadOnly(target ?? '');
|
|
81
|
+
return !!source && !!target && sourceReadOnly && targetReadOnly;
|
|
82
|
+
}
|
|
83
|
+
function useReadOnlyConnectionCheck() {
|
|
84
|
+
const store = useContext(ReadOnlyNodesContext);
|
|
85
|
+
return useCallback((source, target)=>store?.isConnectionReadOnly(source, target) ?? false, [
|
|
86
|
+
store
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
export { ReadOnlyNodesProvider, isConnectionReadOnly, useIsConnectionReadOnly, useIsNodeReadOnly, useReadOnlyConnectionCheck, useStableNodeIdSet };
|