bpmn-js 3.4.3 → 3.5.0

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/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ All notable changes to [bpmn-js](https://github.com/bpmn-io/bpmn-js) are documen
6
6
 
7
7
  ___Note:__ Yet to be released changes appear here._
8
8
 
9
+ ## 3.5.0
10
+
11
+ * `FEAT`: restore `Viewer#importDefinitions` and make it public API ([#1112](https://github.com/bpmn-io/bpmn-js/pull/1112))
12
+
9
13
  ## 3.4.3
10
14
 
11
15
  * `FIX`: prevent HTML injection in search ([diagram-js#362](https://github.com/bpmn-io/diagram-js/pull/362))
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * bpmn-js - bpmn-modeler v3.4.3
2
+ * bpmn-js - bpmn-modeler v3.5.0
3
3
  *
4
4
  * Copyright (c) 2014-present, camunda Services GmbH
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Source Code: https://github.com/bpmn-io/bpmn-js
10
10
  *
11
- * Date: 2019-06-13
11
+ * Date: 2019-06-28
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -220,41 +220,49 @@
220
220
 
221
221
  var nativeToString = Object.prototype.toString;
222
222
  var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
223
+
223
224
  function isUndefined(obj) {
224
225
  return obj === undefined;
225
226
  }
227
+
226
228
  function isDefined(obj) {
227
229
  return obj !== undefined;
228
230
  }
231
+
229
232
  function isArray(obj) {
230
233
  return nativeToString.call(obj) === '[object Array]';
231
234
  }
235
+
232
236
  function isObject(obj) {
233
237
  return nativeToString.call(obj) === '[object Object]';
234
238
  }
239
+
235
240
  function isNumber(obj) {
236
241
  return nativeToString.call(obj) === '[object Number]';
237
242
  }
243
+
238
244
  function isFunction(obj) {
239
- var tag = nativeToString.call(obj);
240
- return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
245
+ return nativeToString.call(obj) === '[object Function]';
241
246
  }
247
+
242
248
  function isString(obj) {
243
249
  return nativeToString.call(obj) === '[object String]';
244
250
  }
251
+
245
252
  /**
246
253
  * Ensure collection is an array.
247
254
  *
248
255
  * @param {Object} obj
249
256
  */
250
-
251
257
  function ensureArray(obj) {
258
+
252
259
  if (isArray(obj)) {
253
260
  return;
254
261
  }
255
262
 
256
263
  throw new Error('must supply array');
257
264
  }
265
+
258
266
  /**
259
267
  * Return true, if target owns a property with the given key.
260
268
  *
@@ -263,7 +271,6 @@
263
271
  *
264
272
  * @return {Boolean}
265
273
  */
266
-
267
274
  function has(target, key) {
268
275
  return nativeHasOwnProperty.call(target, key);
269
276
  }
@@ -276,18 +283,23 @@
276
283
  *
277
284
  * @return {Object}
278
285
  */
279
-
280
286
  function find(collection, matcher) {
287
+
281
288
  matcher = toMatcher(matcher);
289
+
282
290
  var match;
291
+
283
292
  forEach(collection, function (val, key) {
284
293
  if (matcher(val, key)) {
285
294
  match = val;
295
+
286
296
  return false;
287
297
  }
288
298
  });
299
+
289
300
  return match;
290
301
  }
302
+
291
303
  /**
292
304
  * Find element index in collection.
293
305
  *
@@ -296,18 +308,23 @@
296
308
  *
297
309
  * @return {Object}
298
310
  */
299
-
300
311
  function findIndex(collection, matcher) {
312
+
301
313
  matcher = toMatcher(matcher);
314
+
302
315
  var idx = isArray(collection) ? -1 : undefined;
316
+
303
317
  forEach(collection, function (val, key) {
304
318
  if (matcher(val, key)) {
305
319
  idx = key;
320
+
306
321
  return false;
307
322
  }
308
323
  });
324
+
309
325
  return idx;
310
326
  }
327
+
311
328
  /**
312
329
  * Find element in collection.
313
330
  *
@@ -316,16 +333,19 @@
316
333
  *
317
334
  * @return {Array} result
318
335
  */
319
-
320
336
  function filter(collection, matcher) {
337
+
321
338
  var result = [];
339
+
322
340
  forEach(collection, function (val, key) {
323
341
  if (matcher(val, key)) {
324
342
  result.push(val);
325
343
  }
326
344
  });
345
+
327
346
  return result;
328
347
  }
348
+
329
349
  /**
330
350
  * Iterate over collection; returning something
331
351
  * (non-undefined) will stop iteration.
@@ -335,9 +355,7 @@
335
355
  *
336
356
  * @return {Object} return result that stopped the iteration
337
357
  */
338
-
339
358
  function forEach(collection, iterator) {
340
- var val, result;
341
359
 
342
360
  if (isUndefined(collection)) {
343
361
  return;
@@ -346,16 +364,19 @@
346
364
  var convertKey = isArray(collection) ? toNum : identity;
347
365
 
348
366
  for (var key in collection) {
367
+
349
368
  if (has(collection, key)) {
350
- val = collection[key];
351
- result = iterator(val, convertKey(key));
369
+ var val = collection[key];
370
+
371
+ var result = iterator(val, convertKey(key));
352
372
 
353
373
  if (result === false) {
354
- return val;
374
+ return;
355
375
  }
356
376
  }
357
377
  }
358
378
  }
379
+
359
380
  /**
360
381
  * Return collection without element.
361
382
  *
@@ -364,18 +385,21 @@
364
385
  *
365
386
  * @return {Array}
366
387
  */
367
-
368
388
  function without(arr, matcher) {
389
+
369
390
  if (isUndefined(arr)) {
370
391
  return [];
371
392
  }
372
393
 
373
394
  ensureArray(arr);
395
+
374
396
  matcher = toMatcher(matcher);
397
+
375
398
  return arr.filter(function (el, idx) {
376
399
  return !matcher(el, idx);
377
400
  });
378
401
  }
402
+
379
403
  /**
380
404
  * Reduce collection, returning a single result.
381
405
  *
@@ -385,13 +409,15 @@
385
409
  *
386
410
  * @return {Any} result returned from last iterator
387
411
  */
388
-
389
412
  function reduce(collection, iterator, result) {
413
+
390
414
  forEach(collection, function (value, idx) {
391
415
  result = iterator(result, value, idx);
392
416
  });
417
+
393
418
  return result;
394
419
  }
420
+
395
421
  /**
396
422
  * Return true if every element in the collection
397
423
  * matches the criteria.
@@ -401,12 +427,13 @@
401
427
  *
402
428
  * @return {Boolean}
403
429
  */
404
-
405
430
  function every(collection, matcher) {
431
+
406
432
  return reduce(collection, function (matches, val, key) {
407
433
  return matches && matcher(val, key);
408
434
  }, true);
409
435
  }
436
+
410
437
  /**
411
438
  * Return true if some elements in the collection
412
439
  * match the criteria.
@@ -416,10 +443,11 @@
416
443
  *
417
444
  * @return {Boolean}
418
445
  */
419
-
420
446
  function some(collection, matcher) {
447
+
421
448
  return !!find(collection, matcher);
422
449
  }
450
+
423
451
  /**
424
452
  * Transform a collection into another collection
425
453
  * by piping each member through the given fn.
@@ -429,14 +457,17 @@
429
457
  *
430
458
  * @return {Array} transformed collection
431
459
  */
432
-
433
460
  function map(collection, fn) {
461
+
434
462
  var result = [];
463
+
435
464
  forEach(collection, function (val, key) {
436
465
  result.push(fn(val, key));
437
466
  });
467
+
438
468
  return result;
439
469
  }
470
+
440
471
  /**
441
472
  * Get the collections keys.
442
473
  *
@@ -444,10 +475,10 @@
444
475
  *
445
476
  * @return {Array}
446
477
  */
447
-
448
478
  function keys(collection) {
449
479
  return collection && Object.keys(collection) || [];
450
480
  }
481
+
451
482
  /**
452
483
  * Shorthand for `keys(o).length`.
453
484
  *
@@ -455,10 +486,10 @@
455
486
  *
456
487
  * @return {Number}
457
488
  */
458
-
459
489
  function size(collection) {
460
490
  return keys(collection).length;
461
491
  }
492
+
462
493
  /**
463
494
  * Get the values in the collection.
464
495
  *
@@ -466,12 +497,12 @@
466
497
  *
467
498
  * @return {Array}
468
499
  */
469
-
470
500
  function values(collection) {
471
501
  return map(collection, function (val) {
472
502
  return val;
473
503
  });
474
504
  }
505
+
475
506
  /**
476
507
  * Group collection members by attribute.
477
508
  *
@@ -480,12 +511,15 @@
480
511
  *
481
512
  * @return {Object} map with { attrValue => [ a, b, c ] }
482
513
  */
483
-
484
514
  function groupBy(collection, extractor) {
485
515
  var grouped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
516
+
517
+
486
518
  extractor = toExtractor(extractor);
519
+
487
520
  forEach(collection, function (val) {
488
521
  var discriminator = extractor(val) || '_';
522
+
489
523
  var group = grouped[discriminator];
490
524
 
491
525
  if (!group) {
@@ -494,25 +528,33 @@
494
528
 
495
529
  group.push(val);
496
530
  });
531
+
497
532
  return grouped;
498
533
  }
534
+
499
535
  function uniqueBy(extractor) {
536
+
500
537
  extractor = toExtractor(extractor);
538
+
501
539
  var grouped = {};
502
540
 
503
- for (var _len = arguments.length, collections = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
541
+ for (var _len = arguments.length, collections = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
504
542
  collections[_key - 1] = arguments[_key];
505
543
  }
506
544
 
507
545
  forEach(collections, function (c) {
508
546
  return groupBy(c, extractor, grouped);
509
547
  });
548
+
510
549
  var result = map(grouped, function (val, key) {
511
550
  return val[0];
512
551
  });
552
+
513
553
  return result;
514
554
  }
555
+
515
556
  var unionBy = uniqueBy;
557
+
516
558
  /**
517
559
  * Sort collection by criteria.
518
560
  *
@@ -521,12 +563,15 @@
521
563
  *
522
564
  * @return {Array}
523
565
  */
524
-
525
566
  function sortBy(collection, extractor) {
567
+
526
568
  extractor = toExtractor(extractor);
569
+
527
570
  var sorted = [];
571
+
528
572
  forEach(collection, function (value, key) {
529
573
  var disc = extractor(value, key);
574
+
530
575
  var entry = {
531
576
  d: disc,
532
577
  v: value
@@ -535,19 +580,22 @@
535
580
  for (var idx = 0; idx < sorted.length; idx++) {
536
581
  var d = sorted[idx].d;
537
582
 
583
+
538
584
  if (disc < d) {
539
585
  sorted.splice(idx, 0, entry);
540
586
  return;
541
587
  }
542
- } // not inserted, append (!)
543
-
588
+ }
544
589
 
590
+ // not inserted, append (!)
545
591
  sorted.push(entry);
546
592
  });
593
+
547
594
  return map(sorted, function (e) {
548
595
  return e.v;
549
596
  });
550
597
  }
598
+
551
599
  /**
552
600
  * Create an object pattern matcher.
553
601
  *
@@ -561,9 +609,10 @@
561
609
  *
562
610
  * @return {Function} matcherFn
563
611
  */
564
-
565
612
  function matchPattern(pattern) {
613
+
566
614
  return function (el) {
615
+
567
616
  return every(pattern, function (val, key) {
568
617
  return el[key] === val;
569
618
  });
@@ -600,13 +649,18 @@
600
649
  * @return {Function} debounced function
601
650
  */
602
651
  function debounce(fn, timeout) {
652
+
603
653
  var timer;
654
+
604
655
  var lastArgs;
605
656
  var lastThis;
657
+
606
658
  var lastNow;
607
659
 
608
660
  function fire() {
661
+
609
662
  var now = Date.now();
663
+
610
664
  var scheduledDiff = lastNow + timeout - now;
611
665
 
612
666
  if (scheduledDiff > 0) {
@@ -614,6 +668,7 @@
614
668
  }
615
669
 
616
670
  fn.apply(lastThis, lastArgs);
671
+
617
672
  timer = lastNow = lastArgs = lastThis = undefined;
618
673
  }
619
674
 
@@ -622,20 +677,23 @@
622
677
  }
623
678
 
624
679
  return function () {
680
+
625
681
  lastNow = Date.now();
626
682
 
627
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
683
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
628
684
  args[_key] = arguments[_key];
629
685
  }
630
686
 
631
687
  lastArgs = args;
632
- lastThis = this; // ensure an execution is scheduled
688
+ lastThis = this;
633
689
 
690
+ // ensure an execution is scheduled
634
691
  if (!timer) {
635
692
  schedule(timeout);
636
693
  }
637
694
  };
638
695
  }
696
+
639
697
  /**
640
698
  * Bind function against target <this>.
641
699
  *
@@ -644,28 +702,11 @@
644
702
  *
645
703
  * @return {Function} bound function
646
704
  */
647
-
648
705
  function bind(fn, target) {
649
706
  return fn.bind(target);
650
707
  }
651
708
 
652
- function _extends() {
653
- _extends = Object.assign || function (target) {
654
- for (var i = 1; i < arguments.length; i++) {
655
- var source = arguments[i];
656
-
657
- for (var key in source) {
658
- if (Object.prototype.hasOwnProperty.call(source, key)) {
659
- target[key] = source[key];
660
- }
661
- }
662
- }
663
-
664
- return target;
665
- };
666
-
667
- return _extends.apply(this, arguments);
668
- }
709
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
669
710
 
670
711
  /**
671
712
  * Convenience wrapper for `Object.assign`.
@@ -675,14 +716,14 @@
675
716
  *
676
717
  * @return {Object} the target
677
718
  */
678
-
679
719
  function assign(target) {
680
- for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
720
+ for (var _len = arguments.length, others = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
681
721
  others[_key - 1] = arguments[_key];
682
722
  }
683
723
 
684
- return _extends.apply(void 0, [target].concat(others));
724
+ return _extends.apply(undefined, [target].concat(others));
685
725
  }
726
+
686
727
  /**
687
728
  * Pick given properties from the target object.
688
729
  *
@@ -691,17 +732,22 @@
691
732
  *
692
733
  * @return {Object} target
693
734
  */
694
-
695
735
  function pick(target, properties) {
736
+
696
737
  var result = {};
738
+
697
739
  var obj = Object(target);
740
+
698
741
  forEach(properties, function (prop) {
742
+
699
743
  if (prop in obj) {
700
744
  result[prop] = target[prop];
701
745
  }
702
746
  });
747
+
703
748
  return result;
704
749
  }
750
+
705
751
  /**
706
752
  * Pick all target properties, excluding the given ones.
707
753
  *
@@ -710,15 +756,19 @@
710
756
  *
711
757
  * @return {Object} target
712
758
  */
713
-
714
759
  function omit(target, properties) {
760
+
715
761
  var result = {};
762
+
716
763
  var obj = Object(target);
764
+
717
765
  forEach(obj, function (prop, key) {
766
+
718
767
  if (properties.indexOf(key) === -1) {
719
768
  result[key] = prop;
720
769
  }
721
770
  });
771
+
722
772
  return result;
723
773
  }
724
774
 
@@ -20210,9 +20260,7 @@
20210
20260
  return done(err, parseWarnings);
20211
20261
  }
20212
20262
 
20213
- self._setDefinitions(definitions);
20214
-
20215
- self.open(bpmnDiagram, function(err, importWarnings) {
20263
+ self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
20216
20264
  var allWarnings = [].concat(parseWarnings, importWarnings || []);
20217
20265
 
20218
20266
  self._emit('import.done', { error: err, warnings: allWarnings });
@@ -20222,6 +20270,40 @@
20222
20270
  });
20223
20271
  };
20224
20272
 
20273
+ /**
20274
+ * Import parsed definitions and render a BPMN 2.0 diagram.
20275
+ *
20276
+ * Once finished the viewer reports back the result to the
20277
+ * provided callback function with (err, warnings).
20278
+ *
20279
+ * ## Life-Cycle Events
20280
+ *
20281
+ * During import the viewer will fire life-cycle events:
20282
+ *
20283
+ * * import.render.start (graphical import start)
20284
+ * * import.render.complete (graphical import finished)
20285
+ *
20286
+ * You can use these events to hook into the life-cycle.
20287
+ *
20288
+ * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
20289
+ * @param {ModdleElement<BPMNDiagram>|String} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
20290
+ * @param {Function} [done] invoked with (err, warnings=[])
20291
+ */
20292
+ Viewer.prototype.importDefinitions = function(definitions, bpmnDiagram, done) {
20293
+
20294
+ if (isFunction(bpmnDiagram)) {
20295
+ done = bpmnDiagram;
20296
+ bpmnDiagram = null;
20297
+ }
20298
+
20299
+ // done is optional
20300
+ done = done || function() {};
20301
+
20302
+ this._setDefinitions(definitions);
20303
+
20304
+ return this.open(bpmnDiagram, done);
20305
+ };
20306
+
20225
20307
  /**
20226
20308
  * Open diagram of previously imported XML.
20227
20309
  *