@logicflow/extension 1.2.3 → 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 +184 -113
- 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/cjs/materials/group/GroupNode.js +2 -1
- package/es/bpmn-adapter/index.d.ts +47 -34
- package/es/bpmn-adapter/index.js +183 -114
- 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/es/materials/group/GroupNode.js +2 -1
- 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 +47 -34
- package/types/bpmn-adapter/json2xml.d.ts +3 -2
- package/types/insert-node-in-polyline/index.d.ts +13 -0
|
@@ -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
|
};
|
|
@@ -160,7 +160,8 @@ var GroupNodeModel = /** @class */ (function (_super) {
|
|
|
160
160
|
GroupNodeModel.prototype.foldEdge = function (isFolded, allEdges) {
|
|
161
161
|
var _this = this;
|
|
162
162
|
allEdges.forEach(function (edgeModel, index) {
|
|
163
|
-
var id = edgeModel.id, sourceNodeId = edgeModel.sourceNodeId, targetNodeId = edgeModel.targetNodeId, startPoint = edgeModel.startPoint, endPoint = edgeModel.endPoint, type = edgeModel.type,
|
|
163
|
+
var id = edgeModel.id, sourceNodeId = edgeModel.sourceNodeId, targetNodeId = edgeModel.targetNodeId, startPoint = edgeModel.startPoint, endPoint = edgeModel.endPoint, type = edgeModel.type, text = edgeModel.text;
|
|
164
|
+
var properties = edgeModel.getProperties();
|
|
164
165
|
var data = {
|
|
165
166
|
id: id + "__" + index,
|
|
166
167
|
sourceNodeId: sourceNodeId,
|
|
@@ -1,45 +1,58 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare function toXmlJson(retainedFields?: string[]): (json: string | any[] | Object) => any;
|
|
2
|
+
/**
|
|
3
|
+
* 将xmlJson转换为普通的json,在内部使用。
|
|
4
|
+
*/
|
|
5
|
+
declare function toNormalJson(xmlJson: any): {};
|
|
6
|
+
declare class BpmnAdapter {
|
|
7
|
+
static pluginName: string;
|
|
8
|
+
static shapeConfigMap: Map<any, any>;
|
|
9
|
+
processAttributes: {
|
|
10
|
+
['-isExecutable']: string;
|
|
11
|
+
['-id']: string;
|
|
12
|
+
};
|
|
13
|
+
definitionAttributes: {
|
|
14
|
+
['-id']: string;
|
|
15
|
+
['-xmlns:xsi']: string;
|
|
16
|
+
['-xmlns:bpmn']: string;
|
|
17
|
+
['-xmlns:bpmndi']: string;
|
|
18
|
+
['-xmlns:dc']: string;
|
|
19
|
+
['-xmlns:di']: string;
|
|
20
|
+
['-targetNamespace']: string;
|
|
21
|
+
['-exporter']: string;
|
|
22
|
+
['-exporterVersion']: string;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
constructor({ lf }: {
|
|
26
|
+
lf: any;
|
|
27
|
+
});
|
|
5
28
|
setCustomShape(key: any, val: any): void;
|
|
6
|
-
adapterOut(data: any)
|
|
29
|
+
adapterOut: (data: any) => {
|
|
7
30
|
'bpmn:definitions': {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'-id': string;
|
|
19
|
-
'-isExecutable': string;
|
|
20
|
-
};
|
|
21
|
-
'bpmndi:BPMNDiagram': {
|
|
22
|
-
'-id': string;
|
|
23
|
-
'bpmndi:BPMNPlane': {
|
|
24
|
-
'-id': string;
|
|
25
|
-
'-bpmnElement': string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
"-id": string;
|
|
33
|
+
"-xmlns:xsi": string;
|
|
34
|
+
"-xmlns:bpmn": string;
|
|
35
|
+
"-xmlns:bpmndi": string;
|
|
36
|
+
"-xmlns:dc": string;
|
|
37
|
+
"-xmlns:di": string;
|
|
38
|
+
"-targetNamespace": string;
|
|
39
|
+
"-exporter": string;
|
|
40
|
+
"-exporterVersion": string;
|
|
28
41
|
};
|
|
29
42
|
};
|
|
30
|
-
adapterIn(bpmnData: any)
|
|
43
|
+
adapterIn: (bpmnData: any) => {
|
|
31
44
|
nodes: any[];
|
|
32
45
|
edges: any[];
|
|
33
46
|
};
|
|
34
|
-
}
|
|
35
|
-
declare
|
|
36
|
-
pluginName: string;
|
|
37
|
-
|
|
38
|
-
adapterXmlIn(bpmnData: any)
|
|
47
|
+
}
|
|
48
|
+
declare class BpmnXmlAdapter extends BpmnAdapter {
|
|
49
|
+
static pluginName: string;
|
|
50
|
+
constructor(data: any);
|
|
51
|
+
adapterXmlIn: (bpmnData: any) => {
|
|
39
52
|
nodes: any[];
|
|
40
53
|
edges: any[];
|
|
41
54
|
};
|
|
42
|
-
adapterXmlOut(data: any)
|
|
43
|
-
}
|
|
44
|
-
export { BpmnAdapter, BpmnXmlAdapter, };
|
|
55
|
+
adapterXmlOut: (data: any) => string;
|
|
56
|
+
}
|
|
57
|
+
export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
|
|
45
58
|
export default BpmnAdapter;
|
package/es/bpmn-adapter/index.js
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
var __assign = (this && this.__assign) || function () {
|
|
15
|
+
__assign = Object.assign || function(t) {
|
|
16
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
+
s = arguments[i];
|
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
+
t[p] = s[p];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
return __assign.apply(this, arguments);
|
|
24
|
+
};
|
|
1
25
|
var __read = (this && this.__read) || function (o, n) {
|
|
2
26
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
27
|
if (!m) return o;
|
|
@@ -15,7 +39,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
15
39
|
return ar;
|
|
16
40
|
};
|
|
17
41
|
import { getBpmnId } from './bpmnIds';
|
|
18
|
-
import { lfJson2Xml } from './json2xml';
|
|
42
|
+
import { handleAttributes, lfJson2Xml } from './json2xml';
|
|
19
43
|
import { lfXml2Json } from './xml2json';
|
|
20
44
|
import { ExclusiveGatewayConfig, StartEventConfig, EndEventConfig, ServiceTaskConfig, UserTaskConfig, } from '../bpmn/constant';
|
|
21
45
|
var BpmnElements;
|
|
@@ -27,29 +51,60 @@ var BpmnElements;
|
|
|
27
51
|
BpmnElements["SYSTEM"] = "bpmn:serviceTask";
|
|
28
52
|
BpmnElements["FLOW"] = "bpmn:sequenceFlow";
|
|
29
53
|
})(BpmnElements || (BpmnElements = {}));
|
|
30
|
-
var defaultAttrs = [
|
|
54
|
+
var defaultAttrs = [
|
|
55
|
+
'-name',
|
|
56
|
+
'-id',
|
|
57
|
+
'bpmn:incoming',
|
|
58
|
+
'bpmn:outgoing',
|
|
59
|
+
'-sourceRef',
|
|
60
|
+
'-targetRef',
|
|
61
|
+
];
|
|
31
62
|
/**
|
|
32
63
|
* 将普通json转换为xmlJson
|
|
33
64
|
* xmlJson中property会以“-”开头
|
|
34
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
|
|
35
71
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|
|
43
81
|
}
|
|
44
|
-
|
|
45
|
-
|
|
82
|
+
if (Array.isArray(obj)) {
|
|
83
|
+
return obj.map(function (j) { return ToXmlJson(j); });
|
|
46
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;
|
|
47
105
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return xmlJson;
|
|
106
|
+
return ToXmlJson(json);
|
|
107
|
+
};
|
|
53
108
|
}
|
|
54
109
|
/**
|
|
55
110
|
* 将xmlJson转换为普通的json,在内部使用。
|
|
@@ -58,17 +113,19 @@ function toNormalJson(xmlJson) {
|
|
|
58
113
|
var json = {};
|
|
59
114
|
Object.entries(xmlJson).forEach(function (_a) {
|
|
60
115
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
json[key] = value;
|
|
67
|
-
}
|
|
116
|
+
if (key.indexOf('-') === 0) {
|
|
117
|
+
json[key.substring(1)] = handleAttributes(value);
|
|
118
|
+
}
|
|
119
|
+
else if (typeof value === 'string') {
|
|
120
|
+
json[key] = value;
|
|
68
121
|
}
|
|
69
|
-
else if (
|
|
122
|
+
else if (Object.prototype.toString.call(value) === '[object Object]') {
|
|
70
123
|
json[key] = toNormalJson(value);
|
|
71
124
|
}
|
|
125
|
+
else if (Array.isArray(value)) {
|
|
126
|
+
// contain the process of array
|
|
127
|
+
json[key] = value.map(function (v) { return toNormalJson(v); });
|
|
128
|
+
}
|
|
72
129
|
else {
|
|
73
130
|
json[key] = value;
|
|
74
131
|
}
|
|
@@ -94,28 +151,25 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
94
151
|
processNode['-name'] = node.text.value;
|
|
95
152
|
}
|
|
96
153
|
if (node.properties) {
|
|
97
|
-
var properties = toXmlJson(node.properties);
|
|
154
|
+
var properties = toXmlJson()(node.properties);
|
|
98
155
|
Object.assign(processNode, properties);
|
|
99
156
|
}
|
|
100
157
|
nodeMap.set(node.id, processNode);
|
|
101
158
|
if (!bpmnProcessData[node.type]) {
|
|
102
159
|
bpmnProcessData[node.type] = processNode; // 如果只有一个子元素,json中表示为正常属性
|
|
103
160
|
}
|
|
104
|
-
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
161
|
+
else if (Array.isArray(bpmnProcessData[node.type])) {
|
|
162
|
+
// 如果是多个子元素,json中使用数组存储
|
|
105
163
|
bpmnProcessData[node.type].push(processNode);
|
|
106
164
|
}
|
|
107
|
-
else {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
processNode,
|
|
111
|
-
];
|
|
165
|
+
else {
|
|
166
|
+
// 如果是多个子元素,json中使用数组存储
|
|
167
|
+
bpmnProcessData[node.type] = [bpmnProcessData[node.type], processNode];
|
|
112
168
|
}
|
|
113
169
|
});
|
|
114
170
|
var sequenceFlow = data.edges.map(function (edge) {
|
|
115
171
|
var _a, _b;
|
|
116
172
|
var targetNode = nodeMap.get(edge.targetNodeId);
|
|
117
|
-
// @see https://github.com/didi/LogicFlow/issues/325
|
|
118
|
-
// 需要保证incomming在outgoing之前
|
|
119
173
|
if (!targetNode['bpmn:incoming']) {
|
|
120
174
|
targetNode['bpmn:incoming'] = edge.id;
|
|
121
175
|
}
|
|
@@ -123,23 +177,7 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
123
177
|
targetNode['bpmn:incoming'].push(edge.id);
|
|
124
178
|
}
|
|
125
179
|
else {
|
|
126
|
-
targetNode['bpmn:incoming'] = [
|
|
127
|
-
targetNode['bpmn:incoming'],
|
|
128
|
-
edge.id,
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
var sourceNode = nodeMap.get(edge.sourceNodeId);
|
|
132
|
-
if (!sourceNode['bpmn:outgoing']) {
|
|
133
|
-
sourceNode['bpmn:outgoing'] = edge.id;
|
|
134
|
-
}
|
|
135
|
-
else if (Array.isArray(sourceNode['bpmn:outgoing'])) {
|
|
136
|
-
sourceNode['bpmn:outgoing'].push(edge.id);
|
|
137
|
-
}
|
|
138
|
-
else { // 字符串转数组
|
|
139
|
-
sourceNode['bpmn:outgoing'] = [
|
|
140
|
-
sourceNode['bpmn:outgoing'],
|
|
141
|
-
edge.id,
|
|
142
|
-
];
|
|
180
|
+
targetNode['bpmn:incoming'] = [targetNode['bpmn:incoming'], edge.id];
|
|
143
181
|
}
|
|
144
182
|
var edgeConfig = {
|
|
145
183
|
'-id': edge.id,
|
|
@@ -150,11 +188,26 @@ function convertLf2ProcessData(bpmnProcessData, data) {
|
|
|
150
188
|
edgeConfig['-name'] = (_b = edge.text) === null || _b === void 0 ? void 0 : _b.value;
|
|
151
189
|
}
|
|
152
190
|
if (edge.properties) {
|
|
153
|
-
var properties = toXmlJson(edge.properties);
|
|
191
|
+
var properties = toXmlJson()(edge.properties);
|
|
154
192
|
Object.assign(edgeConfig, properties);
|
|
155
193
|
}
|
|
156
194
|
return edgeConfig;
|
|
157
195
|
});
|
|
196
|
+
// @see https://github.com/didi/LogicFlow/issues/325
|
|
197
|
+
// 需要保证incoming在outgoing之前
|
|
198
|
+
data.edges.forEach(function (edge) {
|
|
199
|
+
var sourceNode = nodeMap.get(edge.sourceNodeId);
|
|
200
|
+
if (!sourceNode['bpmn:outgoing']) {
|
|
201
|
+
sourceNode['bpmn:outgoing'] = edge.id;
|
|
202
|
+
}
|
|
203
|
+
else if (Array.isArray(sourceNode['bpmn:outgoing'])) {
|
|
204
|
+
sourceNode['bpmn:outgoing'].push(edge.id);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// 字符串转数组
|
|
208
|
+
sourceNode['bpmn:outgoing'] = [sourceNode['bpmn:outgoing'], edge.id];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
158
211
|
bpmnProcessData[BpmnElements.FLOW] = sequenceFlow;
|
|
159
212
|
}
|
|
160
213
|
/**
|
|
@@ -166,7 +219,10 @@ function convertLf2DiagramData(bpmnDiagramData, data) {
|
|
|
166
219
|
var edgeId = edge.id;
|
|
167
220
|
var pointsList = edge.pointsList.map(function (_a) {
|
|
168
221
|
var x = _a.x, y = _a.y;
|
|
169
|
-
return ({
|
|
222
|
+
return ({
|
|
223
|
+
'-x': x,
|
|
224
|
+
'-y': y,
|
|
225
|
+
});
|
|
170
226
|
});
|
|
171
227
|
var diagramData = {
|
|
172
228
|
'-id': edgeId + "_di",
|
|
@@ -252,7 +308,8 @@ function convertBpmn2LfData(bpmnData) {
|
|
|
252
308
|
}
|
|
253
309
|
function getLfNodes(value, shapes, key) {
|
|
254
310
|
var nodes = [];
|
|
255
|
-
if (Array.isArray(value)) {
|
|
311
|
+
if (Array.isArray(value)) {
|
|
312
|
+
// 数组
|
|
256
313
|
value.forEach(function (val) {
|
|
257
314
|
var shapeValue;
|
|
258
315
|
if (Array.isArray(shapes)) {
|
|
@@ -308,7 +365,8 @@ function getNodeConfig(shapeValue, type, processValue) {
|
|
|
308
365
|
value: name,
|
|
309
366
|
};
|
|
310
367
|
// 自定义文本位置
|
|
311
|
-
if (shapeValue['bpmndi:BPMNLabel']
|
|
368
|
+
if (shapeValue['bpmndi:BPMNLabel']
|
|
369
|
+
&& shapeValue['bpmndi:BPMNLabel']['dc:Bounds']) {
|
|
312
370
|
var textBounds = shapeValue['bpmndi:BPMNLabel']['dc:Bounds'];
|
|
313
371
|
text.x = Number(textBounds['-x']) + Number(textBounds['-width']) / 2;
|
|
314
372
|
text.y = Number(textBounds['-y']) + Number(textBounds['-height']) / 2;
|
|
@@ -399,53 +457,59 @@ function getEdgeConfig(edgeValue, processValue) {
|
|
|
399
457
|
}
|
|
400
458
|
return edge;
|
|
401
459
|
}
|
|
402
|
-
var BpmnAdapter = {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
lf
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
'
|
|
460
|
+
var BpmnAdapter = /** @class */ (function () {
|
|
461
|
+
function BpmnAdapter(_a) {
|
|
462
|
+
var _this = this;
|
|
463
|
+
var lf = _a.lf;
|
|
464
|
+
this.adapterOut = function (data) {
|
|
465
|
+
var bpmnProcessData = __assign({}, _this.processAttributes);
|
|
466
|
+
convertLf2ProcessData(bpmnProcessData, data);
|
|
467
|
+
var bpmnDiagramData = {
|
|
468
|
+
'-id': 'BPMNPlane_1',
|
|
469
|
+
'-bpmnElement': bpmnProcessData['-id'],
|
|
470
|
+
};
|
|
471
|
+
convertLf2DiagramData(bpmnDiagramData, data);
|
|
472
|
+
var definitions = _this.definitionAttributes;
|
|
473
|
+
definitions['bpmn:process'] = bpmnProcessData;
|
|
474
|
+
definitions['bpmndi:BPMNDiagram'] = {
|
|
475
|
+
'-id': 'BPMNDiagram_1',
|
|
476
|
+
'bpmndi:BPMNPlane': bpmnDiagramData,
|
|
477
|
+
};
|
|
478
|
+
var bpmnData = {
|
|
479
|
+
'bpmn:definitions': definitions,
|
|
480
|
+
};
|
|
481
|
+
return bpmnData;
|
|
416
482
|
};
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
483
|
+
this.adapterIn = function (bpmnData) {
|
|
484
|
+
if (bpmnData) {
|
|
485
|
+
return convertBpmn2LfData(bpmnData);
|
|
486
|
+
}
|
|
421
487
|
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
'-xmlns:bpmn': 'http://www.omg.org/spec/BPMN/20100524/MODEL',
|
|
428
|
-
'-xmlns:bpmndi': 'http://www.omg.org/spec/BPMN/20100524/DI',
|
|
429
|
-
'-xmlns:dc': 'http://www.omg.org/spec/DD/20100524/DC',
|
|
430
|
-
'-xmlns:di': 'http://www.omg.org/spec/DD/20100524/DI',
|
|
431
|
-
'-targetNamespace': 'http://bpmn.io/schema/bpmn',
|
|
432
|
-
'-exporter': 'bpmn-js (https://demo.bpmn.io)',
|
|
433
|
-
'-exporterVersion': '7.3.0',
|
|
434
|
-
'bpmn:process': bpmnProcessData,
|
|
435
|
-
'bpmndi:BPMNDiagram': {
|
|
436
|
-
'-id': 'BPMNDiagram_1',
|
|
437
|
-
'bpmndi:BPMNPlane': bpmnDiagramData,
|
|
438
|
-
},
|
|
439
|
-
},
|
|
488
|
+
lf.adapterIn = function (data) { return _this.adapterIn(data); };
|
|
489
|
+
lf.adapterOut = function (data) { return _this.adapterOut(data); };
|
|
490
|
+
this.processAttributes = {
|
|
491
|
+
'-isExecutable': 'true',
|
|
492
|
+
'-id': "Process_" + getBpmnId(),
|
|
440
493
|
};
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
494
|
+
this.definitionAttributes = {
|
|
495
|
+
'-id': "Definitions_" + getBpmnId(),
|
|
496
|
+
'-xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
497
|
+
'-xmlns:bpmn': 'http://www.omg.org/spec/BPMN/20100524/MODEL',
|
|
498
|
+
'-xmlns:bpmndi': 'http://www.omg.org/spec/BPMN/20100524/DI',
|
|
499
|
+
'-xmlns:dc': 'http://www.omg.org/spec/DD/20100524/DC',
|
|
500
|
+
'-xmlns:di': 'http://www.omg.org/spec/DD/20100524/DI',
|
|
501
|
+
'-targetNamespace': 'http://logic-flow.org',
|
|
502
|
+
'-exporter': 'logicflow',
|
|
503
|
+
'-exporterVersion': '1.2.0',
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
BpmnAdapter.prototype.setCustomShape = function (key, val) {
|
|
507
|
+
BpmnAdapter.shapeConfigMap.set(key, val);
|
|
508
|
+
};
|
|
509
|
+
BpmnAdapter.pluginName = 'bpmn-adapter';
|
|
510
|
+
BpmnAdapter.shapeConfigMap = new Map();
|
|
511
|
+
return BpmnAdapter;
|
|
512
|
+
}());
|
|
449
513
|
BpmnAdapter.shapeConfigMap.set(BpmnElements.START, {
|
|
450
514
|
width: StartEventConfig.width,
|
|
451
515
|
height: StartEventConfig.height,
|
|
@@ -466,20 +530,25 @@ BpmnAdapter.shapeConfigMap.set(BpmnElements.USER, {
|
|
|
466
530
|
width: UserTaskConfig.width,
|
|
467
531
|
height: UserTaskConfig.height,
|
|
468
532
|
});
|
|
469
|
-
var BpmnXmlAdapter = {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
533
|
+
var BpmnXmlAdapter = /** @class */ (function (_super) {
|
|
534
|
+
__extends(BpmnXmlAdapter, _super);
|
|
535
|
+
function BpmnXmlAdapter(data) {
|
|
536
|
+
var _this = _super.call(this, data) || this;
|
|
537
|
+
_this.adapterXmlIn = function (bpmnData) {
|
|
538
|
+
var json = lfXml2Json(bpmnData);
|
|
539
|
+
return _this.adapterIn(json);
|
|
540
|
+
};
|
|
541
|
+
_this.adapterXmlOut = function (data) {
|
|
542
|
+
var outData = _this.adapterOut(data);
|
|
543
|
+
return lfJson2Xml(outData);
|
|
544
|
+
};
|
|
545
|
+
var lf = data.lf;
|
|
546
|
+
lf.adapterIn = _this.adapterXmlIn;
|
|
547
|
+
lf.adapterOut = _this.adapterXmlOut;
|
|
548
|
+
return _this;
|
|
549
|
+
}
|
|
550
|
+
BpmnXmlAdapter.pluginName = 'bpmnXmlAdapter';
|
|
551
|
+
return BpmnXmlAdapter;
|
|
552
|
+
}(BpmnAdapter));
|
|
553
|
+
export { BpmnAdapter, BpmnXmlAdapter, toXmlJson, toNormalJson };
|
|
485
554
|
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 };
|