@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 CHANGED
@@ -24,6 +24,7 @@ All three read and write models as Flowable needs them:
24
24
  - **Unknown elements:** `flowable:*` elements the descriptor doesn't define are kept.
25
25
  - **References by code or name:** an `errorRef`, `messageRef`, `signalRef` or `escalationRef` gets the definition Flowable reads it as.
26
26
  - **Saving:** everything is written with the `flowable` prefix.
27
+ - **As read:** an unedited model is saved as it was read. A subprocess shape without `isExpanded` (as Flowable Design writes expanded subprocesses) opens expanded when its children are drawn with it, and isn't given the attribute; gateway shapes aren't given `isMarkerVisible`; values equal to the default, such as `typeLanguage` or `isInterrupting="true"`, are kept.
27
28
 
28
29
  They take the same options as their bpmn-js counterparts. `moddleExtensions` and `additionalModules` add to what is built in.
29
30
 
@@ -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
 
@@ -125312,6 +125312,103 @@ var FlowableBpmnJS = (function () {
125312
125312
  }
125313
125313
  ]
125314
125314
  },
125315
+ {
125316
+ name: "Condition",
125317
+ superClass: [
125318
+ "Element"
125319
+ ],
125320
+ meta: {
125321
+ allowedIn: [
125322
+ "bpmn:BaseElement"
125323
+ ]
125324
+ },
125325
+ properties: [
125326
+ {
125327
+ name: "group",
125328
+ isAttr: true,
125329
+ type: "Boolean"
125330
+ },
125331
+ {
125332
+ name: "match",
125333
+ isAttr: true,
125334
+ type: "String"
125335
+ },
125336
+ {
125337
+ name: "targetAttribute",
125338
+ isAttr: true,
125339
+ type: "String"
125340
+ },
125341
+ {
125342
+ name: "sourceVariableType",
125343
+ isAttr: true,
125344
+ type: "String"
125345
+ },
125346
+ {
125347
+ name: "sourceName",
125348
+ isAttr: true,
125349
+ type: "String"
125350
+ },
125351
+ {
125352
+ name: "sourceType",
125353
+ isAttr: true,
125354
+ type: "String"
125355
+ },
125356
+ {
125357
+ name: "operator",
125358
+ isAttr: true,
125359
+ type: "String"
125360
+ },
125361
+ {
125362
+ name: "targetVariableType",
125363
+ isAttr: true,
125364
+ type: "String"
125365
+ },
125366
+ {
125367
+ name: "targetValue",
125368
+ isAttr: true,
125369
+ type: "String"
125370
+ },
125371
+ {
125372
+ name: "targetType",
125373
+ isAttr: true,
125374
+ type: "String"
125375
+ },
125376
+ {
125377
+ name: "conditions",
125378
+ type: "Condition",
125379
+ isMany: true
125380
+ }
125381
+ ]
125382
+ },
125383
+ {
125384
+ name: "EdgeDockers",
125385
+ isAbstract: true,
125386
+ "extends": [
125387
+ "di:LabeledEdge"
125388
+ ],
125389
+ properties: [
125390
+ {
125391
+ name: "sourceDockerX",
125392
+ isAttr: true,
125393
+ type: "String"
125394
+ },
125395
+ {
125396
+ name: "sourceDockerY",
125397
+ isAttr: true,
125398
+ type: "String"
125399
+ },
125400
+ {
125401
+ name: "targetDockerX",
125402
+ isAttr: true,
125403
+ type: "String"
125404
+ },
125405
+ {
125406
+ name: "targetDockerY",
125407
+ isAttr: true,
125408
+ type: "String"
125409
+ }
125410
+ ]
125411
+ },
125315
125412
  {
125316
125413
  name: "ItemAwareElement",
125317
125414
  isAbstract: true,
@@ -125485,6 +125582,181 @@ var FlowableBpmnJS = (function () {
125485
125582
  return value.replace(/[.*+?^${}()|[\]\\-]/g, '\\$&');
125486
125583
  }
125487
125584
 
125585
+ /**
125586
+ * Keeps a Flowable model as it was written where bpmn-js would change it
125587
+ * although nothing was edited:
125588
+ *
125589
+ * - Expanded subprocesses: Flowable Design and the Flowable engine write an
125590
+ * expanded subprocess shape without `isExpanded`, which BPMN DI reads as
125591
+ * collapsed. bpmn-js would draw it closed and, on save, move its children's
125592
+ * shapes to a diagram of their own with new coordinates. A subprocess shape
125593
+ * without `isExpanded` whose children are drawn on the same plane, or which
125594
+ * has no children, is read as expanded; the attribute isn't written back.
125595
+ * - Exclusive gateway markers: bpmn-js sets `isMarkerVisible` on a gateway
125596
+ * shape that has none, so the marker shows as it does in Flowable. It isn't
125597
+ * written back where the model had no such attribute.
125598
+ * - Attributes with their default value, such as `typeLanguage`,
125599
+ * `expressionLanguage` or `isInterrupting="true"`: moddle doesn't write a
125600
+ * value equal to the default, so a model that states it would lose it. A
125601
+ * value the model sets (read from the file or set by an edit) is written,
125602
+ * even when it equals the default.
125603
+ */
125604
+
125605
+ /**
125606
+ * Reads the subprocess and gateway shapes as Flowable does. Call it when
125607
+ * the model is parsed, before bpmn-js draws it.
125608
+ *
125609
+ * @param {ModdleElement} definitions
125610
+ *
125611
+ * @return {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} the
125612
+ * shapes that got `isExpanded`, and the gateway shapes without
125613
+ * `isMarkerVisible`, so saving can leave the attributes out again
125614
+ */
125615
+ function readAsFlowable(definitions) {
125616
+ const expanded = new Set();
125617
+ const markers = new Set();
125618
+
125619
+ const planes = (definitions.get('diagrams') || [])
125620
+ .map(diagram => diagram.plane)
125621
+ .filter(Boolean);
125622
+
125623
+ for (const plane of planes) {
125624
+ const shapes = (plane.get('planeElement') || []).filter(di => di.$instanceOf('bpmndi:BPMNShape'));
125625
+ const drawn = new Set(shapes.map(di => di.bpmnElement).filter(Boolean));
125626
+
125627
+ for (const di of shapes) {
125628
+ const element = di.bpmnElement;
125629
+
125630
+ if (!element) {
125631
+ continue;
125632
+ }
125633
+
125634
+ if (element.$instanceOf('bpmn:SubProcess') && !hasOwn(di, 'isExpanded') && isDrawnExpanded(element, drawn)) {
125635
+ di.isExpanded = true;
125636
+ expanded.add(di);
125637
+ }
125638
+
125639
+ if (element.$instanceOf('bpmn:ExclusiveGateway') && !hasOwn(di, 'isMarkerVisible')) {
125640
+ markers.add(di);
125641
+ }
125642
+ }
125643
+ }
125644
+
125645
+ return { expanded, markers };
125646
+ }
125647
+
125648
+ /**
125649
+ * Prepares the model to be written as it was read (see the module comment).
125650
+ * Call it when saving starts, and the returned function when saving is done.
125651
+ *
125652
+ * @param {ModdleElement} definitions
125653
+ * @param {{ expanded: Set<ModdleElement>, markers: Set<ModdleElement> }} read
125654
+ * what readAsFlowable returned
125655
+ *
125656
+ * @return {Function} restores the model as the editor uses it
125657
+ */
125658
+ function writeAsRead(definitions, { expanded, markers }) {
125659
+ const restore = [];
125660
+
125661
+ // leave out what reading added, while it still has the value reading gave it
125662
+ for (const di of expanded) {
125663
+ leaveOut(di, 'isExpanded', true, restore);
125664
+ }
125665
+
125666
+ for (const di of markers) {
125667
+ leaveOut(di, 'isMarkerVisible', true, restore);
125668
+ }
125669
+
125670
+ // write values that equal the default as generic attributes, which moddle always writes
125671
+ forEachElement(definitions, element => {
125672
+ for (const property of element.$descriptor.properties) {
125673
+ if (!property.isAttr || property.isMany || property.default === undefined) {
125674
+ continue;
125675
+ }
125676
+
125677
+ if (!hasOwn(element, property.name) || element[property.name] !== property.default) {
125678
+ continue;
125679
+ }
125680
+
125681
+ const name = attributeName(element, property);
125682
+ const attrs = element.$attrs;
125683
+
125684
+ if (attrs[name] === undefined) {
125685
+ attrs[name] = String(property.default);
125686
+ restore.push(() => delete attrs[name]);
125687
+ }
125688
+ }
125689
+ });
125690
+
125691
+ return function() {
125692
+ restore.reverse().forEach(fn => fn());
125693
+ };
125694
+ }
125695
+
125696
+
125697
+ function isDrawnExpanded(subProcess, drawn) {
125698
+ const children = [
125699
+ ...(subProcess.get('flowElements') || []),
125700
+ ...(subProcess.get('artifacts') || [])
125701
+ ];
125702
+
125703
+ return !children.length || children.some(child => drawn.has(child));
125704
+ }
125705
+
125706
+ function leaveOut(element, name, value, restore) {
125707
+ if (element[name] === value) {
125708
+ delete element[name];
125709
+ restore.push(() => {
125710
+ element[name] = value;
125711
+ });
125712
+ }
125713
+ }
125714
+
125715
+ /**
125716
+ * The name the attribute has in the XML: without a prefix in the element's
125717
+ * own namespace, with its prefix in another one (an extension attribute).
125718
+ */
125719
+ function attributeName(element, property) {
125720
+ const ns = property.ns;
125721
+
125722
+ return ns.prefix === element.$descriptor.ns.prefix ? ns.localName : ns.prefix + ':' + ns.localName;
125723
+ }
125724
+
125725
+ /**
125726
+ * Calls fn for the element and every model element it contains (not the
125727
+ * ones it refers to).
125728
+ */
125729
+ function forEachElement(element, fn, seen = new Set()) {
125730
+ if (!isModdleElement(element) || seen.has(element)) {
125731
+ return;
125732
+ }
125733
+
125734
+ seen.add(element);
125735
+ fn(element);
125736
+
125737
+ for (const property of element.$descriptor.properties) {
125738
+ if (property.isReference || property.isAttr) {
125739
+ continue;
125740
+ }
125741
+
125742
+ const value = element[property.name];
125743
+
125744
+ if (Array.isArray(value)) {
125745
+ value.forEach(child => forEachElement(child, fn, seen));
125746
+ } else {
125747
+ forEachElement(value, fn, seen);
125748
+ }
125749
+ }
125750
+ }
125751
+
125752
+ function isModdleElement(value) {
125753
+ return !!value && typeof value === 'object' && !!value.$descriptor && !!value.$attrs;
125754
+ }
125755
+
125756
+ function hasOwn(object, name) {
125757
+ return Object.prototype.hasOwnProperty.call(object, name);
125758
+ }
125759
+
125488
125760
  /**
125489
125761
  * Runs before bpmn-js claims the imported IDs, so created definitions are
125490
125762
  * claimed too.
@@ -125503,11 +125775,17 @@ var FlowableBpmnJS = (function () {
125503
125775
  * signal or escalation they stand for (createMissingDefinitions from the
125504
125776
  * behaviors package), in the viewers too;
125505
125777
  * - on save, other prefixes bound to the Flowable namespace are dropped, so
125506
- * everything is written as flowable: (useFlowablePrefix).
125778
+ * everything is written as flowable: (useFlowablePrefix);
125779
+ * - an unedited model is written as it was read: expanded subprocesses
125780
+ * without `isExpanded`, gateway markers and attributes with their default
125781
+ * value stay as the file had them (see WriteAsRead.js).
125507
125782
  */
125508
125783
  class FlowableXML {
125509
125784
 
125510
125785
  constructor(eventBus, moddle) {
125786
+ let read = { expanded: new Set(), markers: new Set() };
125787
+ let restore = null;
125788
+
125511
125789
  eventBus.on('import.parse.start', ({ xml }) => {
125512
125790
  const migrated = migrateActivitiXML(xml);
125513
125791
 
@@ -125519,10 +125797,24 @@ var FlowableBpmnJS = (function () {
125519
125797
  eventBus.on('import.parse.complete', HIGH_PRIORITY$1, ({ error, definitions, warnings, elementsById }) => {
125520
125798
  if (!error && definitions) {
125521
125799
  createMissingDefinitions(definitions, { warnings, elementsById });
125800
+
125801
+ // before bpmn-js draws the model (and moves the shapes of collapsed subprocesses)
125802
+ read = readAsFlowable(definitions);
125522
125803
  }
125523
125804
  });
125524
125805
 
125525
- eventBus.on('saveXML.start', ({ definitions }) => useFlowablePrefix(definitions));
125806
+ eventBus.on('saveXML.start', ({ definitions }) => {
125807
+ useFlowablePrefix(definitions);
125808
+
125809
+ restore = writeAsRead(definitions, read);
125810
+ });
125811
+
125812
+ eventBus.on('saveXML.done', () => {
125813
+ if (restore) {
125814
+ restore();
125815
+ restore = null;
125816
+ }
125817
+ });
125526
125818
  }
125527
125819
  }
125528
125820