strategy-panel 1.0.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.
Files changed (162) hide show
  1. package/.eslintrc.js +9 -0
  2. package/.fatherrc.ts +26 -0
  3. package/.prettierrc.js +1 -0
  4. package/.umirc.ts +29 -0
  5. package/LICENSE +22 -0
  6. package/README.md +33 -0
  7. package/es/assets/AND.svg +11 -0
  8. package/es/assets/OR.svg +11 -0
  9. package/es/assets/XOR.svg +11 -0
  10. package/es/assets/add.svg +13 -0
  11. package/es/assets/alarm.svg +11 -0
  12. package/es/assets/application.svg +11 -0
  13. package/es/assets/cancel.svg +13 -0
  14. package/es/assets/check.svg +12 -0
  15. package/es/assets/condition.svg +12 -0
  16. package/es/assets/control.svg +11 -0
  17. package/es/assets/decive.svg +11 -0
  18. package/es/assets/delete.svg +11 -0
  19. package/es/assets/device.svg +11 -0
  20. package/es/assets/edit.svg +11 -0
  21. package/es/assets/hand.svg +11 -0
  22. package/es/assets/link.svg +11 -0
  23. package/es/assets/logical.svg +12 -0
  24. package/es/assets/notice.svg +11 -0
  25. package/es/assets/order.svg +11 -0
  26. package/es/assets/relation.svg +11 -0
  27. package/es/assets/rhombus.svg +3 -0
  28. package/es/assets/save.svg +13 -0
  29. package/es/assets/time.svg +11 -0
  30. package/es/assets/variate.svg +12 -0
  31. package/es/common/constants/global.d.ts +1 -0
  32. package/es/common/constants/global.js +1 -0
  33. package/es/common/constants/graph.d.ts +10 -0
  34. package/es/common/constants/graph.js +17 -0
  35. package/es/common/graph-common/category-type.d.ts +16 -0
  36. package/es/common/graph-common/category-type.js +72 -0
  37. package/es/common/graph-common/connector/index.d.ts +1 -0
  38. package/es/common/graph-common/connector/index.js +14 -0
  39. package/es/common/graph-common/node-element/common-element.less +117 -0
  40. package/es/common/graph-common/node-element/condition-element.d.ts +8 -0
  41. package/es/common/graph-common/node-element/condition-element.js +35 -0
  42. package/es/common/graph-common/node-element/condition-element.less +82 -0
  43. package/es/common/graph-common/node-element/logical-element.d.ts +8 -0
  44. package/es/common/graph-common/node-element/logical-element.js +34 -0
  45. package/es/common/graph-common/node-element/logical-element.less +54 -0
  46. package/es/common/graph-common/node-element/node-element.d.ts +8 -0
  47. package/es/common/graph-common/node-element/node-element.js +27 -0
  48. package/es/common/graph-common/node-element/node-element.less +48 -0
  49. package/es/common/graph-common/node-element/node-group.d.ts +8 -0
  50. package/es/common/graph-common/node-element/node-group.js +395 -0
  51. package/es/common/graph-common/node-element/node-group.less +53 -0
  52. package/es/common/graph-common/node-popover/index.d.ts +7 -0
  53. package/es/common/graph-common/node-popover/index.js +11 -0
  54. package/es/common/graph-common/node-popover/index.less +5 -0
  55. package/es/common/graph-common/node-types.d.ts +28 -0
  56. package/es/common/graph-common/node-types.js +60 -0
  57. package/es/common/graph-common/shape/edge.d.ts +10 -0
  58. package/es/common/graph-common/shape/edge.js +115 -0
  59. package/es/common/graph-common/shape/edge.less +8 -0
  60. package/es/common/graph-common/shape/node.d.ts +6 -0
  61. package/es/common/graph-common/shape/node.js +6 -0
  62. package/es/common/graph-common/shape/nodes/BaseNode.d.ts +4 -0
  63. package/es/common/graph-common/shape/nodes/BaseNode.js +46 -0
  64. package/es/common/graph-common/shape/nodes/CommonNode.d.ts +5 -0
  65. package/es/common/graph-common/shape/nodes/CommonNode.js +118 -0
  66. package/es/common/graph-common/shape/nodes/ConditionJudgment.d.ts +5 -0
  67. package/es/common/graph-common/shape/nodes/ConditionJudgment.js +130 -0
  68. package/es/common/graph-common/shape/nodes/GroupNode.d.ts +4 -0
  69. package/es/common/graph-common/shape/nodes/GroupNode.js +99 -0
  70. package/es/common/graph-common/shape/nodes/LogicalNode.d.ts +5 -0
  71. package/es/common/graph-common/shape/nodes/LogicalNode.js +130 -0
  72. package/es/common/graph-utils/graph.d.ts +83 -0
  73. package/es/common/graph-utils/graph.js +98 -0
  74. package/es/component/cut.d.ts +10 -0
  75. package/es/component/cut.js +34 -0
  76. package/es/component/cut.less +6 -0
  77. package/es/component/item-name.d.ts +6 -0
  78. package/es/component/item-name.js +30 -0
  79. package/es/component/keyword.d.ts +9 -0
  80. package/es/component/keyword.js +26 -0
  81. package/es/component/keyword.less +11 -0
  82. package/es/component/rx-component/rx-input.d.ts +8 -0
  83. package/es/component/rx-component/rx-input.js +47 -0
  84. package/es/hooks/useObservableState.d.ts +3 -0
  85. package/es/hooks/useObservableState.js +44 -0
  86. package/es/index.d.ts +8 -0
  87. package/es/index.js +9 -0
  88. package/es/pages/component-tree-panel/category-tree/index.d.ts +16 -0
  89. package/es/pages/component-tree-panel/category-tree/index.js +100 -0
  90. package/es/pages/component-tree-panel/category-tree/index.less +35 -0
  91. package/es/pages/component-tree-panel/category-tree/node-title.d.ts +12 -0
  92. package/es/pages/component-tree-panel/category-tree/node-title.js +57 -0
  93. package/es/pages/component-tree-panel/category-tree/node-title.less +113 -0
  94. package/es/pages/component-tree-panel/index.d.ts +17 -0
  95. package/es/pages/component-tree-panel/index.js +19 -0
  96. package/es/pages/component-tree-panel/index.less +51 -0
  97. package/es/pages/config-panel/components/condition-configuration/configure-modal/data-origin.d.ts +49 -0
  98. package/es/pages/config-panel/components/condition-configuration/configure-modal/data-origin.js +212 -0
  99. package/es/pages/config-panel/components/condition-configuration/configure-modal/index.d.ts +11 -0
  100. package/es/pages/config-panel/components/condition-configuration/configure-modal/index.js +178 -0
  101. package/es/pages/config-panel/components/condition-configuration/configure-modal/style.less +13 -0
  102. package/es/pages/config-panel/components/condition-configuration/cross-line.d.ts +8 -0
  103. package/es/pages/config-panel/components/condition-configuration/cross-line.js +47 -0
  104. package/es/pages/config-panel/components/condition-configuration/index.d.ts +9 -0
  105. package/es/pages/config-panel/components/condition-configuration/index.js +180 -0
  106. package/es/pages/config-panel/components/condition-configuration/style.less +70 -0
  107. package/es/pages/config-panel/components/time-trigger/components/cycle-time.d.ts +8 -0
  108. package/es/pages/config-panel/components/time-trigger/components/cycle-time.js +87 -0
  109. package/es/pages/config-panel/components/time-trigger/components/time-horizon.d.ts +9 -0
  110. package/es/pages/config-panel/components/time-trigger/components/time-horizon.js +73 -0
  111. package/es/pages/config-panel/components/time-trigger/delay-time.d.ts +8 -0
  112. package/es/pages/config-panel/components/time-trigger/delay-time.js +18 -0
  113. package/es/pages/config-panel/components/time-trigger/index.d.ts +8 -0
  114. package/es/pages/config-panel/components/time-trigger/index.js +84 -0
  115. package/es/pages/config-panel/components/time-trigger/interval-time.d.ts +8 -0
  116. package/es/pages/config-panel/components/time-trigger/interval-time.js +50 -0
  117. package/es/pages/config-panel/components/time-trigger/persistent-time.d.ts +8 -0
  118. package/es/pages/config-panel/components/time-trigger/persistent-time.js +18 -0
  119. package/es/pages/config-panel/components/time-trigger/timing-time.d.ts +8 -0
  120. package/es/pages/config-panel/components/time-trigger/timing-time.js +52 -0
  121. package/es/pages/config-panel/config-common.d.ts +37 -0
  122. package/es/pages/config-panel/config-common.js +135 -0
  123. package/es/pages/config-panel/index.d.ts +12 -0
  124. package/es/pages/config-panel/index.js +50 -0
  125. package/es/pages/config-panel/node-form.d.ts +21 -0
  126. package/es/pages/config-panel/node-form.js +97 -0
  127. package/es/pages/config-panel/style.less +62 -0
  128. package/es/pages/dag-canvas/canvas-content.d.ts +9 -0
  129. package/es/pages/dag-canvas/canvas-content.js +92 -0
  130. package/es/pages/dag-canvas/canvas-content.less +5 -0
  131. package/es/pages/dag-canvas/index.d.ts +13 -0
  132. package/es/pages/dag-canvas/index.js +28 -0
  133. package/es/pages/dag-canvas/index.less +11 -0
  134. package/es/pages/dag-canvas/preview.d.ts +9 -0
  135. package/es/pages/dag-canvas/preview.js +34 -0
  136. package/es/pages/index.d.ts +37 -0
  137. package/es/pages/index.js +73 -0
  138. package/es/pages/index.less +50 -0
  139. package/es/pages/rx-models/experiment-graph.d.ts +82 -0
  140. package/es/pages/rx-models/experiment-graph.js +1186 -0
  141. package/es/pages/rx-models/graph-core.d.ts +96 -0
  142. package/es/pages/rx-models/graph-core.js +755 -0
  143. package/es/pages/rx-models/graph-core.less +14 -0
  144. package/es/pages/rx-models/graph-util.d.ts +186 -0
  145. package/es/pages/rx-models/graph-util.js +358 -0
  146. package/es/pages/rx-models/typing.d.ts +126 -0
  147. package/es/pages/strategy-header/index.d.ts +56 -0
  148. package/es/pages/strategy-header/index.js +141 -0
  149. package/es/pages/strategy-header/style.less +22 -0
  150. package/es/pages/strategy-header/theme-switch/index.d.ts +4 -0
  151. package/es/pages/strategy-header/theme-switch/index.js +19 -0
  152. package/es/pages/strategy-header/theme-switch/style.less +11 -0
  153. package/es/style/basic.less +12 -0
  154. package/es/style/default.less +2 -0
  155. package/es/style/position.less +25 -0
  156. package/es/style/theme-light.less +7 -0
  157. package/es/style/variable.less +3 -0
  158. package/es/typings.d.ts +6 -0
  159. package/es/utils/utils.d.ts +1 -0
  160. package/es/utils/utils.js +1 -0
  161. package/package.json +70 -0
  162. package/tsconfig.json +18 -0
@@ -0,0 +1,755 @@
1
+ var _excluded = ["wrapper", "container", "nodes", "edges"];
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+
5
+ 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."); }
6
+
7
+ 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); }
8
+
9
+ 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; }
10
+
11
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
+
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+
15
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
+
17
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+
19
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
+
21
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
22
+
23
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
24
+
25
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
+
27
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
28
+
29
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
30
+
31
+ import { Graph } from '@antv/x6';
32
+ import { BehaviorSubject, fromEventPattern, merge } from 'rxjs';
33
+ import { debounceTime, map, tap, scan } from 'rxjs/operators';
34
+ import "./graph-core.less";
35
+
36
+ function setCellsSelectedStatus(cells, selected) {
37
+ cells.forEach(function (cell) {
38
+ var data = cell.getData() || {};
39
+ cell.setData(_objectSpread(_objectSpread({}, data), {}, {
40
+ selected: selected
41
+ }));
42
+ });
43
+ }
44
+
45
+ export var GraphCore = /*#__PURE__*/function () {
46
+ // 传入的 nodes 原始信息
47
+ // 传入的 edges 原始信息
48
+ // 当前画布右键点击信息
49
+ // 选中的节点
50
+ // 待复制的节点 id
51
+ // 窗口大小 resize 的订阅
52
+ // 右键菜单的订阅
53
+ // 节点右键菜单的订阅
54
+ // 选中节点的订阅
55
+ // 产生连线的订阅
56
+ // 连线已删除的订阅
57
+ // 节点移动的订阅
58
+ // 删除节点或连线的订阅
59
+ // 复制节点的订阅
60
+ function GraphCore(options) {
61
+ var _this = this;
62
+
63
+ _classCallCheck(this, GraphCore);
64
+
65
+ this.wrapper = void 0;
66
+ this.container = void 0;
67
+ this.nodeMetas = void 0;
68
+ this.edgeMetas = void 0;
69
+ this.options = void 0;
70
+ this.graph = void 0;
71
+ this.contextMenuInfo$ = new BehaviorSubject(null);
72
+ this.selectedNodes$ = new BehaviorSubject([]);
73
+ this.copyableNodeId$ = new BehaviorSubject('');
74
+ this.windowResizeSub = void 0;
75
+ this.contextMenuSub = void 0;
76
+ this.nodeContextMenuSub = void 0;
77
+ this.selectNodeSub = void 0;
78
+ this.connectNodeSub = void 0;
79
+ this.connectionRemovedSub = void 0;
80
+ this.moveNodesSub = void 0;
81
+ this.deleteNodeOrEdgeSub = void 0;
82
+ this.copyNodeSub = void 0;
83
+
84
+ this.resizeGraph = function () {
85
+ var graph = _this.graph,
86
+ wrapper = _this.wrapper;
87
+
88
+ if (graph && wrapper) {
89
+ requestAnimationFrame(function () {
90
+ var width = wrapper.clientWidth;
91
+ var height = wrapper.clientHeight;
92
+ graph.resize(width, height);
93
+ });
94
+ }
95
+ };
96
+
97
+ this.addNode = function (nodeMeta) {
98
+ var _this$nodeMetas;
99
+
100
+ (_this$nodeMetas = _this.nodeMetas) === null || _this$nodeMetas === void 0 ? void 0 : _this$nodeMetas.push(nodeMeta);
101
+ return _this.renderNode(nodeMeta);
102
+ };
103
+
104
+ this.addEdge = function (edgeMeta) {
105
+ var _this$edgeMetas;
106
+
107
+ (_this$edgeMetas = _this.edgeMetas) === null || _this$edgeMetas === void 0 ? void 0 : _this$edgeMetas.push(edgeMeta);
108
+ return _this.renderEdge(edgeMeta);
109
+ };
110
+
111
+ this.getNodeById = function (nodeId) {
112
+ var _this$graph;
113
+
114
+ var node = (_this$graph = _this.graph) === null || _this$graph === void 0 ? void 0 : _this$graph.getCellById(nodeId);
115
+
116
+ if (node === null || node === void 0 ? void 0 : node.isNode()) {
117
+ return node;
118
+ }
119
+
120
+ return undefined;
121
+ };
122
+
123
+ this.getNodes = function () {
124
+ var _this$graph2;
125
+
126
+ return ((_this$graph2 = _this.graph) === null || _this$graph2 === void 0 ? void 0 : _this$graph2.getNodes()) || [];
127
+ };
128
+
129
+ this.getEdgeById = function (nodeId) {
130
+ var _this$graph3;
131
+
132
+ var edge = (_this$graph3 = _this.graph) === null || _this$graph3 === void 0 ? void 0 : _this$graph3.getCellById(nodeId);
133
+
134
+ if (edge === null || edge === void 0 ? void 0 : edge.isEdge()) {
135
+ return edge;
136
+ }
137
+
138
+ return undefined;
139
+ };
140
+
141
+ this.getEdges = function () {
142
+ var _this$graph4;
143
+
144
+ return ((_this$graph4 = _this.graph) === null || _this$graph4 === void 0 ? void 0 : _this$graph4.getEdges()) || [];
145
+ };
146
+
147
+ this.getCellById = function (cellId) {
148
+ var _this$graph5;
149
+
150
+ var cell = (_this$graph5 = _this.graph) === null || _this$graph5 === void 0 ? void 0 : _this$graph5.getCellById(cellId);
151
+
152
+ if ((cell === null || cell === void 0 ? void 0 : cell.isNode()) || (cell === null || cell === void 0 ? void 0 : cell.isEdge())) {
153
+ return cell;
154
+ }
155
+
156
+ return undefined;
157
+ };
158
+
159
+ this.getCells = function () {
160
+ var _this$graph6;
161
+
162
+ return ((_this$graph6 = _this.graph) === null || _this$graph6 === void 0 ? void 0 : _this$graph6.getCells()) || [];
163
+ };
164
+
165
+ this.updateNodeById = function (nodeId, handler) {
166
+ handler(_this.getNodeById(nodeId));
167
+ };
168
+
169
+ this.updateNodes = function (handler) {
170
+ handler(_this.getNodes());
171
+ };
172
+
173
+ this.updateEdgeById = function (edgeId, handler) {
174
+ var _this$graph7;
175
+
176
+ var edge = (_this$graph7 = _this.graph) === null || _this$graph7 === void 0 ? void 0 : _this$graph7.getCellById(edgeId);
177
+
178
+ if (edge === null || edge === void 0 ? void 0 : edge.isEdge()) {
179
+ handler(edge);
180
+ } else {
181
+ handler(undefined);
182
+ }
183
+ };
184
+
185
+ this.updateEdges = function (handler) {
186
+ var _this$graph8;
187
+
188
+ var edges = ((_this$graph8 = _this.graph) === null || _this$graph8 === void 0 ? void 0 : _this$graph8.getEdges()) || [];
189
+ handler(edges);
190
+ };
191
+
192
+ this.deleteNodes = function (nodes) {
193
+ var _this$graph9;
194
+
195
+ var target = [].concat(nodes); // @ts-ignore
196
+
197
+ _this.nodeMetas = _this.nodeMetas.filter(function (nodeMeta) {
198
+ return !target.includes(nodeMeta.id);
199
+ });
200
+ (_this$graph9 = _this.graph) === null || _this$graph9 === void 0 ? void 0 : _this$graph9.removeCells(target);
201
+ };
202
+
203
+ this.deleteEdges = function (edges) {
204
+ var _this$graph10;
205
+
206
+ var target = [].concat(edges);
207
+ var targetIds = target.map(function (i) {
208
+ return typeof i === 'string' ? i : i.id;
209
+ }); // @ts-ignore
210
+
211
+ _this.edgeMetas = _this.edgeMetas.filter(function (edgeMeta) {
212
+ return !targetIds.includes(edgeMeta.id);
213
+ });
214
+ (_this$graph10 = _this.graph) === null || _this$graph10 === void 0 ? void 0 : _this$graph10.removeCells(target);
215
+ };
216
+
217
+ this.clearContextMenuInfo = function () {
218
+ _this.contextMenuInfo$.next(null);
219
+ };
220
+
221
+ this.zoom = function (factor) {
222
+ if (typeof factor === 'number') {
223
+ var _this$graph11;
224
+
225
+ (_this$graph11 = _this.graph) === null || _this$graph11 === void 0 ? void 0 : _this$graph11.zoom(factor);
226
+ } else if (factor === 'fit') {
227
+ var _this$graph12;
228
+
229
+ (_this$graph12 = _this.graph) === null || _this$graph12 === void 0 ? void 0 : _this$graph12.zoomToFit({
230
+ padding: 12
231
+ });
232
+ } else if (factor === 'real') {
233
+ var _this$graph13, _this$graph14;
234
+
235
+ (_this$graph13 = _this.graph) === null || _this$graph13 === void 0 ? void 0 : _this$graph13.scale(1);
236
+ (_this$graph14 = _this.graph) === null || _this$graph14 === void 0 ? void 0 : _this$graph14.centerContent();
237
+ }
238
+ };
239
+
240
+ this.toggleSelectionEnabled = function (enabled) {
241
+ var graph = _this.graph;
242
+
243
+ if (graph) {
244
+ var needEnableRubberBand = typeof enabled === 'undefined' ? !graph.isRubberbandEnabled() : enabled;
245
+
246
+ if (needEnableRubberBand) {
247
+ graph.disablePanning();
248
+ graph.enableRubberband(); // graph.scroller.widget?.setCursor('crosshair', { silent: true })
249
+ } else {
250
+ graph.enablePanning();
251
+ graph.disableRubberband(); // graph.scroller.widget?.setCursor('grab', { silent: true })
252
+ }
253
+ }
254
+ };
255
+
256
+ this.selectNodes = function (ids) {
257
+ var graph = _this.graph;
258
+
259
+ if (graph) {
260
+ var target = [].concat(ids).map(function (i) {
261
+ return i.toString();
262
+ });
263
+ graph.cleanSelection();
264
+ graph.select(target);
265
+
266
+ if (!Array.isArray(ids)) {
267
+ var cell = graph.getCellById(ids);
268
+ graph.scrollToCell(cell);
269
+ }
270
+ }
271
+ };
272
+
273
+ this.unSelectNode = function () {
274
+ var graph = _this.graph;
275
+
276
+ if (graph) {
277
+ graph.cleanSelection();
278
+ }
279
+ };
280
+
281
+ this.redo = function () {
282
+ var graph = _this.graph;
283
+
284
+ if (graph) {
285
+ graph.redo();
286
+ }
287
+ };
288
+
289
+ this.undo = function () {
290
+ var graph = _this.graph;
291
+
292
+ if (graph) {
293
+ graph.undo();
294
+ }
295
+ };
296
+
297
+ this.setCopyableNodeId = function (id) {
298
+ _this.copyableNodeId$.next(id);
299
+ };
300
+
301
+ this.throwRenderError = function () {
302
+ if (!_this.wrapper) {
303
+ throw new Error('Wrapper element is needed.');
304
+ }
305
+
306
+ if (!_this.container) {
307
+ throw new Error('Container element is needed.');
308
+ }
309
+
310
+ if (!_this.nodeMetas) {
311
+ throw new Error('NodeMetas could not be empty');
312
+ }
313
+
314
+ if (!_this.edgeMetas) {
315
+ throw new Error('EdgeMetas could not be empty');
316
+ }
317
+ };
318
+
319
+ var _wrapper = options.wrapper,
320
+ container = options.container,
321
+ _nodes = options.nodes,
322
+ _edges = options.edges,
323
+ others = _objectWithoutProperties(options, _excluded);
324
+
325
+ this.setMeta(options);
326
+ this.options = others;
327
+ }
328
+
329
+ _createClass(GraphCore, [{
330
+ key: "setMeta",
331
+ value: function setMeta(params) {
332
+ var wrapper = params.wrapper,
333
+ container = params.container,
334
+ nodes = params.nodes,
335
+ edges = params.edges;
336
+
337
+ if (wrapper) {
338
+ this.setWrapper(wrapper);
339
+ }
340
+
341
+ if (container) {
342
+ this.setContainer(container);
343
+ }
344
+
345
+ if (nodes) {
346
+ this.setNodes(nodes);
347
+ }
348
+
349
+ if (edges) {
350
+ this.setEdges(edges);
351
+ }
352
+ }
353
+ }, {
354
+ key: "isMetaValid",
355
+ get: function get() {
356
+ var wrapper = this.wrapper,
357
+ container = this.container,
358
+ nodeMetas = this.nodeMetas,
359
+ edgeMetas = this.edgeMetas;
360
+ return !!wrapper && !!container && !!nodeMetas && !!edgeMetas;
361
+ }
362
+ }, {
363
+ key: "nodes",
364
+ get: function get() {
365
+ var _this$graph15;
366
+
367
+ return ((_this$graph15 = this.graph) === null || _this$graph15 === void 0 ? void 0 : _this$graph15.getNodes()) || [];
368
+ }
369
+ }, {
370
+ key: "setWrapper",
371
+ value: function setWrapper(wrapper) {
372
+ this.wrapper = wrapper;
373
+ }
374
+ }, {
375
+ key: "setContainer",
376
+ value: function setContainer(container) {
377
+ this.container = container;
378
+ this.options.container = container;
379
+ }
380
+ }, {
381
+ key: "setNodes",
382
+ value: function setNodes(nodes) {
383
+ this.nodeMetas = nodes;
384
+ }
385
+ }, {
386
+ key: "setEdges",
387
+ value: function setEdges(edges) {
388
+ this.edgeMetas = edges;
389
+ } // 渲染
390
+
391
+ }, {
392
+ key: "render",
393
+ value: function render(params) {
394
+ var _this2 = this;
395
+
396
+ this.setMeta(params);
397
+
398
+ if (this.isMetaValid) {
399
+ var wrapper = this.wrapper,
400
+ options = this.options,
401
+ nodeMetas = this.nodeMetas,
402
+ edgeMetas = this.edgeMetas;
403
+ var width = wrapper.clientWidth - 12;
404
+ var height = wrapper.clientHeight;
405
+ var graph = new Graph(_objectSpread(_objectSpread(_objectSpread({}, options), {}, {
406
+ width: width
407
+ }, params.options), {}, {
408
+ height: height
409
+ }));
410
+ this.graph = graph;
411
+ nodeMetas.forEach(function (nodeMeta) {
412
+ return _this2.renderNode(nodeMeta);
413
+ });
414
+ edgeMetas.forEach(function (edgeMeta) {
415
+ return _this2.renderEdge(edgeMeta);
416
+ });
417
+ this.afterLayout();
418
+
419
+ if (graph.isFrozen()) {
420
+ graph.unfreeze();
421
+ }
422
+
423
+ requestAnimationFrame(function () {
424
+ graph.centerContent();
425
+ }); // 处理窗口缩放
426
+
427
+ this.windowResizeSub = fromEventPattern(function (handler) {
428
+ window.addEventListener('resize', handler);
429
+ }, function (handler) {
430
+ window.removeEventListener('resize', handler);
431
+ }).subscribe(this.resizeGraph); // 处理右键菜单
432
+
433
+ var nodeContextMenuObs = fromEventPattern(function (handler) {
434
+ graph.on('node:contextmenu', function (data) {
435
+ handler({
436
+ type: 'node',
437
+ data: data
438
+ });
439
+ });
440
+ }, function (handler) {
441
+ graph.off('node:contextmenu', handler);
442
+ });
443
+ var edgeContextMenuObs = fromEventPattern(function (handler) {
444
+ graph.on('edge:contextmenu', function (data) {
445
+ handler({
446
+ type: 'edge',
447
+ data: data
448
+ });
449
+ });
450
+ }, function (handler) {
451
+ graph.off('edge:contextmenu', handler);
452
+ });
453
+ var graphContextMenuObs = fromEventPattern(function (handler) {
454
+ graph.on('blank:contextmenu', function (data) {
455
+ handler({
456
+ type: 'graph',
457
+ data: data
458
+ });
459
+ });
460
+ }, function (handler) {
461
+ graph.off('edge:contextmenu', handler);
462
+ });
463
+ this.nodeContextMenuSub = nodeContextMenuObs.subscribe(function (data) {
464
+ _this2.onNodeContextMenu(data);
465
+ });
466
+ this.contextMenuSub = merge(nodeContextMenuObs, edgeContextMenuObs, graphContextMenuObs).subscribe(function (data) {
467
+ if (_this2.validateContextMenu(data)) {
468
+ _this2.contextMenuInfo$.next(data);
469
+
470
+ _this2.onContextMenu(data);
471
+ }
472
+ }); // 处理节点选中事件
473
+
474
+ this.selectNodeSub = fromEventPattern(function (handler) {
475
+ graph.on('selection:changed', handler);
476
+ }, function (handler) {
477
+ graph.off('selection:changed', handler);
478
+ }).subscribe(function (args) {
479
+ var removed = args.removed,
480
+ selected = args.selected;
481
+ setCellsSelectedStatus(removed, false);
482
+ setCellsSelectedStatus(selected, true);
483
+
484
+ _this2.onSelectNodes(selected);
485
+ }); // 处理产生连线事件
486
+
487
+ this.connectNodeSub = fromEventPattern(function (handler) {
488
+ graph.on('edge:connected', handler);
489
+ }, function (handler) {
490
+ graph.off('edge:connected', handler);
491
+ }).subscribe(function (args) {
492
+ _this2.onConnectNode(args);
493
+ }); // 处理连线删除事件
494
+
495
+ this.connectionRemovedSub = fromEventPattern(function (handler) {
496
+ graph.on('edge:removed', handler);
497
+ }, function (handler) {
498
+ graph.off('edge:removed', handler);
499
+ }).subscribe(function (args) {
500
+ _this2.onConnectionRemoved(args);
501
+ }); // 处理节点移动事件
502
+
503
+ var moveStarted = false; // 因为需要对移动事件做分片,区分两次移动事件,所以引入一个记录移动开始的变量
504
+
505
+ this.moveNodesSub = fromEventPattern(function (handler) {
506
+ graph.on('node:change:position', handler);
507
+ }, function (handler) {
508
+ graph.off('node:change:position', handler);
509
+ }).pipe(tap(function (args) {
510
+ _this2.onMoveNodeStart(args);
511
+ }), scan(function (accum, args) {
512
+ var currentAccum = !moveStarted ? [] : accum;
513
+ var node = args.node;
514
+ var id = node.id;
515
+ var matchItemIndex = currentAccum.findIndex(function (item) {
516
+ return item.id === id;
517
+ });
518
+
519
+ if (matchItemIndex > -1) {
520
+ currentAccum.splice(matchItemIndex, 1, {
521
+ id: id,
522
+ data: args
523
+ });
524
+ } else {
525
+ currentAccum.push({
526
+ id: id,
527
+ data: args
528
+ });
529
+ }
530
+
531
+ return currentAccum;
532
+ }, []), tap(function () {
533
+ if (!moveStarted) {
534
+ moveStarted = true;
535
+ }
536
+ }), debounceTime(300), tap(function () {
537
+ if (moveStarted) {
538
+ moveStarted = false;
539
+ }
540
+ }), map(function (items) {
541
+ return items.map(function (item) {
542
+ return item.data;
543
+ });
544
+ })).subscribe(function (movedNodes) {
545
+ _this2.onMoveNodes(movedNodes);
546
+ }); // 处理删除节点或连线事件
547
+
548
+ this.deleteNodeOrEdgeSub = fromEventPattern(function (handler) {
549
+ graph.bindKey(['delete', 'backspace'], handler);
550
+ }, function () {
551
+ graph.unbindKey(['delete', 'backspace']);
552
+ }).subscribe(function () {
553
+ var selectedCells = graph.getSelectedCells();
554
+ var selectedNodes = selectedCells.filter(function (cell) {
555
+ return cell.isNode();
556
+ });
557
+ var selectedEdges = selectedCells.filter(function (cell) {
558
+ return cell.isEdge();
559
+ });
560
+
561
+ _this2.onDeleteNodeOrEdge({
562
+ nodes: selectedNodes,
563
+ edges: selectedEdges
564
+ });
565
+ }); // 处理节点复制事件
566
+
567
+ this.copyNodeSub = fromEventPattern(function (handler) {
568
+ graph.bindKey(['command+c', 'ctrl+c', 'command+v', 'ctrl+v'], handler);
569
+ }, function () {
570
+ graph.unbindKey(['command+c', 'ctrl+c', 'command+v', 'ctrl+v']);
571
+ }).subscribe(function (args) {
572
+ var _args = _slicedToArray(args, 2),
573
+ action = _args[1];
574
+
575
+ var selectedCells = graph.getSelectedCells().filter(function (cell) {
576
+ return _this2.validateNodeCopyable(cell);
577
+ });
578
+
579
+ var copyableNodeId = _this2.copyableNodeId$.getValue();
580
+
581
+ var copyableNode;
582
+
583
+ if (copyableNodeId) {
584
+ copyableNode = graph.getCellById(copyableNodeId);
585
+ }
586
+
587
+ switch (action) {
588
+ case 'command+c':
589
+ case 'ctrl+c':
590
+ if (selectedCells === null || selectedCells === void 0 ? void 0 : selectedCells.length) {
591
+ _this2.setCopyableNodeId(selectedCells[0].id); // 当前只支持单节点的复制粘贴
592
+
593
+ }
594
+
595
+ break;
596
+
597
+ case 'command+v':
598
+ case 'ctrl+v':
599
+ // @ts-ignore
600
+ if (copyableNode) {
601
+ _this2.onCopyNode(copyableNode);
602
+ }
603
+
604
+ break;
605
+
606
+ default:
607
+ }
608
+ });
609
+ } else {
610
+ this.throwRenderError();
611
+ }
612
+ }
613
+ }, {
614
+ key: "renderNode",
615
+ value: function renderNode(nodeMeta) {
616
+ console.log('renderNode => ', nodeMeta);
617
+ return this.graph.addNode(nodeMeta);
618
+ }
619
+ }, {
620
+ key: "renderEdge",
621
+ value: function renderEdge(edgeMeta) {
622
+ console.log('renderEdge => ', edgeMeta);
623
+ return this.graph.addEdge(edgeMeta);
624
+ }
625
+ }, {
626
+ key: "afterLayout",
627
+ value: function afterLayout() {
628
+ if (process.env.NODE_ENV === 'development') {
629
+ console.log('[GraphCore] call afterLayout');
630
+ }
631
+ }
632
+ }, {
633
+ key: "validateContextMenu",
634
+ value: function validateContextMenu(data) {
635
+ return !!data;
636
+ }
637
+ }, {
638
+ key: "onContextMenu",
639
+ value: function onContextMenu(data) {
640
+ if (process.env.NODE_ENV === 'development') {
641
+ console.log('[GraphCore] context menu info:', data);
642
+ }
643
+ }
644
+ }, {
645
+ key: "onNodeContextMenu",
646
+ value: function onNodeContextMenu(data) {
647
+ if (process.env.NODE_ENV === 'development') {
648
+ console.log('[GraphCore] context menu info:', data);
649
+ }
650
+ }
651
+ }, {
652
+ key: "onSelectNodes",
653
+ value: function onSelectNodes(nodes) {
654
+ this.selectedNodes$.next(nodes);
655
+
656
+ if (process.env.NODE_ENV === 'development') {
657
+ console.log('[GraphCore] select nodes:', nodes);
658
+ }
659
+ }
660
+ }, {
661
+ key: "onConnectNode",
662
+ value: function onConnectNode(args) {
663
+ if (process.env.NODE_ENV === 'development') {
664
+ console.log('[GraphCore] connect nodes:', args);
665
+ }
666
+ }
667
+ }, {
668
+ key: "onConnectionRemoved",
669
+ value: function onConnectionRemoved(args) {
670
+ if (process.env.NODE_ENV === 'development') {
671
+ console.log('[GraphCore] delete connection:', args);
672
+ }
673
+ }
674
+ }, {
675
+ key: "onMoveNodeStart",
676
+ value: function onMoveNodeStart(args) {
677
+ if (process.env.NODE_ENV === 'development') {
678
+ console.log('[GraphCore] move nodes start:', args);
679
+ }
680
+ }
681
+ }, {
682
+ key: "onMoveNodes",
683
+ value: function onMoveNodes(args) {
684
+ if (process.env.NODE_ENV === 'development') {
685
+ console.log('[GraphCore] move nodes:', args);
686
+ }
687
+ } // 按下删除键的回调,默认参数为当前选中的节点和边
688
+
689
+ }, {
690
+ key: "onDeleteNodeOrEdge",
691
+ value: function onDeleteNodeOrEdge(args) {
692
+ if (process.env.NODE_ENV === 'development') {
693
+ console.log('[GraphCore] delete nodes or edge:', args);
694
+ }
695
+ } // 校验节点是否可复制,为 true 则可被用于复制
696
+
697
+ }, {
698
+ key: "validateNodeCopyable",
699
+ value: function validateNodeCopyable(node) {
700
+ if (process.env.NODE_ENV === 'development') {
701
+ console.log('[GraphCore] validate nodes copyable:', node);
702
+ }
703
+
704
+ return true;
705
+ } // 按下粘贴键的回调,默认参数为待复制的节点
706
+
707
+ }, {
708
+ key: "onCopyNode",
709
+ value: function onCopyNode(copyNode) {
710
+ if (process.env.NODE_ENV === 'development') {
711
+ console.log('[GraphCore] copy nodes:', copyNode);
712
+ }
713
+ }
714
+ /* 以下为主动触发的方法 */
715
+
716
+ }, {
717
+ key: "dispose",
718
+ value: // 注销
719
+ function dispose() {
720
+ var _this$windowResizeSub, _this$contextMenuSub, _this$nodeContextMenu, _this$selectNodeSub, _this$connectNodeSub, _this$connectionRemov, _this$moveNodesSub, _this$deleteNodeOrEdg, _this$copyNodeSub;
721
+
722
+ (_this$windowResizeSub = this.windowResizeSub) === null || _this$windowResizeSub === void 0 ? void 0 : _this$windowResizeSub.unsubscribe();
723
+ (_this$contextMenuSub = this.contextMenuSub) === null || _this$contextMenuSub === void 0 ? void 0 : _this$contextMenuSub.unsubscribe();
724
+ (_this$nodeContextMenu = this.nodeContextMenuSub) === null || _this$nodeContextMenu === void 0 ? void 0 : _this$nodeContextMenu.unsubscribe();
725
+ (_this$selectNodeSub = this.selectNodeSub) === null || _this$selectNodeSub === void 0 ? void 0 : _this$selectNodeSub.unsubscribe();
726
+ (_this$connectNodeSub = this.connectNodeSub) === null || _this$connectNodeSub === void 0 ? void 0 : _this$connectNodeSub.unsubscribe();
727
+ (_this$connectionRemov = this.connectionRemovedSub) === null || _this$connectionRemov === void 0 ? void 0 : _this$connectionRemov.unsubscribe();
728
+ (_this$moveNodesSub = this.moveNodesSub) === null || _this$moveNodesSub === void 0 ? void 0 : _this$moveNodesSub.unsubscribe();
729
+ (_this$deleteNodeOrEdg = this.deleteNodeOrEdgeSub) === null || _this$deleteNodeOrEdg === void 0 ? void 0 : _this$deleteNodeOrEdg.unsubscribe();
730
+ (_this$copyNodeSub = this.copyNodeSub) === null || _this$copyNodeSub === void 0 ? void 0 : _this$copyNodeSub.unsubscribe(); // ! 这一步要注意放在图的事件订阅都取消了之后
731
+
732
+ if (this.wrapper) {
733
+ var _this$graph16;
734
+
735
+ var graphScroller = this.wrapper.querySelector('.x6-graph-scroller');
736
+
737
+ if (graphScroller) {
738
+ graphScroller.innerHTML = '';
739
+ graphScroller.setAttribute('style', '');
740
+ graphScroller.setAttribute('class', '');
741
+
742
+ if (this.container) {
743
+ this.container.innerHTML = '';
744
+ this.container.setAttribute('style', '');
745
+ this.container.setAttribute('class', '');
746
+ }
747
+ }
748
+
749
+ (_this$graph16 = this.graph) === null || _this$graph16 === void 0 ? void 0 : _this$graph16.dispose();
750
+ }
751
+ }
752
+ }]);
753
+
754
+ return GraphCore;
755
+ }();