@logicflow/extension 1.2.4 → 1.2.6
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/cjs/bpmn-adapter/index.js +89 -50
- package/cjs/bpmn-adapter/json2xml.js +78 -46
- package/cjs/bpmn-adapter/xml2json.js +23 -9
- package/cjs/insert-node-in-polyline/index.js +49 -5
- package/es/bpmn-adapter/index.d.ts +13 -3
- package/es/bpmn-adapter/index.js +88 -51
- package/es/bpmn-adapter/json2xml.d.ts +3 -2
- package/es/bpmn-adapter/json2xml.js +77 -46
- package/es/bpmn-adapter/xml2json.js +23 -9
- package/es/insert-node-in-polyline/index.d.ts +13 -0
- package/es/insert-node-in-polyline/index.js +49 -5
- package/lib/AutoLayout.js +1 -1
- package/lib/BpmnAdapter.js +1 -1
- package/lib/BpmnElement.js +1 -1
- package/lib/ContextMenu.js +1 -1
- package/lib/Control.js +1 -1
- package/lib/CurvedEdge.js +1 -1
- package/lib/DndPanel.js +1 -1
- package/lib/FlowPath.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Highlight.js +1 -1
- package/lib/InsertNodeInPolyline.js +1 -1
- package/lib/Menu.js +1 -1
- package/lib/MiniMap.js +1 -1
- package/lib/NodeResize.js +1 -1
- package/lib/RectLabelNode.js +1 -1
- package/lib/SelectionSelect.js +1 -1
- package/lib/Snapshot.js +1 -1
- package/lib/TurboAdapter.js +1 -1
- package/lib/lfJson2Xml.js +1 -1
- package/lib/lfXml2Json.js +1 -1
- package/package.json +5 -4
- package/types/bpmn-adapter/index.d.ts +13 -3
- package/types/bpmn-adapter/json2xml.d.ts +3 -2
- package/types/insert-node-in-polyline/index.d.ts +13 -0
package/es/bpmn-adapter/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
39
39
|
return ar;
|
|
40
40
|
};
|
|
41
41
|
import { getBpmnId } from './bpmnIds';
|
|
42
|
-
import { lfJson2Xml } from './json2xml';
|
|
42
|
+
import { handleAttributes, lfJson2Xml } from './json2xml';
|
|
43
43
|
import { lfXml2Json } from './xml2json';
|
|
44
44
|
import { ExclusiveGatewayConfig, StartEventConfig, EndEventConfig, ServiceTaskConfig, UserTaskConfig, } from '../bpmn/constant';
|
|
45
45
|
var BpmnElements;
|
|
@@ -51,29 +51,60 @@ var BpmnElements;
|
|
|
51
51
|
BpmnElements["SYSTEM"] = "bpmn:serviceTask";
|
|
52
52
|
BpmnElements["FLOW"] = "bpmn:sequenceFlow";
|
|
53
53
|
})(BpmnElements || (BpmnElements = {}));
|
|
54
|
-
var defaultAttrs = [
|
|
54
|
+
var defaultAttrs = [
|
|
55
|
+
'-name',
|
|
56
|
+
'-id',
|
|
57
|
+
'bpmn:incoming',
|
|
58
|
+
'bpmn:outgoing',
|
|
59
|
+
'-sourceRef',
|
|
60
|
+
'-targetRef',
|
|
61
|
+
];
|
|
55
62
|
/**
|
|
56
63
|
* 将普通json转换为xmlJson
|
|
57
64
|
* xmlJson中property会以“-”开头
|
|
58
65
|
* 如果没有“-”表示为子节点
|
|
66
|
+
* fix issue https://github.com/didi/LogicFlow/issues/718, contain the process of #text/#cdata and array
|
|
67
|
+
* @param retainedFields retainedField会和默认的defaultRetainedFields:
|
|
68
|
+
* ["properties", "startPoint", "endPoint", "pointsList"]合并
|
|
69
|
+
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性
|
|
70
|
+
* @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
59
71
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
var defaultRetainedFields = ['properties', 'startPoint', 'endPoint', 'pointsList'];
|
|
73
|
+
function toXmlJson(retainedFields) {
|
|
74
|
+
var fields = retainedFields
|
|
75
|
+
? defaultRetainedFields.concat(retainedFields) : defaultRetainedFields;
|
|
76
|
+
return function (json) {
|
|
77
|
+
function ToXmlJson(obj) {
|
|
78
|
+
var xmlJson = {};
|
|
79
|
+
if (typeof obj === 'string') {
|
|
80
|
+
return obj;
|
|
67
81
|
}
|
|
68
|
-
|
|
69
|
-
|
|
82
|
+
if (Array.isArray(obj)) {
|
|
83
|
+
return obj.map(function (j) { return ToXmlJson(j); });
|
|
70
84
|
}
|
|
85
|
+
Object.entries(obj).forEach(function (_a) {
|
|
86
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
87
|
+
if (typeof value !== 'object') {
|
|
88
|
+
// node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
89
|
+
if (key.indexOf('-') === 0
|
|
90
|
+
|| ['#text', '#cdata-section', '#comment'].includes(key)) {
|
|
91
|
+
xmlJson[key] = value;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
xmlJson["-" + key] = value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (fields.includes(key)) {
|
|
98
|
+
xmlJson["-" + key] = ToXmlJson(value);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
xmlJson[key] = ToXmlJson(value);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return xmlJson;
|
|
71
105
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return xmlJson;
|
|
106
|
+
return ToXmlJson(json);
|
|
107
|
+
};
|
|
77
108
|
}
|
|
78
109
|
/**
|
|
79
110
|
* 将xmlJson转换为普通的json,在内部使用。
|
|
@@ -82,17 +113,19 @@ function toNormalJson(xmlJson) {
|
|
|
82
113
|
var json = {};
|
|
83
114
|
Object.entries(xmlJson).forEach(function (_a) {
|
|
84
115
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
json[key.substr(1)] = value;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
json[key] = value;
|
|
91
|
-
}
|
|
116
|
+
if (key.indexOf('-') === 0) {
|
|
117
|
+
json[key.substring(1)] = handleAttributes(value);
|
|
92
118
|
}
|
|
93
|
-
else if (typeof value === '
|
|
119
|
+
else if (typeof value === 'string') {
|
|
120
|
+
json[key] = value;
|
|
121
|
+
}
|
|
122
|
+
else if (Object.prototype.toString.call(value) === '[object Object]') {
|
|
94
123
|
json[key] = toNormalJson(value);
|
|
95
124
|
}
|
|
125
|
+
else if (Array.isArray(value)) {
|
|
126
|
+
// contain the process of array
|
|
127
|
+
json[key] = value.map(function (v) { return toNormalJson(v); });
|
|
128
|
+
}
|
|
96
129
|
else {
|
|
97
130
|
json[key] = value;
|
|
98
131
|
}
|
|
@@ -107,7 +140,7 @@ function toNormalJson(xmlJson) {
|
|
|
107
140
|
* 2)如果只有一个子元素,json中表示为正常属性
|
|
108
141
|
* 3)如果是多个子元素,json中使用数组存储
|
|
109
142
|
*/
|
|
110
|
-
function convertLf2ProcessData(bpmnProcessData, data) {
|
|
143
|
+
function convertLf2ProcessData(bpmnProcessData, data, retainedFields) {
|
|
111
144
|
var nodeMap = new Map();
|
|
112
145
|
data.nodes.forEach(function (node) {
|
|
113
146
|
var _a;
|
|
@@ -118,21 +151,20 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
118
151
|
processNode['-name'] = node.text.value;
|
|
119
152
|
}
|
|
120
153
|
if (node.properties) {
|
|
121
|
-
var properties = toXmlJson(node.properties);
|
|
154
|
+
var properties = toXmlJson(retainedFields)(node.properties);
|
|
122
155
|
Object.assign(processNode, properties);
|
|
123
156
|
}
|
|
124
157
|
nodeMap.set(node.id, processNode);
|
|
125
158
|
if (!bpmnProcessData[node.type]) {
|
|
126
159
|
bpmnProcessData[node.type] = processNode; // 如果只有一个子元素,json中表示为正常属性
|
|
127
160
|
}
|
|
128
|
-
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
161
|
+
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
162
|
+
// 如果是多个子元素,json中使用数组存储
|
|
129
163
|
bpmnProcessData[node.type].push(processNode);
|
|
130
164
|
}
|
|
131
|
-
else {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
processNode,
|
|
135
|
-
];
|
|
165
|
+
else {
|
|
166
|
+
// 如果是多个子元素,json中使用数组存储
|
|
167
|
+
bpmnProcessData[node.type] = [bpmnProcessData[node.type], processNode];
|
|
136
168
|
}
|
|
137
169
|
});
|
|
138
170
|
var sequenceFlow = data.edges.map(function (edge) {
|
|
@@ -145,10 +177,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
145
177
|
targetNode['bpmn:incoming'].push(edge.id);
|
|
146
178
|
}
|
|
147
179
|
else {
|
|
148
|
-
targetNode['bpmn:incoming'] = [
|
|
149
|
-
targetNode['bpmn:incoming'],
|
|
150
|
-
edge.id,
|
|
151
|
-
];
|
|
180
|
+
targetNode['bpmn:incoming'] = [targetNode['bpmn:incoming'], edge.id];
|
|
152
181
|
}
|
|
153
182
|
var edgeConfig = {
|
|
154
183
|
'-id': edge.id,
|
|
@@ -159,7 +188,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
159
188
|
edgeConfig['-name'] = (_b = edge.text) === null || _b === void 0 ? void 0 : _b.value;
|
|
160
189
|
}
|
|
161
190
|
if (edge.properties) {
|
|
162
|
-
var properties = toXmlJson(edge.properties);
|
|
191
|
+
var properties = toXmlJson(retainedFields)(edge.properties);
|
|
163
192
|
Object.assign(edgeConfig, properties);
|
|
164
193
|
}
|
|
165
194
|
return edgeConfig;
|
|
@@ -174,11 +203,9 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
174
203
|
else if (Array.isArray(sourceNode['bpmn:outgoing'])) {
|
|
175
204
|
sourceNode['bpmn:outgoing'].push(edge.id);
|
|
176
205
|
}
|
|
177
|
-
else {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
edge.id,
|
|
181
|
-
];
|
|
206
|
+
else {
|
|
207
|
+
// 字符串转数组
|
|
208
|
+
sourceNode['bpmn:outgoing'] = [sourceNode['bpmn:outgoing'], edge.id];
|
|
182
209
|
}
|
|
183
210
|
});
|
|
184
211
|
bpmnProcessData[BpmnElements.FLOW] = sequenceFlow;
|
|
@@ -192,7 +219,10 @@ function convertLf2DiagramData(bpmnDiagramData, data) {
|
|
|
192
219
|
var edgeId = edge.id;
|
|
193
220
|
var pointsList = edge.pointsList.map(function (_a) {
|
|
194
221
|
var x = _a.x, y = _a.y;
|
|
195
|
-
return ({
|
|
222
|
+
return ({
|
|
223
|
+
'-x': x,
|
|
224
|
+
'-y': y,
|
|
225
|
+
});
|
|
196
226
|
});
|
|
197
227
|
var diagramData = {
|
|
198
228
|
'-id': edgeId + "_di",
|
|
@@ -278,7 +308,8 @@ function convertBpmn2LfData(bpmnData) {
|
|
|
278
308
|
}
|
|
279
309
|
function getLfNodes(value, shapes, key) {
|
|
280
310
|
var nodes = [];
|
|
281
|
-
if (Array.isArray(value)) {
|
|
311
|
+
if (Array.isArray(value)) {
|
|
312
|
+
// 数组
|
|
282
313
|
value.forEach(function (val) {
|
|
283
314
|
var shapeValue;
|
|
284
315
|
if (Array.isArray(shapes)) {
|
|
@@ -334,7 +365,8 @@ function getNodeConfig(shapeValue, type, processValue) {
|
|
|
334
365
|
value: name,
|
|
335
366
|
};
|
|
336
367
|
// 自定义文本位置
|
|
337
|
-
if (shapeValue['bpmndi:BPMNLabel']
|
|
368
|
+
if (shapeValue['bpmndi:BPMNLabel']
|
|
369
|
+
&& shapeValue['bpmndi:BPMNLabel']['dc:Bounds']) {
|
|
338
370
|
var textBounds = shapeValue['bpmndi:BPMNLabel']['dc:Bounds'];
|
|
339
371
|
text.x = Number(textBounds['-x']) + Number(textBounds['-width']) / 2;
|
|
340
372
|
text.y = Number(textBounds['-y']) + Number(textBounds['-height']) / 2;
|
|
@@ -429,9 +461,14 @@ var BpmnAdapter = /** @class */ (function () {
|
|
|
429
461
|
function BpmnAdapter(_a) {
|
|
430
462
|
var _this = this;
|
|
431
463
|
var lf = _a.lf;
|
|
432
|
-
|
|
464
|
+
/**
|
|
465
|
+
* @param retainedFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
|
|
466
|
+
* ["properties", "startPoint", "endPoint", "pointsList"]合并,
|
|
467
|
+
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
|
|
468
|
+
*/
|
|
469
|
+
this.adapterOut = function (data, retainedFields) {
|
|
433
470
|
var bpmnProcessData = __assign({}, _this.processAttributes);
|
|
434
|
-
convertLf2ProcessData(bpmnProcessData, data);
|
|
471
|
+
convertLf2ProcessData(bpmnProcessData, data, retainedFields);
|
|
435
472
|
var bpmnDiagramData = {
|
|
436
473
|
'-id': 'BPMNPlane_1',
|
|
437
474
|
'-bpmnElement': bpmnProcessData['-id'],
|
|
@@ -454,7 +491,7 @@ var BpmnAdapter = /** @class */ (function () {
|
|
|
454
491
|
}
|
|
455
492
|
};
|
|
456
493
|
lf.adapterIn = function (data) { return _this.adapterIn(data); };
|
|
457
|
-
lf.adapterOut = function (data) { return _this.adapterOut(data); };
|
|
494
|
+
lf.adapterOut = function (data, retainedFields) { return _this.adapterOut(data, retainedFields); };
|
|
458
495
|
this.processAttributes = {
|
|
459
496
|
'-isExecutable': 'true',
|
|
460
497
|
'-id': "Process_" + getBpmnId(),
|
|
@@ -506,8 +543,8 @@ var BpmnXmlAdapter = /** @class */ (function (_super) {
|
|
|
506
543
|
var json = lfXml2Json(bpmnData);
|
|
507
544
|
return _this.adapterIn(json);
|
|
508
545
|
};
|
|
509
|
-
_this.adapterXmlOut = function (data) {
|
|
510
|
-
var outData = _this.adapterOut(data);
|
|
546
|
+
_this.adapterXmlOut = function (data, retainedFields) {
|
|
547
|
+
var outData = _this.adapterOut(data, retainedFields);
|
|
511
548
|
return lfJson2Xml(outData);
|
|
512
549
|
};
|
|
513
550
|
var lf = data.lf;
|
|
@@ -518,5 +555,5 @@ var BpmnXmlAdapter = /** @class */ (function (_super) {
|
|
|
518
555
|
BpmnXmlAdapter.pluginName = 'bpmnXmlAdapter';
|
|
519
556
|
return BpmnXmlAdapter;
|
|
520
557
|
}(BpmnAdapter));
|
|
521
|
-
export { BpmnAdapter, BpmnXmlAdapter, };
|
|
558
|
+
export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
|
|
522
559
|
export default BpmnAdapter;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
declare function
|
|
2
|
-
|
|
1
|
+
declare function handleAttributes(o: any): any;
|
|
2
|
+
declare function lfJson2Xml(o: Object): string;
|
|
3
|
+
export { lfJson2Xml, handleAttributes };
|
|
@@ -1,59 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* License:
|
|
4
|
-
* Version: 0.9
|
|
5
|
-
* Author: Stefan Goessner/2006
|
|
6
|
-
* Web: http://goessner.net/
|
|
7
|
-
*/
|
|
8
|
-
function addIndSpace(ind, deep) {
|
|
9
|
-
for (var i = 0; i < deep; i++) {
|
|
10
|
-
ind += ' ';
|
|
11
|
-
}
|
|
12
|
-
return ind;
|
|
1
|
+
function type(obj) {
|
|
2
|
+
return Object.prototype.toString.call(obj);
|
|
13
3
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
function addSpace(depth) {
|
|
5
|
+
return " ".repeat(depth);
|
|
6
|
+
}
|
|
7
|
+
function handleAttributes(o) {
|
|
8
|
+
var t = o;
|
|
9
|
+
if (type(o) === "[object Object]") {
|
|
10
|
+
t = {};
|
|
11
|
+
Object.keys(o).forEach(function (k) {
|
|
12
|
+
var tk = k;
|
|
13
|
+
if (k.charAt(0) === "-") {
|
|
14
|
+
tk = k.substring(1);
|
|
15
|
+
}
|
|
16
|
+
t[tk] = handleAttributes(o[k]);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(o)) {
|
|
20
|
+
t = [];
|
|
21
|
+
o.forEach(function (item, index) {
|
|
22
|
+
t[index] = handleAttributes(item);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
;
|
|
28
|
+
function getAttributes(obj) {
|
|
29
|
+
var tmp = obj;
|
|
30
|
+
try {
|
|
31
|
+
if (typeof tmp !== "string") {
|
|
32
|
+
tmp = JSON.parse(obj);
|
|
19
33
|
}
|
|
20
34
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
catch (error) {
|
|
36
|
+
tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'");
|
|
37
|
+
}
|
|
38
|
+
return tmp;
|
|
39
|
+
}
|
|
40
|
+
var tn = "\t\n";
|
|
41
|
+
// @see issue https://github.com/didi/LogicFlow/issues/718, refactoring of function toXml
|
|
42
|
+
function toXml(obj, name, depth) {
|
|
43
|
+
var frontSpace = addSpace(depth);
|
|
44
|
+
var str = "";
|
|
45
|
+
if (name === "#text") {
|
|
46
|
+
return tn + frontSpace + obj;
|
|
47
|
+
}
|
|
48
|
+
else if (name === "#cdata-section") {
|
|
49
|
+
return tn + frontSpace + "<![CDATA[" + obj + "]]>";
|
|
50
|
+
}
|
|
51
|
+
else if (name === "#comment") {
|
|
52
|
+
return tn + frontSpace + "<!--" + obj + "-->";
|
|
53
|
+
}
|
|
54
|
+
if (("" + name).charAt(0) === "-") {
|
|
55
|
+
return " " + name.substring(1) + '="' + getAttributes(obj) + '"';
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (Array.isArray(obj)) {
|
|
59
|
+
obj.forEach(function (item) {
|
|
60
|
+
str += toXml(item, name, depth + 1);
|
|
61
|
+
});
|
|
29
62
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
63
|
+
else if (type(obj) === "[object Object]") {
|
|
64
|
+
var keys = Object.keys(obj);
|
|
65
|
+
var attributes_1 = "";
|
|
66
|
+
var children_1 = "";
|
|
67
|
+
str += (depth === 0 ? "" : tn + frontSpace) + "<" + name;
|
|
68
|
+
keys.forEach(function (k) {
|
|
69
|
+
k.charAt(0) === "-"
|
|
70
|
+
? (attributes_1 += toXml(obj[k], k, depth + 1))
|
|
71
|
+
: (children_1 += toXml(obj[k], k, depth + 1));
|
|
72
|
+
});
|
|
73
|
+
str +=
|
|
74
|
+
attributes_1 +
|
|
75
|
+
(children_1 !== "" ? ">" + children_1 + (tn + frontSpace) + "</" + name + ">" : " />");
|
|
41
76
|
}
|
|
42
77
|
else {
|
|
43
|
-
|
|
78
|
+
str += tn + frontSpace + ("<" + name + ">" + obj.toString() + "</" + name + ">");
|
|
44
79
|
}
|
|
45
80
|
}
|
|
46
|
-
|
|
47
|
-
xml += addIndSpace(ind, deep) + "<" + name + ">" + v.toString() + "</" + name + ">";
|
|
48
|
-
}
|
|
49
|
-
return xml;
|
|
81
|
+
return str;
|
|
50
82
|
}
|
|
51
|
-
;
|
|
52
83
|
function lfJson2Xml(o) {
|
|
53
|
-
var xmlStr = "";
|
|
84
|
+
var xmlStr = "<LogicFlow>\t\n";
|
|
54
85
|
for (var m in o) {
|
|
55
|
-
xmlStr += toXml(o[m], m,
|
|
86
|
+
xmlStr += toXml(o[m], m, 0);
|
|
56
87
|
}
|
|
57
|
-
return xmlStr;
|
|
88
|
+
return xmlStr + "\t\n</LogicFlow>";
|
|
58
89
|
}
|
|
59
|
-
export { lfJson2Xml };
|
|
90
|
+
export { lfJson2Xml, handleAttributes };
|
|
@@ -103,35 +103,43 @@ XML.ObjTree.prototype.parseDOM = function (root) {
|
|
|
103
103
|
tmp[root.nodeName] = json; // root nodeName
|
|
104
104
|
json = tmp;
|
|
105
105
|
}
|
|
106
|
-
return json;
|
|
106
|
+
return json["LogicFlow"];
|
|
107
107
|
};
|
|
108
108
|
// method: parseElement( element )
|
|
109
|
+
/**
|
|
110
|
+
* @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
111
|
+
*/
|
|
109
112
|
XML.ObjTree.prototype.parseElement = function (elem) {
|
|
110
|
-
//
|
|
113
|
+
// PROCESSING_INSTRUCTION_NODE
|
|
111
114
|
if (elem.nodeType == 7) {
|
|
112
115
|
return;
|
|
113
116
|
}
|
|
114
|
-
// TEXT_NODE CDATA_SECTION_NODE
|
|
115
|
-
if (elem.nodeType == 3 || elem.nodeType == 4) {
|
|
117
|
+
// TEXT_NODE CDATA_SECTION_NODE COMMENT_NODE
|
|
118
|
+
if (elem.nodeType == 3 || elem.nodeType == 4 || elem.nodeType == 8) {
|
|
116
119
|
var bool = elem.nodeValue.match(/[^\x00-\x20]/);
|
|
117
120
|
if (bool == null)
|
|
118
121
|
return; // ignore white spaces
|
|
119
122
|
return elem.nodeValue;
|
|
120
123
|
}
|
|
121
|
-
var retVal;
|
|
124
|
+
var retVal = null;
|
|
122
125
|
var cnt = {};
|
|
123
|
-
// parse attributes
|
|
124
126
|
if (elem.attributes && elem.attributes.length) {
|
|
125
127
|
retVal = {};
|
|
126
128
|
for (var i = 0; i < elem.attributes.length; i++) {
|
|
127
129
|
var key = elem.attributes[i].nodeName;
|
|
128
|
-
if (typeof
|
|
130
|
+
if (typeof key != "string")
|
|
129
131
|
continue;
|
|
130
132
|
var val = elem.attributes[i].nodeValue;
|
|
133
|
+
try {
|
|
134
|
+
val = JSON.parse(elem.attributes[i].nodeValue.replace(/'/g, '"'));
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
val = elem.attributes[i].nodeValue;
|
|
138
|
+
}
|
|
131
139
|
if (!val)
|
|
132
140
|
continue;
|
|
133
141
|
key = this.attr_prefix + key;
|
|
134
|
-
if (typeof
|
|
142
|
+
if (typeof cnt[key] == "undefined")
|
|
135
143
|
cnt[key] = 0;
|
|
136
144
|
cnt[key]++;
|
|
137
145
|
this.addNode(retVal, key, cnt[key], val);
|
|
@@ -144,7 +152,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
144
152
|
textOnly = false; // some attributes exists
|
|
145
153
|
for (var i = 0; i < elem.childNodes.length && textOnly; i++) {
|
|
146
154
|
var nType = elem.childNodes[i].nodeType;
|
|
147
|
-
if (nType == 3 || nType == 4)
|
|
155
|
+
if (nType == 3 || nType == 4 || nType == 8)
|
|
148
156
|
continue;
|
|
149
157
|
textOnly = false;
|
|
150
158
|
}
|
|
@@ -172,6 +180,12 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
172
180
|
}
|
|
173
181
|
}
|
|
174
182
|
}
|
|
183
|
+
else {
|
|
184
|
+
// @see issue https://github.com/didi/LogicFlow/issues/1068
|
|
185
|
+
// if retVal is null, that means the elem doesn't have any attributes and children,
|
|
186
|
+
// the elem would be like: <a /> or <a></a>, so set retVal to empty object {}
|
|
187
|
+
retVal === null && (retVal = {});
|
|
188
|
+
}
|
|
175
189
|
return retVal;
|
|
176
190
|
};
|
|
177
191
|
// method: addNode( hash, key, count, value )
|
|
@@ -9,6 +9,19 @@ declare class InsertNodeInPolyline {
|
|
|
9
9
|
lf: any;
|
|
10
10
|
});
|
|
11
11
|
eventHandler(): void;
|
|
12
|
+
/**
|
|
13
|
+
* 插入节点前校验规则
|
|
14
|
+
* @param sourceNodeId
|
|
15
|
+
* @param targetNodeId
|
|
16
|
+
* @param sourceAnchorId
|
|
17
|
+
* @param targetAnchorId
|
|
18
|
+
* @param nodeData
|
|
19
|
+
*/
|
|
20
|
+
checkRuleBeforeInsetNode(sourceNodeId: any, targetNodeId: any, sourceAnchorId: any, targetAnchorId: any, nodeData: any): {
|
|
21
|
+
isPass: any;
|
|
22
|
+
sourceMsg: any;
|
|
23
|
+
targetMsg: any;
|
|
24
|
+
};
|
|
12
25
|
insetNode(nodeData: any): void;
|
|
13
26
|
}
|
|
14
27
|
export { InsertNodeInPolyline };
|
|
@@ -18,6 +18,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
18
18
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
19
19
|
return ar;
|
|
20
20
|
};
|
|
21
|
+
import { EventType, formateAnchorConnectValidateData } from '@logicflow/core';
|
|
21
22
|
import { cloneDeep } from 'lodash-es';
|
|
22
23
|
import { isNodeInSegment } from './edge';
|
|
23
24
|
var InsertNodeInPolyline = /** @class */ (function () {
|
|
@@ -58,24 +59,53 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* 插入节点前校验规则
|
|
64
|
+
* @param sourceNodeId
|
|
65
|
+
* @param targetNodeId
|
|
66
|
+
* @param sourceAnchorId
|
|
67
|
+
* @param targetAnchorId
|
|
68
|
+
* @param nodeData
|
|
69
|
+
*/
|
|
70
|
+
// fix: https://github.com/didi/LogicFlow/issues/1078
|
|
71
|
+
InsertNodeInPolyline.prototype.checkRuleBeforeInsetNode = function (sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData) {
|
|
72
|
+
var sourceNodeModel = this._lf.getNodeModelById(sourceNodeId);
|
|
73
|
+
var targetNodeModel = this._lf.getNodeModelById(targetNodeId);
|
|
74
|
+
var sourceAnchorInfo = sourceNodeModel.getAnchorInfo(sourceAnchorId);
|
|
75
|
+
var targetAnchorInfo = targetNodeModel.getAnchorInfo(targetAnchorId);
|
|
76
|
+
var sourceRuleResultData = sourceNodeModel.isAllowConnectedAsSource(nodeData, sourceAnchorInfo, targetAnchorInfo);
|
|
77
|
+
var targetRuleResultData = targetNodeModel.isAllowConnectedAsTarget(nodeData, sourceAnchorInfo, targetAnchorInfo);
|
|
78
|
+
var _a = formateAnchorConnectValidateData(sourceRuleResultData), isSourcePass = _a.isAllPass, sourceMsg = _a.msg;
|
|
79
|
+
var _b = formateAnchorConnectValidateData(targetRuleResultData), isTargetPass = _b.isAllPass, targetMsg = _b.msg;
|
|
80
|
+
return {
|
|
81
|
+
isPass: isSourcePass && isTargetPass,
|
|
82
|
+
sourceMsg: sourceMsg,
|
|
83
|
+
targetMsg: targetMsg,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
61
86
|
InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
|
|
87
|
+
var _this = this;
|
|
62
88
|
var edges = this._lf.graphModel.edges;
|
|
63
89
|
var nodeModel = this._lf.getNodeModelById(nodeData.id);
|
|
64
90
|
for (var i = 0; i < edges.length; i++) {
|
|
65
91
|
// eslint-disable-next-line max-len
|
|
66
92
|
var _a = isNodeInSegment(nodeModel, edges[i], this.deviation), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
|
|
67
93
|
if (crossIndex >= 0) {
|
|
68
|
-
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
|
|
94
|
+
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList, sourceAnchorId = _b.sourceAnchorId, targetAnchorId = _b.targetAnchorId;
|
|
69
95
|
// fix https://github.com/didi/LogicFlow/issues/996
|
|
70
96
|
var startPoint = cloneDeep(pointsList[0]);
|
|
71
97
|
var endPoint = cloneDeep(crossPoints.startCrossPoint);
|
|
98
|
+
this._lf.deleteEdge(id);
|
|
99
|
+
var checkResult = this.checkRuleBeforeInsetNode(sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData);
|
|
72
100
|
this._lf.addEdge({
|
|
73
101
|
type: type,
|
|
74
102
|
sourceNodeId: sourceNodeId,
|
|
75
103
|
targetNodeId: nodeData.id,
|
|
76
104
|
startPoint: startPoint,
|
|
77
105
|
endPoint: endPoint,
|
|
78
|
-
pointsList: __spread(pointsList.slice(0, crossIndex), [
|
|
106
|
+
pointsList: __spread(pointsList.slice(0, crossIndex), [
|
|
107
|
+
crossPoints.startCrossPoint,
|
|
108
|
+
]),
|
|
79
109
|
});
|
|
80
110
|
this._lf.addEdge({
|
|
81
111
|
type: type,
|
|
@@ -83,10 +113,24 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
83
113
|
targetNodeId: targetNodeId,
|
|
84
114
|
startPoint: cloneDeep(crossPoints.endCrossPoint),
|
|
85
115
|
endPoint: cloneDeep(pointsList[pointsList.length - 1]),
|
|
86
|
-
pointsList: __spread([
|
|
116
|
+
pointsList: __spread([
|
|
117
|
+
crossPoints.endCrossPoint
|
|
118
|
+
], pointsList.slice(crossIndex)),
|
|
87
119
|
});
|
|
88
|
-
|
|
89
|
-
|
|
120
|
+
if (!checkResult.isPass) {
|
|
121
|
+
this._lf.graphModel.eventCenter.emit(EventType.CONNECTION_NOT_ALLOWED, {
|
|
122
|
+
data: nodeData,
|
|
123
|
+
msg: checkResult.targetMsg || checkResult.sourceMsg,
|
|
124
|
+
});
|
|
125
|
+
// FIXME:在关闭了历史记录的情况下,撤销操作会不生效。
|
|
126
|
+
setTimeout(function () {
|
|
127
|
+
_this._lf.undo();
|
|
128
|
+
}, 200);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
90
134
|
}
|
|
91
135
|
}
|
|
92
136
|
};
|