@jylups/flowable-bpmn-js 0.1.0 → 0.1.2
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/README.md +1 -0
- package/dist/flowable-bpmn-modeler.development.js +295 -3
- package/dist/flowable-bpmn-modeler.development.js.map +1 -1
- package/dist/flowable-bpmn-modeler.production.min.js +2 -2
- package/dist/flowable-bpmn-navigated-viewer.development.js +295 -3
- package/dist/flowable-bpmn-navigated-viewer.development.js.map +1 -1
- package/dist/flowable-bpmn-navigated-viewer.production.min.js +2 -2
- package/dist/flowable-bpmn-viewer.development.js +295 -3
- package/dist/flowable-bpmn-viewer.development.js.map +1 -1
- package/dist/flowable-bpmn-viewer.production.min.js +2 -2
- package/lib/xml/FlowableXML.js +24 -2
- package/lib/xml/WriteAsRead.js +174 -0
- package/package.json +2 -2
package/lib/xml/FlowableXML.js
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
|
|
7
7
|
import { createMissingDefinitions } from '@jylups/flowable-bpmn-js-behaviors/missing-definitions';
|
|
8
8
|
|
|
9
|
+
import { readAsFlowable, writeAsRead } from './WriteAsRead.js';
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* Runs before bpmn-js claims the imported IDs, so created definitions are
|
|
11
13
|
* claimed too.
|
|
@@ -24,11 +26,17 @@ const HIGH_PRIORITY = 1500;
|
|
|
24
26
|
* signal or escalation they stand for (createMissingDefinitions from the
|
|
25
27
|
* behaviors package), in the viewers too;
|
|
26
28
|
* - on save, other prefixes bound to the Flowable namespace are dropped, so
|
|
27
|
-
* everything is written as flowable: (useFlowablePrefix)
|
|
29
|
+
* everything is written as flowable: (useFlowablePrefix);
|
|
30
|
+
* - an unedited model is written as it was read: expanded subprocesses
|
|
31
|
+
* without `isExpanded`, gateway markers and attributes with their default
|
|
32
|
+
* value stay as the file had them (see WriteAsRead.js).
|
|
28
33
|
*/
|
|
29
34
|
export default class FlowableXML {
|
|
30
35
|
|
|
31
36
|
constructor(eventBus, moddle) {
|
|
37
|
+
let read = { expanded: new Set(), markers: new Set() };
|
|
38
|
+
let restore = null;
|
|
39
|
+
|
|
32
40
|
eventBus.on('import.parse.start', ({ xml }) => {
|
|
33
41
|
const migrated = migrateActivitiXML(xml);
|
|
34
42
|
|
|
@@ -40,10 +48,24 @@ export default class FlowableXML {
|
|
|
40
48
|
eventBus.on('import.parse.complete', HIGH_PRIORITY, ({ error, definitions, warnings, elementsById }) => {
|
|
41
49
|
if (!error && definitions) {
|
|
42
50
|
createMissingDefinitions(definitions, { warnings, elementsById });
|
|
51
|
+
|
|
52
|
+
// before bpmn-js draws the model (and moves the shapes of collapsed subprocesses)
|
|
53
|
+
read = readAsFlowable(definitions);
|
|
43
54
|
}
|
|
44
55
|
});
|
|
45
56
|
|
|
46
|
-
eventBus.on('saveXML.start', ({ definitions }) =>
|
|
57
|
+
eventBus.on('saveXML.start', ({ definitions }) => {
|
|
58
|
+
useFlowablePrefix(definitions);
|
|
59
|
+
|
|
60
|
+
restore = writeAsRead(definitions, read);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
eventBus.on('saveXML.done', () => {
|
|
64
|
+
if (restore) {
|
|
65
|
+
restore();
|
|
66
|
+
restore = null;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
47
69
|
}
|
|
48
70
|
}
|
|
49
71
|
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps a Flowable model as it was written where bpmn-js would change it
|
|
3
|
+
* although nothing was edited:
|
|
4
|
+
*
|
|
5
|
+
* - Expanded subprocesses: Flowable Design and the Flowable engine write an
|
|
6
|
+
* expanded subprocess shape without `isExpanded`, which BPMN DI reads as
|
|
7
|
+
* collapsed. bpmn-js would draw it closed and, on save, move its children's
|
|
8
|
+
* shapes to a diagram of their own with new coordinates. A subprocess shape
|
|
9
|
+
* without `isExpanded` whose children are drawn on the same plane, or which
|
|
10
|
+
* has no children, is read as expanded; the attribute isn't written back.
|
|
11
|
+
* - Exclusive gateway markers: bpmn-js sets `isMarkerVisible` on a gateway
|
|
12
|
+
* shape that has none, so the marker shows as it does in Flowable. It isn't
|
|
13
|
+
* written back where the model had no such attribute.
|
|
14
|
+
* - Attributes with their default value, such as `typeLanguage`,
|
|
15
|
+
* `expressionLanguage` or `isInterrupting="true"`: moddle doesn't write a
|
|
16
|
+
* value equal to the default, so a model that states it would lose it. A
|
|
17
|
+
* value the model sets (read from the file or set by an edit) is written,
|
|
18
|
+
* even when it equals the default.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reads the subprocess and gateway shapes as Flowable does. Call it when
|
|
23
|
+
* the model is parsed, before bpmn-js draws it.
|
|
24
|
+
*
|
|
25
|
+
* @param {ModdleElement} definitions
|
|
26
|
+
*
|
|
27
|
+
* @return {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} the
|
|
28
|
+
* shapes that got `isExpanded`, and the gateway shapes without
|
|
29
|
+
* `isMarkerVisible`, so saving can leave the attributes out again
|
|
30
|
+
*/
|
|
31
|
+
export function readAsFlowable(definitions) {
|
|
32
|
+
const expanded = new Set();
|
|
33
|
+
const markers = new Set();
|
|
34
|
+
|
|
35
|
+
const planes = (definitions.get('diagrams') || [])
|
|
36
|
+
.map(diagram => diagram.plane)
|
|
37
|
+
.filter(Boolean);
|
|
38
|
+
|
|
39
|
+
for (const plane of planes) {
|
|
40
|
+
const shapes = (plane.get('planeElement') || []).filter(di => di.$instanceOf('bpmndi:BPMNShape'));
|
|
41
|
+
const drawn = new Set(shapes.map(di => di.bpmnElement).filter(Boolean));
|
|
42
|
+
|
|
43
|
+
for (const di of shapes) {
|
|
44
|
+
const element = di.bpmnElement;
|
|
45
|
+
|
|
46
|
+
if (!element) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (element.$instanceOf('bpmn:SubProcess') && !hasOwn(di, 'isExpanded') && isDrawnExpanded(element, drawn)) {
|
|
51
|
+
di.isExpanded = true;
|
|
52
|
+
expanded.add(di);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (element.$instanceOf('bpmn:ExclusiveGateway') && !hasOwn(di, 'isMarkerVisible')) {
|
|
56
|
+
markers.add(di);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { expanded, markers };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Prepares the model to be written as it was read (see the module comment).
|
|
66
|
+
* Call it when saving starts, and the returned function when saving is done.
|
|
67
|
+
*
|
|
68
|
+
* @param {ModdleElement} definitions
|
|
69
|
+
* @param {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} read
|
|
70
|
+
* what readAsFlowable returned
|
|
71
|
+
*
|
|
72
|
+
* @return {Function} restores the model as the editor uses it
|
|
73
|
+
*/
|
|
74
|
+
export function writeAsRead(definitions, { expanded, markers }) {
|
|
75
|
+
const restore = [];
|
|
76
|
+
|
|
77
|
+
// leave out what reading added, while it still has the value reading gave it
|
|
78
|
+
for (const di of expanded) {
|
|
79
|
+
leaveOut(di, 'isExpanded', true, restore);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (const di of markers) {
|
|
83
|
+
leaveOut(di, 'isMarkerVisible', true, restore);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// write values that equal the default as generic attributes, which moddle always writes
|
|
87
|
+
forEachElement(definitions, element => {
|
|
88
|
+
for (const property of element.$descriptor.properties) {
|
|
89
|
+
if (!property.isAttr || property.isMany || property.default === undefined) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!hasOwn(element, property.name) || element[property.name] !== property.default) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const name = attributeName(element, property);
|
|
98
|
+
const attrs = element.$attrs;
|
|
99
|
+
|
|
100
|
+
if (attrs[name] === undefined) {
|
|
101
|
+
attrs[name] = String(property.default);
|
|
102
|
+
restore.push(() => delete attrs[name]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return function() {
|
|
108
|
+
restore.reverse().forEach(fn => fn());
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
function isDrawnExpanded(subProcess, drawn) {
|
|
114
|
+
const children = [
|
|
115
|
+
...(subProcess.get('flowElements') || []),
|
|
116
|
+
...(subProcess.get('artifacts') || [])
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
return !children.length || children.some(child => drawn.has(child));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function leaveOut(element, name, value, restore) {
|
|
123
|
+
if (element[name] === value) {
|
|
124
|
+
delete element[name];
|
|
125
|
+
restore.push(() => {
|
|
126
|
+
element[name] = value;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The name the attribute has in the XML: without a prefix in the element's
|
|
133
|
+
* own namespace, with its prefix in another one (an extension attribute).
|
|
134
|
+
*/
|
|
135
|
+
function attributeName(element, property) {
|
|
136
|
+
const ns = property.ns;
|
|
137
|
+
|
|
138
|
+
return ns.prefix === element.$descriptor.ns.prefix ? ns.localName : ns.prefix + ':' + ns.localName;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Calls fn for the element and every model element it contains (not the
|
|
143
|
+
* ones it refers to).
|
|
144
|
+
*/
|
|
145
|
+
function forEachElement(element, fn, seen = new Set()) {
|
|
146
|
+
if (!isModdleElement(element) || seen.has(element)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
seen.add(element);
|
|
151
|
+
fn(element);
|
|
152
|
+
|
|
153
|
+
for (const property of element.$descriptor.properties) {
|
|
154
|
+
if (property.isReference || property.isAttr) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const value = element[property.name];
|
|
159
|
+
|
|
160
|
+
if (Array.isArray(value)) {
|
|
161
|
+
value.forEach(child => forEachElement(child, fn, seen));
|
|
162
|
+
} else {
|
|
163
|
+
forEachElement(value, fn, seen);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function isModdleElement(value) {
|
|
169
|
+
return !!value && typeof value === 'object' && !!value.$descriptor && !!value.$attrs;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function hasOwn(object, name) {
|
|
173
|
+
return Object.prototype.hasOwnProperty.call(object, name);
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jylups/flowable-bpmn-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "bpmn-js modeler and viewer with the Flowable BPMN extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@bpmn-io/properties-panel": "^3.60.2",
|
|
57
57
|
"@jylups/bpmn-js-properties-panel-flowable": "^0.1.0",
|
|
58
58
|
"@jylups/flowable-bpmn-js-behaviors": "^0.1.0",
|
|
59
|
-
"@jylups/flowable-bpmn-moddle": "^0.1.
|
|
59
|
+
"@jylups/flowable-bpmn-moddle": "^0.1.1",
|
|
60
60
|
"bpmn-js": "^18.33.1",
|
|
61
61
|
"bpmn-js-bpmnlint": "^0.25.0",
|
|
62
62
|
"bpmn-js-properties-panel": "^5.65.4",
|