ronds-metadata 1.1.10 → 1.1.13

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.
@@ -5,11 +5,11 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  * @Date: 2022-05-27 09:56:39
6
6
  * @LastEditTime: 2022-05-27 16:16:25
7
7
  */
8
- import useObservable from '@/framework/rxjs-hooks/useObservable';
9
8
  import React from 'react';
10
9
  import NodeContextMenu from './contextMenu/NodeContextMenu';
11
10
  import "./ContextMenu.css";
12
11
  import { EdgeContextMenu } from './contextMenu/EdgeContextMenu';
12
+ import useObservable from '../../../framework/rxjs-hooks/useObservable';
13
13
 
14
14
  var ContextMenu = function ContextMenu(props) {
15
15
  var _graph$factory$;
@@ -4,13 +4,13 @@ import _Popover from "antd/es/popover";
4
4
  /*
5
5
  * @Author: wangxian
6
6
  * @Date: 2022-05-27 14:21:23
7
- * @LastEditTime: 2022-05-28 10:18:24
7
+ * @LastEditTime: 2022-05-30 09:45:54
8
8
  */
9
9
  import React from 'react';
10
10
  import { CompressOutlined, OneToOneOutlined, ZoomInOutlined, ZoomOutOutlined } from '@ant-design/icons';
11
11
  import classNames from 'classnames';
12
12
  import "./index.css";
13
- import { tr } from '@/framework/locale';
13
+ import { tr } from '../../../../framework/locale';
14
14
  export var GraphHandler = function GraphHandler(props) {
15
15
  var className = props.className,
16
16
  onZoomIn = props.onZoomIn,
@@ -54,6 +54,7 @@ declare class DPGraph extends GraphCore<BaseNode, BaseEdge> {
54
54
  }): void;
55
55
  onContextMenu(data: ContextMenuInfo): any;
56
56
  clearContextMenuInfo: () => void;
57
+ onMoveNodes(movedNodes: any[]): Promise<void>;
57
58
  dispose(): void;
58
59
  }
59
60
  export declare let gDPGraph: DPGraph;
@@ -16,6 +16,7 @@ import React from 'react';
16
16
  import ReactDOM from 'react-dom';
17
17
  import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
18
18
  import { filter, take } from 'rxjs/operators';
19
+ import { round } from 'lodash-es';
19
20
  import { GraphCore } from '../../framework/graph';
20
21
  import NodeElement from './comps/NodeElement';
21
22
  import { DPEdge } from './comps/shape/edge';
@@ -559,6 +560,76 @@ var DPGraph = /*#__PURE__*/function (_GraphCore) {
559
560
  this.factory$.contextMenuInfo.next(data);
560
561
  } // 清空右键菜单信息
561
562
 
563
+ }, {
564
+ key: "onMoveNodes",
565
+ value: function () {
566
+ var _onMoveNodes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(movedNodes) {
567
+ var _this2 = this;
568
+
569
+ var targetNodes, newPos, oldGraph, newGraph;
570
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
571
+ while (1) {
572
+ switch (_context6.prev = _context6.next) {
573
+ case 0:
574
+ targetNodes = movedNodes.filter(function (arg) {
575
+ var node = arg.node;
576
+ return !node.isGroup();
577
+ });
578
+
579
+ if (targetNodes === null || targetNodes === void 0 ? void 0 : targetNodes.length) {
580
+ newPos = targetNodes.map(function (moveNode) {
581
+ var current = moveNode.current,
582
+ node = moveNode.node;
583
+ var x = current.x,
584
+ y = current.y;
585
+ var id = node.id;
586
+
587
+ _this2.updateNodeById(id, function (node) {
588
+ node.setData({
589
+ x: x,
590
+ y: y
591
+ });
592
+ });
593
+
594
+ return {
595
+ nodeInstanceId: id,
596
+ posX: round(x),
597
+ posY: round(y)
598
+ };
599
+ });
600
+ oldGraph = this.factory$.dpGraph.getValue();
601
+ newGraph = produce(oldGraph, function (nextGraph) {
602
+ newPos.forEach(function (position) {
603
+ var nodeInstanceId = position.nodeInstanceId,
604
+ posX = position.posX,
605
+ posY = position.posY;
606
+ var matchNode = nextGraph.nodes.find(function (item) {
607
+ return item.id.toString() === nodeInstanceId.toString();
608
+ });
609
+
610
+ if (matchNode) {
611
+ matchNode.x = posX;
612
+ matchNode.y = posY;
613
+ }
614
+ });
615
+ });
616
+ this.factory$.dpGraph.next(newGraph);
617
+ }
618
+
619
+ case 2:
620
+ case "end":
621
+ return _context6.stop();
622
+ }
623
+ }
624
+ }, _callee6, this);
625
+ }));
626
+
627
+ function onMoveNodes(_x4) {
628
+ return _onMoveNodes.apply(this, arguments);
629
+ }
630
+
631
+ return onMoveNodes;
632
+ }()
562
633
  }, {
563
634
  key: "dispose",
564
635
  value: function dispose() {
@@ -16,11 +16,29 @@ export declare namespace NDPGraph {
16
16
  * 图标
17
17
  */
18
18
  icon?: string;
19
+ /**
20
+ * 名称
21
+ */
19
22
  name: string;
23
+ /**
24
+ * 输入引脚
25
+ */
20
26
  inPorts: InPort[];
27
+ /**
28
+ * 输出引脚
29
+ */
21
30
  outPorts: OutPort[];
31
+ /**
32
+ * position x
33
+ */
22
34
  x: number;
35
+ /**
36
+ * position y
37
+ */
23
38
  y: number;
39
+ /**
40
+ * 附带参数信息
41
+ */
24
42
  param?: Param;
25
43
  }
26
44
  interface Edge {
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * @Author: wangxian
3
3
  * @Date: 2022-05-24 16:10:46
4
- * @LastEditTime: 2022-05-28 10:57:33
4
+ * @LastEditTime: 2022-05-30 09:44:45
5
5
  */
6
6
  export {};
@@ -29,7 +29,7 @@ interface IMetadataFormProps {
29
29
  /**
30
30
  * 不可编辑
31
31
  */
32
- disabled?: boolean;
32
+ disabled?: boolean | string[];
33
33
  /**
34
34
  * 引用类型是否显示成表单
35
35
  */
@@ -16,7 +16,7 @@ export interface IMetadataRefContextProps {
16
16
  }
17
17
  export declare const MetadataRefContext: React.Context<IMetadataRefContextProps>;
18
18
  export interface IFormOptions {
19
- disabled: boolean;
19
+ disabled: boolean | string[];
20
20
  isRefForm: boolean;
21
21
  isShowTypeInfo: boolean;
22
22
  initEnumValue?: boolean;
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * @Author:wangxian
3
3
  * @Date: 2021-09-18 14:15:04
4
- * @LastEditTime: 2022-05-23 11:56:54
4
+ * @LastEditTime: 2022-06-08 15:45:36
5
5
  */
6
6
  import React from 'react';
7
7
  export var MetadataFormContext = /*#__PURE__*/React.createContext(null);
@@ -5,7 +5,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
5
5
  /*
6
6
  * @Author: wangxian
7
7
  * @Date: 2021-09-18 14:15:04
8
- * @LastEditTime: 2022-05-28 09:35:48
8
+ * @LastEditTime: 2022-06-08 15:54:53
9
9
  */
10
10
  import React from 'react';
11
11
  import Input from './DataCell/Input';
@@ -26,10 +26,23 @@ var DataCellMap = {
26
26
  export function getDataCell(item, options) {
27
27
  if (item.type && DataCellMap[item.type]) {
28
28
  var Comm = DataCellMap[item.type];
29
+
30
+ var isDisabled = function isDisabled(b) {
31
+ if (typeof b === 'boolean') {
32
+ return b;
33
+ } else if (b.findIndex(function (it) {
34
+ return it === item.id;
35
+ }) > -1) {
36
+ return true;
37
+ }
38
+
39
+ return false;
40
+ };
41
+
29
42
  return /*#__PURE__*/React.createElement(Comm, _extends({
30
43
  key: item.id
31
44
  }, item, {
32
- disabled: options.disabled,
45
+ disabled: isDisabled(options.disabled),
33
46
  isRefForm: options.isRefForm,
34
47
  isShowTypeInfo: options.isShowTypeInfo,
35
48
  field: options.field,
@@ -49,11 +49,18 @@ export declare class GraphCore<N extends Node<Node.Properties> = Node<Node.Prope
49
49
  validateContextMenu(data: ContextMenuInfo): boolean;
50
50
  onContextMenu(data: ContextMenuInfo): any;
51
51
  zoom: (factor: number | 'fit' | 'real') => void;
52
+ onMoveNodeStart(args: any): void;
53
+ onMoveNodes(args: any[]): void;
52
54
  addNode: (nodeMeta: any) => N;
55
+ getNodes: () => N[];
53
56
  addEdge: (edgeMeta: any) => E;
54
57
  deleteNodes: (nodes: (Node | string)[] | Node | string) => void;
55
58
  deleteEdges: (edges: (Edge | string)[] | Edge | string) => void;
56
59
  getNodeById: (nodeId: string) => N | undefined;
60
+ updateNodeById: (nodeId: string, handler: (node?: N) => void) => void;
61
+ updateNodes: (handler: (nodes: N[]) => void) => void;
62
+ updateEdgeById: (edgeId: string, handler: (node?: E) => void) => void;
63
+ updateEdges: (handler: (edges: E[]) => void) => void;
57
64
  throwRenderError: () => void;
58
65
  dispose(): void;
59
66
  }
@@ -7,10 +7,10 @@ var _excluded = ["wrapper", "container", "nodes", "edges"];
7
7
  /*
8
8
  * @Author: wangxian
9
9
  * @Date: 2022-05-24 13:55:44
10
- * @LastEditTime: 2022-05-27 16:19:44
10
+ * @LastEditTime: 2022-05-31 10:43:04
11
11
  */
12
12
  import { Graph } from '@antv/x6';
13
- import { fromEventPattern, merge } from 'rxjs';
13
+ import { debounceTime, fromEventPattern, map, merge, scan, tap } from 'rxjs';
14
14
  import "./index.css";
15
15
  export var GraphCore = /*#__PURE__*/function () {
16
16
  // 传入的 nodes 原始信息
@@ -67,6 +67,12 @@ export var GraphCore = /*#__PURE__*/function () {
67
67
  return _this.renderNode(nodeMeta);
68
68
  };
69
69
 
70
+ this.getNodes = function () {
71
+ var _this$graph5;
72
+
73
+ return ((_this$graph5 = _this.graph) === null || _this$graph5 === void 0 ? void 0 : _this$graph5.getNodes()) || [];
74
+ };
75
+
70
76
  this.addEdge = function (edgeMeta) {
71
77
  var _this$edgeMetas;
72
78
 
@@ -75,18 +81,18 @@ export var GraphCore = /*#__PURE__*/function () {
75
81
  };
76
82
 
77
83
  this.deleteNodes = function (nodes) {
78
- var _this$graph5;
84
+ var _this$graph6;
79
85
 
80
86
  var target = [].concat(nodes); // @ts-ignore
81
87
 
82
88
  _this.nodeMetas = _this.nodeMetas.filter(function (nodeMeta) {
83
89
  return !target.includes(nodeMeta.id);
84
90
  });
85
- (_this$graph5 = _this.graph) === null || _this$graph5 === void 0 ? void 0 : _this$graph5.removeCells(target);
91
+ (_this$graph6 = _this.graph) === null || _this$graph6 === void 0 ? void 0 : _this$graph6.removeCells(target);
86
92
  };
87
93
 
88
94
  this.deleteEdges = function (edges) {
89
- var _this$graph6;
95
+ var _this$graph7;
90
96
 
91
97
  var target = [].concat(edges);
92
98
  var targetIds = target.map(function (i) {
@@ -96,13 +102,13 @@ export var GraphCore = /*#__PURE__*/function () {
96
102
  _this.edgeMetas = _this.edgeMetas.filter(function (edgeMeta) {
97
103
  return !targetIds.includes(edgeMeta.id);
98
104
  });
99
- (_this$graph6 = _this.graph) === null || _this$graph6 === void 0 ? void 0 : _this$graph6.removeCells(target);
105
+ (_this$graph7 = _this.graph) === null || _this$graph7 === void 0 ? void 0 : _this$graph7.removeCells(target);
100
106
  };
101
107
 
102
108
  this.getNodeById = function (nodeId) {
103
- var _this$graph7;
109
+ var _this$graph8;
104
110
 
105
- var node = (_this$graph7 = _this.graph) === null || _this$graph7 === void 0 ? void 0 : _this$graph7.getCellById(nodeId);
111
+ var node = (_this$graph8 = _this.graph) === null || _this$graph8 === void 0 ? void 0 : _this$graph8.getCellById(nodeId);
106
112
 
107
113
  if (node === null || node === void 0 ? void 0 : node.isNode()) {
108
114
  return node;
@@ -111,6 +117,33 @@ export var GraphCore = /*#__PURE__*/function () {
111
117
  return undefined;
112
118
  };
113
119
 
120
+ this.updateNodeById = function (nodeId, handler) {
121
+ handler(_this.getNodeById(nodeId));
122
+ };
123
+
124
+ this.updateNodes = function (handler) {
125
+ handler(_this.getNodes());
126
+ };
127
+
128
+ this.updateEdgeById = function (edgeId, handler) {
129
+ var _this$graph9;
130
+
131
+ var edge = (_this$graph9 = _this.graph) === null || _this$graph9 === void 0 ? void 0 : _this$graph9.getCellById(edgeId);
132
+
133
+ if (edge === null || edge === void 0 ? void 0 : edge.isEdge()) {
134
+ handler(edge);
135
+ } else {
136
+ handler(undefined);
137
+ }
138
+ };
139
+
140
+ this.updateEdges = function (handler) {
141
+ var _this$graph10;
142
+
143
+ var edges = ((_this$graph10 = _this.graph) === null || _this$graph10 === void 0 ? void 0 : _this$graph10.getEdges()) || [];
144
+ handler(edges);
145
+ };
146
+
114
147
  this.throwRenderError = function () {
115
148
  if (!_this.wrapper) {
116
149
  console.warn('Wrapper element is needed.');
@@ -287,6 +320,51 @@ export var GraphCore = /*#__PURE__*/function () {
287
320
  if (_this2.validateContextMenu(data)) {
288
321
  _this2.onContextMenu(data);
289
322
  }
323
+ }); // 处理节点移动事件
324
+
325
+ var moveStarted = false; // 因为需要对移动事件做分片,区分两次移动事件,所以引入一个记录移动开始的变量
326
+
327
+ this.factorySub.moveNodes = fromEventPattern(function (handler) {
328
+ _this2.graph.on('node:change:position', handler);
329
+ }, function (handler) {
330
+ _this2.graph.off('node:change:position', handler);
331
+ }).pipe(tap(function (args) {
332
+ _this2.onMoveNodeStart(args);
333
+ }), scan(function (accum, args) {
334
+ var currentAccum = !moveStarted ? [] : accum;
335
+ var node = args.node;
336
+ var id = node.id;
337
+ var matchItemIndex = currentAccum.findIndex(function (item) {
338
+ return item.id === id;
339
+ });
340
+
341
+ if (matchItemIndex > -1) {
342
+ currentAccum.splice(matchItemIndex, 1, {
343
+ id: id,
344
+ data: args
345
+ });
346
+ } else {
347
+ currentAccum.push({
348
+ id: id,
349
+ data: args
350
+ });
351
+ }
352
+
353
+ return currentAccum;
354
+ }, []), tap(function () {
355
+ if (!moveStarted) {
356
+ moveStarted = true;
357
+ }
358
+ }), debounceTime(300), tap(function () {
359
+ if (moveStarted) {
360
+ moveStarted = false;
361
+ }
362
+ }), map(function (items) {
363
+ return items.map(function (item) {
364
+ return item.data;
365
+ });
366
+ })).subscribe(function (movedNodes) {
367
+ _this2.onMoveNodes(movedNodes);
290
368
  });
291
369
  } // 渲染
292
370
 
@@ -380,6 +458,18 @@ export var GraphCore = /*#__PURE__*/function () {
380
458
  if (process.env.NODE_ENV === 'development') {}
381
459
  } // 缩放画布
382
460
 
461
+ }, {
462
+ key: "onMoveNodeStart",
463
+ value: function onMoveNodeStart(args) {
464
+ if (process.env.NODE_ENV === 'development') {}
465
+ }
466
+ }, {
467
+ key: "onMoveNodes",
468
+ value: function onMoveNodes(args) {
469
+ if (process.env.NODE_ENV === 'development') {}
470
+ }
471
+ /* 以下为主动触发的方法 */
472
+
383
473
  }, {
384
474
  key: "dispose",
385
475
  value: // 注销
@@ -391,7 +481,7 @@ export var GraphCore = /*#__PURE__*/function () {
391
481
  (_this$factorySub$sele = this.factorySub.selectNode) === null || _this$factorySub$sele === void 0 ? void 0 : _this$factorySub$sele.unsubscribe(); // ! 这一步要注意放在图的事件订阅都取消了之后
392
482
 
393
483
  if (this.wrapper) {
394
- var _this$graph8;
484
+ var _this$graph11;
395
485
 
396
486
  var graphScroller = this.wrapper.querySelector('.x6-graph-scroller');
397
487
 
@@ -407,7 +497,7 @@ export var GraphCore = /*#__PURE__*/function () {
407
497
  }
408
498
  }
409
499
 
410
- (_this$graph8 = this.graph) === null || _this$graph8 === void 0 ? void 0 : _this$graph8.dispose();
500
+ (_this$graph11 = this.graph) === null || _this$graph11 === void 0 ? void 0 : _this$graph11.dispose();
411
501
  }
412
502
  }
413
503
  }]);
@@ -1,8 +1,8 @@
1
1
  @font-face {
2
2
  font-family: "fa"; /* Project id 2247093 */
3
- src: url('iconfont.woff2?t=1653706081036') format('woff2'),
4
- url('iconfont.woff?t=1653706081036') format('woff'),
5
- url('iconfont.ttf?t=1653706081036') format('truetype');
3
+ src: url('iconfont.woff2?t=1653875373166') format('woff2'),
4
+ url('iconfont.woff?t=1653875373166') format('woff'),
5
+ url('iconfont.ttf?t=1653875373166') format('truetype');
6
6
  }
7
7
 
8
8
  .fa {
@@ -13,6 +13,22 @@
13
13
  -moz-osx-font-smoothing: grayscale;
14
14
  }
15
15
 
16
+ .fa-ai:before {
17
+ content: "\e887";
18
+ }
19
+
20
+ .fa-signal:before {
21
+ content: "\ec4a";
22
+ }
23
+
24
+ .fa-circle:before {
25
+ content: "\e660";
26
+ }
27
+
28
+ .fa-scan:before {
29
+ content: "\e6df";
30
+ }
31
+
16
32
  .fa-py:before {
17
33
  content: "\e916";
18
34
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.1.10",
4
+ "version": "1.1.13",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",