@jylups/flowable-bpmn-js 0.1.1 → 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 +198 -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 +198 -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 +198 -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 +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @jylups/flowable-bpmn-js 0.1.
|
|
1
|
+
/*! @jylups/flowable-bpmn-js 0.1.2 | MIT | bpmn-js (c) Camunda Services GmbH, bpmn.io license; keep the bpmn.io watermark visible */
|
|
2
2
|
var FlowableBpmnJS = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -26546,6 +26546,181 @@ var FlowableBpmnJS = (function () {
|
|
|
26546
26546
|
definition.$parent = definitions;
|
|
26547
26547
|
}
|
|
26548
26548
|
|
|
26549
|
+
/**
|
|
26550
|
+
* Keeps a Flowable model as it was written where bpmn-js would change it
|
|
26551
|
+
* although nothing was edited:
|
|
26552
|
+
*
|
|
26553
|
+
* - Expanded subprocesses: Flowable Design and the Flowable engine write an
|
|
26554
|
+
* expanded subprocess shape without `isExpanded`, which BPMN DI reads as
|
|
26555
|
+
* collapsed. bpmn-js would draw it closed and, on save, move its children's
|
|
26556
|
+
* shapes to a diagram of their own with new coordinates. A subprocess shape
|
|
26557
|
+
* without `isExpanded` whose children are drawn on the same plane, or which
|
|
26558
|
+
* has no children, is read as expanded; the attribute isn't written back.
|
|
26559
|
+
* - Exclusive gateway markers: bpmn-js sets `isMarkerVisible` on a gateway
|
|
26560
|
+
* shape that has none, so the marker shows as it does in Flowable. It isn't
|
|
26561
|
+
* written back where the model had no such attribute.
|
|
26562
|
+
* - Attributes with their default value, such as `typeLanguage`,
|
|
26563
|
+
* `expressionLanguage` or `isInterrupting="true"`: moddle doesn't write a
|
|
26564
|
+
* value equal to the default, so a model that states it would lose it. A
|
|
26565
|
+
* value the model sets (read from the file or set by an edit) is written,
|
|
26566
|
+
* even when it equals the default.
|
|
26567
|
+
*/
|
|
26568
|
+
|
|
26569
|
+
/**
|
|
26570
|
+
* Reads the subprocess and gateway shapes as Flowable does. Call it when
|
|
26571
|
+
* the model is parsed, before bpmn-js draws it.
|
|
26572
|
+
*
|
|
26573
|
+
* @param {ModdleElement} definitions
|
|
26574
|
+
*
|
|
26575
|
+
* @return {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} the
|
|
26576
|
+
* shapes that got `isExpanded`, and the gateway shapes without
|
|
26577
|
+
* `isMarkerVisible`, so saving can leave the attributes out again
|
|
26578
|
+
*/
|
|
26579
|
+
function readAsFlowable(definitions) {
|
|
26580
|
+
const expanded = new Set();
|
|
26581
|
+
const markers = new Set();
|
|
26582
|
+
|
|
26583
|
+
const planes = (definitions.get('diagrams') || [])
|
|
26584
|
+
.map(diagram => diagram.plane)
|
|
26585
|
+
.filter(Boolean);
|
|
26586
|
+
|
|
26587
|
+
for (const plane of planes) {
|
|
26588
|
+
const shapes = (plane.get('planeElement') || []).filter(di => di.$instanceOf('bpmndi:BPMNShape'));
|
|
26589
|
+
const drawn = new Set(shapes.map(di => di.bpmnElement).filter(Boolean));
|
|
26590
|
+
|
|
26591
|
+
for (const di of shapes) {
|
|
26592
|
+
const element = di.bpmnElement;
|
|
26593
|
+
|
|
26594
|
+
if (!element) {
|
|
26595
|
+
continue;
|
|
26596
|
+
}
|
|
26597
|
+
|
|
26598
|
+
if (element.$instanceOf('bpmn:SubProcess') && !hasOwn(di, 'isExpanded') && isDrawnExpanded(element, drawn)) {
|
|
26599
|
+
di.isExpanded = true;
|
|
26600
|
+
expanded.add(di);
|
|
26601
|
+
}
|
|
26602
|
+
|
|
26603
|
+
if (element.$instanceOf('bpmn:ExclusiveGateway') && !hasOwn(di, 'isMarkerVisible')) {
|
|
26604
|
+
markers.add(di);
|
|
26605
|
+
}
|
|
26606
|
+
}
|
|
26607
|
+
}
|
|
26608
|
+
|
|
26609
|
+
return { expanded, markers };
|
|
26610
|
+
}
|
|
26611
|
+
|
|
26612
|
+
/**
|
|
26613
|
+
* Prepares the model to be written as it was read (see the module comment).
|
|
26614
|
+
* Call it when saving starts, and the returned function when saving is done.
|
|
26615
|
+
*
|
|
26616
|
+
* @param {ModdleElement} definitions
|
|
26617
|
+
* @param {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} read
|
|
26618
|
+
* what readAsFlowable returned
|
|
26619
|
+
*
|
|
26620
|
+
* @return {Function} restores the model as the editor uses it
|
|
26621
|
+
*/
|
|
26622
|
+
function writeAsRead(definitions, { expanded, markers }) {
|
|
26623
|
+
const restore = [];
|
|
26624
|
+
|
|
26625
|
+
// leave out what reading added, while it still has the value reading gave it
|
|
26626
|
+
for (const di of expanded) {
|
|
26627
|
+
leaveOut(di, 'isExpanded', true, restore);
|
|
26628
|
+
}
|
|
26629
|
+
|
|
26630
|
+
for (const di of markers) {
|
|
26631
|
+
leaveOut(di, 'isMarkerVisible', true, restore);
|
|
26632
|
+
}
|
|
26633
|
+
|
|
26634
|
+
// write values that equal the default as generic attributes, which moddle always writes
|
|
26635
|
+
forEachElement(definitions, element => {
|
|
26636
|
+
for (const property of element.$descriptor.properties) {
|
|
26637
|
+
if (!property.isAttr || property.isMany || property.default === undefined) {
|
|
26638
|
+
continue;
|
|
26639
|
+
}
|
|
26640
|
+
|
|
26641
|
+
if (!hasOwn(element, property.name) || element[property.name] !== property.default) {
|
|
26642
|
+
continue;
|
|
26643
|
+
}
|
|
26644
|
+
|
|
26645
|
+
const name = attributeName(element, property);
|
|
26646
|
+
const attrs = element.$attrs;
|
|
26647
|
+
|
|
26648
|
+
if (attrs[name] === undefined) {
|
|
26649
|
+
attrs[name] = String(property.default);
|
|
26650
|
+
restore.push(() => delete attrs[name]);
|
|
26651
|
+
}
|
|
26652
|
+
}
|
|
26653
|
+
});
|
|
26654
|
+
|
|
26655
|
+
return function() {
|
|
26656
|
+
restore.reverse().forEach(fn => fn());
|
|
26657
|
+
};
|
|
26658
|
+
}
|
|
26659
|
+
|
|
26660
|
+
|
|
26661
|
+
function isDrawnExpanded(subProcess, drawn) {
|
|
26662
|
+
const children = [
|
|
26663
|
+
...(subProcess.get('flowElements') || []),
|
|
26664
|
+
...(subProcess.get('artifacts') || [])
|
|
26665
|
+
];
|
|
26666
|
+
|
|
26667
|
+
return !children.length || children.some(child => drawn.has(child));
|
|
26668
|
+
}
|
|
26669
|
+
|
|
26670
|
+
function leaveOut(element, name, value, restore) {
|
|
26671
|
+
if (element[name] === value) {
|
|
26672
|
+
delete element[name];
|
|
26673
|
+
restore.push(() => {
|
|
26674
|
+
element[name] = value;
|
|
26675
|
+
});
|
|
26676
|
+
}
|
|
26677
|
+
}
|
|
26678
|
+
|
|
26679
|
+
/**
|
|
26680
|
+
* The name the attribute has in the XML: without a prefix in the element's
|
|
26681
|
+
* own namespace, with its prefix in another one (an extension attribute).
|
|
26682
|
+
*/
|
|
26683
|
+
function attributeName(element, property) {
|
|
26684
|
+
const ns = property.ns;
|
|
26685
|
+
|
|
26686
|
+
return ns.prefix === element.$descriptor.ns.prefix ? ns.localName : ns.prefix + ':' + ns.localName;
|
|
26687
|
+
}
|
|
26688
|
+
|
|
26689
|
+
/**
|
|
26690
|
+
* Calls fn for the element and every model element it contains (not the
|
|
26691
|
+
* ones it refers to).
|
|
26692
|
+
*/
|
|
26693
|
+
function forEachElement(element, fn, seen = new Set()) {
|
|
26694
|
+
if (!isModdleElement(element) || seen.has(element)) {
|
|
26695
|
+
return;
|
|
26696
|
+
}
|
|
26697
|
+
|
|
26698
|
+
seen.add(element);
|
|
26699
|
+
fn(element);
|
|
26700
|
+
|
|
26701
|
+
for (const property of element.$descriptor.properties) {
|
|
26702
|
+
if (property.isReference || property.isAttr) {
|
|
26703
|
+
continue;
|
|
26704
|
+
}
|
|
26705
|
+
|
|
26706
|
+
const value = element[property.name];
|
|
26707
|
+
|
|
26708
|
+
if (Array.isArray(value)) {
|
|
26709
|
+
value.forEach(child => forEachElement(child, fn, seen));
|
|
26710
|
+
} else {
|
|
26711
|
+
forEachElement(value, fn, seen);
|
|
26712
|
+
}
|
|
26713
|
+
}
|
|
26714
|
+
}
|
|
26715
|
+
|
|
26716
|
+
function isModdleElement(value) {
|
|
26717
|
+
return !!value && typeof value === 'object' && !!value.$descriptor && !!value.$attrs;
|
|
26718
|
+
}
|
|
26719
|
+
|
|
26720
|
+
function hasOwn(object, name) {
|
|
26721
|
+
return Object.prototype.hasOwnProperty.call(object, name);
|
|
26722
|
+
}
|
|
26723
|
+
|
|
26549
26724
|
/**
|
|
26550
26725
|
* Runs before bpmn-js claims the imported IDs, so created definitions are
|
|
26551
26726
|
* claimed too.
|
|
@@ -26564,11 +26739,17 @@ var FlowableBpmnJS = (function () {
|
|
|
26564
26739
|
* signal or escalation they stand for (createMissingDefinitions from the
|
|
26565
26740
|
* behaviors package), in the viewers too;
|
|
26566
26741
|
* - on save, other prefixes bound to the Flowable namespace are dropped, so
|
|
26567
|
-
* everything is written as flowable: (useFlowablePrefix)
|
|
26742
|
+
* everything is written as flowable: (useFlowablePrefix);
|
|
26743
|
+
* - an unedited model is written as it was read: expanded subprocesses
|
|
26744
|
+
* without `isExpanded`, gateway markers and attributes with their default
|
|
26745
|
+
* value stay as the file had them (see WriteAsRead.js).
|
|
26568
26746
|
*/
|
|
26569
26747
|
class FlowableXML {
|
|
26570
26748
|
|
|
26571
26749
|
constructor(eventBus, moddle) {
|
|
26750
|
+
let read = { expanded: new Set(), markers: new Set() };
|
|
26751
|
+
let restore = null;
|
|
26752
|
+
|
|
26572
26753
|
eventBus.on('import.parse.start', ({ xml }) => {
|
|
26573
26754
|
const migrated = migrateActivitiXML(xml);
|
|
26574
26755
|
|
|
@@ -26580,10 +26761,24 @@ var FlowableBpmnJS = (function () {
|
|
|
26580
26761
|
eventBus.on('import.parse.complete', HIGH_PRIORITY$1, ({ error, definitions, warnings, elementsById }) => {
|
|
26581
26762
|
if (!error && definitions) {
|
|
26582
26763
|
createMissingDefinitions(definitions, { warnings, elementsById });
|
|
26764
|
+
|
|
26765
|
+
// before bpmn-js draws the model (and moves the shapes of collapsed subprocesses)
|
|
26766
|
+
read = readAsFlowable(definitions);
|
|
26583
26767
|
}
|
|
26584
26768
|
});
|
|
26585
26769
|
|
|
26586
|
-
eventBus.on('saveXML.start', ({ definitions }) =>
|
|
26770
|
+
eventBus.on('saveXML.start', ({ definitions }) => {
|
|
26771
|
+
useFlowablePrefix(definitions);
|
|
26772
|
+
|
|
26773
|
+
restore = writeAsRead(definitions, read);
|
|
26774
|
+
});
|
|
26775
|
+
|
|
26776
|
+
eventBus.on('saveXML.done', () => {
|
|
26777
|
+
if (restore) {
|
|
26778
|
+
restore();
|
|
26779
|
+
restore = null;
|
|
26780
|
+
}
|
|
26781
|
+
});
|
|
26587
26782
|
}
|
|
26588
26783
|
}
|
|
26589
26784
|
|