ronds-metadata 1.1.6 → 1.1.9
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/es/comps/DynamicPorts/comps/ContextMenu.css +8 -0
- package/es/comps/DynamicPorts/comps/ContextMenu.d.ts +7 -0
- package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
- package/es/comps/DynamicPorts/comps/DragNode.d.ts +7 -0
- package/es/comps/DynamicPorts/comps/DragNode.js +52 -0
- package/es/comps/DynamicPorts/comps/GraphHandler/index.css +27 -0
- package/es/comps/DynamicPorts/comps/GraphHandler/index.d.ts +11 -0
- package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
- package/es/comps/DynamicPorts/comps/NodeElement.d.ts +6 -0
- package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
- package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.css +5 -0
- package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.d.ts +8 -0
- package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
- package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.css +21 -0
- package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.d.ts +8 -0
- package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
- package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.css +23 -0
- package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.d.ts +7 -0
- package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
- package/es/comps/DynamicPorts/comps/shape/connector.d.ts +1 -0
- package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
- package/es/comps/DynamicPorts/comps/shape/edge.css +4 -0
- package/es/comps/DynamicPorts/comps/shape/edge.d.ts +10 -0
- package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
- package/es/comps/DynamicPorts/comps/shape/node.d.ts +11 -0
- package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
- package/es/comps/DynamicPorts/constant/index.d.ts +7 -0
- package/es/comps/DynamicPorts/constant/index.js +19 -0
- package/es/comps/DynamicPorts/graph.d.ts +62 -0
- package/es/comps/DynamicPorts/graph.js +584 -0
- package/es/comps/DynamicPorts/index.css +167 -0
- package/es/comps/DynamicPorts/index.d.ts +18 -1
- package/es/comps/DynamicPorts/index.js +131 -70
- package/es/comps/DynamicPorts/interface.d.ts +44 -0
- package/es/comps/DynamicPorts/interface.js +6 -0
- package/es/comps/DynamicPorts/utils.d.ts +104 -0
- package/es/comps/DynamicPorts/utils.js +127 -0
- package/es/comps/Icons/index.d.ts +18 -0
- package/es/comps/Icons/index.js +23 -0
- package/es/comps/MetadataEdit/components/MetaPropsEdit.js +5 -3
- package/es/comps/MetadataForm/DataCell/layout/TableArray.js +63 -25
- package/es/comps/MetadataForm/utils.d.ts +1 -0
- package/es/comps/MetadataForm/utils.js +10 -1
- package/es/comps/locales/en-US.d.ts +4 -0
- package/es/comps/locales/en-US.js +10 -1
- package/es/comps/locales/zh-CN.d.ts +4 -0
- package/es/comps/locales/zh-CN.js +10 -1
- package/es/framework/graph/index.css +12 -0
- package/es/framework/graph/index.d.ts +60 -0
- package/es/framework/graph/index.js +425 -0
- package/es/framework/libs/iconfont/iconfont.css +187 -0
- package/es/framework/libs/iconfont/iconfont.ttf +0 -0
- package/es/framework/libs/iconfont/iconfont.woff +0 -0
- package/es/framework/libs/iconfont/iconfont.woff2 +0 -0
- package/es/framework/rxjs-hooks/useObservableState.d.ts +3 -0
- package/es/framework/rxjs-hooks/useObservableState.js +45 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -1
- package/package.json +7 -1
@@ -0,0 +1,167 @@
|
|
1
|
+
.node-element {
|
2
|
+
display: flex;
|
3
|
+
align-items: center;
|
4
|
+
box-sizing: border-box;
|
5
|
+
width: 180px;
|
6
|
+
height: 32px;
|
7
|
+
overflow: hidden;
|
8
|
+
background-color: #fff;
|
9
|
+
border-radius: 4px;
|
10
|
+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.08);
|
11
|
+
}
|
12
|
+
.node-element.selected,
|
13
|
+
.node-element:hover {
|
14
|
+
background-color: rgba(243, 249, 255, 0.92);
|
15
|
+
border: 1px solid #1890ff;
|
16
|
+
box-shadow: 0 0 3px 3px rgba(64, 169, 255, 0.2);
|
17
|
+
}
|
18
|
+
.node-element.selected .icon,
|
19
|
+
.node-element:hover .icon {
|
20
|
+
width: 32px;
|
21
|
+
height: 30px;
|
22
|
+
margin: 0 1px 0 -1px;
|
23
|
+
}
|
24
|
+
.node-element > * {
|
25
|
+
flex-grow: 1;
|
26
|
+
}
|
27
|
+
.node-element .icon {
|
28
|
+
display: inline-flex;
|
29
|
+
flex-grow: 0;
|
30
|
+
align-items: center;
|
31
|
+
justify-content: center;
|
32
|
+
width: 32px;
|
33
|
+
height: 32px;
|
34
|
+
background-color: rgba(229, 238, 255, 0.85);
|
35
|
+
border-radius: 4px 0 0 4px;
|
36
|
+
}
|
37
|
+
.node-element .notation {
|
38
|
+
display: inline-flex;
|
39
|
+
align-items: center;
|
40
|
+
width: calc(100% - 32px);
|
41
|
+
padding: 0 8px;
|
42
|
+
user-select: none;
|
43
|
+
}
|
44
|
+
.node-element .notation > * {
|
45
|
+
flex-grow: 1;
|
46
|
+
}
|
47
|
+
.node-element .notation .name {
|
48
|
+
overflow-x: hidden;
|
49
|
+
color: rgba(0, 0, 0, 0.65);
|
50
|
+
font-size: 12px;
|
51
|
+
white-space: nowrap;
|
52
|
+
text-overflow: ellipsis;
|
53
|
+
vertical-align: middle;
|
54
|
+
}
|
55
|
+
.node-element .notation .statusIcon {
|
56
|
+
display: inline-flex;
|
57
|
+
flex-grow: 0;
|
58
|
+
align-items: center;
|
59
|
+
font-size: 14px;
|
60
|
+
transform: translateZ(0);
|
61
|
+
}
|
62
|
+
.dynamic-ports {
|
63
|
+
position: relative;
|
64
|
+
}
|
65
|
+
.dynamic-ports .x6-node [magnet='true'] {
|
66
|
+
cursor: crosshair;
|
67
|
+
transition: none;
|
68
|
+
}
|
69
|
+
.dynamic-ports .x6-node [magnet='true']:hover {
|
70
|
+
opacity: 1;
|
71
|
+
}
|
72
|
+
.dynamic-ports .x6-node [magnet='true'][port-group='in'] {
|
73
|
+
cursor: move;
|
74
|
+
stroke: none;
|
75
|
+
}
|
76
|
+
.dynamic-ports .x6-port-body > span {
|
77
|
+
display: block;
|
78
|
+
}
|
79
|
+
.dynamic-ports .x6-node-selected .node-element {
|
80
|
+
background-color: rgba(243, 249, 255, 0.92);
|
81
|
+
border: 1px solid #1890ff;
|
82
|
+
box-shadow: 0 0 3px 3px rgba(64, 169, 255, 0.2);
|
83
|
+
}
|
84
|
+
.dynamic-ports .dp-port {
|
85
|
+
width: 100%;
|
86
|
+
height: 100%;
|
87
|
+
border: 1px solid #808080;
|
88
|
+
border-radius: 100%;
|
89
|
+
background: #fff;
|
90
|
+
display: block;
|
91
|
+
}
|
92
|
+
.dynamic-ports .dp-port.connected {
|
93
|
+
width: 0;
|
94
|
+
height: 0;
|
95
|
+
margin-top: 3px;
|
96
|
+
margin-left: -1px;
|
97
|
+
border-width: 5px 4px 0;
|
98
|
+
border-style: solid;
|
99
|
+
border-color: #808080 transparent transparent;
|
100
|
+
border-radius: 0;
|
101
|
+
background-color: transparent;
|
102
|
+
}
|
103
|
+
.dynamic-ports .x6-port-body.available {
|
104
|
+
overflow: visible;
|
105
|
+
}
|
106
|
+
.dynamic-ports .x6-port-body.available body {
|
107
|
+
overflow: visible;
|
108
|
+
}
|
109
|
+
.dynamic-ports .x6-port-body.available span {
|
110
|
+
overflow: visible;
|
111
|
+
display: block;
|
112
|
+
}
|
113
|
+
.dynamic-ports .x6-port-body.available body > span::before {
|
114
|
+
content: ' ';
|
115
|
+
float: left;
|
116
|
+
width: 20px;
|
117
|
+
height: 20px;
|
118
|
+
margin-top: -6px;
|
119
|
+
margin-left: -6px;
|
120
|
+
border-radius: 50%;
|
121
|
+
background-color: rgba(57, 202, 116, 0.6);
|
122
|
+
box-sizing: border-box;
|
123
|
+
}
|
124
|
+
.dynamic-ports .x6-port-body.available body > span::after {
|
125
|
+
content: ' ';
|
126
|
+
float: left;
|
127
|
+
clear: both;
|
128
|
+
width: 10px;
|
129
|
+
height: 10px;
|
130
|
+
margin-top: -15px;
|
131
|
+
margin-left: -1px;
|
132
|
+
border-radius: 50%;
|
133
|
+
background-color: #fff;
|
134
|
+
border: 1px solid #39ca74;
|
135
|
+
z-index: 10;
|
136
|
+
box-sizing: border-box;
|
137
|
+
}
|
138
|
+
.dynamic-ports .x6-port-body.adsorbed {
|
139
|
+
overflow: visible;
|
140
|
+
}
|
141
|
+
.dynamic-ports .x6-port-body.adsorbed body {
|
142
|
+
overflow: visible;
|
143
|
+
}
|
144
|
+
.dynamic-ports .x6-port-body.adsorbed body > span::before {
|
145
|
+
content: ' ';
|
146
|
+
float: left;
|
147
|
+
width: 28px;
|
148
|
+
height: 28px;
|
149
|
+
margin-top: -9px;
|
150
|
+
margin-left: -10px;
|
151
|
+
border-radius: 50%;
|
152
|
+
background-color: rgba(57, 202, 116, 0.6);
|
153
|
+
box-sizing: border-box;
|
154
|
+
}
|
155
|
+
.dynamic-ports .x6-port-body.adsorbed body > span::after {
|
156
|
+
content: ' ';
|
157
|
+
float: left;
|
158
|
+
clear: both;
|
159
|
+
width: 10px;
|
160
|
+
height: 10px;
|
161
|
+
margin-top: -19px;
|
162
|
+
border-radius: 50%;
|
163
|
+
background-color: #fff;
|
164
|
+
border: 1px solid #39ca74;
|
165
|
+
z-index: 10;
|
166
|
+
box-sizing: border-box;
|
167
|
+
}
|
@@ -1,2 +1,19 @@
|
|
1
|
-
|
1
|
+
import './index.less';
|
2
|
+
import './comps/shape/connector';
|
3
|
+
import { NDPGraph } from './interface';
|
4
|
+
interface IDynamicPortsProps {
|
5
|
+
/**
|
6
|
+
* 渲染图结构
|
7
|
+
*/
|
8
|
+
defaultValue?: NDPGraph.GraphData;
|
9
|
+
/**
|
10
|
+
* 图更新事件
|
11
|
+
*/
|
12
|
+
onChange?: (data: NDPGraph.GraphData) => void;
|
13
|
+
/**
|
14
|
+
* 节点选中事件
|
15
|
+
*/
|
16
|
+
onNodeSelect?: (data: NDPGraph.Node) => void;
|
17
|
+
}
|
18
|
+
declare const DynamicPorts: (props: IDynamicPortsProps) => JSX.Element;
|
2
19
|
export default DynamicPorts;
|
@@ -1,80 +1,141 @@
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
3
|
+
|
1
4
|
/*
|
2
5
|
* @Author: wangxian
|
3
6
|
* @Date: 2022-05-16 18:53:31
|
4
|
-
* @LastEditTime: 2022-05-
|
7
|
+
* @LastEditTime: 2022-05-27 14:24:06
|
5
8
|
*/
|
6
|
-
import { Markup } from "@antv/x6/es/view/markup";
|
7
9
|
import React from 'react';
|
10
|
+
import { filter } from 'rxjs';
|
11
|
+
import { useDrop } from 'react-dnd';
|
12
|
+
import "./index.css";
|
13
|
+
import './comps/shape/connector';
|
14
|
+
import { useDPGraph, useUnmountDPGraph } from './graph';
|
15
|
+
import { DRAGGABLE_COMPONENT, DRAGGABLE_MODEL } from './constant';
|
16
|
+
import { guid } from '../../utils';
|
17
|
+
import ContextMenu from './comps/ContextMenu';
|
18
|
+
import { GraphHandler } from './comps/GraphHandler';
|
8
19
|
|
9
|
-
var DynamicPorts = function DynamicPorts() {
|
10
|
-
var
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
var DynamicPorts = function DynamicPorts(props) {
|
21
|
+
var defaultValue = props.defaultValue,
|
22
|
+
onChange = props.onChange,
|
23
|
+
onNodeSelect = props.onNodeSelect;
|
24
|
+
var divRef = React.useRef(null);
|
25
|
+
var containerRef = React.useRef(null);
|
26
|
+
|
27
|
+
var _React$useState = React.useState(),
|
28
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
29
|
+
dpGraph = _React$useState2[0],
|
30
|
+
setGraph = _React$useState2[1];
|
31
|
+
|
32
|
+
var dpGraphRef = React.useRef();
|
33
|
+
var firstLoadRef = React.useRef(true); // 处理画布卸载
|
34
|
+
|
35
|
+
useUnmountDPGraph(); // 渲染画布
|
36
|
+
|
37
|
+
React.useEffect(function () {
|
38
|
+
if (firstLoadRef.current) {
|
39
|
+
var _dpGraph = useDPGraph(defaultValue);
|
40
|
+
|
41
|
+
dpGraphRef.current = _dpGraph;
|
42
|
+
setGraph(_dpGraph);
|
43
|
+
|
44
|
+
_dpGraph.renderGraph(containerRef.current, divRef.current); // 获取图信息的订阅
|
45
|
+
|
46
|
+
|
47
|
+
_dpGraph.factory$.dpGraph.pipe(filter(function (x) {
|
48
|
+
return !!x;
|
49
|
+
})).subscribe(function (v) {
|
50
|
+
onChange && onChange(v);
|
51
|
+
}); // 获取选中节点的订阅
|
52
|
+
|
53
|
+
|
54
|
+
_dpGraph.factory$.selectedNodes.subscribe(function (v) {
|
55
|
+
onNodeSelect && onNodeSelect(v[0]);
|
56
|
+
});
|
15
57
|
|
16
|
-
|
17
|
-
var testNode = {
|
18
|
-
x: 40,
|
19
|
-
y: 35,
|
20
|
-
width: 160,
|
21
|
-
height: 30,
|
22
|
-
label: 'Hello',
|
23
|
-
attrs: {
|
24
|
-
body: {
|
25
|
-
strokeWidth: 1,
|
26
|
-
stroke: '#108ee9',
|
27
|
-
fill: '#fff',
|
28
|
-
rx: 5,
|
29
|
-
ry: 5
|
58
|
+
firstLoadRef.current = false;
|
30
59
|
}
|
31
|
-
},
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
fo: {
|
54
|
-
width: 10,
|
55
|
-
height: 10,
|
56
|
-
x: -5,
|
57
|
-
y: -5,
|
58
|
-
magnet: 'true'
|
59
|
-
}
|
60
|
-
},
|
61
|
-
zIndex: 1
|
62
|
-
},
|
63
|
-
out: {
|
64
|
-
position: {
|
65
|
-
name: 'bottom'
|
66
|
-
},
|
67
|
-
attrs: {
|
68
|
-
fo: {
|
69
|
-
width: 10,
|
70
|
-
height: 10,
|
71
|
-
x: -5,
|
72
|
-
y: -5,
|
73
|
-
magnet: 'true'
|
74
|
-
}
|
75
|
-
},
|
76
|
-
zIndex: 1
|
60
|
+
}, []); // 处理组件拖拽落下事件
|
61
|
+
|
62
|
+
var _useDrop = useDrop({
|
63
|
+
accept: [DRAGGABLE_COMPONENT, DRAGGABLE_MODEL],
|
64
|
+
drop: function drop(item, monitor) {
|
65
|
+
var currentMouseOffset = monitor.getClientOffset();
|
66
|
+
var sourceMouseOffset = monitor.getInitialClientOffset();
|
67
|
+
var sourceElementOffset = monitor.getInitialSourceClientOffset();
|
68
|
+
var diffX = sourceMouseOffset.x - sourceElementOffset.x;
|
69
|
+
var diffY = sourceMouseOffset.y - sourceElementOffset.y;
|
70
|
+
var x = currentMouseOffset.x - diffX;
|
71
|
+
var y = currentMouseOffset.y - diffY;
|
72
|
+
|
73
|
+
if (dpGraphRef.current.isGraphReady()) {
|
74
|
+
dpGraphRef.current.addDragNode(_objectSpread(_objectSpread({}, item.comp), {}, {
|
75
|
+
libId: item.comp.id,
|
76
|
+
id: guid(),
|
77
|
+
x: x,
|
78
|
+
y: y
|
79
|
+
}));
|
80
|
+
} else {
|
81
|
+
console.warn('请稍后再尝试添加节点');
|
77
82
|
}
|
78
83
|
}
|
79
|
-
}
|
80
|
-
|
84
|
+
}),
|
85
|
+
_useDrop2 = _slicedToArray(_useDrop, 2),
|
86
|
+
dropRef = _useDrop2[1]; // 画布侧边 toolbar handler
|
87
|
+
|
88
|
+
|
89
|
+
var onHandleSideToolbar = React.useCallback(function (action) {
|
90
|
+
return function () {
|
91
|
+
// 确保画布已渲染
|
92
|
+
if (dpGraphRef.current.isGraphReady()) {
|
93
|
+
switch (action) {
|
94
|
+
case 'in':
|
95
|
+
dpGraphRef.current.zoomGraph(0.1);
|
96
|
+
break;
|
97
|
+
|
98
|
+
case 'out':
|
99
|
+
dpGraphRef.current.zoomGraph(-0.1);
|
100
|
+
break;
|
101
|
+
|
102
|
+
case 'fit':
|
103
|
+
dpGraphRef.current.zoomGraphToFit();
|
104
|
+
break;
|
105
|
+
|
106
|
+
case 'real':
|
107
|
+
dpGraphRef.current.zoomGraphRealSize();
|
108
|
+
break;
|
109
|
+
|
110
|
+
default:
|
111
|
+
}
|
112
|
+
}
|
113
|
+
};
|
114
|
+
}, [dpGraph]);
|
115
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
116
|
+
ref: function ref(elem) {
|
117
|
+
containerRef.current = elem;
|
118
|
+
dropRef(elem);
|
119
|
+
},
|
120
|
+
className: "dynamic-ports",
|
121
|
+
style: {
|
122
|
+
height: '100%',
|
123
|
+
width: '100%'
|
124
|
+
}
|
125
|
+
}, /*#__PURE__*/React.createElement(ContextMenu, {
|
126
|
+
graph: dpGraph
|
127
|
+
}), /*#__PURE__*/React.createElement(GraphHandler, {
|
128
|
+
onZoomIn: onHandleSideToolbar('in'),
|
129
|
+
onZoomOut: onHandleSideToolbar('out'),
|
130
|
+
onFitContent: onHandleSideToolbar('fit'),
|
131
|
+
onRealContent: onHandleSideToolbar('real')
|
132
|
+
}), /*#__PURE__*/React.createElement("div", {
|
133
|
+
style: {
|
134
|
+
height: '100%',
|
135
|
+
width: '100%'
|
136
|
+
},
|
137
|
+
ref: divRef
|
138
|
+
})));
|
139
|
+
};
|
140
|
+
|
141
|
+
export default DynamicPorts;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
export declare namespace NDPGraph {
|
2
|
+
interface GraphData {
|
3
|
+
nodes: Node[];
|
4
|
+
edges: Edge[];
|
5
|
+
}
|
6
|
+
interface Node {
|
7
|
+
/**
|
8
|
+
* 图渲染的主键id
|
9
|
+
*/
|
10
|
+
id: string;
|
11
|
+
/**
|
12
|
+
* 原始组件库的id
|
13
|
+
*/
|
14
|
+
libId?: string;
|
15
|
+
/**
|
16
|
+
* 图标
|
17
|
+
*/
|
18
|
+
icon?: string;
|
19
|
+
name: string;
|
20
|
+
inPorts: InPort[];
|
21
|
+
outPorts: OutPort[];
|
22
|
+
x: number;
|
23
|
+
y: number;
|
24
|
+
param?: Param;
|
25
|
+
}
|
26
|
+
interface Edge {
|
27
|
+
source: string;
|
28
|
+
target: string;
|
29
|
+
outPortId: string;
|
30
|
+
inPortId: string;
|
31
|
+
}
|
32
|
+
interface OutPort extends Port {
|
33
|
+
}
|
34
|
+
interface InPort extends Port {
|
35
|
+
}
|
36
|
+
interface Port {
|
37
|
+
id: string;
|
38
|
+
name: string;
|
39
|
+
seq: number;
|
40
|
+
}
|
41
|
+
interface Param {
|
42
|
+
[key: string]: any;
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
import { NDPGraph } from './interface';
|
2
|
+
import { Graph } from '@antv/x6';
|
3
|
+
export declare function graphPointToOffsetPoint(graph: Graph, graphPoint: {
|
4
|
+
x: number;
|
5
|
+
y: number;
|
6
|
+
}, containerElem: HTMLElement): {
|
7
|
+
x: number;
|
8
|
+
y: number;
|
9
|
+
};
|
10
|
+
export declare function formatNodeInfoToNodeMeta(nodeData: NDPGraph.Node, inputPortConnectedMap?: {
|
11
|
+
[k: string]: boolean;
|
12
|
+
}): {
|
13
|
+
x: number;
|
14
|
+
y: number;
|
15
|
+
type: string;
|
16
|
+
id: string;
|
17
|
+
width: number;
|
18
|
+
height: number;
|
19
|
+
data: {
|
20
|
+
type: string;
|
21
|
+
x: number;
|
22
|
+
y: number;
|
23
|
+
id: string;
|
24
|
+
libId?: string;
|
25
|
+
icon?: string;
|
26
|
+
name: string;
|
27
|
+
inPorts: NDPGraph.InPort[];
|
28
|
+
outPorts: NDPGraph.OutPort[];
|
29
|
+
param?: NDPGraph.Param;
|
30
|
+
};
|
31
|
+
ports: {
|
32
|
+
items: any[];
|
33
|
+
};
|
34
|
+
zIndex: number;
|
35
|
+
libId?: string;
|
36
|
+
icon?: string;
|
37
|
+
name: string;
|
38
|
+
inPorts: NDPGraph.InPort[];
|
39
|
+
outPorts: NDPGraph.OutPort[];
|
40
|
+
param?: NDPGraph.Param;
|
41
|
+
};
|
42
|
+
/**
|
43
|
+
* 将暴露给接口的图信息转换可渲染的结图结构信息
|
44
|
+
* @returns
|
45
|
+
*/
|
46
|
+
export declare function formatGraphData(graphData: NDPGraph.GraphData): {
|
47
|
+
nodes: {
|
48
|
+
x: number;
|
49
|
+
y: number;
|
50
|
+
type: string;
|
51
|
+
id: string;
|
52
|
+
width: number;
|
53
|
+
height: number;
|
54
|
+
data: {
|
55
|
+
type: string;
|
56
|
+
x: number;
|
57
|
+
y: number;
|
58
|
+
id: string;
|
59
|
+
libId?: string;
|
60
|
+
icon?: string;
|
61
|
+
name: string;
|
62
|
+
inPorts: NDPGraph.InPort[];
|
63
|
+
outPorts: NDPGraph.OutPort[];
|
64
|
+
param?: NDPGraph.Param;
|
65
|
+
};
|
66
|
+
ports: {
|
67
|
+
items: any[];
|
68
|
+
};
|
69
|
+
zIndex: number;
|
70
|
+
libId?: string;
|
71
|
+
icon?: string;
|
72
|
+
name: string;
|
73
|
+
inPorts: NDPGraph.InPort[];
|
74
|
+
outPorts: NDPGraph.OutPort[];
|
75
|
+
param?: NDPGraph.Param;
|
76
|
+
}[];
|
77
|
+
edges: {
|
78
|
+
data: {
|
79
|
+
source: string;
|
80
|
+
target: string;
|
81
|
+
outPortId: string;
|
82
|
+
inPortId: string;
|
83
|
+
};
|
84
|
+
sourceAnchor: string;
|
85
|
+
source: {
|
86
|
+
cell: string;
|
87
|
+
port: string;
|
88
|
+
anchor: {
|
89
|
+
name: string;
|
90
|
+
};
|
91
|
+
};
|
92
|
+
target: {
|
93
|
+
cell: string;
|
94
|
+
port: string;
|
95
|
+
anchor: {
|
96
|
+
name: string;
|
97
|
+
};
|
98
|
+
};
|
99
|
+
label: string;
|
100
|
+
zIndex: number;
|
101
|
+
outPortId: string;
|
102
|
+
inPortId: string;
|
103
|
+
}[];
|
104
|
+
};
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @Author: wangxian
|
6
|
+
* @Date: 2022-05-24 16:40:49
|
7
|
+
* @LastEditTime: 2022-05-27 16:02:48
|
8
|
+
*/
|
9
|
+
import { sortBy } from 'lodash-es';
|
10
|
+
import { NODE_HEIGHT, NODE_WIDTH } from './constant'; // 将画布上的点转换成相对于 offset parent 的点
|
11
|
+
|
12
|
+
export function graphPointToOffsetPoint(graph, graphPoint, containerElem) {
|
13
|
+
if (graph) {
|
14
|
+
var point = graph.localToPage({
|
15
|
+
x: graphPoint.x,
|
16
|
+
y: graphPoint.y
|
17
|
+
});
|
18
|
+
var clientRect = containerElem === null || containerElem === void 0 ? void 0 : containerElem.getBoundingClientRect();
|
19
|
+
var y = point.y - ((clientRect === null || clientRect === void 0 ? void 0 : clientRect.y) || 0); // ! offset parent 不能是画布容器,否则会影响内部布局,所以 offset parent 在外部,算上上方 toolbar 的高度
|
20
|
+
|
21
|
+
var x = point.x - ((clientRect === null || clientRect === void 0 ? void 0 : clientRect.x) || 0);
|
22
|
+
return {
|
23
|
+
x: x,
|
24
|
+
y: y
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
return {
|
29
|
+
x: 0,
|
30
|
+
y: 0
|
31
|
+
};
|
32
|
+
} // 格式化单个节点,新增节点时复用
|
33
|
+
|
34
|
+
export function formatNodeInfoToNodeMeta(nodeData) {
|
35
|
+
var inputPortConnectedMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
36
|
+
var portItems = [];
|
37
|
+
var id = nodeData.id,
|
38
|
+
_nodeData$x = nodeData.x,
|
39
|
+
x = _nodeData$x === void 0 ? 0 : _nodeData$x,
|
40
|
+
_nodeData$y = nodeData.y,
|
41
|
+
y = _nodeData$y === void 0 ? 0 : _nodeData$y,
|
42
|
+
inPorts = nodeData.inPorts,
|
43
|
+
outPorts = nodeData.outPorts;
|
44
|
+
sortBy(inPorts, 'seq').forEach(function (inPort) {
|
45
|
+
portItems.push(_objectSpread(_objectSpread({}, inPort), {}, {
|
46
|
+
group: 'in',
|
47
|
+
id: inPort.id.toString(),
|
48
|
+
connected: !!inputPortConnectedMap[inPort.id.toString()]
|
49
|
+
}));
|
50
|
+
});
|
51
|
+
sortBy(outPorts, 'seq').forEach(function (outPort) {
|
52
|
+
portItems.push(_objectSpread(_objectSpread({}, outPort), {}, {
|
53
|
+
group: 'out',
|
54
|
+
id: outPort.id.toString(),
|
55
|
+
connected: !!inputPortConnectedMap[outPort.id.toString()]
|
56
|
+
}));
|
57
|
+
});
|
58
|
+
return _objectSpread(_objectSpread({}, nodeData), {}, {
|
59
|
+
x: x,
|
60
|
+
y: y,
|
61
|
+
type: 'node',
|
62
|
+
id: id.toString(),
|
63
|
+
width: NODE_WIDTH,
|
64
|
+
height: NODE_HEIGHT,
|
65
|
+
data: _objectSpread(_objectSpread({}, nodeData), {}, {
|
66
|
+
type: 'node',
|
67
|
+
x: x,
|
68
|
+
y: y,
|
69
|
+
id: id.toString()
|
70
|
+
}),
|
71
|
+
ports: {
|
72
|
+
items: portItems
|
73
|
+
},
|
74
|
+
zIndex: 10
|
75
|
+
});
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* 将暴露给接口的图信息转换可渲染的结图结构信息
|
79
|
+
* @returns
|
80
|
+
*/
|
81
|
+
|
82
|
+
export function formatGraphData(graphData) {
|
83
|
+
var _graphData$nodes = graphData.nodes,
|
84
|
+
nodes = _graphData$nodes === void 0 ? [] : _graphData$nodes,
|
85
|
+
_graphData$edges = graphData.edges,
|
86
|
+
edges = _graphData$edges === void 0 ? [] : _graphData$edges; // 格式化边
|
87
|
+
|
88
|
+
var formattedEdges = edges.map(function (edges) {
|
89
|
+
var source = edges.source,
|
90
|
+
outPortId = edges.outPortId,
|
91
|
+
target = edges.target,
|
92
|
+
inPortId = edges.inPortId;
|
93
|
+
return _objectSpread(_objectSpread({}, edges), {}, {
|
94
|
+
data: _objectSpread({}, edges),
|
95
|
+
sourceAnchor: 'bottom',
|
96
|
+
source: {
|
97
|
+
cell: source.toString(),
|
98
|
+
port: outPortId.toString(),
|
99
|
+
anchor: {
|
100
|
+
name: 'bottom'
|
101
|
+
}
|
102
|
+
},
|
103
|
+
target: {
|
104
|
+
cell: target.toString(),
|
105
|
+
port: inPortId.toString(),
|
106
|
+
anchor: {
|
107
|
+
name: 'center'
|
108
|
+
}
|
109
|
+
},
|
110
|
+
label: '',
|
111
|
+
zIndex: 1
|
112
|
+
});
|
113
|
+
}); // 记录所有已连线的输入桩
|
114
|
+
|
115
|
+
var inputPortConnectedMap = formattedEdges.reduce(function (acc, edge) {
|
116
|
+
acc[edge.inPortId] = true;
|
117
|
+
return acc;
|
118
|
+
}, {}); // 格式化算法组件节点
|
119
|
+
|
120
|
+
var formattedNodes = nodes.map(function (nodeData) {
|
121
|
+
return formatNodeInfoToNodeMeta(nodeData, inputPortConnectedMap);
|
122
|
+
});
|
123
|
+
return {
|
124
|
+
nodes: _toConsumableArray(formattedNodes),
|
125
|
+
edges: formattedEdges
|
126
|
+
};
|
127
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import '../../framework/libs/iconfont/iconfont.css';
|
3
|
+
interface Props {
|
4
|
+
/**
|
5
|
+
* 图标类型
|
6
|
+
*/
|
7
|
+
type: string;
|
8
|
+
/**
|
9
|
+
* class样式
|
10
|
+
*/
|
11
|
+
className?: string;
|
12
|
+
/**
|
13
|
+
* style
|
14
|
+
*/
|
15
|
+
style?: React.CSSProperties;
|
16
|
+
}
|
17
|
+
declare const Icon: React.FC<Props>;
|
18
|
+
export default Icon;
|