@logicflow/extension 1.2.5 → 1.2.7
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 +13 -8
- package/cjs/bpmn-adapter/json2xml.js +3 -3
- package/cjs/bpmn-adapter/xml2json.js +76 -66
- package/cjs/components/mini-map/index.js +0 -2
- package/cjs/insert-node-in-polyline/index.js +33 -28
- package/cjs/tools/snapshot/index.js +27 -38
- package/es/bpmn-adapter/index.d.ts +7 -2
- package/es/bpmn-adapter/index.js +13 -8
- package/es/bpmn-adapter/json2xml.js +3 -3
- package/es/bpmn-adapter/xml2json.d.ts +1 -1
- package/es/bpmn-adapter/xml2json.js +77 -67
- package/es/components/mini-map/index.js +0 -2
- package/es/insert-node-in-polyline/index.js +33 -28
- package/es/tools/snapshot/index.d.ts +1 -1
- package/es/tools/snapshot/index.js +28 -39
- 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 +2 -2
- package/types/bpmn-adapter/index.d.ts +7 -2
- package/types/bpmn-adapter/xml2json.d.ts +1 -1
- package/types/tools/snapshot/index.d.ts +1 -1
|
@@ -145,7 +145,7 @@ exports.toNormalJson = toNormalJson;
|
|
|
145
145
|
* 2)如果只有一个子元素,json中表示为正常属性
|
|
146
146
|
* 3)如果是多个子元素,json中使用数组存储
|
|
147
147
|
*/
|
|
148
|
-
function convertLf2ProcessData(bpmnProcessData, data) {
|
|
148
|
+
function convertLf2ProcessData(bpmnProcessData, data, retainedFields) {
|
|
149
149
|
var nodeMap = new Map();
|
|
150
150
|
data.nodes.forEach(function (node) {
|
|
151
151
|
var _a;
|
|
@@ -156,7 +156,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
156
156
|
processNode['-name'] = node.text.value;
|
|
157
157
|
}
|
|
158
158
|
if (node.properties) {
|
|
159
|
-
var properties = toXmlJson()(node.properties);
|
|
159
|
+
var properties = toXmlJson(retainedFields)(node.properties);
|
|
160
160
|
Object.assign(processNode, properties);
|
|
161
161
|
}
|
|
162
162
|
nodeMap.set(node.id, processNode);
|
|
@@ -193,7 +193,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
193
193
|
edgeConfig['-name'] = (_b = edge.text) === null || _b === void 0 ? void 0 : _b.value;
|
|
194
194
|
}
|
|
195
195
|
if (edge.properties) {
|
|
196
|
-
var properties = toXmlJson()(edge.properties);
|
|
196
|
+
var properties = toXmlJson(retainedFields)(edge.properties);
|
|
197
197
|
Object.assign(edgeConfig, properties);
|
|
198
198
|
}
|
|
199
199
|
return edgeConfig;
|
|
@@ -466,9 +466,14 @@ var BpmnAdapter = /** @class */ (function () {
|
|
|
466
466
|
function BpmnAdapter(_a) {
|
|
467
467
|
var _this = this;
|
|
468
468
|
var lf = _a.lf;
|
|
469
|
-
|
|
469
|
+
/**
|
|
470
|
+
* @param retainedFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
|
|
471
|
+
* ["properties", "startPoint", "endPoint", "pointsList"]合并,
|
|
472
|
+
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
|
|
473
|
+
*/
|
|
474
|
+
this.adapterOut = function (data, retainedFields) {
|
|
470
475
|
var bpmnProcessData = __assign({}, _this.processAttributes);
|
|
471
|
-
convertLf2ProcessData(bpmnProcessData, data);
|
|
476
|
+
convertLf2ProcessData(bpmnProcessData, data, retainedFields);
|
|
472
477
|
var bpmnDiagramData = {
|
|
473
478
|
'-id': 'BPMNPlane_1',
|
|
474
479
|
'-bpmnElement': bpmnProcessData['-id'],
|
|
@@ -491,7 +496,7 @@ var BpmnAdapter = /** @class */ (function () {
|
|
|
491
496
|
}
|
|
492
497
|
};
|
|
493
498
|
lf.adapterIn = function (data) { return _this.adapterIn(data); };
|
|
494
|
-
lf.adapterOut = function (data) { return _this.adapterOut(data); };
|
|
499
|
+
lf.adapterOut = function (data, retainedFields) { return _this.adapterOut(data, retainedFields); };
|
|
495
500
|
this.processAttributes = {
|
|
496
501
|
'-isExecutable': 'true',
|
|
497
502
|
'-id': "Process_" + bpmnIds_1.getBpmnId(),
|
|
@@ -544,8 +549,8 @@ var BpmnXmlAdapter = /** @class */ (function (_super) {
|
|
|
544
549
|
var json = xml2json_1.lfXml2Json(bpmnData);
|
|
545
550
|
return _this.adapterIn(json);
|
|
546
551
|
};
|
|
547
|
-
_this.adapterXmlOut = function (data) {
|
|
548
|
-
var outData = _this.adapterOut(data);
|
|
552
|
+
_this.adapterXmlOut = function (data, retainedFields) {
|
|
553
|
+
var outData = _this.adapterOut(data, retainedFields);
|
|
549
554
|
return json2xml_1.lfJson2Xml(outData);
|
|
550
555
|
};
|
|
551
556
|
var lf = data.lf;
|
|
@@ -79,16 +79,16 @@ function toXml(obj, name, depth) {
|
|
|
79
79
|
(children_1 !== "" ? ">" + children_1 + (tn + frontSpace) + "</" + name + ">" : " />");
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
str += tn + frontSpace + ("
|
|
82
|
+
str += tn + frontSpace + ("<" + name + ">" + obj.toString() + "</" + name + ">");
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
return str;
|
|
86
86
|
}
|
|
87
87
|
function lfJson2Xml(o) {
|
|
88
|
-
var xmlStr = "
|
|
88
|
+
var xmlStr = "";
|
|
89
89
|
for (var m in o) {
|
|
90
90
|
xmlStr += toXml(o[m], m, 0);
|
|
91
91
|
}
|
|
92
|
-
return xmlStr
|
|
92
|
+
return xmlStr;
|
|
93
93
|
}
|
|
94
94
|
exports.lfJson2Xml = lfJson2Xml;
|
|
@@ -2,26 +2,27 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.lfXml2Json = void 0;
|
|
5
|
-
// ========================================================================
|
|
6
|
-
// XML.ObjTree -- XML source code from/to JavaScript object like E4X
|
|
7
|
-
// ========================================================================
|
|
5
|
+
// ========================================================================
|
|
6
|
+
// XML.ObjTree -- XML source code from/to JavaScript object like E4X
|
|
7
|
+
// ========================================================================
|
|
8
8
|
var XML = function () { };
|
|
9
|
-
// constructor
|
|
9
|
+
// constructor
|
|
10
10
|
XML.ObjTree = function () {
|
|
11
|
+
// @ts-ignore
|
|
11
12
|
return this;
|
|
12
13
|
};
|
|
13
|
-
// class variables
|
|
14
|
-
XML.ObjTree.VERSION =
|
|
15
|
-
// object prototype
|
|
14
|
+
// class variables
|
|
15
|
+
XML.ObjTree.VERSION = '0.23';
|
|
16
|
+
// object prototype
|
|
16
17
|
XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n';
|
|
17
18
|
XML.ObjTree.prototype.attr_prefix = '-';
|
|
18
|
-
// method: parseXML( xmlsource )
|
|
19
|
+
// method: parseXML( xmlsource )
|
|
19
20
|
XML.ObjTree.prototype.parseXML = function (xml) {
|
|
20
21
|
var root;
|
|
21
22
|
if (window.DOMParser) {
|
|
22
23
|
var xmldom = new DOMParser();
|
|
23
|
-
// xmldom.async = false; // DOMParser is always sync-mode
|
|
24
|
-
var dom = xmldom.parseFromString(xml,
|
|
24
|
+
// xmldom.async = false; // DOMParser is always sync-mode
|
|
25
|
+
var dom = xmldom.parseFromString(xml, 'application/xml');
|
|
25
26
|
if (!dom)
|
|
26
27
|
return;
|
|
27
28
|
root = dom.documentElement;
|
|
@@ -36,24 +37,24 @@ XML.ObjTree.prototype.parseXML = function (xml) {
|
|
|
36
37
|
return;
|
|
37
38
|
return this.parseDOM(root);
|
|
38
39
|
};
|
|
39
|
-
// method: parseHTTP( url, options, callback )
|
|
40
|
+
// method: parseHTTP( url, options, callback )
|
|
40
41
|
XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
|
|
41
42
|
var myOpt = {};
|
|
42
43
|
for (var key in options) {
|
|
43
|
-
myOpt[key] = options[key]; // copy object
|
|
44
|
+
myOpt[key] = options[key]; // copy object
|
|
44
45
|
}
|
|
45
46
|
if (!myOpt.method) {
|
|
46
|
-
if (typeof
|
|
47
|
-
typeof
|
|
48
|
-
typeof
|
|
49
|
-
myOpt.method =
|
|
47
|
+
if (typeof myOpt.postBody == 'undefined' &&
|
|
48
|
+
typeof myOpt.postbody == 'undefined' &&
|
|
49
|
+
typeof myOpt.parameters == 'undefined') {
|
|
50
|
+
myOpt.method = 'get';
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
|
-
myOpt.method =
|
|
53
|
+
myOpt.method = 'post';
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
if (callback) {
|
|
56
|
-
myOpt.asynchronous = true; // async-mode
|
|
57
|
+
myOpt.asynchronous = true; // async-mode
|
|
57
58
|
var __this = this;
|
|
58
59
|
var __func = callback;
|
|
59
60
|
var __save = myOpt.onComplete;
|
|
@@ -68,16 +69,16 @@ XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
|
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
else {
|
|
71
|
-
myOpt.asynchronous = false; // sync-mode
|
|
72
|
+
myOpt.asynchronous = false; // sync-mode
|
|
72
73
|
}
|
|
73
74
|
var trans;
|
|
74
|
-
if (typeof
|
|
75
|
+
if (typeof HTTP != 'undefined' && HTTP.Request) {
|
|
75
76
|
myOpt.uri = url;
|
|
76
77
|
var req = new HTTP.Request(myOpt);
|
|
77
78
|
if (req)
|
|
78
79
|
trans = req.transport;
|
|
79
80
|
}
|
|
80
|
-
else if (typeof
|
|
81
|
+
else if (typeof Ajax != 'undefined' && Ajax.Request) {
|
|
81
82
|
var req = new Ajax.Request(url, myOpt);
|
|
82
83
|
if (req)
|
|
83
84
|
trans = req.transport;
|
|
@@ -97,23 +98,24 @@ XML.ObjTree.prototype.parseDOM = function (root) {
|
|
|
97
98
|
this.__force_array[this.force_array[i]] = 1;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
|
-
var json = this.parseElement(root); // parse root node
|
|
101
|
+
var json = this.parseElement(root); // parse root node
|
|
101
102
|
if (this.__force_array[root.nodeName]) {
|
|
102
103
|
json = [json];
|
|
103
104
|
}
|
|
104
|
-
if (root.nodeType != 11) {
|
|
105
|
+
if (root.nodeType != 11) {
|
|
106
|
+
// DOCUMENT_FRAGMENT_NODE
|
|
105
107
|
var tmp = {};
|
|
106
|
-
tmp[root.nodeName] = json; // root nodeName
|
|
108
|
+
tmp[root.nodeName] = json; // root nodeName
|
|
107
109
|
json = tmp;
|
|
108
110
|
}
|
|
109
|
-
return json
|
|
111
|
+
return json;
|
|
110
112
|
};
|
|
111
|
-
// method: parseElement( element )
|
|
113
|
+
// method: parseElement( element )
|
|
112
114
|
/**
|
|
113
115
|
* @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
|
|
114
116
|
*/
|
|
115
117
|
XML.ObjTree.prototype.parseElement = function (elem) {
|
|
116
|
-
// PROCESSING_INSTRUCTION_NODE
|
|
118
|
+
// PROCESSING_INSTRUCTION_NODE
|
|
117
119
|
if (elem.nodeType == 7) {
|
|
118
120
|
return;
|
|
119
121
|
}
|
|
@@ -121,7 +123,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
121
123
|
if (elem.nodeType == 3 || elem.nodeType == 4 || elem.nodeType == 8) {
|
|
122
124
|
var bool = elem.nodeValue.match(/[^\x00-\x20]/);
|
|
123
125
|
if (bool == null)
|
|
124
|
-
return; // ignore white spaces
|
|
126
|
+
return; // ignore white spaces
|
|
125
127
|
return elem.nodeValue;
|
|
126
128
|
}
|
|
127
129
|
var retVal = null;
|
|
@@ -130,7 +132,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
130
132
|
retVal = {};
|
|
131
133
|
for (var i = 0; i < elem.attributes.length; i++) {
|
|
132
134
|
var key = elem.attributes[i].nodeName;
|
|
133
|
-
if (typeof key !=
|
|
135
|
+
if (typeof key != 'string')
|
|
134
136
|
continue;
|
|
135
137
|
var val = elem.attributes[i].nodeValue;
|
|
136
138
|
try {
|
|
@@ -142,17 +144,17 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
142
144
|
if (!val)
|
|
143
145
|
continue;
|
|
144
146
|
key = this.attr_prefix + key;
|
|
145
|
-
if (typeof cnt[key] ==
|
|
147
|
+
if (typeof cnt[key] == 'undefined')
|
|
146
148
|
cnt[key] = 0;
|
|
147
149
|
cnt[key]++;
|
|
148
150
|
this.addNode(retVal, key, cnt[key], val);
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
|
-
// parse child nodes (recursive)
|
|
153
|
+
// parse child nodes (recursive)
|
|
152
154
|
if (elem.childNodes && elem.childNodes.length) {
|
|
153
155
|
var textOnly = true;
|
|
154
156
|
if (retVal)
|
|
155
|
-
textOnly = false; // some attributes exists
|
|
157
|
+
textOnly = false; // some attributes exists
|
|
156
158
|
for (var i = 0; i < elem.childNodes.length && textOnly; i++) {
|
|
157
159
|
var nType = elem.childNodes[i].nodeType;
|
|
158
160
|
if (nType == 3 || nType == 4 || nType == 8)
|
|
@@ -161,7 +163,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
161
163
|
}
|
|
162
164
|
if (textOnly) {
|
|
163
165
|
if (!retVal)
|
|
164
|
-
retVal =
|
|
166
|
+
retVal = '';
|
|
165
167
|
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
166
168
|
retVal += elem.childNodes[i].nodeValue;
|
|
167
169
|
}
|
|
@@ -171,12 +173,12 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
171
173
|
retVal = {};
|
|
172
174
|
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
173
175
|
var key = elem.childNodes[i].nodeName;
|
|
174
|
-
if (typeof
|
|
176
|
+
if (typeof key != 'string')
|
|
175
177
|
continue;
|
|
176
178
|
var val = this.parseElement(elem.childNodes[i]);
|
|
177
179
|
if (!val)
|
|
178
180
|
continue;
|
|
179
|
-
if (typeof
|
|
181
|
+
if (typeof cnt[key] == 'undefined')
|
|
180
182
|
cnt[key] = 0;
|
|
181
183
|
cnt[key]++;
|
|
182
184
|
this.addNode(retVal, key, cnt[key], val);
|
|
@@ -185,35 +187,38 @@ XML.ObjTree.prototype.parseElement = function (elem) {
|
|
|
185
187
|
}
|
|
186
188
|
else {
|
|
187
189
|
// @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,
|
|
190
|
+
// if retVal is null, that means the elem doesn't have any attributes and children,
|
|
189
191
|
// the elem would be like: <a /> or <a></a>, so set retVal to empty object {}
|
|
190
192
|
retVal === null && (retVal = {});
|
|
191
193
|
}
|
|
192
194
|
return retVal;
|
|
193
195
|
};
|
|
194
|
-
// method: addNode( hash, key, count, value )
|
|
196
|
+
// method: addNode( hash, key, count, value )
|
|
195
197
|
XML.ObjTree.prototype.addNode = function (hash, key, counts, val) {
|
|
196
198
|
if (this.__force_array[key]) {
|
|
197
199
|
if (counts == 1)
|
|
198
200
|
hash[key] = [];
|
|
199
|
-
hash[key][hash[key].length] = val; // push
|
|
201
|
+
hash[key][hash[key].length] = val; // push
|
|
200
202
|
}
|
|
201
|
-
else if (counts == 1) {
|
|
203
|
+
else if (counts == 1) {
|
|
204
|
+
// 1st sibling
|
|
202
205
|
hash[key] = val;
|
|
203
206
|
}
|
|
204
|
-
else if (counts == 2) {
|
|
207
|
+
else if (counts == 2) {
|
|
208
|
+
// 2nd sibling
|
|
205
209
|
hash[key] = [hash[key], val];
|
|
206
210
|
}
|
|
207
|
-
else {
|
|
211
|
+
else {
|
|
212
|
+
// 3rd sibling and more
|
|
208
213
|
hash[key][hash[key].length] = val;
|
|
209
214
|
}
|
|
210
215
|
};
|
|
211
|
-
// method: writeXML( tree )
|
|
216
|
+
// method: writeXML( tree )
|
|
212
217
|
XML.ObjTree.prototype.writeXML = function (tree) {
|
|
213
218
|
var xml = this.hash_to_xml(null, tree);
|
|
214
219
|
return this.xmlDecl + xml;
|
|
215
220
|
};
|
|
216
|
-
// method: hash_to_xml( tagName, tree )
|
|
221
|
+
// method: hash_to_xml( tagName, tree )
|
|
217
222
|
XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
|
|
218
223
|
var elem = [];
|
|
219
224
|
var attr = [];
|
|
@@ -222,13 +227,13 @@ XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
|
|
|
222
227
|
continue;
|
|
223
228
|
var val = tree[key];
|
|
224
229
|
if (key.charAt(0) != this.attr_prefix) {
|
|
225
|
-
if (typeof
|
|
226
|
-
elem[elem.length] =
|
|
230
|
+
if (typeof val == 'undefined' || val == null) {
|
|
231
|
+
elem[elem.length] = '<' + key + ' />';
|
|
227
232
|
}
|
|
228
|
-
else if (typeof
|
|
233
|
+
else if (typeof val == 'object' && val.constructor == Array) {
|
|
229
234
|
elem[elem.length] = this.array_to_xml(key, val);
|
|
230
235
|
}
|
|
231
|
-
else if (typeof
|
|
236
|
+
else if (typeof val == 'object') {
|
|
232
237
|
elem[elem.length] = this.hash_to_xml(key, val);
|
|
233
238
|
}
|
|
234
239
|
else {
|
|
@@ -236,59 +241,64 @@ XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
|
|
|
236
241
|
}
|
|
237
242
|
}
|
|
238
243
|
else {
|
|
239
|
-
attr[attr.length] =
|
|
244
|
+
attr[attr.length] =
|
|
245
|
+
' ' + key.substring(1) + '="' + this.xml_escape(val) + '"';
|
|
240
246
|
}
|
|
241
247
|
}
|
|
242
|
-
var jattr = attr.join(
|
|
243
|
-
var jelem = elem.join(
|
|
244
|
-
if (typeof
|
|
245
|
-
// no tag
|
|
248
|
+
var jattr = attr.join('');
|
|
249
|
+
var jelem = elem.join('');
|
|
250
|
+
if (typeof name == 'undefined' || name == null) {
|
|
251
|
+
// no tag
|
|
246
252
|
}
|
|
247
253
|
else if (elem.length > 0) {
|
|
248
254
|
if (jelem.match(/\n/)) {
|
|
249
|
-
jelem =
|
|
255
|
+
jelem = '<' + name + jattr + '>\n' + jelem + '</' + name + '>\n';
|
|
250
256
|
}
|
|
251
257
|
else {
|
|
252
|
-
jelem =
|
|
258
|
+
jelem = '<' + name + jattr + '>' + jelem + '</' + name + '>\n';
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
261
|
else {
|
|
256
|
-
jelem =
|
|
262
|
+
jelem = '<' + name + jattr + ' />\n';
|
|
257
263
|
}
|
|
258
264
|
return jelem;
|
|
259
265
|
};
|
|
260
|
-
// method: array_to_xml( tagName, array )
|
|
266
|
+
// method: array_to_xml( tagName, array )
|
|
261
267
|
XML.ObjTree.prototype.array_to_xml = function (name, array) {
|
|
262
268
|
var out = [];
|
|
263
269
|
for (var i = 0; i < array.length; i++) {
|
|
264
270
|
var val = array[i];
|
|
265
|
-
if (typeof
|
|
266
|
-
out[out.length] =
|
|
271
|
+
if (typeof val == 'undefined' || val == null) {
|
|
272
|
+
out[out.length] = '<' + name + ' />';
|
|
267
273
|
}
|
|
268
|
-
else if (typeof
|
|
274
|
+
else if (typeof val == 'object' && val.constructor == Array) {
|
|
269
275
|
out[out.length] = this.array_to_xml(name, val);
|
|
270
276
|
}
|
|
271
|
-
else if (typeof
|
|
277
|
+
else if (typeof val == 'object') {
|
|
272
278
|
out[out.length] = this.hash_to_xml(name, val);
|
|
273
279
|
}
|
|
274
280
|
else {
|
|
275
281
|
out[out.length] = this.scalar_to_xml(name, val);
|
|
276
282
|
}
|
|
277
283
|
}
|
|
278
|
-
return out.join(
|
|
284
|
+
return out.join('');
|
|
279
285
|
};
|
|
280
|
-
// method: scalar_to_xml( tagName, text )
|
|
286
|
+
// method: scalar_to_xml( tagName, text )
|
|
281
287
|
XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
|
|
282
|
-
if (name ==
|
|
288
|
+
if (name == '#text') {
|
|
283
289
|
return this.xml_escape(text);
|
|
284
290
|
}
|
|
285
291
|
else {
|
|
286
|
-
return
|
|
292
|
+
return '<' + name + '>' + this.xml_escape(text) + '</' + name + '>\n';
|
|
287
293
|
}
|
|
288
294
|
};
|
|
289
|
-
// method: xml_escape( text )
|
|
295
|
+
// method: xml_escape( text )
|
|
290
296
|
XML.ObjTree.prototype.xml_escape = function (text) {
|
|
291
|
-
return text
|
|
297
|
+
return text
|
|
298
|
+
.replace(/&/g, '&')
|
|
299
|
+
.replace(/</g, '<')
|
|
300
|
+
.replace(/>/g, '>')
|
|
301
|
+
.replace(/"/g, '"');
|
|
292
302
|
};
|
|
293
303
|
/*
|
|
294
304
|
// ========================================================================
|
|
@@ -184,8 +184,6 @@ var MiniMap = /** @class */ (function () {
|
|
|
184
184
|
miniMapWrap.style.width = this.width + 4 + "px";
|
|
185
185
|
miniMapWrap.style.height = this.height + "px";
|
|
186
186
|
this.lfMap = new this.LogicFlow({
|
|
187
|
-
width: this.lf.graphModel.width,
|
|
188
|
-
height: (this.lf.graphModel.width * this.height) / this.width,
|
|
189
187
|
container: miniMapWrap,
|
|
190
188
|
isSilentMode: true,
|
|
191
189
|
stopZoomGraph: true,
|
|
@@ -87,6 +87,7 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
87
87
|
};
|
|
88
88
|
};
|
|
89
89
|
InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
|
|
90
|
+
var _this = this;
|
|
90
91
|
var edges = this._lf.graphModel.edges;
|
|
91
92
|
var nodeModel = this._lf.getNodeModelById(nodeData.id);
|
|
92
93
|
for (var i = 0; i < edges.length; i++) {
|
|
@@ -94,39 +95,43 @@ var InsertNodeInPolyline = /** @class */ (function () {
|
|
|
94
95
|
var _a = edge_1.isNodeInSegment(nodeModel, edges[i], this.deviation), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
|
|
95
96
|
if (crossIndex >= 0) {
|
|
96
97
|
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;
|
|
98
|
+
// fix https://github.com/didi/LogicFlow/issues/996
|
|
99
|
+
var startPoint = lodash_es_1.cloneDeep(pointsList[0]);
|
|
100
|
+
var endPoint = lodash_es_1.cloneDeep(crossPoints.startCrossPoint);
|
|
101
|
+
this._lf.deleteEdge(id);
|
|
97
102
|
var checkResult = this.checkRuleBeforeInsetNode(sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
crossPoints.endCrossPoint
|
|
120
|
-
], pointsList.slice(crossIndex)),
|
|
121
|
-
});
|
|
122
|
-
this._lf.deleteEdge(id);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
103
|
+
this._lf.addEdge({
|
|
104
|
+
type: type,
|
|
105
|
+
sourceNodeId: sourceNodeId,
|
|
106
|
+
targetNodeId: nodeData.id,
|
|
107
|
+
startPoint: startPoint,
|
|
108
|
+
endPoint: endPoint,
|
|
109
|
+
pointsList: __spread(pointsList.slice(0, crossIndex), [
|
|
110
|
+
crossPoints.startCrossPoint,
|
|
111
|
+
]),
|
|
112
|
+
});
|
|
113
|
+
this._lf.addEdge({
|
|
114
|
+
type: type,
|
|
115
|
+
sourceNodeId: nodeData.id,
|
|
116
|
+
targetNodeId: targetNodeId,
|
|
117
|
+
startPoint: lodash_es_1.cloneDeep(crossPoints.endCrossPoint),
|
|
118
|
+
endPoint: lodash_es_1.cloneDeep(pointsList[pointsList.length - 1]),
|
|
119
|
+
pointsList: __spread([
|
|
120
|
+
crossPoints.endCrossPoint
|
|
121
|
+
], pointsList.slice(crossIndex)),
|
|
122
|
+
});
|
|
123
|
+
if (!checkResult.isPass) {
|
|
126
124
|
this._lf.graphModel.eventCenter.emit(core_1.EventType.CONNECTION_NOT_ALLOWED, {
|
|
127
125
|
data: nodeData,
|
|
128
126
|
msg: checkResult.targetMsg || checkResult.sourceMsg,
|
|
129
127
|
});
|
|
128
|
+
// FIXME:在关闭了历史记录的情况下,撤销操作会不生效。
|
|
129
|
+
setTimeout(function () {
|
|
130
|
+
_this._lf.undo();
|
|
131
|
+
}, 200);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
130
135
|
break;
|
|
131
136
|
}
|
|
132
137
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable operator-linebreak */
|
|
3
|
+
/* eslint-disable implicit-arrow-linebreak */
|
|
2
4
|
/**
|
|
3
5
|
* 快照插件,生成视图
|
|
4
6
|
*/
|
|
@@ -16,39 +18,16 @@ var Snapshot = /** @class */ (function () {
|
|
|
16
18
|
_this.getSnapshot(fileName, backgroundColor);
|
|
17
19
|
};
|
|
18
20
|
/* 获取Blob对象,用户图片上传 */
|
|
19
|
-
lf.getSnapshotBlob = function (backgroundColor) {
|
|
21
|
+
lf.getSnapshotBlob = function (backgroundColor) {
|
|
22
|
+
return _this.getSnapshotBlob(backgroundColor);
|
|
23
|
+
};
|
|
20
24
|
/* 获取Base64对象,用户图片上传 */
|
|
21
|
-
lf.getSnapshotBase64 = function (backgroundColor) {
|
|
25
|
+
lf.getSnapshotBase64 = function (backgroundColor) {
|
|
26
|
+
return _this.getSnapshotBase64(backgroundColor);
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
/* 获取svgRoot对象 */
|
|
24
30
|
Snapshot.prototype.getSvgRootElement = function (lf) {
|
|
25
|
-
var _this = this;
|
|
26
|
-
this.offsetX = Number.MAX_SAFE_INTEGER;
|
|
27
|
-
this.offsetY = Number.MAX_SAFE_INTEGER;
|
|
28
|
-
lf.graphModel.nodes.forEach(function (item) {
|
|
29
|
-
var x = item.x, width = item.width, y = item.y, height = item.height;
|
|
30
|
-
var offsetX = x - width / 2;
|
|
31
|
-
var offsetY = y - height / 2;
|
|
32
|
-
if (offsetX < _this.offsetX) {
|
|
33
|
-
_this.offsetX = offsetX - 5;
|
|
34
|
-
}
|
|
35
|
-
if (offsetY < _this.offsetY) {
|
|
36
|
-
_this.offsetY = offsetY - 5;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
lf.graphModel.edges.forEach(function (edge) {
|
|
40
|
-
if (edge.pointsList) {
|
|
41
|
-
edge.pointsList.forEach(function (point) {
|
|
42
|
-
var x = point.x, y = point.y;
|
|
43
|
-
if (x < _this.offsetX) {
|
|
44
|
-
_this.offsetX = x - 5;
|
|
45
|
-
}
|
|
46
|
-
if (y < _this.offsetY) {
|
|
47
|
-
_this.offsetY = y - 5;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
31
|
var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
|
|
53
32
|
return svgRootElement;
|
|
54
33
|
};
|
|
@@ -83,7 +62,8 @@ var Snapshot = /** @class */ (function () {
|
|
|
83
62
|
this.fileName = fileName || "logic-flow." + Date.now() + ".png";
|
|
84
63
|
var svg = this.getSvgRootElement(this.lf);
|
|
85
64
|
this.getCanvasData(svg, backgroundColor).then(function (canvas) {
|
|
86
|
-
var imgURI = canvas
|
|
65
|
+
var imgURI = canvas
|
|
66
|
+
.toDataURL('image/png')
|
|
87
67
|
.replace('image/png', 'image/octet-stream');
|
|
88
68
|
_this.triggerDownload(imgURI);
|
|
89
69
|
});
|
|
@@ -148,15 +128,14 @@ var Snapshot = /** @class */ (function () {
|
|
|
148
128
|
else {
|
|
149
129
|
// 删除锚点
|
|
150
130
|
var lfBase = graph.childNodes[i];
|
|
151
|
-
lfBase &&
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
131
|
+
lfBase &&
|
|
132
|
+
lfBase.childNodes.forEach(function (item) {
|
|
133
|
+
var element = item;
|
|
134
|
+
_this.removeAnchor(element.firstChild);
|
|
135
|
+
});
|
|
155
136
|
}
|
|
156
137
|
}
|
|
157
138
|
}
|
|
158
|
-
// offset值加10,保证图形不会紧贴着下载图片的左边和上边
|
|
159
|
-
copy.lastChild.style.transform = "matrix(1, 0, 0, 1, " + (-this.offsetX + 10) + ", " + (-this.offsetY + 10) + ")";
|
|
160
139
|
var dpr = window.devicePixelRatio || 1;
|
|
161
140
|
var canvas = document.createElement('canvas');
|
|
162
141
|
/*
|
|
@@ -166,9 +145,16 @@ var Snapshot = /** @class */ (function () {
|
|
|
166
145
|
*/
|
|
167
146
|
var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
|
|
168
147
|
var bbox = base.getBoundingClientRect();
|
|
148
|
+
var layout = document
|
|
149
|
+
.querySelector('.lf-canvas-overlay')
|
|
150
|
+
.getBoundingClientRect();
|
|
151
|
+
var offsetX = bbox.x - layout.x;
|
|
152
|
+
var offsetY = bbox.y - layout.y;
|
|
169
153
|
var graphModel = this.lf.graphModel;
|
|
170
154
|
var transformModel = graphModel.transformModel;
|
|
171
|
-
var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y;
|
|
155
|
+
var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
|
|
156
|
+
// offset值加10,保证图形不会紧贴着下载图片的左边和上边
|
|
157
|
+
copy.lastChild.style.transform = "matrix(1, 0, 0, 1, " + (-offsetX + 10 + TRANSLATE_X) + ", " + (-offsetY + 10 + TRANSLATE_Y) + ")";
|
|
172
158
|
var bboxWidth = Math.ceil(bbox.width / SCALE_X);
|
|
173
159
|
var bboxHeight = Math.ceil(bbox.height / SCALE_Y);
|
|
174
160
|
// width,height 值加40,保证图形不会紧贴着下载图片的右边和下边
|
|
@@ -224,7 +210,10 @@ var Snapshot = /** @class */ (function () {
|
|
|
224
210
|
fixme: XMLSerializer的中的css background url不会下载图片
|
|
225
211
|
*/
|
|
226
212
|
var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
|
|
227
|
-
var imgSrc = svg2Img
|
|
213
|
+
var imgSrc = svg2Img
|
|
214
|
+
.replace(/\n/g, '')
|
|
215
|
+
.replace(/\t/g, '')
|
|
216
|
+
.replace(/#/g, '%23');
|
|
228
217
|
img.src = imgSrc;
|
|
229
218
|
});
|
|
230
219
|
};
|
|
@@ -26,7 +26,12 @@ declare class BpmnAdapter {
|
|
|
26
26
|
lf: any;
|
|
27
27
|
});
|
|
28
28
|
setCustomShape(key: any, val: any): void;
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @param retainedFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
|
|
31
|
+
* ["properties", "startPoint", "endPoint", "pointsList"]合并,
|
|
32
|
+
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
|
|
33
|
+
*/
|
|
34
|
+
adapterOut: (data: any, retainedFields?: string[]) => {
|
|
30
35
|
'bpmn:definitions': {
|
|
31
36
|
[key: string]: any;
|
|
32
37
|
"-id": string;
|
|
@@ -52,7 +57,7 @@ declare class BpmnXmlAdapter extends BpmnAdapter {
|
|
|
52
57
|
nodes: any[];
|
|
53
58
|
edges: any[];
|
|
54
59
|
};
|
|
55
|
-
adapterXmlOut: (data: any) => string;
|
|
60
|
+
adapterXmlOut: (data: any, retainedFields?: string[]) => string;
|
|
56
61
|
}
|
|
57
62
|
export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
|
|
58
63
|
export default BpmnAdapter;
|