@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.
@@ -1,4 +1,4 @@
1
- /*! @jylups/flowable-bpmn-js 0.1.0 | MIT | bpmn-js (c) Camunda Services GmbH, bpmn.io license; keep the bpmn.io watermark visible */
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
 
@@ -26104,6 +26104,103 @@ var FlowableBpmnJS = (function () {
26104
26104
  }
26105
26105
  ]
26106
26106
  },
26107
+ {
26108
+ name: "Condition",
26109
+ superClass: [
26110
+ "Element"
26111
+ ],
26112
+ meta: {
26113
+ allowedIn: [
26114
+ "bpmn:BaseElement"
26115
+ ]
26116
+ },
26117
+ properties: [
26118
+ {
26119
+ name: "group",
26120
+ isAttr: true,
26121
+ type: "Boolean"
26122
+ },
26123
+ {
26124
+ name: "match",
26125
+ isAttr: true,
26126
+ type: "String"
26127
+ },
26128
+ {
26129
+ name: "targetAttribute",
26130
+ isAttr: true,
26131
+ type: "String"
26132
+ },
26133
+ {
26134
+ name: "sourceVariableType",
26135
+ isAttr: true,
26136
+ type: "String"
26137
+ },
26138
+ {
26139
+ name: "sourceName",
26140
+ isAttr: true,
26141
+ type: "String"
26142
+ },
26143
+ {
26144
+ name: "sourceType",
26145
+ isAttr: true,
26146
+ type: "String"
26147
+ },
26148
+ {
26149
+ name: "operator",
26150
+ isAttr: true,
26151
+ type: "String"
26152
+ },
26153
+ {
26154
+ name: "targetVariableType",
26155
+ isAttr: true,
26156
+ type: "String"
26157
+ },
26158
+ {
26159
+ name: "targetValue",
26160
+ isAttr: true,
26161
+ type: "String"
26162
+ },
26163
+ {
26164
+ name: "targetType",
26165
+ isAttr: true,
26166
+ type: "String"
26167
+ },
26168
+ {
26169
+ name: "conditions",
26170
+ type: "Condition",
26171
+ isMany: true
26172
+ }
26173
+ ]
26174
+ },
26175
+ {
26176
+ name: "EdgeDockers",
26177
+ isAbstract: true,
26178
+ "extends": [
26179
+ "di:LabeledEdge"
26180
+ ],
26181
+ properties: [
26182
+ {
26183
+ name: "sourceDockerX",
26184
+ isAttr: true,
26185
+ type: "String"
26186
+ },
26187
+ {
26188
+ name: "sourceDockerY",
26189
+ isAttr: true,
26190
+ type: "String"
26191
+ },
26192
+ {
26193
+ name: "targetDockerX",
26194
+ isAttr: true,
26195
+ type: "String"
26196
+ },
26197
+ {
26198
+ name: "targetDockerY",
26199
+ isAttr: true,
26200
+ type: "String"
26201
+ }
26202
+ ]
26203
+ },
26107
26204
  {
26108
26205
  name: "ItemAwareElement",
26109
26206
  isAbstract: true,
@@ -26449,6 +26546,181 @@ var FlowableBpmnJS = (function () {
26449
26546
  definition.$parent = definitions;
26450
26547
  }
26451
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
+
26452
26724
  /**
26453
26725
  * Runs before bpmn-js claims the imported IDs, so created definitions are
26454
26726
  * claimed too.
@@ -26467,11 +26739,17 @@ var FlowableBpmnJS = (function () {
26467
26739
  * signal or escalation they stand for (createMissingDefinitions from the
26468
26740
  * behaviors package), in the viewers too;
26469
26741
  * - on save, other prefixes bound to the Flowable namespace are dropped, so
26470
- * 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).
26471
26746
  */
26472
26747
  class FlowableXML {
26473
26748
 
26474
26749
  constructor(eventBus, moddle) {
26750
+ let read = { expanded: new Set(), markers: new Set() };
26751
+ let restore = null;
26752
+
26475
26753
  eventBus.on('import.parse.start', ({ xml }) => {
26476
26754
  const migrated = migrateActivitiXML(xml);
26477
26755
 
@@ -26483,10 +26761,24 @@ var FlowableBpmnJS = (function () {
26483
26761
  eventBus.on('import.parse.complete', HIGH_PRIORITY$1, ({ error, definitions, warnings, elementsById }) => {
26484
26762
  if (!error && definitions) {
26485
26763
  createMissingDefinitions(definitions, { warnings, elementsById });
26764
+
26765
+ // before bpmn-js draws the model (and moves the shapes of collapsed subprocesses)
26766
+ read = readAsFlowable(definitions);
26486
26767
  }
26487
26768
  });
26488
26769
 
26489
- eventBus.on('saveXML.start', ({ definitions }) => useFlowablePrefix(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
+ });
26490
26782
  }
26491
26783
  }
26492
26784