@agentscope-ai/flow 0.0.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.
- package/README.zh-CN.md +67 -0
- package/dist/components/base-node/index.d.ts +27 -0
- package/dist/components/base-node/index.js +320 -0
- package/dist/components/base-node/index.less +258 -0
- package/dist/components/branch-title-header/index.d.ts +12 -0
- package/dist/components/branch-title-header/index.js +176 -0
- package/dist/components/branch-title-header/index.less +28 -0
- package/dist/components/check-list-btn/index.d.ts +4 -0
- package/dist/components/check-list-btn/index.js +144 -0
- package/dist/components/check-list-btn/index.less +113 -0
- package/dist/components/code-input/index.d.ts +24 -0
- package/dist/components/code-input/index.js +356 -0
- package/dist/components/code-input/index.less +87 -0
- package/dist/components/condition-item/index.d.ts +13 -0
- package/dist/components/condition-item/index.js +185 -0
- package/dist/components/condition-item/index.less +23 -0
- package/dist/components/custom-connection-line/index.d.ts +4 -0
- package/dist/components/custom-connection-line/index.js +28 -0
- package/dist/components/custom-handle/source-handle.d.ts +10 -0
- package/dist/components/custom-handle/source-handle.js +45 -0
- package/dist/components/custom-handle/target-handle.d.ts +6 -0
- package/dist/components/custom-handle/target-handle.js +21 -0
- package/dist/components/custom-inputs-control/index.d.ts +56 -0
- package/dist/components/custom-inputs-control/index.js +366 -0
- package/dist/components/custom-inputs-control/index.less +28 -0
- package/dist/components/custom-outputs-form/index.d.ts +24 -0
- package/dist/components/custom-outputs-form/index.js +346 -0
- package/dist/components/custom-outputs-form/index.less +51 -0
- package/dist/components/drag-panel/index.d.ts +10 -0
- package/dist/components/drag-panel/index.js +79 -0
- package/dist/components/drag-panel/index.less +23 -0
- package/dist/components/draggable-with-handle/index.d.ts +13 -0
- package/dist/components/draggable-with-handle/index.js +81 -0
- package/dist/components/draggable-with-handle/index.less +23 -0
- package/dist/components/flow-aside/index.d.ts +4 -0
- package/dist/components/flow-aside/index.js +62 -0
- package/dist/components/flow-aside/index.less +84 -0
- package/dist/components/flow-base-edge/index.d.ts +5 -0
- package/dist/components/flow-base-edge/index.js +226 -0
- package/dist/components/flow-base-edge/index.less +28 -0
- package/dist/components/flow-base-edge/linear-gradient-svg.d.ts +21 -0
- package/dist/components/flow-base-edge/linear-gradient-svg.js +32 -0
- package/dist/components/flow-icon/index.d.ts +9 -0
- package/dist/components/flow-icon/index.js +30 -0
- package/dist/components/flow-icon/index.less +20 -0
- package/dist/components/flow-mini-map/index.d.ts +4 -0
- package/dist/components/flow-mini-map/index.js +26 -0
- package/dist/components/flow-mini-map/index.less +22 -0
- package/dist/components/flow-panel/config-panel.d.ts +15 -0
- package/dist/components/flow-panel/config-panel.js +303 -0
- package/dist/components/flow-panel/index.d.ts +7 -0
- package/dist/components/flow-panel/index.js +7 -0
- package/dist/components/flow-panel/index.less +85 -0
- package/dist/components/flow-panel/panel-container.d.ts +12 -0
- package/dist/components/flow-panel/panel-container.js +25 -0
- package/dist/components/flow-tools/add-node-btn.d.ts +3 -0
- package/dist/components/flow-tools/add-node-btn.js +26 -0
- package/dist/components/flow-tools/history-btn.d.ts +3 -0
- package/dist/components/flow-tools/history-btn.js +59 -0
- package/dist/components/flow-tools/index.d.ts +4 -0
- package/dist/components/flow-tools/index.js +29 -0
- package/dist/components/flow-tools/index.less +82 -0
- package/dist/components/flow-tools/layout-btn.d.ts +3 -0
- package/dist/components/flow-tools/layout-btn.js +27 -0
- package/dist/components/flow-tools/mini-map-btn.d.ts +3 -0
- package/dist/components/flow-tools/mini-map-btn.js +32 -0
- package/dist/components/flow-tools/scale-btn.d.ts +3 -0
- package/dist/components/flow-tools/scale-btn.js +101 -0
- package/dist/components/flow-tools/short-key-btn.d.ts +3 -0
- package/dist/components/flow-tools/short-key-btn.js +38 -0
- package/dist/components/flow-tools/short-key-content.d.ts +4 -0
- package/dist/components/flow-tools/short-key-content.js +153 -0
- package/dist/components/flow-tools/short-key-content.less +38 -0
- package/dist/components/flow-tools/touch-mode-btn.d.ts +3 -0
- package/dist/components/flow-tools/touch-mode-btn.js +89 -0
- package/dist/components/input-text-area/index.d.ts +16 -0
- package/dist/components/input-text-area/index.js +74 -0
- package/dist/components/input-text-area/index.less +30 -0
- package/dist/components/judge-form/index.d.ts +13 -0
- package/dist/components/judge-form/index.js +182 -0
- package/dist/components/judge-form/index.less +11 -0
- package/dist/components/node-menu/index.d.ts +35 -0
- package/dist/components/node-menu/index.js +266 -0
- package/dist/components/node-menu/index.less +79 -0
- package/dist/components/node-resizer/index.d.ts +11 -0
- package/dist/components/node-resizer/index.js +46 -0
- package/dist/components/node-resizer/index.less +12 -0
- package/dist/components/node-result-panel/index.d.ts +9 -0
- package/dist/components/node-result-panel/index.js +155 -0
- package/dist/components/node-result-panel/index.less +132 -0
- package/dist/components/node-tree/index.d.ts +4 -0
- package/dist/components/node-tree/index.js +213 -0
- package/dist/components/node-tree/index.less +51 -0
- package/dist/components/output-params-tree/index.d.ts +10 -0
- package/dist/components/output-params-tree/index.js +34 -0
- package/dist/components/output-params-tree/index.less +27 -0
- package/dist/components/script-code-mirror/index.d.ts +14 -0
- package/dist/components/script-code-mirror/index.js +162 -0
- package/dist/components/script-code-mirror/index.less +11 -0
- package/dist/components/script-edit-modal/index.d.ts +30 -0
- package/dist/components/script-edit-modal/index.js +84 -0
- package/dist/components/script-edit-modal/index.less +24 -0
- package/dist/components/select-with-desc/index.d.ts +5 -0
- package/dist/components/select-with-desc/index.js +20 -0
- package/dist/components/select-with-desc/index.less +11 -0
- package/dist/components/task-status/index.d.ts +4 -0
- package/dist/components/task-status/index.js +209 -0
- package/dist/components/task-status/index.less +65 -0
- package/dist/components/var-input-text-area/index.d.ts +17 -0
- package/dist/components/var-input-text-area/index.js +211 -0
- package/dist/components/var-input-text-area/index.less +64 -0
- package/dist/components/var-type-prefix/index.d.ts +17 -0
- package/dist/components/var-type-prefix/index.js +21 -0
- package/dist/components/variable-input/index.d.ts +24 -0
- package/dist/components/variable-input/index.js +163 -0
- package/dist/components/variable-input/index.less +13 -0
- package/dist/components/variable-tree-select/index.d.ts +33 -0
- package/dist/components/variable-tree-select/index.js +160 -0
- package/dist/components/variable-tree-select/index.less +61 -0
- package/dist/constant/index.d.ts +61 -0
- package/dist/constant/index.js +515 -0
- package/dist/flow/animate.css +5 -0
- package/dist/flow/context.d.ts +12 -0
- package/dist/flow/context.js +44 -0
- package/dist/flow/index.d.ts +13 -0
- package/dist/flow/index.js +162 -0
- package/dist/flow/index.less +72 -0
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.js +10 -0
- package/dist/hooks/use-edges-interaction.d.ts +11 -0
- package/dist/hooks/use-edges-interaction.js +125 -0
- package/dist/hooks/use-flow-debug-interaction.d.ts +5 -0
- package/dist/hooks/use-flow-debug-interaction.js +23 -0
- package/dist/hooks/use-flow-interaction.d.ts +12 -0
- package/dist/hooks/use-flow-interaction.js +173 -0
- package/dist/hooks/use-flow-key-press.d.ts +1 -0
- package/dist/hooks/use-flow-key-press.js +32 -0
- package/dist/hooks/use-flow-save.d.ts +5 -0
- package/dist/hooks/use-flow-save.js +47 -0
- package/dist/hooks/use-flow-view-port.d.ts +7 -0
- package/dist/hooks/use-flow-view-port.js +46 -0
- package/dist/hooks/use-history.d.ts +21 -0
- package/dist/hooks/use-history.js +80 -0
- package/dist/hooks/use-nodes-interaction.d.ts +34 -0
- package/dist/hooks/use-nodes-interaction.js +777 -0
- package/dist/hooks/use-nodes-output-params.d.ts +31 -0
- package/dist/hooks/use-nodes-output-params.js +300 -0
- package/dist/hooks/use-nodes-update.d.ts +9 -0
- package/dist/hooks/use-nodes-update.js +38 -0
- package/dist/hooks/use-work-flow.d.ts +4 -0
- package/dist/hooks/use-work-flow.js +21 -0
- package/dist/i18n/i18n.d.ts +62 -0
- package/dist/i18n/i18n.js +111 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +12 -0
- package/dist/i18n/locales/en-us.json +327 -0
- package/dist/i18n/locales/ja-jp.json +300 -0
- package/dist/i18n/locales/zh-cn.json +327 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +47 -0
- package/dist/index.less +1 -0
- package/dist/store/index.d.ts +70 -0
- package/dist/store/index.js +146 -0
- package/dist/tailwind.css +28 -0
- package/dist/types/work-flow.d.ts +188 -0
- package/dist/types/work-flow.js +1 -0
- package/dist/utils/default-values.d.ts +2 -0
- package/dist/utils/default-values.js +16 -0
- package/dist/utils/index.d.ts +39 -0
- package/dist/utils/index.js +273 -0
- package/dist/utils/unique-id.d.ts +2 -0
- package/dist/utils/unique-id.js +39 -0
- package/dist/utils/work-flow.d.ts +17 -0
- package/dist/utils/work-flow.js +44 -0
- package/package.json +78 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
import CustomConnectionLine from "../components/custom-connection-line";
|
|
9
|
+
import FlowBaseEdge from "../components/flow-base-edge";
|
|
10
|
+
import FlowMiniMap from "../components/flow-mini-map";
|
|
11
|
+
import { useNodesReadOnly } from "../hooks";
|
|
12
|
+
import { useEdgesInteraction } from "../hooks/use-edges-interaction";
|
|
13
|
+
import { useFlowInteraction } from "../hooks/use-flow-interaction";
|
|
14
|
+
import useFlowKeyPress from "../hooks/use-flow-key-press";
|
|
15
|
+
import { useHistory } from "../hooks/use-history";
|
|
16
|
+
import { useNodesInteraction } from "../hooks/use-nodes-interaction";
|
|
17
|
+
import $i18n from "../i18n";
|
|
18
|
+
import { useCommonConfig } from '@agentscope-ai/design';
|
|
19
|
+
import { Background, ReactFlow, useEdgesState, useNodesState } from '@xyflow/react';
|
|
20
|
+
import '@xyflow/react/dist/style.css';
|
|
21
|
+
import { message } from 'antd';
|
|
22
|
+
import classNames from 'classnames';
|
|
23
|
+
import React, { memo, useCallback, useEffect, useMemo } from 'react';
|
|
24
|
+
import useBus from 'use-bus';
|
|
25
|
+
import "./animate.css";
|
|
26
|
+
import { useStore } from "./context";
|
|
27
|
+
import "./index.less";
|
|
28
|
+
var Flow = /*#__PURE__*/memo(function (props) {
|
|
29
|
+
var _useNodesState = useNodesState([]),
|
|
30
|
+
_useNodesState2 = _slicedToArray(_useNodesState, 2),
|
|
31
|
+
nodes = _useNodesState2[0],
|
|
32
|
+
setNodes = _useNodesState2[1];
|
|
33
|
+
var _useEdgesState = useEdgesState([]),
|
|
34
|
+
_useEdgesState2 = _slicedToArray(_useEdgesState, 2),
|
|
35
|
+
edges = _useEdgesState2[0],
|
|
36
|
+
setEdges = _useEdgesState2[1];
|
|
37
|
+
var _useNodesInteraction = useNodesInteraction(),
|
|
38
|
+
onDrop = _useNodesInteraction.onDrop,
|
|
39
|
+
onDragOver = _useNodesInteraction.onDragOver;
|
|
40
|
+
var _useFlowInteraction = useFlowInteraction(),
|
|
41
|
+
autoFitView = _useFlowInteraction.autoFitView;
|
|
42
|
+
var _useNodesInteraction2 = useNodesInteraction(),
|
|
43
|
+
onConnect = _useNodesInteraction2.onConnect,
|
|
44
|
+
onNodeDrag = _useNodesInteraction2.onNodeDrag,
|
|
45
|
+
onNodesChange = _useNodesInteraction2.onNodesChange,
|
|
46
|
+
onNodeClick = _useNodesInteraction2.onNodeClick;
|
|
47
|
+
useFlowKeyPress();
|
|
48
|
+
var _useEdgesInteraction = useEdgesInteraction(),
|
|
49
|
+
onEdgeEnter = _useEdgesInteraction.onEdgeEnter,
|
|
50
|
+
onEdgeLeave = _useEdgesInteraction.onEdgeLeave,
|
|
51
|
+
onEdgesChange = _useEdgesInteraction.onEdgesChange,
|
|
52
|
+
onReconnect = _useEdgesInteraction.onReconnect;
|
|
53
|
+
var nodeSchemaMap = useStore(function (state) {
|
|
54
|
+
return state.nodeSchemaMap;
|
|
55
|
+
});
|
|
56
|
+
var _useHistory = useHistory(),
|
|
57
|
+
initHistoryStep = _useHistory.initHistoryStep;
|
|
58
|
+
var _useStore = useStore(function (state) {
|
|
59
|
+
return state.minMaxZoom;
|
|
60
|
+
}),
|
|
61
|
+
_useStore2 = _slicedToArray(_useStore, 2),
|
|
62
|
+
minZoom = _useStore2[0],
|
|
63
|
+
maxZoom = _useStore2[1];
|
|
64
|
+
var interactiveMode = useStore(function (state) {
|
|
65
|
+
return state.interactiveMode;
|
|
66
|
+
});
|
|
67
|
+
var showSingleTest = useStore(function (state) {
|
|
68
|
+
return state.showSingleTest;
|
|
69
|
+
});
|
|
70
|
+
var _useNodesReadOnly = useNodesReadOnly(),
|
|
71
|
+
nodesReadOnly = _useNodesReadOnly.nodesReadOnly;
|
|
72
|
+
useEffect(function () {
|
|
73
|
+
var _props$onFlowEvent;
|
|
74
|
+
(_props$onFlowEvent = props.onFlowEvent) === null || _props$onFlowEvent === void 0 || _props$onFlowEvent.call(props, 'showSingleTest', null);
|
|
75
|
+
}, [showSingleTest]);
|
|
76
|
+
var handleUpdateFlowData = function handleUpdateFlowData(event) {
|
|
77
|
+
var data = event.data;
|
|
78
|
+
setNodes(data.nodes);
|
|
79
|
+
setEdges(data.edges);
|
|
80
|
+
initHistoryStep({
|
|
81
|
+
nodes: data.nodes,
|
|
82
|
+
edges: data.edges
|
|
83
|
+
});
|
|
84
|
+
setTimeout(function () {
|
|
85
|
+
autoFitView();
|
|
86
|
+
}, 200);
|
|
87
|
+
};
|
|
88
|
+
var onBeforeDelete = useCallback(function (willDeleteData) {
|
|
89
|
+
var allowDeleteNodes = [];
|
|
90
|
+
var showTip = false;
|
|
91
|
+
willDeleteData.nodes.forEach(function (node) {
|
|
92
|
+
if (nodeSchemaMap[node.type].isSystem && !willDeleteData.nodes.some(function (item) {
|
|
93
|
+
return item.id === node.parentId;
|
|
94
|
+
})) {
|
|
95
|
+
showTip = true;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
allowDeleteNodes.push(node);
|
|
99
|
+
});
|
|
100
|
+
if (showTip) {
|
|
101
|
+
message.warning($i18n.get({
|
|
102
|
+
id: 'spark-flow.flow.index.systemNodeCannotBeDeleted',
|
|
103
|
+
dm: '系统节点不允许删除'
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
return Promise.resolve({
|
|
107
|
+
nodes: allowDeleteNodes,
|
|
108
|
+
edges: willDeleteData.edges
|
|
109
|
+
});
|
|
110
|
+
}, [nodeSchemaMap]);
|
|
111
|
+
var memoInteractionProps = useMemo(function () {
|
|
112
|
+
return interactiveMode === 'touch' ? {
|
|
113
|
+
panOnDrag: false,
|
|
114
|
+
zoomOnScroll: true,
|
|
115
|
+
panOnScroll: true
|
|
116
|
+
} : {
|
|
117
|
+
panOnDrag: true
|
|
118
|
+
};
|
|
119
|
+
}, [interactiveMode]);
|
|
120
|
+
useBus('update-flow-data', handleUpdateFlowData);
|
|
121
|
+
var _useCommonConfig = useCommonConfig(),
|
|
122
|
+
isDarkMode = _useCommonConfig.isDarkMode;
|
|
123
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
124
|
+
className: classNames('spark-flow-container', {
|
|
125
|
+
'spark-flow-container-readonly': nodesReadOnly
|
|
126
|
+
})
|
|
127
|
+
}, /*#__PURE__*/React.createElement(ReactFlow, _extends({
|
|
128
|
+
proOptions: {
|
|
129
|
+
hideAttribution: true
|
|
130
|
+
},
|
|
131
|
+
connectionLineComponent: CustomConnectionLine,
|
|
132
|
+
nodes: nodes,
|
|
133
|
+
edges: edges,
|
|
134
|
+
colorMode: isDarkMode ? 'dark' : 'light',
|
|
135
|
+
nodeTypes: props.nodeTypes,
|
|
136
|
+
onDragOver: onDragOver,
|
|
137
|
+
onNodeDrag: onNodeDrag,
|
|
138
|
+
onNodeClick: onNodeClick,
|
|
139
|
+
onNodesChange: onNodesChange,
|
|
140
|
+
onBeforeDelete: onBeforeDelete,
|
|
141
|
+
onDrop: onDrop,
|
|
142
|
+
onConnect: onConnect,
|
|
143
|
+
onEdgeMouseEnter: onEdgeEnter,
|
|
144
|
+
onEdgeMouseLeave: onEdgeLeave,
|
|
145
|
+
onEdgesChange: onEdgesChange,
|
|
146
|
+
noWheelClassName: "nowheel"
|
|
147
|
+
}, memoInteractionProps, {
|
|
148
|
+
nodesDraggable: !nodesReadOnly,
|
|
149
|
+
nodesConnectable: !nodesReadOnly,
|
|
150
|
+
elementsSelectable: !nodesReadOnly,
|
|
151
|
+
edgesFocusable: !nodesReadOnly,
|
|
152
|
+
edgesReconnectable: !nodesReadOnly,
|
|
153
|
+
onReconnect: onReconnect,
|
|
154
|
+
onlyRenderVisibleElements: props.onlyRenderVisibleElements,
|
|
155
|
+
edgeTypes: {
|
|
156
|
+
default: FlowBaseEdge
|
|
157
|
+
},
|
|
158
|
+
minZoom: minZoom,
|
|
159
|
+
maxZoom: maxZoom
|
|
160
|
+
}), /*#__PURE__*/React.createElement(FlowMiniMap, null), /*#__PURE__*/React.createElement(Background, null)));
|
|
161
|
+
});
|
|
162
|
+
export default Flow;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
@import '../index.less';
|
|
2
|
+
|
|
3
|
+
.spark-flow-small-padding-popover {
|
|
4
|
+
&.@{ant-prefix}-popover .@{ant-prefix}-popover-inner {
|
|
5
|
+
padding: 4px 8px;
|
|
6
|
+
}
|
|
7
|
+
.@{ant-prefix}-popover-inner-content {
|
|
8
|
+
max-height: 280px;
|
|
9
|
+
overflow-y: auto;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.spark-var-type {
|
|
14
|
+
font-family: Menlo, monospace;
|
|
15
|
+
margin: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.spark-flow-container-wrap {
|
|
19
|
+
height: 100%;
|
|
20
|
+
width: 100%;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.spark-flow-container {
|
|
24
|
+
position: relative;
|
|
25
|
+
height: 100%;
|
|
26
|
+
width: 100%;
|
|
27
|
+
|
|
28
|
+
.react-flow__background {
|
|
29
|
+
background-color: e('var(--@{ant-prefix}-color-bg-layout)');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.spark-flow-icon {
|
|
34
|
+
font-size: 16px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.spark-flow-operator-icon-with-bg {
|
|
38
|
+
transition: 0.4s ease-in-out;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
|
|
41
|
+
.spark-flow-node-action-btn {
|
|
42
|
+
color: e('var(--@{ant-prefix}-color-text-secondary)');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
&:hover {
|
|
46
|
+
background: e('var(--@{ant-prefix}-color-primary-bg)');
|
|
47
|
+
|
|
48
|
+
.spark-flow-node-action-btn {
|
|
49
|
+
color: e('var(--@{ant-prefix}-color-primary)');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.spark-flow-text-btn {
|
|
55
|
+
font-size: 12px;
|
|
56
|
+
padding: 0;
|
|
57
|
+
gap: 4px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.spark-flow-icon-base-color {
|
|
61
|
+
color: e('var(--@{ant-prefix}-color-text-tertiary)');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.text-desc {
|
|
65
|
+
color: e('var(--@{ant-prefix}-color-text-tertiary)');
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.spark-flow-disabled-icon-btn {
|
|
70
|
+
color: e('var(--@{ant-prefix}-color-text-disabled)');
|
|
71
|
+
cursor: not-allowed;
|
|
72
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './use-edges-interaction';
|
|
2
|
+
export * from './use-flow-debug-interaction';
|
|
3
|
+
export * from './use-flow-interaction';
|
|
4
|
+
export * from './use-flow-key-press';
|
|
5
|
+
export * from './use-flow-save';
|
|
6
|
+
export * from './use-flow-view-port';
|
|
7
|
+
export * from './use-nodes-interaction';
|
|
8
|
+
export * from './use-nodes-output-params';
|
|
9
|
+
export * from './use-nodes-update';
|
|
10
|
+
export * from './use-work-flow';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./use-edges-interaction";
|
|
2
|
+
export * from "./use-flow-debug-interaction";
|
|
3
|
+
export * from "./use-flow-interaction";
|
|
4
|
+
export * from "./use-flow-key-press";
|
|
5
|
+
export * from "./use-flow-save";
|
|
6
|
+
export * from "./use-flow-view-port";
|
|
7
|
+
export * from "./use-nodes-interaction";
|
|
8
|
+
export * from "./use-nodes-output-params";
|
|
9
|
+
export * from "./use-nodes-update";
|
|
10
|
+
export * from "./use-work-flow";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IWorkFlowNodeResultItem } from "../types/work-flow";
|
|
2
|
+
import { EdgeMouseHandler, OnEdgesChange, OnReconnect } from '@xyflow/react';
|
|
3
|
+
export declare const useEdgesInteraction: () => {
|
|
4
|
+
onEdgeEnter: EdgeMouseHandler;
|
|
5
|
+
onEdgeLeave: EdgeMouseHandler;
|
|
6
|
+
onEdgesChange: OnEdgesChange;
|
|
7
|
+
updateEdgeByNodeResults: (val: IWorkFlowNodeResultItem[]) => void;
|
|
8
|
+
hiddenEdgeStatus: () => void;
|
|
9
|
+
onReconnect: OnReconnect;
|
|
10
|
+
handleRemoveEdgeByTargetId: (targetId: string) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { applyEdgeChanges, reconnectEdge, useStoreApi } from '@xyflow/react';
|
|
8
|
+
import { useCallback } from 'react';
|
|
9
|
+
import { useFlowSave } from "./use-flow-save";
|
|
10
|
+
export var useEdgesInteraction = function useEdgesInteraction() {
|
|
11
|
+
var store = useStoreApi();
|
|
12
|
+
var _useFlowSave = useFlowSave(),
|
|
13
|
+
handleSaveFlowDraft = _useFlowSave.handleSaveFlowDraft;
|
|
14
|
+
var updateEdgeByNodeResults = useCallback(function (val) {
|
|
15
|
+
var _store$getState = store.getState(),
|
|
16
|
+
edges = _store$getState.edges,
|
|
17
|
+
setEdges = _store$getState.setEdges;
|
|
18
|
+
var cacheNodeResult = {};
|
|
19
|
+
var newEdges = edges.map(function (item) {
|
|
20
|
+
var source = item.source,
|
|
21
|
+
target = item.target;
|
|
22
|
+
var sourceNodeResult = cacheNodeResult[source] || val.find(function (v) {
|
|
23
|
+
return v.node_id === source;
|
|
24
|
+
});
|
|
25
|
+
var targetNodeResult = cacheNodeResult[target] || val.find(function (v) {
|
|
26
|
+
return v.node_id === target;
|
|
27
|
+
});
|
|
28
|
+
if (!cacheNodeResult[source]) {
|
|
29
|
+
cacheNodeResult[source] = sourceNodeResult;
|
|
30
|
+
}
|
|
31
|
+
if (!cacheNodeResult[target]) {
|
|
32
|
+
cacheNodeResult[target] = targetNodeResult;
|
|
33
|
+
}
|
|
34
|
+
if (!!sourceNodeResult && !!targetNodeResult) return _objectSpread(_objectSpread({}, item), {}, {
|
|
35
|
+
animated: targetNodeResult.node_status === 'executing',
|
|
36
|
+
data: _objectSpread(_objectSpread({}, item.data), {}, {
|
|
37
|
+
_source_node_status: sourceNodeResult.node_status,
|
|
38
|
+
_target_node_status: targetNodeResult.node_status
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
42
|
+
animated: false,
|
|
43
|
+
data: _objectSpread(_objectSpread({}, item.data), {}, {
|
|
44
|
+
_source_node_status: undefined,
|
|
45
|
+
_target_node_status: undefined
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
setEdges(newEdges);
|
|
50
|
+
}, [store]);
|
|
51
|
+
var hiddenEdgeStatus = useCallback(function () {
|
|
52
|
+
var _store$getState2 = store.getState(),
|
|
53
|
+
edges = _store$getState2.edges,
|
|
54
|
+
setEdges = _store$getState2.setEdges;
|
|
55
|
+
var newEdges = edges.map(function (item) {
|
|
56
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
57
|
+
animated: false,
|
|
58
|
+
data: _objectSpread(_objectSpread({}, item.data), {}, {
|
|
59
|
+
_source_node_status: undefined,
|
|
60
|
+
_target_node_status: undefined
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
setEdges(newEdges);
|
|
65
|
+
}, [store]);
|
|
66
|
+
var setEdgeData = useCallback(function (edgeId, payload) {
|
|
67
|
+
var _store$getState3 = store.getState(),
|
|
68
|
+
edges = _store$getState3.edges,
|
|
69
|
+
setEdges = _store$getState3.setEdges;
|
|
70
|
+
var newEdges = edges.map(function (item) {
|
|
71
|
+
if (item.id === edgeId) {
|
|
72
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
73
|
+
data: _objectSpread(_objectSpread({}, item.data || {}), payload)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return item;
|
|
77
|
+
});
|
|
78
|
+
setEdges(newEdges);
|
|
79
|
+
}, [store]);
|
|
80
|
+
var onEdgeEnter = useCallback(function (_, edge) {
|
|
81
|
+
setEdgeData(edge.id, {
|
|
82
|
+
_hover: true
|
|
83
|
+
});
|
|
84
|
+
}, [store]);
|
|
85
|
+
var onEdgeLeave = useCallback(function (_, edge) {
|
|
86
|
+
setEdgeData(edge.id, {
|
|
87
|
+
_hover: false
|
|
88
|
+
});
|
|
89
|
+
}, [store]);
|
|
90
|
+
var onEdgesChange = useCallback(function (changes) {
|
|
91
|
+
var _store$getState4 = store.getState(),
|
|
92
|
+
edges = _store$getState4.edges,
|
|
93
|
+
setEdges = _store$getState4.setEdges;
|
|
94
|
+
var newEdges = applyEdgeChanges(changes, edges);
|
|
95
|
+
setEdges(newEdges);
|
|
96
|
+
if (changes.some(function (change) {
|
|
97
|
+
return change.type === 'remove';
|
|
98
|
+
})) handleSaveFlowDraft();
|
|
99
|
+
}, [store, handleSaveFlowDraft]);
|
|
100
|
+
var onReconnect = useCallback(function (oldEdge, newConnection) {
|
|
101
|
+
var _store$getState5 = store.getState(),
|
|
102
|
+
edges = _store$getState5.edges,
|
|
103
|
+
setEdges = _store$getState5.setEdges;
|
|
104
|
+
setEdges(reconnectEdge(oldEdge, newConnection, edges));
|
|
105
|
+
handleSaveFlowDraft();
|
|
106
|
+
}, [store, handleSaveFlowDraft]);
|
|
107
|
+
var handleRemoveEdgeByTargetId = useCallback(function (targetId) {
|
|
108
|
+
var _store$getState6 = store.getState(),
|
|
109
|
+
edges = _store$getState6.edges,
|
|
110
|
+
setEdges = _store$getState6.setEdges;
|
|
111
|
+
setEdges(edges.filter(function (item) {
|
|
112
|
+
return item.sourceHandle !== targetId;
|
|
113
|
+
}));
|
|
114
|
+
handleSaveFlowDraft();
|
|
115
|
+
}, [store, handleSaveFlowDraft]);
|
|
116
|
+
return {
|
|
117
|
+
onEdgeEnter: onEdgeEnter,
|
|
118
|
+
onEdgeLeave: onEdgeLeave,
|
|
119
|
+
onEdgesChange: onEdgesChange,
|
|
120
|
+
updateEdgeByNodeResults: updateEdgeByNodeResults,
|
|
121
|
+
hiddenEdgeStatus: hiddenEdgeStatus,
|
|
122
|
+
onReconnect: onReconnect,
|
|
123
|
+
handleRemoveEdgeByTargetId: handleRemoveEdgeByTargetId
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useStore } from "../flow/context";
|
|
3
|
+
import { useEdgesInteraction } from "./use-edges-interaction";
|
|
4
|
+
export var useFlowDebugInteraction = function useFlowDebugInteraction() {
|
|
5
|
+
var setTaskStore = useStore(function (s) {
|
|
6
|
+
return s.setTaskStore;
|
|
7
|
+
});
|
|
8
|
+
var _useEdgesInteraction = useEdgesInteraction(),
|
|
9
|
+
updateEdgeByNodeResults = _useEdgesInteraction.updateEdgeByNodeResults,
|
|
10
|
+
hiddenEdgeStatus = _useEdgesInteraction.hiddenEdgeStatus;
|
|
11
|
+
var updateTaskStore = useCallback(function (val) {
|
|
12
|
+
setTaskStore(val);
|
|
13
|
+
updateEdgeByNodeResults(val.node_results);
|
|
14
|
+
}, [setTaskStore, updateEdgeByNodeResults]);
|
|
15
|
+
var clearTaskStore = useCallback(function () {
|
|
16
|
+
setTaskStore(void 0);
|
|
17
|
+
hiddenEdgeStatus();
|
|
18
|
+
}, [setTaskStore, hiddenEdgeStatus]);
|
|
19
|
+
return {
|
|
20
|
+
updateTaskStore: updateTaskStore,
|
|
21
|
+
clearTaskStore: clearTaskStore
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnSelectionChangeFunc } from '@xyflow/react';
|
|
2
|
+
export declare const useFlowInteraction: () => {
|
|
3
|
+
onSelectionChange: OnSelectionChangeFunc;
|
|
4
|
+
onFlowClearState: (options: {
|
|
5
|
+
readyOnly?: boolean;
|
|
6
|
+
}) => void;
|
|
7
|
+
autoFitView: () => void;
|
|
8
|
+
focusElement: ({ nodeId }: {
|
|
9
|
+
nodeId: string;
|
|
10
|
+
}) => void;
|
|
11
|
+
onLayout: () => Promise<void>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
|
+
import { useStore } from "../flow/context";
|
|
17
|
+
import { getIteratorNodeSize, layoutFlow } from "../utils";
|
|
18
|
+
import { useReactFlow, useStoreApi } from '@xyflow/react';
|
|
19
|
+
import { useCallback } from 'react';
|
|
20
|
+
import { useFlowDebugInteraction } from "./use-flow-debug-interaction";
|
|
21
|
+
import { useFlowSave } from "./use-flow-save";
|
|
22
|
+
export var useFlowInteraction = function useFlowInteraction() {
|
|
23
|
+
var reactFlow = useReactFlow();
|
|
24
|
+
var store = useStoreApi();
|
|
25
|
+
var _useFlowDebugInteract = useFlowDebugInteraction(),
|
|
26
|
+
clearTaskStore = _useFlowDebugInteract.clearTaskStore;
|
|
27
|
+
var setReadyOnly = useStore(function (state) {
|
|
28
|
+
return state.setReadyOnly;
|
|
29
|
+
});
|
|
30
|
+
var setSelectedNode = useStore(function (state) {
|
|
31
|
+
return state.setSelectedNode;
|
|
32
|
+
});
|
|
33
|
+
var nodeSchemaMap = useStore(function (state) {
|
|
34
|
+
return state.nodeSchemaMap;
|
|
35
|
+
});
|
|
36
|
+
var _useFlowSave = useFlowSave(),
|
|
37
|
+
handleSaveFlowDraft = _useFlowSave.handleSaveFlowDraft;
|
|
38
|
+
var onLayout = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
39
|
+
var _store$getState, nodes, edges, setNodes, subFlowNodesMap, globalNodes, globalEdges, subFlow;
|
|
40
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
41
|
+
while (1) switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
_store$getState = store.getState(), nodes = _store$getState.nodes, edges = _store$getState.edges, setNodes = _store$getState.setNodes;
|
|
44
|
+
subFlowNodesMap = {};
|
|
45
|
+
globalNodes = [];
|
|
46
|
+
nodes.forEach(function (node) {
|
|
47
|
+
if (node.parentId) {
|
|
48
|
+
if (!subFlowNodesMap[node.parentId]) {
|
|
49
|
+
subFlowNodesMap[node.parentId] = [];
|
|
50
|
+
}
|
|
51
|
+
subFlowNodesMap[node.parentId].push(node);
|
|
52
|
+
} else {
|
|
53
|
+
globalNodes.push(node);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
globalEdges = edges.filter(function (edge) {
|
|
57
|
+
return globalNodes.some(function (node) {
|
|
58
|
+
return node.id === edge.source || node.id === edge.target;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
subFlow = Object.keys(subFlowNodesMap).map(function (parentNodeId) {
|
|
62
|
+
var subFlowNodes = subFlowNodesMap[parentNodeId];
|
|
63
|
+
return {
|
|
64
|
+
nodes: subFlowNodes,
|
|
65
|
+
edges: edges.filter(function (edge) {
|
|
66
|
+
return subFlowNodes.some(function (node) {
|
|
67
|
+
return node.id === edge.source || node.id === edge.target;
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
Promise.all([layoutFlow({
|
|
73
|
+
nodes: globalNodes,
|
|
74
|
+
edges: globalEdges
|
|
75
|
+
})].concat(_toConsumableArray(subFlow.map(function (subFlow) {
|
|
76
|
+
return layoutFlow(_objectSpread(_objectSpread({}, subFlow), {}, {
|
|
77
|
+
isSubFlow: true
|
|
78
|
+
}));
|
|
79
|
+
})))).then(function (layoutedFlows) {
|
|
80
|
+
var newNodes = [];
|
|
81
|
+
layoutedFlows.forEach(function (flow) {
|
|
82
|
+
newNodes = [].concat(_toConsumableArray(newNodes), _toConsumableArray(flow.layoutedNodes));
|
|
83
|
+
});
|
|
84
|
+
newNodes = newNodes.map(function (node) {
|
|
85
|
+
if (nodeSchemaMap[node.type].isGroup) {
|
|
86
|
+
var _getIteratorNodeSize = getIteratorNodeSize(newNodes.filter(function (n) {
|
|
87
|
+
return n.parentId === node.id;
|
|
88
|
+
})),
|
|
89
|
+
width = _getIteratorNodeSize.width,
|
|
90
|
+
height = _getIteratorNodeSize.height;
|
|
91
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
92
|
+
width: width,
|
|
93
|
+
height: height
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return node;
|
|
97
|
+
});
|
|
98
|
+
setNodes(newNodes);
|
|
99
|
+
setTimeout(autoFitView, 200);
|
|
100
|
+
handleSaveFlowDraft();
|
|
101
|
+
});
|
|
102
|
+
case 7:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context.stop();
|
|
105
|
+
}
|
|
106
|
+
}, _callee);
|
|
107
|
+
})), [store, nodeSchemaMap, handleSaveFlowDraft]);
|
|
108
|
+
var focusElement = useCallback(function (_ref2) {
|
|
109
|
+
var _document$querySelect;
|
|
110
|
+
var nodeId = _ref2.nodeId;
|
|
111
|
+
var rightPanelWidth = ((_document$querySelect = document.querySelector('.spark-flow-panel-group')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.clientWidth) || 0;
|
|
112
|
+
var _store$getState2 = store.getState(),
|
|
113
|
+
nodes = _store$getState2.nodes,
|
|
114
|
+
setNodes = _store$getState2.setNodes;
|
|
115
|
+
var targetNode = nodes.find(function (item) {
|
|
116
|
+
return item.id === nodeId;
|
|
117
|
+
});
|
|
118
|
+
if (!targetNode) return;
|
|
119
|
+
var parentNode = targetNode.parentId ? nodes.find(function (item) {
|
|
120
|
+
return item.id === targetNode.parentId;
|
|
121
|
+
}) || {
|
|
122
|
+
position: {
|
|
123
|
+
x: 0,
|
|
124
|
+
y: 0
|
|
125
|
+
}
|
|
126
|
+
} : {
|
|
127
|
+
position: {
|
|
128
|
+
x: 0,
|
|
129
|
+
y: 0
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
reactFlow.setCenter(targetNode.position.x + parentNode.position.x + rightPanelWidth / 2 + (targetNode.width || 0) / 2, targetNode.position.y + parentNode.position.y + (targetNode.height || 0) / 2, {
|
|
133
|
+
zoom: targetNode.width > 1000 || targetNode.height > 1000 ? 0.45 : 0.75,
|
|
134
|
+
duration: 400
|
|
135
|
+
});
|
|
136
|
+
setNodes(nodes.map(function (item) {
|
|
137
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
138
|
+
selected: item.id === nodeId
|
|
139
|
+
});
|
|
140
|
+
}));
|
|
141
|
+
}, [store]);
|
|
142
|
+
var autoFitView = useCallback(function () {
|
|
143
|
+
reactFlow.fitView({
|
|
144
|
+
duration: 400
|
|
145
|
+
});
|
|
146
|
+
}, [reactFlow, store]);
|
|
147
|
+
var onSelectionChange = useCallback(function (_ref3) {
|
|
148
|
+
var selectedNodes = _ref3.nodes;
|
|
149
|
+
var _store$getState3 = store.getState(),
|
|
150
|
+
nodes = _store$getState3.nodes,
|
|
151
|
+
setNodes = _store$getState3.setNodes;
|
|
152
|
+
var newNodes = nodes.map(function (node) {
|
|
153
|
+
return _objectSpread(_objectSpread({}, node), {}, {
|
|
154
|
+
selected: selectedNodes.some(function (selectedNode) {
|
|
155
|
+
return selectedNode.id === node.id;
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
setNodes(newNodes);
|
|
160
|
+
}, [store]);
|
|
161
|
+
var onFlowClearState = useCallback(function (options) {
|
|
162
|
+
clearTaskStore();
|
|
163
|
+
setReadyOnly(options.readyOnly || false);
|
|
164
|
+
setSelectedNode(null);
|
|
165
|
+
}, [clearTaskStore, setReadyOnly, setSelectedNode]);
|
|
166
|
+
return {
|
|
167
|
+
onSelectionChange: onSelectionChange,
|
|
168
|
+
onFlowClearState: onFlowClearState,
|
|
169
|
+
autoFitView: autoFitView,
|
|
170
|
+
focusElement: focusElement,
|
|
171
|
+
onLayout: onLayout
|
|
172
|
+
};
|
|
173
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useFlowKeyPress(): void;
|