@logicflow/extension 1.2.4 → 1.2.5
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 +78 -44
- package/cjs/bpmn-adapter/json2xml.js +78 -46
- package/cjs/bpmn-adapter/xml2json.js +23 -9
- package/cjs/insert-node-in-polyline/index.js +61 -22
- package/es/bpmn-adapter/index.d.ts +6 -1
- package/es/bpmn-adapter/index.js +77 -45
- 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 +61 -22
- 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 +6 -1
- package/types/bpmn-adapter/json2xml.d.ts +3 -2
- package/types/insert-node-in-polyline/index.d.ts +13 -0
|
@@ -40,7 +40,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
40
40
|
return ar;
|
|
41
41
|
};
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.BpmnXmlAdapter = exports.BpmnAdapter = void 0;
|
|
43
|
+
exports.toNormalJson = exports.toXmlJson = exports.BpmnXmlAdapter = exports.BpmnAdapter = void 0;
|
|
44
44
|
var bpmnIds_1 = require("./bpmnIds");
|
|
45
45
|
var json2xml_1 = require("./json2xml");
|
|
46
46
|
var xml2json_1 = require("./xml2json");
|
|
@@ -54,30 +54,62 @@ var BpmnElements;
|
|
|
54
54
|
BpmnElements["SYSTEM"] = "bpmn:serviceTask";
|
|
55
55
|
BpmnElements["FLOW"] = "bpmn:sequenceFlow";
|
|
56
56
|
})(BpmnElements || (BpmnElements = {}));
|
|
57
|
-
var defaultAttrs = [
|
|
57
|
+
var defaultAttrs = [
|
|
58
|
+
'-name',
|
|
59
|
+
'-id',
|
|
60
|
+
'bpmn:incoming',
|
|
61
|
+
'bpmn:outgoing',
|
|
62
|
+
'-sourceRef',
|
|
63
|
+
'-targetRef',
|
|
64
|
+
];
|
|
58
65
|
/**
|
|
59
66
|
* 将普通json转换为xmlJson
|
|
60
67
|
* xmlJson中property会以“-”开头
|
|
61
68
|
* 如果没有“-”表示为子节点
|
|
69
|
+
* fix issue https://github.com/didi/LogicFlow/issues/718, contain the process of #text/#cdata and array
|
|
70
|
+
* @param retainedFields retainedField会和默认的defaultRetainedFields:
|
|
71
|
+
* ["properties", "startPoint", "endPoint", "pointsList"]合并
|
|
72
|
+
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性
|
|
73
|
+
* @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
62
74
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
var defaultRetainedFields = ['properties', 'startPoint', 'endPoint', 'pointsList'];
|
|
76
|
+
function toXmlJson(retainedFields) {
|
|
77
|
+
var fields = retainedFields
|
|
78
|
+
? defaultRetainedFields.concat(retainedFields) : defaultRetainedFields;
|
|
79
|
+
return function (json) {
|
|
80
|
+
function ToXmlJson(obj) {
|
|
81
|
+
var xmlJson = {};
|
|
82
|
+
if (typeof obj === 'string') {
|
|
83
|
+
return obj;
|
|
70
84
|
}
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
if (Array.isArray(obj)) {
|
|
86
|
+
return obj.map(function (j) { return ToXmlJson(j); });
|
|
73
87
|
}
|
|
88
|
+
Object.entries(obj).forEach(function (_a) {
|
|
89
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
90
|
+
if (typeof value !== 'object') {
|
|
91
|
+
// node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
92
|
+
if (key.indexOf('-') === 0
|
|
93
|
+
|| ['#text', '#cdata-section', '#comment'].includes(key)) {
|
|
94
|
+
xmlJson[key] = value;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
xmlJson["-" + key] = value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (fields.includes(key)) {
|
|
101
|
+
xmlJson["-" + key] = ToXmlJson(value);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
xmlJson[key] = ToXmlJson(value);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return xmlJson;
|
|
74
108
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return xmlJson;
|
|
109
|
+
return ToXmlJson(json);
|
|
110
|
+
};
|
|
80
111
|
}
|
|
112
|
+
exports.toXmlJson = toXmlJson;
|
|
81
113
|
/**
|
|
82
114
|
* 将xmlJson转换为普通的json,在内部使用。
|
|
83
115
|
*/
|
|
@@ -85,23 +117,26 @@ function toNormalJson(xmlJson) {
|
|
|
85
117
|
var json = {};
|
|
86
118
|
Object.entries(xmlJson).forEach(function (_a) {
|
|
87
119
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
json[key.substr(1)] = value;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
json[key] = value;
|
|
94
|
-
}
|
|
120
|
+
if (key.indexOf('-') === 0) {
|
|
121
|
+
json[key.substring(1)] = json2xml_1.handleAttributes(value);
|
|
95
122
|
}
|
|
96
|
-
else if (typeof value === '
|
|
123
|
+
else if (typeof value === 'string') {
|
|
124
|
+
json[key] = value;
|
|
125
|
+
}
|
|
126
|
+
else if (Object.prototype.toString.call(value) === '[object Object]') {
|
|
97
127
|
json[key] = toNormalJson(value);
|
|
98
128
|
}
|
|
129
|
+
else if (Array.isArray(value)) {
|
|
130
|
+
// contain the process of array
|
|
131
|
+
json[key] = value.map(function (v) { return toNormalJson(v); });
|
|
132
|
+
}
|
|
99
133
|
else {
|
|
100
134
|
json[key] = value;
|
|
101
135
|
}
|
|
102
136
|
});
|
|
103
137
|
return json;
|
|
104
138
|
}
|
|
139
|
+
exports.toNormalJson = toNormalJson;
|
|
105
140
|
/**
|
|
106
141
|
* 设置bpmn process信息
|
|
107
142
|
* 目标格式请参考examples/bpmn.json
|
|
@@ -121,21 +156,20 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
121
156
|
processNode['-name'] = node.text.value;
|
|
122
157
|
}
|
|
123
158
|
if (node.properties) {
|
|
124
|
-
var properties = toXmlJson(node.properties);
|
|
159
|
+
var properties = toXmlJson()(node.properties);
|
|
125
160
|
Object.assign(processNode, properties);
|
|
126
161
|
}
|
|
127
162
|
nodeMap.set(node.id, processNode);
|
|
128
163
|
if (!bpmnProcessData[node.type]) {
|
|
129
164
|
bpmnProcessData[node.type] = processNode; // 如果只有一个子元素,json中表示为正常属性
|
|
130
165
|
}
|
|
131
|
-
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
166
|
+
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
167
|
+
// 如果是多个子元素,json中使用数组存储
|
|
132
168
|
bpmnProcessData[node.type].push(processNode);
|
|
133
169
|
}
|
|
134
|
-
else {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
processNode,
|
|
138
|
-
];
|
|
170
|
+
else {
|
|
171
|
+
// 如果是多个子元素,json中使用数组存储
|
|
172
|
+
bpmnProcessData[node.type] = [bpmnProcessData[node.type], processNode];
|
|
139
173
|
}
|
|
140
174
|
});
|
|
141
175
|
var sequenceFlow = data.edges.map(function (edge) {
|
|
@@ -148,10 +182,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
148
182
|
targetNode['bpmn:incoming'].push(edge.id);
|
|
149
183
|
}
|
|
150
184
|
else {
|
|
151
|
-
targetNode['bpmn:incoming'] = [
|
|
152
|
-
targetNode['bpmn:incoming'],
|
|
153
|
-
edge.id,
|
|
154
|
-
];
|
|
185
|
+
targetNode['bpmn:incoming'] = [targetNode['bpmn:incoming'], edge.id];
|
|
155
186
|
}
|
|
156
187
|
var edgeConfig = {
|
|
157
188
|
'-id': edge.id,
|
|
@@ -162,7 +193,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
162
193
|
edgeConfig['-name'] = (_b = edge.text) === null || _b === void 0 ? void 0 : _b.value;
|
|
163
194
|
}
|
|
164
195
|
if (edge.properties) {
|
|
165
|
-
var properties = toXmlJson(edge.properties);
|
|
196
|
+
var properties = toXmlJson()(edge.properties);
|
|
166
197
|
Object.assign(edgeConfig, properties);
|
|
167
198
|
}
|
|
168
199
|
return edgeConfig;
|
|
@@ -177,11 +208,9 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
177
208
|
else if (Array.isArray(sourceNode['bpmn:outgoing'])) {
|
|
178
209
|
sourceNode['bpmn:outgoing'].push(edge.id);
|
|
179
210
|
}
|
|
180
|
-
else {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
edge.id,
|
|
184
|
-
];
|
|
211
|
+
else {
|
|
212
|
+
// 字符串转数组
|
|
213
|
+
sourceNode['bpmn:outgoing'] = [sourceNode['bpmn:outgoing'], edge.id];
|
|
185
214
|
}
|
|
186
215
|
});
|
|
187
216
|
bpmnProcessData[BpmnElements.FLOW] = sequenceFlow;
|
|
@@ -195,7 +224,10 @@ function convertLf2DiagramData(bpmnDiagramData, data) {
|
|
|
195
224
|
var edgeId = edge.id;
|
|
196
225
|
var pointsList = edge.pointsList.map(function (_a) {
|
|
197
226
|
var x = _a.x, y = _a.y;
|
|
198
|
-
return ({
|
|
227
|
+
return ({
|
|
228
|
+
'-x': x,
|
|
229
|
+
'-y': y,
|
|
230
|
+
});
|
|
199
231
|
});
|
|
200
232
|
var diagramData = {
|
|
201
233
|
'-id': edgeId + "_di",
|
|
@@ -281,7 +313,8 @@ function convertBpmn2LfData(bpmnData) {
|
|
|
281
313
|
}
|
|
282
314
|
function getLfNodes(value, shapes, key) {
|
|
283
315
|
var nodes = [];
|
|
284
|
-
if (Array.isArray(value)) {
|
|
316
|
+
if (Array.isArray(value)) {
|
|
317
|
+
// 数组
|
|
285
318
|
value.forEach(function (val) {
|
|
286
319
|
var shapeValue;
|
|
287
320
|
if (Array.isArray(shapes)) {
|
|
@@ -337,7 +370,8 @@ function getNodeConfig(shapeValue, type, processValue) {
|
|
|
337
370
|
value: name,
|
|
338
371
|
};
|
|
339
372
|
// 自定义文本位置
|
|
340
|
-
if (shapeValue['bpmndi:BPMNLabel']
|
|
373
|
+
if (shapeValue['bpmndi:BPMNLabel']
|
|
374
|
+
&& shapeValue['bpmndi:BPMNLabel']['dc:Bounds']) {
|
|
341
375
|
var textBounds = shapeValue['bpmndi:BPMNLabel']['dc:Bounds'];
|
|
342
376
|
text.x = Number(textBounds['-x']) + Number(textBounds['-width']) / 2;
|
|
343
377
|
text.y = Number(textBounds['-y']) + Number(textBounds['-height']) / 2;
|
|
@@ -1,62 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lfJson2Xml = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* License:
|
|
7
|
-
* Version: 0.9
|
|
8
|
-
* Author: Stefan Goessner/2006
|
|
9
|
-
* Web: http://goessner.net/
|
|
10
|
-
*/
|
|
11
|
-
function addIndSpace(ind, deep) {
|
|
12
|
-
for (var i = 0; i < deep; i++) {
|
|
13
|
-
ind += ' ';
|
|
14
|
-
}
|
|
15
|
-
return ind;
|
|
3
|
+
exports.handleAttributes = exports.lfJson2Xml = void 0;
|
|
4
|
+
function type(obj) {
|
|
5
|
+
return Object.prototype.toString.call(obj);
|
|
16
6
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
function addSpace(depth) {
|
|
8
|
+
return " ".repeat(depth);
|
|
9
|
+
}
|
|
10
|
+
function handleAttributes(o) {
|
|
11
|
+
var t = o;
|
|
12
|
+
if (type(o) === "[object Object]") {
|
|
13
|
+
t = {};
|
|
14
|
+
Object.keys(o).forEach(function (k) {
|
|
15
|
+
var tk = k;
|
|
16
|
+
if (k.charAt(0) === "-") {
|
|
17
|
+
tk = k.substring(1);
|
|
18
|
+
}
|
|
19
|
+
t[tk] = handleAttributes(o[k]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else if (Array.isArray(o)) {
|
|
23
|
+
t = [];
|
|
24
|
+
o.forEach(function (item, index) {
|
|
25
|
+
t[index] = handleAttributes(item);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
exports.handleAttributes = handleAttributes;
|
|
31
|
+
;
|
|
32
|
+
function getAttributes(obj) {
|
|
33
|
+
var tmp = obj;
|
|
34
|
+
try {
|
|
35
|
+
if (typeof tmp !== "string") {
|
|
36
|
+
tmp = JSON.parse(obj);
|
|
22
37
|
}
|
|
23
38
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
catch (error) {
|
|
40
|
+
tmp = JSON.stringify(handleAttributes(obj)).replace(/"/g, "'");
|
|
41
|
+
}
|
|
42
|
+
return tmp;
|
|
43
|
+
}
|
|
44
|
+
var tn = "\t\n";
|
|
45
|
+
// @see issue https://github.com/didi/LogicFlow/issues/718, refactoring of function toXml
|
|
46
|
+
function toXml(obj, name, depth) {
|
|
47
|
+
var frontSpace = addSpace(depth);
|
|
48
|
+
var str = "";
|
|
49
|
+
if (name === "#text") {
|
|
50
|
+
return tn + frontSpace + obj;
|
|
51
|
+
}
|
|
52
|
+
else if (name === "#cdata-section") {
|
|
53
|
+
return tn + frontSpace + "<![CDATA[" + obj + "]]>";
|
|
54
|
+
}
|
|
55
|
+
else if (name === "#comment") {
|
|
56
|
+
return tn + frontSpace + "<!--" + obj + "-->";
|
|
57
|
+
}
|
|
58
|
+
if (("" + name).charAt(0) === "-") {
|
|
59
|
+
return " " + name.substring(1) + '="' + getAttributes(obj) + '"';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (Array.isArray(obj)) {
|
|
63
|
+
obj.forEach(function (item) {
|
|
64
|
+
str += toXml(item, name, depth + 1);
|
|
65
|
+
});
|
|
32
66
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
67
|
+
else if (type(obj) === "[object Object]") {
|
|
68
|
+
var keys = Object.keys(obj);
|
|
69
|
+
var attributes_1 = "";
|
|
70
|
+
var children_1 = "";
|
|
71
|
+
str += (depth === 0 ? "" : tn + frontSpace) + "<" + name;
|
|
72
|
+
keys.forEach(function (k) {
|
|
73
|
+
k.charAt(0) === "-"
|
|
74
|
+
? (attributes_1 += toXml(obj[k], k, depth + 1))
|
|
75
|
+
: (children_1 += toXml(obj[k], k, depth + 1));
|
|
76
|
+
});
|
|
77
|
+
str +=
|
|
78
|
+
attributes_1 +
|
|
79
|
+
(children_1 !== "" ? ">" + children_1 + (tn + frontSpace) + "</" + name + ">" : " />");
|
|
44
80
|
}
|
|
45
81
|
else {
|
|
46
|
-
|
|
82
|
+
str += tn + frontSpace + ("<$" + name + ">" + obj.toString() + "</" + name + ">");
|
|
47
83
|
}
|
|
48
84
|
}
|
|
49
|
-
|
|
50
|
-
xml += addIndSpace(ind, deep) + "<" + name + ">" + v.toString() + "</" + name + ">";
|
|
51
|
-
}
|
|
52
|
-
return xml;
|
|
85
|
+
return str;
|
|
53
86
|
}
|
|
54
|
-
;
|
|
55
87
|
function lfJson2Xml(o) {
|
|
56
|
-
var xmlStr = "";
|
|
88
|
+
var xmlStr = "<LogicFlow>\t\n";
|
|
57
89
|
for (var m in o) {
|
|
58
|
-
xmlStr += toXml(o[m], m,
|
|
90
|
+
xmlStr += toXml(o[m], m, 0);
|
|
59
91
|
}
|
|
60
|
-
return xmlStr;
|
|
92
|
+
return xmlStr + "\t\n</LogicFlow>";
|
|
61
93
|
}
|
|
62
94
|
exports.lfJson2Xml = lfJson2Xml;
|
|
@@ -106,35 +106,43 @@ XML.ObjTree.prototype.parseDOM = function (root) {
|
|
|
106
106
|
tmp[root.nodeName] = json; // root nodeName
|
|
107
107
|
json = tmp;
|
|
108
108
|
}
|
|
109
|
-
return json;
|
|
109
|
+
return json["LogicFlow"];
|
|
110
110
|
};
|
|
111
111
|
// method: parseElement( element )
|
|
112
|
+
/**
|
|
113
|
+
* @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
114
|
+
*/
|
|
112
115
|
XML.ObjTree.prototype.parseElement = function (elem) {
|
|
113
|
-
//
|
|
116
|
+
// PROCESSING_INSTRUCTION_NODE
|
|
114
117
|
if (elem.nodeType == 7) {
|
|
115
118
|
return;
|
|
116
119
|
}
|
|
117
|
-
// TEXT_NODE CDATA_SECTION_NODE
|
|
118
|
-
if (elem.nodeType == 3 || elem.nodeType == 4) {
|
|
120
|
+
// TEXT_NODE CDATA_SECTION_NODE COMMENT_NODE
|
|
121
|
+
if (elem.nodeType == 3 || elem.nodeType == 4 || elem.nodeType == 8) {
|
|
119
122
|
var bool = elem.nodeValue.match(/[^\x00-\x20]/);
|
|
120
123
|
if (bool == null)
|
|
121
124
|
return; // ignore white spaces
|
|
122
125
|
return elem.nodeValue;
|
|
123
126
|
}
|
|
124
|
-
var retVal;
|
|
127
|
+
var retVal = null;
|
|
125
128
|
var cnt = {};
|
|
126
|
-
// parse attributes
|
|
127
129
|
if (elem.attributes && elem.attributes.length) {
|
|
128
130
|
retVal = {};
|
|
129
131
|
for (var i = 0; i < elem.attributes.length; i++) {
|
|
130
132
|
var key = elem.attributes[i].nodeName;
|
|
131
|
-
if (typeof
|
|
133
|
+
if (typeof key != "string")
|
|
132
134
|
continue;
|
|
133
135
|
var val = elem.attributes[i].nodeValue;
|
|
136
|
+
try {
|
|
137
|
+
val = JSON.parse(elem.attributes[i].nodeValue.replace(/'/g, '"'));
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
val = elem.attributes[i].nodeValue;
|
|
141
|
+
}
|
|
134
142
|
if (!val)
|
|
135
143
|
continue;
|
|
136
144
|
key = this.attr_prefix + key;
|
|
137
|
-
if (typeof
|
|
145
|
+
if (typeof cnt[key] == "undefined")
|
|
138
146
|
cnt[key] = 0;
|
|
139
147
|
cnt[key]++;
|
|
140
148
|
this.addNode(retVal, key, cnt[key], val);
|
|
@@ -147,7 +155,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
147
155
|
textOnly = false; // some attributes exists
|
|
148
156
|
for (var i = 0; i < elem.childNodes.length && textOnly; i++) {
|
|
149
157
|
var nType = elem.childNodes[i].nodeType;
|
|
150
|
-
if (nType == 3 || nType == 4)
|
|
158
|
+
if (nType == 3 || nType == 4 || nType == 8)
|
|
151
159
|
continue;
|
|
152
160
|
textOnly = false;
|
|
153
161
|
}
|
|
@@ -175,6 +183,12 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
175
183
|
}
|
|
176
184
|
}
|
|
177
185
|
}
|
|
186
|
+
else {
|
|
187
|
+
// @see issue https://github.com/didi/LogicFlow/issues/1068
|
|
188
|
+
// if retVal is null, that means the elem doesn't have any attributes and children,
|
|
189
|
+
// the elem would be like: <a /> or <a></a>, so set retVal to empty object {}
|
|
190
|
+
retVal === null && (retVal = {});
|
|
191
|
+
}
|
|
178
192
|
return retVal;
|
|
179
193
|
};
|
|
180
194
|
// method: addNode( hash, key, count, value )
|
|
@@ -21,6 +21,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.InsertNodeInPolyline = void 0;
|
|
24
|
+
var core_1 = require("@logicflow/core");
|
|
24
25
|
var lodash_es_1 = require("lodash-es");
|
|
25
26
|
var edge_1 = require("./edge");
|
|
26
27
|
var InsertNodeInPolyline = /** @class */ (function () {
|
|
@@ -61,6 +62,30 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* 插入节点前校验规则
|
|
67
|
+
* @param sourceNodeId
|
|
68
|
+
* @param targetNodeId
|
|
69
|
+
* @param sourceAnchorId
|
|
70
|
+
* @param targetAnchorId
|
|
71
|
+
* @param nodeData
|
|
72
|
+
*/
|
|
73
|
+
// fix: https://github.com/didi/LogicFlow/issues/1078
|
|
74
|
+
InsertNodeInPolyline.prototype.checkRuleBeforeInsetNode = function (sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData) {
|
|
75
|
+
var sourceNodeModel = this._lf.getNodeModelById(sourceNodeId);
|
|
76
|
+
var targetNodeModel = this._lf.getNodeModelById(targetNodeId);
|
|
77
|
+
var sourceAnchorInfo = sourceNodeModel.getAnchorInfo(sourceAnchorId);
|
|
78
|
+
var targetAnchorInfo = targetNodeModel.getAnchorInfo(targetAnchorId);
|
|
79
|
+
var sourceRuleResultData = sourceNodeModel.isAllowConnectedAsSource(nodeData, sourceAnchorInfo, targetAnchorInfo);
|
|
80
|
+
var targetRuleResultData = targetNodeModel.isAllowConnectedAsTarget(nodeData, sourceAnchorInfo, targetAnchorInfo);
|
|
81
|
+
var _a = core_1.formateAnchorConnectValidateData(sourceRuleResultData), isSourcePass = _a.isAllPass, sourceMsg = _a.msg;
|
|
82
|
+
var _b = core_1.formateAnchorConnectValidateData(targetRuleResultData), isTargetPass = _b.isAllPass, targetMsg = _b.msg;
|
|
83
|
+
return {
|
|
84
|
+
isPass: isSourcePass && isTargetPass,
|
|
85
|
+
sourceMsg: sourceMsg,
|
|
86
|
+
targetMsg: targetMsg,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
64
89
|
InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
|
|
65
90
|
var edges = this._lf.graphModel.edges;
|
|
66
91
|
var nodeModel = this._lf.getNodeModelById(nodeData.id);
|
|
@@ -68,28 +93,42 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
68
93
|
// eslint-disable-next-line max-len
|
|
69
94
|
var _a = edge_1.isNodeInSegment(nodeModel, edges[i], this.deviation), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
|
|
70
95
|
if (crossIndex >= 0) {
|
|
71
|
-
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
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;
|
|
97
|
+
var checkResult = this.checkRuleBeforeInsetNode(sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData);
|
|
98
|
+
if (checkResult.isPass) {
|
|
99
|
+
// fix https://github.com/didi/LogicFlow/issues/996
|
|
100
|
+
var startPoint = lodash_es_1.cloneDeep(pointsList[0]);
|
|
101
|
+
var endPoint = lodash_es_1.cloneDeep(crossPoints.startCrossPoint);
|
|
102
|
+
this._lf.addEdge({
|
|
103
|
+
type: type,
|
|
104
|
+
sourceNodeId: sourceNodeId,
|
|
105
|
+
targetNodeId: nodeData.id,
|
|
106
|
+
startPoint: startPoint,
|
|
107
|
+
endPoint: endPoint,
|
|
108
|
+
pointsList: __spread(pointsList.slice(0, crossIndex), [
|
|
109
|
+
crossPoints.startCrossPoint,
|
|
110
|
+
]),
|
|
111
|
+
});
|
|
112
|
+
this._lf.addEdge({
|
|
113
|
+
type: type,
|
|
114
|
+
sourceNodeId: nodeData.id,
|
|
115
|
+
targetNodeId: targetNodeId,
|
|
116
|
+
startPoint: lodash_es_1.cloneDeep(crossPoints.endCrossPoint),
|
|
117
|
+
endPoint: lodash_es_1.cloneDeep(pointsList[pointsList.length - 1]),
|
|
118
|
+
pointsList: __spread([
|
|
119
|
+
crossPoints.endCrossPoint
|
|
120
|
+
], pointsList.slice(crossIndex)),
|
|
121
|
+
});
|
|
122
|
+
this._lf.deleteEdge(id);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this._lf.graphModel.eventCenter.emit(core_1.EventType.CONNECTION_NOT_ALLOWED, {
|
|
127
|
+
data: nodeData,
|
|
128
|
+
msg: checkResult.targetMsg || checkResult.sourceMsg,
|
|
129
|
+
});
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
93
132
|
}
|
|
94
133
|
}
|
|
95
134
|
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
declare function toXmlJson(retainedFields?: string[]): (json: string | any[] | Object) => any;
|
|
2
|
+
/**
|
|
3
|
+
* 将xmlJson转换为普通的json,在内部使用。
|
|
4
|
+
*/
|
|
5
|
+
declare function toNormalJson(xmlJson: any): {};
|
|
1
6
|
declare class BpmnAdapter {
|
|
2
7
|
static pluginName: string;
|
|
3
8
|
static shapeConfigMap: Map<any, any>;
|
|
@@ -49,5 +54,5 @@ declare class BpmnXmlAdapter extends BpmnAdapter {
|
|
|
49
54
|
};
|
|
50
55
|
adapterXmlOut: (data: any) => string;
|
|
51
56
|
}
|
|
52
|
-
export { BpmnAdapter, BpmnXmlAdapter, };
|
|
57
|
+
export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
|
|
53
58
|
export default BpmnAdapter;
|