@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.
@@ -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 = ['-name', '-id', 'bpmn:incoming', 'bpmn:outgoing', '-sourceRef', '-targetRef'];
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
- function toXmlJson(json) {
64
- var xmlJson = {};
65
- Object.entries(json).forEach(function (_a) {
66
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
67
- if (typeof value !== 'object') {
68
- if (key.indexOf('-') === 0) { // 如果本来就是“-”开头的了,那就不处理了。
69
- xmlJson[key] = value;
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
- else {
72
- xmlJson["-" + key] = value;
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
- else {
76
- xmlJson[key] = toXmlJson(value);
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 (typeof value === 'string') {
89
- if (key.indexOf('-') === 0) { // 如果本来就是“-”开头的了,那就不处理了。
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 === 'object') {
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
@@ -110,7 +145,7 @@ function toNormalJson(xmlJson) {
110
145
  * 2)如果只有一个子元素,json中表示为正常属性
111
146
  * 3)如果是多个子元素,json中使用数组存储
112
147
  */
113
- function convertLf2ProcessData(bpmnProcessData, data) {
148
+ function convertLf2ProcessData(bpmnProcessData, data, retainedFields) {
114
149
  var nodeMap = new Map();
115
150
  data.nodes.forEach(function (node) {
116
151
  var _a;
@@ -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(retainedFields)(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])) { // 如果是多个子元素,json中使用数组存储
166
+ else if (Array.isArray(bpmnProcessData[node.type])) {
167
+ // 如果是多个子元素,json中使用数组存储
132
168
  bpmnProcessData[node.type].push(processNode);
133
169
  }
134
- else { // 如果是多个子元素,json中使用数组存储
135
- bpmnProcessData[node.type] = [
136
- bpmnProcessData[node.type],
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(retainedFields)(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
- sourceNode['bpmn:outgoing'] = [
182
- sourceNode['bpmn:outgoing'],
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 ({ '-x': x, '-y': y });
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'] && shapeValue['bpmndi:BPMNLabel']['dc:Bounds']) {
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;
@@ -432,9 +466,14 @@ var BpmnAdapter = /** @class */ (function () {
432
466
  function BpmnAdapter(_a) {
433
467
  var _this = this;
434
468
  var lf = _a.lf;
435
- this.adapterOut = function (data) {
469
+ /**
470
+ * @param retainedFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
471
+ * ["properties", "startPoint", "endPoint", "pointsList"]合并,
472
+ * 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
473
+ */
474
+ this.adapterOut = function (data, retainedFields) {
436
475
  var bpmnProcessData = __assign({}, _this.processAttributes);
437
- convertLf2ProcessData(bpmnProcessData, data);
476
+ convertLf2ProcessData(bpmnProcessData, data, retainedFields);
438
477
  var bpmnDiagramData = {
439
478
  '-id': 'BPMNPlane_1',
440
479
  '-bpmnElement': bpmnProcessData['-id'],
@@ -457,7 +496,7 @@ var BpmnAdapter = /** @class */ (function () {
457
496
  }
458
497
  };
459
498
  lf.adapterIn = function (data) { return _this.adapterIn(data); };
460
- lf.adapterOut = function (data) { return _this.adapterOut(data); };
499
+ lf.adapterOut = function (data, retainedFields) { return _this.adapterOut(data, retainedFields); };
461
500
  this.processAttributes = {
462
501
  '-isExecutable': 'true',
463
502
  '-id': "Process_" + bpmnIds_1.getBpmnId(),
@@ -510,8 +549,8 @@ var BpmnXmlAdapter = /** @class */ (function (_super) {
510
549
  var json = xml2json_1.lfXml2Json(bpmnData);
511
550
  return _this.adapterIn(json);
512
551
  };
513
- _this.adapterXmlOut = function (data) {
514
- var outData = _this.adapterOut(data);
552
+ _this.adapterXmlOut = function (data, retainedFields) {
553
+ var outData = _this.adapterOut(data, retainedFields);
515
554
  return json2xml_1.lfJson2Xml(outData);
516
555
  };
517
556
  var lf = data.lf;
@@ -1,62 +1,94 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lfJson2Xml = void 0;
4
- /**
5
- * This work is licensed under Creative Commons GNU LGPL License.
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 toXml(v, name, ind, deep) {
18
- var xml = "";
19
- if (v instanceof Array) {
20
- for (var i = 0, n = v.length; i < n; i++) {
21
- xml += addIndSpace(ind, deep) + toXml(v[i], name, ind, deep + 1);
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
- else if (typeof (v) == "object") {
25
- var hasChild = false;
26
- xml += addIndSpace(ind, deep) + "<" + name;
27
- for (var m in v) {
28
- if (m.charAt(0) == "-")
29
- xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";
30
- else
31
- hasChild = true;
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
- xml += hasChild ? ">" : " />";
34
- if (hasChild) {
35
- for (var m in v) {
36
- if (m == "#text")
37
- xml += v[m];
38
- else if (m == "#cdata")
39
- xml += "<![CDATA[" + v[m] + "]]>";
40
- else if (m.charAt(0) != "-")
41
- xml += toXml(v[m], m, ind, deep + 1);
42
- }
43
- xml += addIndSpace(ind, deep) + "</" + name + ">";
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
- // xml += addIndSpace(ind, deep);
82
+ str += tn + frontSpace + ("<" + name + ">" + obj.toString() + "</" + name + ">");
47
83
  }
48
84
  }
49
- else {
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, "\t\n", 0);
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
- // COMMENT_NODE
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 (key) != "string")
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 (cnt[key]) == "undefined")
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,24 +62,53 @@ 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) {
90
+ var _this = this;
65
91
  var edges = this._lf.graphModel.edges;
66
92
  var nodeModel = this._lf.getNodeModelById(nodeData.id);
67
93
  for (var i = 0; i < edges.length; i++) {
68
94
  // eslint-disable-next-line max-len
69
95
  var _a = edge_1.isNodeInSegment(nodeModel, edges[i], this.deviation), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
70
96
  if (crossIndex >= 0) {
71
- var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
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;
72
98
  // fix https://github.com/didi/LogicFlow/issues/996
73
99
  var startPoint = lodash_es_1.cloneDeep(pointsList[0]);
74
100
  var endPoint = lodash_es_1.cloneDeep(crossPoints.startCrossPoint);
101
+ this._lf.deleteEdge(id);
102
+ var checkResult = this.checkRuleBeforeInsetNode(sourceNodeId, targetNodeId, sourceAnchorId, targetAnchorId, nodeData);
75
103
  this._lf.addEdge({
76
104
  type: type,
77
105
  sourceNodeId: sourceNodeId,
78
106
  targetNodeId: nodeData.id,
79
107
  startPoint: startPoint,
80
108
  endPoint: endPoint,
81
- pointsList: __spread(pointsList.slice(0, crossIndex), [crossPoints.startCrossPoint]),
109
+ pointsList: __spread(pointsList.slice(0, crossIndex), [
110
+ crossPoints.startCrossPoint,
111
+ ]),
82
112
  });
83
113
  this._lf.addEdge({
84
114
  type: type,
@@ -86,10 +116,24 @@ var InsertNodeInPolyline = /** @class */ (function () {
86
116
  targetNodeId: targetNodeId,
87
117
  startPoint: lodash_es_1.cloneDeep(crossPoints.endCrossPoint),
88
118
  endPoint: lodash_es_1.cloneDeep(pointsList[pointsList.length - 1]),
89
- pointsList: __spread([crossPoints.endCrossPoint], pointsList.slice(crossIndex)),
119
+ pointsList: __spread([
120
+ crossPoints.endCrossPoint
121
+ ], pointsList.slice(crossIndex)),
90
122
  });
91
- this._lf.deleteEdge(id);
92
- break;
123
+ if (!checkResult.isPass) {
124
+ this._lf.graphModel.eventCenter.emit(core_1.EventType.CONNECTION_NOT_ALLOWED, {
125
+ data: nodeData,
126
+ msg: checkResult.targetMsg || checkResult.sourceMsg,
127
+ });
128
+ // FIXME:在关闭了历史记录的情况下,撤销操作会不生效。
129
+ setTimeout(function () {
130
+ _this._lf.undo();
131
+ }, 200);
132
+ break;
133
+ }
134
+ else {
135
+ break;
136
+ }
93
137
  }
94
138
  }
95
139
  };
@@ -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>;
@@ -21,7 +26,12 @@ declare class BpmnAdapter {
21
26
  lf: any;
22
27
  });
23
28
  setCustomShape(key: any, val: any): void;
24
- adapterOut: (data: any) => {
29
+ /**
30
+ * @param retainedFields?: string[] (可选)属性保留字段,retainedField会和默认的defaultRetainedFields:
31
+ * ["properties", "startPoint", "endPoint", "pointsList"]合并,
32
+ * 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性。
33
+ */
34
+ adapterOut: (data: any, retainedFields?: string[]) => {
25
35
  'bpmn:definitions': {
26
36
  [key: string]: any;
27
37
  "-id": string;
@@ -47,7 +57,7 @@ declare class BpmnXmlAdapter extends BpmnAdapter {
47
57
  nodes: any[];
48
58
  edges: any[];
49
59
  };
50
- adapterXmlOut: (data: any) => string;
60
+ adapterXmlOut: (data: any, retainedFields?: string[]) => string;
51
61
  }
52
- export { BpmnAdapter, BpmnXmlAdapter, };
62
+ export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
53
63
  export default BpmnAdapter;