1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | (function (global, factory) {
|
14 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
15 | typeof define === 'function' && define.amd ? define(factory) :
|
16 | (global.BpmnJS = factory());
|
17 | }(this, (function () { 'use strict';
|
18 |
|
19 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
20 |
|
21 | function createCommonjsModule(fn, module) {
|
22 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
23 | }
|
24 |
|
25 | function getCjsExportFromNamespace (n) {
|
26 | return n && n.default || n;
|
27 | }
|
28 |
|
29 | var inherits_browser = createCommonjsModule(function (module) {
|
30 | if (typeof Object.create === 'function') {
|
31 |
|
32 | module.exports = function inherits(ctor, superCtor) {
|
33 | ctor.super_ = superCtor;
|
34 | ctor.prototype = Object.create(superCtor.prototype, {
|
35 | constructor: {
|
36 | value: ctor,
|
37 | enumerable: false,
|
38 | writable: true,
|
39 | configurable: true
|
40 | }
|
41 | });
|
42 | };
|
43 | } else {
|
44 |
|
45 | module.exports = function inherits(ctor, superCtor) {
|
46 | ctor.super_ = superCtor;
|
47 | var TempCtor = function () {};
|
48 | TempCtor.prototype = superCtor.prototype;
|
49 | ctor.prototype = new TempCtor();
|
50 | ctor.prototype.constructor = ctor;
|
51 | };
|
52 | }
|
53 | });
|
54 |
|
55 | var hat_1 = createCommonjsModule(function (module) {
|
56 | var hat = module.exports = function (bits, base) {
|
57 | if (!base) base = 16;
|
58 | if (bits === undefined) bits = 128;
|
59 | if (bits <= 0) return '0';
|
60 |
|
61 | var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
|
62 | for (var i = 2; digits === Infinity; i *= 2) {
|
63 | digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
|
64 | }
|
65 |
|
66 | var rem = digits - Math.floor(digits);
|
67 |
|
68 | var res = '';
|
69 |
|
70 | for (var i = 0; i < Math.floor(digits); i++) {
|
71 | var x = Math.floor(Math.random() * base).toString(base);
|
72 | res = x + res;
|
73 | }
|
74 |
|
75 | if (rem) {
|
76 | var b = Math.pow(base, rem);
|
77 | var x = Math.floor(Math.random() * b).toString(base);
|
78 | res = x + res;
|
79 | }
|
80 |
|
81 | var parsed = parseInt(res, base);
|
82 | if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
|
83 | return hat(bits, base)
|
84 | }
|
85 | else return res;
|
86 | };
|
87 |
|
88 | hat.rack = function (bits, base, expandBy) {
|
89 | var fn = function (data) {
|
90 | var iters = 0;
|
91 | do {
|
92 | if (iters ++ > 10) {
|
93 | if (expandBy) bits += expandBy;
|
94 | else throw new Error('too many ID collisions, use more bits')
|
95 | }
|
96 |
|
97 | var id = hat(bits, base);
|
98 | } while (Object.hasOwnProperty.call(hats, id));
|
99 |
|
100 | hats[id] = data;
|
101 | return id;
|
102 | };
|
103 | var hats = fn.hats = {};
|
104 |
|
105 | fn.get = function (id) {
|
106 | return fn.hats[id];
|
107 | };
|
108 |
|
109 | fn.set = function (id, value) {
|
110 | fn.hats[id] = value;
|
111 | return fn;
|
112 | };
|
113 |
|
114 | fn.bits = bits || 128;
|
115 | fn.base = base || 16;
|
116 | return fn;
|
117 | };
|
118 | });
|
119 |
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | function Ids(seed) {
|
128 |
|
129 | if (!(this instanceof Ids)) {
|
130 | return new Ids(seed);
|
131 | }
|
132 |
|
133 | seed = seed || [ 128, 36, 1 ];
|
134 | this._seed = seed.length ? hat_1.rack(seed[0], seed[1], seed[2]) : seed;
|
135 | }
|
136 |
|
137 | var ids = Ids;
|
138 |
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | Ids.prototype.next = function(element) {
|
147 | return this._seed(element || true);
|
148 | };
|
149 |
|
150 | |
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | Ids.prototype.nextPrefixed = function(prefix, element) {
|
158 | var id;
|
159 |
|
160 | do {
|
161 | id = prefix + this.next(true);
|
162 | } while (this.assigned(id));
|
163 |
|
164 |
|
165 | this.claim(id, element);
|
166 |
|
167 |
|
168 | return id;
|
169 | };
|
170 |
|
171 | |
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | Ids.prototype.claim = function(id, element) {
|
178 | this._seed.set(id, element || true);
|
179 | };
|
180 |
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | Ids.prototype.assigned = function(id) {
|
188 | return this._seed.get(id) || false;
|
189 | };
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 | Ids.prototype.unclaim = function(id) {
|
197 | delete this._seed.hats[id];
|
198 | };
|
199 |
|
200 |
|
201 | |
202 |
|
203 |
|
204 | Ids.prototype.clear = function() {
|
205 |
|
206 | var hats = this._seed.hats,
|
207 | id;
|
208 |
|
209 | for (id in hats) {
|
210 | this.unclaim(id);
|
211 | }
|
212 | };
|
213 |
|
214 | |
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | function flatten(arr) {
|
222 | return Array.prototype.concat.apply([], arr);
|
223 | }
|
224 |
|
225 | var nativeToString = Object.prototype.toString;
|
226 | var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
|
227 |
|
228 | function isUndefined(obj) {
|
229 | return obj === undefined;
|
230 | }
|
231 |
|
232 | function isDefined(obj) {
|
233 | return obj !== undefined;
|
234 | }
|
235 |
|
236 | function isArray(obj) {
|
237 | return nativeToString.call(obj) === '[object Array]';
|
238 | }
|
239 |
|
240 | function isObject(obj) {
|
241 | return nativeToString.call(obj) === '[object Object]';
|
242 | }
|
243 |
|
244 | function isNumber(obj) {
|
245 | return nativeToString.call(obj) === '[object Number]';
|
246 | }
|
247 |
|
248 | function isFunction(obj) {
|
249 | return nativeToString.call(obj) === '[object Function]';
|
250 | }
|
251 |
|
252 | function isString(obj) {
|
253 | return nativeToString.call(obj) === '[object String]';
|
254 | }
|
255 |
|
256 | |
257 |
|
258 |
|
259 |
|
260 |
|
261 | function ensureArray(obj) {
|
262 |
|
263 | if (isArray(obj)) {
|
264 | return;
|
265 | }
|
266 |
|
267 | throw new Error('must supply array');
|
268 | }
|
269 |
|
270 | |
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | function has(target, key) {
|
279 | return nativeHasOwnProperty.call(target, key);
|
280 | }
|
281 |
|
282 | |
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 | function find(collection, matcher) {
|
291 |
|
292 | matcher = toMatcher(matcher);
|
293 |
|
294 | var match;
|
295 |
|
296 | forEach(collection, function (val, key) {
|
297 | if (matcher(val, key)) {
|
298 | match = val;
|
299 |
|
300 | return false;
|
301 | }
|
302 | });
|
303 |
|
304 | return match;
|
305 | }
|
306 |
|
307 | |
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | function findIndex(collection, matcher) {
|
316 |
|
317 | matcher = toMatcher(matcher);
|
318 |
|
319 | var idx = isArray(collection) ? -1 : undefined;
|
320 |
|
321 | forEach(collection, function (val, key) {
|
322 | if (matcher(val, key)) {
|
323 | idx = key;
|
324 |
|
325 | return false;
|
326 | }
|
327 | });
|
328 |
|
329 | return idx;
|
330 | }
|
331 |
|
332 | |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 | function filter(collection, matcher) {
|
341 |
|
342 | var result = [];
|
343 |
|
344 | forEach(collection, function (val, key) {
|
345 | if (matcher(val, key)) {
|
346 | result.push(val);
|
347 | }
|
348 | });
|
349 |
|
350 | return result;
|
351 | }
|
352 |
|
353 | |
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | function forEach(collection, iterator) {
|
363 |
|
364 | if (isUndefined(collection)) {
|
365 | return;
|
366 | }
|
367 |
|
368 | var convertKey = isArray(collection) ? toNum : identity;
|
369 |
|
370 | for (var key in collection) {
|
371 |
|
372 | if (has(collection, key)) {
|
373 | var val = collection[key];
|
374 |
|
375 | var result = iterator(val, convertKey(key));
|
376 |
|
377 | if (result === false) {
|
378 | return;
|
379 | }
|
380 | }
|
381 | }
|
382 | }
|
383 |
|
384 | |
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | function without(arr, matcher) {
|
393 |
|
394 | if (isUndefined(arr)) {
|
395 | return [];
|
396 | }
|
397 |
|
398 | ensureArray(arr);
|
399 |
|
400 | matcher = toMatcher(matcher);
|
401 |
|
402 | return arr.filter(function (el, idx) {
|
403 | return !matcher(el, idx);
|
404 | });
|
405 | }
|
406 |
|
407 | |
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | function reduce(collection, iterator, result) {
|
417 |
|
418 | forEach(collection, function (value, idx) {
|
419 | result = iterator(result, value, idx);
|
420 | });
|
421 |
|
422 | return result;
|
423 | }
|
424 |
|
425 | |
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 | function every(collection, matcher) {
|
435 |
|
436 | return reduce(collection, function (matches, val, key) {
|
437 | return matches && matcher(val, key);
|
438 | }, true);
|
439 | }
|
440 |
|
441 | |
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 | function some(collection, matcher) {
|
451 |
|
452 | return !!find(collection, matcher);
|
453 | }
|
454 |
|
455 | |
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 | function map(collection, fn) {
|
465 |
|
466 | var result = [];
|
467 |
|
468 | forEach(collection, function (val, key) {
|
469 | result.push(fn(val, key));
|
470 | });
|
471 |
|
472 | return result;
|
473 | }
|
474 |
|
475 | |
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | function keys(collection) {
|
483 | return collection && Object.keys(collection) || [];
|
484 | }
|
485 |
|
486 | |
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 | function size(collection) {
|
494 | return keys(collection).length;
|
495 | }
|
496 |
|
497 | |
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 | function values(collection) {
|
505 | return map(collection, function (val) {
|
506 | return val;
|
507 | });
|
508 | }
|
509 |
|
510 | |
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 | function groupBy(collection, extractor) {
|
519 | var grouped = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
520 |
|
521 |
|
522 | extractor = toExtractor(extractor);
|
523 |
|
524 | forEach(collection, function (val) {
|
525 | var discriminator = extractor(val) || '_';
|
526 |
|
527 | var group = grouped[discriminator];
|
528 |
|
529 | if (!group) {
|
530 | group = grouped[discriminator] = [];
|
531 | }
|
532 |
|
533 | group.push(val);
|
534 | });
|
535 |
|
536 | return grouped;
|
537 | }
|
538 |
|
539 | function uniqueBy(extractor) {
|
540 |
|
541 | extractor = toExtractor(extractor);
|
542 |
|
543 | var grouped = {};
|
544 |
|
545 | for (var _len = arguments.length, collections = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
546 | collections[_key - 1] = arguments[_key];
|
547 | }
|
548 |
|
549 | forEach(collections, function (c) {
|
550 | return groupBy(c, extractor, grouped);
|
551 | });
|
552 |
|
553 | var result = map(grouped, function (val, key) {
|
554 | return val[0];
|
555 | });
|
556 |
|
557 | return result;
|
558 | }
|
559 |
|
560 | var unionBy = uniqueBy;
|
561 |
|
562 | |
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 | function sortBy(collection, extractor) {
|
571 |
|
572 | extractor = toExtractor(extractor);
|
573 |
|
574 | var sorted = [];
|
575 |
|
576 | forEach(collection, function (value, key) {
|
577 | var disc = extractor(value, key);
|
578 |
|
579 | var entry = {
|
580 | d: disc,
|
581 | v: value
|
582 | };
|
583 |
|
584 | for (var idx = 0; idx < sorted.length; idx++) {
|
585 | var d = sorted[idx].d;
|
586 |
|
587 |
|
588 | if (disc < d) {
|
589 | sorted.splice(idx, 0, entry);
|
590 | return;
|
591 | }
|
592 | }
|
593 |
|
594 |
|
595 | sorted.push(entry);
|
596 | });
|
597 |
|
598 | return map(sorted, function (e) {
|
599 | return e.v;
|
600 | });
|
601 | }
|
602 |
|
603 | |
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | function matchPattern(pattern) {
|
617 |
|
618 | return function (el) {
|
619 |
|
620 | return every(pattern, function (val, key) {
|
621 | return el[key] === val;
|
622 | });
|
623 | };
|
624 | }
|
625 |
|
626 | function toExtractor(extractor) {
|
627 | return isFunction(extractor) ? extractor : function (e) {
|
628 | return e[extractor];
|
629 | };
|
630 | }
|
631 |
|
632 | function toMatcher(matcher) {
|
633 | return isFunction(matcher) ? matcher : function (e) {
|
634 | return e === matcher;
|
635 | };
|
636 | }
|
637 |
|
638 | function identity(arg) {
|
639 | return arg;
|
640 | }
|
641 |
|
642 | function toNum(arg) {
|
643 | return Number(arg);
|
644 | }
|
645 |
|
646 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
647 |
|
648 | var slice = Array.prototype.slice;
|
649 |
|
650 | |
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 | function debounce(fn, timeout) {
|
660 |
|
661 | var timer;
|
662 |
|
663 | return function () {
|
664 |
|
665 | var args = slice.call(arguments);
|
666 |
|
667 | if (timer) {
|
668 | clearTimeout(timer);
|
669 | }
|
670 |
|
671 | timer = setTimeout(function () {
|
672 | fn.apply(undefined, _toConsumableArray(args));
|
673 | }, timeout);
|
674 | };
|
675 | }
|
676 |
|
677 | |
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | function bind(fn, target) {
|
686 | return fn.bind(target);
|
687 | }
|
688 |
|
689 | 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; };
|
690 |
|
691 | |
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 | function assign(target) {
|
700 | for (var _len = arguments.length, others = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
701 | others[_key - 1] = arguments[_key];
|
702 | }
|
703 |
|
704 | return _extends.apply(undefined, [target].concat(others));
|
705 | }
|
706 |
|
707 | |
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | function pick(target, properties) {
|
716 |
|
717 | var result = {};
|
718 |
|
719 | var obj = Object(target);
|
720 |
|
721 | forEach(properties, function (prop) {
|
722 |
|
723 | if (prop in obj) {
|
724 | result[prop] = target[prop];
|
725 | }
|
726 | });
|
727 |
|
728 | return result;
|
729 | }
|
730 |
|
731 | |
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 | function omit(target, properties) {
|
740 |
|
741 | var result = {};
|
742 |
|
743 | var obj = Object(target);
|
744 |
|
745 | forEach(obj, function (prop, key) {
|
746 |
|
747 | if (properties.indexOf(key) === -1) {
|
748 | result[key] = prop;
|
749 | }
|
750 | });
|
751 |
|
752 | return result;
|
753 | }
|
754 |
|
755 | |
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 | function attr(el, name, val) {
|
764 |
|
765 | if (arguments.length == 2) {
|
766 | return el.getAttribute(name);
|
767 | }
|
768 |
|
769 |
|
770 | if (val === null) {
|
771 | return el.removeAttribute(name);
|
772 | }
|
773 |
|
774 |
|
775 | el.setAttribute(name, val);
|
776 |
|
777 | return el;
|
778 | }
|
779 |
|
780 | var indexOf = [].indexOf;
|
781 |
|
782 | var indexof = function(arr, obj){
|
783 | if (indexOf) return arr.indexOf(obj);
|
784 | for (var i = 0; i < arr.length; ++i) {
|
785 | if (arr[i] === obj) return i;
|
786 | }
|
787 | return -1;
|
788 | };
|
789 |
|
790 | |
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 | |
797 |
|
798 |
|
799 |
|
800 | var re = /\s+/;
|
801 |
|
802 | |
803 |
|
804 |
|
805 |
|
806 | var toString = Object.prototype.toString;
|
807 |
|
808 | |
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 | function classes(el) {
|
817 | return new ClassList(el);
|
818 | }
|
819 |
|
820 | |
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 | function ClassList(el) {
|
828 | if (!el || !el.nodeType) {
|
829 | throw new Error('A DOM element reference is required');
|
830 | }
|
831 | this.el = el;
|
832 | this.list = el.classList;
|
833 | }
|
834 |
|
835 | |
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 | ClassList.prototype.add = function (name) {
|
844 |
|
845 | if (this.list) {
|
846 | this.list.add(name);
|
847 | return this;
|
848 | }
|
849 |
|
850 |
|
851 | var arr = this.array();
|
852 | var i = indexof(arr, name);
|
853 | if (!~i) arr.push(name);
|
854 | this.el.className = arr.join(' ');
|
855 | return this;
|
856 | };
|
857 |
|
858 | |
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 | ClassList.prototype.remove = function (name) {
|
869 | if ('[object RegExp]' == toString.call(name)) {
|
870 | return this.removeMatching(name);
|
871 | }
|
872 |
|
873 |
|
874 | if (this.list) {
|
875 | this.list.remove(name);
|
876 | return this;
|
877 | }
|
878 |
|
879 |
|
880 | var arr = this.array();
|
881 | var i = indexof(arr, name);
|
882 | if (~i) arr.splice(i, 1);
|
883 | this.el.className = arr.join(' ');
|
884 | return this;
|
885 | };
|
886 |
|
887 | |
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 | ClassList.prototype.removeMatching = function (re) {
|
896 | var arr = this.array();
|
897 | for (var i = 0; i < arr.length; i++) {
|
898 | if (re.test(arr[i])) {
|
899 | this.remove(arr[i]);
|
900 | }
|
901 | }
|
902 | return this;
|
903 | };
|
904 |
|
905 | |
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 | ClassList.prototype.toggle = function (name, force) {
|
918 |
|
919 | if (this.list) {
|
920 | if ('undefined' !== typeof force) {
|
921 | if (force !== this.list.toggle(name, force)) {
|
922 | this.list.toggle(name);
|
923 | }
|
924 | } else {
|
925 | this.list.toggle(name);
|
926 | }
|
927 | return this;
|
928 | }
|
929 |
|
930 |
|
931 | if ('undefined' !== typeof force) {
|
932 | if (!force) {
|
933 | this.remove(name);
|
934 | } else {
|
935 | this.add(name);
|
936 | }
|
937 | } else {
|
938 | if (this.has(name)) {
|
939 | this.remove(name);
|
940 | } else {
|
941 | this.add(name);
|
942 | }
|
943 | }
|
944 |
|
945 | return this;
|
946 | };
|
947 |
|
948 | |
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 | ClassList.prototype.array = function () {
|
956 | var className = this.el.getAttribute('class') || '';
|
957 | var str = className.replace(/^\s+|\s+$/g, '');
|
958 | var arr = str.split(re);
|
959 | if ('' === arr[0]) arr.shift();
|
960 | return arr;
|
961 | };
|
962 |
|
963 | |
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 | ClassList.prototype.has = ClassList.prototype.contains = function (name) {
|
972 | return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
|
973 | };
|
974 |
|
975 | |
976 |
|
977 |
|
978 | function clear(el) {
|
979 |
|
980 | var c;
|
981 |
|
982 | while (el.childNodes.length) {
|
983 | c = el.childNodes[0];
|
984 | el.removeChild(c);
|
985 | }
|
986 |
|
987 | return el;
|
988 | }
|
989 |
|
990 | |
991 |
|
992 |
|
993 |
|
994 | var proto = Element.prototype;
|
995 |
|
996 | |
997 |
|
998 |
|
999 |
|
1000 | var vendor = proto.matchesSelector
|
1001 | || proto.webkitMatchesSelector
|
1002 | || proto.mozMatchesSelector
|
1003 | || proto.msMatchesSelector
|
1004 | || proto.oMatchesSelector;
|
1005 |
|
1006 | |
1007 |
|
1008 |
|
1009 |
|
1010 | var matchesSelector = match;
|
1011 |
|
1012 | |
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 | function match(el, selector) {
|
1022 | if (vendor) return vendor.call(el, selector);
|
1023 | var nodes = el.parentNode.querySelectorAll(selector);
|
1024 | for (var i = 0; i < nodes.length; ++i) {
|
1025 | if (nodes[i] == el) return true;
|
1026 | }
|
1027 | return false;
|
1028 | }
|
1029 |
|
1030 | var closest = function (element, selector, checkYoSelf) {
|
1031 | var parent = checkYoSelf ? element : element.parentNode;
|
1032 |
|
1033 | while (parent && parent !== document) {
|
1034 | if (matchesSelector(parent, selector)) return parent;
|
1035 | parent = parent.parentNode;
|
1036 | }
|
1037 | };
|
1038 |
|
1039 | var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
|
1040 | unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
|
1041 | prefix = bind$1 !== 'addEventListener' ? 'on' : '';
|
1042 |
|
1043 | |
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 | var bind_1 = function(el, type, fn, capture){
|
1055 | el[bind$1](prefix + type, fn, capture || false);
|
1056 | return fn;
|
1057 | };
|
1058 |
|
1059 | |
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 | var unbind_1 = function(el, type, fn, capture){
|
1071 | el[unbind](prefix + type, fn, capture || false);
|
1072 | return fn;
|
1073 | };
|
1074 |
|
1075 | var componentEvent = {
|
1076 | bind: bind_1,
|
1077 | unbind: unbind_1
|
1078 | };
|
1079 |
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 | |
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | var forceCaptureEvents = ['focus', 'blur'];
|
1103 |
|
1104 | var bind$1$1 = function(el, selector, type, fn, capture){
|
1105 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1106 |
|
1107 | return componentEvent.bind(el, type, function(e){
|
1108 | var target = e.target || e.srcElement;
|
1109 | e.delegateTarget = closest(target, selector, true, el);
|
1110 | if (e.delegateTarget) fn.call(el, e);
|
1111 | }, capture);
|
1112 | };
|
1113 |
|
1114 | |
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 | var unbind$1 = function(el, type, fn, capture){
|
1125 | if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
|
1126 |
|
1127 | componentEvent.unbind(el, type, fn, capture);
|
1128 | };
|
1129 |
|
1130 | var delegateEvents = {
|
1131 | bind: bind$1$1,
|
1132 | unbind: unbind$1
|
1133 | };
|
1134 |
|
1135 | |
1136 |
|
1137 |
|
1138 |
|
1139 | var domify = parse;
|
1140 |
|
1141 | |
1142 |
|
1143 |
|
1144 |
|
1145 | var innerHTMLBug = false;
|
1146 | var bugTestDiv;
|
1147 | if (typeof document !== 'undefined') {
|
1148 | bugTestDiv = document.createElement('div');
|
1149 |
|
1150 | bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
|
1151 |
|
1152 |
|
1153 | innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
|
1154 | bugTestDiv = undefined;
|
1155 | }
|
1156 |
|
1157 | |
1158 |
|
1159 |
|
1160 |
|
1161 | var map$1 = {
|
1162 | legend: [1, '<fieldset>', '</fieldset>'],
|
1163 | tr: [2, '<table><tbody>', '</tbody></table>'],
|
1164 | col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
|
1165 |
|
1166 |
|
1167 | _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
|
1168 | };
|
1169 |
|
1170 | map$1.td =
|
1171 | map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
|
1172 |
|
1173 | map$1.option =
|
1174 | map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
|
1175 |
|
1176 | map$1.thead =
|
1177 | map$1.tbody =
|
1178 | map$1.colgroup =
|
1179 | map$1.caption =
|
1180 | map$1.tfoot = [1, '<table>', '</table>'];
|
1181 |
|
1182 | map$1.polyline =
|
1183 | map$1.ellipse =
|
1184 | map$1.polygon =
|
1185 | map$1.circle =
|
1186 | map$1.text =
|
1187 | map$1.line =
|
1188 | map$1.path =
|
1189 | map$1.rect =
|
1190 | map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
|
1191 |
|
1192 | |
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 | function parse(html, doc) {
|
1204 | if ('string' != typeof html) throw new TypeError('String expected');
|
1205 |
|
1206 |
|
1207 | if (!doc) doc = document;
|
1208 |
|
1209 |
|
1210 | var m = /<([\w:]+)/.exec(html);
|
1211 | if (!m) return doc.createTextNode(html);
|
1212 |
|
1213 | html = html.replace(/^\s+|\s+$/g, '');
|
1214 |
|
1215 | var tag = m[1];
|
1216 |
|
1217 |
|
1218 | if (tag == 'body') {
|
1219 | var el = doc.createElement('html');
|
1220 | el.innerHTML = html;
|
1221 | return el.removeChild(el.lastChild);
|
1222 | }
|
1223 |
|
1224 |
|
1225 | var wrap = map$1[tag] || map$1._default;
|
1226 | var depth = wrap[0];
|
1227 | var prefix = wrap[1];
|
1228 | var suffix = wrap[2];
|
1229 | var el = doc.createElement('div');
|
1230 | el.innerHTML = prefix + html + suffix;
|
1231 | while (depth--) el = el.lastChild;
|
1232 |
|
1233 |
|
1234 | if (el.firstChild == el.lastChild) {
|
1235 | return el.removeChild(el.firstChild);
|
1236 | }
|
1237 |
|
1238 |
|
1239 | var fragment = doc.createDocumentFragment();
|
1240 | while (el.firstChild) {
|
1241 | fragment.appendChild(el.removeChild(el.firstChild));
|
1242 | }
|
1243 |
|
1244 | return fragment;
|
1245 | }
|
1246 |
|
1247 | var proto$1 = typeof Element !== 'undefined' ? Element.prototype : {};
|
1248 | var vendor$1 = proto$1.matches
|
1249 | || proto$1.matchesSelector
|
1250 | || proto$1.webkitMatchesSelector
|
1251 | || proto$1.mozMatchesSelector
|
1252 | || proto$1.msMatchesSelector
|
1253 | || proto$1.oMatchesSelector;
|
1254 |
|
1255 | var matchesSelector$1 = match$1;
|
1256 |
|
1257 | |
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 | function match$1(el, selector) {
|
1267 | if (!el || el.nodeType !== 1) return false;
|
1268 | if (vendor$1) return vendor$1.call(el, selector);
|
1269 | var nodes = el.parentNode.querySelectorAll(selector);
|
1270 | for (var i = 0; i < nodes.length; i++) {
|
1271 | if (nodes[i] == el) return true;
|
1272 | }
|
1273 | return false;
|
1274 | }
|
1275 |
|
1276 | function query(selector, el) {
|
1277 | el = el || document;
|
1278 |
|
1279 | return el.querySelector(selector);
|
1280 | }
|
1281 |
|
1282 | function all(selector, el) {
|
1283 | el = el || document;
|
1284 |
|
1285 | return el.querySelectorAll(selector);
|
1286 | }
|
1287 |
|
1288 | function remove(el) {
|
1289 | el.parentNode && el.parentNode.removeChild(el);
|
1290 | }
|
1291 |
|
1292 | function ensureImported(element, target) {
|
1293 |
|
1294 | if (element.ownerDocument !== target.ownerDocument) {
|
1295 | try {
|
1296 |
|
1297 | return target.ownerDocument.importNode(element, true);
|
1298 | } catch (e) {
|
1299 |
|
1300 | }
|
1301 | }
|
1302 |
|
1303 | return element;
|
1304 | }
|
1305 |
|
1306 | |
1307 |
|
1308 |
|
1309 |
|
1310 | |
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 | function appendTo(element, target) {
|
1319 | return target.appendChild(ensureImported(element, target));
|
1320 | }
|
1321 |
|
1322 | |
1323 |
|
1324 |
|
1325 |
|
1326 | |
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 | function append(target, node) {
|
1335 | appendTo(node, target);
|
1336 | return target;
|
1337 | }
|
1338 |
|
1339 | |
1340 |
|
1341 |
|
1342 |
|
1343 | var LENGTH_ATTR = 2;
|
1344 |
|
1345 | var CSS_PROPERTIES = {
|
1346 | 'alignment-baseline': 1,
|
1347 | 'baseline-shift': 1,
|
1348 | 'clip': 1,
|
1349 | 'clip-path': 1,
|
1350 | 'clip-rule': 1,
|
1351 | 'color': 1,
|
1352 | 'color-interpolation': 1,
|
1353 | 'color-interpolation-filters': 1,
|
1354 | 'color-profile': 1,
|
1355 | 'color-rendering': 1,
|
1356 | 'cursor': 1,
|
1357 | 'direction': 1,
|
1358 | 'display': 1,
|
1359 | 'dominant-baseline': 1,
|
1360 | 'enable-background': 1,
|
1361 | 'fill': 1,
|
1362 | 'fill-opacity': 1,
|
1363 | 'fill-rule': 1,
|
1364 | 'filter': 1,
|
1365 | 'flood-color': 1,
|
1366 | 'flood-opacity': 1,
|
1367 | 'font': 1,
|
1368 | 'font-family': 1,
|
1369 | 'font-size': LENGTH_ATTR,
|
1370 | 'font-size-adjust': 1,
|
1371 | 'font-stretch': 1,
|
1372 | 'font-style': 1,
|
1373 | 'font-variant': 1,
|
1374 | 'font-weight': 1,
|
1375 | 'glyph-orientation-horizontal': 1,
|
1376 | 'glyph-orientation-vertical': 1,
|
1377 | 'image-rendering': 1,
|
1378 | 'kerning': 1,
|
1379 | 'letter-spacing': 1,
|
1380 | 'lighting-color': 1,
|
1381 | 'marker': 1,
|
1382 | 'marker-end': 1,
|
1383 | 'marker-mid': 1,
|
1384 | 'marker-start': 1,
|
1385 | 'mask': 1,
|
1386 | 'opacity': 1,
|
1387 | 'overflow': 1,
|
1388 | 'pointer-events': 1,
|
1389 | 'shape-rendering': 1,
|
1390 | 'stop-color': 1,
|
1391 | 'stop-opacity': 1,
|
1392 | 'stroke': 1,
|
1393 | 'stroke-dasharray': 1,
|
1394 | 'stroke-dashoffset': 1,
|
1395 | 'stroke-linecap': 1,
|
1396 | 'stroke-linejoin': 1,
|
1397 | 'stroke-miterlimit': 1,
|
1398 | 'stroke-opacity': 1,
|
1399 | 'stroke-width': LENGTH_ATTR,
|
1400 | 'text-anchor': 1,
|
1401 | 'text-decoration': 1,
|
1402 | 'text-rendering': 1,
|
1403 | 'unicode-bidi': 1,
|
1404 | 'visibility': 1,
|
1405 | 'word-spacing': 1,
|
1406 | 'writing-mode': 1
|
1407 | };
|
1408 |
|
1409 |
|
1410 | function getAttribute(node, name) {
|
1411 | if (CSS_PROPERTIES[name]) {
|
1412 | return node.style[name];
|
1413 | } else {
|
1414 | return node.getAttributeNS(null, name);
|
1415 | }
|
1416 | }
|
1417 |
|
1418 | function setAttribute(node, name, value) {
|
1419 | var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
1420 |
|
1421 | var type = CSS_PROPERTIES[hyphenated];
|
1422 |
|
1423 | if (type) {
|
1424 |
|
1425 | if (type === LENGTH_ATTR && typeof value === 'number') {
|
1426 | value = String(value) + 'px';
|
1427 | }
|
1428 |
|
1429 | node.style[hyphenated] = value;
|
1430 | } else {
|
1431 | node.setAttributeNS(null, name, value);
|
1432 | }
|
1433 | }
|
1434 |
|
1435 | function setAttributes(node, attrs) {
|
1436 |
|
1437 | var names = Object.keys(attrs), i, name;
|
1438 |
|
1439 | for (i = 0, name; (name = names[i]); i++) {
|
1440 | setAttribute(node, name, attrs[name]);
|
1441 | }
|
1442 | }
|
1443 |
|
1444 | |
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 | function attr$1(node, name, value) {
|
1455 | if (typeof name === 'string') {
|
1456 | if (value !== undefined) {
|
1457 | setAttribute(node, name, value);
|
1458 | } else {
|
1459 | return getAttribute(node, name);
|
1460 | }
|
1461 | } else {
|
1462 | setAttributes(node, name);
|
1463 | }
|
1464 |
|
1465 | return node;
|
1466 | }
|
1467 |
|
1468 | |
1469 |
|
1470 |
|
1471 | function index(arr, obj) {
|
1472 | if (arr.indexOf) {
|
1473 | return arr.indexOf(obj);
|
1474 | }
|
1475 |
|
1476 |
|
1477 | for (var i = 0; i < arr.length; ++i) {
|
1478 | if (arr[i] === obj) {
|
1479 | return i;
|
1480 | }
|
1481 | }
|
1482 |
|
1483 | return -1;
|
1484 | }
|
1485 |
|
1486 | var re$1 = /\s+/;
|
1487 |
|
1488 | var toString$1 = Object.prototype.toString;
|
1489 |
|
1490 | function defined(o) {
|
1491 | return typeof o !== 'undefined';
|
1492 | }
|
1493 |
|
1494 | |
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 | function classes$1(el) {
|
1503 | return new ClassList$1(el);
|
1504 | }
|
1505 |
|
1506 | function ClassList$1(el) {
|
1507 | if (!el || !el.nodeType) {
|
1508 | throw new Error('A DOM element reference is required');
|
1509 | }
|
1510 | this.el = el;
|
1511 | this.list = el.classList;
|
1512 | }
|
1513 |
|
1514 | |
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 | ClassList$1.prototype.add = function(name) {
|
1523 |
|
1524 |
|
1525 | if (this.list) {
|
1526 | this.list.add(name);
|
1527 | return this;
|
1528 | }
|
1529 |
|
1530 |
|
1531 | var arr = this.array();
|
1532 | var i = index(arr, name);
|
1533 | if (!~i) {
|
1534 | arr.push(name);
|
1535 | }
|
1536 |
|
1537 | if (defined(this.el.className.baseVal)) {
|
1538 | this.el.className.baseVal = arr.join(' ');
|
1539 | } else {
|
1540 | this.el.className = arr.join(' ');
|
1541 | }
|
1542 |
|
1543 | return this;
|
1544 | };
|
1545 |
|
1546 | |
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 | ClassList$1.prototype.remove = function(name) {
|
1557 | if ('[object RegExp]' === toString$1.call(name)) {
|
1558 | return this.removeMatching(name);
|
1559 | }
|
1560 |
|
1561 |
|
1562 | if (this.list) {
|
1563 | this.list.remove(name);
|
1564 | return this;
|
1565 | }
|
1566 |
|
1567 |
|
1568 | var arr = this.array();
|
1569 | var i = index(arr, name);
|
1570 | if (~i) {
|
1571 | arr.splice(i, 1);
|
1572 | }
|
1573 | this.el.className.baseVal = arr.join(' ');
|
1574 | return this;
|
1575 | };
|
1576 |
|
1577 | |
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 | ClassList$1.prototype.removeMatching = function(re) {
|
1586 | var arr = this.array();
|
1587 | for (var i = 0; i < arr.length; i++) {
|
1588 | if (re.test(arr[i])) {
|
1589 | this.remove(arr[i]);
|
1590 | }
|
1591 | }
|
1592 | return this;
|
1593 | };
|
1594 |
|
1595 | |
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 | ClassList$1.prototype.toggle = function(name, force) {
|
1608 |
|
1609 | if (this.list) {
|
1610 | if (defined(force)) {
|
1611 | if (force !== this.list.toggle(name, force)) {
|
1612 | this.list.toggle(name);
|
1613 | }
|
1614 | } else {
|
1615 | this.list.toggle(name);
|
1616 | }
|
1617 | return this;
|
1618 | }
|
1619 |
|
1620 |
|
1621 | if (defined(force)) {
|
1622 | if (!force) {
|
1623 | this.remove(name);
|
1624 | } else {
|
1625 | this.add(name);
|
1626 | }
|
1627 | } else {
|
1628 | if (this.has(name)) {
|
1629 | this.remove(name);
|
1630 | } else {
|
1631 | this.add(name);
|
1632 | }
|
1633 | }
|
1634 |
|
1635 | return this;
|
1636 | };
|
1637 |
|
1638 | |
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 | ClassList$1.prototype.array = function() {
|
1646 | var className = this.el.getAttribute('class') || '';
|
1647 | var str = className.replace(/^\s+|\s+$/g, '');
|
1648 | var arr = str.split(re$1);
|
1649 | if ('' === arr[0]) {
|
1650 | arr.shift();
|
1651 | }
|
1652 | return arr;
|
1653 | };
|
1654 |
|
1655 | |
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 | ClassList$1.prototype.has =
|
1664 | ClassList$1.prototype.contains = function(name) {
|
1665 | return (
|
1666 | this.list ?
|
1667 | this.list.contains(name) :
|
1668 | !! ~index(this.array(), name)
|
1669 | );
|
1670 | };
|
1671 |
|
1672 | function remove$1(element) {
|
1673 | var parent = element.parentNode;
|
1674 |
|
1675 | if (parent) {
|
1676 | parent.removeChild(element);
|
1677 | }
|
1678 |
|
1679 | return element;
|
1680 | }
|
1681 |
|
1682 | |
1683 |
|
1684 |
|
1685 |
|
1686 | |
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 | function clear$1(element) {
|
1693 | var child;
|
1694 |
|
1695 | while ((child = element.firstChild)) {
|
1696 | remove$1(child);
|
1697 | }
|
1698 |
|
1699 | return element;
|
1700 | }
|
1701 |
|
1702 | function clone(element) {
|
1703 | return element.cloneNode(true);
|
1704 | }
|
1705 |
|
1706 | var ns = {
|
1707 | svg: 'http://www.w3.org/2000/svg'
|
1708 | };
|
1709 |
|
1710 | |
1711 |
|
1712 |
|
1713 |
|
1714 | var SVG_START = '<svg xmlns="' + ns.svg + '"';
|
1715 |
|
1716 | function parse$1(svg) {
|
1717 |
|
1718 | var unwrap = false;
|
1719 |
|
1720 |
|
1721 | if (svg.substring(0, 4) === '<svg') {
|
1722 | if (svg.indexOf(ns.svg) === -1) {
|
1723 | svg = SVG_START + svg.substring(4);
|
1724 | }
|
1725 | } else {
|
1726 |
|
1727 | svg = SVG_START + '>' + svg + '</svg>';
|
1728 | unwrap = true;
|
1729 | }
|
1730 |
|
1731 | var parsed = parseDocument(svg);
|
1732 |
|
1733 | if (!unwrap) {
|
1734 | return parsed;
|
1735 | }
|
1736 |
|
1737 | var fragment = document.createDocumentFragment();
|
1738 |
|
1739 | var parent = parsed.firstChild;
|
1740 |
|
1741 | while (parent.firstChild) {
|
1742 | fragment.appendChild(parent.firstChild);
|
1743 | }
|
1744 |
|
1745 | return fragment;
|
1746 | }
|
1747 |
|
1748 | function parseDocument(svg) {
|
1749 |
|
1750 | var parser;
|
1751 |
|
1752 |
|
1753 | parser = new DOMParser();
|
1754 | parser.async = false;
|
1755 |
|
1756 | return parser.parseFromString(svg, 'text/xml');
|
1757 | }
|
1758 |
|
1759 | |
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 | |
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 | function create(name, attrs) {
|
1773 | var element;
|
1774 |
|
1775 | if (name.charAt(0) === '<') {
|
1776 | element = parse$1(name).firstChild;
|
1777 | element = document.importNode(element, true);
|
1778 | } else {
|
1779 | element = document.createElementNS(ns.svg, name);
|
1780 | }
|
1781 |
|
1782 | if (attrs) {
|
1783 | attr$1(element, attrs);
|
1784 | }
|
1785 |
|
1786 | return element;
|
1787 | }
|
1788 |
|
1789 | |
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 | var node = create('svg');
|
1795 |
|
1796 | function extend(object, props) {
|
1797 | var i, k, keys = Object.keys(props);
|
1798 |
|
1799 | for (i = 0; (k = keys[i]); i++) {
|
1800 | object[k] = props[k];
|
1801 | }
|
1802 |
|
1803 | return object;
|
1804 | }
|
1805 |
|
1806 | function createMatrix(a, b, c, d, e, f) {
|
1807 | var matrix = node.createSVGMatrix();
|
1808 |
|
1809 | switch (arguments.length) {
|
1810 | case 0:
|
1811 | return matrix;
|
1812 | case 6:
|
1813 | a = {
|
1814 | a: a,
|
1815 | b: b,
|
1816 | c: c,
|
1817 | d: d,
|
1818 | e: e,
|
1819 | f: f
|
1820 | };
|
1821 | break;
|
1822 | }
|
1823 |
|
1824 | return extend(matrix, a);
|
1825 | }
|
1826 |
|
1827 | function createTransform(matrix) {
|
1828 | if (matrix) {
|
1829 | return node.createSVGTransformFromMatrix(matrix);
|
1830 | } else {
|
1831 | return node.createSVGTransform();
|
1832 | }
|
1833 | }
|
1834 |
|
1835 | |
1836 |
|
1837 |
|
1838 |
|
1839 | var TEXT_ENTITIES = /([&<>]{1})/g;
|
1840 | var ATTR_ENTITIES = /([\n\r"]{1})/g;
|
1841 |
|
1842 | var ENTITY_REPLACEMENT = {
|
1843 | '&': '&',
|
1844 | '<': '<',
|
1845 | '>': '>',
|
1846 | '"': '\''
|
1847 | };
|
1848 |
|
1849 | function escape(str, pattern) {
|
1850 |
|
1851 | function replaceFn(match, entity) {
|
1852 | return ENTITY_REPLACEMENT[entity] || entity;
|
1853 | }
|
1854 |
|
1855 | return str.replace(pattern, replaceFn);
|
1856 | }
|
1857 |
|
1858 | function serialize(node, output) {
|
1859 |
|
1860 | var i, len, attrMap, attrNode, childNodes;
|
1861 |
|
1862 | switch (node.nodeType) {
|
1863 |
|
1864 | case 3:
|
1865 |
|
1866 | output.push(escape(node.textContent, TEXT_ENTITIES));
|
1867 | break;
|
1868 |
|
1869 |
|
1870 | case 1:
|
1871 | output.push('<', node.tagName);
|
1872 |
|
1873 | if (node.hasAttributes()) {
|
1874 | attrMap = node.attributes;
|
1875 | for (i = 0, len = attrMap.length; i < len; ++i) {
|
1876 | attrNode = attrMap.item(i);
|
1877 | output.push(' ', attrNode.name, '="', escape(attrNode.value, ATTR_ENTITIES), '"');
|
1878 | }
|
1879 | }
|
1880 |
|
1881 | if (node.hasChildNodes()) {
|
1882 | output.push('>');
|
1883 | childNodes = node.childNodes;
|
1884 | for (i = 0, len = childNodes.length; i < len; ++i) {
|
1885 | serialize(childNodes.item(i), output);
|
1886 | }
|
1887 | output.push('</', node.tagName, '>');
|
1888 | } else {
|
1889 | output.push('/>');
|
1890 | }
|
1891 | break;
|
1892 |
|
1893 |
|
1894 | case 8:
|
1895 | output.push('<!--', escape(node.nodeValue, TEXT_ENTITIES), '-->');
|
1896 | break;
|
1897 |
|
1898 |
|
1899 | case 4:
|
1900 | output.push('<![CDATA[', node.nodeValue, ']]>');
|
1901 | break;
|
1902 |
|
1903 | default:
|
1904 | throw new Error('unable to handle node ' + node.nodeType);
|
1905 | }
|
1906 |
|
1907 | return output;
|
1908 | }
|
1909 |
|
1910 | |
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 | function set(element, svg) {
|
1917 |
|
1918 | var parsed = parse$1(svg);
|
1919 |
|
1920 |
|
1921 | clear$1(element);
|
1922 |
|
1923 | if (!svg) {
|
1924 | return;
|
1925 | }
|
1926 |
|
1927 | if (!isFragment(parsed)) {
|
1928 |
|
1929 | parsed = parsed.documentElement;
|
1930 | }
|
1931 |
|
1932 | var nodes = slice$1(parsed.childNodes);
|
1933 |
|
1934 |
|
1935 | for (var i = 0; i < nodes.length; i++) {
|
1936 | appendTo(nodes[i], element);
|
1937 | }
|
1938 |
|
1939 | }
|
1940 |
|
1941 | function get(element) {
|
1942 | var child = element.firstChild,
|
1943 | output = [];
|
1944 |
|
1945 | while (child) {
|
1946 | serialize(child, output);
|
1947 | child = child.nextSibling;
|
1948 | }
|
1949 |
|
1950 | return output.join('');
|
1951 | }
|
1952 |
|
1953 | function isFragment(node) {
|
1954 | return node.nodeName === '#document-fragment';
|
1955 | }
|
1956 |
|
1957 | function innerSVG(element, svg) {
|
1958 |
|
1959 | if (svg !== undefined) {
|
1960 |
|
1961 | try {
|
1962 | set(element, svg);
|
1963 | } catch (e) {
|
1964 | throw new Error('error parsing SVG: ' + e.message);
|
1965 | }
|
1966 |
|
1967 | return element;
|
1968 | } else {
|
1969 | return get(element);
|
1970 | }
|
1971 | }
|
1972 |
|
1973 |
|
1974 | function slice$1(arr) {
|
1975 | return Array.prototype.slice.call(arr);
|
1976 | }
|
1977 |
|
1978 | |
1979 |
|
1980 |
|
1981 |
|
1982 | function wrapMatrix(transformList, transform) {
|
1983 | if (transform instanceof SVGMatrix) {
|
1984 | return transformList.createSVGTransformFromMatrix(transform);
|
1985 | } else {
|
1986 | return transform;
|
1987 | }
|
1988 | }
|
1989 |
|
1990 | function setTransforms(transformList, transforms) {
|
1991 | var i, t;
|
1992 |
|
1993 | transformList.clear();
|
1994 |
|
1995 | for (i = 0; (t = transforms[i]); i++) {
|
1996 | transformList.appendItem(wrapMatrix(transformList, t));
|
1997 | }
|
1998 |
|
1999 | transformList.consolidate();
|
2000 | }
|
2001 |
|
2002 | function transform(node, transforms) {
|
2003 | var transformList = node.transform.baseVal;
|
2004 |
|
2005 | if (arguments.length === 1) {
|
2006 | return transformList.consolidate();
|
2007 | } else {
|
2008 | if (transforms.length) {
|
2009 | setTransforms(transformList, transforms);
|
2010 | } else {
|
2011 | transformList.initialize(wrapMatrix(transformList, transforms));
|
2012 | }
|
2013 | }
|
2014 | }
|
2015 |
|
2016 | var CLASS_PATTERN = /^class /;
|
2017 |
|
2018 | function isClass(fn) {
|
2019 | return CLASS_PATTERN.test(fn.toString());
|
2020 | }
|
2021 |
|
2022 | function isArray$1(obj) {
|
2023 | return Object.prototype.toString.call(obj) === '[object Array]';
|
2024 | }
|
2025 |
|
2026 | function annotate() {
|
2027 | var args = Array.prototype.slice.call(arguments);
|
2028 |
|
2029 | if (args.length === 1 && isArray$1(args[0])) {
|
2030 | args = args[0];
|
2031 | }
|
2032 |
|
2033 | var fn = args.pop();
|
2034 |
|
2035 | fn.$inject = args;
|
2036 |
|
2037 | return fn;
|
2038 | }
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 | var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
|
2054 | var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;
|
2055 | var FN_ARG = /\/\*([^*]*)\*\//m;
|
2056 |
|
2057 | function parse$2(fn) {
|
2058 |
|
2059 | if (typeof fn !== 'function') {
|
2060 | throw new Error('Cannot annotate "' + fn + '". Expected a function!');
|
2061 | }
|
2062 |
|
2063 | var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
|
2064 |
|
2065 |
|
2066 | if (!match) {
|
2067 | return [];
|
2068 | }
|
2069 |
|
2070 | return match[1] && match[1].split(',').map(function (arg) {
|
2071 | match = arg.match(FN_ARG);
|
2072 | return match ? match[1].trim() : arg.trim();
|
2073 | }) || [];
|
2074 | }
|
2075 |
|
2076 | function Module() {
|
2077 | var providers = [];
|
2078 |
|
2079 | this.factory = function (name, factory) {
|
2080 | providers.push([name, 'factory', factory]);
|
2081 | return this;
|
2082 | };
|
2083 |
|
2084 | this.value = function (name, value) {
|
2085 | providers.push([name, 'value', value]);
|
2086 | return this;
|
2087 | };
|
2088 |
|
2089 | this.type = function (name, type) {
|
2090 | providers.push([name, 'type', type]);
|
2091 | return this;
|
2092 | };
|
2093 |
|
2094 | this.forEach = function (iterator) {
|
2095 | providers.forEach(iterator);
|
2096 | };
|
2097 | }
|
2098 |
|
2099 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
2100 |
|
2101 | function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
2102 |
|
2103 | function Injector(modules, parent) {
|
2104 | parent = parent || {
|
2105 | get: function get(name, strict) {
|
2106 | currentlyResolving.push(name);
|
2107 |
|
2108 | if (strict === false) {
|
2109 | return null;
|
2110 | } else {
|
2111 | throw error('No provider for "' + name + '"!');
|
2112 | }
|
2113 | }
|
2114 | };
|
2115 |
|
2116 | var currentlyResolving = [];
|
2117 | var providers = this._providers = Object.create(parent._providers || null);
|
2118 | var instances = this._instances = Object.create(null);
|
2119 |
|
2120 | var self = instances.injector = this;
|
2121 |
|
2122 | var error = function error(msg) {
|
2123 | var stack = currentlyResolving.join(' -> ');
|
2124 | currentlyResolving.length = 0;
|
2125 | return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
|
2126 | };
|
2127 |
|
2128 | |
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 | var get = function get(name, strict) {
|
2137 | if (!providers[name] && name.indexOf('.') !== -1) {
|
2138 | var parts = name.split('.');
|
2139 | var pivot = get(parts.shift());
|
2140 |
|
2141 | while (parts.length) {
|
2142 | pivot = pivot[parts.shift()];
|
2143 | }
|
2144 |
|
2145 | return pivot;
|
2146 | }
|
2147 |
|
2148 | if (hasProp(instances, name)) {
|
2149 | return instances[name];
|
2150 | }
|
2151 |
|
2152 | if (hasProp(providers, name)) {
|
2153 | if (currentlyResolving.indexOf(name) !== -1) {
|
2154 | currentlyResolving.push(name);
|
2155 | throw error('Cannot resolve circular dependency!');
|
2156 | }
|
2157 |
|
2158 | currentlyResolving.push(name);
|
2159 | instances[name] = providers[name][0](providers[name][1]);
|
2160 | currentlyResolving.pop();
|
2161 |
|
2162 | return instances[name];
|
2163 | }
|
2164 |
|
2165 | return parent.get(name, strict);
|
2166 | };
|
2167 |
|
2168 | var fnDef = function fnDef(fn) {
|
2169 | var locals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
2170 |
|
2171 | if (typeof fn !== 'function') {
|
2172 | if (isArray$1(fn)) {
|
2173 | fn = annotate(fn.slice());
|
2174 | } else {
|
2175 | throw new Error('Cannot invoke "' + fn + '". Expected a function!');
|
2176 | }
|
2177 | }
|
2178 |
|
2179 | var inject = fn.$inject || parse$2(fn);
|
2180 | var dependencies = inject.map(function (dep) {
|
2181 | if (hasProp(locals, dep)) {
|
2182 | return locals[dep];
|
2183 | } else {
|
2184 | return get(dep);
|
2185 | }
|
2186 | });
|
2187 |
|
2188 | return {
|
2189 | fn: fn,
|
2190 | dependencies: dependencies
|
2191 | };
|
2192 | };
|
2193 |
|
2194 | var instantiate = function instantiate(Type) {
|
2195 | var _fnDef = fnDef(Type),
|
2196 | dependencies = _fnDef.dependencies,
|
2197 | fn = _fnDef.fn;
|
2198 |
|
2199 | return new (Function.prototype.bind.apply(fn, [null].concat(_toConsumableArray$1(dependencies))))();
|
2200 | };
|
2201 |
|
2202 | var invoke = function invoke(func, context, locals) {
|
2203 | var _fnDef2 = fnDef(func, locals),
|
2204 | dependencies = _fnDef2.dependencies,
|
2205 | fn = _fnDef2.fn;
|
2206 |
|
2207 | return fn.call.apply(fn, [context].concat(_toConsumableArray$1(dependencies)));
|
2208 | };
|
2209 |
|
2210 | var createPrivateInjectorFactory = function createPrivateInjectorFactory(privateChildInjector) {
|
2211 | return annotate(function (key) {
|
2212 | return privateChildInjector.get(key);
|
2213 | });
|
2214 | };
|
2215 |
|
2216 | var createChild = function createChild(modules, forceNewInstances) {
|
2217 | if (forceNewInstances && forceNewInstances.length) {
|
2218 | var fromParentModule = Object.create(null);
|
2219 | var matchedScopes = Object.create(null);
|
2220 |
|
2221 | var privateInjectorsCache = [];
|
2222 | var privateChildInjectors = [];
|
2223 | var privateChildFactories = [];
|
2224 |
|
2225 | var provider;
|
2226 | var cacheIdx;
|
2227 | var privateChildInjector;
|
2228 | var privateChildInjectorFactory;
|
2229 | for (var name in providers) {
|
2230 | provider = providers[name];
|
2231 |
|
2232 | if (forceNewInstances.indexOf(name) !== -1) {
|
2233 | if (provider[2] === 'private') {
|
2234 | cacheIdx = privateInjectorsCache.indexOf(provider[3]);
|
2235 | if (cacheIdx === -1) {
|
2236 | privateChildInjector = provider[3].createChild([], forceNewInstances);
|
2237 | privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
|
2238 | privateInjectorsCache.push(provider[3]);
|
2239 | privateChildInjectors.push(privateChildInjector);
|
2240 | privateChildFactories.push(privateChildInjectorFactory);
|
2241 | fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
|
2242 | } else {
|
2243 | fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
|
2244 | }
|
2245 | } else {
|
2246 | fromParentModule[name] = [provider[2], provider[1]];
|
2247 | }
|
2248 | matchedScopes[name] = true;
|
2249 | }
|
2250 |
|
2251 | if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
|
2252 |
|
2253 | forceNewInstances.forEach(function (scope) {
|
2254 | if (provider[1].$scope.indexOf(scope) !== -1) {
|
2255 | fromParentModule[name] = [provider[2], provider[1]];
|
2256 | matchedScopes[scope] = true;
|
2257 | }
|
2258 | });
|
2259 | }
|
2260 | }
|
2261 |
|
2262 | forceNewInstances.forEach(function (scope) {
|
2263 | if (!matchedScopes[scope]) {
|
2264 | throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
|
2265 | }
|
2266 | });
|
2267 |
|
2268 | modules.unshift(fromParentModule);
|
2269 | }
|
2270 |
|
2271 | return new Injector(modules, self);
|
2272 | };
|
2273 |
|
2274 | var factoryMap = {
|
2275 | factory: invoke,
|
2276 | type: instantiate,
|
2277 | value: function value(_value) {
|
2278 | return _value;
|
2279 | }
|
2280 | };
|
2281 |
|
2282 | modules.forEach(function (module) {
|
2283 |
|
2284 | function arrayUnwrap(type, value) {
|
2285 | if (type !== 'value' && isArray$1(value)) {
|
2286 | value = annotate(value.slice());
|
2287 | }
|
2288 |
|
2289 | return value;
|
2290 | }
|
2291 |
|
2292 |
|
2293 | if (module instanceof Module) {
|
2294 | module.forEach(function (provider) {
|
2295 | var name = provider[0];
|
2296 | var type = provider[1];
|
2297 | var value = provider[2];
|
2298 |
|
2299 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2300 | });
|
2301 | } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
|
2302 | if (module.__exports__) {
|
2303 | var clonedModule = Object.keys(module).reduce(function (m, key) {
|
2304 | if (key.substring(0, 2) !== '__') {
|
2305 | m[key] = module[key];
|
2306 | }
|
2307 | return m;
|
2308 | }, Object.create(null));
|
2309 |
|
2310 | var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
|
2311 | var getFromPrivateInjector = annotate(function (key) {
|
2312 | return privateInjector.get(key);
|
2313 | });
|
2314 | module.__exports__.forEach(function (key) {
|
2315 | providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
|
2316 | });
|
2317 | } else {
|
2318 | Object.keys(module).forEach(function (name) {
|
2319 | if (module[name][2] === 'private') {
|
2320 | providers[name] = module[name];
|
2321 | return;
|
2322 | }
|
2323 |
|
2324 | var type = module[name][0];
|
2325 | var value = module[name][1];
|
2326 |
|
2327 | providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
|
2328 | });
|
2329 | }
|
2330 | }
|
2331 | });
|
2332 |
|
2333 |
|
2334 | this.get = get;
|
2335 | this.invoke = invoke;
|
2336 | this.instantiate = instantiate;
|
2337 | this.createChild = createChild;
|
2338 | }
|
2339 |
|
2340 | // helpers /////////////////
|
2341 |
|
2342 | function hasProp(obj, prop) {
|
2343 | return Object.hasOwnProperty.call(obj, prop);
|
2344 | }
|
2345 |
|
2346 | var DEFAULT_RENDER_PRIORITY = 1000;
|
2347 |
|
2348 | |
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 | function BaseRenderer(eventBus, renderPriority) {
|
2355 | var self = this;
|
2356 |
|
2357 | renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
|
2358 |
|
2359 | eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
|
2360 | var type = evt.type,
|
2361 | element = context.element,
|
2362 | visuals = context.gfx;
|
2363 |
|
2364 | if (self.canRender(element)) {
|
2365 | if (type === 'render.shape') {
|
2366 | return self.drawShape(visuals, element);
|
2367 | } else {
|
2368 | return self.drawConnection(visuals, element);
|
2369 | }
|
2370 | }
|
2371 | });
|
2372 |
|
2373 | eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
|
2374 | if (self.canRender(element)) {
|
2375 | if (evt.type === 'render.getShapePath') {
|
2376 | return self.getShapePath(element);
|
2377 | } else {
|
2378 | return self.getConnectionPath(element);
|
2379 | }
|
2380 | }
|
2381 | });
|
2382 | }
|
2383 |
|
2384 | |
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 | BaseRenderer.prototype.canRender = function() {};
|
2393 |
|
2394 | |
2395 |
|
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 | BaseRenderer.prototype.drawShape = function() {};
|
2403 |
|
2404 | |
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 | BaseRenderer.prototype.drawConnection = function() {};
|
2413 |
|
2414 | |
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | BaseRenderer.prototype.getShapePath = function() {};
|
2422 |
|
2423 | |
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 | BaseRenderer.prototype.getConnectionPath = function() {};
|
2431 |
|
2432 | function componentsToPath(elements) {
|
2433 | return elements.join(',').replace(/,?([A-z]),?/g, '$1');
|
2434 | }
|
2435 |
|
2436 | function toSVGPoints(points) {
|
2437 | var result = '';
|
2438 |
|
2439 | for (var i = 0, p; (p = points[i]); i++) {
|
2440 | result += p.x + ',' + p.y + ' ';
|
2441 | }
|
2442 |
|
2443 | return result;
|
2444 | }
|
2445 |
|
2446 | function createLine(points, attrs) {
|
2447 |
|
2448 | var line = create('polyline');
|
2449 | attr$1(line, { points: toSVGPoints(points) });
|
2450 |
|
2451 | if (attrs) {
|
2452 | attr$1(line, attrs);
|
2453 | }
|
2454 |
|
2455 | return line;
|
2456 | }
|
2457 |
|
2458 | function updateLine(gfx, points) {
|
2459 | attr$1(gfx, { points: toSVGPoints(points) });
|
2460 |
|
2461 | return gfx;
|
2462 | }
|
2463 |
|
2464 |
|
2465 |
|
2466 | var DEFAULT_RENDER_PRIORITY$1 = 1;
|
2467 |
|
2468 | |
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 | function DefaultRenderer(eventBus, styles) {
|
2475 |
|
2476 | BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY$1);
|
2477 |
|
2478 | this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
|
2479 | this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
|
2480 | }
|
2481 |
|
2482 | inherits_browser(DefaultRenderer, BaseRenderer);
|
2483 |
|
2484 |
|
2485 | DefaultRenderer.prototype.canRender = function() {
|
2486 | return true;
|
2487 | };
|
2488 |
|
2489 | DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
|
2490 |
|
2491 | var rect = create('rect');
|
2492 | attr$1(rect, {
|
2493 | x: 0,
|
2494 | y: 0,
|
2495 | width: element.width || 0,
|
2496 | height: element.height || 0
|
2497 | });
|
2498 | attr$1(rect, this.SHAPE_STYLE);
|
2499 |
|
2500 | append(visuals, rect);
|
2501 |
|
2502 | return rect;
|
2503 | };
|
2504 |
|
2505 | DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
|
2506 |
|
2507 | var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
|
2508 | append(visuals, line);
|
2509 |
|
2510 | return line;
|
2511 | };
|
2512 |
|
2513 | DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
|
2514 |
|
2515 | var x = shape.x,
|
2516 | y = shape.y,
|
2517 | width = shape.width,
|
2518 | height = shape.height;
|
2519 |
|
2520 | var shapePath = [
|
2521 | ['M', x, y],
|
2522 | ['l', width, 0],
|
2523 | ['l', 0, height],
|
2524 | ['l', -width, 0],
|
2525 | ['z']
|
2526 | ];
|
2527 |
|
2528 | return componentsToPath(shapePath);
|
2529 | };
|
2530 |
|
2531 | DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
|
2532 | var waypoints = connection.waypoints;
|
2533 |
|
2534 | var idx, point, connectionPath = [];
|
2535 |
|
2536 | for (idx = 0; (point = waypoints[idx]); idx++) {
|
2537 |
|
2538 |
|
2539 |
|
2540 | point = point.original || point;
|
2541 |
|
2542 | connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
|
2543 | }
|
2544 |
|
2545 | return componentsToPath(connectionPath);
|
2546 | };
|
2547 |
|
2548 |
|
2549 | DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
|
2550 |
|
2551 | |
2552 |
|
2553 |
|
2554 | function Styles() {
|
2555 |
|
2556 | var defaultTraits = {
|
2557 |
|
2558 | 'no-fill': {
|
2559 | fill: 'none'
|
2560 | },
|
2561 | 'no-border': {
|
2562 | strokeOpacity: 0.0
|
2563 | },
|
2564 | 'no-events': {
|
2565 | pointerEvents: 'none'
|
2566 | }
|
2567 | };
|
2568 |
|
2569 | var self = this;
|
2570 |
|
2571 | |
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 | this.cls = function(className, traits, additionalAttrs) {
|
2581 | var attrs = this.style(traits, additionalAttrs);
|
2582 |
|
2583 | return assign(attrs, { 'class': className });
|
2584 | };
|
2585 |
|
2586 | |
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 | this.style = function(traits, additionalAttrs) {
|
2595 |
|
2596 | if (!isArray(traits) && !additionalAttrs) {
|
2597 | additionalAttrs = traits;
|
2598 | traits = [];
|
2599 | }
|
2600 |
|
2601 | var attrs = reduce(traits, function(attrs, t) {
|
2602 | return assign(attrs, defaultTraits[t] || {});
|
2603 | }, {});
|
2604 |
|
2605 | return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
|
2606 | };
|
2607 |
|
2608 | this.computeStyle = function(custom, traits, defaultStyles) {
|
2609 | if (!isArray(traits)) {
|
2610 | defaultStyles = traits;
|
2611 | traits = [];
|
2612 | }
|
2613 |
|
2614 | return self.style(traits || [], assign({}, defaultStyles, custom || {}));
|
2615 | };
|
2616 | }
|
2617 |
|
2618 | var DrawModule = {
|
2619 | __init__: [ 'defaultRenderer' ],
|
2620 | defaultRenderer: [ 'type', DefaultRenderer ],
|
2621 | styles: [ 'type', Styles ]
|
2622 | };
|
2623 |
|
2624 | |
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 |
|
2631 |
|
2632 | function remove$2(collection, element) {
|
2633 |
|
2634 | if (!collection || !element) {
|
2635 | return -1;
|
2636 | }
|
2637 |
|
2638 | var idx = collection.indexOf(element);
|
2639 |
|
2640 | if (idx !== -1) {
|
2641 | collection.splice(idx, 1);
|
2642 | }
|
2643 |
|
2644 | return idx;
|
2645 | }
|
2646 |
|
2647 | |
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 | function add(collection, element, idx) {
|
2656 |
|
2657 | if (!collection || !element) {
|
2658 | return;
|
2659 | }
|
2660 |
|
2661 | if (typeof idx !== 'number') {
|
2662 | idx = -1;
|
2663 | }
|
2664 |
|
2665 | var currentIdx = collection.indexOf(element);
|
2666 |
|
2667 | if (currentIdx !== -1) {
|
2668 |
|
2669 | if (currentIdx === idx) {
|
2670 |
|
2671 | return;
|
2672 | } else {
|
2673 |
|
2674 | if (idx !== -1) {
|
2675 |
|
2676 | collection.splice(currentIdx, 1);
|
2677 | } else {
|
2678 |
|
2679 | return;
|
2680 | }
|
2681 | }
|
2682 | }
|
2683 |
|
2684 | if (idx !== -1) {
|
2685 |
|
2686 | collection.splice(idx, 0, element);
|
2687 | } else {
|
2688 |
|
2689 | collection.push(element);
|
2690 | }
|
2691 | }
|
2692 |
|
2693 |
|
2694 | |
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 | function indexOf$1(collection, element) {
|
2704 |
|
2705 | if (!collection || !element) {
|
2706 | return -1;
|
2707 | }
|
2708 |
|
2709 | return collection.indexOf(element);
|
2710 | }
|
2711 |
|
2712 | |
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 | function add$1(elements, e, unique) {
|
2721 | var canAdd = !unique || elements.indexOf(e) === -1;
|
2722 |
|
2723 | if (canAdd) {
|
2724 | elements.push(e);
|
2725 | }
|
2726 |
|
2727 | return canAdd;
|
2728 | }
|
2729 |
|
2730 |
|
2731 | |
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 | function eachElement(elements, fn, depth) {
|
2742 |
|
2743 | depth = depth || 0;
|
2744 |
|
2745 | if (!isArray(elements)) {
|
2746 | elements = [ elements ];
|
2747 | }
|
2748 |
|
2749 | forEach(elements, function(s, i) {
|
2750 | var filter$$1 = fn(s, i, depth);
|
2751 |
|
2752 | if (isArray(filter$$1) && filter$$1.length) {
|
2753 | eachElement(filter$$1, fn, depth + 1);
|
2754 | }
|
2755 | });
|
2756 | }
|
2757 |
|
2758 |
|
2759 | |
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 | function selfAndChildren(elements, unique, maxDepth) {
|
2769 | var result = [],
|
2770 | processedChildren = [];
|
2771 |
|
2772 | eachElement(elements, function(element, i, depth) {
|
2773 | add$1(result, element, unique);
|
2774 |
|
2775 | var children = element.children;
|
2776 |
|
2777 |
|
2778 | if (maxDepth === -1 || depth < maxDepth) {
|
2779 |
|
2780 |
|
2781 | if (children && add$1(processedChildren, children, unique)) {
|
2782 | return children;
|
2783 | }
|
2784 | }
|
2785 | });
|
2786 |
|
2787 | return result;
|
2788 | }
|
2789 |
|
2790 |
|
2791 | |
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 | function selfAndAllChildren(elements, allowDuplicates) {
|
2800 | return selfAndChildren(elements, !allowDuplicates, -1);
|
2801 | }
|
2802 |
|
2803 |
|
2804 | |
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 | function getClosure(elements, isTopLevel, closure) {
|
2815 |
|
2816 | if (isUndefined(isTopLevel)) {
|
2817 | isTopLevel = true;
|
2818 | }
|
2819 |
|
2820 | if (isObject(isTopLevel)) {
|
2821 | closure = isTopLevel;
|
2822 | isTopLevel = true;
|
2823 | }
|
2824 |
|
2825 |
|
2826 | closure = closure || {};
|
2827 |
|
2828 | var allShapes = copyObject(closure.allShapes),
|
2829 | allConnections = copyObject(closure.allConnections),
|
2830 | enclosedElements = copyObject(closure.enclosedElements),
|
2831 | enclosedConnections = copyObject(closure.enclosedConnections);
|
2832 |
|
2833 | var topLevel = copyObject(
|
2834 | closure.topLevel,
|
2835 | isTopLevel && groupBy(elements, function(e) { return e.id; })
|
2836 | );
|
2837 |
|
2838 |
|
2839 | function handleConnection(c) {
|
2840 | if (topLevel[c.source.id] && topLevel[c.target.id]) {
|
2841 | topLevel[c.id] = [ c ];
|
2842 | }
|
2843 |
|
2844 |
|
2845 |
|
2846 | if (allShapes[c.source.id] && allShapes[c.target.id]) {
|
2847 | enclosedConnections[c.id] = enclosedElements[c.id] = c;
|
2848 | }
|
2849 |
|
2850 | allConnections[c.id] = c;
|
2851 | }
|
2852 |
|
2853 | function handleElement(element) {
|
2854 |
|
2855 | enclosedElements[element.id] = element;
|
2856 |
|
2857 | if (element.waypoints) {
|
2858 |
|
2859 | enclosedConnections[element.id] = allConnections[element.id] = element;
|
2860 | } else {
|
2861 |
|
2862 | allShapes[element.id] = element;
|
2863 |
|
2864 |
|
2865 | forEach(element.incoming, handleConnection);
|
2866 |
|
2867 | forEach(element.outgoing, handleConnection);
|
2868 |
|
2869 |
|
2870 | return element.children;
|
2871 | }
|
2872 | }
|
2873 |
|
2874 | eachElement(elements, handleElement);
|
2875 |
|
2876 | return {
|
2877 | allShapes: allShapes,
|
2878 | allConnections: allConnections,
|
2879 | topLevel: topLevel,
|
2880 | enclosedConnections: enclosedConnections,
|
2881 | enclosedElements: enclosedElements
|
2882 | };
|
2883 | }
|
2884 |
|
2885 | |
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 |
|
2892 | function getBBox(elements, stopRecursion) {
|
2893 |
|
2894 | stopRecursion = !!stopRecursion;
|
2895 | if (!isArray(elements)) {
|
2896 | elements = [elements];
|
2897 | }
|
2898 |
|
2899 | var minX,
|
2900 | minY,
|
2901 | maxX,
|
2902 | maxY;
|
2903 |
|
2904 | forEach(elements, function(element) {
|
2905 |
|
2906 |
|
2907 | var bbox = element;
|
2908 | if (element.waypoints && !stopRecursion) {
|
2909 | bbox = getBBox(element.waypoints, true);
|
2910 | }
|
2911 |
|
2912 | var x = bbox.x,
|
2913 | y = bbox.y,
|
2914 | height = bbox.height || 0,
|
2915 | width = bbox.width || 0;
|
2916 |
|
2917 | if (x < minX || minX === undefined) {
|
2918 | minX = x;
|
2919 | }
|
2920 | if (y < minY || minY === undefined) {
|
2921 | minY = y;
|
2922 | }
|
2923 |
|
2924 | if ((x + width) > maxX || maxX === undefined) {
|
2925 | maxX = x + width;
|
2926 | }
|
2927 | if ((y + height) > maxY || maxY === undefined) {
|
2928 | maxY = y + height;
|
2929 | }
|
2930 | });
|
2931 |
|
2932 | return {
|
2933 | x: minX,
|
2934 | y: minY,
|
2935 | height: maxY - minY,
|
2936 | width: maxX - minX
|
2937 | };
|
2938 | }
|
2939 |
|
2940 |
|
2941 | |
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 | function getEnclosedElements(elements, bbox) {
|
2955 |
|
2956 | var filteredElements = {};
|
2957 |
|
2958 | forEach(elements, function(element) {
|
2959 |
|
2960 | var e = element;
|
2961 |
|
2962 | if (e.waypoints) {
|
2963 | e = getBBox(e);
|
2964 | }
|
2965 |
|
2966 | if (!isNumber(bbox.y) && (e.x > bbox.x)) {
|
2967 | filteredElements[element.id] = element;
|
2968 | }
|
2969 | if (!isNumber(bbox.x) && (e.y > bbox.y)) {
|
2970 | filteredElements[element.id] = element;
|
2971 | }
|
2972 | if (e.x > bbox.x && e.y > bbox.y) {
|
2973 | if (isNumber(bbox.width) && isNumber(bbox.height) &&
|
2974 | e.width + e.x < bbox.width + bbox.x &&
|
2975 | e.height + e.y < bbox.height + bbox.y) {
|
2976 |
|
2977 | filteredElements[element.id] = element;
|
2978 | } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) {
|
2979 | filteredElements[element.id] = element;
|
2980 | }
|
2981 | }
|
2982 | });
|
2983 |
|
2984 | return filteredElements;
|
2985 | }
|
2986 |
|
2987 |
|
2988 | function getType(element) {
|
2989 |
|
2990 | if ('waypoints' in element) {
|
2991 | return 'connection';
|
2992 | }
|
2993 |
|
2994 | if ('x' in element) {
|
2995 | return 'shape';
|
2996 | }
|
2997 |
|
2998 | return 'root';
|
2999 | }
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 | function copyObject(src1, src2) {
|
3005 | return assign({}, src1 || {}, src2 || {});
|
3006 | }
|
3007 |
|
3008 | function round(number, resolution) {
|
3009 | return Math.round(number * resolution) / resolution;
|
3010 | }
|
3011 |
|
3012 | function ensurePx(number) {
|
3013 | return isNumber(number) ? number + 'px' : number;
|
3014 | }
|
3015 |
|
3016 | |
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 | function createContainer(options) {
|
3024 |
|
3025 | options = assign({}, { width: '100%', height: '100%' }, options);
|
3026 |
|
3027 | var container = options.container || document.body;
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 | var parent = document.createElement('div');
|
3033 | parent.setAttribute('class', 'djs-container');
|
3034 |
|
3035 | assign(parent.style, {
|
3036 | position: 'relative',
|
3037 | overflow: 'hidden',
|
3038 | width: ensurePx(options.width),
|
3039 | height: ensurePx(options.height)
|
3040 | });
|
3041 |
|
3042 | container.appendChild(parent);
|
3043 |
|
3044 | return parent;
|
3045 | }
|
3046 |
|
3047 | function createGroup(parent, cls, childIndex) {
|
3048 | var group = create('g');
|
3049 | classes$1(group).add(cls);
|
3050 |
|
3051 | var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
|
3052 |
|
3053 |
|
3054 |
|
3055 | parent.insertBefore(group, parent.childNodes[index] || null);
|
3056 |
|
3057 | return group;
|
3058 | }
|
3059 |
|
3060 | var BASE_LAYER = 'base';
|
3061 |
|
3062 |
|
3063 | var REQUIRED_MODEL_ATTRS = {
|
3064 | shape: [ 'x', 'y', 'width', 'height' ],
|
3065 | connection: [ 'waypoints' ]
|
3066 | };
|
3067 |
|
3068 | |
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 | function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
|
3082 |
|
3083 | this._eventBus = eventBus;
|
3084 | this._elementRegistry = elementRegistry;
|
3085 | this._graphicsFactory = graphicsFactory;
|
3086 |
|
3087 | this._init(config || {});
|
3088 | }
|
3089 |
|
3090 | Canvas.$inject = [
|
3091 | 'config.canvas',
|
3092 | 'eventBus',
|
3093 | 'graphicsFactory',
|
3094 | 'elementRegistry'
|
3095 | ];
|
3096 |
|
3097 |
|
3098 | Canvas.prototype._init = function(config) {
|
3099 |
|
3100 | var eventBus = this._eventBus;
|
3101 |
|
3102 |
|
3103 |
|
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 | var container = this._container = createContainer(config);
|
3116 |
|
3117 | var svg = this._svg = create('svg');
|
3118 | attr$1(svg, { width: '100%', height: '100%' });
|
3119 |
|
3120 | append(container, svg);
|
3121 |
|
3122 | var viewport = this._viewport = createGroup(svg, 'viewport');
|
3123 |
|
3124 | this._layers = {};
|
3125 |
|
3126 |
|
3127 |
|
3128 | if (config.deferUpdate !== false) {
|
3129 | this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
|
3130 | }
|
3131 |
|
3132 | eventBus.on('diagram.init', function() {
|
3133 |
|
3134 | |
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 | eventBus.fire('canvas.init', {
|
3146 | svg: svg,
|
3147 | viewport: viewport
|
3148 | });
|
3149 |
|
3150 | }, this);
|
3151 |
|
3152 |
|
3153 |
|
3154 | eventBus.on([
|
3155 | 'shape.added',
|
3156 | 'connection.added',
|
3157 | 'shape.removed',
|
3158 | 'connection.removed',
|
3159 | 'elements.changed'
|
3160 | ], function() {
|
3161 | delete this._cachedViewbox;
|
3162 | }, this);
|
3163 |
|
3164 | eventBus.on('diagram.destroy', 500, this._destroy, this);
|
3165 | eventBus.on('diagram.clear', 500, this._clear, this);
|
3166 | };
|
3167 |
|
3168 | Canvas.prototype._destroy = function(emit) {
|
3169 | this._eventBus.fire('canvas.destroy', {
|
3170 | svg: this._svg,
|
3171 | viewport: this._viewport
|
3172 | });
|
3173 |
|
3174 | var parent = this._container.parentNode;
|
3175 |
|
3176 | if (parent) {
|
3177 | parent.removeChild(this._container);
|
3178 | }
|
3179 |
|
3180 | delete this._svg;
|
3181 | delete this._container;
|
3182 | delete this._layers;
|
3183 | delete this._rootElement;
|
3184 | delete this._viewport;
|
3185 | };
|
3186 |
|
3187 | Canvas.prototype._clear = function() {
|
3188 |
|
3189 | var self = this;
|
3190 |
|
3191 | var allElements = this._elementRegistry.getAll();
|
3192 |
|
3193 |
|
3194 | allElements.forEach(function(element) {
|
3195 | var type = getType(element);
|
3196 |
|
3197 | if (type === 'root') {
|
3198 | self.setRootElement(null, true);
|
3199 | } else {
|
3200 | self._removeElement(element, type);
|
3201 | }
|
3202 | });
|
3203 |
|
3204 |
|
3205 | delete this._cachedViewbox;
|
3206 | };
|
3207 |
|
3208 | |
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 | Canvas.prototype.getDefaultLayer = function() {
|
3215 | return this.getLayer(BASE_LAYER, 0);
|
3216 | };
|
3217 |
|
3218 | |
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 |
|
3233 | Canvas.prototype.getLayer = function(name, index) {
|
3234 |
|
3235 | if (!name) {
|
3236 | throw new Error('must specify a name');
|
3237 | }
|
3238 |
|
3239 | var layer = this._layers[name];
|
3240 |
|
3241 | if (!layer) {
|
3242 | layer = this._layers[name] = this._createLayer(name, index);
|
3243 | }
|
3244 |
|
3245 |
|
3246 |
|
3247 | if (typeof index !== 'undefined' && layer.index !== index) {
|
3248 | throw new Error('layer <' + name + '> already created at index <' + index + '>');
|
3249 | }
|
3250 |
|
3251 | return layer.group;
|
3252 | };
|
3253 |
|
3254 | |
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 | Canvas.prototype._createLayer = function(name, index) {
|
3263 |
|
3264 | if (!index) {
|
3265 | index = 0;
|
3266 | }
|
3267 |
|
3268 | var childIndex = reduce(this._layers, function(childIndex, layer) {
|
3269 | if (index >= layer.index) {
|
3270 | childIndex++;
|
3271 | }
|
3272 |
|
3273 | return childIndex;
|
3274 | }, 0);
|
3275 |
|
3276 | return {
|
3277 | group: createGroup(this._viewport, 'layer-' + name, childIndex),
|
3278 | index: index
|
3279 | };
|
3280 |
|
3281 | };
|
3282 |
|
3283 | |
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 | Canvas.prototype.getContainer = function() {
|
3290 | return this._container;
|
3291 | };
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 | Canvas.prototype._updateMarker = function(element, marker, add$$1) {
|
3297 | var container;
|
3298 |
|
3299 | if (!element.id) {
|
3300 | element = this._elementRegistry.get(element);
|
3301 | }
|
3302 |
|
3303 |
|
3304 | container = this._elementRegistry._elements[element.id];
|
3305 |
|
3306 | if (!container) {
|
3307 | return;
|
3308 | }
|
3309 |
|
3310 | forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
|
3311 | if (gfx) {
|
3312 |
|
3313 | if (add$$1) {
|
3314 | classes$1(gfx).add(marker);
|
3315 | } else {
|
3316 | classes$1(gfx).remove(marker);
|
3317 | }
|
3318 | }
|
3319 | });
|
3320 |
|
3321 | |
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 |
|
3331 | this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add$$1 });
|
3332 | };
|
3333 |
|
3334 |
|
3335 | |
3336 |
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 | Canvas.prototype.addMarker = function(element, marker) {
|
3352 | this._updateMarker(element, marker, true);
|
3353 | };
|
3354 |
|
3355 |
|
3356 | |
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 | Canvas.prototype.removeMarker = function(element, marker) {
|
3366 | this._updateMarker(element, marker, false);
|
3367 | };
|
3368 |
|
3369 | |
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 | Canvas.prototype.hasMarker = function(element, marker) {
|
3376 | if (!element.id) {
|
3377 | element = this._elementRegistry.get(element);
|
3378 | }
|
3379 |
|
3380 | var gfx = this.getGraphics(element);
|
3381 |
|
3382 | return classes$1(gfx).has(marker);
|
3383 | };
|
3384 |
|
3385 | |
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 | Canvas.prototype.toggleMarker = function(element, marker) {
|
3395 | if (this.hasMarker(element, marker)) {
|
3396 | this.removeMarker(element, marker);
|
3397 | } else {
|
3398 | this.addMarker(element, marker);
|
3399 | }
|
3400 | };
|
3401 |
|
3402 | Canvas.prototype.getRootElement = function() {
|
3403 | if (!this._rootElement) {
|
3404 | this.setRootElement({ id: '__implicitroot', children: [] });
|
3405 | }
|
3406 |
|
3407 | return this._rootElement;
|
3408 | };
|
3409 |
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 | |
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 | Canvas.prototype.setRootElement = function(element, override) {
|
3424 |
|
3425 | if (element) {
|
3426 | this._ensureValid('root', element);
|
3427 | }
|
3428 |
|
3429 | var currentRoot = this._rootElement,
|
3430 | elementRegistry = this._elementRegistry,
|
3431 | eventBus = this._eventBus;
|
3432 |
|
3433 | if (currentRoot) {
|
3434 | if (!override) {
|
3435 | throw new Error('rootElement already set, need to specify override');
|
3436 | }
|
3437 |
|
3438 |
|
3439 | eventBus.fire('root.remove', { element: currentRoot });
|
3440 | eventBus.fire('root.removed', { element: currentRoot });
|
3441 |
|
3442 | elementRegistry.remove(currentRoot);
|
3443 | }
|
3444 |
|
3445 | if (element) {
|
3446 | var gfx = this.getDefaultLayer();
|
3447 |
|
3448 |
|
3449 | eventBus.fire('root.add', { element: element });
|
3450 |
|
3451 | elementRegistry.add(element, gfx, this._svg);
|
3452 |
|
3453 | eventBus.fire('root.added', { element: element, gfx: gfx });
|
3454 | }
|
3455 |
|
3456 | this._rootElement = element;
|
3457 |
|
3458 | return element;
|
3459 | };
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 | Canvas.prototype._ensureValid = function(type, element) {
|
3466 | if (!element.id) {
|
3467 | throw new Error('element must have an id');
|
3468 | }
|
3469 |
|
3470 | if (this._elementRegistry.get(element.id)) {
|
3471 | throw new Error('element with id ' + element.id + ' already exists');
|
3472 | }
|
3473 |
|
3474 | var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
|
3475 |
|
3476 | var valid = every(requiredAttrs, function(attr$$1) {
|
3477 | return typeof element[attr$$1] !== 'undefined';
|
3478 | });
|
3479 |
|
3480 | if (!valid) {
|
3481 | throw new Error(
|
3482 | 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
|
3483 | }
|
3484 | };
|
3485 |
|
3486 | Canvas.prototype._setParent = function(element, parent, parentIndex) {
|
3487 | add(parent.children, element, parentIndex);
|
3488 | element.parent = parent;
|
3489 | };
|
3490 |
|
3491 | |
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 | Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
|
3512 |
|
3513 | parent = parent || this.getRootElement();
|
3514 |
|
3515 | var eventBus = this._eventBus,
|
3516 | graphicsFactory = this._graphicsFactory;
|
3517 |
|
3518 | this._ensureValid(type, element);
|
3519 |
|
3520 | eventBus.fire(type + '.add', { element: element, parent: parent });
|
3521 |
|
3522 | this._setParent(element, parent, parentIndex);
|
3523 |
|
3524 |
|
3525 | var gfx = graphicsFactory.create(type, element, parentIndex);
|
3526 |
|
3527 | this._elementRegistry.add(element, gfx);
|
3528 |
|
3529 |
|
3530 | graphicsFactory.update(type, element, gfx);
|
3531 |
|
3532 | eventBus.fire(type + '.added', { element: element, gfx: gfx });
|
3533 |
|
3534 | return element;
|
3535 | };
|
3536 |
|
3537 | |
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | Canvas.prototype.addShape = function(shape, parent, parentIndex) {
|
3547 | return this._addElement('shape', shape, parent, parentIndex);
|
3548 | };
|
3549 |
|
3550 | |
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 | Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
|
3560 | return this._addElement('connection', connection, parent, parentIndex);
|
3561 | };
|
3562 |
|
3563 |
|
3564 | |
3565 |
|
3566 |
|
3567 | Canvas.prototype._removeElement = function(element, type) {
|
3568 |
|
3569 | var elementRegistry = this._elementRegistry,
|
3570 | graphicsFactory = this._graphicsFactory,
|
3571 | eventBus = this._eventBus;
|
3572 |
|
3573 | element = elementRegistry.get(element.id || element);
|
3574 |
|
3575 | if (!element) {
|
3576 |
|
3577 | return;
|
3578 | }
|
3579 |
|
3580 | eventBus.fire(type + '.remove', { element: element });
|
3581 |
|
3582 | graphicsFactory.remove(element);
|
3583 |
|
3584 |
|
3585 | remove$2(element.parent && element.parent.children, element);
|
3586 | element.parent = null;
|
3587 |
|
3588 | eventBus.fire(type + '.removed', { element: element });
|
3589 |
|
3590 | elementRegistry.remove(element);
|
3591 |
|
3592 | return element;
|
3593 | };
|
3594 |
|
3595 |
|
3596 | |
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 | Canvas.prototype.removeShape = function(shape) {
|
3604 |
|
3605 | |
3606 |
|
3607 |
|
3608 |
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 | |
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 |
|
3624 |
|
3625 |
|
3626 | return this._removeElement(shape, 'shape');
|
3627 | };
|
3628 |
|
3629 |
|
3630 | |
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 | Canvas.prototype.removeConnection = function(connection) {
|
3638 |
|
3639 | |
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 | |
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 | return this._removeElement(connection, 'connection');
|
3661 | };
|
3662 |
|
3663 |
|
3664 | |
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 | Canvas.prototype.getGraphics = function(element, secondary) {
|
3673 | return this._elementRegistry.getGraphics(element, secondary);
|
3674 | };
|
3675 |
|
3676 |
|
3677 | |
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 | Canvas.prototype._changeViewbox = function(changeFn) {
|
3683 |
|
3684 |
|
3685 | this._eventBus.fire('canvas.viewbox.changing');
|
3686 |
|
3687 |
|
3688 | changeFn.apply(this);
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 | this._cachedViewbox = null;
|
3694 |
|
3695 |
|
3696 |
|
3697 | this._viewboxChanged();
|
3698 | };
|
3699 |
|
3700 | Canvas.prototype._viewboxChanged = function() {
|
3701 | this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
|
3702 | };
|
3703 |
|
3704 |
|
3705 | |
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 | Canvas.prototype.viewbox = function(box) {
|
3751 |
|
3752 | if (box === undefined && this._cachedViewbox) {
|
3753 | return this._cachedViewbox;
|
3754 | }
|
3755 |
|
3756 | var viewport = this._viewport,
|
3757 | innerBox,
|
3758 | outerBox = this.getSize(),
|
3759 | matrix,
|
3760 | transform$$1,
|
3761 | scale,
|
3762 | x, y;
|
3763 |
|
3764 | if (!box) {
|
3765 |
|
3766 |
|
3767 |
|
3768 | innerBox = this.getDefaultLayer().getBBox();
|
3769 |
|
3770 | transform$$1 = transform(viewport);
|
3771 | matrix = transform$$1 ? transform$$1.matrix : createMatrix();
|
3772 | scale = round(matrix.a, 1000);
|
3773 |
|
3774 | x = round(-matrix.e || 0, 1000);
|
3775 | y = round(-matrix.f || 0, 1000);
|
3776 |
|
3777 | box = this._cachedViewbox = {
|
3778 | x: x ? x / scale : 0,
|
3779 | y: y ? y / scale : 0,
|
3780 | width: outerBox.width / scale,
|
3781 | height: outerBox.height / scale,
|
3782 | scale: scale,
|
3783 | inner: {
|
3784 | width: innerBox.width,
|
3785 | height: innerBox.height,
|
3786 | x: innerBox.x,
|
3787 | y: innerBox.y
|
3788 | },
|
3789 | outer: outerBox
|
3790 | };
|
3791 |
|
3792 | return box;
|
3793 | } else {
|
3794 |
|
3795 | this._changeViewbox(function() {
|
3796 | scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
|
3797 |
|
3798 | var matrix = this._svg.createSVGMatrix()
|
3799 | .scale(scale)
|
3800 | .translate(-box.x, -box.y);
|
3801 |
|
3802 | transform(viewport, matrix);
|
3803 | });
|
3804 | }
|
3805 |
|
3806 | return box;
|
3807 | };
|
3808 |
|
3809 |
|
3810 | |
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 | Canvas.prototype.scroll = function(delta) {
|
3819 |
|
3820 | var node = this._viewport;
|
3821 | var matrix = node.getCTM();
|
3822 |
|
3823 | if (delta) {
|
3824 | this._changeViewbox(function() {
|
3825 | delta = assign({ dx: 0, dy: 0 }, delta || {});
|
3826 |
|
3827 | matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
|
3828 |
|
3829 | setCTM(node, matrix);
|
3830 | });
|
3831 | }
|
3832 |
|
3833 | return { x: matrix.e, y: matrix.f };
|
3834 | };
|
3835 |
|
3836 |
|
3837 | |
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 |
|
3849 |
|
3850 | Canvas.prototype.zoom = function(newScale, center) {
|
3851 |
|
3852 | if (!newScale) {
|
3853 | return this.viewbox(newScale).scale;
|
3854 | }
|
3855 |
|
3856 | if (newScale === 'fit-viewport') {
|
3857 | return this._fitViewport(center);
|
3858 | }
|
3859 |
|
3860 | var outer,
|
3861 | matrix;
|
3862 |
|
3863 | this._changeViewbox(function() {
|
3864 |
|
3865 | if (typeof center !== 'object') {
|
3866 | outer = this.viewbox().outer;
|
3867 |
|
3868 | center = {
|
3869 | x: outer.width / 2,
|
3870 | y: outer.height / 2
|
3871 | };
|
3872 | }
|
3873 |
|
3874 | matrix = this._setZoom(newScale, center);
|
3875 | });
|
3876 |
|
3877 | return round(matrix.a, 1000);
|
3878 | };
|
3879 |
|
3880 | function setCTM(node, m) {
|
3881 | var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
|
3882 | node.setAttribute('transform', mstr);
|
3883 | }
|
3884 |
|
3885 | Canvas.prototype._fitViewport = function(center) {
|
3886 |
|
3887 | var vbox = this.viewbox(),
|
3888 | outer = vbox.outer,
|
3889 | inner = vbox.inner,
|
3890 | newScale,
|
3891 | newViewbox;
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 | if (inner.x >= 0 &&
|
3901 | inner.y >= 0 &&
|
3902 | inner.x + inner.width <= outer.width &&
|
3903 | inner.y + inner.height <= outer.height &&
|
3904 | !center) {
|
3905 |
|
3906 | newViewbox = {
|
3907 | x: 0,
|
3908 | y: 0,
|
3909 | width: Math.max(inner.width + inner.x, outer.width),
|
3910 | height: Math.max(inner.height + inner.y, outer.height)
|
3911 | };
|
3912 | } else {
|
3913 |
|
3914 | newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
|
3915 | newViewbox = {
|
3916 | x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
|
3917 | y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
|
3918 | width: outer.width / newScale,
|
3919 | height: outer.height / newScale
|
3920 | };
|
3921 | }
|
3922 |
|
3923 | this.viewbox(newViewbox);
|
3924 |
|
3925 | return this.viewbox(false).scale;
|
3926 | };
|
3927 |
|
3928 |
|
3929 | Canvas.prototype._setZoom = function(scale, center) {
|
3930 |
|
3931 | var svg = this._svg,
|
3932 | viewport = this._viewport;
|
3933 |
|
3934 | var matrix = svg.createSVGMatrix();
|
3935 | var point = svg.createSVGPoint();
|
3936 |
|
3937 | var centerPoint,
|
3938 | originalPoint,
|
3939 | currentMatrix,
|
3940 | scaleMatrix,
|
3941 | newMatrix;
|
3942 |
|
3943 | currentMatrix = viewport.getCTM();
|
3944 |
|
3945 | var currentScale = currentMatrix.a;
|
3946 |
|
3947 | if (center) {
|
3948 | centerPoint = assign(point, center);
|
3949 |
|
3950 |
|
3951 | originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
|
3952 |
|
3953 |
|
3954 | scaleMatrix = matrix
|
3955 | .translate(originalPoint.x, originalPoint.y)
|
3956 | .scale(1 / currentScale * scale)
|
3957 | .translate(-originalPoint.x, -originalPoint.y);
|
3958 |
|
3959 | newMatrix = currentMatrix.multiply(scaleMatrix);
|
3960 | } else {
|
3961 | newMatrix = matrix.scale(scale);
|
3962 | }
|
3963 |
|
3964 | setCTM(this._viewport, newMatrix);
|
3965 |
|
3966 | return newMatrix;
|
3967 | };
|
3968 |
|
3969 |
|
3970 | |
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 | Canvas.prototype.getSize = function() {
|
3976 | return {
|
3977 | width: this._container.clientWidth,
|
3978 | height: this._container.clientHeight
|
3979 | };
|
3980 | };
|
3981 |
|
3982 |
|
3983 | |
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 | Canvas.prototype.getAbsoluteBBox = function(element) {
|
3994 | var vbox = this.viewbox();
|
3995 | var bbox;
|
3996 |
|
3997 |
|
3998 |
|
3999 | if (element.waypoints) {
|
4000 | var gfx = this.getGraphics(element);
|
4001 |
|
4002 | bbox = gfx.getBBox();
|
4003 | }
|
4004 |
|
4005 |
|
4006 | else {
|
4007 | bbox = element;
|
4008 | }
|
4009 |
|
4010 | var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
|
4011 | var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
|
4012 |
|
4013 | var width = bbox.width * vbox.scale;
|
4014 | var height = bbox.height * vbox.scale;
|
4015 |
|
4016 | return {
|
4017 | x: x,
|
4018 | y: y,
|
4019 | width: width,
|
4020 | height: height
|
4021 | };
|
4022 | };
|
4023 |
|
4024 | |
4025 |
|
4026 |
|
4027 |
|
4028 | Canvas.prototype.resized = function() {
|
4029 |
|
4030 |
|
4031 | delete this._cachedViewbox;
|
4032 |
|
4033 | this._eventBus.fire('canvas.resized');
|
4034 | };
|
4035 |
|
4036 | var ELEMENT_ID = 'data-element-id';
|
4037 |
|
4038 |
|
4039 | |
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 | function ElementRegistry(eventBus) {
|
4045 | this._elements = {};
|
4046 |
|
4047 | this._eventBus = eventBus;
|
4048 | }
|
4049 |
|
4050 | ElementRegistry.$inject = [ 'eventBus' ];
|
4051 |
|
4052 | |
4053 |
|
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 | ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
|
4060 |
|
4061 | var id = element.id;
|
4062 |
|
4063 | this._validateId(id);
|
4064 |
|
4065 |
|
4066 | attr$1(gfx, ELEMENT_ID, id);
|
4067 |
|
4068 | if (secondaryGfx) {
|
4069 | attr$1(secondaryGfx, ELEMENT_ID, id);
|
4070 | }
|
4071 |
|
4072 | this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
|
4073 | };
|
4074 |
|
4075 | |
4076 |
|
4077 |
|
4078 |
|
4079 |
|
4080 | ElementRegistry.prototype.remove = function(element) {
|
4081 | var elements = this._elements,
|
4082 | id = element.id || element,
|
4083 | container = id && elements[id];
|
4084 |
|
4085 | if (container) {
|
4086 |
|
4087 |
|
4088 | attr$1(container.gfx, ELEMENT_ID, '');
|
4089 |
|
4090 | if (container.secondaryGfx) {
|
4091 | attr$1(container.secondaryGfx, ELEMENT_ID, '');
|
4092 | }
|
4093 |
|
4094 | delete elements[id];
|
4095 | }
|
4096 | };
|
4097 |
|
4098 | |
4099 |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 | ElementRegistry.prototype.updateId = function(element, newId) {
|
4105 |
|
4106 | this._validateId(newId);
|
4107 |
|
4108 | if (typeof element === 'string') {
|
4109 | element = this.get(element);
|
4110 | }
|
4111 |
|
4112 | this._eventBus.fire('element.updateId', {
|
4113 | element: element,
|
4114 | newId: newId
|
4115 | });
|
4116 |
|
4117 | var gfx = this.getGraphics(element),
|
4118 | secondaryGfx = this.getGraphics(element, true);
|
4119 |
|
4120 | this.remove(element);
|
4121 |
|
4122 | element.id = newId;
|
4123 |
|
4124 | this.add(element, gfx, secondaryGfx);
|
4125 | };
|
4126 |
|
4127 | |
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 |
|
4138 |
|
4139 |
|
4140 | ElementRegistry.prototype.get = function(filter) {
|
4141 | var id;
|
4142 |
|
4143 | if (typeof filter === 'string') {
|
4144 | id = filter;
|
4145 | } else {
|
4146 | id = filter && attr$1(filter, ELEMENT_ID);
|
4147 | }
|
4148 |
|
4149 | var container = this._elements[id];
|
4150 | return container && container.element;
|
4151 | };
|
4152 |
|
4153 | |
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 |
|
4159 |
|
4160 | ElementRegistry.prototype.filter = function(fn) {
|
4161 |
|
4162 | var filtered = [];
|
4163 |
|
4164 | this.forEach(function(element, gfx) {
|
4165 | if (fn(element, gfx)) {
|
4166 | filtered.push(element);
|
4167 | }
|
4168 | });
|
4169 |
|
4170 | return filtered;
|
4171 | };
|
4172 |
|
4173 | |
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 | ElementRegistry.prototype.getAll = function() {
|
4179 | return this.filter(function(e) { return e; });
|
4180 | };
|
4181 |
|
4182 | |
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 | ElementRegistry.prototype.forEach = function(fn) {
|
4188 |
|
4189 | var map = this._elements;
|
4190 |
|
4191 | Object.keys(map).forEach(function(id) {
|
4192 | var container = map[id],
|
4193 | element = container.element,
|
4194 | gfx = container.gfx;
|
4195 |
|
4196 | return fn(element, gfx);
|
4197 | });
|
4198 | };
|
4199 |
|
4200 | |
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 |
|
4212 |
|
4213 |
|
4214 |
|
4215 | ElementRegistry.prototype.getGraphics = function(filter, secondary) {
|
4216 | var id = filter.id || filter;
|
4217 |
|
4218 | var container = this._elements[id];
|
4219 | return container && (secondary ? container.secondaryGfx : container.gfx);
|
4220 | };
|
4221 |
|
4222 | |
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 | ElementRegistry.prototype._validateId = function(id) {
|
4231 | if (!id) {
|
4232 | throw new Error('element must have an id');
|
4233 | }
|
4234 |
|
4235 | if (this._elements[id]) {
|
4236 | throw new Error('element with id ' + id + ' already added');
|
4237 | }
|
4238 | };
|
4239 |
|
4240 | |
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 | |
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 | function extend$1(collection, refs, property, target) {
|
4261 |
|
4262 | var inverseProperty = property.inverse;
|
4263 |
|
4264 | |
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 |
|
4271 | Object.defineProperty(collection, 'remove', {
|
4272 | value: function(element) {
|
4273 | var idx = this.indexOf(element);
|
4274 | if (idx !== -1) {
|
4275 | this.splice(idx, 1);
|
4276 |
|
4277 |
|
4278 | refs.unset(element, inverseProperty, target);
|
4279 | }
|
4280 |
|
4281 | return element;
|
4282 | }
|
4283 | });
|
4284 |
|
4285 | |
4286 |
|
4287 |
|
4288 |
|
4289 |
|
4290 |
|
4291 |
|
4292 | Object.defineProperty(collection, 'contains', {
|
4293 | value: function(element) {
|
4294 | return this.indexOf(element) !== -1;
|
4295 | }
|
4296 | });
|
4297 |
|
4298 | |
4299 |
|
4300 |
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 | Object.defineProperty(collection, 'add', {
|
4308 | value: function(element, idx) {
|
4309 |
|
4310 | var currentIdx = this.indexOf(element);
|
4311 |
|
4312 | if (typeof idx === 'undefined') {
|
4313 |
|
4314 | if (currentIdx !== -1) {
|
4315 |
|
4316 | return;
|
4317 | }
|
4318 |
|
4319 |
|
4320 | idx = this.length;
|
4321 | }
|
4322 |
|
4323 |
|
4324 | if (currentIdx !== -1) {
|
4325 |
|
4326 |
|
4327 | this.splice(currentIdx, 1);
|
4328 | }
|
4329 |
|
4330 |
|
4331 | this.splice(idx, 0, element);
|
4332 |
|
4333 | if (currentIdx === -1) {
|
4334 |
|
4335 |
|
4336 | refs.set(element, inverseProperty, target);
|
4337 | }
|
4338 | }
|
4339 | });
|
4340 |
|
4341 |
|
4342 |
|
4343 | Object.defineProperty(collection, '__refs_collection', {
|
4344 | value: true
|
4345 | });
|
4346 |
|
4347 | return collection;
|
4348 | }
|
4349 |
|
4350 |
|
4351 | function isExtended(collection) {
|
4352 | return collection.__refs_collection === true;
|
4353 | }
|
4354 |
|
4355 | var extend_1 = extend$1;
|
4356 |
|
4357 | var isExtended_1 = isExtended;
|
4358 |
|
4359 | var collection = {
|
4360 | extend: extend_1,
|
4361 | isExtended: isExtended_1
|
4362 | };
|
4363 |
|
4364 | function hasOwnProperty(e, property) {
|
4365 | return Object.prototype.hasOwnProperty.call(e, property.name || property);
|
4366 | }
|
4367 |
|
4368 | function defineCollectionProperty(ref, property, target) {
|
4369 |
|
4370 | var collection$$1 = collection.extend(target[property.name] || [], ref, property, target);
|
4371 |
|
4372 | Object.defineProperty(target, property.name, {
|
4373 | enumerable: property.enumerable,
|
4374 | value: collection$$1
|
4375 | });
|
4376 |
|
4377 | if (collection$$1.length) {
|
4378 |
|
4379 | collection$$1.forEach(function(o) {
|
4380 | ref.set(o, property.inverse, target);
|
4381 | });
|
4382 | }
|
4383 | }
|
4384 |
|
4385 |
|
4386 | function defineProperty(ref, property, target) {
|
4387 |
|
4388 | var inverseProperty = property.inverse;
|
4389 |
|
4390 | var _value = target[property.name];
|
4391 |
|
4392 | Object.defineProperty(target, property.name, {
|
4393 | configurable: property.configurable,
|
4394 | enumerable: property.enumerable,
|
4395 |
|
4396 | get: function() {
|
4397 | return _value;
|
4398 | },
|
4399 |
|
4400 | set: function(value) {
|
4401 |
|
4402 |
|
4403 | if (value === _value) {
|
4404 | return;
|
4405 | }
|
4406 |
|
4407 | var old = _value;
|
4408 |
|
4409 |
|
4410 | _value = null;
|
4411 |
|
4412 | if (old) {
|
4413 | ref.unset(old, inverseProperty, target);
|
4414 | }
|
4415 |
|
4416 |
|
4417 | _value = value;
|
4418 |
|
4419 |
|
4420 | ref.set(_value, inverseProperty, target);
|
4421 | }
|
4422 | });
|
4423 |
|
4424 | }
|
4425 |
|
4426 | |
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 |
|
4441 |
|
4442 |
|
4443 |
|
4444 |
|
4445 |
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 |
|
4452 |
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 | function Refs(a, b) {
|
4470 |
|
4471 | if (!(this instanceof Refs)) {
|
4472 | return new Refs(a, b);
|
4473 | }
|
4474 |
|
4475 |
|
4476 | a.inverse = b;
|
4477 | b.inverse = a;
|
4478 |
|
4479 | this.props = {};
|
4480 | this.props[a.name] = a;
|
4481 | this.props[b.name] = b;
|
4482 | }
|
4483 |
|
4484 | |
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 |
|
4490 |
|
4491 |
|
4492 |
|
4493 | Refs.prototype.bind = function(target, property) {
|
4494 | if (typeof property === 'string') {
|
4495 | if (!this.props[property]) {
|
4496 | throw new Error('no property <' + property + '> in ref');
|
4497 | }
|
4498 | property = this.props[property];
|
4499 | }
|
4500 |
|
4501 | if (property.collection) {
|
4502 | defineCollectionProperty(this, property, target);
|
4503 | } else {
|
4504 | defineProperty(this, property, target);
|
4505 | }
|
4506 | };
|
4507 |
|
4508 | Refs.prototype.ensureRefsCollection = function(target, property) {
|
4509 |
|
4510 | var collection$$1 = target[property.name];
|
4511 |
|
4512 | if (!collection.isExtended(collection$$1)) {
|
4513 | defineCollectionProperty(this, property, target);
|
4514 | }
|
4515 |
|
4516 | return collection$$1;
|
4517 | };
|
4518 |
|
4519 | Refs.prototype.ensureBound = function(target, property) {
|
4520 | if (!hasOwnProperty(target, property)) {
|
4521 | this.bind(target, property);
|
4522 | }
|
4523 | };
|
4524 |
|
4525 | Refs.prototype.unset = function(target, property, value) {
|
4526 |
|
4527 | if (target) {
|
4528 | this.ensureBound(target, property);
|
4529 |
|
4530 | if (property.collection) {
|
4531 | this.ensureRefsCollection(target, property).remove(value);
|
4532 | } else {
|
4533 | target[property.name] = undefined;
|
4534 | }
|
4535 | }
|
4536 | };
|
4537 |
|
4538 | Refs.prototype.set = function(target, property, value) {
|
4539 |
|
4540 | if (target) {
|
4541 | this.ensureBound(target, property);
|
4542 |
|
4543 | if (property.collection) {
|
4544 | this.ensureRefsCollection(target, property).add(value);
|
4545 | } else {
|
4546 | target[property.name] = value;
|
4547 | }
|
4548 | }
|
4549 | };
|
4550 |
|
4551 | var refs = Refs;
|
4552 |
|
4553 | var objectRefs = refs;
|
4554 |
|
4555 | var Collection = collection;
|
4556 | objectRefs.Collection = Collection;
|
4557 |
|
4558 | var parentRefs = new objectRefs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
|
4559 | labelRefs = new objectRefs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
|
4560 | attacherRefs = new objectRefs({ name: 'attachers', collection: true }, { name: 'host' }),
|
4561 | outgoingRefs = new objectRefs({ name: 'outgoing', collection: true }, { name: 'source' }),
|
4562 | incomingRefs = new objectRefs({ name: 'incoming', collection: true }, { name: 'target' });
|
4563 |
|
4564 | |
4565 |
|
4566 |
|
4567 |
|
4568 | |
4569 |
|
4570 |
|
4571 |
|
4572 | |
4573 |
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 | function Base() {
|
4580 |
|
4581 | |
4582 |
|
4583 |
|
4584 |
|
4585 |
|
4586 |
|
4587 | Object.defineProperty(this, 'businessObject', {
|
4588 | writable: true
|
4589 | });
|
4590 |
|
4591 |
|
4592 | |
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
|
4598 | Object.defineProperty(this, 'label', {
|
4599 | get: function() {
|
4600 | return this.labels[0];
|
4601 | },
|
4602 | set: function(newLabel) {
|
4603 |
|
4604 | var label = this.label,
|
4605 | labels = this.labels;
|
4606 |
|
4607 | if (!newLabel && label) {
|
4608 | labels.remove(label);
|
4609 | } else {
|
4610 | labels.add(newLabel, 0);
|
4611 | }
|
4612 | }
|
4613 | });
|
4614 |
|
4615 | |
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 |
|
4621 | parentRefs.bind(this, 'parent');
|
4622 |
|
4623 | |
4624 |
|
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 | labelRefs.bind(this, 'labels');
|
4630 |
|
4631 | |
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 |
|
4637 | outgoingRefs.bind(this, 'outgoing');
|
4638 |
|
4639 | |
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 | incomingRefs.bind(this, 'incoming');
|
4646 | }
|
4647 |
|
4648 |
|
4649 | |
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 | function Shape() {
|
4658 | Base.call(this);
|
4659 |
|
4660 | |
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 | parentRefs.bind(this, 'children');
|
4667 |
|
4668 | |
4669 |
|
4670 |
|
4671 |
|
4672 | attacherRefs.bind(this, 'host');
|
4673 |
|
4674 | |
4675 |
|
4676 |
|
4677 |
|
4678 | attacherRefs.bind(this, 'attachers');
|
4679 | }
|
4680 |
|
4681 | inherits_browser(Shape, Base);
|
4682 |
|
4683 |
|
4684 | |
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 | function Root() {
|
4693 | Shape.call(this);
|
4694 | }
|
4695 |
|
4696 | inherits_browser(Root, Shape);
|
4697 |
|
4698 |
|
4699 | |
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 | function Label() {
|
4708 | Shape.call(this);
|
4709 |
|
4710 | |
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 | labelRefs.bind(this, 'labelTarget');
|
4717 | }
|
4718 |
|
4719 | inherits_browser(Label, Shape);
|
4720 |
|
4721 |
|
4722 | |
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 | function Connection() {
|
4731 | Base.call(this);
|
4732 |
|
4733 | |
4734 |
|
4735 |
|
4736 |
|
4737 |
|
4738 |
|
4739 | outgoingRefs.bind(this, 'source');
|
4740 |
|
4741 | |
4742 |
|
4743 |
|
4744 |
|
4745 |
|
4746 |
|
4747 | incomingRefs.bind(this, 'target');
|
4748 | }
|
4749 |
|
4750 | inherits_browser(Connection, Base);
|
4751 |
|
4752 |
|
4753 | var types = {
|
4754 | connection: Connection,
|
4755 | shape: Shape,
|
4756 | label: Label,
|
4757 | root: Root
|
4758 | };
|
4759 |
|
4760 | |
4761 |
|
4762 |
|
4763 |
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 | function create$1(type, attrs) {
|
4778 | var Type = types[type];
|
4779 | if (!Type) {
|
4780 | throw new Error('unknown type: <' + type + '>');
|
4781 | }
|
4782 | return assign(new Type(), attrs);
|
4783 | }
|
4784 |
|
4785 | |
4786 |
|
4787 |
|
4788 | function ElementFactory() {
|
4789 | this._uid = 12;
|
4790 | }
|
4791 |
|
4792 |
|
4793 | ElementFactory.prototype.createRoot = function(attrs) {
|
4794 | return this.create('root', attrs);
|
4795 | };
|
4796 |
|
4797 | ElementFactory.prototype.createLabel = function(attrs) {
|
4798 | return this.create('label', attrs);
|
4799 | };
|
4800 |
|
4801 | ElementFactory.prototype.createShape = function(attrs) {
|
4802 | return this.create('shape', attrs);
|
4803 | };
|
4804 |
|
4805 | ElementFactory.prototype.createConnection = function(attrs) {
|
4806 | return this.create('connection', attrs);
|
4807 | };
|
4808 |
|
4809 | |
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 | ElementFactory.prototype.create = function(type, attrs) {
|
4818 |
|
4819 | attrs = assign({}, attrs || {});
|
4820 |
|
4821 | if (!attrs.id) {
|
4822 | attrs.id = type + '_' + (this._uid++);
|
4823 | }
|
4824 |
|
4825 | return create$1(type, attrs);
|
4826 | };
|
4827 |
|
4828 | var FN_REF = '__fn';
|
4829 |
|
4830 | var DEFAULT_PRIORITY = 1000;
|
4831 |
|
4832 | var slice$2 = Array.prototype.slice;
|
4833 |
|
4834 | |
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 |
|
4840 |
|
4841 |
|
4842 |
|
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 |
|
4850 |
|
4851 |
|
4852 |
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 |
|
4858 |
|
4859 |
|
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 |
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 | function EventBus() {
|
4918 | this._listeners = {};
|
4919 |
|
4920 |
|
4921 |
|
4922 | this.on('diagram.destroy', 1, this._destroy, this);
|
4923 | }
|
4924 |
|
4925 |
|
4926 | |
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 |
|
4941 |
|
4942 |
|
4943 | EventBus.prototype.on = function(events, priority, callback, that) {
|
4944 |
|
4945 | events = isArray(events) ? events : [ events ];
|
4946 |
|
4947 | if (isFunction(priority)) {
|
4948 | that = callback;
|
4949 | callback = priority;
|
4950 | priority = DEFAULT_PRIORITY;
|
4951 | }
|
4952 |
|
4953 | if (!isNumber(priority)) {
|
4954 | throw new Error('priority must be a number');
|
4955 | }
|
4956 |
|
4957 | var actualCallback = callback;
|
4958 |
|
4959 | if (that) {
|
4960 | actualCallback = bind(callback, that);
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 | actualCallback[FN_REF] = callback[FN_REF] || callback;
|
4966 | }
|
4967 |
|
4968 | var self = this,
|
4969 | listener = { priority: priority, callback: actualCallback };
|
4970 |
|
4971 | events.forEach(function(e) {
|
4972 | self._addListener(e, listener);
|
4973 | });
|
4974 | };
|
4975 |
|
4976 |
|
4977 | |
4978 |
|
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 | EventBus.prototype.once = function(event, priority, callback, that) {
|
4985 | var self = this;
|
4986 |
|
4987 | if (isFunction(priority)) {
|
4988 | that = callback;
|
4989 | callback = priority;
|
4990 | priority = DEFAULT_PRIORITY;
|
4991 | }
|
4992 |
|
4993 | if (!isNumber(priority)) {
|
4994 | throw new Error('priority must be a number');
|
4995 | }
|
4996 |
|
4997 | function wrappedCallback() {
|
4998 | self.off(event, wrappedCallback);
|
4999 | return callback.apply(that, arguments);
|
5000 | }
|
5001 |
|
5002 |
|
5003 |
|
5004 |
|
5005 | wrappedCallback[FN_REF] = callback;
|
5006 |
|
5007 | this.on(event, priority, wrappedCallback);
|
5008 | };
|
5009 |
|
5010 |
|
5011 | |
5012 |
|
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 | EventBus.prototype.off = function(events, callback) {
|
5020 |
|
5021 | events = isArray(events) ? events : [ events ];
|
5022 |
|
5023 | var self = this;
|
5024 |
|
5025 | events.forEach(function(event) {
|
5026 | self._removeListener(event, callback);
|
5027 | });
|
5028 |
|
5029 | };
|
5030 |
|
5031 |
|
5032 | |
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 | EventBus.prototype.createEvent = function(data) {
|
5040 | var event = new InternalEvent();
|
5041 |
|
5042 | event.init(data);
|
5043 |
|
5044 | return event;
|
5045 | };
|
5046 |
|
5047 |
|
5048 | |
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 |
|
5071 |
|
5072 |
|
5073 |
|
5074 |
|
5075 |
|
5076 |
|
5077 |
|
5078 | EventBus.prototype.fire = function(type, data) {
|
5079 |
|
5080 | var event,
|
5081 | listeners,
|
5082 | returnValue,
|
5083 | args;
|
5084 |
|
5085 | args = slice$2.call(arguments);
|
5086 |
|
5087 | if (typeof type === 'object') {
|
5088 | event = type;
|
5089 | type = event.type;
|
5090 | }
|
5091 |
|
5092 | if (!type) {
|
5093 | throw new Error('no event type specified');
|
5094 | }
|
5095 |
|
5096 | listeners = this._listeners[type];
|
5097 |
|
5098 | if (!listeners) {
|
5099 | return;
|
5100 | }
|
5101 |
|
5102 |
|
5103 |
|
5104 | if (data instanceof InternalEvent) {
|
5105 |
|
5106 | event = data;
|
5107 | } else {
|
5108 | event = this.createEvent(data);
|
5109 | }
|
5110 |
|
5111 |
|
5112 | args[0] = event;
|
5113 |
|
5114 |
|
5115 | var originalType = event.type;
|
5116 |
|
5117 |
|
5118 | if (type !== originalType) {
|
5119 | event.type = type;
|
5120 | }
|
5121 |
|
5122 | try {
|
5123 | returnValue = this._invokeListeners(event, args, listeners);
|
5124 | } finally {
|
5125 |
|
5126 | if (type !== originalType) {
|
5127 | event.type = originalType;
|
5128 | }
|
5129 | }
|
5130 |
|
5131 |
|
5132 |
|
5133 | if (returnValue === undefined && event.defaultPrevented) {
|
5134 | returnValue = false;
|
5135 | }
|
5136 |
|
5137 | return returnValue;
|
5138 | };
|
5139 |
|
5140 |
|
5141 | EventBus.prototype.handleError = function(error) {
|
5142 | return this.fire('error', { error: error }) === false;
|
5143 | };
|
5144 |
|
5145 |
|
5146 | EventBus.prototype._destroy = function() {
|
5147 | this._listeners = {};
|
5148 | };
|
5149 |
|
5150 | EventBus.prototype._invokeListeners = function(event, args, listeners) {
|
5151 |
|
5152 | var idx,
|
5153 | listener,
|
5154 | returnValue;
|
5155 |
|
5156 | for (idx = 0; (listener = listeners[idx]); idx++) {
|
5157 |
|
5158 |
|
5159 | if (event.cancelBubble) {
|
5160 | break;
|
5161 | }
|
5162 |
|
5163 | returnValue = this._invokeListener(event, args, listener);
|
5164 | }
|
5165 |
|
5166 | return returnValue;
|
5167 | };
|
5168 |
|
5169 | EventBus.prototype._invokeListener = function(event, args, listener) {
|
5170 |
|
5171 | var returnValue;
|
5172 |
|
5173 | try {
|
5174 |
|
5175 | returnValue = invokeFunction(listener.callback, args);
|
5176 |
|
5177 |
|
5178 | if (returnValue !== undefined) {
|
5179 | event.returnValue = returnValue;
|
5180 | event.stopPropagation();
|
5181 | }
|
5182 |
|
5183 |
|
5184 | if (returnValue === false) {
|
5185 | event.preventDefault();
|
5186 | }
|
5187 | } catch (e) {
|
5188 | if (!this.handleError(e)) {
|
5189 | console.error('unhandled error in event listener');
|
5190 | console.error(e.stack);
|
5191 |
|
5192 | throw e;
|
5193 | }
|
5194 | }
|
5195 |
|
5196 | return returnValue;
|
5197 | };
|
5198 |
|
5199 | |
5200 |
|
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 | EventBus.prototype._addListener = function(event, newListener) {
|
5216 |
|
5217 | var listeners = this._getListeners(event),
|
5218 | existingListener,
|
5219 | idx;
|
5220 |
|
5221 |
|
5222 |
|
5223 | for (idx = 0; (existingListener = listeners[idx]); idx++) {
|
5224 | if (existingListener.priority < newListener.priority) {
|
5225 |
|
5226 |
|
5227 | listeners.splice(idx, 0, newListener);
|
5228 | return;
|
5229 | }
|
5230 | }
|
5231 |
|
5232 | listeners.push(newListener);
|
5233 | };
|
5234 |
|
5235 |
|
5236 | EventBus.prototype._getListeners = function(name) {
|
5237 | var listeners = this._listeners[name];
|
5238 |
|
5239 | if (!listeners) {
|
5240 | this._listeners[name] = listeners = [];
|
5241 | }
|
5242 |
|
5243 | return listeners;
|
5244 | };
|
5245 |
|
5246 |
|
5247 | EventBus.prototype._removeListener = function(event, callback) {
|
5248 |
|
5249 | var listeners = this._getListeners(event),
|
5250 | listener,
|
5251 | listenerCallback,
|
5252 | idx;
|
5253 |
|
5254 | if (callback) {
|
5255 |
|
5256 |
|
5257 |
|
5258 | for (idx = listeners.length - 1; (listener = listeners[idx]); idx--) {
|
5259 | listenerCallback = listener.callback;
|
5260 |
|
5261 | if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
|
5262 | listeners.splice(idx, 1);
|
5263 | }
|
5264 | }
|
5265 | } else {
|
5266 |
|
5267 | listeners.length = 0;
|
5268 | }
|
5269 | };
|
5270 |
|
5271 |
|
5272 | |
5273 |
|
5274 |
|
5275 | function InternalEvent() { }
|
5276 |
|
5277 | InternalEvent.prototype.stopPropagation = function() {
|
5278 | this.cancelBubble = true;
|
5279 | };
|
5280 |
|
5281 | InternalEvent.prototype.preventDefault = function() {
|
5282 | this.defaultPrevented = true;
|
5283 | };
|
5284 |
|
5285 | InternalEvent.prototype.init = function(data) {
|
5286 | assign(this, data || {});
|
5287 | };
|
5288 |
|
5289 |
|
5290 | |
5291 |
|
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 | function invokeFunction(fn, args) {
|
5299 | return fn.apply(null, args);
|
5300 | }
|
5301 |
|
5302 | |
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 |
|
5308 |
|
5309 | |
5310 |
|
5311 |
|
5312 |
|
5313 |
|
5314 |
|
5315 |
|
5316 | function getVisual(gfx) {
|
5317 | return query('.djs-visual', gfx);
|
5318 | }
|
5319 |
|
5320 | |
5321 |
|
5322 |
|
5323 |
|
5324 |
|
5325 |
|
5326 | function getChildren(gfx) {
|
5327 | return gfx.parentNode.childNodes[1];
|
5328 | }
|
5329 |
|
5330 | |
5331 |
|
5332 |
|
5333 |
|
5334 |
|
5335 |
|
5336 |
|
5337 | function transform$1(gfx, x, y, angle, amount) {
|
5338 | var translate = createTransform();
|
5339 | translate.setTranslate(x, y);
|
5340 |
|
5341 | var rotate = createTransform();
|
5342 | rotate.setRotate(angle, 0, 0);
|
5343 |
|
5344 | var scale = createTransform();
|
5345 | scale.setScale(amount || 1, amount || 1);
|
5346 |
|
5347 | transform(gfx, [ translate, rotate, scale ]);
|
5348 | }
|
5349 |
|
5350 |
|
5351 | |
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 | function translate(gfx, x, y) {
|
5357 | var translate = createTransform();
|
5358 | translate.setTranslate(x, y);
|
5359 |
|
5360 | transform(gfx, translate);
|
5361 | }
|
5362 |
|
5363 |
|
5364 | |
5365 |
|
5366 |
|
5367 |
|
5368 | function rotate(gfx, angle) {
|
5369 | var rotate = createTransform();
|
5370 | rotate.setRotate(angle, 0, 0);
|
5371 |
|
5372 | transform(gfx, rotate);
|
5373 | }
|
5374 |
|
5375 | |
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 | function GraphicsFactory(eventBus, elementRegistry) {
|
5382 | this._eventBus = eventBus;
|
5383 | this._elementRegistry = elementRegistry;
|
5384 | }
|
5385 |
|
5386 | GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
|
5387 |
|
5388 |
|
5389 | GraphicsFactory.prototype._getChildren = function(element) {
|
5390 |
|
5391 | var gfx = this._elementRegistry.getGraphics(element);
|
5392 |
|
5393 | var childrenGfx;
|
5394 |
|
5395 |
|
5396 | if (!element.parent) {
|
5397 | childrenGfx = gfx;
|
5398 | } else {
|
5399 | childrenGfx = getChildren(gfx);
|
5400 | if (!childrenGfx) {
|
5401 | childrenGfx = create('g');
|
5402 | classes$1(childrenGfx).add('djs-children');
|
5403 |
|
5404 | append(gfx.parentNode, childrenGfx);
|
5405 | }
|
5406 | }
|
5407 |
|
5408 | return childrenGfx;
|
5409 | };
|
5410 |
|
5411 | |
5412 |
|
5413 |
|
5414 |
|
5415 | GraphicsFactory.prototype._clear = function(gfx) {
|
5416 | var visual = getVisual(gfx);
|
5417 |
|
5418 | clear(visual);
|
5419 |
|
5420 | return visual;
|
5421 | };
|
5422 |
|
5423 | |
5424 |
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 | GraphicsFactory.prototype._createContainer = function(type, childrenGfx, parentIndex) {
|
5448 | var outerGfx = create('g');
|
5449 | classes$1(outerGfx).add('djs-group');
|
5450 |
|
5451 |
|
5452 | if (typeof parentIndex !== 'undefined') {
|
5453 | prependTo$1(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
|
5454 | } else {
|
5455 | append(childrenGfx, outerGfx);
|
5456 | }
|
5457 |
|
5458 | var gfx = create('g');
|
5459 | classes$1(gfx).add('djs-element');
|
5460 | classes$1(gfx).add('djs-' + type);
|
5461 |
|
5462 | append(outerGfx, gfx);
|
5463 |
|
5464 |
|
5465 | var visual = create('g');
|
5466 | classes$1(visual).add('djs-visual');
|
5467 |
|
5468 | append(gfx, visual);
|
5469 |
|
5470 | return gfx;
|
5471 | };
|
5472 |
|
5473 | GraphicsFactory.prototype.create = function(type, element, parentIndex) {
|
5474 | var childrenGfx = this._getChildren(element.parent);
|
5475 | return this._createContainer(type, childrenGfx, parentIndex);
|
5476 | };
|
5477 |
|
5478 | GraphicsFactory.prototype.updateContainments = function(elements) {
|
5479 |
|
5480 | var self = this,
|
5481 | elementRegistry = this._elementRegistry,
|
5482 | parents;
|
5483 |
|
5484 | parents = reduce(elements, function(map$$1, e) {
|
5485 |
|
5486 | if (e.parent) {
|
5487 | map$$1[e.parent.id] = e.parent;
|
5488 | }
|
5489 |
|
5490 | return map$$1;
|
5491 | }, {});
|
5492 |
|
5493 |
|
5494 |
|
5495 | forEach(parents, function(parent) {
|
5496 |
|
5497 | var children = parent.children;
|
5498 |
|
5499 | if (!children) {
|
5500 | return;
|
5501 | }
|
5502 |
|
5503 | var childGfx = self._getChildren(parent);
|
5504 |
|
5505 | forEach(children.slice().reverse(), function(c) {
|
5506 | var gfx = elementRegistry.getGraphics(c);
|
5507 |
|
5508 | prependTo$1(gfx.parentNode, childGfx);
|
5509 | });
|
5510 | });
|
5511 | };
|
5512 |
|
5513 | GraphicsFactory.prototype.drawShape = function(visual, element) {
|
5514 | var eventBus = this._eventBus;
|
5515 |
|
5516 | return eventBus.fire('render.shape', { gfx: visual, element: element });
|
5517 | };
|
5518 |
|
5519 | GraphicsFactory.prototype.getShapePath = function(element) {
|
5520 | var eventBus = this._eventBus;
|
5521 |
|
5522 | return eventBus.fire('render.getShapePath', element);
|
5523 | };
|
5524 |
|
5525 | GraphicsFactory.prototype.drawConnection = function(visual, element) {
|
5526 | var eventBus = this._eventBus;
|
5527 |
|
5528 | return eventBus.fire('render.connection', { gfx: visual, element: element });
|
5529 | };
|
5530 |
|
5531 | GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
|
5532 | var eventBus = this._eventBus;
|
5533 |
|
5534 | return eventBus.fire('render.getConnectionPath', waypoints);
|
5535 | };
|
5536 |
|
5537 | GraphicsFactory.prototype.update = function(type, element, gfx) {
|
5538 |
|
5539 | if (!element.parent) {
|
5540 | return;
|
5541 | }
|
5542 |
|
5543 | var visual = this._clear(gfx);
|
5544 |
|
5545 |
|
5546 | if (type === 'shape') {
|
5547 | this.drawShape(visual, element);
|
5548 |
|
5549 |
|
5550 | translate(gfx, element.x, element.y);
|
5551 | } else
|
5552 | if (type === 'connection') {
|
5553 | this.drawConnection(visual, element);
|
5554 | } else {
|
5555 | throw new Error('unknown type: ' + type);
|
5556 | }
|
5557 |
|
5558 | if (element.hidden) {
|
5559 | attr$1(gfx, 'display', 'none');
|
5560 | } else {
|
5561 | attr$1(gfx, 'display', 'block');
|
5562 | }
|
5563 | };
|
5564 |
|
5565 | GraphicsFactory.prototype.remove = function(element) {
|
5566 | var gfx = this._elementRegistry.getGraphics(element);
|
5567 |
|
5568 |
|
5569 | remove$1(gfx.parentNode);
|
5570 | };
|
5571 |
|
5572 |
|
5573 |
|
5574 |
|
5575 | function prependTo$1(newNode, parentNode, siblingNode) {
|
5576 | parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild);
|
5577 | }
|
5578 |
|
5579 | var CoreModule = {
|
5580 | __depends__: [ DrawModule ],
|
5581 | __init__: [ 'canvas' ],
|
5582 | canvas: [ 'type', Canvas ],
|
5583 | elementRegistry: [ 'type', ElementRegistry ],
|
5584 | elementFactory: [ 'type', ElementFactory ],
|
5585 | eventBus: [ 'type', EventBus ],
|
5586 | graphicsFactory: [ 'type', GraphicsFactory ]
|
5587 | };
|
5588 |
|
5589 | |
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 | function bootstrap(bootstrapModules) {
|
5598 |
|
5599 | var modules = [],
|
5600 | components = [];
|
5601 |
|
5602 | function hasModule(m) {
|
5603 | return modules.indexOf(m) >= 0;
|
5604 | }
|
5605 |
|
5606 | function addModule(m) {
|
5607 | modules.push(m);
|
5608 | }
|
5609 |
|
5610 | function visit(m) {
|
5611 | if (hasModule(m)) {
|
5612 | return;
|
5613 | }
|
5614 |
|
5615 | (m.__depends__ || []).forEach(visit);
|
5616 |
|
5617 | if (hasModule(m)) {
|
5618 | return;
|
5619 | }
|
5620 |
|
5621 | addModule(m);
|
5622 |
|
5623 | (m.__init__ || []).forEach(function(c) {
|
5624 | components.push(c);
|
5625 | });
|
5626 | }
|
5627 |
|
5628 | bootstrapModules.forEach(visit);
|
5629 |
|
5630 | var injector = new Injector(modules);
|
5631 |
|
5632 | components.forEach(function(c) {
|
5633 |
|
5634 | try {
|
5635 |
|
5636 | injector[typeof c === 'string' ? 'get' : 'invoke'](c);
|
5637 | } catch (e) {
|
5638 | console.error('Failed to instantiate component');
|
5639 | console.error(e.stack);
|
5640 |
|
5641 | throw e;
|
5642 | }
|
5643 | });
|
5644 |
|
5645 | return injector;
|
5646 | }
|
5647 |
|
5648 | |
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 |
|
5654 |
|
5655 | function createInjector(options) {
|
5656 |
|
5657 | options = options || {};
|
5658 |
|
5659 | var configModule = {
|
5660 | 'config': ['value', options]
|
5661 | };
|
5662 |
|
5663 | var modules = [ configModule, CoreModule ].concat(options.modules || []);
|
5664 |
|
5665 | return bootstrap(modules);
|
5666 | }
|
5667 |
|
5668 |
|
5669 | |
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 |
|
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 | function Diagram(options, injector) {
|
5719 |
|
5720 |
|
5721 | this.injector = injector = injector || createInjector(options);
|
5722 |
|
5723 |
|
5724 |
|
5725 | |
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 | this.get = injector.get;
|
5734 |
|
5735 | |
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 | this.invoke = injector.invoke;
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 |
|
5750 | |
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 |
|
5764 |
|
5765 |
|
5766 |
|
5767 | this.get('eventBus').fire('diagram.init');
|
5768 | }
|
5769 |
|
5770 |
|
5771 | |
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 | Diagram.prototype.destroy = function() {
|
5777 | this.get('eventBus').fire('diagram.destroy');
|
5778 | };
|
5779 |
|
5780 | |
5781 |
|
5782 |
|
5783 | Diagram.prototype.clear = function() {
|
5784 | this.get('eventBus').fire('diagram.clear');
|
5785 | };
|
5786 |
|
5787 | var Diagram$1 = Object.freeze({
|
5788 | default: Diagram
|
5789 | });
|
5790 |
|
5791 | var require$$0 = getCjsExportFromNamespace(Diagram$1);
|
5792 |
|
5793 | var diagramJs = require$$0;
|
5794 |
|
5795 | |
5796 |
|
5797 |
|
5798 | function Base$1() { }
|
5799 |
|
5800 | Base$1.prototype.get = function(name) {
|
5801 | return this.$model.properties.get(this, name);
|
5802 | };
|
5803 |
|
5804 | Base$1.prototype.set = function(name, value) {
|
5805 | this.$model.properties.set(this, name, value);
|
5806 | };
|
5807 |
|
5808 | |
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 | function Factory(model, properties) {
|
5815 | this.model = model;
|
5816 | this.properties = properties;
|
5817 | }
|
5818 |
|
5819 |
|
5820 | Factory.prototype.createType = function(descriptor) {
|
5821 |
|
5822 | var model = this.model;
|
5823 |
|
5824 | var props = this.properties,
|
5825 | prototype = Object.create(Base$1.prototype);
|
5826 |
|
5827 |
|
5828 | forEach(descriptor.properties, function(p) {
|
5829 | if (!p.isMany && p.default !== undefined) {
|
5830 | prototype[p.name] = p.default;
|
5831 | }
|
5832 | });
|
5833 |
|
5834 | props.defineModel(prototype, model);
|
5835 | props.defineDescriptor(prototype, descriptor);
|
5836 |
|
5837 | var name = descriptor.ns.name;
|
5838 |
|
5839 | |
5840 |
|
5841 |
|
5842 | function ModdleElement(attrs) {
|
5843 | props.define(this, '$type', { value: name, enumerable: true });
|
5844 | props.define(this, '$attrs', { value: {} });
|
5845 | props.define(this, '$parent', { writable: true });
|
5846 |
|
5847 | forEach(attrs, bind(function(val, key) {
|
5848 | this.set(key, val);
|
5849 | }, this));
|
5850 | }
|
5851 |
|
5852 | ModdleElement.prototype = prototype;
|
5853 |
|
5854 | ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
|
5855 |
|
5856 |
|
5857 | props.defineModel(ModdleElement, model);
|
5858 | props.defineDescriptor(ModdleElement, descriptor);
|
5859 |
|
5860 | return ModdleElement;
|
5861 | };
|
5862 |
|
5863 | |
5864 |
|
5865 |
|
5866 | var BUILTINS = {
|
5867 | String: true,
|
5868 | Boolean: true,
|
5869 | Integer: true,
|
5870 | Real: true,
|
5871 | Element: true
|
5872 | };
|
5873 |
|
5874 | |
5875 |
|
5876 |
|
5877 | var TYPE_CONVERTERS = {
|
5878 | String: function(s) { return s; },
|
5879 | Boolean: function(s) { return s === 'true'; },
|
5880 | Integer: function(s) { return parseInt(s, 10); },
|
5881 | Real: function(s) { return parseFloat(s, 10); }
|
5882 | };
|
5883 |
|
5884 | |
5885 |
|
5886 |
|
5887 | function coerceType(type, value) {
|
5888 |
|
5889 | var converter = TYPE_CONVERTERS[type];
|
5890 |
|
5891 | if (converter) {
|
5892 | return converter(value);
|
5893 | } else {
|
5894 | return value;
|
5895 | }
|
5896 | }
|
5897 |
|
5898 | |
5899 |
|
5900 |
|
5901 | function isBuiltIn(type) {
|
5902 | return !!BUILTINS[type];
|
5903 | }
|
5904 |
|
5905 | |
5906 |
|
5907 |
|
5908 | function isSimple(type) {
|
5909 | return !!TYPE_CONVERTERS[type];
|
5910 | }
|
5911 |
|
5912 | |
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 |
|
5920 |
|
5921 | function parseName(name, defaultPrefix) {
|
5922 | var parts = name.split(/:/),
|
5923 | localName, prefix;
|
5924 |
|
5925 |
|
5926 | if (parts.length === 1) {
|
5927 | localName = name;
|
5928 | prefix = defaultPrefix;
|
5929 | } else
|
5930 |
|
5931 | if (parts.length === 2) {
|
5932 | localName = parts[1];
|
5933 | prefix = parts[0];
|
5934 | } else {
|
5935 | throw new Error('expected <prefix:localName> or <localName>, got ' + name);
|
5936 | }
|
5937 |
|
5938 | name = (prefix ? prefix + ':' : '') + localName;
|
5939 |
|
5940 | return {
|
5941 | name: name,
|
5942 | prefix: prefix,
|
5943 | localName: localName
|
5944 | };
|
5945 | }
|
5946 |
|
5947 | |
5948 |
|
5949 |
|
5950 | function DescriptorBuilder(nameNs) {
|
5951 | this.ns = nameNs;
|
5952 | this.name = nameNs.name;
|
5953 | this.allTypes = [];
|
5954 | this.allTypesByName = {};
|
5955 | this.properties = [];
|
5956 | this.propertiesByName = {};
|
5957 | }
|
5958 |
|
5959 |
|
5960 | DescriptorBuilder.prototype.build = function() {
|
5961 | return pick(this, [
|
5962 | 'ns',
|
5963 | 'name',
|
5964 | 'allTypes',
|
5965 | 'allTypesByName',
|
5966 | 'properties',
|
5967 | 'propertiesByName',
|
5968 | 'bodyProperty',
|
5969 | 'idProperty'
|
5970 | ]);
|
5971 | };
|
5972 |
|
5973 | |
5974 |
|
5975 |
|
5976 |
|
5977 |
|
5978 |
|
5979 |
|
5980 | DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
|
5981 |
|
5982 | if (typeof idx === 'boolean') {
|
5983 | validate = idx;
|
5984 | idx = undefined;
|
5985 | }
|
5986 |
|
5987 | this.addNamedProperty(p, validate !== false);
|
5988 |
|
5989 | var properties = this.properties;
|
5990 |
|
5991 | if (idx !== undefined) {
|
5992 | properties.splice(idx, 0, p);
|
5993 | } else {
|
5994 | properties.push(p);
|
5995 | }
|
5996 | };
|
5997 |
|
5998 |
|
5999 | DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
|
6000 | var oldNameNs = oldProperty.ns;
|
6001 |
|
6002 | var props = this.properties,
|
6003 | propertiesByName = this.propertiesByName,
|
6004 | rename = oldProperty.name !== newProperty.name;
|
6005 |
|
6006 | if (oldProperty.isId) {
|
6007 | if (!newProperty.isId) {
|
6008 | throw new Error(
|
6009 | 'property <' + newProperty.ns.name + '> must be id property ' +
|
6010 | 'to refine <' + oldProperty.ns.name + '>');
|
6011 | }
|
6012 |
|
6013 | this.setIdProperty(newProperty, false);
|
6014 | }
|
6015 |
|
6016 | if (oldProperty.isBody) {
|
6017 |
|
6018 | if (!newProperty.isBody) {
|
6019 | throw new Error(
|
6020 | 'property <' + newProperty.ns.name + '> must be body property ' +
|
6021 | 'to refine <' + oldProperty.ns.name + '>');
|
6022 | }
|
6023 |
|
6024 |
|
6025 | this.setBodyProperty(newProperty, false);
|
6026 | }
|
6027 |
|
6028 |
|
6029 | var idx = props.indexOf(oldProperty);
|
6030 | if (idx === -1) {
|
6031 | throw new Error('property <' + oldNameNs.name + '> not found in property list');
|
6032 | }
|
6033 |
|
6034 |
|
6035 | props.splice(idx, 1);
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 | this.addProperty(newProperty, replace ? undefined : idx, rename);
|
6043 |
|
6044 |
|
6045 | propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
|
6046 | };
|
6047 |
|
6048 |
|
6049 | DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
|
6050 |
|
6051 | var nsPrefix = p.ns.prefix;
|
6052 | var parts = targetPropertyName.split('#');
|
6053 |
|
6054 | var name = parseName(parts[0], nsPrefix);
|
6055 | var attrName = parseName(parts[1], name.prefix).name;
|
6056 |
|
6057 | var redefinedProperty = this.propertiesByName[attrName];
|
6058 | if (!redefinedProperty) {
|
6059 | throw new Error('refined property <' + attrName + '> not found');
|
6060 | } else {
|
6061 | this.replaceProperty(redefinedProperty, p, replace);
|
6062 | }
|
6063 |
|
6064 | delete p.redefines;
|
6065 | };
|
6066 |
|
6067 | DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
|
6068 | var ns = p.ns,
|
6069 | propsByName = this.propertiesByName;
|
6070 |
|
6071 | if (validate) {
|
6072 | this.assertNotDefined(p, ns.name);
|
6073 | this.assertNotDefined(p, ns.localName);
|
6074 | }
|
6075 |
|
6076 | propsByName[ns.name] = propsByName[ns.localName] = p;
|
6077 | };
|
6078 |
|
6079 | DescriptorBuilder.prototype.removeNamedProperty = function(p) {
|
6080 | var ns = p.ns,
|
6081 | propsByName = this.propertiesByName;
|
6082 |
|
6083 | delete propsByName[ns.name];
|
6084 | delete propsByName[ns.localName];
|
6085 | };
|
6086 |
|
6087 | DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
|
6088 |
|
6089 | if (validate && this.bodyProperty) {
|
6090 | throw new Error(
|
6091 | 'body property defined multiple times ' +
|
6092 | '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6093 | }
|
6094 |
|
6095 | this.bodyProperty = p;
|
6096 | };
|
6097 |
|
6098 | DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
|
6099 |
|
6100 | if (validate && this.idProperty) {
|
6101 | throw new Error(
|
6102 | 'id property defined multiple times ' +
|
6103 | '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
|
6104 | }
|
6105 |
|
6106 | this.idProperty = p;
|
6107 | };
|
6108 |
|
6109 | DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
|
6110 | var propertyName = p.name,
|
6111 | definedProperty = this.propertiesByName[propertyName];
|
6112 |
|
6113 | if (definedProperty) {
|
6114 | throw new Error(
|
6115 | 'property <' + propertyName + '> already defined; ' +
|
6116 | 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
|
6117 | '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
|
6118 | }
|
6119 | };
|
6120 |
|
6121 | DescriptorBuilder.prototype.hasProperty = function(name) {
|
6122 | return this.propertiesByName[name];
|
6123 | };
|
6124 |
|
6125 | DescriptorBuilder.prototype.addTrait = function(t, inherited) {
|
6126 |
|
6127 | var typesByName = this.allTypesByName,
|
6128 | types = this.allTypes;
|
6129 |
|
6130 | var typeName = t.name;
|
6131 |
|
6132 | if (typeName in typesByName) {
|
6133 | return;
|
6134 | }
|
6135 |
|
6136 | forEach(t.properties, bind(function(p) {
|
6137 |
|
6138 |
|
6139 | p = assign({}, p, {
|
6140 | name: p.ns.localName,
|
6141 | inherited: inherited
|
6142 | });
|
6143 |
|
6144 | Object.defineProperty(p, 'definedBy', {
|
6145 | value: t
|
6146 | });
|
6147 |
|
6148 | var replaces = p.replaces,
|
6149 | redefines = p.redefines;
|
6150 |
|
6151 |
|
6152 | if (replaces || redefines) {
|
6153 | this.redefineProperty(p, replaces || redefines, replaces);
|
6154 | } else {
|
6155 | if (p.isBody) {
|
6156 | this.setBodyProperty(p);
|
6157 | }
|
6158 | if (p.isId) {
|
6159 | this.setIdProperty(p);
|
6160 | }
|
6161 | this.addProperty(p);
|
6162 | }
|
6163 | }, this));
|
6164 |
|
6165 | types.push(t);
|
6166 | typesByName[typeName] = t;
|
6167 | };
|
6168 |
|
6169 | |
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 | function Registry(packages, properties) {
|
6176 | this.packageMap = {};
|
6177 | this.typeMap = {};
|
6178 |
|
6179 | this.packages = [];
|
6180 |
|
6181 | this.properties = properties;
|
6182 |
|
6183 | forEach(packages, bind(this.registerPackage, this));
|
6184 | }
|
6185 |
|
6186 |
|
6187 | Registry.prototype.getPackage = function(uriOrPrefix) {
|
6188 | return this.packageMap[uriOrPrefix];
|
6189 | };
|
6190 |
|
6191 | Registry.prototype.getPackages = function() {
|
6192 | return this.packages;
|
6193 | };
|
6194 |
|
6195 |
|
6196 | Registry.prototype.registerPackage = function(pkg) {
|
6197 |
|
6198 |
|
6199 | pkg = assign({}, pkg);
|
6200 |
|
6201 | var pkgMap = this.packageMap;
|
6202 |
|
6203 | ensureAvailable(pkgMap, pkg, 'prefix');
|
6204 | ensureAvailable(pkgMap, pkg, 'uri');
|
6205 |
|
6206 |
|
6207 | forEach(pkg.types, bind(function(descriptor) {
|
6208 | this.registerType(descriptor, pkg);
|
6209 | }, this));
|
6210 |
|
6211 | pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
|
6212 | this.packages.push(pkg);
|
6213 | };
|
6214 |
|
6215 |
|
6216 | |
6217 |
|
6218 |
|
6219 | Registry.prototype.registerType = function(type, pkg) {
|
6220 |
|
6221 | type = assign({}, type, {
|
6222 | superClass: (type.superClass || []).slice(),
|
6223 | extends: (type.extends || []).slice(),
|
6224 | properties: (type.properties || []).slice(),
|
6225 | meta: assign((type.meta || {}))
|
6226 | });
|
6227 |
|
6228 | var ns = parseName(type.name, pkg.prefix),
|
6229 | name = ns.name,
|
6230 | propertiesByName = {};
|
6231 |
|
6232 |
|
6233 | forEach(type.properties, bind(function(p) {
|
6234 |
|
6235 |
|
6236 | var propertyNs = parseName(p.name, ns.prefix),
|
6237 | propertyName = propertyNs.name;
|
6238 |
|
6239 |
|
6240 | if (!isBuiltIn(p.type)) {
|
6241 | p.type = parseName(p.type, propertyNs.prefix).name;
|
6242 | }
|
6243 |
|
6244 | assign(p, {
|
6245 | ns: propertyNs,
|
6246 | name: propertyName
|
6247 | });
|
6248 |
|
6249 | propertiesByName[propertyName] = p;
|
6250 | }, this));
|
6251 |
|
6252 |
|
6253 | assign(type, {
|
6254 | ns: ns,
|
6255 | name: name,
|
6256 | propertiesByName: propertiesByName
|
6257 | });
|
6258 |
|
6259 | forEach(type.extends, bind(function(extendsName) {
|
6260 | var extended = this.typeMap[extendsName];
|
6261 |
|
6262 | extended.traits = extended.traits || [];
|
6263 | extended.traits.push(name);
|
6264 | }, this));
|
6265 |
|
6266 |
|
6267 | this.definePackage(type, pkg);
|
6268 |
|
6269 |
|
6270 | this.typeMap[name] = type;
|
6271 | };
|
6272 |
|
6273 |
|
6274 | |
6275 |
|
6276 |
|
6277 |
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 |
|
6283 | Registry.prototype.mapTypes = function(nsName, iterator, trait) {
|
6284 |
|
6285 | var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
|
6286 |
|
6287 | var self = this;
|
6288 |
|
6289 | |
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 | function traverseTrait(cls) {
|
6295 | return traverseSuper(cls, true);
|
6296 | }
|
6297 |
|
6298 | |
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 | function traverseSuper(cls, trait) {
|
6305 | var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
|
6306 | self.mapTypes(parentNs, iterator, trait);
|
6307 | }
|
6308 |
|
6309 | if (!type) {
|
6310 | throw new Error('unknown type <' + nsName.name + '>');
|
6311 | }
|
6312 |
|
6313 | forEach(type.superClass, trait ? traverseTrait : traverseSuper);
|
6314 |
|
6315 |
|
6316 | iterator(type, !trait);
|
6317 |
|
6318 | forEach(type.traits, traverseTrait);
|
6319 | };
|
6320 |
|
6321 |
|
6322 | |
6323 |
|
6324 |
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 | Registry.prototype.getEffectiveDescriptor = function(name) {
|
6330 |
|
6331 | var nsName = parseName(name);
|
6332 |
|
6333 | var builder = new DescriptorBuilder(nsName);
|
6334 |
|
6335 | this.mapTypes(nsName, function(type, inherited) {
|
6336 | builder.addTrait(type, inherited);
|
6337 | });
|
6338 |
|
6339 | var descriptor = builder.build();
|
6340 |
|
6341 |
|
6342 | this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
|
6343 |
|
6344 | return descriptor;
|
6345 | };
|
6346 |
|
6347 |
|
6348 | Registry.prototype.definePackage = function(target, pkg) {
|
6349 | this.properties.define(target, '$pkg', { value: pkg });
|
6350 | };
|
6351 |
|
6352 |
|
6353 |
|
6354 |
|
6355 |
|
6356 | function ensureAvailable(packageMap, pkg, identifierKey) {
|
6357 |
|
6358 | var value = pkg[identifierKey];
|
6359 |
|
6360 | if (value in packageMap) {
|
6361 | throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
|
6362 | }
|
6363 | }
|
6364 |
|
6365 | |
6366 |
|
6367 |
|
6368 |
|
6369 |
|
6370 | function Properties(model) {
|
6371 | this.model = model;
|
6372 | }
|
6373 |
|
6374 |
|
6375 | |
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 |
|
6383 | Properties.prototype.set = function(target, name, value) {
|
6384 |
|
6385 | var property = this.model.getPropertyDescriptor(target, name);
|
6386 |
|
6387 | var propertyName = property && property.name;
|
6388 |
|
6389 | if (isUndefined$1(value)) {
|
6390 |
|
6391 |
|
6392 | if (property) {
|
6393 | delete target[propertyName];
|
6394 | } else {
|
6395 | delete target.$attrs[name];
|
6396 | }
|
6397 | } else {
|
6398 |
|
6399 |
|
6400 | if (property) {
|
6401 | if (propertyName in target) {
|
6402 | target[propertyName] = value;
|
6403 | } else {
|
6404 | defineProperty$1(target, property, value);
|
6405 | }
|
6406 | } else {
|
6407 | target.$attrs[name] = value;
|
6408 | }
|
6409 | }
|
6410 | };
|
6411 |
|
6412 | |
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 |
|
6420 | Properties.prototype.get = function(target, name) {
|
6421 |
|
6422 | var property = this.model.getPropertyDescriptor(target, name);
|
6423 |
|
6424 | if (!property) {
|
6425 | return target.$attrs[name];
|
6426 | }
|
6427 |
|
6428 | var propertyName = property.name;
|
6429 |
|
6430 |
|
6431 | if (!target[propertyName] && property.isMany) {
|
6432 | defineProperty$1(target, property, []);
|
6433 | }
|
6434 |
|
6435 | return target[propertyName];
|
6436 | };
|
6437 |
|
6438 |
|
6439 | |
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 | Properties.prototype.define = function(target, name, options) {
|
6447 | Object.defineProperty(target, name, options);
|
6448 | };
|
6449 |
|
6450 |
|
6451 | |
6452 |
|
6453 |
|
6454 | Properties.prototype.defineDescriptor = function(target, descriptor) {
|
6455 | this.define(target, '$descriptor', { value: descriptor });
|
6456 | };
|
6457 |
|
6458 | |
6459 |
|
6460 |
|
6461 | Properties.prototype.defineModel = function(target, model) {
|
6462 | this.define(target, '$model', { value: model });
|
6463 | };
|
6464 |
|
6465 |
|
6466 | function isUndefined$1(val) {
|
6467 | return typeof val === 'undefined';
|
6468 | }
|
6469 |
|
6470 | function defineProperty$1(target, property, value) {
|
6471 | Object.defineProperty(target, property.name, {
|
6472 | enumerable: !property.isReference,
|
6473 | writable: true,
|
6474 | value: value,
|
6475 | configurable: true
|
6476 | });
|
6477 | }
|
6478 |
|
6479 |
|
6480 |
|
6481 | |
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 |
|
6502 | function Moddle(packages) {
|
6503 |
|
6504 | this.properties = new Properties(this);
|
6505 |
|
6506 | this.factory = new Factory(this, this.properties);
|
6507 | this.registry = new Registry(packages, this.properties);
|
6508 |
|
6509 | this.typeCache = {};
|
6510 | }
|
6511 |
|
6512 |
|
6513 | |
6514 |
|
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 |
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 |
|
6527 | Moddle.prototype.create = function(descriptor, attrs) {
|
6528 | var Type = this.getType(descriptor);
|
6529 |
|
6530 | if (!Type) {
|
6531 | throw new Error('unknown type <' + descriptor + '>');
|
6532 | }
|
6533 |
|
6534 | return new Type(attrs);
|
6535 | };
|
6536 |
|
6537 |
|
6538 | |
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 |
|
6547 |
|
6548 |
|
6549 |
|
6550 |
|
6551 | Moddle.prototype.getType = function(descriptor) {
|
6552 |
|
6553 | var cache = this.typeCache;
|
6554 |
|
6555 | var name = isString(descriptor) ? descriptor : descriptor.ns.name;
|
6556 |
|
6557 | var type = cache[name];
|
6558 |
|
6559 | if (!type) {
|
6560 | descriptor = this.registry.getEffectiveDescriptor(name);
|
6561 | type = cache[name] = this.factory.createType(descriptor);
|
6562 | }
|
6563 |
|
6564 | return type;
|
6565 | };
|
6566 |
|
6567 |
|
6568 | |
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 |
|
6577 |
|
6578 |
|
6579 |
|
6580 |
|
6581 |
|
6582 |
|
6583 |
|
6584 |
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 | Moddle.prototype.createAny = function(name, nsUri, properties) {
|
6596 |
|
6597 | var nameNs = parseName(name);
|
6598 |
|
6599 | var element = {
|
6600 | $type: name,
|
6601 | $instanceOf: function(type) {
|
6602 | return type === this.$type;
|
6603 | }
|
6604 | };
|
6605 |
|
6606 | var descriptor = {
|
6607 | name: name,
|
6608 | isGeneric: true,
|
6609 | ns: {
|
6610 | prefix: nameNs.prefix,
|
6611 | localName: nameNs.localName,
|
6612 | uri: nsUri
|
6613 | }
|
6614 | };
|
6615 |
|
6616 | this.properties.defineDescriptor(element, descriptor);
|
6617 | this.properties.defineModel(element, this);
|
6618 | this.properties.define(element, '$parent', { enumerable: false, writable: true });
|
6619 |
|
6620 | forEach(properties, function(a, key) {
|
6621 | if (isObject(a) && a.value !== undefined) {
|
6622 | element[a.name] = a.value;
|
6623 | } else {
|
6624 | element[key] = a;
|
6625 | }
|
6626 | });
|
6627 |
|
6628 | return element;
|
6629 | };
|
6630 |
|
6631 | |
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 | Moddle.prototype.getPackage = function(uriOrPrefix) {
|
6637 | return this.registry.getPackage(uriOrPrefix);
|
6638 | };
|
6639 |
|
6640 | |
6641 |
|
6642 |
|
6643 |
|
6644 |
|
6645 | Moddle.prototype.getPackages = function() {
|
6646 | return this.registry.getPackages();
|
6647 | };
|
6648 |
|
6649 | |
6650 |
|
6651 |
|
6652 | Moddle.prototype.getElementDescriptor = function(element) {
|
6653 | return element.$descriptor;
|
6654 | };
|
6655 |
|
6656 | |
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 |
|
6662 | Moddle.prototype.hasType = function(element, type) {
|
6663 | if (type === undefined) {
|
6664 | type = element;
|
6665 | element = this;
|
6666 | }
|
6667 |
|
6668 | var descriptor = element.$model.getElementDescriptor(element);
|
6669 |
|
6670 | return (type in descriptor.allTypesByName);
|
6671 | };
|
6672 |
|
6673 | |
6674 |
|
6675 |
|
6676 | Moddle.prototype.getPropertyDescriptor = function(element, property) {
|
6677 | return this.getElementDescriptor(element).propertiesByName[property];
|
6678 | };
|
6679 |
|
6680 | |
6681 |
|
6682 |
|
6683 | Moddle.prototype.getTypeDescriptor = function(type) {
|
6684 | return this.registry.typeMap[type];
|
6685 | };
|
6686 |
|
6687 | var tinyStack = createCommonjsModule(function (module, exports) {
|
6688 |
|
6689 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
6690 |
|
6691 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6692 |
|
6693 | |
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 |
|
6701 |
|
6702 | (function (global) {
|
6703 |
|
6704 | var TinyStack = function () {
|
6705 | function TinyStack() {
|
6706 | _classCallCheck(this, TinyStack);
|
6707 |
|
6708 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
6709 | args[_key] = arguments[_key];
|
6710 | }
|
6711 |
|
6712 | this.data = [null].concat(args);
|
6713 | this.top = this.data.length - 1;
|
6714 | }
|
6715 |
|
6716 | _createClass(TinyStack, [{
|
6717 | key: "clear",
|
6718 | value: function clear() {
|
6719 | this.data.length = 1;
|
6720 | this.top = 0;
|
6721 |
|
6722 | return this;
|
6723 | }
|
6724 | }, {
|
6725 | key: "empty",
|
6726 | value: function empty() {
|
6727 | return this.top === 0;
|
6728 | }
|
6729 | }, {
|
6730 | key: "length",
|
6731 | value: function length() {
|
6732 | return this.top;
|
6733 | }
|
6734 | }, {
|
6735 | key: "peek",
|
6736 | value: function peek() {
|
6737 | return this.data[this.top];
|
6738 | }
|
6739 | }, {
|
6740 | key: "pop",
|
6741 | value: function pop() {
|
6742 | var result = void 0;
|
6743 |
|
6744 | if (this.top > 0) {
|
6745 | result = this.data.pop();
|
6746 | this.top--;
|
6747 | }
|
6748 |
|
6749 | return result;
|
6750 | }
|
6751 | }, {
|
6752 | key: "push",
|
6753 | value: function push(arg) {
|
6754 | this.data[++this.top] = arg;
|
6755 |
|
6756 | return this;
|
6757 | }
|
6758 | }, {
|
6759 | key: "search",
|
6760 | value: function search(arg) {
|
6761 | var index = this.data.indexOf(arg);
|
6762 |
|
6763 | return index === -1 ? -1 : this.data.length - index;
|
6764 | }
|
6765 | }]);
|
6766 |
|
6767 | return TinyStack;
|
6768 | }();
|
6769 |
|
6770 | function factory() {
|
6771 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
6772 | args[_key2] = arguments[_key2];
|
6773 | }
|
6774 |
|
6775 | return new (Function.prototype.bind.apply(TinyStack, [null].concat(args)))();
|
6776 | }
|
6777 |
|
6778 |
|
6779 | {
|
6780 | module.exports = factory;
|
6781 | }
|
6782 | })(typeof window !== "undefined" ? window : commonjsGlobal);
|
6783 | });
|
6784 |
|
6785 | var fromCharCode = String.fromCharCode;
|
6786 |
|
6787 | var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
6788 |
|
6789 | var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
|
6790 |
|
6791 | var ENTITY_MAPPING = {
|
6792 | 'amp': '&',
|
6793 | 'apos': '\'',
|
6794 | 'gt': '>',
|
6795 | 'lt': '<',
|
6796 | 'quot': '"'
|
6797 | };
|
6798 |
|
6799 |
|
6800 | Object.keys(ENTITY_MAPPING).forEach(function(k) {
|
6801 | ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
|
6802 | });
|
6803 |
|
6804 |
|
6805 | function replaceEntities(_, d, x, z) {
|
6806 |
|
6807 |
|
6808 | if (z) {
|
6809 | if (hasOwnProperty$1.call(ENTITY_MAPPING, z)) {
|
6810 | return ENTITY_MAPPING[z];
|
6811 | } else {
|
6812 |
|
6813 | return '&' + z + ';';
|
6814 | }
|
6815 | }
|
6816 |
|
6817 |
|
6818 | if (d) {
|
6819 | return fromCharCode(d);
|
6820 | }
|
6821 |
|
6822 |
|
6823 | return fromCharCode(parseInt(x, 16));
|
6824 | }
|
6825 |
|
6826 |
|
6827 | |
6828 |
|
6829 |
|
6830 |
|
6831 |
|
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 | function decodeEntities(s) {
|
6837 | if (s.length > 3 && s.indexOf('&') !== -1) {
|
6838 | return s.replace(ENTITY_PATTERN, replaceEntities);
|
6839 | }
|
6840 |
|
6841 | return s;
|
6842 | }
|
6843 |
|
6844 | var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
|
6845 | var XSI_PREFIX = 'xsi';
|
6846 | var XSI_TYPE = 'xsi:type';
|
6847 |
|
6848 | var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
|
6849 |
|
6850 | function error(msg) {
|
6851 | return new Error(msg);
|
6852 | }
|
6853 |
|
6854 | function missingNamespaceForPrefix(prefix) {
|
6855 | return 'missing namespace for prefix <' + prefix + '>';
|
6856 | }
|
6857 |
|
6858 | function getter(getFn) {
|
6859 | return {
|
6860 | 'get': getFn,
|
6861 | 'enumerable': true
|
6862 | };
|
6863 | }
|
6864 |
|
6865 | function cloneNsMatrix(nsMatrix) {
|
6866 | var clone = {}, key;
|
6867 | for (key in nsMatrix) {
|
6868 | clone[key] = nsMatrix[key];
|
6869 | }
|
6870 | return clone;
|
6871 | }
|
6872 |
|
6873 | function uriPrefix(prefix) {
|
6874 | return prefix + '$uri';
|
6875 | }
|
6876 |
|
6877 | function buildNsMatrix(nsUriToPrefix) {
|
6878 | var nsMatrix = {},
|
6879 | uri,
|
6880 | prefix;
|
6881 |
|
6882 | for (uri in nsUriToPrefix) {
|
6883 | prefix = nsUriToPrefix[uri];
|
6884 | nsMatrix[prefix] = prefix;
|
6885 | nsMatrix[uriPrefix(prefix)] = uri;
|
6886 | }
|
6887 |
|
6888 | return nsMatrix;
|
6889 | }
|
6890 |
|
6891 | function noopGetContext() {
|
6892 | return { 'line': 0, 'column': 0 };
|
6893 | }
|
6894 |
|
6895 | function throwFunc(err) {
|
6896 | throw err;
|
6897 | }
|
6898 |
|
6899 | |
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 | function Parser(options) {
|
6907 |
|
6908 | if (!this) {
|
6909 | return new Parser(options);
|
6910 | }
|
6911 |
|
6912 | var proxy = options && options['proxy'];
|
6913 |
|
6914 | var onText,
|
6915 | onOpenTag,
|
6916 | onCloseTag,
|
6917 | onCDATA,
|
6918 | onError = throwFunc,
|
6919 | onWarning,
|
6920 | onComment,
|
6921 | onQuestion,
|
6922 | onAttention;
|
6923 |
|
6924 | var getContext = noopGetContext;
|
6925 |
|
6926 | |
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 | var maybeNS = false;
|
6932 |
|
6933 | |
6934 |
|
6935 |
|
6936 |
|
6937 |
|
6938 | var isNamespace = false;
|
6939 |
|
6940 | |
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 | var returnError = null;
|
6946 |
|
6947 | |
6948 |
|
6949 |
|
6950 |
|
6951 |
|
6952 | var parseStop = false;
|
6953 |
|
6954 | |
6955 |
|
6956 |
|
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 | var nsUriToPrefix;
|
6963 |
|
6964 | |
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 | function handleError(err) {
|
6970 | if (!(err instanceof Error)) {
|
6971 | err = error(err);
|
6972 | }
|
6973 |
|
6974 | returnError = err;
|
6975 |
|
6976 | onError(err, getContext);
|
6977 | }
|
6978 |
|
6979 | |
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 | function handleWarning(err) {
|
6985 |
|
6986 | if (!onWarning) {
|
6987 | return;
|
6988 | }
|
6989 |
|
6990 | if (!(err instanceof Error)) {
|
6991 | err = error(err);
|
6992 | }
|
6993 |
|
6994 | onWarning(err, getContext);
|
6995 | }
|
6996 |
|
6997 | |
6998 |
|
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 |
|
7005 | this['on'] = function(name, cb) {
|
7006 |
|
7007 | if (typeof cb !== 'function') {
|
7008 | throw error('required args <name, cb>');
|
7009 | }
|
7010 |
|
7011 | switch (name) {
|
7012 | case 'openTag': onOpenTag = cb; break;
|
7013 | case 'text': onText = cb; break;
|
7014 | case 'closeTag': onCloseTag = cb; break;
|
7015 | case 'error': onError = cb; break;
|
7016 | case 'warn': onWarning = cb; break;
|
7017 | case 'cdata': onCDATA = cb; break;
|
7018 | case 'attention': onAttention = cb; break;
|
7019 | case 'question': onQuestion = cb; break;
|
7020 | case 'comment': onComment = cb; break;
|
7021 | default:
|
7022 | throw error('unsupported event: ' + name);
|
7023 | }
|
7024 |
|
7025 | return this;
|
7026 | };
|
7027 |
|
7028 | |
7029 |
|
7030 |
|
7031 |
|
7032 |
|
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 |
|
7040 |
|
7041 |
|
7042 | this['ns'] = function(nsMap) {
|
7043 |
|
7044 | if (typeof nsMap === 'undefined') {
|
7045 | nsMap = {};
|
7046 | }
|
7047 |
|
7048 | if (typeof nsMap !== 'object') {
|
7049 | throw error('required args <nsMap={}>');
|
7050 | }
|
7051 |
|
7052 | var _nsUriToPrefix = {}, k;
|
7053 |
|
7054 | for (k in nsMap) {
|
7055 | _nsUriToPrefix[k] = nsMap[k];
|
7056 | }
|
7057 |
|
7058 |
|
7059 | _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
|
7060 |
|
7061 | isNamespace = true;
|
7062 | nsUriToPrefix = _nsUriToPrefix;
|
7063 |
|
7064 | return this;
|
7065 | };
|
7066 |
|
7067 | |
7068 |
|
7069 |
|
7070 |
|
7071 |
|
7072 |
|
7073 |
|
7074 | this['parse'] = function(xml) {
|
7075 | if (typeof xml !== 'string') {
|
7076 | throw error('required args <xml=string>');
|
7077 | }
|
7078 |
|
7079 | returnError = null;
|
7080 |
|
7081 | parse(xml);
|
7082 |
|
7083 | getContext = noopGetContext;
|
7084 | parseStop = false;
|
7085 |
|
7086 | return returnError;
|
7087 | };
|
7088 |
|
7089 | |
7090 |
|
7091 |
|
7092 | this['stop'] = function() {
|
7093 | parseStop = true;
|
7094 | };
|
7095 |
|
7096 | |
7097 |
|
7098 |
|
7099 |
|
7100 |
|
7101 | function parse(xml) {
|
7102 | var nsMatrixStack = isNamespace ? [] : null,
|
7103 | nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
|
7104 | _nsMatrix,
|
7105 | nodeStack = [],
|
7106 | anonymousNsCount = 0,
|
7107 | tagStart = false,
|
7108 | tagEnd = false,
|
7109 | i = 0, j = 0,
|
7110 | x, y, q, w,
|
7111 | xmlns,
|
7112 | elementName,
|
7113 | _elementName,
|
7114 | elementProxy
|
7115 | ;
|
7116 |
|
7117 | var attrsString = '',
|
7118 | attrsStart = 0,
|
7119 | cachedAttrs
|
7120 | ;
|
7121 |
|
7122 | |
7123 |
|
7124 |
|
7125 |
|
7126 |
|
7127 |
|
7128 |
|
7129 |
|
7130 | function getAttrs() {
|
7131 | if (cachedAttrs !== null) {
|
7132 | return cachedAttrs;
|
7133 | }
|
7134 |
|
7135 | var nsUri,
|
7136 | nsUriPrefix,
|
7137 | nsName,
|
7138 | defaultAlias = isNamespace && nsMatrix['xmlns'],
|
7139 | attrList = isNamespace && maybeNS ? [] : null,
|
7140 | i = attrsStart,
|
7141 | s = attrsString,
|
7142 | l = s.length,
|
7143 | hasNewMatrix,
|
7144 | newalias,
|
7145 | value,
|
7146 | alias,
|
7147 | name,
|
7148 | attrs = {},
|
7149 | seenAttrs = {},
|
7150 | skipAttr,
|
7151 | w,
|
7152 | j;
|
7153 |
|
7154 | parseAttr:
|
7155 | for (; i < l; i++) {
|
7156 | skipAttr = false;
|
7157 | w = s.charCodeAt(i);
|
7158 |
|
7159 | if (w === 32 || (w < 14 && w > 8)) {
|
7160 | continue;
|
7161 | }
|
7162 |
|
7163 |
|
7164 | if (w < 65 || w > 122 || (w > 90 && w < 97)) {
|
7165 | if (w !== 95 && w !== 58) {
|
7166 | handleWarning('illegal first char attribute name');
|
7167 | skipAttr = true;
|
7168 | }
|
7169 | }
|
7170 |
|
7171 |
|
7172 | for (j = i + 1; j < l; j++) {
|
7173 | w = s.charCodeAt(j);
|
7174 |
|
7175 | if (
|
7176 | w > 96 && w < 123 ||
|
7177 | w > 64 && w < 91 ||
|
7178 | w > 47 && w < 59 ||
|
7179 | w === 46 ||
|
7180 | w === 45 ||
|
7181 | w === 95
|
7182 | ) {
|
7183 | continue;
|
7184 | }
|
7185 |
|
7186 |
|
7187 | if (w === 32 || (w < 14 && w > 8)) {
|
7188 | handleWarning('missing attribute value');
|
7189 | i = j;
|
7190 |
|
7191 | continue parseAttr;
|
7192 | }
|
7193 |
|
7194 |
|
7195 | if (w === 61) {
|
7196 | break;
|
7197 | }
|
7198 |
|
7199 | handleWarning('illegal attribute name char');
|
7200 | skipAttr = true;
|
7201 | }
|
7202 |
|
7203 | name = s.substring(i, j);
|
7204 |
|
7205 | if (name === 'xmlns:xmlns') {
|
7206 | handleWarning('illegal declaration of xmlns');
|
7207 | skipAttr = true;
|
7208 | }
|
7209 |
|
7210 | w = s.charCodeAt(j + 1);
|
7211 |
|
7212 | if (w === 34) {
|
7213 | j = s.indexOf('"', i = j + 2);
|
7214 |
|
7215 | if (j === -1) {
|
7216 | j = s.indexOf('\'', i);
|
7217 |
|
7218 | if (j !== -1) {
|
7219 | handleWarning('attribute value quote missmatch');
|
7220 | skipAttr = true;
|
7221 | }
|
7222 | }
|
7223 |
|
7224 | } else if (w === 39) {
|
7225 | j = s.indexOf('\'', i = j + 2);
|
7226 |
|
7227 | if (j === -1) {
|
7228 | j = s.indexOf('"', i);
|
7229 |
|
7230 | if (j !== -1) {
|
7231 | handleWarning('attribute value quote missmatch');
|
7232 | skipAttr = true;
|
7233 | }
|
7234 | }
|
7235 |
|
7236 | } else {
|
7237 | handleWarning('missing attribute value quotes');
|
7238 | skipAttr = true;
|
7239 |
|
7240 |
|
7241 | for (j = j + 1; j < l; j++) {
|
7242 | w = s.charCodeAt(j + 1);
|
7243 |
|
7244 | if (w === 32 || (w < 14 && w > 8)) {
|
7245 | break;
|
7246 | }
|
7247 | }
|
7248 |
|
7249 | }
|
7250 |
|
7251 | if (j === -1) {
|
7252 | handleWarning('missing closing quotes');
|
7253 |
|
7254 | j = l;
|
7255 | skipAttr = true;
|
7256 | }
|
7257 |
|
7258 | if (!skipAttr) {
|
7259 | value = s.substring(i, j);
|
7260 | }
|
7261 |
|
7262 | i = j;
|
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 | for (; j + 1 < l; j++) {
|
7268 | w = s.charCodeAt(j + 1);
|
7269 |
|
7270 | if (w === 32 || (w < 14 && w > 8)) {
|
7271 | break;
|
7272 | }
|
7273 |
|
7274 |
|
7275 | if (i === j) {
|
7276 | handleWarning('illegal character after attribute end');
|
7277 | skipAttr = true;
|
7278 | }
|
7279 | }
|
7280 |
|
7281 |
|
7282 | i = j + 1;
|
7283 |
|
7284 | if (skipAttr) {
|
7285 | continue parseAttr;
|
7286 | }
|
7287 |
|
7288 |
|
7289 | if (name in seenAttrs) {
|
7290 | handleWarning('attribute <' + name + '> already defined');
|
7291 | continue;
|
7292 | }
|
7293 |
|
7294 | seenAttrs[name] = true;
|
7295 |
|
7296 | if (!isNamespace) {
|
7297 | attrs[name] = value;
|
7298 | continue;
|
7299 | }
|
7300 |
|
7301 |
|
7302 | if (maybeNS) {
|
7303 | newalias = (
|
7304 | name === 'xmlns'
|
7305 | ? 'xmlns'
|
7306 | : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
|
7307 | ? name.substr(6)
|
7308 | : null
|
7309 | );
|
7310 |
|
7311 |
|
7312 | if (newalias !== null) {
|
7313 | nsUri = decodeEntities(value);
|
7314 | nsUriPrefix = uriPrefix(newalias);
|
7315 |
|
7316 | alias = nsUriToPrefix[nsUri];
|
7317 |
|
7318 | if (!alias) {
|
7319 |
|
7320 | if (
|
7321 | (newalias === 'xmlns') ||
|
7322 | (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
|
7323 | ) {
|
7324 |
|
7325 | do {
|
7326 | alias = 'ns' + (anonymousNsCount++);
|
7327 | } while (typeof nsMatrix[alias] !== 'undefined');
|
7328 | } else {
|
7329 | alias = newalias;
|
7330 | }
|
7331 |
|
7332 | nsUriToPrefix[nsUri] = alias;
|
7333 | }
|
7334 |
|
7335 | if (nsMatrix[newalias] !== alias) {
|
7336 | if (!hasNewMatrix) {
|
7337 | nsMatrix = cloneNsMatrix(nsMatrix);
|
7338 | hasNewMatrix = true;
|
7339 | }
|
7340 |
|
7341 | nsMatrix[newalias] = alias;
|
7342 | if (newalias === 'xmlns') {
|
7343 | nsMatrix[uriPrefix(alias)] = nsUri;
|
7344 | defaultAlias = alias;
|
7345 | }
|
7346 |
|
7347 | nsMatrix[nsUriPrefix] = nsUri;
|
7348 | }
|
7349 |
|
7350 |
|
7351 | attrs[name] = value;
|
7352 | continue;
|
7353 | }
|
7354 |
|
7355 |
|
7356 |
|
7357 | attrList.push(name, value);
|
7358 | continue;
|
7359 |
|
7360 | }
|
7361 |
|
7362 |
|
7363 |
|
7364 | w = name.indexOf(':');
|
7365 | if (w === -1) {
|
7366 | attrs[name] = value;
|
7367 | continue;
|
7368 | }
|
7369 |
|
7370 |
|
7371 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7372 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7373 | continue;
|
7374 | }
|
7375 |
|
7376 | name = defaultAlias === nsName
|
7377 | ? name.substr(w + 1)
|
7378 | : nsName + name.substr(w);
|
7379 |
|
7380 |
|
7381 |
|
7382 | if (name === XSI_TYPE) {
|
7383 | w = value.indexOf(':');
|
7384 |
|
7385 | if (w !== -1) {
|
7386 | nsName = value.substring(0, w);
|
7387 |
|
7388 | nsName = nsMatrix[nsName] || nsName;
|
7389 | value = nsName + value.substring(w);
|
7390 | } else {
|
7391 | value = defaultAlias + ':' + value;
|
7392 | }
|
7393 | }
|
7394 |
|
7395 |
|
7396 | attrs[name] = value;
|
7397 | }
|
7398 |
|
7399 |
|
7400 |
|
7401 | if (maybeNS) {
|
7402 |
|
7403 |
|
7404 | for (i = 0, l = attrList.length; i < l; i++) {
|
7405 |
|
7406 | name = attrList[i++];
|
7407 | value = attrList[i];
|
7408 |
|
7409 | w = name.indexOf(':');
|
7410 |
|
7411 | if (w !== -1) {
|
7412 |
|
7413 | if (!(nsName = nsMatrix[name.substring(0, w)])) {
|
7414 | handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
|
7415 | continue;
|
7416 | }
|
7417 |
|
7418 | name = defaultAlias === nsName
|
7419 | ? name.substr(w + 1)
|
7420 | : nsName + name.substr(w);
|
7421 |
|
7422 |
|
7423 |
|
7424 | if (name === XSI_TYPE) {
|
7425 | w = value.indexOf(':');
|
7426 |
|
7427 | if (w !== -1) {
|
7428 | nsName = value.substring(0, w);
|
7429 |
|
7430 | nsName = nsMatrix[nsName] || nsName;
|
7431 | value = nsName + value.substring(w);
|
7432 | } else {
|
7433 | value = defaultAlias + ':' + value;
|
7434 | }
|
7435 | }
|
7436 |
|
7437 | }
|
7438 |
|
7439 | attrs[name] = value;
|
7440 | }
|
7441 |
|
7442 | }
|
7443 |
|
7444 | return cachedAttrs = attrs;
|
7445 | }
|
7446 |
|
7447 | |
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 | function getParseContext() {
|
7454 | var splitsRe = /(\r\n|\r|\n)/g;
|
7455 |
|
7456 | var line = 0;
|
7457 | var column = 0;
|
7458 | var startOfLine = 0;
|
7459 | var endOfLine = j;
|
7460 | var match;
|
7461 | var data;
|
7462 |
|
7463 | while (i >= startOfLine) {
|
7464 |
|
7465 | match = splitsRe.exec(xml);
|
7466 |
|
7467 | if (!match) {
|
7468 | break;
|
7469 | }
|
7470 |
|
7471 |
|
7472 | endOfLine = match[0].length + match.index;
|
7473 |
|
7474 | if (endOfLine > i) {
|
7475 | break;
|
7476 | }
|
7477 |
|
7478 |
|
7479 | line += 1;
|
7480 |
|
7481 | startOfLine = endOfLine;
|
7482 | }
|
7483 |
|
7484 |
|
7485 | if (i == -1) {
|
7486 | column = endOfLine;
|
7487 | data = xml.substring(j);
|
7488 | } else
|
7489 |
|
7490 | if (j === 0) {
|
7491 | console.log(i - startOfLine);
|
7492 | data = xml.substring(j, i);
|
7493 | }
|
7494 |
|
7495 | else {
|
7496 | column = i - startOfLine;
|
7497 | data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
|
7498 | }
|
7499 |
|
7500 | return {
|
7501 | 'data': data,
|
7502 | 'line': line,
|
7503 | 'column': column
|
7504 | };
|
7505 | }
|
7506 |
|
7507 | getContext = getParseContext;
|
7508 |
|
7509 |
|
7510 | if (proxy) {
|
7511 | elementProxy = Object.create({}, {
|
7512 | 'name': getter(function() {
|
7513 | return elementName;
|
7514 | }),
|
7515 | 'originalName': getter(function() {
|
7516 | return _elementName;
|
7517 | }),
|
7518 | 'attrs': getter(getAttrs),
|
7519 | 'ns': getter(function() {
|
7520 | return nsMatrix;
|
7521 | })
|
7522 | });
|
7523 | }
|
7524 |
|
7525 |
|
7526 | while (j !== -1) {
|
7527 |
|
7528 | if (xml.charCodeAt(j) === 60) {
|
7529 | i = j;
|
7530 | } else {
|
7531 | i = xml.indexOf('<', j);
|
7532 | }
|
7533 |
|
7534 |
|
7535 | if (i === -1) {
|
7536 | if (nodeStack.length) {
|
7537 | return handleError('unexpected end of file');
|
7538 | }
|
7539 |
|
7540 | if (j === 0) {
|
7541 | return handleError('missing start tag');
|
7542 | }
|
7543 |
|
7544 | if (j < xml.length) {
|
7545 | if (xml.substring(j).trim()) {
|
7546 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7547 | }
|
7548 | }
|
7549 |
|
7550 | return;
|
7551 | }
|
7552 |
|
7553 |
|
7554 | if (j !== i) {
|
7555 |
|
7556 | if (nodeStack.length) {
|
7557 | if (onText) {
|
7558 | onText(xml.substring(j, i), decodeEntities, getContext);
|
7559 |
|
7560 | if (parseStop) {
|
7561 | return;
|
7562 | }
|
7563 | }
|
7564 | } else {
|
7565 | if (xml.substring(j, i).trim()) {
|
7566 | handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
|
7567 |
|
7568 | if (parseStop) {
|
7569 | return;
|
7570 | }
|
7571 | }
|
7572 | }
|
7573 | }
|
7574 |
|
7575 | w = xml.charCodeAt(i+1);
|
7576 |
|
7577 |
|
7578 | if (w === 33) {
|
7579 | w = xml.charCodeAt(i+2);
|
7580 | if (w === 91 && xml.substr(i + 3, 6) === 'CDATA[') {
|
7581 | j = xml.indexOf(']]>', i);
|
7582 | if (j === -1) {
|
7583 | return handleError('unclosed cdata');
|
7584 | }
|
7585 |
|
7586 | if (onCDATA) {
|
7587 | onCDATA(xml.substring(i + 9, j), getContext);
|
7588 | if (parseStop) {
|
7589 | return;
|
7590 | }
|
7591 | }
|
7592 |
|
7593 | j += 3;
|
7594 | continue;
|
7595 | }
|
7596 |
|
7597 |
|
7598 | if (w === 45 && xml.charCodeAt(i + 3) === 45) {
|
7599 | j = xml.indexOf('-->', i);
|
7600 | if (j === -1) {
|
7601 | return handleError('unclosed comment');
|
7602 | }
|
7603 |
|
7604 |
|
7605 | if (onComment) {
|
7606 | onComment(xml.substring(i + 4, j), decodeEntities, getContext);
|
7607 | if (parseStop) {
|
7608 | return;
|
7609 | }
|
7610 | }
|
7611 |
|
7612 | j += 3;
|
7613 | continue;
|
7614 | }
|
7615 |
|
7616 | j = xml.indexOf('>', i + 1);
|
7617 | if (j === -1) {
|
7618 | return handleError('unclosed tag');
|
7619 | }
|
7620 |
|
7621 | if (onAttention) {
|
7622 | onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
|
7623 | if (parseStop) {
|
7624 | return;
|
7625 | }
|
7626 | }
|
7627 |
|
7628 | j += 1;
|
7629 | continue;
|
7630 | }
|
7631 |
|
7632 | if (w === 63) {
|
7633 | j = xml.indexOf('?>', i);
|
7634 | if (j === -1) {
|
7635 | return handleError('unclosed question');
|
7636 | }
|
7637 |
|
7638 | if (onQuestion) {
|
7639 | onQuestion(xml.substring(i, j + 2), getContext);
|
7640 | if (parseStop) {
|
7641 | return;
|
7642 | }
|
7643 | }
|
7644 |
|
7645 | j += 2;
|
7646 | continue;
|
7647 | }
|
7648 |
|
7649 | j = xml.indexOf('>', i + 1);
|
7650 |
|
7651 | if (j == -1) {
|
7652 | return handleError('unclosed tag');
|
7653 | }
|
7654 |
|
7655 |
|
7656 |
|
7657 | cachedAttrs = {};
|
7658 |
|
7659 |
|
7660 | if (w === 47) {
|
7661 | tagStart = false;
|
7662 | tagEnd = true;
|
7663 |
|
7664 | if (!nodeStack.length) {
|
7665 | return handleError('missing open tag');
|
7666 | }
|
7667 |
|
7668 |
|
7669 | x = elementName = nodeStack.pop();
|
7670 | q = i + 2 + x.length;
|
7671 |
|
7672 | if (xml.substring(i + 2, q) !== x) {
|
7673 | return handleError('closing tag mismatch');
|
7674 | }
|
7675 |
|
7676 |
|
7677 | for (; q < j; q++) {
|
7678 | w = xml.charCodeAt(q);
|
7679 |
|
7680 | if (w === 32 || (w > 8 && w < 14)) {
|
7681 | continue;
|
7682 | }
|
7683 |
|
7684 | return handleError('close tag');
|
7685 | }
|
7686 |
|
7687 | } else {
|
7688 | if (xml.charCodeAt(j - 1) === 47) {
|
7689 | x = elementName = xml.substring(i + 1, j - 1);
|
7690 |
|
7691 | tagStart = true;
|
7692 | tagEnd = true;
|
7693 |
|
7694 | } else {
|
7695 | x = elementName = xml.substring(i + 1, j);
|
7696 |
|
7697 | tagStart = true;
|
7698 | tagEnd = false;
|
7699 | }
|
7700 |
|
7701 | if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) {
|
7702 | return handleError('illegal first char nodeName');
|
7703 | }
|
7704 |
|
7705 | for (q = 1, y = x.length; q < y; q++) {
|
7706 | w = x.charCodeAt(q);
|
7707 |
|
7708 | if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
|
7709 | continue;
|
7710 | }
|
7711 |
|
7712 | if (w === 32 || (w < 14 && w > 8)) {
|
7713 | elementName = x.substring(0, q);
|
7714 |
|
7715 | cachedAttrs = null;
|
7716 | break;
|
7717 | }
|
7718 |
|
7719 | return handleError('invalid nodeName');
|
7720 | }
|
7721 |
|
7722 | if (!tagEnd) {
|
7723 | nodeStack.push(elementName);
|
7724 | }
|
7725 | }
|
7726 |
|
7727 | if (isNamespace) {
|
7728 |
|
7729 | _nsMatrix = nsMatrix;
|
7730 |
|
7731 | if (tagStart) {
|
7732 |
|
7733 |
|
7734 | if (!tagEnd) {
|
7735 | nsMatrixStack.push(_nsMatrix);
|
7736 | }
|
7737 |
|
7738 | if (cachedAttrs === null) {
|
7739 |
|
7740 |
|
7741 |
|
7742 | if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
|
7743 | attrsStart = q;
|
7744 | attrsString = x;
|
7745 |
|
7746 | getAttrs();
|
7747 |
|
7748 | maybeNS = false;
|
7749 | }
|
7750 | }
|
7751 | }
|
7752 |
|
7753 | _elementName = elementName;
|
7754 |
|
7755 | w = elementName.indexOf(':');
|
7756 | if (w !== -1) {
|
7757 | xmlns = nsMatrix[elementName.substring(0, w)];
|
7758 |
|
7759 |
|
7760 | if (!xmlns) {
|
7761 | return handleError('missing namespace on <' + _elementName + '>');
|
7762 | }
|
7763 |
|
7764 | elementName = elementName.substr(w + 1);
|
7765 | } else {
|
7766 | xmlns = nsMatrix['xmlns'];
|
7767 |
|
7768 |
|
7769 |
|
7770 |
|
7771 |
|
7772 |
|
7773 |
|
7774 | }
|
7775 |
|
7776 |
|
7777 | if (xmlns) {
|
7778 | elementName = xmlns + ':' + elementName;
|
7779 | }
|
7780 |
|
7781 | }
|
7782 |
|
7783 | if (tagStart) {
|
7784 | attrsStart = q;
|
7785 | attrsString = x;
|
7786 |
|
7787 | if (onOpenTag) {
|
7788 | if (proxy) {
|
7789 | onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
|
7790 | } else {
|
7791 | onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
|
7792 | }
|
7793 |
|
7794 | if (parseStop) {
|
7795 | return;
|
7796 | }
|
7797 | }
|
7798 |
|
7799 | }
|
7800 |
|
7801 | if (tagEnd) {
|
7802 |
|
7803 | if (onCloseTag) {
|
7804 | onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
|
7805 |
|
7806 | if (parseStop) {
|
7807 | return;
|
7808 | }
|
7809 | }
|
7810 |
|
7811 |
|
7812 | if (isNamespace) {
|
7813 | if (!tagStart) {
|
7814 | nsMatrix = nsMatrixStack.pop();
|
7815 | } else {
|
7816 | nsMatrix = _nsMatrix;
|
7817 | }
|
7818 | }
|
7819 | }
|
7820 |
|
7821 | j += 1;
|
7822 | }
|
7823 | }
|
7824 |
|
7825 | }
|
7826 |
|
7827 | function hasLowerCaseAlias(pkg) {
|
7828 | return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
|
7829 | }
|
7830 |
|
7831 | var DEFAULT_NS_MAP = {
|
7832 | 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
|
7833 | };
|
7834 |
|
7835 | var XSI_TYPE$1 = 'xsi:type';
|
7836 |
|
7837 | function serializeFormat(element) {
|
7838 | return element.xml && element.xml.serialize;
|
7839 | }
|
7840 |
|
7841 | function serializeAsType(element) {
|
7842 | return serializeFormat(element) === XSI_TYPE$1;
|
7843 | }
|
7844 |
|
7845 | function serializeAsProperty(element) {
|
7846 | return serializeFormat(element) === 'property';
|
7847 | }
|
7848 |
|
7849 | function capitalize(str) {
|
7850 | return str.charAt(0).toUpperCase() + str.slice(1);
|
7851 | }
|
7852 |
|
7853 | function aliasToName(aliasNs, pkg) {
|
7854 |
|
7855 | if (!hasLowerCaseAlias(pkg)) {
|
7856 | return aliasNs.name;
|
7857 | }
|
7858 |
|
7859 | return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
|
7860 | }
|
7861 |
|
7862 | function prefixedToName(nameNs, pkg) {
|
7863 |
|
7864 | var name = nameNs.name,
|
7865 | localName = nameNs.localName;
|
7866 |
|
7867 | var typePrefix = pkg.xml && pkg.xml.typePrefix;
|
7868 |
|
7869 | if (typePrefix && localName.indexOf(typePrefix) === 0) {
|
7870 | return nameNs.prefix + ':' + localName.slice(typePrefix.length);
|
7871 | } else {
|
7872 | return name;
|
7873 | }
|
7874 | }
|
7875 |
|
7876 | function normalizeXsiTypeName(name, model) {
|
7877 |
|
7878 | var nameNs = parseName(name);
|
7879 | var pkg = model.getPackage(nameNs.prefix);
|
7880 |
|
7881 | return prefixedToName(nameNs, pkg);
|
7882 | }
|
7883 |
|
7884 | function error$1(message) {
|
7885 | return new Error(message);
|
7886 | }
|
7887 |
|
7888 | |
7889 |
|
7890 |
|
7891 |
|
7892 |
|
7893 |
|
7894 |
|
7895 | function getModdleDescriptor(element) {
|
7896 | return element.$descriptor;
|
7897 | }
|
7898 |
|
7899 | function defer(fn) {
|
7900 | setTimeout(fn, 0);
|
7901 | }
|
7902 |
|
7903 | |
7904 |
|
7905 |
|
7906 |
|
7907 |
|
7908 |
|
7909 |
|
7910 |
|
7911 |
|
7912 | function Context(options) {
|
7913 |
|
7914 | |
7915 |
|
7916 |
|
7917 |
|
7918 | |
7919 |
|
7920 |
|
7921 |
|
7922 | assign(this, options);
|
7923 |
|
7924 | this.elementsById = {};
|
7925 | this.references = [];
|
7926 | this.warnings = [];
|
7927 |
|
7928 | |
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 | this.addReference = function(reference) {
|
7934 | this.references.push(reference);
|
7935 | };
|
7936 |
|
7937 | |
7938 |
|
7939 |
|
7940 |
|
7941 |
|
7942 | this.addElement = function(element) {
|
7943 |
|
7944 | if (!element) {
|
7945 | throw error$1('expected element');
|
7946 | }
|
7947 |
|
7948 | var elementsById = this.elementsById;
|
7949 |
|
7950 | var descriptor = getModdleDescriptor(element);
|
7951 |
|
7952 | var idProperty = descriptor.idProperty,
|
7953 | id;
|
7954 |
|
7955 | if (idProperty) {
|
7956 | id = element.get(idProperty.name);
|
7957 |
|
7958 | if (id) {
|
7959 |
|
7960 | if (elementsById[id]) {
|
7961 | throw error$1('duplicate ID <' + id + '>');
|
7962 | }
|
7963 |
|
7964 | elementsById[id] = element;
|
7965 | }
|
7966 | }
|
7967 | };
|
7968 |
|
7969 | |
7970 |
|
7971 |
|
7972 |
|
7973 |
|
7974 |
|
7975 |
|
7976 | this.addWarning = function(warning) {
|
7977 | this.warnings.push(warning);
|
7978 | };
|
7979 | }
|
7980 |
|
7981 | function BaseHandler() {}
|
7982 |
|
7983 | BaseHandler.prototype.handleEnd = function() {};
|
7984 | BaseHandler.prototype.handleText = function() {};
|
7985 | BaseHandler.prototype.handleNode = function() {};
|
7986 |
|
7987 |
|
7988 | |
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 |
|
7995 | function NoopHandler() { }
|
7996 |
|
7997 | NoopHandler.prototype = Object.create(BaseHandler.prototype);
|
7998 |
|
7999 | NoopHandler.prototype.handleNode = function() {
|
8000 | return this;
|
8001 | };
|
8002 |
|
8003 | function BodyHandler() {}
|
8004 |
|
8005 | BodyHandler.prototype = Object.create(BaseHandler.prototype);
|
8006 |
|
8007 | BodyHandler.prototype.handleText = function(text) {
|
8008 | this.body = (this.body || '') + text;
|
8009 | };
|
8010 |
|
8011 | function ReferenceHandler(property, context) {
|
8012 | this.property = property;
|
8013 | this.context = context;
|
8014 | }
|
8015 |
|
8016 | ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
|
8017 |
|
8018 | ReferenceHandler.prototype.handleNode = function(node) {
|
8019 |
|
8020 | if (this.element) {
|
8021 | throw error$1('expected no sub nodes');
|
8022 | } else {
|
8023 | this.element = this.createReference(node);
|
8024 | }
|
8025 |
|
8026 | return this;
|
8027 | };
|
8028 |
|
8029 | ReferenceHandler.prototype.handleEnd = function() {
|
8030 | this.element.id = this.body;
|
8031 | };
|
8032 |
|
8033 | ReferenceHandler.prototype.createReference = function(node) {
|
8034 | return {
|
8035 | property: this.property.ns.name,
|
8036 | id: ''
|
8037 | };
|
8038 | };
|
8039 |
|
8040 | function ValueHandler(propertyDesc, element) {
|
8041 | this.element = element;
|
8042 | this.propertyDesc = propertyDesc;
|
8043 | }
|
8044 |
|
8045 | ValueHandler.prototype = Object.create(BodyHandler.prototype);
|
8046 |
|
8047 | ValueHandler.prototype.handleEnd = function() {
|
8048 |
|
8049 | var value = this.body || '',
|
8050 | element = this.element,
|
8051 | propertyDesc = this.propertyDesc;
|
8052 |
|
8053 | value = coerceType(propertyDesc.type, value);
|
8054 |
|
8055 | if (propertyDesc.isMany) {
|
8056 | element.get(propertyDesc.name).push(value);
|
8057 | } else {
|
8058 | element.set(propertyDesc.name, value);
|
8059 | }
|
8060 | };
|
8061 |
|
8062 |
|
8063 | function BaseElementHandler() {}
|
8064 |
|
8065 | BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
|
8066 |
|
8067 | BaseElementHandler.prototype.handleNode = function(node) {
|
8068 | var parser = this,
|
8069 | element = this.element;
|
8070 |
|
8071 | if (!element) {
|
8072 | element = this.element = this.createElement(node);
|
8073 |
|
8074 | this.context.addElement(element);
|
8075 | } else {
|
8076 | parser = this.handleChild(node);
|
8077 | }
|
8078 |
|
8079 | return parser;
|
8080 | };
|
8081 |
|
8082 | |
8083 |
|
8084 |
|
8085 |
|
8086 | function ElementHandler(model, typeName, context) {
|
8087 | this.model = model;
|
8088 | this.type = model.getType(typeName);
|
8089 | this.context = context;
|
8090 | }
|
8091 |
|
8092 | ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8093 |
|
8094 | ElementHandler.prototype.addReference = function(reference) {
|
8095 | this.context.addReference(reference);
|
8096 | };
|
8097 |
|
8098 | ElementHandler.prototype.handleEnd = function() {
|
8099 |
|
8100 | var value = this.body,
|
8101 | element = this.element,
|
8102 | descriptor = getModdleDescriptor(element),
|
8103 | bodyProperty = descriptor.bodyProperty;
|
8104 |
|
8105 | if (bodyProperty && value !== undefined) {
|
8106 | value = coerceType(bodyProperty.type, value);
|
8107 | element.set(bodyProperty.name, value);
|
8108 | }
|
8109 | };
|
8110 |
|
8111 | |
8112 |
|
8113 |
|
8114 |
|
8115 |
|
8116 | ElementHandler.prototype.createElement = function(node) {
|
8117 | var attributes = node.attributes,
|
8118 | Type = this.type,
|
8119 | descriptor = getModdleDescriptor(Type),
|
8120 | context = this.context,
|
8121 | instance = new Type({}),
|
8122 | model = this.model,
|
8123 | propNameNs;
|
8124 |
|
8125 | forEach(attributes, function(value, name) {
|
8126 |
|
8127 | var prop = descriptor.propertiesByName[name],
|
8128 | values$$1;
|
8129 |
|
8130 | if (prop && prop.isReference) {
|
8131 |
|
8132 | if (!prop.isMany) {
|
8133 | context.addReference({
|
8134 | element: instance,
|
8135 | property: prop.ns.name,
|
8136 | id: value
|
8137 | });
|
8138 | } else {
|
8139 |
|
8140 | values$$1 = value.split(' ');
|
8141 |
|
8142 | forEach(values$$1, function(v) {
|
8143 | context.addReference({
|
8144 | element: instance,
|
8145 | property: prop.ns.name,
|
8146 | id: v
|
8147 | });
|
8148 | });
|
8149 | }
|
8150 |
|
8151 | } else {
|
8152 | if (prop) {
|
8153 | value = coerceType(prop.type, value);
|
8154 | } else
|
8155 | if (name !== 'xmlns') {
|
8156 | propNameNs = parseName(name, descriptor.ns.prefix);
|
8157 |
|
8158 |
|
8159 |
|
8160 | if (model.getPackage(propNameNs.prefix)) {
|
8161 |
|
8162 | context.addWarning({
|
8163 | message: 'unknown attribute <' + name + '>',
|
8164 | element: instance,
|
8165 | property: name,
|
8166 | value: value
|
8167 | });
|
8168 | }
|
8169 | }
|
8170 |
|
8171 | instance.set(name, value);
|
8172 | }
|
8173 | });
|
8174 |
|
8175 | return instance;
|
8176 | };
|
8177 |
|
8178 | ElementHandler.prototype.getPropertyForNode = function(node) {
|
8179 |
|
8180 | var name = node.name;
|
8181 | var nameNs = parseName(name);
|
8182 |
|
8183 | var type = this.type,
|
8184 | model = this.model,
|
8185 | descriptor = getModdleDescriptor(type);
|
8186 |
|
8187 | var propertyName = nameNs.name,
|
8188 | property = descriptor.propertiesByName[propertyName],
|
8189 | elementTypeName,
|
8190 | elementType;
|
8191 |
|
8192 |
|
8193 |
|
8194 | if (property) {
|
8195 |
|
8196 | if (serializeAsType(property)) {
|
8197 | elementTypeName = node.attributes[XSI_TYPE$1];
|
8198 |
|
8199 |
|
8200 |
|
8201 | if (elementTypeName) {
|
8202 |
|
8203 |
|
8204 |
|
8205 | elementTypeName = normalizeXsiTypeName(elementTypeName, model);
|
8206 |
|
8207 | elementType = model.getType(elementTypeName);
|
8208 |
|
8209 | return assign({}, property, {
|
8210 | effectiveType: getModdleDescriptor(elementType).name
|
8211 | });
|
8212 | }
|
8213 | }
|
8214 |
|
8215 |
|
8216 | return property;
|
8217 | }
|
8218 |
|
8219 | var pkg = model.getPackage(nameNs.prefix);
|
8220 |
|
8221 | if (pkg) {
|
8222 | elementTypeName = aliasToName(nameNs, pkg);
|
8223 | elementType = model.getType(elementTypeName);
|
8224 |
|
8225 |
|
8226 | property = find(descriptor.properties, function(p) {
|
8227 | return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
|
8228 | });
|
8229 |
|
8230 | if (property) {
|
8231 | return assign({}, property, {
|
8232 | effectiveType: getModdleDescriptor(elementType).name
|
8233 | });
|
8234 | }
|
8235 | } else {
|
8236 |
|
8237 | property = find(descriptor.properties, function(p) {
|
8238 | return !p.isReference && !p.isAttribute && p.type === 'Element';
|
8239 | });
|
8240 |
|
8241 | if (property) {
|
8242 | return property;
|
8243 | }
|
8244 | }
|
8245 |
|
8246 | throw error$1('unrecognized element <' + nameNs.name + '>');
|
8247 | };
|
8248 |
|
8249 | ElementHandler.prototype.toString = function() {
|
8250 | return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
|
8251 | };
|
8252 |
|
8253 | ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
|
8254 | return new ValueHandler(propertyDesc, element);
|
8255 | };
|
8256 |
|
8257 | ElementHandler.prototype.referenceHandler = function(propertyDesc) {
|
8258 | return new ReferenceHandler(propertyDesc, this.context);
|
8259 | };
|
8260 |
|
8261 | ElementHandler.prototype.handler = function(type) {
|
8262 | if (type === 'Element') {
|
8263 | return new GenericElementHandler(this.model, type, this.context);
|
8264 | } else {
|
8265 | return new ElementHandler(this.model, type, this.context);
|
8266 | }
|
8267 | };
|
8268 |
|
8269 | |
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 | ElementHandler.prototype.handleChild = function(node) {
|
8275 | var propertyDesc, type, element, childHandler;
|
8276 |
|
8277 | propertyDesc = this.getPropertyForNode(node);
|
8278 | element = this.element;
|
8279 |
|
8280 | type = propertyDesc.effectiveType || propertyDesc.type;
|
8281 |
|
8282 | if (isSimple(type)) {
|
8283 | return this.valueHandler(propertyDesc, element);
|
8284 | }
|
8285 |
|
8286 | if (propertyDesc.isReference) {
|
8287 | childHandler = this.referenceHandler(propertyDesc).handleNode(node);
|
8288 | } else {
|
8289 | childHandler = this.handler(type).handleNode(node);
|
8290 | }
|
8291 |
|
8292 | var newElement = childHandler.element;
|
8293 |
|
8294 |
|
8295 |
|
8296 | if (newElement !== undefined) {
|
8297 |
|
8298 | if (propertyDesc.isMany) {
|
8299 | element.get(propertyDesc.name).push(newElement);
|
8300 | } else {
|
8301 | element.set(propertyDesc.name, newElement);
|
8302 | }
|
8303 |
|
8304 | if (propertyDesc.isReference) {
|
8305 | assign(newElement, {
|
8306 | element: element
|
8307 | });
|
8308 |
|
8309 | this.context.addReference(newElement);
|
8310 | } else {
|
8311 |
|
8312 | newElement.$parent = element;
|
8313 | }
|
8314 | }
|
8315 |
|
8316 | return childHandler;
|
8317 | };
|
8318 |
|
8319 | |
8320 |
|
8321 |
|
8322 |
|
8323 |
|
8324 |
|
8325 |
|
8326 |
|
8327 |
|
8328 | function RootElementHandler(model, typeName, context) {
|
8329 | ElementHandler.call(this, model, typeName, context);
|
8330 | }
|
8331 |
|
8332 | RootElementHandler.prototype = Object.create(ElementHandler.prototype);
|
8333 |
|
8334 | RootElementHandler.prototype.createElement = function(node) {
|
8335 |
|
8336 | var name = node.name,
|
8337 | nameNs = parseName(name),
|
8338 | model = this.model,
|
8339 | type = this.type,
|
8340 | pkg = model.getPackage(nameNs.prefix),
|
8341 | typeName = pkg && aliasToName(nameNs, pkg) || name;
|
8342 |
|
8343 |
|
8344 |
|
8345 |
|
8346 |
|
8347 | if (!type.hasType(typeName)) {
|
8348 | throw error$1('unexpected element <' + node.originalName + '>');
|
8349 | }
|
8350 |
|
8351 | return ElementHandler.prototype.createElement.call(this, node);
|
8352 | };
|
8353 |
|
8354 |
|
8355 | function GenericElementHandler(model, typeName, context) {
|
8356 | this.model = model;
|
8357 | this.context = context;
|
8358 | }
|
8359 |
|
8360 | GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
|
8361 |
|
8362 | GenericElementHandler.prototype.createElement = function(node) {
|
8363 |
|
8364 | var name = node.name,
|
8365 | ns = parseName(name),
|
8366 | prefix = ns.prefix,
|
8367 | uri = node.ns[prefix + '$uri'],
|
8368 | attributes = node.attributes;
|
8369 |
|
8370 | return this.model.createAny(name, uri, attributes);
|
8371 | };
|
8372 |
|
8373 | GenericElementHandler.prototype.handleChild = function(node) {
|
8374 |
|
8375 | var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
|
8376 | element = this.element;
|
8377 |
|
8378 | var newElement = handler.element,
|
8379 | children;
|
8380 |
|
8381 | if (newElement !== undefined) {
|
8382 | children = element.$children = element.$children || [];
|
8383 | children.push(newElement);
|
8384 |
|
8385 |
|
8386 | newElement.$parent = element;
|
8387 | }
|
8388 |
|
8389 | return handler;
|
8390 | };
|
8391 |
|
8392 | GenericElementHandler.prototype.handleText = function(text) {
|
8393 | this.body = this.body || '' + text;
|
8394 | };
|
8395 |
|
8396 | GenericElementHandler.prototype.handleEnd = function() {
|
8397 | if (this.body) {
|
8398 | this.element.$body = this.body;
|
8399 | }
|
8400 | };
|
8401 |
|
8402 | |
8403 |
|
8404 |
|
8405 |
|
8406 |
|
8407 |
|
8408 |
|
8409 | function Reader(options) {
|
8410 |
|
8411 | if (options instanceof Moddle) {
|
8412 | options = {
|
8413 | model: options
|
8414 | };
|
8415 | }
|
8416 |
|
8417 | assign(this, { lax: false }, options);
|
8418 | }
|
8419 |
|
8420 |
|
8421 | |
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 | Reader.prototype.fromXML = function(xml, options, done) {
|
8429 |
|
8430 | var rootHandler = options.rootHandler;
|
8431 |
|
8432 | if (options instanceof ElementHandler) {
|
8433 |
|
8434 | rootHandler = options;
|
8435 | options = {};
|
8436 | } else {
|
8437 | if (typeof options === 'string') {
|
8438 |
|
8439 | rootHandler = this.handler(options);
|
8440 | options = {};
|
8441 | } else if (typeof rootHandler === 'string') {
|
8442 |
|
8443 | rootHandler = this.handler(rootHandler);
|
8444 | }
|
8445 | }
|
8446 |
|
8447 | var model = this.model,
|
8448 | lax = this.lax;
|
8449 |
|
8450 | var context = new Context(assign({}, options, { rootHandler: rootHandler })),
|
8451 | parser = new Parser({ proxy: true }),
|
8452 | stack = new tinyStack();
|
8453 |
|
8454 | rootHandler.context = context;
|
8455 |
|
8456 |
|
8457 | stack.push(rootHandler);
|
8458 |
|
8459 |
|
8460 | |
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 |
|
8469 | function handleError(err, getContext, lax) {
|
8470 |
|
8471 | var ctx = getContext();
|
8472 |
|
8473 | var line = ctx.line,
|
8474 | column = ctx.column,
|
8475 | data = ctx.data;
|
8476 |
|
8477 |
|
8478 |
|
8479 |
|
8480 | if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
|
8481 | data = data.slice(0, data.indexOf(' ')) + '>';
|
8482 | }
|
8483 |
|
8484 | var message =
|
8485 | 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
|
8486 | 'line: ' + line + '\n\t' +
|
8487 | 'column: ' + column + '\n\t' +
|
8488 | 'nested error: ' + err.message;
|
8489 |
|
8490 | if (lax) {
|
8491 | context.addWarning({
|
8492 | message: message,
|
8493 | error: err
|
8494 | });
|
8495 |
|
8496 | console.warn('could not parse node');
|
8497 | console.warn(err);
|
8498 |
|
8499 | return true;
|
8500 | } else {
|
8501 | console.error('could not parse document');
|
8502 | console.error(err);
|
8503 |
|
8504 | throw error$1(message);
|
8505 | }
|
8506 | }
|
8507 |
|
8508 | function handleWarning(err, getContext) {
|
8509 |
|
8510 | return handleError(err, getContext, true);
|
8511 | }
|
8512 |
|
8513 | |
8514 |
|
8515 |
|
8516 | function resolveReferences() {
|
8517 |
|
8518 | var elementsById = context.elementsById;
|
8519 | var references = context.references;
|
8520 |
|
8521 | var i, r;
|
8522 |
|
8523 | for (i = 0; (r = references[i]); i++) {
|
8524 | var element = r.element;
|
8525 | var reference = elementsById[r.id];
|
8526 | var property = getModdleDescriptor(element).propertiesByName[r.property];
|
8527 |
|
8528 | if (!reference) {
|
8529 | context.addWarning({
|
8530 | message: 'unresolved reference <' + r.id + '>',
|
8531 | element: r.element,
|
8532 | property: r.property,
|
8533 | value: r.id
|
8534 | });
|
8535 | }
|
8536 |
|
8537 | if (property.isMany) {
|
8538 | var collection = element.get(property.name),
|
8539 | idx = collection.indexOf(r);
|
8540 |
|
8541 |
|
8542 |
|
8543 | if (idx === -1) {
|
8544 | idx = collection.length;
|
8545 | }
|
8546 |
|
8547 | if (!reference) {
|
8548 |
|
8549 | collection.splice(idx, 1);
|
8550 | } else {
|
8551 |
|
8552 | collection[idx] = reference;
|
8553 | }
|
8554 | } else {
|
8555 | element.set(property.name, reference);
|
8556 | }
|
8557 | }
|
8558 | }
|
8559 |
|
8560 | function handleClose() {
|
8561 | stack.pop().handleEnd();
|
8562 | }
|
8563 |
|
8564 | var PREAMBLE_START_PATTERN = /^<\?xml /i;
|
8565 |
|
8566 | var ENCODING_PATTERN = / encoding="([^"]+)"/i;
|
8567 |
|
8568 | var UTF_8_PATTERN = /^utf-8$/i;
|
8569 |
|
8570 | function handleQuestion(question) {
|
8571 |
|
8572 | if (!PREAMBLE_START_PATTERN.test(question)) {
|
8573 | return;
|
8574 | }
|
8575 |
|
8576 | var match = ENCODING_PATTERN.exec(question);
|
8577 | var encoding = match && match[1];
|
8578 |
|
8579 | if (!encoding || UTF_8_PATTERN.test(encoding)) {
|
8580 | return;
|
8581 | }
|
8582 |
|
8583 | context.addWarning({
|
8584 | message:
|
8585 | 'unsupported document encoding <' + encoding + '>, ' +
|
8586 | 'falling back to UTF-8'
|
8587 | });
|
8588 | }
|
8589 |
|
8590 | function handleOpen(node, getContext) {
|
8591 | var handler = stack.peek();
|
8592 |
|
8593 | try {
|
8594 | stack.push(handler.handleNode(node));
|
8595 | } catch (err) {
|
8596 |
|
8597 | if (handleError(err, getContext, lax)) {
|
8598 | stack.push(new NoopHandler());
|
8599 | }
|
8600 | }
|
8601 | }
|
8602 |
|
8603 | function handleCData(text) {
|
8604 | stack.peek().handleText(text);
|
8605 | }
|
8606 |
|
8607 | function handleText(text) {
|
8608 |
|
8609 |
|
8610 | text = text.trim();
|
8611 |
|
8612 | if (!text) {
|
8613 | return;
|
8614 | }
|
8615 |
|
8616 | stack.peek().handleText(text);
|
8617 | }
|
8618 |
|
8619 | var uriMap = model.getPackages().reduce(function(uriMap, p) {
|
8620 | uriMap[p.uri] = p.prefix;
|
8621 |
|
8622 | return uriMap;
|
8623 | }, {});
|
8624 |
|
8625 | parser
|
8626 | .ns(uriMap)
|
8627 | .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
|
8628 |
|
8629 |
|
8630 | var attrs = obj.attrs || {};
|
8631 |
|
8632 | var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
|
8633 | var value = decodeStr(attrs[key]);
|
8634 |
|
8635 | d[key] = value;
|
8636 |
|
8637 | return d;
|
8638 | }, {});
|
8639 |
|
8640 | var node = {
|
8641 | name: obj.name,
|
8642 | originalName: obj.originalName,
|
8643 | attributes: decodedAttrs,
|
8644 | ns: obj.ns
|
8645 | };
|
8646 |
|
8647 | handleOpen(node, getContext);
|
8648 | })
|
8649 | .on('question', handleQuestion)
|
8650 | .on('closeTag', handleClose)
|
8651 | .on('cdata', handleCData)
|
8652 | .on('text', function(text, decodeEntities$$1) {
|
8653 | handleText(decodeEntities$$1(text));
|
8654 | })
|
8655 | .on('error', handleError)
|
8656 | .on('warn', handleWarning);
|
8657 |
|
8658 |
|
8659 |
|
8660 |
|
8661 |
|
8662 | defer(function() {
|
8663 | var err;
|
8664 |
|
8665 | try {
|
8666 | parser.parse(xml);
|
8667 |
|
8668 | resolveReferences();
|
8669 | } catch (e) {
|
8670 | err = e;
|
8671 | }
|
8672 |
|
8673 | var element = rootHandler.element;
|
8674 |
|
8675 |
|
8676 |
|
8677 | if (!err && !element) {
|
8678 | err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
|
8679 | }
|
8680 |
|
8681 | done(err, err ? undefined : element, context);
|
8682 | });
|
8683 | };
|
8684 |
|
8685 | Reader.prototype.handler = function(name) {
|
8686 | return new RootElementHandler(this.model, name);
|
8687 | };
|
8688 |
|
8689 | var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
8690 |
|
8691 | var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
|
8692 | var ESCAPE_CHARS = /<|>|&/g;
|
8693 |
|
8694 |
|
8695 | function Namespaces(parent) {
|
8696 |
|
8697 | var prefixMap = {};
|
8698 | var uriMap = {};
|
8699 | var used = {};
|
8700 |
|
8701 | var wellknown = [];
|
8702 | var custom = [];
|
8703 |
|
8704 |
|
8705 |
|
8706 | this.byUri = function(uri) {
|
8707 | return uriMap[uri] || (
|
8708 | parent && parent.byUri(uri)
|
8709 | );
|
8710 | };
|
8711 |
|
8712 | this.add = function(ns, isWellknown) {
|
8713 |
|
8714 | uriMap[ns.uri] = ns;
|
8715 |
|
8716 | if (isWellknown) {
|
8717 | wellknown.push(ns);
|
8718 | } else {
|
8719 | custom.push(ns);
|
8720 | }
|
8721 |
|
8722 | this.mapPrefix(ns.prefix, ns.uri);
|
8723 | };
|
8724 |
|
8725 | this.uriByPrefix = function(prefix) {
|
8726 | return prefixMap[prefix || 'xmlns'];
|
8727 | };
|
8728 |
|
8729 | this.mapPrefix = function(prefix, uri) {
|
8730 | prefixMap[prefix || 'xmlns'] = uri;
|
8731 | };
|
8732 |
|
8733 | this.logUsed = function(ns) {
|
8734 | var uri = ns.uri;
|
8735 |
|
8736 | used[uri] = this.byUri(uri);
|
8737 | };
|
8738 |
|
8739 | this.getUsed = function(ns) {
|
8740 |
|
8741 | function isUsed(ns) {
|
8742 | return used[ns.uri];
|
8743 | }
|
8744 |
|
8745 | var allNs = [].concat(wellknown, custom);
|
8746 |
|
8747 | return allNs.filter(isUsed);
|
8748 | };
|
8749 |
|
8750 | }
|
8751 |
|
8752 | function lower(string) {
|
8753 | return string.charAt(0).toLowerCase() + string.slice(1);
|
8754 | }
|
8755 |
|
8756 | function nameToAlias(name, pkg) {
|
8757 | if (hasLowerCaseAlias(pkg)) {
|
8758 | return lower(name);
|
8759 | } else {
|
8760 | return name;
|
8761 | }
|
8762 | }
|
8763 |
|
8764 | function inherits(ctor, superCtor) {
|
8765 | ctor.super_ = superCtor;
|
8766 | ctor.prototype = Object.create(superCtor.prototype, {
|
8767 | constructor: {
|
8768 | value: ctor,
|
8769 | enumerable: false,
|
8770 | writable: true,
|
8771 | configurable: true
|
8772 | }
|
8773 | });
|
8774 | }
|
8775 |
|
8776 | function nsName(ns) {
|
8777 | if (isString(ns)) {
|
8778 | return ns;
|
8779 | } else {
|
8780 | return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
|
8781 | }
|
8782 | }
|
8783 |
|
8784 | function getNsAttrs(namespaces) {
|
8785 |
|
8786 | return map(namespaces.getUsed(), function(ns) {
|
8787 | var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
|
8788 | return { name: name, value: ns.uri };
|
8789 | });
|
8790 |
|
8791 | }
|
8792 |
|
8793 | function getElementNs(ns, descriptor) {
|
8794 | if (descriptor.isGeneric) {
|
8795 | return assign({ localName: descriptor.ns.localName }, ns);
|
8796 | } else {
|
8797 | return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
|
8798 | }
|
8799 | }
|
8800 |
|
8801 | function getPropertyNs(ns, descriptor) {
|
8802 | return assign({ localName: descriptor.ns.localName }, ns);
|
8803 | }
|
8804 |
|
8805 | function getSerializableProperties(element) {
|
8806 | var descriptor = element.$descriptor;
|
8807 |
|
8808 | return filter(descriptor.properties, function(p) {
|
8809 | var name = p.name;
|
8810 |
|
8811 | if (p.isVirtual) {
|
8812 | return false;
|
8813 | }
|
8814 |
|
8815 |
|
8816 | if (!element.hasOwnProperty(name)) {
|
8817 | return false;
|
8818 | }
|
8819 |
|
8820 | var value = element[name];
|
8821 |
|
8822 |
|
8823 | if (value === p.default) {
|
8824 | return false;
|
8825 | }
|
8826 |
|
8827 |
|
8828 | if (value === null) {
|
8829 | return false;
|
8830 | }
|
8831 |
|
8832 | return p.isMany ? value.length : true;
|
8833 | });
|
8834 | }
|
8835 |
|
8836 | var ESCAPE_ATTR_MAP = {
|
8837 | '\n': '#10',
|
8838 | '\n\r': '#10',
|
8839 | '"': '#34',
|
8840 | '\'': '#39',
|
8841 | '<': '#60',
|
8842 | '>': '#62',
|
8843 | '&': '#38'
|
8844 | };
|
8845 |
|
8846 | var ESCAPE_MAP = {
|
8847 | '<': 'lt',
|
8848 | '>': 'gt',
|
8849 | '&': 'amp'
|
8850 | };
|
8851 |
|
8852 | function escape$1(str, charPattern, replaceMap) {
|
8853 |
|
8854 |
|
8855 | str = isString(str) ? str : '' + str;
|
8856 |
|
8857 | return str.replace(charPattern, function(s) {
|
8858 | return '&' + replaceMap[s] + ';';
|
8859 | });
|
8860 | }
|
8861 |
|
8862 | |
8863 |
|
8864 |
|
8865 |
|
8866 |
|
8867 |
|
8868 | function escapeAttr(str) {
|
8869 | return escape$1(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
|
8870 | }
|
8871 |
|
8872 | function escapeBody(str) {
|
8873 | return escape$1(str, ESCAPE_CHARS, ESCAPE_MAP);
|
8874 | }
|
8875 |
|
8876 | function filterAttributes(props) {
|
8877 | return filter(props, function(p) { return p.isAttr; });
|
8878 | }
|
8879 |
|
8880 | function filterContained(props) {
|
8881 | return filter(props, function(p) { return !p.isAttr; });
|
8882 | }
|
8883 |
|
8884 |
|
8885 | function ReferenceSerializer(tagName) {
|
8886 | this.tagName = tagName;
|
8887 | }
|
8888 |
|
8889 | ReferenceSerializer.prototype.build = function(element) {
|
8890 | this.element = element;
|
8891 | return this;
|
8892 | };
|
8893 |
|
8894 | ReferenceSerializer.prototype.serializeTo = function(writer) {
|
8895 | writer
|
8896 | .appendIndent()
|
8897 | .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
|
8898 | .appendNewLine();
|
8899 | };
|
8900 |
|
8901 | function BodySerializer() {}
|
8902 |
|
8903 | BodySerializer.prototype.serializeValue =
|
8904 | BodySerializer.prototype.serializeTo = function(writer) {
|
8905 | writer.append(
|
8906 | this.escape
|
8907 | ? escapeBody(this.value)
|
8908 | : this.value
|
8909 | );
|
8910 | };
|
8911 |
|
8912 | BodySerializer.prototype.build = function(prop, value) {
|
8913 | this.value = value;
|
8914 |
|
8915 | if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
|
8916 | this.escape = true;
|
8917 | }
|
8918 |
|
8919 | return this;
|
8920 | };
|
8921 |
|
8922 | function ValueSerializer(tagName) {
|
8923 | this.tagName = tagName;
|
8924 | }
|
8925 |
|
8926 | inherits(ValueSerializer, BodySerializer);
|
8927 |
|
8928 | ValueSerializer.prototype.serializeTo = function(writer) {
|
8929 |
|
8930 | writer
|
8931 | .appendIndent()
|
8932 | .append('<' + this.tagName + '>');
|
8933 |
|
8934 | this.serializeValue(writer);
|
8935 |
|
8936 | writer
|
8937 | .append('</' + this.tagName + '>')
|
8938 | .appendNewLine();
|
8939 | };
|
8940 |
|
8941 | function ElementSerializer(parent, propertyDescriptor) {
|
8942 | this.body = [];
|
8943 | this.attrs = [];
|
8944 |
|
8945 | this.parent = parent;
|
8946 | this.propertyDescriptor = propertyDescriptor;
|
8947 | }
|
8948 |
|
8949 | ElementSerializer.prototype.build = function(element) {
|
8950 | this.element = element;
|
8951 |
|
8952 | var elementDescriptor = element.$descriptor,
|
8953 | propertyDescriptor = this.propertyDescriptor;
|
8954 |
|
8955 | var otherAttrs,
|
8956 | properties;
|
8957 |
|
8958 | var isGeneric = elementDescriptor.isGeneric;
|
8959 |
|
8960 | if (isGeneric) {
|
8961 | otherAttrs = this.parseGeneric(element);
|
8962 | } else {
|
8963 | otherAttrs = this.parseNsAttributes(element);
|
8964 | }
|
8965 |
|
8966 | if (propertyDescriptor) {
|
8967 | this.ns = this.nsPropertyTagName(propertyDescriptor);
|
8968 | } else {
|
8969 | this.ns = this.nsTagName(elementDescriptor);
|
8970 | }
|
8971 |
|
8972 |
|
8973 | this.tagName = this.addTagName(this.ns);
|
8974 |
|
8975 | if (!isGeneric) {
|
8976 | properties = getSerializableProperties(element);
|
8977 |
|
8978 | this.parseAttributes(filterAttributes(properties));
|
8979 | this.parseContainments(filterContained(properties));
|
8980 | }
|
8981 |
|
8982 | this.parseGenericAttributes(element, otherAttrs);
|
8983 |
|
8984 | return this;
|
8985 | };
|
8986 |
|
8987 | ElementSerializer.prototype.nsTagName = function(descriptor) {
|
8988 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
8989 | return getElementNs(effectiveNs, descriptor);
|
8990 | };
|
8991 |
|
8992 | ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
|
8993 | var effectiveNs = this.logNamespaceUsed(descriptor.ns);
|
8994 | return getPropertyNs(effectiveNs, descriptor);
|
8995 | };
|
8996 |
|
8997 | ElementSerializer.prototype.isLocalNs = function(ns) {
|
8998 | return ns.uri === this.ns.uri;
|
8999 | };
|
9000 |
|
9001 | |
9002 |
|
9003 |
|
9004 |
|
9005 |
|
9006 |
|
9007 |
|
9008 |
|
9009 | ElementSerializer.prototype.nsAttributeName = function(element) {
|
9010 |
|
9011 | var ns;
|
9012 |
|
9013 | if (isString(element)) {
|
9014 | ns = parseName(element);
|
9015 | } else {
|
9016 | ns = element.ns;
|
9017 | }
|
9018 |
|
9019 |
|
9020 | if (element.inherited) {
|
9021 | return { localName: ns.localName };
|
9022 | }
|
9023 |
|
9024 |
|
9025 | var effectiveNs = this.logNamespaceUsed(ns);
|
9026 |
|
9027 |
|
9028 | this.getNamespaces().logUsed(effectiveNs);
|
9029 |
|
9030 |
|
9031 | if (this.isLocalNs(effectiveNs)) {
|
9032 | return { localName: ns.localName };
|
9033 | } else {
|
9034 | return assign({ localName: ns.localName }, effectiveNs);
|
9035 | }
|
9036 | };
|
9037 |
|
9038 | ElementSerializer.prototype.parseGeneric = function(element) {
|
9039 |
|
9040 | var self = this,
|
9041 | body = this.body;
|
9042 |
|
9043 | var attributes = [];
|
9044 |
|
9045 | forEach(element, function(val, key) {
|
9046 |
|
9047 | var nonNsAttr;
|
9048 |
|
9049 | if (key === '$body') {
|
9050 | body.push(new BodySerializer().build({ type: 'String' }, val));
|
9051 | } else
|
9052 | if (key === '$children') {
|
9053 | forEach(val, function(child) {
|
9054 | body.push(new ElementSerializer(self).build(child));
|
9055 | });
|
9056 | } else
|
9057 | if (key.indexOf('$') !== 0) {
|
9058 | nonNsAttr = self.parseNsAttribute(element, key, val);
|
9059 |
|
9060 | if (nonNsAttr) {
|
9061 | attributes.push({ name: key, value: val });
|
9062 | }
|
9063 | }
|
9064 | });
|
9065 |
|
9066 | return attributes;
|
9067 | };
|
9068 |
|
9069 | ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
|
9070 | var model = element.$model;
|
9071 |
|
9072 | var nameNs = parseName(name);
|
9073 |
|
9074 | var ns;
|
9075 |
|
9076 |
|
9077 | if (nameNs.prefix === 'xmlns') {
|
9078 | ns = { prefix: nameNs.localName, uri: value };
|
9079 | }
|
9080 |
|
9081 |
|
9082 | if (!nameNs.prefix && nameNs.localName === 'xmlns') {
|
9083 | ns = { uri: value };
|
9084 | }
|
9085 |
|
9086 | if (!ns) {
|
9087 | return {
|
9088 | name: name,
|
9089 | value: value
|
9090 | };
|
9091 | }
|
9092 |
|
9093 | if (model && model.getPackage(value)) {
|
9094 |
|
9095 | this.logNamespace(ns, true, true);
|
9096 | } else {
|
9097 |
|
9098 | var actualNs = this.logNamespaceUsed(ns, true);
|
9099 |
|
9100 | this.getNamespaces().logUsed(actualNs);
|
9101 | }
|
9102 | };
|
9103 |
|
9104 |
|
9105 | |
9106 |
|
9107 |
|
9108 |
|
9109 |
|
9110 |
|
9111 | ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
|
9112 | var self = this;
|
9113 |
|
9114 | var genericAttrs = element.$attrs;
|
9115 |
|
9116 | var attributes = [];
|
9117 |
|
9118 |
|
9119 |
|
9120 |
|
9121 | forEach(genericAttrs, function(value, name) {
|
9122 |
|
9123 | var nonNsAttr = self.parseNsAttribute(element, name, value);
|
9124 |
|
9125 | if (nonNsAttr) {
|
9126 | attributes.push(nonNsAttr);
|
9127 | }
|
9128 | });
|
9129 |
|
9130 | return attributes;
|
9131 | };
|
9132 |
|
9133 | ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
|
9134 |
|
9135 | var self = this;
|
9136 |
|
9137 | forEach(attributes, function(attr) {
|
9138 |
|
9139 |
|
9140 |
|
9141 | if (attr.name === XSI_TYPE$1) {
|
9142 | return;
|
9143 | }
|
9144 |
|
9145 | try {
|
9146 | self.addAttribute(self.nsAttributeName(attr.name), attr.value);
|
9147 | } catch (e) {
|
9148 | console.warn(
|
9149 | 'missing namespace information for ',
|
9150 | attr.name, '=', attr.value, 'on', element,
|
9151 | e);
|
9152 | }
|
9153 | });
|
9154 | };
|
9155 |
|
9156 | ElementSerializer.prototype.parseContainments = function(properties) {
|
9157 |
|
9158 | var self = this,
|
9159 | body = this.body,
|
9160 | element = this.element;
|
9161 |
|
9162 | forEach(properties, function(p) {
|
9163 | var value = element.get(p.name),
|
9164 | isReference = p.isReference,
|
9165 | isMany = p.isMany;
|
9166 |
|
9167 | if (!isMany) {
|
9168 | value = [ value ];
|
9169 | }
|
9170 |
|
9171 | if (p.isBody) {
|
9172 | body.push(new BodySerializer().build(p, value[0]));
|
9173 | } else
|
9174 | if (isSimple(p.type)) {
|
9175 | forEach(value, function(v) {
|
9176 | body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
|
9177 | });
|
9178 | } else
|
9179 | if (isReference) {
|
9180 | forEach(value, function(v) {
|
9181 | body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
|
9182 | });
|
9183 | } else {
|
9184 |
|
9185 |
|
9186 | var asType = serializeAsType(p),
|
9187 | asProperty = serializeAsProperty(p);
|
9188 |
|
9189 | forEach(value, function(v) {
|
9190 | var serializer;
|
9191 |
|
9192 | if (asType) {
|
9193 | serializer = new TypeSerializer(self, p);
|
9194 | } else
|
9195 | if (asProperty) {
|
9196 | serializer = new ElementSerializer(self, p);
|
9197 | } else {
|
9198 | serializer = new ElementSerializer(self);
|
9199 | }
|
9200 |
|
9201 | body.push(serializer.build(v));
|
9202 | });
|
9203 | }
|
9204 | });
|
9205 | };
|
9206 |
|
9207 | ElementSerializer.prototype.getNamespaces = function(local) {
|
9208 |
|
9209 | var namespaces = this.namespaces,
|
9210 | parent = this.parent,
|
9211 | parentNamespaces;
|
9212 |
|
9213 | if (!namespaces) {
|
9214 | parentNamespaces = parent && parent.getNamespaces();
|
9215 |
|
9216 | if (local || !parentNamespaces) {
|
9217 | this.namespaces = namespaces = new Namespaces(parentNamespaces);
|
9218 | } else {
|
9219 | namespaces = parentNamespaces;
|
9220 | }
|
9221 | }
|
9222 |
|
9223 | return namespaces;
|
9224 | };
|
9225 |
|
9226 | ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
|
9227 | var namespaces = this.getNamespaces(local);
|
9228 |
|
9229 | var nsUri = ns.uri,
|
9230 | nsPrefix = ns.prefix;
|
9231 |
|
9232 | var existing = namespaces.byUri(nsUri);
|
9233 |
|
9234 | if (!existing) {
|
9235 | namespaces.add(ns, wellknown);
|
9236 | }
|
9237 |
|
9238 | namespaces.mapPrefix(nsPrefix, nsUri);
|
9239 |
|
9240 | return ns;
|
9241 | };
|
9242 |
|
9243 | ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
|
9244 | var element = this.element,
|
9245 | model = element.$model,
|
9246 | namespaces = this.getNamespaces(local);
|
9247 |
|
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 | var prefix = ns.prefix,
|
9255 | uri = ns.uri,
|
9256 | newPrefix, idx,
|
9257 | wellknownUri;
|
9258 |
|
9259 |
|
9260 | if (!prefix && !uri) {
|
9261 | return { localName: ns.localName };
|
9262 | }
|
9263 |
|
9264 | wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
|
9265 |
|
9266 | uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
|
9267 |
|
9268 | if (!uri) {
|
9269 | throw new Error('no namespace uri given for prefix <' + prefix + '>');
|
9270 | }
|
9271 |
|
9272 | ns = namespaces.byUri(uri);
|
9273 |
|
9274 | if (!ns) {
|
9275 | newPrefix = prefix;
|
9276 | idx = 1;
|
9277 |
|
9278 |
|
9279 | while (namespaces.uriByPrefix(newPrefix)) {
|
9280 | newPrefix = prefix + '_' + idx++;
|
9281 | }
|
9282 |
|
9283 | ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
|
9284 | }
|
9285 |
|
9286 | if (prefix) {
|
9287 | namespaces.mapPrefix(prefix, uri);
|
9288 | }
|
9289 |
|
9290 | return ns;
|
9291 | };
|
9292 |
|
9293 | ElementSerializer.prototype.parseAttributes = function(properties) {
|
9294 | var self = this,
|
9295 | element = this.element;
|
9296 |
|
9297 | forEach(properties, function(p) {
|
9298 |
|
9299 | var value = element.get(p.name);
|
9300 |
|
9301 | if (p.isReference) {
|
9302 |
|
9303 | if (!p.isMany) {
|
9304 | value = value.id;
|
9305 | }
|
9306 | else {
|
9307 | var values$$1 = [];
|
9308 | forEach(value, function(v) {
|
9309 | values$$1.push(v.id);
|
9310 | });
|
9311 |
|
9312 | value = values$$1.join(' ');
|
9313 | }
|
9314 |
|
9315 | }
|
9316 |
|
9317 | self.addAttribute(self.nsAttributeName(p), value);
|
9318 | });
|
9319 | };
|
9320 |
|
9321 | ElementSerializer.prototype.addTagName = function(nsTagName) {
|
9322 | var actualNs = this.logNamespaceUsed(nsTagName);
|
9323 |
|
9324 | this.getNamespaces().logUsed(actualNs);
|
9325 |
|
9326 | return nsName(nsTagName);
|
9327 | };
|
9328 |
|
9329 | ElementSerializer.prototype.addAttribute = function(name, value) {
|
9330 | var attrs = this.attrs;
|
9331 |
|
9332 | if (isString(value)) {
|
9333 | value = escapeAttr(value);
|
9334 | }
|
9335 |
|
9336 | attrs.push({ name: name, value: value });
|
9337 | };
|
9338 |
|
9339 | ElementSerializer.prototype.serializeAttributes = function(writer) {
|
9340 | var attrs = this.attrs,
|
9341 | namespaces = this.namespaces;
|
9342 |
|
9343 | if (namespaces) {
|
9344 | attrs = getNsAttrs(namespaces).concat(attrs);
|
9345 | }
|
9346 |
|
9347 | forEach(attrs, function(a) {
|
9348 | writer
|
9349 | .append(' ')
|
9350 | .append(nsName(a.name)).append('="').append(a.value).append('"');
|
9351 | });
|
9352 | };
|
9353 |
|
9354 | ElementSerializer.prototype.serializeTo = function(writer) {
|
9355 | var firstBody = this.body[0],
|
9356 | indent = firstBody && firstBody.constructor !== BodySerializer;
|
9357 |
|
9358 | writer
|
9359 | .appendIndent()
|
9360 | .append('<' + this.tagName);
|
9361 |
|
9362 | this.serializeAttributes(writer);
|
9363 |
|
9364 | writer.append(firstBody ? '>' : ' />');
|
9365 |
|
9366 | if (firstBody) {
|
9367 |
|
9368 | if (indent) {
|
9369 | writer
|
9370 | .appendNewLine()
|
9371 | .indent();
|
9372 | }
|
9373 |
|
9374 | forEach(this.body, function(b) {
|
9375 | b.serializeTo(writer);
|
9376 | });
|
9377 |
|
9378 | if (indent) {
|
9379 | writer
|
9380 | .unindent()
|
9381 | .appendIndent();
|
9382 | }
|
9383 |
|
9384 | writer.append('</' + this.tagName + '>');
|
9385 | }
|
9386 |
|
9387 | writer.appendNewLine();
|
9388 | };
|
9389 |
|
9390 | |
9391 |
|
9392 |
|
9393 | function TypeSerializer(parent, propertyDescriptor) {
|
9394 | ElementSerializer.call(this, parent, propertyDescriptor);
|
9395 | }
|
9396 |
|
9397 | inherits(TypeSerializer, ElementSerializer);
|
9398 |
|
9399 | TypeSerializer.prototype.parseNsAttributes = function(element) {
|
9400 |
|
9401 |
|
9402 | var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
|
9403 |
|
9404 | var descriptor = element.$descriptor;
|
9405 |
|
9406 |
|
9407 | if (descriptor.name === this.propertyDescriptor.type) {
|
9408 | return attributes;
|
9409 | }
|
9410 |
|
9411 | var typeNs = this.typeNs = this.nsTagName(descriptor);
|
9412 | this.getNamespaces().logUsed(this.typeNs);
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 | var pkg = element.$model.getPackage(typeNs.uri),
|
9418 | typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
|
9419 |
|
9420 | this.addAttribute(
|
9421 | this.nsAttributeName(XSI_TYPE$1),
|
9422 | (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
|
9423 | );
|
9424 |
|
9425 | return attributes;
|
9426 | };
|
9427 |
|
9428 | TypeSerializer.prototype.isLocalNs = function(ns) {
|
9429 | return ns.uri === (this.typeNs || this.ns).uri;
|
9430 | };
|
9431 |
|
9432 | function SavingWriter() {
|
9433 | this.value = '';
|
9434 |
|
9435 | this.write = function(str) {
|
9436 | this.value += str;
|
9437 | };
|
9438 | }
|
9439 |
|
9440 | function FormatingWriter(out, format) {
|
9441 |
|
9442 | var indent = [''];
|
9443 |
|
9444 | this.append = function(str) {
|
9445 | out.write(str);
|
9446 |
|
9447 | return this;
|
9448 | };
|
9449 |
|
9450 | this.appendNewLine = function() {
|
9451 | if (format) {
|
9452 | out.write('\n');
|
9453 | }
|
9454 |
|
9455 | return this;
|
9456 | };
|
9457 |
|
9458 | this.appendIndent = function() {
|
9459 | if (format) {
|
9460 | out.write(indent.join(' '));
|
9461 | }
|
9462 |
|
9463 | return this;
|
9464 | };
|
9465 |
|
9466 | this.indent = function() {
|
9467 | indent.push('');
|
9468 | return this;
|
9469 | };
|
9470 |
|
9471 | this.unindent = function() {
|
9472 | indent.pop();
|
9473 | return this;
|
9474 | };
|
9475 | }
|
9476 |
|
9477 | |
9478 |
|
9479 |
|
9480 |
|
9481 |
|
9482 | function Writer(options) {
|
9483 |
|
9484 | options = assign({ format: false, preamble: true }, options || {});
|
9485 |
|
9486 | function toXML(tree, writer) {
|
9487 | var internalWriter = writer || new SavingWriter();
|
9488 | var formatingWriter = new FormatingWriter(internalWriter, options.format);
|
9489 |
|
9490 | if (options.preamble) {
|
9491 | formatingWriter.append(XML_PREAMBLE);
|
9492 | }
|
9493 |
|
9494 | new ElementSerializer().build(tree).serializeTo(formatingWriter);
|
9495 |
|
9496 | if (!writer) {
|
9497 | return internalWriter.value;
|
9498 | }
|
9499 | }
|
9500 |
|
9501 | return {
|
9502 | toXML: toXML
|
9503 | };
|
9504 | }
|
9505 |
|
9506 | |
9507 |
|
9508 |
|
9509 |
|
9510 |
|
9511 |
|
9512 |
|
9513 |
|
9514 |
|
9515 | function BpmnModdle(packages, options) {
|
9516 | Moddle.call(this, packages, options);
|
9517 | }
|
9518 |
|
9519 | BpmnModdle.prototype = Object.create(Moddle.prototype);
|
9520 |
|
9521 |
|
9522 | |
9523 |
|
9524 |
|
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 |
|
9530 |
|
9531 | BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
|
9532 |
|
9533 | if (!isString(typeName)) {
|
9534 | done = options;
|
9535 | options = typeName;
|
9536 | typeName = 'bpmn:Definitions';
|
9537 | }
|
9538 |
|
9539 | if (isFunction(options)) {
|
9540 | done = options;
|
9541 | options = {};
|
9542 | }
|
9543 |
|
9544 | var reader = new Reader(assign({ model: this, lax: true }, options));
|
9545 | var rootHandler = reader.handler(typeName);
|
9546 |
|
9547 | reader.fromXML(xmlStr, rootHandler, done);
|
9548 | };
|
9549 |
|
9550 |
|
9551 | |
9552 |
|
9553 |
|
9554 |
|
9555 |
|
9556 |
|
9557 |
|
9558 | BpmnModdle.prototype.toXML = function(element, options, done) {
|
9559 |
|
9560 | if (isFunction(options)) {
|
9561 | done = options;
|
9562 | options = {};
|
9563 | }
|
9564 |
|
9565 | var writer = new Writer(options);
|
9566 |
|
9567 | var result;
|
9568 | var err;
|
9569 |
|
9570 | try {
|
9571 | result = writer.toXML(element);
|
9572 | } catch (e) {
|
9573 | err = e;
|
9574 | }
|
9575 |
|
9576 | return done(err, result);
|
9577 | };
|
9578 |
|
9579 | var name = "BPMN20";
|
9580 | var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
|
9581 | var associations = [
|
9582 | ];
|
9583 | var types$1 = [
|
9584 | {
|
9585 | name: "Interface",
|
9586 | superClass: [
|
9587 | "RootElement"
|
9588 | ],
|
9589 | properties: [
|
9590 | {
|
9591 | name: "name",
|
9592 | isAttr: true,
|
9593 | type: "String"
|
9594 | },
|
9595 | {
|
9596 | name: "operations",
|
9597 | type: "Operation",
|
9598 | isMany: true
|
9599 | },
|
9600 | {
|
9601 | name: "implementationRef",
|
9602 | type: "String",
|
9603 | isAttr: true
|
9604 | }
|
9605 | ]
|
9606 | },
|
9607 | {
|
9608 | name: "Operation",
|
9609 | superClass: [
|
9610 | "BaseElement"
|
9611 | ],
|
9612 | properties: [
|
9613 | {
|
9614 | name: "name",
|
9615 | isAttr: true,
|
9616 | type: "String"
|
9617 | },
|
9618 | {
|
9619 | name: "inMessageRef",
|
9620 | type: "Message",
|
9621 | isReference: true
|
9622 | },
|
9623 | {
|
9624 | name: "outMessageRef",
|
9625 | type: "Message",
|
9626 | isReference: true
|
9627 | },
|
9628 | {
|
9629 | name: "errorRef",
|
9630 | type: "Error",
|
9631 | isMany: true,
|
9632 | isReference: true
|
9633 | },
|
9634 | {
|
9635 | name: "implementationRef",
|
9636 | type: "String",
|
9637 | isAttr: true
|
9638 | }
|
9639 | ]
|
9640 | },
|
9641 | {
|
9642 | name: "EndPoint",
|
9643 | superClass: [
|
9644 | "RootElement"
|
9645 | ]
|
9646 | },
|
9647 | {
|
9648 | name: "Auditing",
|
9649 | superClass: [
|
9650 | "BaseElement"
|
9651 | ]
|
9652 | },
|
9653 | {
|
9654 | name: "GlobalTask",
|
9655 | superClass: [
|
9656 | "CallableElement"
|
9657 | ],
|
9658 | properties: [
|
9659 | {
|
9660 | name: "resources",
|
9661 | type: "ResourceRole",
|
9662 | isMany: true
|
9663 | }
|
9664 | ]
|
9665 | },
|
9666 | {
|
9667 | name: "Monitoring",
|
9668 | superClass: [
|
9669 | "BaseElement"
|
9670 | ]
|
9671 | },
|
9672 | {
|
9673 | name: "Performer",
|
9674 | superClass: [
|
9675 | "ResourceRole"
|
9676 | ]
|
9677 | },
|
9678 | {
|
9679 | name: "Process",
|
9680 | superClass: [
|
9681 | "FlowElementsContainer",
|
9682 | "CallableElement"
|
9683 | ],
|
9684 | properties: [
|
9685 | {
|
9686 | name: "processType",
|
9687 | type: "ProcessType",
|
9688 | isAttr: true
|
9689 | },
|
9690 | {
|
9691 | name: "isClosed",
|
9692 | isAttr: true,
|
9693 | type: "Boolean"
|
9694 | },
|
9695 | {
|
9696 | name: "auditing",
|
9697 | type: "Auditing"
|
9698 | },
|
9699 | {
|
9700 | name: "monitoring",
|
9701 | type: "Monitoring"
|
9702 | },
|
9703 | {
|
9704 | name: "properties",
|
9705 | type: "Property",
|
9706 | isMany: true
|
9707 | },
|
9708 | {
|
9709 | name: "laneSets",
|
9710 | type: "LaneSet",
|
9711 | isMany: true,
|
9712 | replaces: "FlowElementsContainer#laneSets"
|
9713 | },
|
9714 | {
|
9715 | name: "flowElements",
|
9716 | type: "FlowElement",
|
9717 | isMany: true,
|
9718 | replaces: "FlowElementsContainer#flowElements"
|
9719 | },
|
9720 | {
|
9721 | name: "artifacts",
|
9722 | type: "Artifact",
|
9723 | isMany: true
|
9724 | },
|
9725 | {
|
9726 | name: "resources",
|
9727 | type: "ResourceRole",
|
9728 | isMany: true
|
9729 | },
|
9730 | {
|
9731 | name: "correlationSubscriptions",
|
9732 | type: "CorrelationSubscription",
|
9733 | isMany: true
|
9734 | },
|
9735 | {
|
9736 | name: "supports",
|
9737 | type: "Process",
|
9738 | isMany: true,
|
9739 | isReference: true
|
9740 | },
|
9741 | {
|
9742 | name: "definitionalCollaborationRef",
|
9743 | type: "Collaboration",
|
9744 | isAttr: true,
|
9745 | isReference: true
|
9746 | },
|
9747 | {
|
9748 | name: "isExecutable",
|
9749 | isAttr: true,
|
9750 | type: "Boolean"
|
9751 | }
|
9752 | ]
|
9753 | },
|
9754 | {
|
9755 | name: "LaneSet",
|
9756 | superClass: [
|
9757 | "BaseElement"
|
9758 | ],
|
9759 | properties: [
|
9760 | {
|
9761 | name: "lanes",
|
9762 | type: "Lane",
|
9763 | isMany: true
|
9764 | },
|
9765 | {
|
9766 | name: "name",
|
9767 | isAttr: true,
|
9768 | type: "String"
|
9769 | }
|
9770 | ]
|
9771 | },
|
9772 | {
|
9773 | name: "Lane",
|
9774 | superClass: [
|
9775 | "BaseElement"
|
9776 | ],
|
9777 | properties: [
|
9778 | {
|
9779 | name: "name",
|
9780 | isAttr: true,
|
9781 | type: "String"
|
9782 | },
|
9783 | {
|
9784 | name: "partitionElementRef",
|
9785 | type: "BaseElement",
|
9786 | isAttr: true,
|
9787 | isReference: true
|
9788 | },
|
9789 | {
|
9790 | name: "partitionElement",
|
9791 | type: "BaseElement"
|
9792 | },
|
9793 | {
|
9794 | name: "flowNodeRef",
|
9795 | type: "FlowNode",
|
9796 | isMany: true,
|
9797 | isReference: true
|
9798 | },
|
9799 | {
|
9800 | name: "childLaneSet",
|
9801 | type: "LaneSet",
|
9802 | xml: {
|
9803 | serialize: "xsi:type"
|
9804 | }
|
9805 | }
|
9806 | ]
|
9807 | },
|
9808 | {
|
9809 | name: "GlobalManualTask",
|
9810 | superClass: [
|
9811 | "GlobalTask"
|
9812 | ]
|
9813 | },
|
9814 | {
|
9815 | name: "ManualTask",
|
9816 | superClass: [
|
9817 | "Task"
|
9818 | ]
|
9819 | },
|
9820 | {
|
9821 | name: "UserTask",
|
9822 | superClass: [
|
9823 | "Task"
|
9824 | ],
|
9825 | properties: [
|
9826 | {
|
9827 | name: "renderings",
|
9828 | type: "Rendering",
|
9829 | isMany: true
|
9830 | },
|
9831 | {
|
9832 | name: "implementation",
|
9833 | isAttr: true,
|
9834 | type: "String"
|
9835 | }
|
9836 | ]
|
9837 | },
|
9838 | {
|
9839 | name: "Rendering",
|
9840 | superClass: [
|
9841 | "BaseElement"
|
9842 | ]
|
9843 | },
|
9844 | {
|
9845 | name: "HumanPerformer",
|
9846 | superClass: [
|
9847 | "Performer"
|
9848 | ]
|
9849 | },
|
9850 | {
|
9851 | name: "PotentialOwner",
|
9852 | superClass: [
|
9853 | "HumanPerformer"
|
9854 | ]
|
9855 | },
|
9856 | {
|
9857 | name: "GlobalUserTask",
|
9858 | superClass: [
|
9859 | "GlobalTask"
|
9860 | ],
|
9861 | properties: [
|
9862 | {
|
9863 | name: "implementation",
|
9864 | isAttr: true,
|
9865 | type: "String"
|
9866 | },
|
9867 | {
|
9868 | name: "renderings",
|
9869 | type: "Rendering",
|
9870 | isMany: true
|
9871 | }
|
9872 | ]
|
9873 | },
|
9874 | {
|
9875 | name: "Gateway",
|
9876 | isAbstract: true,
|
9877 | superClass: [
|
9878 | "FlowNode"
|
9879 | ],
|
9880 | properties: [
|
9881 | {
|
9882 | name: "gatewayDirection",
|
9883 | type: "GatewayDirection",
|
9884 | "default": "Unspecified",
|
9885 | isAttr: true
|
9886 | }
|
9887 | ]
|
9888 | },
|
9889 | {
|
9890 | name: "EventBasedGateway",
|
9891 | superClass: [
|
9892 | "Gateway"
|
9893 | ],
|
9894 | properties: [
|
9895 | {
|
9896 | name: "instantiate",
|
9897 | "default": false,
|
9898 | isAttr: true,
|
9899 | type: "Boolean"
|
9900 | },
|
9901 | {
|
9902 | name: "eventGatewayType",
|
9903 | type: "EventBasedGatewayType",
|
9904 | isAttr: true,
|
9905 | "default": "Exclusive"
|
9906 | }
|
9907 | ]
|
9908 | },
|
9909 | {
|
9910 | name: "ComplexGateway",
|
9911 | superClass: [
|
9912 | "Gateway"
|
9913 | ],
|
9914 | properties: [
|
9915 | {
|
9916 | name: "activationCondition",
|
9917 | type: "Expression",
|
9918 | xml: {
|
9919 | serialize: "xsi:type"
|
9920 | }
|
9921 | },
|
9922 | {
|
9923 | name: "default",
|
9924 | type: "SequenceFlow",
|
9925 | isAttr: true,
|
9926 | isReference: true
|
9927 | }
|
9928 | ]
|
9929 | },
|
9930 | {
|
9931 | name: "ExclusiveGateway",
|
9932 | superClass: [
|
9933 | "Gateway"
|
9934 | ],
|
9935 | properties: [
|
9936 | {
|
9937 | name: "default",
|
9938 | type: "SequenceFlow",
|
9939 | isAttr: true,
|
9940 | isReference: true
|
9941 | }
|
9942 | ]
|
9943 | },
|
9944 | {
|
9945 | name: "InclusiveGateway",
|
9946 | superClass: [
|
9947 | "Gateway"
|
9948 | ],
|
9949 | properties: [
|
9950 | {
|
9951 | name: "default",
|
9952 | type: "SequenceFlow",
|
9953 | isAttr: true,
|
9954 | isReference: true
|
9955 | }
|
9956 | ]
|
9957 | },
|
9958 | {
|
9959 | name: "ParallelGateway",
|
9960 | superClass: [
|
9961 | "Gateway"
|
9962 | ]
|
9963 | },
|
9964 | {
|
9965 | name: "RootElement",
|
9966 | isAbstract: true,
|
9967 | superClass: [
|
9968 | "BaseElement"
|
9969 | ]
|
9970 | },
|
9971 | {
|
9972 | name: "Relationship",
|
9973 | superClass: [
|
9974 | "BaseElement"
|
9975 | ],
|
9976 | properties: [
|
9977 | {
|
9978 | name: "type",
|
9979 | isAttr: true,
|
9980 | type: "String"
|
9981 | },
|
9982 | {
|
9983 | name: "direction",
|
9984 | type: "RelationshipDirection",
|
9985 | isAttr: true
|
9986 | },
|
9987 | {
|
9988 | name: "source",
|
9989 | isMany: true,
|
9990 | isReference: true,
|
9991 | type: "Element"
|
9992 | },
|
9993 | {
|
9994 | name: "target",
|
9995 | isMany: true,
|
9996 | isReference: true,
|
9997 | type: "Element"
|
9998 | }
|
9999 | ]
|
10000 | },
|
10001 | {
|
10002 | name: "BaseElement",
|
10003 | isAbstract: true,
|
10004 | properties: [
|
10005 | {
|
10006 | name: "id",
|
10007 | isAttr: true,
|
10008 | type: "String",
|
10009 | isId: true
|
10010 | },
|
10011 | {
|
10012 | name: "documentation",
|
10013 | type: "Documentation",
|
10014 | isMany: true
|
10015 | },
|
10016 | {
|
10017 | name: "extensionDefinitions",
|
10018 | type: "ExtensionDefinition",
|
10019 | isMany: true,
|
10020 | isReference: true
|
10021 | },
|
10022 | {
|
10023 | name: "extensionElements",
|
10024 | type: "ExtensionElements"
|
10025 | }
|
10026 | ]
|
10027 | },
|
10028 | {
|
10029 | name: "Extension",
|
10030 | properties: [
|
10031 | {
|
10032 | name: "mustUnderstand",
|
10033 | "default": false,
|
10034 | isAttr: true,
|
10035 | type: "Boolean"
|
10036 | },
|
10037 | {
|
10038 | name: "definition",
|
10039 | type: "ExtensionDefinition",
|
10040 | isAttr: true,
|
10041 | isReference: true
|
10042 | }
|
10043 | ]
|
10044 | },
|
10045 | {
|
10046 | name: "ExtensionDefinition",
|
10047 | properties: [
|
10048 | {
|
10049 | name: "name",
|
10050 | isAttr: true,
|
10051 | type: "String"
|
10052 | },
|
10053 | {
|
10054 | name: "extensionAttributeDefinitions",
|
10055 | type: "ExtensionAttributeDefinition",
|
10056 | isMany: true
|
10057 | }
|
10058 | ]
|
10059 | },
|
10060 | {
|
10061 | name: "ExtensionAttributeDefinition",
|
10062 | properties: [
|
10063 | {
|
10064 | name: "name",
|
10065 | isAttr: true,
|
10066 | type: "String"
|
10067 | },
|
10068 | {
|
10069 | name: "type",
|
10070 | isAttr: true,
|
10071 | type: "String"
|
10072 | },
|
10073 | {
|
10074 | name: "isReference",
|
10075 | "default": false,
|
10076 | isAttr: true,
|
10077 | type: "Boolean"
|
10078 | },
|
10079 | {
|
10080 | name: "extensionDefinition",
|
10081 | type: "ExtensionDefinition",
|
10082 | isAttr: true,
|
10083 | isReference: true
|
10084 | }
|
10085 | ]
|
10086 | },
|
10087 | {
|
10088 | name: "ExtensionElements",
|
10089 | properties: [
|
10090 | {
|
10091 | name: "valueRef",
|
10092 | isAttr: true,
|
10093 | isReference: true,
|
10094 | type: "Element"
|
10095 | },
|
10096 | {
|
10097 | name: "values",
|
10098 | type: "Element",
|
10099 | isMany: true
|
10100 | },
|
10101 | {
|
10102 | name: "extensionAttributeDefinition",
|
10103 | type: "ExtensionAttributeDefinition",
|
10104 | isAttr: true,
|
10105 | isReference: true
|
10106 | }
|
10107 | ]
|
10108 | },
|
10109 | {
|
10110 | name: "Documentation",
|
10111 | superClass: [
|
10112 | "BaseElement"
|
10113 | ],
|
10114 | properties: [
|
10115 | {
|
10116 | name: "text",
|
10117 | type: "String",
|
10118 | isBody: true
|
10119 | },
|
10120 | {
|
10121 | name: "textFormat",
|
10122 | "default": "text/plain",
|
10123 | isAttr: true,
|
10124 | type: "String"
|
10125 | }
|
10126 | ]
|
10127 | },
|
10128 | {
|
10129 | name: "Event",
|
10130 | isAbstract: true,
|
10131 | superClass: [
|
10132 | "FlowNode",
|
10133 | "InteractionNode"
|
10134 | ],
|
10135 | properties: [
|
10136 | {
|
10137 | name: "properties",
|
10138 | type: "Property",
|
10139 | isMany: true
|
10140 | }
|
10141 | ]
|
10142 | },
|
10143 | {
|
10144 | name: "IntermediateCatchEvent",
|
10145 | superClass: [
|
10146 | "CatchEvent"
|
10147 | ]
|
10148 | },
|
10149 | {
|
10150 | name: "IntermediateThrowEvent",
|
10151 | superClass: [
|
10152 | "ThrowEvent"
|
10153 | ]
|
10154 | },
|
10155 | {
|
10156 | name: "EndEvent",
|
10157 | superClass: [
|
10158 | "ThrowEvent"
|
10159 | ]
|
10160 | },
|
10161 | {
|
10162 | name: "StartEvent",
|
10163 | superClass: [
|
10164 | "CatchEvent"
|
10165 | ],
|
10166 | properties: [
|
10167 | {
|
10168 | name: "isInterrupting",
|
10169 | "default": true,
|
10170 | isAttr: true,
|
10171 | type: "Boolean"
|
10172 | }
|
10173 | ]
|
10174 | },
|
10175 | {
|
10176 | name: "ThrowEvent",
|
10177 | isAbstract: true,
|
10178 | superClass: [
|
10179 | "Event"
|
10180 | ],
|
10181 | properties: [
|
10182 | {
|
10183 | name: "dataInputs",
|
10184 | type: "DataInput",
|
10185 | isMany: true
|
10186 | },
|
10187 | {
|
10188 | name: "dataInputAssociations",
|
10189 | type: "DataInputAssociation",
|
10190 | isMany: true
|
10191 | },
|
10192 | {
|
10193 | name: "inputSet",
|
10194 | type: "InputSet"
|
10195 | },
|
10196 | {
|
10197 | name: "eventDefinitions",
|
10198 | type: "EventDefinition",
|
10199 | isMany: true
|
10200 | },
|
10201 | {
|
10202 | name: "eventDefinitionRef",
|
10203 | type: "EventDefinition",
|
10204 | isMany: true,
|
10205 | isReference: true
|
10206 | }
|
10207 | ]
|
10208 | },
|
10209 | {
|
10210 | name: "CatchEvent",
|
10211 | isAbstract: true,
|
10212 | superClass: [
|
10213 | "Event"
|
10214 | ],
|
10215 | properties: [
|
10216 | {
|
10217 | name: "parallelMultiple",
|
10218 | isAttr: true,
|
10219 | type: "Boolean",
|
10220 | "default": false
|
10221 | },
|
10222 | {
|
10223 | name: "dataOutputs",
|
10224 | type: "DataOutput",
|
10225 | isMany: true
|
10226 | },
|
10227 | {
|
10228 | name: "dataOutputAssociations",
|
10229 | type: "DataOutputAssociation",
|
10230 | isMany: true
|
10231 | },
|
10232 | {
|
10233 | name: "outputSet",
|
10234 | type: "OutputSet"
|
10235 | },
|
10236 | {
|
10237 | name: "eventDefinitions",
|
10238 | type: "EventDefinition",
|
10239 | isMany: true
|
10240 | },
|
10241 | {
|
10242 | name: "eventDefinitionRef",
|
10243 | type: "EventDefinition",
|
10244 | isMany: true,
|
10245 | isReference: true
|
10246 | }
|
10247 | ]
|
10248 | },
|
10249 | {
|
10250 | name: "BoundaryEvent",
|
10251 | superClass: [
|
10252 | "CatchEvent"
|
10253 | ],
|
10254 | properties: [
|
10255 | {
|
10256 | name: "cancelActivity",
|
10257 | "default": true,
|
10258 | isAttr: true,
|
10259 | type: "Boolean"
|
10260 | },
|
10261 | {
|
10262 | name: "attachedToRef",
|
10263 | type: "Activity",
|
10264 | isAttr: true,
|
10265 | isReference: true
|
10266 | }
|
10267 | ]
|
10268 | },
|
10269 | {
|
10270 | name: "EventDefinition",
|
10271 | isAbstract: true,
|
10272 | superClass: [
|
10273 | "RootElement"
|
10274 | ]
|
10275 | },
|
10276 | {
|
10277 | name: "CancelEventDefinition",
|
10278 | superClass: [
|
10279 | "EventDefinition"
|
10280 | ]
|
10281 | },
|
10282 | {
|
10283 | name: "ErrorEventDefinition",
|
10284 | superClass: [
|
10285 | "EventDefinition"
|
10286 | ],
|
10287 | properties: [
|
10288 | {
|
10289 | name: "errorRef",
|
10290 | type: "Error",
|
10291 | isAttr: true,
|
10292 | isReference: true
|
10293 | }
|
10294 | ]
|
10295 | },
|
10296 | {
|
10297 | name: "TerminateEventDefinition",
|
10298 | superClass: [
|
10299 | "EventDefinition"
|
10300 | ]
|
10301 | },
|
10302 | {
|
10303 | name: "EscalationEventDefinition",
|
10304 | superClass: [
|
10305 | "EventDefinition"
|
10306 | ],
|
10307 | properties: [
|
10308 | {
|
10309 | name: "escalationRef",
|
10310 | type: "Escalation",
|
10311 | isAttr: true,
|
10312 | isReference: true
|
10313 | }
|
10314 | ]
|
10315 | },
|
10316 | {
|
10317 | name: "Escalation",
|
10318 | properties: [
|
10319 | {
|
10320 | name: "structureRef",
|
10321 | type: "ItemDefinition",
|
10322 | isAttr: true,
|
10323 | isReference: true
|
10324 | },
|
10325 | {
|
10326 | name: "name",
|
10327 | isAttr: true,
|
10328 | type: "String"
|
10329 | },
|
10330 | {
|
10331 | name: "escalationCode",
|
10332 | isAttr: true,
|
10333 | type: "String"
|
10334 | }
|
10335 | ],
|
10336 | superClass: [
|
10337 | "RootElement"
|
10338 | ]
|
10339 | },
|
10340 | {
|
10341 | name: "CompensateEventDefinition",
|
10342 | superClass: [
|
10343 | "EventDefinition"
|
10344 | ],
|
10345 | properties: [
|
10346 | {
|
10347 | name: "waitForCompletion",
|
10348 | isAttr: true,
|
10349 | type: "Boolean",
|
10350 | "default": true
|
10351 | },
|
10352 | {
|
10353 | name: "activityRef",
|
10354 | type: "Activity",
|
10355 | isAttr: true,
|
10356 | isReference: true
|
10357 | }
|
10358 | ]
|
10359 | },
|
10360 | {
|
10361 | name: "TimerEventDefinition",
|
10362 | superClass: [
|
10363 | "EventDefinition"
|
10364 | ],
|
10365 | properties: [
|
10366 | {
|
10367 | name: "timeDate",
|
10368 | type: "Expression",
|
10369 | xml: {
|
10370 | serialize: "xsi:type"
|
10371 | }
|
10372 | },
|
10373 | {
|
10374 | name: "timeCycle",
|
10375 | type: "Expression",
|
10376 | xml: {
|
10377 | serialize: "xsi:type"
|
10378 | }
|
10379 | },
|
10380 | {
|
10381 | name: "timeDuration",
|
10382 | type: "Expression",
|
10383 | xml: {
|
10384 | serialize: "xsi:type"
|
10385 | }
|
10386 | }
|
10387 | ]
|
10388 | },
|
10389 | {
|
10390 | name: "LinkEventDefinition",
|
10391 | superClass: [
|
10392 | "EventDefinition"
|
10393 | ],
|
10394 | properties: [
|
10395 | {
|
10396 | name: "name",
|
10397 | isAttr: true,
|
10398 | type: "String"
|
10399 | },
|
10400 | {
|
10401 | name: "target",
|
10402 | type: "LinkEventDefinition",
|
10403 | isAttr: true,
|
10404 | isReference: true
|
10405 | },
|
10406 | {
|
10407 | name: "source",
|
10408 | type: "LinkEventDefinition",
|
10409 | isMany: true,
|
10410 | isReference: true
|
10411 | }
|
10412 | ]
|
10413 | },
|
10414 | {
|
10415 | name: "MessageEventDefinition",
|
10416 | superClass: [
|
10417 | "EventDefinition"
|
10418 | ],
|
10419 | properties: [
|
10420 | {
|
10421 | name: "messageRef",
|
10422 | type: "Message",
|
10423 | isAttr: true,
|
10424 | isReference: true
|
10425 | },
|
10426 | {
|
10427 | name: "operationRef",
|
10428 | type: "Operation",
|
10429 | isAttr: true,
|
10430 | isReference: true
|
10431 | }
|
10432 | ]
|
10433 | },
|
10434 | {
|
10435 | name: "ConditionalEventDefinition",
|
10436 | superClass: [
|
10437 | "EventDefinition"
|
10438 | ],
|
10439 | properties: [
|
10440 | {
|
10441 | name: "condition",
|
10442 | type: "Expression",
|
10443 | xml: {
|
10444 | serialize: "xsi:type"
|
10445 | }
|
10446 | }
|
10447 | ]
|
10448 | },
|
10449 | {
|
10450 | name: "SignalEventDefinition",
|
10451 | superClass: [
|
10452 | "EventDefinition"
|
10453 | ],
|
10454 | properties: [
|
10455 | {
|
10456 | name: "signalRef",
|
10457 | type: "Signal",
|
10458 | isAttr: true,
|
10459 | isReference: true
|
10460 | }
|
10461 | ]
|
10462 | },
|
10463 | {
|
10464 | name: "Signal",
|
10465 | superClass: [
|
10466 | "RootElement"
|
10467 | ],
|
10468 | properties: [
|
10469 | {
|
10470 | name: "structureRef",
|
10471 | type: "ItemDefinition",
|
10472 | isAttr: true,
|
10473 | isReference: true
|
10474 | },
|
10475 | {
|
10476 | name: "name",
|
10477 | isAttr: true,
|
10478 | type: "String"
|
10479 | }
|
10480 | ]
|
10481 | },
|
10482 | {
|
10483 | name: "ImplicitThrowEvent",
|
10484 | superClass: [
|
10485 | "ThrowEvent"
|
10486 | ]
|
10487 | },
|
10488 | {
|
10489 | name: "DataState",
|
10490 | superClass: [
|
10491 | "BaseElement"
|
10492 | ],
|
10493 | properties: [
|
10494 | {
|
10495 | name: "name",
|
10496 | isAttr: true,
|
10497 | type: "String"
|
10498 | }
|
10499 | ]
|
10500 | },
|
10501 | {
|
10502 | name: "ItemAwareElement",
|
10503 | superClass: [
|
10504 | "BaseElement"
|
10505 | ],
|
10506 | properties: [
|
10507 | {
|
10508 | name: "itemSubjectRef",
|
10509 | type: "ItemDefinition",
|
10510 | isAttr: true,
|
10511 | isReference: true
|
10512 | },
|
10513 | {
|
10514 | name: "dataState",
|
10515 | type: "DataState"
|
10516 | }
|
10517 | ]
|
10518 | },
|
10519 | {
|
10520 | name: "DataAssociation",
|
10521 | superClass: [
|
10522 | "BaseElement"
|
10523 | ],
|
10524 | properties: [
|
10525 | {
|
10526 | name: "assignment",
|
10527 | type: "Assignment",
|
10528 | isMany: true
|
10529 | },
|
10530 | {
|
10531 | name: "sourceRef",
|
10532 | type: "ItemAwareElement",
|
10533 | isMany: true,
|
10534 | isReference: true
|
10535 | },
|
10536 | {
|
10537 | name: "targetRef",
|
10538 | type: "ItemAwareElement",
|
10539 | isReference: true
|
10540 | },
|
10541 | {
|
10542 | name: "transformation",
|
10543 | type: "FormalExpression",
|
10544 | xml: {
|
10545 | serialize: "property"
|
10546 | }
|
10547 | }
|
10548 | ]
|
10549 | },
|
10550 | {
|
10551 | name: "DataInput",
|
10552 | superClass: [
|
10553 | "ItemAwareElement"
|
10554 | ],
|
10555 | properties: [
|
10556 | {
|
10557 | name: "name",
|
10558 | isAttr: true,
|
10559 | type: "String"
|
10560 | },
|
10561 | {
|
10562 | name: "isCollection",
|
10563 | "default": false,
|
10564 | isAttr: true,
|
10565 | type: "Boolean"
|
10566 | },
|
10567 | {
|
10568 | name: "inputSetRef",
|
10569 | type: "InputSet",
|
10570 | isVirtual: true,
|
10571 | isMany: true,
|
10572 | isReference: true
|
10573 | },
|
10574 | {
|
10575 | name: "inputSetWithOptional",
|
10576 | type: "InputSet",
|
10577 | isVirtual: true,
|
10578 | isMany: true,
|
10579 | isReference: true
|
10580 | },
|
10581 | {
|
10582 | name: "inputSetWithWhileExecuting",
|
10583 | type: "InputSet",
|
10584 | isVirtual: true,
|
10585 | isMany: true,
|
10586 | isReference: true
|
10587 | }
|
10588 | ]
|
10589 | },
|
10590 | {
|
10591 | name: "DataOutput",
|
10592 | superClass: [
|
10593 | "ItemAwareElement"
|
10594 | ],
|
10595 | properties: [
|
10596 | {
|
10597 | name: "name",
|
10598 | isAttr: true,
|
10599 | type: "String"
|
10600 | },
|
10601 | {
|
10602 | name: "isCollection",
|
10603 | "default": false,
|
10604 | isAttr: true,
|
10605 | type: "Boolean"
|
10606 | },
|
10607 | {
|
10608 | name: "outputSetRef",
|
10609 | type: "OutputSet",
|
10610 | isVirtual: true,
|
10611 | isMany: true,
|
10612 | isReference: true
|
10613 | },
|
10614 | {
|
10615 | name: "outputSetWithOptional",
|
10616 | type: "OutputSet",
|
10617 | isVirtual: true,
|
10618 | isMany: true,
|
10619 | isReference: true
|
10620 | },
|
10621 | {
|
10622 | name: "outputSetWithWhileExecuting",
|
10623 | type: "OutputSet",
|
10624 | isVirtual: true,
|
10625 | isMany: true,
|
10626 | isReference: true
|
10627 | }
|
10628 | ]
|
10629 | },
|
10630 | {
|
10631 | name: "InputSet",
|
10632 | superClass: [
|
10633 | "BaseElement"
|
10634 | ],
|
10635 | properties: [
|
10636 | {
|
10637 | name: "name",
|
10638 | isAttr: true,
|
10639 | type: "String"
|
10640 | },
|
10641 | {
|
10642 | name: "dataInputRefs",
|
10643 | type: "DataInput",
|
10644 | isMany: true,
|
10645 | isReference: true
|
10646 | },
|
10647 | {
|
10648 | name: "optionalInputRefs",
|
10649 | type: "DataInput",
|
10650 | isMany: true,
|
10651 | isReference: true
|
10652 | },
|
10653 | {
|
10654 | name: "whileExecutingInputRefs",
|
10655 | type: "DataInput",
|
10656 | isMany: true,
|
10657 | isReference: true
|
10658 | },
|
10659 | {
|
10660 | name: "outputSetRefs",
|
10661 | type: "OutputSet",
|
10662 | isMany: true,
|
10663 | isReference: true
|
10664 | }
|
10665 | ]
|
10666 | },
|
10667 | {
|
10668 | name: "OutputSet",
|
10669 | superClass: [
|
10670 | "BaseElement"
|
10671 | ],
|
10672 | properties: [
|
10673 | {
|
10674 | name: "dataOutputRefs",
|
10675 | type: "DataOutput",
|
10676 | isMany: true,
|
10677 | isReference: true
|
10678 | },
|
10679 | {
|
10680 | name: "name",
|
10681 | isAttr: true,
|
10682 | type: "String"
|
10683 | },
|
10684 | {
|
10685 | name: "inputSetRefs",
|
10686 | type: "InputSet",
|
10687 | isMany: true,
|
10688 | isReference: true
|
10689 | },
|
10690 | {
|
10691 | name: "optionalOutputRefs",
|
10692 | type: "DataOutput",
|
10693 | isMany: true,
|
10694 | isReference: true
|
10695 | },
|
10696 | {
|
10697 | name: "whileExecutingOutputRefs",
|
10698 | type: "DataOutput",
|
10699 | isMany: true,
|
10700 | isReference: true
|
10701 | }
|
10702 | ]
|
10703 | },
|
10704 | {
|
10705 | name: "Property",
|
10706 | superClass: [
|
10707 | "ItemAwareElement"
|
10708 | ],
|
10709 | properties: [
|
10710 | {
|
10711 | name: "name",
|
10712 | isAttr: true,
|
10713 | type: "String"
|
10714 | }
|
10715 | ]
|
10716 | },
|
10717 | {
|
10718 | name: "DataInputAssociation",
|
10719 | superClass: [
|
10720 | "DataAssociation"
|
10721 | ]
|
10722 | },
|
10723 | {
|
10724 | name: "DataOutputAssociation",
|
10725 | superClass: [
|
10726 | "DataAssociation"
|
10727 | ]
|
10728 | },
|
10729 | {
|
10730 | name: "InputOutputSpecification",
|
10731 | superClass: [
|
10732 | "BaseElement"
|
10733 | ],
|
10734 | properties: [
|
10735 | {
|
10736 | name: "dataInputs",
|
10737 | type: "DataInput",
|
10738 | isMany: true
|
10739 | },
|
10740 | {
|
10741 | name: "dataOutputs",
|
10742 | type: "DataOutput",
|
10743 | isMany: true
|
10744 | },
|
10745 | {
|
10746 | name: "inputSets",
|
10747 | type: "InputSet",
|
10748 | isMany: true
|
10749 | },
|
10750 | {
|
10751 | name: "outputSets",
|
10752 | type: "OutputSet",
|
10753 | isMany: true
|
10754 | }
|
10755 | ]
|
10756 | },
|
10757 | {
|
10758 | name: "DataObject",
|
10759 | superClass: [
|
10760 | "FlowElement",
|
10761 | "ItemAwareElement"
|
10762 | ],
|
10763 | properties: [
|
10764 | {
|
10765 | name: "isCollection",
|
10766 | "default": false,
|
10767 | isAttr: true,
|
10768 | type: "Boolean"
|
10769 | }
|
10770 | ]
|
10771 | },
|
10772 | {
|
10773 | name: "InputOutputBinding",
|
10774 | properties: [
|
10775 | {
|
10776 | name: "inputDataRef",
|
10777 | type: "InputSet",
|
10778 | isAttr: true,
|
10779 | isReference: true
|
10780 | },
|
10781 | {
|
10782 | name: "outputDataRef",
|
10783 | type: "OutputSet",
|
10784 | isAttr: true,
|
10785 | isReference: true
|
10786 | },
|
10787 | {
|
10788 | name: "operationRef",
|
10789 | type: "Operation",
|
10790 | isAttr: true,
|
10791 | isReference: true
|
10792 | }
|
10793 | ]
|
10794 | },
|
10795 | {
|
10796 | name: "Assignment",
|
10797 | superClass: [
|
10798 | "BaseElement"
|
10799 | ],
|
10800 | properties: [
|
10801 | {
|
10802 | name: "from",
|
10803 | type: "Expression",
|
10804 | xml: {
|
10805 | serialize: "xsi:type"
|
10806 | }
|
10807 | },
|
10808 | {
|
10809 | name: "to",
|
10810 | type: "Expression",
|
10811 | xml: {
|
10812 | serialize: "xsi:type"
|
10813 | }
|
10814 | }
|
10815 | ]
|
10816 | },
|
10817 | {
|
10818 | name: "DataStore",
|
10819 | superClass: [
|
10820 | "RootElement",
|
10821 | "ItemAwareElement"
|
10822 | ],
|
10823 | properties: [
|
10824 | {
|
10825 | name: "name",
|
10826 | isAttr: true,
|
10827 | type: "String"
|
10828 | },
|
10829 | {
|
10830 | name: "capacity",
|
10831 | isAttr: true,
|
10832 | type: "Integer"
|
10833 | },
|
10834 | {
|
10835 | name: "isUnlimited",
|
10836 | "default": true,
|
10837 | isAttr: true,
|
10838 | type: "Boolean"
|
10839 | }
|
10840 | ]
|
10841 | },
|
10842 | {
|
10843 | name: "DataStoreReference",
|
10844 | superClass: [
|
10845 | "ItemAwareElement",
|
10846 | "FlowElement"
|
10847 | ],
|
10848 | properties: [
|
10849 | {
|
10850 | name: "dataStoreRef",
|
10851 | type: "DataStore",
|
10852 | isAttr: true,
|
10853 | isReference: true
|
10854 | }
|
10855 | ]
|
10856 | },
|
10857 | {
|
10858 | name: "DataObjectReference",
|
10859 | superClass: [
|
10860 | "ItemAwareElement",
|
10861 | "FlowElement"
|
10862 | ],
|
10863 | properties: [
|
10864 | {
|
10865 | name: "dataObjectRef",
|
10866 | type: "DataObject",
|
10867 | isAttr: true,
|
10868 | isReference: true
|
10869 | }
|
10870 | ]
|
10871 | },
|
10872 | {
|
10873 | name: "ConversationLink",
|
10874 | superClass: [
|
10875 | "BaseElement"
|
10876 | ],
|
10877 | properties: [
|
10878 | {
|
10879 | name: "sourceRef",
|
10880 | type: "InteractionNode",
|
10881 | isAttr: true,
|
10882 | isReference: true
|
10883 | },
|
10884 | {
|
10885 | name: "targetRef",
|
10886 | type: "InteractionNode",
|
10887 | isAttr: true,
|
10888 | isReference: true
|
10889 | },
|
10890 | {
|
10891 | name: "name",
|
10892 | isAttr: true,
|
10893 | type: "String"
|
10894 | }
|
10895 | ]
|
10896 | },
|
10897 | {
|
10898 | name: "ConversationAssociation",
|
10899 | superClass: [
|
10900 | "BaseElement"
|
10901 | ],
|
10902 | properties: [
|
10903 | {
|
10904 | name: "innerConversationNodeRef",
|
10905 | type: "ConversationNode",
|
10906 | isAttr: true,
|
10907 | isReference: true
|
10908 | },
|
10909 | {
|
10910 | name: "outerConversationNodeRef",
|
10911 | type: "ConversationNode",
|
10912 | isAttr: true,
|
10913 | isReference: true
|
10914 | }
|
10915 | ]
|
10916 | },
|
10917 | {
|
10918 | name: "CallConversation",
|
10919 | superClass: [
|
10920 | "ConversationNode"
|
10921 | ],
|
10922 | properties: [
|
10923 | {
|
10924 | name: "calledCollaborationRef",
|
10925 | type: "Collaboration",
|
10926 | isAttr: true,
|
10927 | isReference: true
|
10928 | },
|
10929 | {
|
10930 | name: "participantAssociations",
|
10931 | type: "ParticipantAssociation",
|
10932 | isMany: true
|
10933 | }
|
10934 | ]
|
10935 | },
|
10936 | {
|
10937 | name: "Conversation",
|
10938 | superClass: [
|
10939 | "ConversationNode"
|
10940 | ]
|
10941 | },
|
10942 | {
|
10943 | name: "SubConversation",
|
10944 | superClass: [
|
10945 | "ConversationNode"
|
10946 | ],
|
10947 | properties: [
|
10948 | {
|
10949 | name: "conversationNodes",
|
10950 | type: "ConversationNode",
|
10951 | isMany: true
|
10952 | }
|
10953 | ]
|
10954 | },
|
10955 | {
|
10956 | name: "ConversationNode",
|
10957 | isAbstract: true,
|
10958 | superClass: [
|
10959 | "InteractionNode",
|
10960 | "BaseElement"
|
10961 | ],
|
10962 | properties: [
|
10963 | {
|
10964 | name: "name",
|
10965 | isAttr: true,
|
10966 | type: "String"
|
10967 | },
|
10968 | {
|
10969 | name: "participantRef",
|
10970 | type: "Participant",
|
10971 | isMany: true,
|
10972 | isReference: true
|
10973 | },
|
10974 | {
|
10975 | name: "messageFlowRefs",
|
10976 | type: "MessageFlow",
|
10977 | isMany: true,
|
10978 | isReference: true
|
10979 | },
|
10980 | {
|
10981 | name: "correlationKeys",
|
10982 | type: "CorrelationKey",
|
10983 | isMany: true
|
10984 | }
|
10985 | ]
|
10986 | },
|
10987 | {
|
10988 | name: "GlobalConversation",
|
10989 | superClass: [
|
10990 | "Collaboration"
|
10991 | ]
|
10992 | },
|
10993 | {
|
10994 | name: "PartnerEntity",
|
10995 | superClass: [
|
10996 | "RootElement"
|
10997 | ],
|
10998 | properties: [
|
10999 | {
|
11000 | name: "name",
|
11001 | isAttr: true,
|
11002 | type: "String"
|
11003 | },
|
11004 | {
|
11005 | name: "participantRef",
|
11006 | type: "Participant",
|
11007 | isMany: true,
|
11008 | isReference: true
|
11009 | }
|
11010 | ]
|
11011 | },
|
11012 | {
|
11013 | name: "PartnerRole",
|
11014 | superClass: [
|
11015 | "RootElement"
|
11016 | ],
|
11017 | properties: [
|
11018 | {
|
11019 | name: "name",
|
11020 | isAttr: true,
|
11021 | type: "String"
|
11022 | },
|
11023 | {
|
11024 | name: "participantRef",
|
11025 | type: "Participant",
|
11026 | isMany: true,
|
11027 | isReference: true
|
11028 | }
|
11029 | ]
|
11030 | },
|
11031 | {
|
11032 | name: "CorrelationProperty",
|
11033 | superClass: [
|
11034 | "RootElement"
|
11035 | ],
|
11036 | properties: [
|
11037 | {
|
11038 | name: "correlationPropertyRetrievalExpression",
|
11039 | type: "CorrelationPropertyRetrievalExpression",
|
11040 | isMany: true
|
11041 | },
|
11042 | {
|
11043 | name: "name",
|
11044 | isAttr: true,
|
11045 | type: "String"
|
11046 | },
|
11047 | {
|
11048 | name: "type",
|
11049 | type: "ItemDefinition",
|
11050 | isAttr: true,
|
11051 | isReference: true
|
11052 | }
|
11053 | ]
|
11054 | },
|
11055 | {
|
11056 | name: "Error",
|
11057 | superClass: [
|
11058 | "RootElement"
|
11059 | ],
|
11060 | properties: [
|
11061 | {
|
11062 | name: "structureRef",
|
11063 | type: "ItemDefinition",
|
11064 | isAttr: true,
|
11065 | isReference: true
|
11066 | },
|
11067 | {
|
11068 | name: "name",
|
11069 | isAttr: true,
|
11070 | type: "String"
|
11071 | },
|
11072 | {
|
11073 | name: "errorCode",
|
11074 | isAttr: true,
|
11075 | type: "String"
|
11076 | }
|
11077 | ]
|
11078 | },
|
11079 | {
|
11080 | name: "CorrelationKey",
|
11081 | superClass: [
|
11082 | "BaseElement"
|
11083 | ],
|
11084 | properties: [
|
11085 | {
|
11086 | name: "correlationPropertyRef",
|
11087 | type: "CorrelationProperty",
|
11088 | isMany: true,
|
11089 | isReference: true
|
11090 | },
|
11091 | {
|
11092 | name: "name",
|
11093 | isAttr: true,
|
11094 | type: "String"
|
11095 | }
|
11096 | ]
|
11097 | },
|
11098 | {
|
11099 | name: "Expression",
|
11100 | superClass: [
|
11101 | "BaseElement"
|
11102 | ],
|
11103 | isAbstract: false,
|
11104 | properties: [
|
11105 | {
|
11106 | name: "body",
|
11107 | type: "String",
|
11108 | isBody: true
|
11109 | }
|
11110 | ]
|
11111 | },
|
11112 | {
|
11113 | name: "FormalExpression",
|
11114 | superClass: [
|
11115 | "Expression"
|
11116 | ],
|
11117 | properties: [
|
11118 | {
|
11119 | name: "language",
|
11120 | isAttr: true,
|
11121 | type: "String"
|
11122 | },
|
11123 | {
|
11124 | name: "evaluatesToTypeRef",
|
11125 | type: "ItemDefinition",
|
11126 | isAttr: true,
|
11127 | isReference: true
|
11128 | }
|
11129 | ]
|
11130 | },
|
11131 | {
|
11132 | name: "Message",
|
11133 | superClass: [
|
11134 | "RootElement"
|
11135 | ],
|
11136 | properties: [
|
11137 | {
|
11138 | name: "name",
|
11139 | isAttr: true,
|
11140 | type: "String"
|
11141 | },
|
11142 | {
|
11143 | name: "itemRef",
|
11144 | type: "ItemDefinition",
|
11145 | isAttr: true,
|
11146 | isReference: true
|
11147 | }
|
11148 | ]
|
11149 | },
|
11150 | {
|
11151 | name: "ItemDefinition",
|
11152 | superClass: [
|
11153 | "RootElement"
|
11154 | ],
|
11155 | properties: [
|
11156 | {
|
11157 | name: "itemKind",
|
11158 | type: "ItemKind",
|
11159 | isAttr: true
|
11160 | },
|
11161 | {
|
11162 | name: "structureRef",
|
11163 | type: "String",
|
11164 | isAttr: true
|
11165 | },
|
11166 | {
|
11167 | name: "isCollection",
|
11168 | "default": false,
|
11169 | isAttr: true,
|
11170 | type: "Boolean"
|
11171 | },
|
11172 | {
|
11173 | name: "import",
|
11174 | type: "Import",
|
11175 | isAttr: true,
|
11176 | isReference: true
|
11177 | }
|
11178 | ]
|
11179 | },
|
11180 | {
|
11181 | name: "FlowElement",
|
11182 | isAbstract: true,
|
11183 | superClass: [
|
11184 | "BaseElement"
|
11185 | ],
|
11186 | properties: [
|
11187 | {
|
11188 | name: "name",
|
11189 | isAttr: true,
|
11190 | type: "String"
|
11191 | },
|
11192 | {
|
11193 | name: "auditing",
|
11194 | type: "Auditing"
|
11195 | },
|
11196 | {
|
11197 | name: "monitoring",
|
11198 | type: "Monitoring"
|
11199 | },
|
11200 | {
|
11201 | name: "categoryValueRef",
|
11202 | type: "CategoryValue",
|
11203 | isMany: true,
|
11204 | isReference: true
|
11205 | }
|
11206 | ]
|
11207 | },
|
11208 | {
|
11209 | name: "SequenceFlow",
|
11210 | superClass: [
|
11211 | "FlowElement"
|
11212 | ],
|
11213 | properties: [
|
11214 | {
|
11215 | name: "isImmediate",
|
11216 | isAttr: true,
|
11217 | type: "Boolean"
|
11218 | },
|
11219 | {
|
11220 | name: "conditionExpression",
|
11221 | type: "Expression",
|
11222 | xml: {
|
11223 | serialize: "xsi:type"
|
11224 | }
|
11225 | },
|
11226 | {
|
11227 | name: "sourceRef",
|
11228 | type: "FlowNode",
|
11229 | isAttr: true,
|
11230 | isReference: true
|
11231 | },
|
11232 | {
|
11233 | name: "targetRef",
|
11234 | type: "FlowNode",
|
11235 | isAttr: true,
|
11236 | isReference: true
|
11237 | }
|
11238 | ]
|
11239 | },
|
11240 | {
|
11241 | name: "FlowElementsContainer",
|
11242 | isAbstract: true,
|
11243 | superClass: [
|
11244 | "BaseElement"
|
11245 | ],
|
11246 | properties: [
|
11247 | {
|
11248 | name: "laneSets",
|
11249 | type: "LaneSet",
|
11250 | isMany: true
|
11251 | },
|
11252 | {
|
11253 | name: "flowElements",
|
11254 | type: "FlowElement",
|
11255 | isMany: true
|
11256 | }
|
11257 | ]
|
11258 | },
|
11259 | {
|
11260 | name: "CallableElement",
|
11261 | isAbstract: true,
|
11262 | superClass: [
|
11263 | "RootElement"
|
11264 | ],
|
11265 | properties: [
|
11266 | {
|
11267 | name: "name",
|
11268 | isAttr: true,
|
11269 | type: "String"
|
11270 | },
|
11271 | {
|
11272 | name: "ioSpecification",
|
11273 | type: "InputOutputSpecification",
|
11274 | xml: {
|
11275 | serialize: "property"
|
11276 | }
|
11277 | },
|
11278 | {
|
11279 | name: "supportedInterfaceRef",
|
11280 | type: "Interface",
|
11281 | isMany: true,
|
11282 | isReference: true
|
11283 | },
|
11284 | {
|
11285 | name: "ioBinding",
|
11286 | type: "InputOutputBinding",
|
11287 | isMany: true,
|
11288 | xml: {
|
11289 | serialize: "property"
|
11290 | }
|
11291 | }
|
11292 | ]
|
11293 | },
|
11294 | {
|
11295 | name: "FlowNode",
|
11296 | isAbstract: true,
|
11297 | superClass: [
|
11298 | "FlowElement"
|
11299 | ],
|
11300 | properties: [
|
11301 | {
|
11302 | name: "incoming",
|
11303 | type: "SequenceFlow",
|
11304 | isMany: true,
|
11305 | isReference: true
|
11306 | },
|
11307 | {
|
11308 | name: "outgoing",
|
11309 | type: "SequenceFlow",
|
11310 | isMany: true,
|
11311 | isReference: true
|
11312 | },
|
11313 | {
|
11314 | name: "lanes",
|
11315 | type: "Lane",
|
11316 | isVirtual: true,
|
11317 | isMany: true,
|
11318 | isReference: true
|
11319 | }
|
11320 | ]
|
11321 | },
|
11322 | {
|
11323 | name: "CorrelationPropertyRetrievalExpression",
|
11324 | superClass: [
|
11325 | "BaseElement"
|
11326 | ],
|
11327 | properties: [
|
11328 | {
|
11329 | name: "messagePath",
|
11330 | type: "FormalExpression"
|
11331 | },
|
11332 | {
|
11333 | name: "messageRef",
|
11334 | type: "Message",
|
11335 | isAttr: true,
|
11336 | isReference: true
|
11337 | }
|
11338 | ]
|
11339 | },
|
11340 | {
|
11341 | name: "CorrelationPropertyBinding",
|
11342 | superClass: [
|
11343 | "BaseElement"
|
11344 | ],
|
11345 | properties: [
|
11346 | {
|
11347 | name: "dataPath",
|
11348 | type: "FormalExpression"
|
11349 | },
|
11350 | {
|
11351 | name: "correlationPropertyRef",
|
11352 | type: "CorrelationProperty",
|
11353 | isAttr: true,
|
11354 | isReference: true
|
11355 | }
|
11356 | ]
|
11357 | },
|
11358 | {
|
11359 | name: "Resource",
|
11360 | superClass: [
|
11361 | "RootElement"
|
11362 | ],
|
11363 | properties: [
|
11364 | {
|
11365 | name: "name",
|
11366 | isAttr: true,
|
11367 | type: "String"
|
11368 | },
|
11369 | {
|
11370 | name: "resourceParameters",
|
11371 | type: "ResourceParameter",
|
11372 | isMany: true
|
11373 | }
|
11374 | ]
|
11375 | },
|
11376 | {
|
11377 | name: "ResourceParameter",
|
11378 | superClass: [
|
11379 | "BaseElement"
|
11380 | ],
|
11381 | properties: [
|
11382 | {
|
11383 | name: "name",
|
11384 | isAttr: true,
|
11385 | type: "String"
|
11386 | },
|
11387 | {
|
11388 | name: "isRequired",
|
11389 | isAttr: true,
|
11390 | type: "Boolean"
|
11391 | },
|
11392 | {
|
11393 | name: "type",
|
11394 | type: "ItemDefinition",
|
11395 | isAttr: true,
|
11396 | isReference: true
|
11397 | }
|
11398 | ]
|
11399 | },
|
11400 | {
|
11401 | name: "CorrelationSubscription",
|
11402 | superClass: [
|
11403 | "BaseElement"
|
11404 | ],
|
11405 | properties: [
|
11406 | {
|
11407 | name: "correlationKeyRef",
|
11408 | type: "CorrelationKey",
|
11409 | isAttr: true,
|
11410 | isReference: true
|
11411 | },
|
11412 | {
|
11413 | name: "correlationPropertyBinding",
|
11414 | type: "CorrelationPropertyBinding",
|
11415 | isMany: true
|
11416 | }
|
11417 | ]
|
11418 | },
|
11419 | {
|
11420 | name: "MessageFlow",
|
11421 | superClass: [
|
11422 | "BaseElement"
|
11423 | ],
|
11424 | properties: [
|
11425 | {
|
11426 | name: "name",
|
11427 | isAttr: true,
|
11428 | type: "String"
|
11429 | },
|
11430 | {
|
11431 | name: "sourceRef",
|
11432 | type: "InteractionNode",
|
11433 | isAttr: true,
|
11434 | isReference: true
|
11435 | },
|
11436 | {
|
11437 | name: "targetRef",
|
11438 | type: "InteractionNode",
|
11439 | isAttr: true,
|
11440 | isReference: true
|
11441 | },
|
11442 | {
|
11443 | name: "messageRef",
|
11444 | type: "Message",
|
11445 | isAttr: true,
|
11446 | isReference: true
|
11447 | }
|
11448 | ]
|
11449 | },
|
11450 | {
|
11451 | name: "MessageFlowAssociation",
|
11452 | superClass: [
|
11453 | "BaseElement"
|
11454 | ],
|
11455 | properties: [
|
11456 | {
|
11457 | name: "innerMessageFlowRef",
|
11458 | type: "MessageFlow",
|
11459 | isAttr: true,
|
11460 | isReference: true
|
11461 | },
|
11462 | {
|
11463 | name: "outerMessageFlowRef",
|
11464 | type: "MessageFlow",
|
11465 | isAttr: true,
|
11466 | isReference: true
|
11467 | }
|
11468 | ]
|
11469 | },
|
11470 | {
|
11471 | name: "InteractionNode",
|
11472 | isAbstract: true,
|
11473 | properties: [
|
11474 | {
|
11475 | name: "incomingConversationLinks",
|
11476 | type: "ConversationLink",
|
11477 | isVirtual: true,
|
11478 | isMany: true,
|
11479 | isReference: true
|
11480 | },
|
11481 | {
|
11482 | name: "outgoingConversationLinks",
|
11483 | type: "ConversationLink",
|
11484 | isVirtual: true,
|
11485 | isMany: true,
|
11486 | isReference: true
|
11487 | }
|
11488 | ]
|
11489 | },
|
11490 | {
|
11491 | name: "Participant",
|
11492 | superClass: [
|
11493 | "InteractionNode",
|
11494 | "BaseElement"
|
11495 | ],
|
11496 | properties: [
|
11497 | {
|
11498 | name: "name",
|
11499 | isAttr: true,
|
11500 | type: "String"
|
11501 | },
|
11502 | {
|
11503 | name: "interfaceRef",
|
11504 | type: "Interface",
|
11505 | isMany: true,
|
11506 | isReference: true
|
11507 | },
|
11508 | {
|
11509 | name: "participantMultiplicity",
|
11510 | type: "ParticipantMultiplicity"
|
11511 | },
|
11512 | {
|
11513 | name: "endPointRefs",
|
11514 | type: "EndPoint",
|
11515 | isMany: true,
|
11516 | isReference: true
|
11517 | },
|
11518 | {
|
11519 | name: "processRef",
|
11520 | type: "Process",
|
11521 | isAttr: true,
|
11522 | isReference: true
|
11523 | }
|
11524 | ]
|
11525 | },
|
11526 | {
|
11527 | name: "ParticipantAssociation",
|
11528 | superClass: [
|
11529 | "BaseElement"
|
11530 | ],
|
11531 | properties: [
|
11532 | {
|
11533 | name: "innerParticipantRef",
|
11534 | type: "Participant",
|
11535 | isAttr: true,
|
11536 | isReference: true
|
11537 | },
|
11538 | {
|
11539 | name: "outerParticipantRef",
|
11540 | type: "Participant",
|
11541 | isAttr: true,
|
11542 | isReference: true
|
11543 | }
|
11544 | ]
|
11545 | },
|
11546 | {
|
11547 | name: "ParticipantMultiplicity",
|
11548 | properties: [
|
11549 | {
|
11550 | name: "minimum",
|
11551 | "default": 0,
|
11552 | isAttr: true,
|
11553 | type: "Integer"
|
11554 | },
|
11555 | {
|
11556 | name: "maximum",
|
11557 | "default": 1,
|
11558 | isAttr: true,
|
11559 | type: "Integer"
|
11560 | }
|
11561 | ],
|
11562 | superClass: [
|
11563 | "BaseElement"
|
11564 | ]
|
11565 | },
|
11566 | {
|
11567 | name: "Collaboration",
|
11568 | superClass: [
|
11569 | "RootElement"
|
11570 | ],
|
11571 | properties: [
|
11572 | {
|
11573 | name: "name",
|
11574 | isAttr: true,
|
11575 | type: "String"
|
11576 | },
|
11577 | {
|
11578 | name: "isClosed",
|
11579 | isAttr: true,
|
11580 | type: "Boolean"
|
11581 | },
|
11582 | {
|
11583 | name: "participants",
|
11584 | type: "Participant",
|
11585 | isMany: true
|
11586 | },
|
11587 | {
|
11588 | name: "messageFlows",
|
11589 | type: "MessageFlow",
|
11590 | isMany: true
|
11591 | },
|
11592 | {
|
11593 | name: "artifacts",
|
11594 | type: "Artifact",
|
11595 | isMany: true
|
11596 | },
|
11597 | {
|
11598 | name: "conversations",
|
11599 | type: "ConversationNode",
|
11600 | isMany: true
|
11601 | },
|
11602 | {
|
11603 | name: "conversationAssociations",
|
11604 | type: "ConversationAssociation"
|
11605 | },
|
11606 | {
|
11607 | name: "participantAssociations",
|
11608 | type: "ParticipantAssociation",
|
11609 | isMany: true
|
11610 | },
|
11611 | {
|
11612 | name: "messageFlowAssociations",
|
11613 | type: "MessageFlowAssociation",
|
11614 | isMany: true
|
11615 | },
|
11616 | {
|
11617 | name: "correlationKeys",
|
11618 | type: "CorrelationKey",
|
11619 | isMany: true
|
11620 | },
|
11621 | {
|
11622 | name: "choreographyRef",
|
11623 | type: "Choreography",
|
11624 | isMany: true,
|
11625 | isReference: true
|
11626 | },
|
11627 | {
|
11628 | name: "conversationLinks",
|
11629 | type: "ConversationLink",
|
11630 | isMany: true
|
11631 | }
|
11632 | ]
|
11633 | },
|
11634 | {
|
11635 | name: "ChoreographyActivity",
|
11636 | isAbstract: true,
|
11637 | superClass: [
|
11638 | "FlowNode"
|
11639 | ],
|
11640 | properties: [
|
11641 | {
|
11642 | name: "participantRef",
|
11643 | type: "Participant",
|
11644 | isMany: true,
|
11645 | isReference: true
|
11646 | },
|
11647 | {
|
11648 | name: "initiatingParticipantRef",
|
11649 | type: "Participant",
|
11650 | isAttr: true,
|
11651 | isReference: true
|
11652 | },
|
11653 | {
|
11654 | name: "correlationKeys",
|
11655 | type: "CorrelationKey",
|
11656 | isMany: true
|
11657 | },
|
11658 | {
|
11659 | name: "loopType",
|
11660 | type: "ChoreographyLoopType",
|
11661 | "default": "None",
|
11662 | isAttr: true
|
11663 | }
|
11664 | ]
|
11665 | },
|
11666 | {
|
11667 | name: "CallChoreography",
|
11668 | superClass: [
|
11669 | "ChoreographyActivity"
|
11670 | ],
|
11671 | properties: [
|
11672 | {
|
11673 | name: "calledChoreographyRef",
|
11674 | type: "Choreography",
|
11675 | isAttr: true,
|
11676 | isReference: true
|
11677 | },
|
11678 | {
|
11679 | name: "participantAssociations",
|
11680 | type: "ParticipantAssociation",
|
11681 | isMany: true
|
11682 | }
|
11683 | ]
|
11684 | },
|
11685 | {
|
11686 | name: "SubChoreography",
|
11687 | superClass: [
|
11688 | "ChoreographyActivity",
|
11689 | "FlowElementsContainer"
|
11690 | ],
|
11691 | properties: [
|
11692 | {
|
11693 | name: "artifacts",
|
11694 | type: "Artifact",
|
11695 | isMany: true
|
11696 | }
|
11697 | ]
|
11698 | },
|
11699 | {
|
11700 | name: "ChoreographyTask",
|
11701 | superClass: [
|
11702 | "ChoreographyActivity"
|
11703 | ],
|
11704 | properties: [
|
11705 | {
|
11706 | name: "messageFlowRef",
|
11707 | type: "MessageFlow",
|
11708 | isMany: true,
|
11709 | isReference: true
|
11710 | }
|
11711 | ]
|
11712 | },
|
11713 | {
|
11714 | name: "Choreography",
|
11715 | superClass: [
|
11716 | "Collaboration",
|
11717 | "FlowElementsContainer"
|
11718 | ]
|
11719 | },
|
11720 | {
|
11721 | name: "GlobalChoreographyTask",
|
11722 | superClass: [
|
11723 | "Choreography"
|
11724 | ],
|
11725 | properties: [
|
11726 | {
|
11727 | name: "initiatingParticipantRef",
|
11728 | type: "Participant",
|
11729 | isAttr: true,
|
11730 | isReference: true
|
11731 | }
|
11732 | ]
|
11733 | },
|
11734 | {
|
11735 | name: "TextAnnotation",
|
11736 | superClass: [
|
11737 | "Artifact"
|
11738 | ],
|
11739 | properties: [
|
11740 | {
|
11741 | name: "text",
|
11742 | type: "String"
|
11743 | },
|
11744 | {
|
11745 | name: "textFormat",
|
11746 | "default": "text/plain",
|
11747 | isAttr: true,
|
11748 | type: "String"
|
11749 | }
|
11750 | ]
|
11751 | },
|
11752 | {
|
11753 | name: "Group",
|
11754 | superClass: [
|
11755 | "Artifact"
|
11756 | ],
|
11757 | properties: [
|
11758 | {
|
11759 | name: "categoryValueRef",
|
11760 | type: "CategoryValue",
|
11761 | isAttr: true,
|
11762 | isReference: true
|
11763 | }
|
11764 | ]
|
11765 | },
|
11766 | {
|
11767 | name: "Association",
|
11768 | superClass: [
|
11769 | "Artifact"
|
11770 | ],
|
11771 | properties: [
|
11772 | {
|
11773 | name: "associationDirection",
|
11774 | type: "AssociationDirection",
|
11775 | isAttr: true
|
11776 | },
|
11777 | {
|
11778 | name: "sourceRef",
|
11779 | type: "BaseElement",
|
11780 | isAttr: true,
|
11781 | isReference: true
|
11782 | },
|
11783 | {
|
11784 | name: "targetRef",
|
11785 | type: "BaseElement",
|
11786 | isAttr: true,
|
11787 | isReference: true
|
11788 | }
|
11789 | ]
|
11790 | },
|
11791 | {
|
11792 | name: "Category",
|
11793 | superClass: [
|
11794 | "RootElement"
|
11795 | ],
|
11796 | properties: [
|
11797 | {
|
11798 | name: "categoryValue",
|
11799 | type: "CategoryValue",
|
11800 | isMany: true
|
11801 | },
|
11802 | {
|
11803 | name: "name",
|
11804 | isAttr: true,
|
11805 | type: "String"
|
11806 | }
|
11807 | ]
|
11808 | },
|
11809 | {
|
11810 | name: "Artifact",
|
11811 | isAbstract: true,
|
11812 | superClass: [
|
11813 | "BaseElement"
|
11814 | ]
|
11815 | },
|
11816 | {
|
11817 | name: "CategoryValue",
|
11818 | superClass: [
|
11819 | "BaseElement"
|
11820 | ],
|
11821 | properties: [
|
11822 | {
|
11823 | name: "categorizedFlowElements",
|
11824 | type: "FlowElement",
|
11825 | isVirtual: true,
|
11826 | isMany: true,
|
11827 | isReference: true
|
11828 | },
|
11829 | {
|
11830 | name: "value",
|
11831 | isAttr: true,
|
11832 | type: "String"
|
11833 | }
|
11834 | ]
|
11835 | },
|
11836 | {
|
11837 | name: "Activity",
|
11838 | isAbstract: true,
|
11839 | superClass: [
|
11840 | "FlowNode"
|
11841 | ],
|
11842 | properties: [
|
11843 | {
|
11844 | name: "isForCompensation",
|
11845 | "default": false,
|
11846 | isAttr: true,
|
11847 | type: "Boolean"
|
11848 | },
|
11849 | {
|
11850 | name: "default",
|
11851 | type: "SequenceFlow",
|
11852 | isAttr: true,
|
11853 | isReference: true
|
11854 | },
|
11855 | {
|
11856 | name: "ioSpecification",
|
11857 | type: "InputOutputSpecification",
|
11858 | xml: {
|
11859 | serialize: "property"
|
11860 | }
|
11861 | },
|
11862 | {
|
11863 | name: "boundaryEventRefs",
|
11864 | type: "BoundaryEvent",
|
11865 | isMany: true,
|
11866 | isReference: true
|
11867 | },
|
11868 | {
|
11869 | name: "properties",
|
11870 | type: "Property",
|
11871 | isMany: true
|
11872 | },
|
11873 | {
|
11874 | name: "dataInputAssociations",
|
11875 | type: "DataInputAssociation",
|
11876 | isMany: true
|
11877 | },
|
11878 | {
|
11879 | name: "dataOutputAssociations",
|
11880 | type: "DataOutputAssociation",
|
11881 | isMany: true
|
11882 | },
|
11883 | {
|
11884 | name: "startQuantity",
|
11885 | "default": 1,
|
11886 | isAttr: true,
|
11887 | type: "Integer"
|
11888 | },
|
11889 | {
|
11890 | name: "resources",
|
11891 | type: "ResourceRole",
|
11892 | isMany: true
|
11893 | },
|
11894 | {
|
11895 | name: "completionQuantity",
|
11896 | "default": 1,
|
11897 | isAttr: true,
|
11898 | type: "Integer"
|
11899 | },
|
11900 | {
|
11901 | name: "loopCharacteristics",
|
11902 | type: "LoopCharacteristics"
|
11903 | }
|
11904 | ]
|
11905 | },
|
11906 | {
|
11907 | name: "ServiceTask",
|
11908 | superClass: [
|
11909 | "Task"
|
11910 | ],
|
11911 | properties: [
|
11912 | {
|
11913 | name: "implementation",
|
11914 | isAttr: true,
|
11915 | type: "String"
|
11916 | },
|
11917 | {
|
11918 | name: "operationRef",
|
11919 | type: "Operation",
|
11920 | isAttr: true,
|
11921 | isReference: true
|
11922 | }
|
11923 | ]
|
11924 | },
|
11925 | {
|
11926 | name: "SubProcess",
|
11927 | superClass: [
|
11928 | "Activity",
|
11929 | "FlowElementsContainer",
|
11930 | "InteractionNode"
|
11931 | ],
|
11932 | properties: [
|
11933 | {
|
11934 | name: "triggeredByEvent",
|
11935 | "default": false,
|
11936 | isAttr: true,
|
11937 | type: "Boolean"
|
11938 | },
|
11939 | {
|
11940 | name: "artifacts",
|
11941 | type: "Artifact",
|
11942 | isMany: true
|
11943 | }
|
11944 | ]
|
11945 | },
|
11946 | {
|
11947 | name: "LoopCharacteristics",
|
11948 | isAbstract: true,
|
11949 | superClass: [
|
11950 | "BaseElement"
|
11951 | ]
|
11952 | },
|
11953 | {
|
11954 | name: "MultiInstanceLoopCharacteristics",
|
11955 | superClass: [
|
11956 | "LoopCharacteristics"
|
11957 | ],
|
11958 | properties: [
|
11959 | {
|
11960 | name: "isSequential",
|
11961 | "default": false,
|
11962 | isAttr: true,
|
11963 | type: "Boolean"
|
11964 | },
|
11965 | {
|
11966 | name: "behavior",
|
11967 | type: "MultiInstanceBehavior",
|
11968 | "default": "All",
|
11969 | isAttr: true
|
11970 | },
|
11971 | {
|
11972 | name: "loopCardinality",
|
11973 | type: "Expression",
|
11974 | xml: {
|
11975 | serialize: "xsi:type"
|
11976 | }
|
11977 | },
|
11978 | {
|
11979 | name: "loopDataInputRef",
|
11980 | type: "ItemAwareElement",
|
11981 | isReference: true
|
11982 | },
|
11983 | {
|
11984 | name: "loopDataOutputRef",
|
11985 | type: "ItemAwareElement",
|
11986 | isReference: true
|
11987 | },
|
11988 | {
|
11989 | name: "inputDataItem",
|
11990 | type: "DataInput",
|
11991 | xml: {
|
11992 | serialize: "property"
|
11993 | }
|
11994 | },
|
11995 | {
|
11996 | name: "outputDataItem",
|
11997 | type: "DataOutput",
|
11998 | xml: {
|
11999 | serialize: "property"
|
12000 | }
|
12001 | },
|
12002 | {
|
12003 | name: "complexBehaviorDefinition",
|
12004 | type: "ComplexBehaviorDefinition",
|
12005 | isMany: true
|
12006 | },
|
12007 | {
|
12008 | name: "completionCondition",
|
12009 | type: "Expression",
|
12010 | xml: {
|
12011 | serialize: "xsi:type"
|
12012 | }
|
12013 | },
|
12014 | {
|
12015 | name: "oneBehaviorEventRef",
|
12016 | type: "EventDefinition",
|
12017 | isAttr: true,
|
12018 | isReference: true
|
12019 | },
|
12020 | {
|
12021 | name: "noneBehaviorEventRef",
|
12022 | type: "EventDefinition",
|
12023 | isAttr: true,
|
12024 | isReference: true
|
12025 | }
|
12026 | ]
|
12027 | },
|
12028 | {
|
12029 | name: "StandardLoopCharacteristics",
|
12030 | superClass: [
|
12031 | "LoopCharacteristics"
|
12032 | ],
|
12033 | properties: [
|
12034 | {
|
12035 | name: "testBefore",
|
12036 | "default": false,
|
12037 | isAttr: true,
|
12038 | type: "Boolean"
|
12039 | },
|
12040 | {
|
12041 | name: "loopCondition",
|
12042 | type: "Expression",
|
12043 | xml: {
|
12044 | serialize: "xsi:type"
|
12045 | }
|
12046 | },
|
12047 | {
|
12048 | name: "loopMaximum",
|
12049 | type: "Integer",
|
12050 | isAttr: true
|
12051 | }
|
12052 | ]
|
12053 | },
|
12054 | {
|
12055 | name: "CallActivity",
|
12056 | superClass: [
|
12057 | "Activity"
|
12058 | ],
|
12059 | properties: [
|
12060 | {
|
12061 | name: "calledElement",
|
12062 | type: "String",
|
12063 | isAttr: true
|
12064 | }
|
12065 | ]
|
12066 | },
|
12067 | {
|
12068 | name: "Task",
|
12069 | superClass: [
|
12070 | "Activity",
|
12071 | "InteractionNode"
|
12072 | ]
|
12073 | },
|
12074 | {
|
12075 | name: "SendTask",
|
12076 | superClass: [
|
12077 | "Task"
|
12078 | ],
|
12079 | properties: [
|
12080 | {
|
12081 | name: "implementation",
|
12082 | isAttr: true,
|
12083 | type: "String"
|
12084 | },
|
12085 | {
|
12086 | name: "operationRef",
|
12087 | type: "Operation",
|
12088 | isAttr: true,
|
12089 | isReference: true
|
12090 | },
|
12091 | {
|
12092 | name: "messageRef",
|
12093 | type: "Message",
|
12094 | isAttr: true,
|
12095 | isReference: true
|
12096 | }
|
12097 | ]
|
12098 | },
|
12099 | {
|
12100 | name: "ReceiveTask",
|
12101 | superClass: [
|
12102 | "Task"
|
12103 | ],
|
12104 | properties: [
|
12105 | {
|
12106 | name: "implementation",
|
12107 | isAttr: true,
|
12108 | type: "String"
|
12109 | },
|
12110 | {
|
12111 | name: "instantiate",
|
12112 | "default": false,
|
12113 | isAttr: true,
|
12114 | type: "Boolean"
|
12115 | },
|
12116 | {
|
12117 | name: "operationRef",
|
12118 | type: "Operation",
|
12119 | isAttr: true,
|
12120 | isReference: true
|
12121 | },
|
12122 | {
|
12123 | name: "messageRef",
|
12124 | type: "Message",
|
12125 | isAttr: true,
|
12126 | isReference: true
|
12127 | }
|
12128 | ]
|
12129 | },
|
12130 | {
|
12131 | name: "ScriptTask",
|
12132 | superClass: [
|
12133 | "Task"
|
12134 | ],
|
12135 | properties: [
|
12136 | {
|
12137 | name: "scriptFormat",
|
12138 | isAttr: true,
|
12139 | type: "String"
|
12140 | },
|
12141 | {
|
12142 | name: "script",
|
12143 | type: "String"
|
12144 | }
|
12145 | ]
|
12146 | },
|
12147 | {
|
12148 | name: "BusinessRuleTask",
|
12149 | superClass: [
|
12150 | "Task"
|
12151 | ],
|
12152 | properties: [
|
12153 | {
|
12154 | name: "implementation",
|
12155 | isAttr: true,
|
12156 | type: "String"
|
12157 | }
|
12158 | ]
|
12159 | },
|
12160 | {
|
12161 | name: "AdHocSubProcess",
|
12162 | superClass: [
|
12163 | "SubProcess"
|
12164 | ],
|
12165 | properties: [
|
12166 | {
|
12167 | name: "completionCondition",
|
12168 | type: "Expression",
|
12169 | xml: {
|
12170 | serialize: "xsi:type"
|
12171 | }
|
12172 | },
|
12173 | {
|
12174 | name: "ordering",
|
12175 | type: "AdHocOrdering",
|
12176 | isAttr: true
|
12177 | },
|
12178 | {
|
12179 | name: "cancelRemainingInstances",
|
12180 | "default": true,
|
12181 | isAttr: true,
|
12182 | type: "Boolean"
|
12183 | }
|
12184 | ]
|
12185 | },
|
12186 | {
|
12187 | name: "Transaction",
|
12188 | superClass: [
|
12189 | "SubProcess"
|
12190 | ],
|
12191 | properties: [
|
12192 | {
|
12193 | name: "protocol",
|
12194 | isAttr: true,
|
12195 | type: "String"
|
12196 | },
|
12197 | {
|
12198 | name: "method",
|
12199 | isAttr: true,
|
12200 | type: "String"
|
12201 | }
|
12202 | ]
|
12203 | },
|
12204 | {
|
12205 | name: "GlobalScriptTask",
|
12206 | superClass: [
|
12207 | "GlobalTask"
|
12208 | ],
|
12209 | properties: [
|
12210 | {
|
12211 | name: "scriptLanguage",
|
12212 | isAttr: true,
|
12213 | type: "String"
|
12214 | },
|
12215 | {
|
12216 | name: "script",
|
12217 | isAttr: true,
|
12218 | type: "String"
|
12219 | }
|
12220 | ]
|
12221 | },
|
12222 | {
|
12223 | name: "GlobalBusinessRuleTask",
|
12224 | superClass: [
|
12225 | "GlobalTask"
|
12226 | ],
|
12227 | properties: [
|
12228 | {
|
12229 | name: "implementation",
|
12230 | isAttr: true,
|
12231 | type: "String"
|
12232 | }
|
12233 | ]
|
12234 | },
|
12235 | {
|
12236 | name: "ComplexBehaviorDefinition",
|
12237 | superClass: [
|
12238 | "BaseElement"
|
12239 | ],
|
12240 | properties: [
|
12241 | {
|
12242 | name: "condition",
|
12243 | type: "FormalExpression"
|
12244 | },
|
12245 | {
|
12246 | name: "event",
|
12247 | type: "ImplicitThrowEvent"
|
12248 | }
|
12249 | ]
|
12250 | },
|
12251 | {
|
12252 | name: "ResourceRole",
|
12253 | superClass: [
|
12254 | "BaseElement"
|
12255 | ],
|
12256 | properties: [
|
12257 | {
|
12258 | name: "resourceRef",
|
12259 | type: "Resource",
|
12260 | isReference: true
|
12261 | },
|
12262 | {
|
12263 | name: "resourceParameterBindings",
|
12264 | type: "ResourceParameterBinding",
|
12265 | isMany: true
|
12266 | },
|
12267 | {
|
12268 | name: "resourceAssignmentExpression",
|
12269 | type: "ResourceAssignmentExpression"
|
12270 | },
|
12271 | {
|
12272 | name: "name",
|
12273 | isAttr: true,
|
12274 | type: "String"
|
12275 | }
|
12276 | ]
|
12277 | },
|
12278 | {
|
12279 | name: "ResourceParameterBinding",
|
12280 | properties: [
|
12281 | {
|
12282 | name: "expression",
|
12283 | type: "Expression",
|
12284 | xml: {
|
12285 | serialize: "xsi:type"
|
12286 | }
|
12287 | },
|
12288 | {
|
12289 | name: "parameterRef",
|
12290 | type: "ResourceParameter",
|
12291 | isAttr: true,
|
12292 | isReference: true
|
12293 | }
|
12294 | ],
|
12295 | superClass: [
|
12296 | "BaseElement"
|
12297 | ]
|
12298 | },
|
12299 | {
|
12300 | name: "ResourceAssignmentExpression",
|
12301 | properties: [
|
12302 | {
|
12303 | name: "expression",
|
12304 | type: "Expression",
|
12305 | xml: {
|
12306 | serialize: "xsi:type"
|
12307 | }
|
12308 | }
|
12309 | ],
|
12310 | superClass: [
|
12311 | "BaseElement"
|
12312 | ]
|
12313 | },
|
12314 | {
|
12315 | name: "Import",
|
12316 | properties: [
|
12317 | {
|
12318 | name: "importType",
|
12319 | isAttr: true,
|
12320 | type: "String"
|
12321 | },
|
12322 | {
|
12323 | name: "location",
|
12324 | isAttr: true,
|
12325 | type: "String"
|
12326 | },
|
12327 | {
|
12328 | name: "namespace",
|
12329 | isAttr: true,
|
12330 | type: "String"
|
12331 | }
|
12332 | ]
|
12333 | },
|
12334 | {
|
12335 | name: "Definitions",
|
12336 | superClass: [
|
12337 | "BaseElement"
|
12338 | ],
|
12339 | properties: [
|
12340 | {
|
12341 | name: "name",
|
12342 | isAttr: true,
|
12343 | type: "String"
|
12344 | },
|
12345 | {
|
12346 | name: "targetNamespace",
|
12347 | isAttr: true,
|
12348 | type: "String"
|
12349 | },
|
12350 | {
|
12351 | name: "expressionLanguage",
|
12352 | "default": "http://www.w3.org/1999/XPath",
|
12353 | isAttr: true,
|
12354 | type: "String"
|
12355 | },
|
12356 | {
|
12357 | name: "typeLanguage",
|
12358 | "default": "http://www.w3.org/2001/XMLSchema",
|
12359 | isAttr: true,
|
12360 | type: "String"
|
12361 | },
|
12362 | {
|
12363 | name: "imports",
|
12364 | type: "Import",
|
12365 | isMany: true
|
12366 | },
|
12367 | {
|
12368 | name: "extensions",
|
12369 | type: "Extension",
|
12370 | isMany: true
|
12371 | },
|
12372 | {
|
12373 | name: "rootElements",
|
12374 | type: "RootElement",
|
12375 | isMany: true
|
12376 | },
|
12377 | {
|
12378 | name: "diagrams",
|
12379 | isMany: true,
|
12380 | type: "bpmndi:BPMNDiagram"
|
12381 | },
|
12382 | {
|
12383 | name: "exporter",
|
12384 | isAttr: true,
|
12385 | type: "String"
|
12386 | },
|
12387 | {
|
12388 | name: "relationships",
|
12389 | type: "Relationship",
|
12390 | isMany: true
|
12391 | },
|
12392 | {
|
12393 | name: "exporterVersion",
|
12394 | isAttr: true,
|
12395 | type: "String"
|
12396 | }
|
12397 | ]
|
12398 | }
|
12399 | ];
|
12400 | var enumerations = [
|
12401 | {
|
12402 | name: "ProcessType",
|
12403 | literalValues: [
|
12404 | {
|
12405 | name: "None"
|
12406 | },
|
12407 | {
|
12408 | name: "Public"
|
12409 | },
|
12410 | {
|
12411 | name: "Private"
|
12412 | }
|
12413 | ]
|
12414 | },
|
12415 | {
|
12416 | name: "GatewayDirection",
|
12417 | literalValues: [
|
12418 | {
|
12419 | name: "Unspecified"
|
12420 | },
|
12421 | {
|
12422 | name: "Converging"
|
12423 | },
|
12424 | {
|
12425 | name: "Diverging"
|
12426 | },
|
12427 | {
|
12428 | name: "Mixed"
|
12429 | }
|
12430 | ]
|
12431 | },
|
12432 | {
|
12433 | name: "EventBasedGatewayType",
|
12434 | literalValues: [
|
12435 | {
|
12436 | name: "Parallel"
|
12437 | },
|
12438 | {
|
12439 | name: "Exclusive"
|
12440 | }
|
12441 | ]
|
12442 | },
|
12443 | {
|
12444 | name: "RelationshipDirection",
|
12445 | literalValues: [
|
12446 | {
|
12447 | name: "None"
|
12448 | },
|
12449 | {
|
12450 | name: "Forward"
|
12451 | },
|
12452 | {
|
12453 | name: "Backward"
|
12454 | },
|
12455 | {
|
12456 | name: "Both"
|
12457 | }
|
12458 | ]
|
12459 | },
|
12460 | {
|
12461 | name: "ItemKind",
|
12462 | literalValues: [
|
12463 | {
|
12464 | name: "Physical"
|
12465 | },
|
12466 | {
|
12467 | name: "Information"
|
12468 | }
|
12469 | ]
|
12470 | },
|
12471 | {
|
12472 | name: "ChoreographyLoopType",
|
12473 | literalValues: [
|
12474 | {
|
12475 | name: "None"
|
12476 | },
|
12477 | {
|
12478 | name: "Standard"
|
12479 | },
|
12480 | {
|
12481 | name: "MultiInstanceSequential"
|
12482 | },
|
12483 | {
|
12484 | name: "MultiInstanceParallel"
|
12485 | }
|
12486 | ]
|
12487 | },
|
12488 | {
|
12489 | name: "AssociationDirection",
|
12490 | literalValues: [
|
12491 | {
|
12492 | name: "None"
|
12493 | },
|
12494 | {
|
12495 | name: "One"
|
12496 | },
|
12497 | {
|
12498 | name: "Both"
|
12499 | }
|
12500 | ]
|
12501 | },
|
12502 | {
|
12503 | name: "MultiInstanceBehavior",
|
12504 | literalValues: [
|
12505 | {
|
12506 | name: "None"
|
12507 | },
|
12508 | {
|
12509 | name: "One"
|
12510 | },
|
12511 | {
|
12512 | name: "All"
|
12513 | },
|
12514 | {
|
12515 | name: "Complex"
|
12516 | }
|
12517 | ]
|
12518 | },
|
12519 | {
|
12520 | name: "AdHocOrdering",
|
12521 | literalValues: [
|
12522 | {
|
12523 | name: "Parallel"
|
12524 | },
|
12525 | {
|
12526 | name: "Sequential"
|
12527 | }
|
12528 | ]
|
12529 | }
|
12530 | ];
|
12531 | var prefix$1 = "bpmn";
|
12532 | var xml = {
|
12533 | tagAlias: "lowerCase",
|
12534 | typePrefix: "t"
|
12535 | };
|
12536 | var BpmnPackage = {
|
12537 | name: name,
|
12538 | uri: uri,
|
12539 | associations: associations,
|
12540 | types: types$1,
|
12541 | enumerations: enumerations,
|
12542 | prefix: prefix$1,
|
12543 | xml: xml
|
12544 | };
|
12545 |
|
12546 | var name$1 = "BPMNDI";
|
12547 | var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
|
12548 | var types$2 = [
|
12549 | {
|
12550 | name: "BPMNDiagram",
|
12551 | properties: [
|
12552 | {
|
12553 | name: "plane",
|
12554 | type: "BPMNPlane",
|
12555 | redefines: "di:Diagram#rootElement"
|
12556 | },
|
12557 | {
|
12558 | name: "labelStyle",
|
12559 | type: "BPMNLabelStyle",
|
12560 | isMany: true
|
12561 | }
|
12562 | ],
|
12563 | superClass: [
|
12564 | "di:Diagram"
|
12565 | ]
|
12566 | },
|
12567 | {
|
12568 | name: "BPMNPlane",
|
12569 | properties: [
|
12570 | {
|
12571 | name: "bpmnElement",
|
12572 | isAttr: true,
|
12573 | isReference: true,
|
12574 | type: "bpmn:BaseElement",
|
12575 | redefines: "di:DiagramElement#modelElement"
|
12576 | }
|
12577 | ],
|
12578 | superClass: [
|
12579 | "di:Plane"
|
12580 | ]
|
12581 | },
|
12582 | {
|
12583 | name: "BPMNShape",
|
12584 | properties: [
|
12585 | {
|
12586 | name: "bpmnElement",
|
12587 | isAttr: true,
|
12588 | isReference: true,
|
12589 | type: "bpmn:BaseElement",
|
12590 | redefines: "di:DiagramElement#modelElement"
|
12591 | },
|
12592 | {
|
12593 | name: "isHorizontal",
|
12594 | isAttr: true,
|
12595 | type: "Boolean"
|
12596 | },
|
12597 | {
|
12598 | name: "isExpanded",
|
12599 | isAttr: true,
|
12600 | type: "Boolean"
|
12601 | },
|
12602 | {
|
12603 | name: "isMarkerVisible",
|
12604 | isAttr: true,
|
12605 | type: "Boolean"
|
12606 | },
|
12607 | {
|
12608 | name: "label",
|
12609 | type: "BPMNLabel"
|
12610 | },
|
12611 | {
|
12612 | name: "isMessageVisible",
|
12613 | isAttr: true,
|
12614 | type: "Boolean"
|
12615 | },
|
12616 | {
|
12617 | name: "participantBandKind",
|
12618 | type: "ParticipantBandKind",
|
12619 | isAttr: true
|
12620 | },
|
12621 | {
|
12622 | name: "choreographyActivityShape",
|
12623 | type: "BPMNShape",
|
12624 | isAttr: true,
|
12625 | isReference: true
|
12626 | }
|
12627 | ],
|
12628 | superClass: [
|
12629 | "di:LabeledShape"
|
12630 | ]
|
12631 | },
|
12632 | {
|
12633 | name: "BPMNEdge",
|
12634 | properties: [
|
12635 | {
|
12636 | name: "label",
|
12637 | type: "BPMNLabel"
|
12638 | },
|
12639 | {
|
12640 | name: "bpmnElement",
|
12641 | isAttr: true,
|
12642 | isReference: true,
|
12643 | type: "bpmn:BaseElement",
|
12644 | redefines: "di:DiagramElement#modelElement"
|
12645 | },
|
12646 | {
|
12647 | name: "sourceElement",
|
12648 | isAttr: true,
|
12649 | isReference: true,
|
12650 | type: "di:DiagramElement",
|
12651 | redefines: "di:Edge#source"
|
12652 | },
|
12653 | {
|
12654 | name: "targetElement",
|
12655 | isAttr: true,
|
12656 | isReference: true,
|
12657 | type: "di:DiagramElement",
|
12658 | redefines: "di:Edge#target"
|
12659 | },
|
12660 | {
|
12661 | name: "messageVisibleKind",
|
12662 | type: "MessageVisibleKind",
|
12663 | isAttr: true,
|
12664 | "default": "initiating"
|
12665 | }
|
12666 | ],
|
12667 | superClass: [
|
12668 | "di:LabeledEdge"
|
12669 | ]
|
12670 | },
|
12671 | {
|
12672 | name: "BPMNLabel",
|
12673 | properties: [
|
12674 | {
|
12675 | name: "labelStyle",
|
12676 | type: "BPMNLabelStyle",
|
12677 | isAttr: true,
|
12678 | isReference: true,
|
12679 | redefines: "di:DiagramElement#style"
|
12680 | }
|
12681 | ],
|
12682 | superClass: [
|
12683 | "di:Label"
|
12684 | ]
|
12685 | },
|
12686 | {
|
12687 | name: "BPMNLabelStyle",
|
12688 | properties: [
|
12689 | {
|
12690 | name: "font",
|
12691 | type: "dc:Font"
|
12692 | }
|
12693 | ],
|
12694 | superClass: [
|
12695 | "di:Style"
|
12696 | ]
|
12697 | }
|
12698 | ];
|
12699 | var enumerations$1 = [
|
12700 | {
|
12701 | name: "ParticipantBandKind",
|
12702 | literalValues: [
|
12703 | {
|
12704 | name: "top_initiating"
|
12705 | },
|
12706 | {
|
12707 | name: "middle_initiating"
|
12708 | },
|
12709 | {
|
12710 | name: "bottom_initiating"
|
12711 | },
|
12712 | {
|
12713 | name: "top_non_initiating"
|
12714 | },
|
12715 | {
|
12716 | name: "middle_non_initiating"
|
12717 | },
|
12718 | {
|
12719 | name: "bottom_non_initiating"
|
12720 | }
|
12721 | ]
|
12722 | },
|
12723 | {
|
12724 | name: "MessageVisibleKind",
|
12725 | literalValues: [
|
12726 | {
|
12727 | name: "initiating"
|
12728 | },
|
12729 | {
|
12730 | name: "non_initiating"
|
12731 | }
|
12732 | ]
|
12733 | }
|
12734 | ];
|
12735 | var associations$1 = [
|
12736 | ];
|
12737 | var prefix$2 = "bpmndi";
|
12738 | var BpmnDiPackage = {
|
12739 | name: name$1,
|
12740 | uri: uri$1,
|
12741 | types: types$2,
|
12742 | enumerations: enumerations$1,
|
12743 | associations: associations$1,
|
12744 | prefix: prefix$2
|
12745 | };
|
12746 |
|
12747 | var name$2 = "DC";
|
12748 | var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
|
12749 | var types$3 = [
|
12750 | {
|
12751 | name: "Boolean"
|
12752 | },
|
12753 | {
|
12754 | name: "Integer"
|
12755 | },
|
12756 | {
|
12757 | name: "Real"
|
12758 | },
|
12759 | {
|
12760 | name: "String"
|
12761 | },
|
12762 | {
|
12763 | name: "Font",
|
12764 | properties: [
|
12765 | {
|
12766 | name: "name",
|
12767 | type: "String",
|
12768 | isAttr: true
|
12769 | },
|
12770 | {
|
12771 | name: "size",
|
12772 | type: "Real",
|
12773 | isAttr: true
|
12774 | },
|
12775 | {
|
12776 | name: "isBold",
|
12777 | type: "Boolean",
|
12778 | isAttr: true
|
12779 | },
|
12780 | {
|
12781 | name: "isItalic",
|
12782 | type: "Boolean",
|
12783 | isAttr: true
|
12784 | },
|
12785 | {
|
12786 | name: "isUnderline",
|
12787 | type: "Boolean",
|
12788 | isAttr: true
|
12789 | },
|
12790 | {
|
12791 | name: "isStrikeThrough",
|
12792 | type: "Boolean",
|
12793 | isAttr: true
|
12794 | }
|
12795 | ]
|
12796 | },
|
12797 | {
|
12798 | name: "Point",
|
12799 | properties: [
|
12800 | {
|
12801 | name: "x",
|
12802 | type: "Real",
|
12803 | "default": "0",
|
12804 | isAttr: true
|
12805 | },
|
12806 | {
|
12807 | name: "y",
|
12808 | type: "Real",
|
12809 | "default": "0",
|
12810 | isAttr: true
|
12811 | }
|
12812 | ]
|
12813 | },
|
12814 | {
|
12815 | name: "Bounds",
|
12816 | properties: [
|
12817 | {
|
12818 | name: "x",
|
12819 | type: "Real",
|
12820 | "default": "0",
|
12821 | isAttr: true
|
12822 | },
|
12823 | {
|
12824 | name: "y",
|
12825 | type: "Real",
|
12826 | "default": "0",
|
12827 | isAttr: true
|
12828 | },
|
12829 | {
|
12830 | name: "width",
|
12831 | type: "Real",
|
12832 | isAttr: true
|
12833 | },
|
12834 | {
|
12835 | name: "height",
|
12836 | type: "Real",
|
12837 | isAttr: true
|
12838 | }
|
12839 | ]
|
12840 | }
|
12841 | ];
|
12842 | var prefix$3 = "dc";
|
12843 | var associations$2 = [
|
12844 | ];
|
12845 | var DcPackage = {
|
12846 | name: name$2,
|
12847 | uri: uri$2,
|
12848 | types: types$3,
|
12849 | prefix: prefix$3,
|
12850 | associations: associations$2
|
12851 | };
|
12852 |
|
12853 | var name$3 = "DI";
|
12854 | var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
|
12855 | var types$4 = [
|
12856 | {
|
12857 | name: "DiagramElement",
|
12858 | isAbstract: true,
|
12859 | properties: [
|
12860 | {
|
12861 | name: "id",
|
12862 | type: "String",
|
12863 | isAttr: true,
|
12864 | isId: true
|
12865 | },
|
12866 | {
|
12867 | name: "extension",
|
12868 | type: "Extension"
|
12869 | },
|
12870 | {
|
12871 | name: "owningDiagram",
|
12872 | type: "Diagram",
|
12873 | isReadOnly: true,
|
12874 | isVirtual: true,
|
12875 | isReference: true
|
12876 | },
|
12877 | {
|
12878 | name: "owningElement",
|
12879 | type: "DiagramElement",
|
12880 | isReadOnly: true,
|
12881 | isVirtual: true,
|
12882 | isReference: true
|
12883 | },
|
12884 | {
|
12885 | name: "modelElement",
|
12886 | isReadOnly: true,
|
12887 | isVirtual: true,
|
12888 | isReference: true,
|
12889 | type: "Element"
|
12890 | },
|
12891 | {
|
12892 | name: "style",
|
12893 | type: "Style",
|
12894 | isReadOnly: true,
|
12895 | isVirtual: true,
|
12896 | isReference: true
|
12897 | },
|
12898 | {
|
12899 | name: "ownedElement",
|
12900 | type: "DiagramElement",
|
12901 | isReadOnly: true,
|
12902 | isVirtual: true,
|
12903 | isMany: true
|
12904 | }
|
12905 | ]
|
12906 | },
|
12907 | {
|
12908 | name: "Node",
|
12909 | isAbstract: true,
|
12910 | superClass: [
|
12911 | "DiagramElement"
|
12912 | ]
|
12913 | },
|
12914 | {
|
12915 | name: "Edge",
|
12916 | isAbstract: true,
|
12917 | superClass: [
|
12918 | "DiagramElement"
|
12919 | ],
|
12920 | properties: [
|
12921 | {
|
12922 | name: "source",
|
12923 | type: "DiagramElement",
|
12924 | isReadOnly: true,
|
12925 | isVirtual: true,
|
12926 | isReference: true
|
12927 | },
|
12928 | {
|
12929 | name: "target",
|
12930 | type: "DiagramElement",
|
12931 | isReadOnly: true,
|
12932 | isVirtual: true,
|
12933 | isReference: true
|
12934 | },
|
12935 | {
|
12936 | name: "waypoint",
|
12937 | isUnique: false,
|
12938 | isMany: true,
|
12939 | type: "dc:Point",
|
12940 | xml: {
|
12941 | serialize: "xsi:type"
|
12942 | }
|
12943 | }
|
12944 | ]
|
12945 | },
|
12946 | {
|
12947 | name: "Diagram",
|
12948 | isAbstract: true,
|
12949 | properties: [
|
12950 | {
|
12951 | name: "id",
|
12952 | type: "String",
|
12953 | isAttr: true,
|
12954 | isId: true
|
12955 | },
|
12956 | {
|
12957 | name: "rootElement",
|
12958 | type: "DiagramElement",
|
12959 | isReadOnly: true,
|
12960 | isVirtual: true
|
12961 | },
|
12962 | {
|
12963 | name: "name",
|
12964 | isAttr: true,
|
12965 | type: "String"
|
12966 | },
|
12967 | {
|
12968 | name: "documentation",
|
12969 | isAttr: true,
|
12970 | type: "String"
|
12971 | },
|
12972 | {
|
12973 | name: "resolution",
|
12974 | isAttr: true,
|
12975 | type: "Real"
|
12976 | },
|
12977 | {
|
12978 | name: "ownedStyle",
|
12979 | type: "Style",
|
12980 | isReadOnly: true,
|
12981 | isVirtual: true,
|
12982 | isMany: true
|
12983 | }
|
12984 | ]
|
12985 | },
|
12986 | {
|
12987 | name: "Shape",
|
12988 | isAbstract: true,
|
12989 | superClass: [
|
12990 | "Node"
|
12991 | ],
|
12992 | properties: [
|
12993 | {
|
12994 | name: "bounds",
|
12995 | type: "dc:Bounds"
|
12996 | }
|
12997 | ]
|
12998 | },
|
12999 | {
|
13000 | name: "Plane",
|
13001 | isAbstract: true,
|
13002 | superClass: [
|
13003 | "Node"
|
13004 | ],
|
13005 | properties: [
|
13006 | {
|
13007 | name: "planeElement",
|
13008 | type: "DiagramElement",
|
13009 | subsettedProperty: "DiagramElement-ownedElement",
|
13010 | isMany: true
|
13011 | }
|
13012 | ]
|
13013 | },
|
13014 | {
|
13015 | name: "LabeledEdge",
|
13016 | isAbstract: true,
|
13017 | superClass: [
|
13018 | "Edge"
|
13019 | ],
|
13020 | properties: [
|
13021 | {
|
13022 | name: "ownedLabel",
|
13023 | type: "Label",
|
13024 | isReadOnly: true,
|
13025 | subsettedProperty: "DiagramElement-ownedElement",
|
13026 | isVirtual: true,
|
13027 | isMany: true
|
13028 | }
|
13029 | ]
|
13030 | },
|
13031 | {
|
13032 | name: "LabeledShape",
|
13033 | isAbstract: true,
|
13034 | superClass: [
|
13035 | "Shape"
|
13036 | ],
|
13037 | properties: [
|
13038 | {
|
13039 | name: "ownedLabel",
|
13040 | type: "Label",
|
13041 | isReadOnly: true,
|
13042 | subsettedProperty: "DiagramElement-ownedElement",
|
13043 | isVirtual: true,
|
13044 | isMany: true
|
13045 | }
|
13046 | ]
|
13047 | },
|
13048 | {
|
13049 | name: "Label",
|
13050 | isAbstract: true,
|
13051 | superClass: [
|
13052 | "Node"
|
13053 | ],
|
13054 | properties: [
|
13055 | {
|
13056 | name: "bounds",
|
13057 | type: "dc:Bounds"
|
13058 | }
|
13059 | ]
|
13060 | },
|
13061 | {
|
13062 | name: "Style",
|
13063 | isAbstract: true,
|
13064 | properties: [
|
13065 | {
|
13066 | name: "id",
|
13067 | type: "String",
|
13068 | isAttr: true,
|
13069 | isId: true
|
13070 | }
|
13071 | ]
|
13072 | },
|
13073 | {
|
13074 | name: "Extension",
|
13075 | properties: [
|
13076 | {
|
13077 | name: "values",
|
13078 | type: "Element",
|
13079 | isMany: true
|
13080 | }
|
13081 | ]
|
13082 | }
|
13083 | ];
|
13084 | var associations$3 = [
|
13085 | ];
|
13086 | var prefix$4 = "di";
|
13087 | var xml$1 = {
|
13088 | tagAlias: "lowerCase"
|
13089 | };
|
13090 | var DiPackage = {
|
13091 | name: name$3,
|
13092 | uri: uri$3,
|
13093 | types: types$4,
|
13094 | associations: associations$3,
|
13095 | prefix: prefix$4,
|
13096 | xml: xml$1
|
13097 | };
|
13098 |
|
13099 | var name$4 = "bpmn.io colors for BPMN";
|
13100 | var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
|
13101 | var prefix$5 = "bioc";
|
13102 | var types$5 = [
|
13103 | {
|
13104 | name: "ColoredShape",
|
13105 | "extends": [
|
13106 | "bpmndi:BPMNShape"
|
13107 | ],
|
13108 | properties: [
|
13109 | {
|
13110 | name: "stroke",
|
13111 | isAttr: true,
|
13112 | type: "String"
|
13113 | },
|
13114 | {
|
13115 | name: "fill",
|
13116 | isAttr: true,
|
13117 | type: "String"
|
13118 | }
|
13119 | ]
|
13120 | },
|
13121 | {
|
13122 | name: "ColoredEdge",
|
13123 | "extends": [
|
13124 | "bpmndi:BPMNEdge"
|
13125 | ],
|
13126 | properties: [
|
13127 | {
|
13128 | name: "stroke",
|
13129 | isAttr: true,
|
13130 | type: "String"
|
13131 | },
|
13132 | {
|
13133 | name: "fill",
|
13134 | isAttr: true,
|
13135 | type: "String"
|
13136 | }
|
13137 | ]
|
13138 | }
|
13139 | ];
|
13140 | var enumerations$2 = [
|
13141 | ];
|
13142 | var associations$4 = [
|
13143 | ];
|
13144 | var BiocPackage = {
|
13145 | name: name$4,
|
13146 | uri: uri$4,
|
13147 | prefix: prefix$5,
|
13148 | types: types$5,
|
13149 | enumerations: enumerations$2,
|
13150 | associations: associations$4
|
13151 | };
|
13152 |
|
13153 | var packages = {
|
13154 | bpmn: BpmnPackage,
|
13155 | bpmndi: BpmnDiPackage,
|
13156 | dc: DcPackage,
|
13157 | di: DiPackage,
|
13158 | bioc: BiocPackage
|
13159 | };
|
13160 |
|
13161 | function BpmnModdle$1(additionalPackages, options) {
|
13162 | var pks = assign({}, packages, additionalPackages);
|
13163 |
|
13164 | return new BpmnModdle(pks, options);
|
13165 | }
|
13166 |
|
13167 | function elementToString(e) {
|
13168 | if (!e) {
|
13169 | return '<null>';
|
13170 | }
|
13171 |
|
13172 | return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
|
13173 | }
|
13174 |
|
13175 | var diRefs = new objectRefs(
|
13176 | { name: 'bpmnElement', enumerable: true },
|
13177 | { name: 'di', configurable: true }
|
13178 | );
|
13179 |
|
13180 | |
13181 |
|
13182 |
|
13183 |
|
13184 |
|
13185 |
|
13186 |
|
13187 |
|
13188 | function is(element, type) {
|
13189 | return element.$instanceOf(type);
|
13190 | }
|
13191 |
|
13192 |
|
13193 | |
13194 |
|
13195 |
|
13196 |
|
13197 | function findDisplayCandidate(definitions) {
|
13198 | return find(definitions.rootElements, function(e) {
|
13199 | return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
|
13200 | });
|
13201 | }
|
13202 |
|
13203 |
|
13204 | function BpmnTreeWalker(handler, translate) {
|
13205 |
|
13206 |
|
13207 | var handledElements = {};
|
13208 |
|
13209 |
|
13210 |
|
13211 | var deferred = [];
|
13212 |
|
13213 |
|
13214 |
|
13215 | function contextual(fn, ctx) {
|
13216 | return function(e) {
|
13217 | fn(e, ctx);
|
13218 | };
|
13219 | }
|
13220 |
|
13221 | function handled(element) {
|
13222 | handledElements[element.id] = element;
|
13223 | }
|
13224 |
|
13225 | function isHandled(element) {
|
13226 | return handledElements[element.id];
|
13227 | }
|
13228 |
|
13229 | function visit(element, ctx) {
|
13230 |
|
13231 | var gfx = element.gfx;
|
13232 |
|
13233 |
|
13234 | if (gfx) {
|
13235 | throw new Error(
|
13236 | translate('already rendered {element}', { element: elementToString(element) })
|
13237 | );
|
13238 | }
|
13239 |
|
13240 |
|
13241 | return handler.element(element, ctx);
|
13242 | }
|
13243 |
|
13244 | function visitRoot(element, diagram) {
|
13245 | return handler.root(element, diagram);
|
13246 | }
|
13247 |
|
13248 | function visitIfDi(element, ctx) {
|
13249 |
|
13250 | try {
|
13251 | var gfx = element.di && visit(element, ctx);
|
13252 |
|
13253 | handled(element);
|
13254 |
|
13255 | return gfx;
|
13256 | } catch (e) {
|
13257 | logError(e.message, { element: element, error: e });
|
13258 |
|
13259 | console.error(translate('failed to import {element}', { element: elementToString(element) }));
|
13260 | console.error(e);
|
13261 | }
|
13262 | }
|
13263 |
|
13264 | function logError(message, context) {
|
13265 | handler.error(message, context);
|
13266 | }
|
13267 |
|
13268 |
|
13269 |
|
13270 | function registerDi(di) {
|
13271 | var bpmnElement = di.bpmnElement;
|
13272 |
|
13273 | if (bpmnElement) {
|
13274 | if (bpmnElement.di) {
|
13275 | logError(
|
13276 | translate('multiple DI elements defined for {element}', {
|
13277 | element: elementToString(bpmnElement)
|
13278 | }),
|
13279 | { element: bpmnElement }
|
13280 | );
|
13281 | } else {
|
13282 | diRefs.bind(bpmnElement, 'di');
|
13283 | bpmnElement.di = di;
|
13284 | }
|
13285 | } else {
|
13286 | logError(
|
13287 | translate('no bpmnElement referenced in {element}', {
|
13288 | element: elementToString(di)
|
13289 | }),
|
13290 | { element: di }
|
13291 | );
|
13292 | }
|
13293 | }
|
13294 |
|
13295 | function handleDiagram(diagram) {
|
13296 | handlePlane(diagram.plane);
|
13297 | }
|
13298 |
|
13299 | function handlePlane(plane) {
|
13300 | registerDi(plane);
|
13301 |
|
13302 | forEach(plane.planeElement, handlePlaneElement);
|
13303 | }
|
13304 |
|
13305 | function handlePlaneElement(planeElement) {
|
13306 | registerDi(planeElement);
|
13307 | }
|
13308 |
|
13309 |
|
13310 |
|
13311 |
|
13312 | |
13313 |
|
13314 |
|
13315 |
|
13316 |
|
13317 |
|
13318 |
|
13319 |
|
13320 | function handleDefinitions(definitions, diagram) {
|
13321 |
|
13322 |
|
13323 | var diagrams = definitions.diagrams;
|
13324 |
|
13325 | if (diagram && diagrams.indexOf(diagram) === -1) {
|
13326 | throw new Error(translate('diagram not part of bpmn:Definitions'));
|
13327 | }
|
13328 |
|
13329 | if (!diagram && diagrams && diagrams.length) {
|
13330 | diagram = diagrams[0];
|
13331 | }
|
13332 |
|
13333 |
|
13334 | if (!diagram) {
|
13335 | throw new Error(translate('no diagram to display'));
|
13336 | }
|
13337 |
|
13338 |
|
13339 | handleDiagram(diagram);
|
13340 |
|
13341 |
|
13342 | var plane = diagram.plane;
|
13343 |
|
13344 | if (!plane) {
|
13345 | throw new Error(translate(
|
13346 | 'no plane for {element}',
|
13347 | { element: elementToString(diagram) }
|
13348 | ));
|
13349 | }
|
13350 |
|
13351 | var rootElement = plane.bpmnElement;
|
13352 |
|
13353 |
|
13354 |
|
13355 | if (!rootElement) {
|
13356 | rootElement = findDisplayCandidate(definitions);
|
13357 |
|
13358 | if (!rootElement) {
|
13359 | throw new Error(translate('no process or collaboration to display'));
|
13360 | } else {
|
13361 |
|
13362 | logError(
|
13363 | translate('correcting missing bpmnElement on {plane} to {rootElement}', {
|
13364 | plane: elementToString(plane),
|
13365 | rootElement: elementToString(rootElement)
|
13366 | })
|
13367 | );
|
13368 |
|
13369 |
|
13370 | plane.bpmnElement = rootElement;
|
13371 | registerDi(plane);
|
13372 | }
|
13373 | }
|
13374 |
|
13375 |
|
13376 | var ctx = visitRoot(rootElement, plane);
|
13377 |
|
13378 | if (is(rootElement, 'bpmn:Process')) {
|
13379 | handleProcess(rootElement, ctx);
|
13380 | } else if (is(rootElement, 'bpmn:Collaboration')) {
|
13381 | handleCollaboration(rootElement, ctx);
|
13382 |
|
13383 |
|
13384 | handleUnhandledProcesses(definitions.rootElements, ctx);
|
13385 | } else {
|
13386 | throw new Error(
|
13387 | translate('unsupported bpmnElement for {plane}: {rootElement}', {
|
13388 | plane: elementToString(plane),
|
13389 | rootElement: elementToString(rootElement)
|
13390 | })
|
13391 | );
|
13392 | }
|
13393 |
|
13394 |
|
13395 | handleDeferred(deferred);
|
13396 | }
|
13397 |
|
13398 | function handleDeferred() {
|
13399 |
|
13400 | var fn;
|
13401 |
|
13402 |
|
13403 | while (deferred.length) {
|
13404 | fn = deferred.shift();
|
13405 |
|
13406 | fn();
|
13407 | }
|
13408 | }
|
13409 |
|
13410 | function handleProcess(process, context) {
|
13411 | handleFlowElementsContainer(process, context);
|
13412 | handleIoSpecification(process.ioSpecification, context);
|
13413 |
|
13414 | handleArtifacts(process.artifacts, context);
|
13415 |
|
13416 |
|
13417 | handled(process);
|
13418 | }
|
13419 |
|
13420 | function handleUnhandledProcesses(rootElements) {
|
13421 |
|
13422 |
|
13423 |
|
13424 |
|
13425 | var processes = filter(rootElements, function(e) {
|
13426 | return !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
|
13427 | });
|
13428 |
|
13429 | processes.forEach(contextual(handleProcess));
|
13430 | }
|
13431 |
|
13432 | function handleMessageFlow(messageFlow, context) {
|
13433 | visitIfDi(messageFlow, context);
|
13434 | }
|
13435 |
|
13436 | function handleMessageFlows(messageFlows, context) {
|
13437 | forEach(messageFlows, contextual(handleMessageFlow, context));
|
13438 | }
|
13439 |
|
13440 | function handleDataAssociation(association, context) {
|
13441 | visitIfDi(association, context);
|
13442 | }
|
13443 |
|
13444 | function handleDataInput(dataInput, context) {
|
13445 | visitIfDi(dataInput, context);
|
13446 | }
|
13447 |
|
13448 | function handleDataOutput(dataOutput, context) {
|
13449 | visitIfDi(dataOutput, context);
|
13450 | }
|
13451 |
|
13452 | function handleArtifact(artifact, context) {
|
13453 |
|
13454 |
|
13455 |
|
13456 |
|
13457 |
|
13458 | visitIfDi(artifact, context);
|
13459 | }
|
13460 |
|
13461 | function handleArtifacts(artifacts, context) {
|
13462 |
|
13463 | forEach(artifacts, function(e) {
|
13464 | if (is(e, 'bpmn:Association')) {
|
13465 | deferred.push(function() {
|
13466 | handleArtifact(e, context);
|
13467 | });
|
13468 | } else {
|
13469 | handleArtifact(e, context);
|
13470 | }
|
13471 | });
|
13472 | }
|
13473 |
|
13474 | function handleIoSpecification(ioSpecification, context) {
|
13475 |
|
13476 | if (!ioSpecification) {
|
13477 | return;
|
13478 | }
|
13479 |
|
13480 | forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
|
13481 | forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
|
13482 | }
|
13483 |
|
13484 | function handleSubProcess(subProcess, context) {
|
13485 | handleFlowElementsContainer(subProcess, context);
|
13486 | handleArtifacts(subProcess.artifacts, context);
|
13487 | }
|
13488 |
|
13489 | function handleFlowNode(flowNode, context) {
|
13490 | var childCtx = visitIfDi(flowNode, context);
|
13491 |
|
13492 | if (is(flowNode, 'bpmn:SubProcess')) {
|
13493 | handleSubProcess(flowNode, childCtx || context);
|
13494 | }
|
13495 |
|
13496 | if (is(flowNode, 'bpmn:Activity')) {
|
13497 | handleIoSpecification(flowNode.ioSpecification, context);
|
13498 | }
|
13499 |
|
13500 |
|
13501 |
|
13502 |
|
13503 |
|
13504 |
|
13505 |
|
13506 |
|
13507 | deferred.push(function() {
|
13508 | forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
|
13509 | forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
|
13510 | });
|
13511 | }
|
13512 |
|
13513 | function handleSequenceFlow(sequenceFlow, context) {
|
13514 | visitIfDi(sequenceFlow, context);
|
13515 | }
|
13516 |
|
13517 | function handleDataElement(dataObject, context) {
|
13518 | visitIfDi(dataObject, context);
|
13519 | }
|
13520 |
|
13521 | function handleBoundaryEvent(dataObject, context) {
|
13522 | visitIfDi(dataObject, context);
|
13523 | }
|
13524 |
|
13525 | function handleLane(lane, context) {
|
13526 |
|
13527 | deferred.push(function() {
|
13528 |
|
13529 | var newContext = visitIfDi(lane, context);
|
13530 |
|
13531 | if (lane.childLaneSet) {
|
13532 | handleLaneSet(lane.childLaneSet, newContext || context);
|
13533 | }
|
13534 |
|
13535 | wireFlowNodeRefs(lane);
|
13536 | });
|
13537 | }
|
13538 |
|
13539 | function handleLaneSet(laneSet, context) {
|
13540 | forEach(laneSet.lanes, contextual(handleLane, context));
|
13541 | }
|
13542 |
|
13543 | function handleLaneSets(laneSets, context) {
|
13544 | forEach(laneSets, contextual(handleLaneSet, context));
|
13545 | }
|
13546 |
|
13547 | function handleFlowElementsContainer(container, context) {
|
13548 | handleFlowElements(container.flowElements, context);
|
13549 |
|
13550 | if (container.laneSets) {
|
13551 | handleLaneSets(container.laneSets, context);
|
13552 | }
|
13553 | }
|
13554 |
|
13555 | function handleFlowElements(flowElements, context) {
|
13556 | forEach(flowElements, function(e) {
|
13557 | if (is(e, 'bpmn:SequenceFlow')) {
|
13558 | deferred.push(function() {
|
13559 | handleSequenceFlow(e, context);
|
13560 | });
|
13561 | } else if (is(e, 'bpmn:BoundaryEvent')) {
|
13562 | deferred.unshift(function() {
|
13563 | handleBoundaryEvent(e, context);
|
13564 | });
|
13565 | } else if (is(e, 'bpmn:FlowNode')) {
|
13566 | handleFlowNode(e, context);
|
13567 | } else if (is(e, 'bpmn:DataObject')) ; else if (is(e, 'bpmn:DataStoreReference')) {
|
13568 | handleDataElement(e, context);
|
13569 | } else if (is(e, 'bpmn:DataObjectReference')) {
|
13570 | handleDataElement(e, context);
|
13571 | } else {
|
13572 | logError(
|
13573 | translate('unrecognized flowElement {element} in context {context}', {
|
13574 | element: elementToString(e),
|
13575 | context: (context ? elementToString(context.businessObject) : 'null')
|
13576 | }),
|
13577 | { element: e, context: context }
|
13578 | );
|
13579 | }
|
13580 | });
|
13581 | }
|
13582 |
|
13583 | function handleParticipant(participant, context) {
|
13584 | var newCtx = visitIfDi(participant, context);
|
13585 |
|
13586 | var process = participant.processRef;
|
13587 | if (process) {
|
13588 | handleProcess(process, newCtx || context);
|
13589 | }
|
13590 | }
|
13591 |
|
13592 | function handleCollaboration(collaboration) {
|
13593 |
|
13594 | forEach(collaboration.participants, contextual(handleParticipant));
|
13595 |
|
13596 | handleArtifacts(collaboration.artifacts);
|
13597 |
|
13598 |
|
13599 | deferred.push(function() {
|
13600 | handleMessageFlows(collaboration.messageFlows);
|
13601 | });
|
13602 | }
|
13603 |
|
13604 |
|
13605 | function wireFlowNodeRefs(lane) {
|
13606 |
|
13607 | forEach(lane.flowNodeRef, function(flowNode) {
|
13608 | var lanes = flowNode.get('lanes');
|
13609 |
|
13610 | if (lanes) {
|
13611 | lanes.push(lane);
|
13612 | }
|
13613 | });
|
13614 | }
|
13615 |
|
13616 |
|
13617 |
|
13618 | return {
|
13619 | handleDeferred: handleDeferred,
|
13620 | handleDefinitions: handleDefinitions,
|
13621 | handleSubProcess: handleSubProcess,
|
13622 | registerDi: registerDi
|
13623 | };
|
13624 | }
|
13625 |
|
13626 | |
13627 |
|
13628 |
|
13629 |
|
13630 |
|
13631 |
|
13632 |
|
13633 |
|
13634 |
|
13635 | function importBpmnDiagram(diagram, definitions, done) {
|
13636 |
|
13637 | var importer,
|
13638 | eventBus,
|
13639 | translate;
|
13640 |
|
13641 | var error,
|
13642 | warnings = [];
|
13643 |
|
13644 | |
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 | function render(definitions) {
|
13651 |
|
13652 | var visitor = {
|
13653 |
|
13654 | root: function(element) {
|
13655 | return importer.add(element);
|
13656 | },
|
13657 |
|
13658 | element: function(element, parentShape) {
|
13659 | return importer.add(element, parentShape);
|
13660 | },
|
13661 |
|
13662 | error: function(message, context) {
|
13663 | warnings.push({ message: message, context: context });
|
13664 | }
|
13665 | };
|
13666 |
|
13667 | var walker = new BpmnTreeWalker(visitor, translate);
|
13668 |
|
13669 |
|
13670 |
|
13671 | walker.handleDefinitions(definitions);
|
13672 | }
|
13673 |
|
13674 | try {
|
13675 | importer = diagram.get('bpmnImporter');
|
13676 | eventBus = diagram.get('eventBus');
|
13677 | translate = diagram.get('translate');
|
13678 |
|
13679 | eventBus.fire('import.render.start', { definitions: definitions });
|
13680 |
|
13681 | render(definitions);
|
13682 |
|
13683 | eventBus.fire('import.render.complete', {
|
13684 | error: error,
|
13685 | warnings: warnings
|
13686 | });
|
13687 | } catch (e) {
|
13688 | error = e;
|
13689 | }
|
13690 |
|
13691 | done(error, warnings);
|
13692 | }
|
13693 |
|
13694 | |
13695 |
|
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 | function is$1(element, type) {
|
13703 | var bo = getBusinessObject(element);
|
13704 |
|
13705 | return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
|
13706 | }
|
13707 |
|
13708 |
|
13709 | |
13710 |
|
13711 |
|
13712 |
|
13713 |
|
13714 |
|
13715 |
|
13716 | function getBusinessObject(element) {
|
13717 | return (element && element.businessObject) || element;
|
13718 | }
|
13719 |
|
13720 | function isExpanded(element) {
|
13721 |
|
13722 | if (is$1(element, 'bpmn:CallActivity')) {
|
13723 | return false;
|
13724 | }
|
13725 |
|
13726 | if (is$1(element, 'bpmn:SubProcess')) {
|
13727 | return !!getBusinessObject(element).di.isExpanded;
|
13728 | }
|
13729 |
|
13730 | if (is$1(element, 'bpmn:Participant')) {
|
13731 | return !!getBusinessObject(element).processRef;
|
13732 | }
|
13733 |
|
13734 | return true;
|
13735 | }
|
13736 |
|
13737 | function isInterrupting(element) {
|
13738 | return element && getBusinessObject(element).isInterrupting !== false;
|
13739 | }
|
13740 |
|
13741 | function isEventSubProcess(element) {
|
13742 | return element && !!getBusinessObject(element).triggeredByEvent;
|
13743 | }
|
13744 |
|
13745 | function hasEventDefinition(element, eventType) {
|
13746 | var bo = getBusinessObject(element),
|
13747 | hasEventDefinition = false;
|
13748 |
|
13749 | if (bo.eventDefinitions) {
|
13750 | forEach(bo.eventDefinitions, function(event) {
|
13751 | if (is$1(event, eventType)) {
|
13752 | hasEventDefinition = true;
|
13753 | }
|
13754 | });
|
13755 | }
|
13756 |
|
13757 | return hasEventDefinition;
|
13758 | }
|
13759 |
|
13760 | function hasErrorEventDefinition(element) {
|
13761 | return hasEventDefinition(element, 'bpmn:ErrorEventDefinition');
|
13762 | }
|
13763 |
|
13764 | function hasEscalationEventDefinition(element) {
|
13765 | return hasEventDefinition(element, 'bpmn:EscalationEventDefinition');
|
13766 | }
|
13767 |
|
13768 | function hasCompensateEventDefinition(element) {
|
13769 | return hasEventDefinition(element, 'bpmn:CompensateEventDefinition');
|
13770 | }
|
13771 |
|
13772 |
|
13773 |
|
13774 | |
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 | function isTypedEvent(event, eventDefinitionType, filter$$1) {
|
13780 |
|
13781 | function matches(definition, filter$$1) {
|
13782 | return every(filter$$1, function(val, key) {
|
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 | return definition[key] == val;
|
13788 | });
|
13789 | }
|
13790 |
|
13791 | return some(event.eventDefinitions, function(definition) {
|
13792 | return definition.$type === eventDefinitionType && matches(event, filter$$1);
|
13793 | });
|
13794 | }
|
13795 |
|
13796 | function isThrowEvent(event) {
|
13797 | return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
|
13798 | }
|
13799 |
|
13800 | function isCollection(element) {
|
13801 | var dataObject = element.dataObjectRef;
|
13802 |
|
13803 | return element.isCollection || (dataObject && dataObject.isCollection);
|
13804 | }
|
13805 |
|
13806 | function getDi(element) {
|
13807 | return element.businessObject.di;
|
13808 | }
|
13809 |
|
13810 | function getSemantic(element) {
|
13811 | return element.businessObject;
|
13812 | }
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 | function getFillColor(element, defaultColor) {
|
13818 | return getDi(element).get('bioc:fill') || defaultColor || 'white';
|
13819 | }
|
13820 |
|
13821 | function getStrokeColor(element, defaultColor) {
|
13822 | return getDi(element).get('bioc:stroke') || defaultColor || 'black';
|
13823 | }
|
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 | function getCirclePath(shape) {
|
13829 |
|
13830 | var cx = shape.x + shape.width / 2,
|
13831 | cy = shape.y + shape.height / 2,
|
13832 | radius = shape.width / 2;
|
13833 |
|
13834 | var circlePath = [
|
13835 | ['M', cx, cy],
|
13836 | ['m', 0, -radius],
|
13837 | ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
|
13838 | ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
|
13839 | ['z']
|
13840 | ];
|
13841 |
|
13842 | return componentsToPath(circlePath);
|
13843 | }
|
13844 |
|
13845 | function getRoundRectPath(shape, borderRadius) {
|
13846 |
|
13847 | var x = shape.x,
|
13848 | y = shape.y,
|
13849 | width = shape.width,
|
13850 | height = shape.height;
|
13851 |
|
13852 | var roundRectPath = [
|
13853 | ['M', x + borderRadius, y],
|
13854 | ['l', width - borderRadius * 2, 0],
|
13855 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
|
13856 | ['l', 0, height - borderRadius * 2],
|
13857 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
|
13858 | ['l', borderRadius * 2 - width, 0],
|
13859 | ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
|
13860 | ['l', 0, borderRadius * 2 - height],
|
13861 | ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
|
13862 | ['z']
|
13863 | ];
|
13864 |
|
13865 | return componentsToPath(roundRectPath);
|
13866 | }
|
13867 |
|
13868 | function getDiamondPath(shape) {
|
13869 |
|
13870 | var width = shape.width,
|
13871 | height = shape.height,
|
13872 | x = shape.x,
|
13873 | y = shape.y,
|
13874 | halfWidth = width / 2,
|
13875 | halfHeight = height / 2;
|
13876 |
|
13877 | var diamondPath = [
|
13878 | ['M', x + halfWidth, y],
|
13879 | ['l', halfWidth, halfHeight],
|
13880 | ['l', -halfWidth, halfHeight],
|
13881 | ['l', -halfWidth, -halfHeight],
|
13882 | ['z']
|
13883 | ];
|
13884 |
|
13885 | return componentsToPath(diamondPath);
|
13886 | }
|
13887 |
|
13888 | function getRectPath(shape) {
|
13889 | var x = shape.x,
|
13890 | y = shape.y,
|
13891 | width = shape.width,
|
13892 | height = shape.height;
|
13893 |
|
13894 | var rectPath = [
|
13895 | ['M', x, y],
|
13896 | ['l', width, 0],
|
13897 | ['l', 0, height],
|
13898 | ['l', -width, 0],
|
13899 | ['z']
|
13900 | ];
|
13901 |
|
13902 | return componentsToPath(rectPath);
|
13903 | }
|
13904 |
|
13905 | var RENDERER_IDS = new ids();
|
13906 |
|
13907 | var TASK_BORDER_RADIUS = 10;
|
13908 | var INNER_OUTER_DIST = 3;
|
13909 |
|
13910 | var DEFAULT_FILL_OPACITY = .95,
|
13911 | HIGH_FILL_OPACITY = .35;
|
13912 |
|
13913 |
|
13914 | function BpmnRenderer(
|
13915 | config, eventBus, styles, pathMap,
|
13916 | canvas, textRenderer, priority) {
|
13917 |
|
13918 | BaseRenderer.call(this, eventBus, priority);
|
13919 |
|
13920 | var defaultFillColor = config && config.defaultFillColor,
|
13921 | defaultStrokeColor = config && config.defaultStrokeColor;
|
13922 |
|
13923 | var rendererId = RENDERER_IDS.next();
|
13924 |
|
13925 | var markers = {};
|
13926 |
|
13927 | var computeStyle = styles.computeStyle;
|
13928 |
|
13929 | function addMarker(id, options) {
|
13930 | var attrs = assign({
|
13931 | fill: 'black',
|
13932 | strokeWidth: 1,
|
13933 | strokeLinecap: 'round',
|
13934 | strokeDasharray: 'none'
|
13935 | }, options.attrs);
|
13936 |
|
13937 | var ref = options.ref || { x: 0, y: 0 };
|
13938 |
|
13939 | var scale$$1 = options.scale || 1;
|
13940 |
|
13941 |
|
13942 |
|
13943 | if (attrs.strokeDasharray === 'none') {
|
13944 | attrs.strokeDasharray = [10000, 1];
|
13945 | }
|
13946 |
|
13947 | var marker = create('marker');
|
13948 |
|
13949 | attr$1(options.element, attrs);
|
13950 |
|
13951 | append(marker, options.element);
|
13952 |
|
13953 | attr$1(marker, {
|
13954 | id: id,
|
13955 | viewBox: '0 0 20 20',
|
13956 | refX: ref.x,
|
13957 | refY: ref.y,
|
13958 | markerWidth: 20 * scale$$1,
|
13959 | markerHeight: 20 * scale$$1,
|
13960 | orient: 'auto'
|
13961 | });
|
13962 |
|
13963 | var defs = query('defs', canvas._svg);
|
13964 |
|
13965 | if (!defs) {
|
13966 | defs = create('defs');
|
13967 |
|
13968 | append(canvas._svg, defs);
|
13969 | }
|
13970 |
|
13971 | append(defs, marker);
|
13972 |
|
13973 | markers[id] = marker;
|
13974 | }
|
13975 |
|
13976 | function marker(type, fill, stroke) {
|
13977 | var id = type + '-' + fill + '-' + stroke + '-' + rendererId;
|
13978 |
|
13979 | if (!markers[id]) {
|
13980 | createMarker(type, fill, stroke);
|
13981 | }
|
13982 |
|
13983 | return 'url(#' + id + ')';
|
13984 | }
|
13985 |
|
13986 | function createMarker(type, fill, stroke) {
|
13987 | var id = type + '-' + fill + '-' + stroke + '-' + rendererId;
|
13988 |
|
13989 | if (type === 'sequenceflow-end') {
|
13990 | var sequenceflowEnd = create('path');
|
13991 | attr$1(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
|
13992 |
|
13993 | addMarker(id, {
|
13994 | element: sequenceflowEnd,
|
13995 | ref: { x: 11, y: 10 },
|
13996 | scale: 0.5,
|
13997 | attrs: {
|
13998 | fill: stroke,
|
13999 | stroke: stroke
|
14000 | }
|
14001 | });
|
14002 | }
|
14003 |
|
14004 | if (type === 'messageflow-start') {
|
14005 | var messageflowStart = create('circle');
|
14006 | attr$1(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
|
14007 |
|
14008 | addMarker(id, {
|
14009 | element: messageflowStart,
|
14010 | attrs: {
|
14011 | fill: fill,
|
14012 | stroke: stroke
|
14013 | },
|
14014 | ref: { x: 6, y: 6 }
|
14015 | });
|
14016 | }
|
14017 |
|
14018 | if (type === 'messageflow-end') {
|
14019 | var messageflowEnd = create('path');
|
14020 | attr$1(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
|
14021 |
|
14022 | addMarker(id, {
|
14023 | element: messageflowEnd,
|
14024 | attrs: {
|
14025 | fill: fill,
|
14026 | stroke: stroke,
|
14027 | strokeLinecap: 'butt'
|
14028 | },
|
14029 | ref: { x: 8.5, y: 5 }
|
14030 | });
|
14031 | }
|
14032 |
|
14033 | if (type === 'association-start') {
|
14034 | var associationStart = create('path');
|
14035 | attr$1(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
|
14036 |
|
14037 | addMarker(id, {
|
14038 | element: associationStart,
|
14039 | attrs: {
|
14040 | fill: 'none',
|
14041 | stroke: stroke,
|
14042 | strokeWidth: 1.5
|
14043 | },
|
14044 | ref: { x: 1, y: 10 },
|
14045 | scale: 0.5
|
14046 | });
|
14047 | }
|
14048 |
|
14049 | if (type === 'association-end') {
|
14050 | var associationEnd = create('path');
|
14051 | attr$1(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
|
14052 |
|
14053 | addMarker(id, {
|
14054 | element: associationEnd,
|
14055 | attrs: {
|
14056 | fill: 'none',
|
14057 | stroke: stroke,
|
14058 | strokeWidth: 1.5
|
14059 | },
|
14060 | ref: { x: 12, y: 10 },
|
14061 | scale: 0.5
|
14062 | });
|
14063 | }
|
14064 |
|
14065 | if (type === 'conditional-flow-marker') {
|
14066 | var conditionalflowMarker = create('path');
|
14067 | attr$1(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
|
14068 |
|
14069 | addMarker(id, {
|
14070 | element: conditionalflowMarker,
|
14071 | attrs: {
|
14072 | fill: fill,
|
14073 | stroke: stroke
|
14074 | },
|
14075 | ref: { x: -1, y: 10 },
|
14076 | scale: 0.5
|
14077 | });
|
14078 | }
|
14079 |
|
14080 | if (type === 'conditional-default-flow-marker') {
|
14081 | var conditionaldefaultflowMarker = create('path');
|
14082 | attr$1(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
|
14083 |
|
14084 | addMarker(id, {
|
14085 | element: conditionaldefaultflowMarker,
|
14086 | attrs: {
|
14087 | stroke: stroke
|
14088 | },
|
14089 | ref: { x: 0, y: 10 },
|
14090 | scale: 0.5
|
14091 | });
|
14092 | }
|
14093 | }
|
14094 |
|
14095 | function drawCircle(parentGfx, width, height, offset, attrs) {
|
14096 |
|
14097 | if (isObject(offset)) {
|
14098 | attrs = offset;
|
14099 | offset = 0;
|
14100 | }
|
14101 |
|
14102 | offset = offset || 0;
|
14103 |
|
14104 | attrs = computeStyle(attrs, {
|
14105 | stroke: 'black',
|
14106 | strokeWidth: 2,
|
14107 | fill: 'white'
|
14108 | });
|
14109 |
|
14110 | if (attrs.fill === 'none') {
|
14111 | delete attrs.fillOpacity;
|
14112 | }
|
14113 |
|
14114 | var cx = width / 2,
|
14115 | cy = height / 2;
|
14116 |
|
14117 | var circle = create('circle');
|
14118 | attr$1(circle, {
|
14119 | cx: cx,
|
14120 | cy: cy,
|
14121 | r: Math.round((width + height) / 4 - offset)
|
14122 | });
|
14123 | attr$1(circle, attrs);
|
14124 |
|
14125 | append(parentGfx, circle);
|
14126 |
|
14127 | return circle;
|
14128 | }
|
14129 |
|
14130 | function drawRect(parentGfx, width, height, r, offset, attrs) {
|
14131 |
|
14132 | if (isObject(offset)) {
|
14133 | attrs = offset;
|
14134 | offset = 0;
|
14135 | }
|
14136 |
|
14137 | offset = offset || 0;
|
14138 |
|
14139 | attrs = computeStyle(attrs, {
|
14140 | stroke: 'black',
|
14141 | strokeWidth: 2,
|
14142 | fill: 'white'
|
14143 | });
|
14144 |
|
14145 | var rect = create('rect');
|
14146 | attr$1(rect, {
|
14147 | x: offset,
|
14148 | y: offset,
|
14149 | width: width - offset * 2,
|
14150 | height: height - offset * 2,
|
14151 | rx: r,
|
14152 | ry: r
|
14153 | });
|
14154 | attr$1(rect, attrs);
|
14155 |
|
14156 | append(parentGfx, rect);
|
14157 |
|
14158 | return rect;
|
14159 | }
|
14160 |
|
14161 | function drawDiamond(parentGfx, width, height, attrs) {
|
14162 |
|
14163 | var x_2 = width / 2;
|
14164 | var y_2 = height / 2;
|
14165 |
|
14166 | var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
|
14167 |
|
14168 | var pointsString = points.map(function(point) {
|
14169 | return point.x + ',' + point.y;
|
14170 | }).join(' ');
|
14171 |
|
14172 | attrs = computeStyle(attrs, {
|
14173 | stroke: 'black',
|
14174 | strokeWidth: 2,
|
14175 | fill: 'white'
|
14176 | });
|
14177 |
|
14178 | var polygon = create('polygon');
|
14179 | attr$1(polygon, {
|
14180 | points: pointsString
|
14181 | });
|
14182 | attr$1(polygon, attrs);
|
14183 |
|
14184 | append(parentGfx, polygon);
|
14185 |
|
14186 | return polygon;
|
14187 | }
|
14188 |
|
14189 | function drawLine(parentGfx, waypoints, attrs) {
|
14190 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
14191 | stroke: 'black',
|
14192 | strokeWidth: 2,
|
14193 | fill: 'none'
|
14194 | });
|
14195 |
|
14196 | var line = createLine(waypoints, attrs);
|
14197 |
|
14198 | append(parentGfx, line);
|
14199 |
|
14200 | return line;
|
14201 | }
|
14202 |
|
14203 | function drawPath(parentGfx, d, attrs) {
|
14204 |
|
14205 | attrs = computeStyle(attrs, [ 'no-fill' ], {
|
14206 | strokeWidth: 2,
|
14207 | stroke: 'black'
|
14208 | });
|
14209 |
|
14210 | var path = create('path');
|
14211 | attr$1(path, { d: d });
|
14212 | attr$1(path, attrs);
|
14213 |
|
14214 | append(parentGfx, path);
|
14215 |
|
14216 | return path;
|
14217 | }
|
14218 |
|
14219 | function drawMarker(type, parentGfx, path, attrs) {
|
14220 | return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
|
14221 | }
|
14222 |
|
14223 | function as(type) {
|
14224 | return function(parentGfx, element) {
|
14225 | return handlers[type](parentGfx, element);
|
14226 | };
|
14227 | }
|
14228 |
|
14229 | function renderer(type) {
|
14230 | return handlers[type];
|
14231 | }
|
14232 |
|
14233 | function renderEventContent(element, parentGfx) {
|
14234 |
|
14235 | var event = getSemantic(element);
|
14236 | var isThrowing = isThrowEvent(event);
|
14237 |
|
14238 | if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
|
14239 | return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
|
14240 | }
|
14241 |
|
14242 | if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
|
14243 | return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
|
14244 | }
|
14245 |
|
14246 | if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
|
14247 | return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
|
14248 | }
|
14249 |
|
14250 | if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
|
14251 | return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
|
14252 | }
|
14253 |
|
14254 | if (isTypedEvent(event, 'bpmn:CancelEventDefinition') &&
|
14255 | isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: false })) {
|
14256 | return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
|
14257 | }
|
14258 |
|
14259 | if (isTypedEvent(event, 'bpmn:CancelEventDefinition') &&
|
14260 | isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: true })) {
|
14261 | return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
|
14262 | }
|
14263 |
|
14264 | if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
|
14265 | return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
|
14266 | }
|
14267 |
|
14268 | if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
|
14269 | return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
|
14270 | }
|
14271 |
|
14272 | if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
|
14273 | return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
|
14274 | }
|
14275 |
|
14276 | if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
|
14277 | return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
|
14278 | }
|
14279 |
|
14280 | if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
|
14281 | return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
|
14282 | }
|
14283 |
|
14284 | if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
|
14285 | return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
|
14286 | }
|
14287 |
|
14288 | return null;
|
14289 | }
|
14290 |
|
14291 | function renderLabel(parentGfx, label, options) {
|
14292 |
|
14293 | options = assign({
|
14294 | size: {
|
14295 | width: 100
|
14296 | }
|
14297 | }, options);
|
14298 |
|
14299 | var text = textRenderer.createText(label || '', options);
|
14300 |
|
14301 | classes$1(text).add('djs-label');
|
14302 |
|
14303 | append(parentGfx, text);
|
14304 |
|
14305 | return text;
|
14306 | }
|
14307 |
|
14308 | function renderEmbeddedLabel(parentGfx, element, align) {
|
14309 | var semantic = getSemantic(element);
|
14310 |
|
14311 | return renderLabel(parentGfx, semantic.name, {
|
14312 | box: element,
|
14313 | align: align,
|
14314 | padding: 5,
|
14315 | style: {
|
14316 | fill: getStrokeColor(element, defaultStrokeColor)
|
14317 | }
|
14318 | });
|
14319 | }
|
14320 |
|
14321 | function renderExternalLabel(parentGfx, element) {
|
14322 | var semantic = getSemantic(element);
|
14323 | var box = {
|
14324 | width: 90,
|
14325 | height: 30,
|
14326 | x: element.width / 2 + element.x,
|
14327 | y: element.height / 2 + element.y
|
14328 | };
|
14329 |
|
14330 | return renderLabel(parentGfx, semantic.name, {
|
14331 | box: box,
|
14332 | fitBox: true,
|
14333 | style: assign(
|
14334 | {},
|
14335 | textRenderer.getExternalStyle(),
|
14336 | {
|
14337 | fill: getStrokeColor(element, defaultStrokeColor)
|
14338 | }
|
14339 | )
|
14340 | });
|
14341 | }
|
14342 |
|
14343 | function renderLaneLabel(parentGfx, text, element) {
|
14344 | var textBox = renderLabel(parentGfx, text, {
|
14345 | box: {
|
14346 | height: 30,
|
14347 | width: element.height
|
14348 | },
|
14349 | align: 'center-middle',
|
14350 | style: {
|
14351 | fill: getStrokeColor(element, defaultStrokeColor)
|
14352 | }
|
14353 | });
|
14354 |
|
14355 | var top = -1 * element.height;
|
14356 |
|
14357 | transform$1(textBox, 0, -top, 270);
|
14358 | }
|
14359 |
|
14360 | function createPathFromConnection(connection) {
|
14361 | var waypoints = connection.waypoints;
|
14362 |
|
14363 | var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
|
14364 | for (var i = 1; i < waypoints.length; i++) {
|
14365 | pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
|
14366 | }
|
14367 | return pathData;
|
14368 | }
|
14369 |
|
14370 | var handlers = this.handlers = {
|
14371 | 'bpmn:Event': function(parentGfx, element, attrs) {
|
14372 |
|
14373 | if (!('fillOpacity' in attrs)) {
|
14374 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
14375 | }
|
14376 |
|
14377 | return drawCircle(parentGfx, element.width, element.height, attrs);
|
14378 | },
|
14379 | 'bpmn:StartEvent': function(parentGfx, element) {
|
14380 | var attrs = {
|
14381 | fill: getFillColor(element, defaultFillColor),
|
14382 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14383 | };
|
14384 |
|
14385 | var semantic = getSemantic(element);
|
14386 |
|
14387 | if (!semantic.isInterrupting) {
|
14388 | attrs = {
|
14389 | strokeDasharray: '6',
|
14390 | strokeLinecap: 'round',
|
14391 | fill: getFillColor(element, defaultFillColor),
|
14392 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14393 | };
|
14394 | }
|
14395 |
|
14396 | var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
|
14397 |
|
14398 | renderEventContent(element, parentGfx);
|
14399 |
|
14400 | return circle;
|
14401 | },
|
14402 | 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
|
14403 | var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
|
14404 | xScaleFactor: 0.9,
|
14405 | yScaleFactor: 0.9,
|
14406 | containerWidth: element.width,
|
14407 | containerHeight: element.height,
|
14408 | position: {
|
14409 | mx: 0.235,
|
14410 | my: 0.315
|
14411 | }
|
14412 | });
|
14413 |
|
14414 | var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
|
14415 | var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
|
14416 |
|
14417 | var messagePath = drawPath(parentGfx, pathData, {
|
14418 | strokeWidth: 1,
|
14419 | fill: fill,
|
14420 | stroke: stroke
|
14421 | });
|
14422 |
|
14423 | return messagePath;
|
14424 | },
|
14425 | 'bpmn:TimerEventDefinition': function(parentGfx, element) {
|
14426 | var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
|
14427 | strokeWidth: 2,
|
14428 | fill: getFillColor(element, defaultFillColor),
|
14429 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14430 | });
|
14431 |
|
14432 | var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
|
14433 | xScaleFactor: 0.75,
|
14434 | yScaleFactor: 0.75,
|
14435 | containerWidth: element.width,
|
14436 | containerHeight: element.height,
|
14437 | position: {
|
14438 | mx: 0.5,
|
14439 | my: 0.5
|
14440 | }
|
14441 | });
|
14442 |
|
14443 | drawPath(parentGfx, pathData, {
|
14444 | strokeWidth: 2,
|
14445 | strokeLinecap: 'square',
|
14446 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14447 | });
|
14448 |
|
14449 | for (var i = 0;i < 12; i++) {
|
14450 |
|
14451 | var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
|
14452 | xScaleFactor: 0.75,
|
14453 | yScaleFactor: 0.75,
|
14454 | containerWidth: element.width,
|
14455 | containerHeight: element.height,
|
14456 | position: {
|
14457 | mx: 0.5,
|
14458 | my: 0.5
|
14459 | }
|
14460 | });
|
14461 |
|
14462 | var width = element.width / 2;
|
14463 | var height = element.height / 2;
|
14464 |
|
14465 | drawPath(parentGfx, linePathData, {
|
14466 | strokeWidth: 1,
|
14467 | strokeLinecap: 'square',
|
14468 | transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
|
14469 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14470 | });
|
14471 | }
|
14472 |
|
14473 | return circle;
|
14474 | },
|
14475 | 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
|
14476 | var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
|
14477 | xScaleFactor: 1,
|
14478 | yScaleFactor: 1,
|
14479 | containerWidth: event.width,
|
14480 | containerHeight: event.height,
|
14481 | position: {
|
14482 | mx: 0.5,
|
14483 | my: 0.2
|
14484 | }
|
14485 | });
|
14486 |
|
14487 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14488 |
|
14489 | return drawPath(parentGfx, pathData, {
|
14490 | strokeWidth: 1,
|
14491 | fill: fill,
|
14492 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14493 | });
|
14494 | },
|
14495 | 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
|
14496 | var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
|
14497 | xScaleFactor: 1,
|
14498 | yScaleFactor: 1,
|
14499 | containerWidth: event.width,
|
14500 | containerHeight: event.height,
|
14501 | position: {
|
14502 | mx: 0.5,
|
14503 | my: 0.222
|
14504 | }
|
14505 | });
|
14506 |
|
14507 | return drawPath(parentGfx, pathData, {
|
14508 | strokeWidth: 1,
|
14509 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14510 | });
|
14511 | },
|
14512 | 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
|
14513 | var pathData = pathMap.getScaledPath('EVENT_LINK', {
|
14514 | xScaleFactor: 1,
|
14515 | yScaleFactor: 1,
|
14516 | containerWidth: event.width,
|
14517 | containerHeight: event.height,
|
14518 | position: {
|
14519 | mx: 0.57,
|
14520 | my: 0.263
|
14521 | }
|
14522 | });
|
14523 |
|
14524 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14525 |
|
14526 | return drawPath(parentGfx, pathData, {
|
14527 | strokeWidth: 1,
|
14528 | fill: fill,
|
14529 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14530 | });
|
14531 | },
|
14532 | 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
|
14533 | var pathData = pathMap.getScaledPath('EVENT_ERROR', {
|
14534 | xScaleFactor: 1.1,
|
14535 | yScaleFactor: 1.1,
|
14536 | containerWidth: event.width,
|
14537 | containerHeight: event.height,
|
14538 | position: {
|
14539 | mx: 0.2,
|
14540 | my: 0.722
|
14541 | }
|
14542 | });
|
14543 |
|
14544 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14545 |
|
14546 | return drawPath(parentGfx, pathData, {
|
14547 | strokeWidth: 1,
|
14548 | fill: fill,
|
14549 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14550 | });
|
14551 | },
|
14552 | 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
|
14553 | var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
|
14554 | xScaleFactor: 1.0,
|
14555 | yScaleFactor: 1.0,
|
14556 | containerWidth: event.width,
|
14557 | containerHeight: event.height,
|
14558 | position: {
|
14559 | mx: 0.638,
|
14560 | my: -0.055
|
14561 | }
|
14562 | });
|
14563 |
|
14564 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14565 |
|
14566 | var path = drawPath(parentGfx, pathData, {
|
14567 | strokeWidth: 1,
|
14568 | fill: fill,
|
14569 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14570 | });
|
14571 |
|
14572 | rotate(path, 45);
|
14573 |
|
14574 | return path;
|
14575 | },
|
14576 | 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
|
14577 | var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
|
14578 | xScaleFactor: 1,
|
14579 | yScaleFactor: 1,
|
14580 | containerWidth: event.width,
|
14581 | containerHeight: event.height,
|
14582 | position: {
|
14583 | mx: 0.22,
|
14584 | my: 0.5
|
14585 | }
|
14586 | });
|
14587 |
|
14588 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14589 |
|
14590 | return drawPath(parentGfx, pathData, {
|
14591 | strokeWidth: 1,
|
14592 | fill: fill,
|
14593 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14594 | });
|
14595 | },
|
14596 | 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
|
14597 | var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
|
14598 | xScaleFactor: 0.9,
|
14599 | yScaleFactor: 0.9,
|
14600 | containerWidth: event.width,
|
14601 | containerHeight: event.height,
|
14602 | position: {
|
14603 | mx: 0.5,
|
14604 | my: 0.2
|
14605 | }
|
14606 | });
|
14607 |
|
14608 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14609 |
|
14610 | return drawPath(parentGfx, pathData, {
|
14611 | strokeWidth: 1,
|
14612 | fill: fill,
|
14613 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14614 | });
|
14615 | },
|
14616 | 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
|
14617 | var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
|
14618 | xScaleFactor: 1.1,
|
14619 | yScaleFactor: 1.1,
|
14620 | containerWidth: event.width,
|
14621 | containerHeight: event.height,
|
14622 | position: {
|
14623 | mx: 0.222,
|
14624 | my: 0.36
|
14625 | }
|
14626 | });
|
14627 |
|
14628 | var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
|
14629 |
|
14630 | return drawPath(parentGfx, pathData, {
|
14631 | strokeWidth: 1,
|
14632 | fill: fill
|
14633 | });
|
14634 | },
|
14635 | 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
|
14636 | var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
|
14637 | xScaleFactor: 1.2,
|
14638 | yScaleFactor: 1.2,
|
14639 | containerWidth: event.width,
|
14640 | containerHeight: event.height,
|
14641 | position: {
|
14642 | mx: 0.458,
|
14643 | my: 0.194
|
14644 | }
|
14645 | });
|
14646 |
|
14647 | return drawPath(parentGfx, pathData, {
|
14648 | strokeWidth: 1,
|
14649 | fill: getStrokeColor(event, defaultStrokeColor),
|
14650 | stroke: getStrokeColor(event, defaultStrokeColor)
|
14651 | });
|
14652 | },
|
14653 | 'bpmn:EndEvent': function(parentGfx, element) {
|
14654 | var circle = renderer('bpmn:Event')(parentGfx, element, {
|
14655 | strokeWidth: 4,
|
14656 | fill: getFillColor(element, defaultFillColor),
|
14657 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14658 | });
|
14659 |
|
14660 | renderEventContent(element, parentGfx, true);
|
14661 |
|
14662 | return circle;
|
14663 | },
|
14664 | 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
|
14665 | var circle = drawCircle(parentGfx, element.width, element.height, 8, {
|
14666 | strokeWidth: 4,
|
14667 | fill: getStrokeColor(element, defaultStrokeColor),
|
14668 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14669 | });
|
14670 |
|
14671 | return circle;
|
14672 | },
|
14673 | 'bpmn:IntermediateEvent': function(parentGfx, element) {
|
14674 | var outer = renderer('bpmn:Event')(parentGfx, element, {
|
14675 | strokeWidth: 1,
|
14676 | fill: getFillColor(element, defaultFillColor),
|
14677 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14678 | });
|
14679 |
|
14680 |
|
14681 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
|
14682 | strokeWidth: 1,
|
14683 | fill: getFillColor(element, 'none'),
|
14684 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14685 | });
|
14686 |
|
14687 | renderEventContent(element, parentGfx);
|
14688 |
|
14689 | return outer;
|
14690 | },
|
14691 | 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
|
14692 | 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
|
14693 |
|
14694 | 'bpmn:Activity': function(parentGfx, element, attrs) {
|
14695 |
|
14696 | attrs = attrs || {};
|
14697 |
|
14698 | if (!('fillOpacity' in attrs)) {
|
14699 | attrs.fillOpacity = DEFAULT_FILL_OPACITY;
|
14700 | }
|
14701 |
|
14702 | return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
|
14703 | },
|
14704 |
|
14705 | 'bpmn:Task': function(parentGfx, element) {
|
14706 | var attrs = {
|
14707 | fill: getFillColor(element, defaultFillColor),
|
14708 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14709 | };
|
14710 |
|
14711 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
14712 |
|
14713 | renderEmbeddedLabel(parentGfx, element, 'center-middle');
|
14714 | attachTaskMarkers(parentGfx, element);
|
14715 |
|
14716 | return rect;
|
14717 | },
|
14718 | 'bpmn:ServiceTask': function(parentGfx, element) {
|
14719 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14720 |
|
14721 | var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
14722 | abspos: {
|
14723 | x: 12,
|
14724 | y: 18
|
14725 | }
|
14726 | });
|
14727 |
|
14728 | drawPath(parentGfx, pathDataBG, {
|
14729 | strokeWidth: 1,
|
14730 | fill: getFillColor(element, defaultFillColor),
|
14731 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14732 | });
|
14733 |
|
14734 | var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
|
14735 | abspos: {
|
14736 | x: 17.2,
|
14737 | y: 18
|
14738 | }
|
14739 | });
|
14740 |
|
14741 | drawPath(parentGfx, fillPathData, {
|
14742 | strokeWidth: 0,
|
14743 | fill: getFillColor(element, defaultFillColor)
|
14744 | });
|
14745 |
|
14746 | var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
|
14747 | abspos: {
|
14748 | x: 17,
|
14749 | y: 22
|
14750 | }
|
14751 | });
|
14752 |
|
14753 | drawPath(parentGfx, pathData, {
|
14754 | strokeWidth: 1,
|
14755 | fill: getFillColor(element, defaultFillColor),
|
14756 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14757 | });
|
14758 |
|
14759 | return task;
|
14760 | },
|
14761 | 'bpmn:UserTask': function(parentGfx, element) {
|
14762 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14763 |
|
14764 | var x = 15;
|
14765 | var y = 12;
|
14766 |
|
14767 | var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
|
14768 | abspos: {
|
14769 | x: x,
|
14770 | y: y
|
14771 | }
|
14772 | });
|
14773 |
|
14774 | drawPath(parentGfx, pathData, {
|
14775 | strokeWidth: 0.5,
|
14776 | fill: getFillColor(element, defaultFillColor),
|
14777 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14778 | });
|
14779 |
|
14780 | var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
|
14781 | abspos: {
|
14782 | x: x,
|
14783 | y: y
|
14784 | }
|
14785 | });
|
14786 |
|
14787 | drawPath(parentGfx, pathData2, {
|
14788 | strokeWidth: 0.5,
|
14789 | fill: getFillColor(element, defaultFillColor),
|
14790 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14791 | });
|
14792 |
|
14793 | var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
|
14794 | abspos: {
|
14795 | x: x,
|
14796 | y: y
|
14797 | }
|
14798 | });
|
14799 |
|
14800 | drawPath(parentGfx, pathData3, {
|
14801 | strokeWidth: 0.5,
|
14802 | fill: getStrokeColor(element, defaultStrokeColor),
|
14803 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14804 | });
|
14805 |
|
14806 | return task;
|
14807 | },
|
14808 | 'bpmn:ManualTask': function(parentGfx, element) {
|
14809 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14810 |
|
14811 | var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
|
14812 | abspos: {
|
14813 | x: 17,
|
14814 | y: 15
|
14815 | }
|
14816 | });
|
14817 |
|
14818 | drawPath(parentGfx, pathData, {
|
14819 | strokeWidth: 0.5,
|
14820 | fill: getFillColor(element, defaultFillColor),
|
14821 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14822 | });
|
14823 |
|
14824 | return task;
|
14825 | },
|
14826 | 'bpmn:SendTask': function(parentGfx, element) {
|
14827 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14828 |
|
14829 | var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
14830 | xScaleFactor: 1,
|
14831 | yScaleFactor: 1,
|
14832 | containerWidth: 21,
|
14833 | containerHeight: 14,
|
14834 | position: {
|
14835 | mx: 0.285,
|
14836 | my: 0.357
|
14837 | }
|
14838 | });
|
14839 |
|
14840 | drawPath(parentGfx, pathData, {
|
14841 | strokeWidth: 1,
|
14842 | fill: getStrokeColor(element, defaultStrokeColor),
|
14843 | stroke: getFillColor(element, defaultFillColor)
|
14844 | });
|
14845 |
|
14846 | return task;
|
14847 | },
|
14848 | 'bpmn:ReceiveTask' : function(parentGfx, element) {
|
14849 | var semantic = getSemantic(element);
|
14850 |
|
14851 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14852 | var pathData;
|
14853 |
|
14854 | if (semantic.instantiate) {
|
14855 | drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
|
14856 |
|
14857 | pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
|
14858 | abspos: {
|
14859 | x: 7.77,
|
14860 | y: 9.52
|
14861 | }
|
14862 | });
|
14863 | } else {
|
14864 |
|
14865 | pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
|
14866 | xScaleFactor: 0.9,
|
14867 | yScaleFactor: 0.9,
|
14868 | containerWidth: 21,
|
14869 | containerHeight: 14,
|
14870 | position: {
|
14871 | mx: 0.3,
|
14872 | my: 0.4
|
14873 | }
|
14874 | });
|
14875 | }
|
14876 |
|
14877 | drawPath(parentGfx, pathData, {
|
14878 | strokeWidth: 1,
|
14879 | fill: getFillColor(element, defaultFillColor),
|
14880 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14881 | });
|
14882 |
|
14883 | return task;
|
14884 | },
|
14885 | 'bpmn:ScriptTask': function(parentGfx, element) {
|
14886 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14887 |
|
14888 | var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
|
14889 | abspos: {
|
14890 | x: 15,
|
14891 | y: 20
|
14892 | }
|
14893 | });
|
14894 |
|
14895 | drawPath(parentGfx, pathData, {
|
14896 | strokeWidth: 1,
|
14897 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14898 | });
|
14899 |
|
14900 | return task;
|
14901 | },
|
14902 | 'bpmn:BusinessRuleTask': function(parentGfx, element) {
|
14903 | var task = renderer('bpmn:Task')(parentGfx, element);
|
14904 |
|
14905 | var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
|
14906 | abspos: {
|
14907 | x: 8,
|
14908 | y: 8
|
14909 | }
|
14910 | });
|
14911 |
|
14912 | var businessHeaderPath = drawPath(parentGfx, headerPathData);
|
14913 | attr$1(businessHeaderPath, {
|
14914 | strokeWidth: 1,
|
14915 | fill: getFillColor(element, '#aaaaaa'),
|
14916 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14917 | });
|
14918 |
|
14919 | var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
|
14920 | abspos: {
|
14921 | x: 8,
|
14922 | y: 8
|
14923 | }
|
14924 | });
|
14925 |
|
14926 | var businessPath = drawPath(parentGfx, headerData);
|
14927 | attr$1(businessPath, {
|
14928 | strokeWidth: 1,
|
14929 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14930 | });
|
14931 |
|
14932 | return task;
|
14933 | },
|
14934 | 'bpmn:SubProcess': function(parentGfx, element, attrs) {
|
14935 | attrs = assign({
|
14936 | fill: getFillColor(element, defaultFillColor),
|
14937 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14938 | }, attrs);
|
14939 |
|
14940 | var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
|
14941 |
|
14942 | var expanded = isExpanded(element);
|
14943 |
|
14944 | if (isEventSubProcess(element)) {
|
14945 | attr$1(rect, {
|
14946 | strokeDasharray: '1,2'
|
14947 | });
|
14948 | }
|
14949 |
|
14950 | renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
|
14951 |
|
14952 | if (expanded) {
|
14953 | attachTaskMarkers(parentGfx, element);
|
14954 | } else {
|
14955 | attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
|
14956 | }
|
14957 |
|
14958 | return rect;
|
14959 | },
|
14960 | 'bpmn:AdHocSubProcess': function(parentGfx, element) {
|
14961 | return renderer('bpmn:SubProcess')(parentGfx, element);
|
14962 | },
|
14963 | 'bpmn:Transaction': function(parentGfx, element) {
|
14964 | var outer = renderer('bpmn:SubProcess')(parentGfx, element);
|
14965 |
|
14966 | var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
|
14967 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14968 | });
|
14969 |
|
14970 | drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
|
14971 |
|
14972 | return outer;
|
14973 | },
|
14974 | 'bpmn:CallActivity': function(parentGfx, element) {
|
14975 | return renderer('bpmn:SubProcess')(parentGfx, element, {
|
14976 | strokeWidth: 5
|
14977 | });
|
14978 | },
|
14979 | 'bpmn:Participant': function(parentGfx, element) {
|
14980 |
|
14981 | var attrs = {
|
14982 | fillOpacity: DEFAULT_FILL_OPACITY,
|
14983 | fill: getFillColor(element, defaultFillColor),
|
14984 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14985 | };
|
14986 |
|
14987 | var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
|
14988 |
|
14989 | var expandedPool = isExpanded(element);
|
14990 |
|
14991 | if (expandedPool) {
|
14992 | drawLine(parentGfx, [
|
14993 | { x: 30, y: 0 },
|
14994 | { x: 30, y: element.height }
|
14995 | ], {
|
14996 | stroke: getStrokeColor(element, defaultStrokeColor)
|
14997 | });
|
14998 | var text = getSemantic(element).name;
|
14999 | renderLaneLabel(parentGfx, text, element);
|
15000 | } else {
|
15001 |
|
15002 | var text2 = getSemantic(element).name;
|
15003 | renderLabel(parentGfx, text2, {
|
15004 | box: element, align: 'center-middle',
|
15005 | style: {
|
15006 | fill: getStrokeColor(element, defaultStrokeColor)
|
15007 | }
|
15008 | });
|
15009 | }
|
15010 |
|
15011 | var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
|
15012 |
|
15013 | if (participantMultiplicity) {
|
15014 | renderer('ParticipantMultiplicityMarker')(parentGfx, element);
|
15015 | }
|
15016 |
|
15017 | return lane;
|
15018 | },
|
15019 | 'bpmn:Lane': function(parentGfx, element, attrs) {
|
15020 | var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
|
15021 | fill: getFillColor(element, defaultFillColor),
|
15022 | fillOpacity: HIGH_FILL_OPACITY,
|
15023 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15024 | }, attrs));
|
15025 |
|
15026 | var semantic = getSemantic(element);
|
15027 |
|
15028 | if (semantic.$type === 'bpmn:Lane') {
|
15029 | var text = semantic.name;
|
15030 | renderLaneLabel(parentGfx, text, element);
|
15031 | }
|
15032 |
|
15033 | return rect;
|
15034 | },
|
15035 | 'bpmn:InclusiveGateway': function(parentGfx, element) {
|
15036 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15037 |
|
15038 |
|
15039 | drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
|
15040 | strokeWidth: 2.5,
|
15041 | fill: getFillColor(element, defaultFillColor),
|
15042 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15043 | });
|
15044 |
|
15045 | return diamond;
|
15046 | },
|
15047 | 'bpmn:ExclusiveGateway': function(parentGfx, element) {
|
15048 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15049 |
|
15050 | var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
|
15051 | xScaleFactor: 0.4,
|
15052 | yScaleFactor: 0.4,
|
15053 | containerWidth: element.width,
|
15054 | containerHeight: element.height,
|
15055 | position: {
|
15056 | mx: 0.32,
|
15057 | my: 0.3
|
15058 | }
|
15059 | });
|
15060 |
|
15061 | if ((getDi(element).isMarkerVisible)) {
|
15062 | drawPath(parentGfx, pathData, {
|
15063 | strokeWidth: 1,
|
15064 | fill: getStrokeColor(element, defaultStrokeColor),
|
15065 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15066 | });
|
15067 | }
|
15068 |
|
15069 | return diamond;
|
15070 | },
|
15071 | 'bpmn:ComplexGateway': function(parentGfx, element) {
|
15072 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15073 |
|
15074 | var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
|
15075 | xScaleFactor: 0.5,
|
15076 | yScaleFactor:0.5,
|
15077 | containerWidth: element.width,
|
15078 | containerHeight: element.height,
|
15079 | position: {
|
15080 | mx: 0.46,
|
15081 | my: 0.26
|
15082 | }
|
15083 | });
|
15084 |
|
15085 | drawPath(parentGfx, pathData, {
|
15086 | strokeWidth: 1,
|
15087 | fill: getStrokeColor(element, defaultStrokeColor),
|
15088 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15089 | });
|
15090 |
|
15091 | return diamond;
|
15092 | },
|
15093 | 'bpmn:ParallelGateway': function(parentGfx, element) {
|
15094 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15095 |
|
15096 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
15097 | xScaleFactor: 0.6,
|
15098 | yScaleFactor:0.6,
|
15099 | containerWidth: element.width,
|
15100 | containerHeight: element.height,
|
15101 | position: {
|
15102 | mx: 0.46,
|
15103 | my: 0.2
|
15104 | }
|
15105 | });
|
15106 |
|
15107 | drawPath(parentGfx, pathData, {
|
15108 | strokeWidth: 1,
|
15109 | fill: getStrokeColor(element, defaultStrokeColor),
|
15110 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15111 | });
|
15112 |
|
15113 | return diamond;
|
15114 | },
|
15115 | 'bpmn:EventBasedGateway': function(parentGfx, element) {
|
15116 |
|
15117 | var semantic = getSemantic(element);
|
15118 |
|
15119 | var diamond = renderer('bpmn:Gateway')(parentGfx, element);
|
15120 |
|
15121 | drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
|
15122 | strokeWidth: 1,
|
15123 | fill: 'none',
|
15124 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15125 | });
|
15126 |
|
15127 | var type = semantic.eventGatewayType;
|
15128 | var instantiate = !!semantic.instantiate;
|
15129 |
|
15130 | function drawEvent() {
|
15131 |
|
15132 | var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
|
15133 | xScaleFactor: 0.18,
|
15134 | yScaleFactor: 0.18,
|
15135 | containerWidth: element.width,
|
15136 | containerHeight: element.height,
|
15137 | position: {
|
15138 | mx: 0.36,
|
15139 | my: 0.44
|
15140 | }
|
15141 | });
|
15142 |
|
15143 | var attrs = {
|
15144 | strokeWidth: 2,
|
15145 | fill: getFillColor(element, 'none'),
|
15146 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15147 | };
|
15148 |
|
15149 | drawPath(parentGfx, pathData, attrs);
|
15150 | }
|
15151 |
|
15152 | if (type === 'Parallel') {
|
15153 |
|
15154 | var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
|
15155 | xScaleFactor: 0.4,
|
15156 | yScaleFactor:0.4,
|
15157 | containerWidth: element.width,
|
15158 | containerHeight: element.height,
|
15159 | position: {
|
15160 | mx: 0.474,
|
15161 | my: 0.296
|
15162 | }
|
15163 | });
|
15164 |
|
15165 | var parallelPath = drawPath(parentGfx, pathData);
|
15166 | attr$1(parallelPath, {
|
15167 | strokeWidth: 1,
|
15168 | fill: 'none'
|
15169 | });
|
15170 | } else if (type === 'Exclusive') {
|
15171 |
|
15172 | if (!instantiate) {
|
15173 | var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
|
15174 | attr$1(innerCircle, {
|
15175 | strokeWidth: 1,
|
15176 | fill: 'none',
|
15177 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15178 | });
|
15179 | }
|
15180 |
|
15181 | drawEvent();
|
15182 | }
|
15183 |
|
15184 |
|
15185 | return diamond;
|
15186 | },
|
15187 | 'bpmn:Gateway': function(parentGfx, element) {
|
15188 | var attrs = {
|
15189 | fill: getFillColor(element, defaultFillColor),
|
15190 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15191 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15192 | };
|
15193 |
|
15194 | return drawDiamond(parentGfx, element.width, element.height, attrs);
|
15195 | },
|
15196 | 'bpmn:SequenceFlow': function(parentGfx, element) {
|
15197 | var pathData = createPathFromConnection(element);
|
15198 |
|
15199 | var fill = getFillColor(element, defaultFillColor),
|
15200 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15201 |
|
15202 | var attrs = {
|
15203 | strokeLinejoin: 'round',
|
15204 | markerEnd: marker('sequenceflow-end', fill, stroke),
|
15205 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15206 | };
|
15207 |
|
15208 | var path = drawPath(parentGfx, pathData, attrs);
|
15209 |
|
15210 | var sequenceFlow = getSemantic(element);
|
15211 |
|
15212 | var source;
|
15213 |
|
15214 | if (element.source) {
|
15215 | source = element.source.businessObject;
|
15216 |
|
15217 |
|
15218 | if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
|
15219 | attr$1(path, {
|
15220 | markerStart: marker('conditional-flow-marker', fill, stroke)
|
15221 | });
|
15222 | }
|
15223 |
|
15224 |
|
15225 | if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
|
15226 | source.default === sequenceFlow) {
|
15227 | attr$1(path, {
|
15228 | markerStart: marker('conditional-default-flow-marker', fill, stroke)
|
15229 | });
|
15230 | }
|
15231 | }
|
15232 |
|
15233 | return path;
|
15234 | },
|
15235 | 'bpmn:Association': function(parentGfx, element, attrs) {
|
15236 |
|
15237 | var semantic = getSemantic(element);
|
15238 |
|
15239 | var fill = getFillColor(element, defaultFillColor),
|
15240 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15241 |
|
15242 | attrs = assign({
|
15243 | strokeDasharray: '0.5, 5',
|
15244 | strokeLinecap: 'round',
|
15245 | strokeLinejoin: 'round',
|
15246 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15247 | }, attrs || {});
|
15248 |
|
15249 | if (semantic.associationDirection === 'One' ||
|
15250 | semantic.associationDirection === 'Both') {
|
15251 | attrs.markerEnd = marker('association-end', fill, stroke);
|
15252 | }
|
15253 |
|
15254 | if (semantic.associationDirection === 'Both') {
|
15255 | attrs.markerStart = marker('association-start', fill, stroke);
|
15256 | }
|
15257 |
|
15258 | return drawLine(parentGfx, element.waypoints, attrs);
|
15259 | },
|
15260 | 'bpmn:DataInputAssociation': function(parentGfx, element) {
|
15261 | var fill = getFillColor(element, defaultFillColor),
|
15262 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15263 |
|
15264 | return renderer('bpmn:Association')(parentGfx, element, {
|
15265 | markerEnd: marker('association-end', fill, stroke)
|
15266 | });
|
15267 | },
|
15268 | 'bpmn:DataOutputAssociation': function(parentGfx, element) {
|
15269 | var fill = getFillColor(element, defaultFillColor),
|
15270 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15271 |
|
15272 | return renderer('bpmn:Association')(parentGfx, element, {
|
15273 | markerEnd: marker('association-end', fill, stroke)
|
15274 | });
|
15275 | },
|
15276 | 'bpmn:MessageFlow': function(parentGfx, element) {
|
15277 |
|
15278 | var semantic = getSemantic(element),
|
15279 | di = getDi(element);
|
15280 |
|
15281 | var fill = getFillColor(element, defaultFillColor),
|
15282 | stroke = getStrokeColor(element, defaultStrokeColor);
|
15283 |
|
15284 | var pathData = createPathFromConnection(element);
|
15285 |
|
15286 | var attrs = {
|
15287 | markerEnd: marker('messageflow-end', fill, stroke),
|
15288 | markerStart: marker('messageflow-start', fill, stroke),
|
15289 | strokeDasharray: '10, 12',
|
15290 | strokeLinecap: 'round',
|
15291 | strokeLinejoin: 'round',
|
15292 | strokeWidth: '1.5px',
|
15293 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15294 | };
|
15295 |
|
15296 | var path = drawPath(parentGfx, pathData, attrs);
|
15297 |
|
15298 | if (semantic.messageRef) {
|
15299 | var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
|
15300 |
|
15301 | var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
|
15302 | abspos: {
|
15303 | x: midPoint.x,
|
15304 | y: midPoint.y
|
15305 | }
|
15306 | });
|
15307 |
|
15308 | var messageAttrs = { strokeWidth: 1 };
|
15309 |
|
15310 | if (di.messageVisibleKind === 'initiating') {
|
15311 | messageAttrs.fill = 'white';
|
15312 | messageAttrs.stroke = 'black';
|
15313 | } else {
|
15314 | messageAttrs.fill = '#888';
|
15315 | messageAttrs.stroke = 'white';
|
15316 | }
|
15317 |
|
15318 | drawPath(parentGfx, markerPathData, messageAttrs);
|
15319 | }
|
15320 |
|
15321 | return path;
|
15322 | },
|
15323 | 'bpmn:DataObject': function(parentGfx, element) {
|
15324 | var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
|
15325 | xScaleFactor: 1,
|
15326 | yScaleFactor: 1,
|
15327 | containerWidth: element.width,
|
15328 | containerHeight: element.height,
|
15329 | position: {
|
15330 | mx: 0.474,
|
15331 | my: 0.296
|
15332 | }
|
15333 | });
|
15334 |
|
15335 | var elementObject = drawPath(parentGfx, pathData, {
|
15336 | fill: getFillColor(element, defaultFillColor),
|
15337 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15338 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15339 | });
|
15340 |
|
15341 | var semantic = getSemantic(element);
|
15342 |
|
15343 | if (isCollection(semantic)) {
|
15344 | renderDataItemCollection(parentGfx, element);
|
15345 | }
|
15346 |
|
15347 | return elementObject;
|
15348 | },
|
15349 | 'bpmn:DataObjectReference': as('bpmn:DataObject'),
|
15350 | 'bpmn:DataInput': function(parentGfx, element) {
|
15351 |
|
15352 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
15353 |
|
15354 |
|
15355 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
15356 |
|
15357 | drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
|
15358 |
|
15359 | return elementObject;
|
15360 | },
|
15361 | 'bpmn:DataOutput': function(parentGfx, element) {
|
15362 | var arrowPathData = pathMap.getRawPath('DATA_ARROW');
|
15363 |
|
15364 |
|
15365 | var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
|
15366 |
|
15367 | drawPath(parentGfx, arrowPathData, {
|
15368 | strokeWidth: 1,
|
15369 | fill: 'black'
|
15370 | });
|
15371 |
|
15372 | return elementObject;
|
15373 | },
|
15374 | 'bpmn:DataStoreReference': function(parentGfx, element) {
|
15375 | var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
|
15376 | xScaleFactor: 1,
|
15377 | yScaleFactor: 1,
|
15378 | containerWidth: element.width,
|
15379 | containerHeight: element.height,
|
15380 | position: {
|
15381 | mx: 0,
|
15382 | my: 0.133
|
15383 | }
|
15384 | });
|
15385 |
|
15386 | var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
|
15387 | strokeWidth: 2,
|
15388 | fill: getFillColor(element, defaultFillColor),
|
15389 | fillOpacity: DEFAULT_FILL_OPACITY,
|
15390 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15391 | });
|
15392 |
|
15393 | return elementStore;
|
15394 | },
|
15395 | 'bpmn:BoundaryEvent': function(parentGfx, element) {
|
15396 |
|
15397 | var semantic = getSemantic(element),
|
15398 | cancel = semantic.cancelActivity;
|
15399 |
|
15400 | var attrs = {
|
15401 | strokeWidth: 1,
|
15402 | fill: getFillColor(element, defaultFillColor),
|
15403 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15404 | };
|
15405 |
|
15406 | if (!cancel) {
|
15407 | attrs.strokeDasharray = '6';
|
15408 | attrs.strokeLinecap = 'round';
|
15409 | }
|
15410 |
|
15411 |
|
15412 | var outerAttrs = assign({}, attrs, {
|
15413 | fillOpacity: 1
|
15414 | });
|
15415 |
|
15416 |
|
15417 | var innerAttrs = assign({}, attrs, {
|
15418 | fill: 'none'
|
15419 | });
|
15420 |
|
15421 | var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
|
15422 |
|
15423 | drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
|
15424 |
|
15425 | renderEventContent(element, parentGfx);
|
15426 |
|
15427 | return outer;
|
15428 | },
|
15429 | 'bpmn:Group': function(parentGfx, element) {
|
15430 | var semantic = getSemantic(element),
|
15431 | di = getDi(element);
|
15432 |
|
15433 | var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
|
15434 | strokeWidth: 1,
|
15435 | strokeDasharray: '8,3,1,3',
|
15436 | fill: 'none',
|
15437 | pointerEvents: 'none'
|
15438 | });
|
15439 |
|
15440 | var categoryValueRef = semantic.categoryValueRef || {};
|
15441 |
|
15442 | if (categoryValueRef.value) {
|
15443 | var box = di.label ? di.label.bounds : element;
|
15444 |
|
15445 | renderLabel(parentGfx, categoryValueRef.value, {
|
15446 | box: box,
|
15447 | style: {
|
15448 | fill: getStrokeColor(element, defaultStrokeColor)
|
15449 | }
|
15450 | });
|
15451 | }
|
15452 |
|
15453 | return group;
|
15454 | },
|
15455 | 'label': function(parentGfx, element) {
|
15456 | return renderExternalLabel(parentGfx, element);
|
15457 | },
|
15458 | 'bpmn:TextAnnotation': function(parentGfx, element) {
|
15459 | var style = {
|
15460 | 'fill': 'none',
|
15461 | 'stroke': 'none'
|
15462 | };
|
15463 |
|
15464 | var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
|
15465 |
|
15466 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
15467 | xScaleFactor: 1,
|
15468 | yScaleFactor: 1,
|
15469 | containerWidth: element.width,
|
15470 | containerHeight: element.height,
|
15471 | position: {
|
15472 | mx: 0.0,
|
15473 | my: 0.0
|
15474 | }
|
15475 | });
|
15476 |
|
15477 | drawPath(parentGfx, textPathData, {
|
15478 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15479 | });
|
15480 |
|
15481 | var text = getSemantic(element).text || '';
|
15482 | renderLabel(parentGfx, text, {
|
15483 | box: element,
|
15484 | align: 'left-top',
|
15485 | padding: 5,
|
15486 | style: {
|
15487 | fill: getStrokeColor(element, defaultStrokeColor)
|
15488 | }
|
15489 | });
|
15490 |
|
15491 | return textElement;
|
15492 | },
|
15493 | 'ParticipantMultiplicityMarker': function(parentGfx, element) {
|
15494 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
15495 | xScaleFactor: 1,
|
15496 | yScaleFactor: 1,
|
15497 | containerWidth: element.width,
|
15498 | containerHeight: element.height,
|
15499 | position: {
|
15500 | mx: ((element.width / 2) / element.width),
|
15501 | my: (element.height - 15) / element.height
|
15502 | }
|
15503 | });
|
15504 |
|
15505 | drawMarker('participant-multiplicity', parentGfx, markerPath, {
|
15506 | strokeWidth: 1,
|
15507 | fill: getFillColor(element, defaultFillColor),
|
15508 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15509 | });
|
15510 | },
|
15511 | 'SubProcessMarker': function(parentGfx, element) {
|
15512 | var markerRect = drawRect(parentGfx, 14, 14, 0, {
|
15513 | strokeWidth: 1,
|
15514 | fill: getFillColor(element, defaultFillColor),
|
15515 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15516 | });
|
15517 |
|
15518 |
|
15519 |
|
15520 | translate(markerRect, element.width / 2 - 7.5, element.height - 20);
|
15521 |
|
15522 | var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
|
15523 | xScaleFactor: 1.5,
|
15524 | yScaleFactor: 1.5,
|
15525 | containerWidth: element.width,
|
15526 | containerHeight: element.height,
|
15527 | position: {
|
15528 | mx: (element.width / 2 - 7.5) / element.width,
|
15529 | my: (element.height - 20) / element.height
|
15530 | }
|
15531 | });
|
15532 |
|
15533 | drawMarker('sub-process', parentGfx, markerPath, {
|
15534 | fill: getFillColor(element, defaultFillColor),
|
15535 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15536 | });
|
15537 | },
|
15538 | 'ParallelMarker': function(parentGfx, element, position) {
|
15539 | var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
|
15540 | xScaleFactor: 1,
|
15541 | yScaleFactor: 1,
|
15542 | containerWidth: element.width,
|
15543 | containerHeight: element.height,
|
15544 | position: {
|
15545 | mx: ((element.width / 2 + position.parallel) / element.width),
|
15546 | my: (element.height - 20) / element.height
|
15547 | }
|
15548 | });
|
15549 |
|
15550 | drawMarker('parallel', parentGfx, markerPath, {
|
15551 | fill: getFillColor(element, defaultFillColor),
|
15552 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15553 | });
|
15554 | },
|
15555 | 'SequentialMarker': function(parentGfx, element, position) {
|
15556 | var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
|
15557 | xScaleFactor: 1,
|
15558 | yScaleFactor: 1,
|
15559 | containerWidth: element.width,
|
15560 | containerHeight: element.height,
|
15561 | position: {
|
15562 | mx: ((element.width / 2 + position.seq) / element.width),
|
15563 | my: (element.height - 19) / element.height
|
15564 | }
|
15565 | });
|
15566 |
|
15567 | drawMarker('sequential', parentGfx, markerPath, {
|
15568 | fill: getFillColor(element, defaultFillColor),
|
15569 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15570 | });
|
15571 | },
|
15572 | 'CompensationMarker': function(parentGfx, element, position) {
|
15573 | var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
|
15574 | xScaleFactor: 1,
|
15575 | yScaleFactor: 1,
|
15576 | containerWidth: element.width,
|
15577 | containerHeight: element.height,
|
15578 | position: {
|
15579 | mx: ((element.width / 2 + position.compensation) / element.width),
|
15580 | my: (element.height - 13) / element.height
|
15581 | }
|
15582 | });
|
15583 |
|
15584 | drawMarker('compensation', parentGfx, markerMath, {
|
15585 | strokeWidth: 1,
|
15586 | fill: getFillColor(element, defaultFillColor),
|
15587 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15588 | });
|
15589 | },
|
15590 | 'LoopMarker': function(parentGfx, element, position) {
|
15591 | var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
|
15592 | xScaleFactor: 1,
|
15593 | yScaleFactor: 1,
|
15594 | containerWidth: element.width,
|
15595 | containerHeight: element.height,
|
15596 | position: {
|
15597 | mx: ((element.width / 2 + position.loop) / element.width),
|
15598 | my: (element.height - 7) / element.height
|
15599 | }
|
15600 | });
|
15601 |
|
15602 | drawMarker('loop', parentGfx, markerPath, {
|
15603 | strokeWidth: 1,
|
15604 | fill: getFillColor(element, defaultFillColor),
|
15605 | stroke: getStrokeColor(element, defaultStrokeColor),
|
15606 | strokeLinecap: 'round',
|
15607 | strokeMiterlimit: 0.5
|
15608 | });
|
15609 | },
|
15610 | 'AdhocMarker': function(parentGfx, element, position) {
|
15611 | var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
|
15612 | xScaleFactor: 1,
|
15613 | yScaleFactor: 1,
|
15614 | containerWidth: element.width,
|
15615 | containerHeight: element.height,
|
15616 | position: {
|
15617 | mx: ((element.width / 2 + position.adhoc) / element.width),
|
15618 | my: (element.height - 15) / element.height
|
15619 | }
|
15620 | });
|
15621 |
|
15622 | drawMarker('adhoc', parentGfx, markerPath, {
|
15623 | strokeWidth: 1,
|
15624 | fill: getStrokeColor(element, defaultStrokeColor),
|
15625 | stroke: getStrokeColor(element, defaultStrokeColor)
|
15626 | });
|
15627 | }
|
15628 | };
|
15629 |
|
15630 | function attachTaskMarkers(parentGfx, element, taskMarkers) {
|
15631 | var obj = getSemantic(element);
|
15632 |
|
15633 | var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
|
15634 | var position;
|
15635 |
|
15636 | if (subprocess) {
|
15637 | position = {
|
15638 | seq: -21,
|
15639 | parallel: -22,
|
15640 | compensation: -42,
|
15641 | loop: -18,
|
15642 | adhoc: 10
|
15643 | };
|
15644 | } else {
|
15645 | position = {
|
15646 | seq: -3,
|
15647 | parallel: -6,
|
15648 | compensation: -27,
|
15649 | loop: 0,
|
15650 | adhoc: 10
|
15651 | };
|
15652 | }
|
15653 |
|
15654 | forEach(taskMarkers, function(marker) {
|
15655 | renderer(marker)(parentGfx, element, position);
|
15656 | });
|
15657 |
|
15658 | if (obj.isForCompensation) {
|
15659 | renderer('CompensationMarker')(parentGfx, element, position);
|
15660 | }
|
15661 |
|
15662 | if (obj.$type === 'bpmn:AdHocSubProcess') {
|
15663 | renderer('AdhocMarker')(parentGfx, element, position);
|
15664 | }
|
15665 |
|
15666 | var loopCharacteristics = obj.loopCharacteristics,
|
15667 | isSequential = loopCharacteristics && loopCharacteristics.isSequential;
|
15668 |
|
15669 | if (loopCharacteristics) {
|
15670 |
|
15671 | if (isSequential === undefined) {
|
15672 | renderer('LoopMarker')(parentGfx, element, position);
|
15673 | }
|
15674 |
|
15675 | if (isSequential === false) {
|
15676 | renderer('ParallelMarker')(parentGfx, element, position);
|
15677 | }
|
15678 |
|
15679 | if (isSequential === true) {
|
15680 | renderer('SequentialMarker')(parentGfx, element, position);
|
15681 | }
|
15682 | }
|
15683 | }
|
15684 |
|
15685 | function renderDataItemCollection(parentGfx, element) {
|
15686 |
|
15687 | var yPosition = (element.height - 16) / element.height;
|
15688 |
|
15689 | var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
|
15690 | xScaleFactor: 1,
|
15691 | yScaleFactor: 1,
|
15692 | containerWidth: element.width,
|
15693 | containerHeight: element.height,
|
15694 | position: {
|
15695 | mx: 0.451,
|
15696 | my: yPosition
|
15697 | }
|
15698 | });
|
15699 |
|
15700 | drawPath(parentGfx, pathData, {
|
15701 | strokeWidth: 2
|
15702 | });
|
15703 | }
|
15704 |
|
15705 |
|
15706 |
|
15707 | this._drawPath = drawPath;
|
15708 |
|
15709 | }
|
15710 |
|
15711 |
|
15712 | inherits_browser(BpmnRenderer, BaseRenderer);
|
15713 |
|
15714 | BpmnRenderer.$inject = [
|
15715 | 'config.bpmnRenderer',
|
15716 | 'eventBus',
|
15717 | 'styles',
|
15718 | 'pathMap',
|
15719 | 'canvas',
|
15720 | 'textRenderer'
|
15721 | ];
|
15722 |
|
15723 |
|
15724 | BpmnRenderer.prototype.canRender = function(element) {
|
15725 | return is$1(element, 'bpmn:BaseElement');
|
15726 | };
|
15727 |
|
15728 | BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
|
15729 | var type = element.type;
|
15730 | var h = this.handlers[type];
|
15731 |
|
15732 |
|
15733 | return h(parentGfx, element);
|
15734 | };
|
15735 |
|
15736 | BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
|
15737 | var type = element.type;
|
15738 | var h = this.handlers[type];
|
15739 |
|
15740 |
|
15741 | return h(parentGfx, element);
|
15742 | };
|
15743 |
|
15744 | BpmnRenderer.prototype.getShapePath = function(element) {
|
15745 |
|
15746 | if (is$1(element, 'bpmn:Event')) {
|
15747 | return getCirclePath(element);
|
15748 | }
|
15749 |
|
15750 | if (is$1(element, 'bpmn:Activity')) {
|
15751 | return getRoundRectPath(element, TASK_BORDER_RADIUS);
|
15752 | }
|
15753 |
|
15754 | if (is$1(element, 'bpmn:Gateway')) {
|
15755 | return getDiamondPath(element);
|
15756 | }
|
15757 |
|
15758 | return getRectPath(element);
|
15759 | };
|
15760 |
|
15761 | var DEFAULT_BOX_PADDING = 0;
|
15762 |
|
15763 | var DEFAULT_LABEL_SIZE = {
|
15764 | width: 150,
|
15765 | height: 50
|
15766 | };
|
15767 |
|
15768 |
|
15769 | function parseAlign(align) {
|
15770 |
|
15771 | var parts = align.split('-');
|
15772 |
|
15773 | return {
|
15774 | horizontal: parts[0] || 'center',
|
15775 | vertical: parts[1] || 'top'
|
15776 | };
|
15777 | }
|
15778 |
|
15779 | function parsePadding(padding) {
|
15780 |
|
15781 | if (isObject(padding)) {
|
15782 | return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
|
15783 | } else {
|
15784 | return {
|
15785 | top: padding,
|
15786 | left: padding,
|
15787 | right: padding,
|
15788 | bottom: padding
|
15789 | };
|
15790 | }
|
15791 | }
|
15792 |
|
15793 | function getTextBBox(text, fakeText) {
|
15794 |
|
15795 | fakeText.textContent = text;
|
15796 |
|
15797 | var textBBox;
|
15798 |
|
15799 | try {
|
15800 | var bbox,
|
15801 | emptyLine = text === '';
|
15802 |
|
15803 |
|
15804 |
|
15805 | fakeText.textContent = emptyLine ? 'dummy' : text;
|
15806 |
|
15807 | textBBox = fakeText.getBBox();
|
15808 |
|
15809 |
|
15810 |
|
15811 | bbox = {
|
15812 | width: textBBox.width + textBBox.x * 2,
|
15813 | height: textBBox.height
|
15814 | };
|
15815 |
|
15816 | if (emptyLine) {
|
15817 |
|
15818 | bbox.width = 0;
|
15819 | }
|
15820 |
|
15821 | return bbox;
|
15822 | } catch (e) {
|
15823 | return { width: 0, height: 0 };
|
15824 | }
|
15825 | }
|
15826 |
|
15827 |
|
15828 | |
15829 |
|
15830 |
|
15831 |
|
15832 |
|
15833 |
|
15834 |
|
15835 |
|
15836 | function layoutNext(lines, maxWidth, fakeText) {
|
15837 |
|
15838 | var originalLine = lines.shift(),
|
15839 | fitLine = originalLine;
|
15840 |
|
15841 | var textBBox;
|
15842 |
|
15843 | for (;;) {
|
15844 | textBBox = getTextBBox(fitLine, fakeText);
|
15845 |
|
15846 | textBBox.width = fitLine ? textBBox.width : 0;
|
15847 |
|
15848 |
|
15849 | if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
|
15850 | return fit(lines, fitLine, originalLine, textBBox);
|
15851 | }
|
15852 |
|
15853 | fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
|
15854 | }
|
15855 | }
|
15856 |
|
15857 | function fit(lines, fitLine, originalLine, textBBox) {
|
15858 | if (fitLine.length < originalLine.length) {
|
15859 | var remainder = originalLine.slice(fitLine.length).trim();
|
15860 |
|
15861 | lines.unshift(remainder);
|
15862 | }
|
15863 |
|
15864 | return {
|
15865 | width: textBBox.width,
|
15866 | height: textBBox.height,
|
15867 | text: fitLine
|
15868 | };
|
15869 | }
|
15870 |
|
15871 |
|
15872 | |
15873 |
|
15874 |
|
15875 |
|
15876 |
|
15877 |
|
15878 |
|
15879 |
|
15880 | function semanticShorten(line, maxLength) {
|
15881 | var parts = line.split(/(\s|-)/g),
|
15882 | part,
|
15883 | shortenedParts = [],
|
15884 | length = 0;
|
15885 |
|
15886 |
|
15887 | if (parts.length > 1) {
|
15888 | while ((part = parts.shift())) {
|
15889 | if (part.length + length < maxLength) {
|
15890 | shortenedParts.push(part);
|
15891 | length += part.length;
|
15892 | } else {
|
15893 |
|
15894 | if (part === '-') {
|
15895 | shortenedParts.pop();
|
15896 | }
|
15897 |
|
15898 | break;
|
15899 | }
|
15900 | }
|
15901 | }
|
15902 |
|
15903 | return shortenedParts.join('');
|
15904 | }
|
15905 |
|
15906 |
|
15907 | function shortenLine(line, width, maxWidth) {
|
15908 | var length = Math.max(line.length * (maxWidth / width), 1);
|
15909 |
|
15910 |
|
15911 | var shortenedLine = semanticShorten(line, length);
|
15912 |
|
15913 | if (!shortenedLine) {
|
15914 |
|
15915 |
|
15916 | shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
|
15917 | }
|
15918 |
|
15919 | return shortenedLine;
|
15920 | }
|
15921 |
|
15922 |
|
15923 | function getHelperSvg() {
|
15924 | var helperSvg = document.getElementById('helper-svg');
|
15925 |
|
15926 | if (!helperSvg) {
|
15927 | helperSvg = create('svg');
|
15928 |
|
15929 | attr$1(helperSvg, {
|
15930 | id: 'helper-svg',
|
15931 | width: 0,
|
15932 | height: 0,
|
15933 | style: 'visibility: hidden; position: fixed'
|
15934 | });
|
15935 |
|
15936 | document.body.appendChild(helperSvg);
|
15937 | }
|
15938 |
|
15939 | return helperSvg;
|
15940 | }
|
15941 |
|
15942 |
|
15943 | |
15944 |
|
15945 |
|
15946 |
|
15947 |
|
15948 |
|
15949 |
|
15950 |
|
15951 |
|
15952 | function Text(config) {
|
15953 |
|
15954 | this._config = assign({}, {
|
15955 | size: DEFAULT_LABEL_SIZE,
|
15956 | padding: DEFAULT_BOX_PADDING,
|
15957 | style: {},
|
15958 | align: 'center-top'
|
15959 | }, config || {});
|
15960 | }
|
15961 |
|
15962 | |
15963 |
|
15964 |
|
15965 |
|
15966 |
|
15967 |
|
15968 |
|
15969 |
|
15970 | Text.prototype.createText = function(text, options) {
|
15971 | return this.layoutText(text, options).element;
|
15972 | };
|
15973 |
|
15974 | |
15975 |
|
15976 |
|
15977 |
|
15978 |
|
15979 |
|
15980 |
|
15981 |
|
15982 | Text.prototype.getDimensions = function(text, options) {
|
15983 | return this.layoutText(text, options).dimensions;
|
15984 | };
|
15985 |
|
15986 | |
15987 |
|
15988 |
|
15989 |
|
15990 |
|
15991 |
|
15992 |
|
15993 |
|
15994 |
|
15995 |
|
15996 |
|
15997 |
|
15998 |
|
15999 |
|
16000 |
|
16001 |
|
16002 | Text.prototype.layoutText = function(text, options) {
|
16003 | var box = assign({}, this._config.size, options.box),
|
16004 | style = assign({}, this._config.style, options.style),
|
16005 | align = parseAlign(options.align || this._config.align),
|
16006 | padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
|
16007 | fitBox = options.fitBox || false;
|
16008 |
|
16009 | var lineHeight = getLineHeight(style);
|
16010 |
|
16011 | var lines = text.split(/\r?\n/g),
|
16012 | layouted = [];
|
16013 |
|
16014 | var maxWidth = box.width - padding.left - padding.right;
|
16015 |
|
16016 |
|
16017 | var helperText = create('text');
|
16018 | attr$1(helperText, { x: 0, y: 0 });
|
16019 | attr$1(helperText, style);
|
16020 |
|
16021 | var helperSvg = getHelperSvg();
|
16022 |
|
16023 | append(helperSvg, helperText);
|
16024 |
|
16025 | while (lines.length) {
|
16026 | layouted.push(layoutNext(lines, maxWidth, helperText));
|
16027 | }
|
16028 |
|
16029 | if (align.vertical === 'middle') {
|
16030 | padding.top = padding.bottom = 0;
|
16031 | }
|
16032 |
|
16033 | var totalHeight = reduce(layouted, function(sum, line, idx) {
|
16034 | return sum + (lineHeight || line.height);
|
16035 | }, 0) + padding.top + padding.bottom;
|
16036 |
|
16037 | var maxLineWidth = reduce(layouted, function(sum, line, idx) {
|
16038 | return line.width > sum ? line.width : sum;
|
16039 | }, 0);
|
16040 |
|
16041 |
|
16042 | var y = padding.top;
|
16043 |
|
16044 | if (align.vertical === 'middle') {
|
16045 | y += (box.height - totalHeight) / 2;
|
16046 | }
|
16047 |
|
16048 |
|
16049 | y -= (lineHeight || layouted[0].height) / 4;
|
16050 |
|
16051 |
|
16052 | var textElement = create('text');
|
16053 |
|
16054 | attr$1(textElement, style);
|
16055 |
|
16056 |
|
16057 |
|
16058 | forEach(layouted, function(line) {
|
16059 |
|
16060 | var x;
|
16061 |
|
16062 | y += (lineHeight || line.height);
|
16063 |
|
16064 | switch (align.horizontal) {
|
16065 | case 'left':
|
16066 | x = padding.left;
|
16067 | break;
|
16068 |
|
16069 | case 'right':
|
16070 | x = ((fitBox ? maxLineWidth : maxWidth)
|
16071 | - padding.right - line.width);
|
16072 | break;
|
16073 |
|
16074 | default:
|
16075 |
|
16076 | x = Math.max((((fitBox ? maxLineWidth : maxWidth)
|
16077 | - line.width) / 2 + padding.left), 0);
|
16078 | }
|
16079 |
|
16080 | var tspan = create('tspan');
|
16081 | attr$1(tspan, { x: x, y: y });
|
16082 |
|
16083 | tspan.textContent = line.text;
|
16084 |
|
16085 | append(textElement, tspan);
|
16086 | });
|
16087 |
|
16088 | remove$1(helperText);
|
16089 |
|
16090 | var dimensions = {
|
16091 | width: maxLineWidth,
|
16092 | height: totalHeight
|
16093 | };
|
16094 |
|
16095 | return {
|
16096 | dimensions: dimensions,
|
16097 | element: textElement
|
16098 | };
|
16099 | };
|
16100 |
|
16101 |
|
16102 | function getLineHeight(style) {
|
16103 | if ('fontSize' in style && 'lineHeight' in style) {
|
16104 | return style.lineHeight * parseInt(style.fontSize, 10);
|
16105 | }
|
16106 | }
|
16107 |
|
16108 | var DEFAULT_FONT_SIZE = 12;
|
16109 | var LINE_HEIGHT_RATIO = 1.2;
|
16110 |
|
16111 | var MIN_TEXT_ANNOTATION_HEIGHT = 30;
|
16112 |
|
16113 |
|
16114 | function TextRenderer(config) {
|
16115 |
|
16116 | var defaultStyle = assign({
|
16117 | fontFamily: 'Arial, sans-serif',
|
16118 | fontSize: DEFAULT_FONT_SIZE,
|
16119 | fontWeight: 'normal',
|
16120 | lineHeight: LINE_HEIGHT_RATIO
|
16121 | }, config && config.defaultStyle || {});
|
16122 |
|
16123 | var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
|
16124 |
|
16125 | var externalStyle = assign({}, defaultStyle, {
|
16126 | fontSize: fontSize
|
16127 | }, config && config.externalStyle || {});
|
16128 |
|
16129 | var textUtil = new Text({
|
16130 | style: defaultStyle
|
16131 | });
|
16132 |
|
16133 | |
16134 |
|
16135 |
|
16136 |
|
16137 |
|
16138 |
|
16139 |
|
16140 |
|
16141 |
|
16142 | this.getExternalLabelBounds = function(bounds, text) {
|
16143 |
|
16144 | var layoutedDimensions = textUtil.getDimensions(text, {
|
16145 | box: {
|
16146 | width: 90,
|
16147 | height: 30,
|
16148 | x: bounds.width / 2 + bounds.x,
|
16149 | y: bounds.height / 2 + bounds.y
|
16150 | },
|
16151 | style: externalStyle
|
16152 | });
|
16153 |
|
16154 |
|
16155 | return {
|
16156 | x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
|
16157 | y: Math.round(bounds.y),
|
16158 | width: Math.ceil(layoutedDimensions.width),
|
16159 | height: Math.ceil(layoutedDimensions.height)
|
16160 | };
|
16161 |
|
16162 | };
|
16163 |
|
16164 | |
16165 |
|
16166 |
|
16167 |
|
16168 |
|
16169 |
|
16170 |
|
16171 |
|
16172 | this.getTextAnnotationBounds = function(bounds, text) {
|
16173 |
|
16174 | var layoutedDimensions = textUtil.getDimensions(text, {
|
16175 | box: bounds,
|
16176 | style: defaultStyle,
|
16177 | align: 'left-top',
|
16178 | padding: 5
|
16179 | });
|
16180 |
|
16181 | return {
|
16182 | x: bounds.x,
|
16183 | y: bounds.y,
|
16184 | width: bounds.width,
|
16185 | height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
|
16186 | };
|
16187 | };
|
16188 |
|
16189 | |
16190 |
|
16191 |
|
16192 |
|
16193 |
|
16194 |
|
16195 |
|
16196 |
|
16197 | this.createText = function(text, options) {
|
16198 | return textUtil.createText(text, options || {});
|
16199 | };
|
16200 |
|
16201 | |
16202 |
|
16203 |
|
16204 | this.getDefaultStyle = function() {
|
16205 | return defaultStyle;
|
16206 | };
|
16207 |
|
16208 | |
16209 |
|
16210 |
|
16211 | this.getExternalStyle = function() {
|
16212 | return externalStyle;
|
16213 | };
|
16214 |
|
16215 | }
|
16216 |
|
16217 | TextRenderer.$inject = [
|
16218 | 'config.textRenderer'
|
16219 | ];
|
16220 |
|
16221 | |
16222 |
|
16223 |
|
16224 |
|
16225 | function PathMap() {
|
16226 |
|
16227 | |
16228 |
|
16229 |
|
16230 |
|
16231 |
|
16232 |
|
16233 |
|
16234 |
|
16235 |
|
16236 |
|
16237 |
|
16238 |
|
16239 |
|
16240 |
|
16241 |
|
16242 |
|
16243 |
|
16244 |
|
16245 |
|
16246 |
|
16247 |
|
16248 |
|
16249 |
|
16250 |
|
16251 |
|
16252 |
|
16253 |
|
16254 |
|
16255 |
|
16256 |
|
16257 |
|
16258 | this.pathMap = {
|
16259 | 'EVENT_MESSAGE': {
|
16260 | d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
|
16261 | height: 36,
|
16262 | width: 36,
|
16263 | heightElements: [6, 14],
|
16264 | widthElements: [10.5, 21]
|
16265 | },
|
16266 | 'EVENT_SIGNAL': {
|
16267 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
|
16268 | height: 36,
|
16269 | width: 36,
|
16270 | heightElements: [18],
|
16271 | widthElements: [10, 20]
|
16272 | },
|
16273 | 'EVENT_ESCALATION': {
|
16274 | d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
|
16275 | height: 36,
|
16276 | width: 36,
|
16277 | heightElements: [20, 7],
|
16278 | widthElements: [8]
|
16279 | },
|
16280 | 'EVENT_CONDITIONAL': {
|
16281 | d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
|
16282 | 'M {e.x2},{e.y3} l {e.x0},0 ' +
|
16283 | 'M {e.x2},{e.y4} l {e.x0},0 ' +
|
16284 | 'M {e.x2},{e.y5} l {e.x0},0 ' +
|
16285 | 'M {e.x2},{e.y6} l {e.x0},0 ' +
|
16286 | 'M {e.x2},{e.y7} l {e.x0},0 ' +
|
16287 | 'M {e.x2},{e.y8} l {e.x0},0 ',
|
16288 | height: 36,
|
16289 | width: 36,
|
16290 | heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
|
16291 | widthElements: [10.5, 14.5, 12.5]
|
16292 | },
|
16293 | 'EVENT_LINK': {
|
16294 | d: 'm {mx},{my} 0,{e.y0} -{e.x1},0 0,{e.y1} {e.x1},0 0,{e.y0} {e.x0},-{e.y2} -{e.x0},-{e.y2} z',
|
16295 | height: 36,
|
16296 | width: 36,
|
16297 | heightElements: [4.4375, 6.75, 7.8125],
|
16298 | widthElements: [9.84375, 13.5]
|
16299 | },
|
16300 | 'EVENT_ERROR': {
|
16301 | d: 'm {mx},{my} {e.x0},-{e.y0} {e.x1},-{e.y1} {e.x2},{e.y2} {e.x3},-{e.y3} -{e.x4},{e.y4} -{e.x5},-{e.y5} z',
|
16302 | height: 36,
|
16303 | width: 36,
|
16304 | heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
|
16305 | widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
|
16306 | },
|
16307 | 'EVENT_CANCEL_45': {
|
16308 | d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
16309 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
16310 | height: 36,
|
16311 | width: 36,
|
16312 | heightElements: [4.75, 8.5],
|
16313 | widthElements: [4.75, 8.5]
|
16314 | },
|
16315 | 'EVENT_COMPENSATION': {
|
16316 | d: 'm {mx},{my} {e.x0},-{e.y0} 0,{e.y1} z m {e.x1},-{e.y2} {e.x2},-{e.y3} 0,{e.y1} -{e.x2},-{e.y3} z',
|
16317 | height: 36,
|
16318 | width: 36,
|
16319 | heightElements: [6.5, 13, 0.4, 6.1],
|
16320 | widthElements: [9, 9.3, 8.7]
|
16321 | },
|
16322 | 'EVENT_TIMER_WH': {
|
16323 | d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
|
16324 | height: 36,
|
16325 | width: 36,
|
16326 | heightElements: [10, 2],
|
16327 | widthElements: [3, 7]
|
16328 | },
|
16329 | 'EVENT_TIMER_LINE': {
|
16330 | d: 'M {mx},{my} ' +
|
16331 | 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
|
16332 | height: 36,
|
16333 | width: 36,
|
16334 | heightElements: [10, 3],
|
16335 | widthElements: [0, 0]
|
16336 | },
|
16337 | 'EVENT_MULTIPLE': {
|
16338 | d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
|
16339 | height: 36,
|
16340 | width: 36,
|
16341 | heightElements: [6.28099, 12.56199],
|
16342 | widthElements: [3.1405, 9.42149, 12.56198]
|
16343 | },
|
16344 | 'EVENT_PARALLEL_MULTIPLE': {
|
16345 | d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
|
16346 | '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
|
16347 | height: 36,
|
16348 | width: 36,
|
16349 | heightElements: [2.56228, 7.68683],
|
16350 | widthElements: [2.56228, 7.68683]
|
16351 | },
|
16352 | 'GATEWAY_EXCLUSIVE': {
|
16353 | d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
|
16354 | '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
|
16355 | '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
|
16356 | height: 17.5,
|
16357 | width: 17.5,
|
16358 | heightElements: [8.5, 6.5312, -6.5312, -8.5],
|
16359 | widthElements: [6.5, -6.5, 3, -3, 5, -5]
|
16360 | },
|
16361 | 'GATEWAY_PARALLEL': {
|
16362 | d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
|
16363 | '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
|
16364 | height: 30,
|
16365 | width: 30,
|
16366 | heightElements: [5, 12.5],
|
16367 | widthElements: [5, 12.5]
|
16368 | },
|
16369 | 'GATEWAY_EVENT_BASED': {
|
16370 | d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
|
16371 | height: 11,
|
16372 | width: 11,
|
16373 | heightElements: [-6, 6, 12, -12],
|
16374 | widthElements: [9, -3, -12]
|
16375 | },
|
16376 | 'GATEWAY_COMPLEX': {
|
16377 | d:'m {mx},{my} 0,{e.y0} -{e.x0},-{e.y1} -{e.x1},{e.y2} {e.x0},{e.y1} -{e.x2},0 0,{e.y3} ' +
|
16378 | '{e.x2},0 -{e.x0},{e.y1} l {e.x1},{e.y2} {e.x0},-{e.y1} 0,{e.y0} {e.x3},0 0,-{e.y0} {e.x0},{e.y1} ' +
|
16379 | '{e.x1},-{e.y2} -{e.x0},-{e.y1} {e.x2},0 0,-{e.y3} -{e.x2},0 {e.x0},-{e.y1} -{e.x1},-{e.y2} ' +
|
16380 | '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
|
16381 | height: 17.125,
|
16382 | width: 17.125,
|
16383 | heightElements: [4.875, 3.4375, 2.125, 3],
|
16384 | widthElements: [3.4375, 2.125, 4.875, 3]
|
16385 | },
|
16386 | 'DATA_OBJECT_PATH': {
|
16387 | d:'m 0,0 {e.x1},0 {e.x0},{e.y0} 0,{e.y1} -{e.x2},0 0,-{e.y2} {e.x1},0 0,{e.y0} {e.x0},0',
|
16388 | height: 61,
|
16389 | width: 51,
|
16390 | heightElements: [10, 50, 60],
|
16391 | widthElements: [10, 40, 50, 60]
|
16392 | },
|
16393 | 'DATA_OBJECT_COLLECTION_PATH': {
|
16394 | d:'m {mx}, {my} ' +
|
16395 | 'm 0 15 l 0 -15 ' +
|
16396 | 'm 4 15 l 0 -15 ' +
|
16397 | 'm 4 15 l 0 -15 ',
|
16398 | height: 61,
|
16399 | width: 51,
|
16400 | heightElements: [12],
|
16401 | widthElements: [1, 6, 12, 15]
|
16402 | },
|
16403 | 'DATA_ARROW': {
|
16404 | d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
|
16405 | height: 61,
|
16406 | width: 51,
|
16407 | heightElements: [],
|
16408 | widthElements: []
|
16409 | },
|
16410 | 'DATA_STORE': {
|
16411 | d:'m {mx},{my} ' +
|
16412 | 'l 0,{e.y2} ' +
|
16413 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
16414 | 'l 0,-{e.y2} ' +
|
16415 | 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
|
16416 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
|
16417 | 'm -{e.x2},{e.y0}' +
|
16418 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
|
16419 | 'm -{e.x2},{e.y0}' +
|
16420 | 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
|
16421 | height: 61,
|
16422 | width: 61,
|
16423 | heightElements: [7, 10, 45],
|
16424 | widthElements: [2, 58, 60]
|
16425 | },
|
16426 | 'TEXT_ANNOTATION': {
|
16427 | d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
|
16428 | height: 30,
|
16429 | width: 10,
|
16430 | heightElements: [30],
|
16431 | widthElements: [10]
|
16432 | },
|
16433 | 'MARKER_SUB_PROCESS': {
|
16434 | d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
|
16435 | height: 10,
|
16436 | width: 10,
|
16437 | heightElements: [],
|
16438 | widthElements: []
|
16439 | },
|
16440 | 'MARKER_PARALLEL': {
|
16441 | d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
|
16442 | height: 10,
|
16443 | width: 10,
|
16444 | heightElements: [],
|
16445 | widthElements: []
|
16446 | },
|
16447 | 'MARKER_SEQUENTIAL': {
|
16448 | d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
|
16449 | height: 10,
|
16450 | width: 10,
|
16451 | heightElements: [],
|
16452 | widthElements: []
|
16453 | },
|
16454 | 'MARKER_COMPENSATION': {
|
16455 | d: 'm {mx},{my} 7,-5 0,10 z m 7.1,-0.3 6.9,-4.7 0,10 -6.9,-4.7 z',
|
16456 | height: 10,
|
16457 | width: 21,
|
16458 | heightElements: [],
|
16459 | widthElements: []
|
16460 | },
|
16461 | 'MARKER_LOOP': {
|
16462 | d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
|
16463 | '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
|
16464 | '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
|
16465 | 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
|
16466 | height: 13.9,
|
16467 | width: 13.7,
|
16468 | heightElements: [],
|
16469 | widthElements: []
|
16470 | },
|
16471 | 'MARKER_ADHOC': {
|
16472 | d: 'm {mx},{my} m 0.84461,2.64411 c 1.05533,-1.23780996 2.64337,-2.07882 4.29653,-1.97997996 2.05163,0.0805 ' +
|
16473 | '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
|
16474 | '1.2775,-0.64078 1.7542,-1.17511 0,0.56023 0,1.12046 0,1.6807 -0.98706,0.96237996 -2.29792,1.62393996 ' +
|
16475 | '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
|
16476 | '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
|
16477 | height: 4,
|
16478 | width: 15,
|
16479 | heightElements: [],
|
16480 | widthElements: []
|
16481 | },
|
16482 | 'TASK_TYPE_SEND': {
|
16483 | d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
|
16484 | height: 14,
|
16485 | width: 21,
|
16486 | heightElements: [6, 14],
|
16487 | widthElements: [10.5, 21]
|
16488 | },
|
16489 | 'TASK_TYPE_SCRIPT': {
|
16490 | d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
|
16491 | 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
|
16492 | 'm -7,-12 l 5,0 ' +
|
16493 | 'm -4.5,3 l 4.5,0 ' +
|
16494 | 'm -3,3 l 5,0' +
|
16495 | 'm -4,3 l 5,0',
|
16496 | height: 15,
|
16497 | width: 12.6,
|
16498 | heightElements: [6, 14],
|
16499 | widthElements: [10.5, 21]
|
16500 | },
|
16501 | 'TASK_TYPE_USER_1': {
|
16502 | d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
|
16503 | '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
|
16504 | '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
|
16505 | 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
|
16506 | 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
|
16507 | },
|
16508 | 'TASK_TYPE_USER_2': {
|
16509 | d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
|
16510 | '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
|
16511 | },
|
16512 | 'TASK_TYPE_USER_3': {
|
16513 | d: 'm {mx},{my} m -6.9,-3.80 c 0,0 2.25099998,-2.358 4.27399998,-1.177 2.024,1.181 4.221,1.537 ' +
|
16514 | '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
|
16515 | '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
|
16516 | },
|
16517 | 'TASK_TYPE_MANUAL': {
|
16518 | d: 'm {mx},{my} c 0.234,-0.01 5.604,0.008 8.029,0.004 0.808,0 1.271,-0.172 1.417,-0.752 0.227,-0.898 ' +
|
16519 | '-0.334,-1.314 -1.338,-1.316 -2.467,-0.01 -7.886,-0.004 -8.108,-0.004 -0.014,-0.079 0.016,-0.533 0,-0.61 ' +
|
16520 | '0.195,-0.042 8.507,0.006 9.616,0.002 0.877,-0.007 1.35,-0.438 1.353,-1.208 0.003,-0.768 -0.479,-1.09 ' +
|
16521 | '-1.35,-1.091 -2.968,-0.002 -9.619,-0.013 -9.619,-0.013 v -0.591 c 0,0 5.052,-0.016 7.225,-0.016 ' +
|
16522 | '0.888,-0.002 1.354,-0.416 1.351,-1.193 -0.006,-0.761 -0.492,-1.196 -1.361,-1.196 -3.473,-0.005 ' +
|
16523 | '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
|
16524 | '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
|
16525 | '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
|
16526 | '-1.516,1.253 -1.882,2.19 -0.37000002,0.95 -0.17,2.01 -0.166,2.979 0.004,0.718 -0.27300002,1.345 ' +
|
16527 | '-0.055,2.063 0.629,2.087 2.425,3.312 4.859,3.318 4.6179995,0.014 9.2379995,-0.139 13.8569995,-0.158 ' +
|
16528 | '0.755,-0.004 1.171,-0.301 1.182,-1.033 0.012,-0.754 -0.423,-0.969 -1.183,-0.973 -1.778,-0.01 ' +
|
16529 | '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
|
16530 | },
|
16531 | 'TASK_TYPE_INSTANTIATING_SEND': {
|
16532 | d: 'm {mx},{my} l 0,8.4 l 12.6,0 l 0,-8.4 z l 6.3,3.6 l 6.3,-3.6'
|
16533 | },
|
16534 | 'TASK_TYPE_SERVICE': {
|
16535 | d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
|
16536 | '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
|
16537 | '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
|
16538 | 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
|
16539 | '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
|
16540 | '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
|
16541 | 'h -2.241173 l 0.0042,1.63124 c -0.353763,0.0736 -0.705369,0.17977 -1.049785,0.32371 -0.344415,0.14437 ' +
|
16542 | '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
|
16543 | 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
|
16544 | 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
|
16545 | '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
|
16546 | 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
|
16547 | 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
16548 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
16549 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
16550 | },
|
16551 | 'TASK_TYPE_SERVICE_FILL': {
|
16552 | d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
|
16553 | '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
|
16554 | '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
|
16555 | },
|
16556 | 'TASK_TYPE_BUSINESS_RULE_HEADER': {
|
16557 | d: 'm {mx},{my} 0,4 20,0 0,-4 z'
|
16558 | },
|
16559 | 'TASK_TYPE_BUSINESS_RULE_MAIN': {
|
16560 | d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
|
16561 | 'm 0,8 l 20,0 ' +
|
16562 | 'm -13,-4 l 0,8'
|
16563 | },
|
16564 | 'MESSAGE_FLOW_MARKER': {
|
16565 | d: 'm {mx},{my} m -10.5 ,-7 l 0,14 l 21,0 l 0,-14 z l 10.5,6 l 10.5,-6'
|
16566 | }
|
16567 | };
|
16568 |
|
16569 | this.getRawPath = function getRawPath(pathId) {
|
16570 | return this.pathMap[pathId].d;
|
16571 | };
|
16572 |
|
16573 | |
16574 |
|
16575 |
|
16576 |
|
16577 |
|
16578 |
|
16579 |
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 |
|
16585 |
|
16586 |
|
16587 |
|
16588 |
|
16589 |
|
16590 |
|
16591 |
|
16592 |
|
16593 |
|
16594 |
|
16595 |
|
16596 |
|
16597 |
|
16598 |
|
16599 |
|
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 |
|
16607 |
|
16608 |
|
16609 |
|
16610 |
|
16611 |
|
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 |
|
16618 |
|
16619 |
|
16620 |
|
16621 |
|
16622 | this.getScaledPath = function getScaledPath(pathId, param) {
|
16623 | var rawPath = this.pathMap[pathId];
|
16624 |
|
16625 |
|
16626 |
|
16627 | var mx, my;
|
16628 |
|
16629 | if (param.abspos) {
|
16630 | mx = param.abspos.x;
|
16631 | my = param.abspos.y;
|
16632 | } else {
|
16633 | mx = param.containerWidth * param.position.mx;
|
16634 | my = param.containerHeight * param.position.my;
|
16635 | }
|
16636 |
|
16637 | var coordinates = {};
|
16638 | if (param.position) {
|
16639 |
|
16640 |
|
16641 | var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
|
16642 | var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
|
16643 |
|
16644 |
|
16645 |
|
16646 | for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
|
16647 | coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
|
16648 | }
|
16649 |
|
16650 |
|
16651 | for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
|
16652 | coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
|
16653 | }
|
16654 | }
|
16655 |
|
16656 |
|
16657 | var path = format(
|
16658 | rawPath.d, {
|
16659 | mx: mx,
|
16660 | my: my,
|
16661 | e: coordinates
|
16662 | }
|
16663 | );
|
16664 | return path;
|
16665 | };
|
16666 | }
|
16667 |
|
16668 |
|
16669 |
|
16670 |
|
16671 | var tokenRegex = /\{([^}]+)\}/g,
|
16672 | objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g;
|
16673 |
|
16674 | function replacer(all, key, obj) {
|
16675 | var res = obj;
|
16676 | key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
|
16677 | name = name || quotedName;
|
16678 | if (res) {
|
16679 | if (name in res) {
|
16680 | res = res[name];
|
16681 | }
|
16682 | typeof res == 'function' && isFunc && (res = res());
|
16683 | }
|
16684 | });
|
16685 | res = (res == null || res == obj ? all : res) + '';
|
16686 |
|
16687 | return res;
|
16688 | }
|
16689 |
|
16690 | function format(str, obj) {
|
16691 | return String(str).replace(tokenRegex, function(all, key) {
|
16692 | return replacer(all, key, obj);
|
16693 | });
|
16694 | }
|
16695 |
|
16696 | var DrawModule$1 = {
|
16697 | __init__: [ 'bpmnRenderer' ],
|
16698 | bpmnRenderer: [ 'type', BpmnRenderer ],
|
16699 | textRenderer: [ 'type', TextRenderer ],
|
16700 | pathMap: [ 'type', PathMap ]
|
16701 | };
|
16702 |
|
16703 | |
16704 |
|
16705 |
|
16706 |
|
16707 |
|
16708 |
|
16709 |
|
16710 |
|
16711 |
|
16712 |
|
16713 |
|
16714 |
|
16715 |
|
16716 |
|
16717 |
|
16718 |
|
16719 |
|
16720 |
|
16721 | function translate$1(template, replacements) {
|
16722 |
|
16723 | replacements = replacements || {};
|
16724 |
|
16725 | return template.replace(/{([^}]+)}/g, function(_, key) {
|
16726 | return replacements[key] || '{' + key + '}';
|
16727 | });
|
16728 | }
|
16729 |
|
16730 | var translate$2 = {
|
16731 | translate: [ 'value', translate$1 ]
|
16732 | };
|
16733 |
|
16734 | var DEFAULT_LABEL_SIZE$1 = {
|
16735 | width: 90,
|
16736 | height: 20
|
16737 | };
|
16738 |
|
16739 | var FLOW_LABEL_INDENT = 15;
|
16740 |
|
16741 |
|
16742 | |
16743 |
|
16744 |
|
16745 |
|
16746 |
|
16747 |
|
16748 | function isLabelExternal(semantic) {
|
16749 | return is$1(semantic, 'bpmn:Event') ||
|
16750 | is$1(semantic, 'bpmn:Gateway') ||
|
16751 | is$1(semantic, 'bpmn:DataStoreReference') ||
|
16752 | is$1(semantic, 'bpmn:DataObjectReference') ||
|
16753 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
16754 | is$1(semantic, 'bpmn:MessageFlow');
|
16755 | }
|
16756 |
|
16757 | |
16758 |
|
16759 |
|
16760 |
|
16761 |
|
16762 |
|
16763 | function hasExternalLabel(element) {
|
16764 | return isLabel(element.label);
|
16765 | }
|
16766 |
|
16767 | |
16768 |
|
16769 |
|
16770 |
|
16771 |
|
16772 |
|
16773 | function getFlowLabelPosition(waypoints) {
|
16774 |
|
16775 |
|
16776 | var mid = waypoints.length / 2 - 1;
|
16777 |
|
16778 | var first = waypoints[Math.floor(mid)];
|
16779 | var second = waypoints[Math.ceil(mid + 0.01)];
|
16780 |
|
16781 |
|
16782 | var position = getWaypointsMid(waypoints);
|
16783 |
|
16784 |
|
16785 | var angle = Math.atan((second.y - first.y) / (second.x - first.x));
|
16786 |
|
16787 | var x = position.x,
|
16788 | y = position.y;
|
16789 |
|
16790 | if (Math.abs(angle) < Math.PI / 2) {
|
16791 | y -= FLOW_LABEL_INDENT;
|
16792 | } else {
|
16793 | x += FLOW_LABEL_INDENT;
|
16794 | }
|
16795 |
|
16796 | return { x: x, y: y };
|
16797 | }
|
16798 |
|
16799 |
|
16800 | |
16801 |
|
16802 |
|
16803 |
|
16804 |
|
16805 |
|
16806 | function getWaypointsMid(waypoints) {
|
16807 |
|
16808 | var mid = waypoints.length / 2 - 1;
|
16809 |
|
16810 | var first = waypoints[Math.floor(mid)];
|
16811 | var second = waypoints[Math.ceil(mid + 0.01)];
|
16812 |
|
16813 | return {
|
16814 | x: first.x + (second.x - first.x) / 2,
|
16815 | y: first.y + (second.y - first.y) / 2
|
16816 | };
|
16817 | }
|
16818 |
|
16819 |
|
16820 | function getExternalLabelMid(element) {
|
16821 |
|
16822 | if (element.waypoints) {
|
16823 | return getFlowLabelPosition(element.waypoints);
|
16824 | } else {
|
16825 | return {
|
16826 | x: element.x + element.width / 2,
|
16827 | y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
|
16828 | };
|
16829 | }
|
16830 | }
|
16831 |
|
16832 |
|
16833 | |
16834 |
|
16835 |
|
16836 |
|
16837 |
|
16838 |
|
16839 |
|
16840 | function getExternalLabelBounds(semantic, element) {
|
16841 |
|
16842 | var mid,
|
16843 | size$$1,
|
16844 | bounds,
|
16845 | di = semantic.di,
|
16846 | label = di.label;
|
16847 |
|
16848 | if (label && label.bounds) {
|
16849 | bounds = label.bounds;
|
16850 |
|
16851 | size$$1 = {
|
16852 | width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
|
16853 | height: bounds.height
|
16854 | };
|
16855 |
|
16856 | mid = {
|
16857 | x: bounds.x + bounds.width / 2,
|
16858 | y: bounds.y + bounds.height / 2
|
16859 | };
|
16860 | } else {
|
16861 |
|
16862 | mid = getExternalLabelMid(element);
|
16863 |
|
16864 | size$$1 = DEFAULT_LABEL_SIZE$1;
|
16865 | }
|
16866 |
|
16867 | return assign({
|
16868 | x: mid.x - size$$1.width / 2,
|
16869 | y: mid.y - size$$1.height / 2
|
16870 | }, size$$1);
|
16871 | }
|
16872 |
|
16873 | function isLabel(element) {
|
16874 | return element && element.labelTarget;
|
16875 | }
|
16876 |
|
16877 | |
16878 |
|
16879 |
|
16880 |
|
16881 |
|
16882 |
|
16883 |
|
16884 |
|
16885 | function pointDistance(a, b) {
|
16886 | if (!a || !b) {
|
16887 | return -1;
|
16888 | }
|
16889 |
|
16890 | return Math.sqrt(
|
16891 | Math.pow(a.x - b.x, 2) +
|
16892 | Math.pow(a.y - b.y, 2)
|
16893 | );
|
16894 | }
|
16895 |
|
16896 |
|
16897 | |
16898 |
|
16899 |
|
16900 |
|
16901 |
|
16902 |
|
16903 |
|
16904 |
|
16905 |
|
16906 |
|
16907 | function pointsOnLine(p, q, r, accuracy) {
|
16908 |
|
16909 | if (typeof accuracy === 'undefined') {
|
16910 | accuracy = 5;
|
16911 | }
|
16912 |
|
16913 | if (!p || !q || !r) {
|
16914 | return false;
|
16915 | }
|
16916 |
|
16917 | var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x),
|
16918 | dist = pointDistance(p, q);
|
16919 |
|
16920 |
|
16921 | return Math.abs(val / dist) <= accuracy;
|
16922 | }
|
16923 |
|
16924 |
|
16925 | var ALIGNED_THRESHOLD = 2;
|
16926 |
|
16927 | |
16928 |
|
16929 |
|
16930 |
|
16931 |
|
16932 |
|
16933 |
|
16934 |
|
16935 |
|
16936 |
|
16937 | function pointsAligned(a, b) {
|
16938 | if (Math.abs(a.x - b.x) <= ALIGNED_THRESHOLD) {
|
16939 | return 'h';
|
16940 | }
|
16941 |
|
16942 | if (Math.abs(a.y - b.y) <= ALIGNED_THRESHOLD) {
|
16943 | return 'v';
|
16944 | }
|
16945 |
|
16946 | return false;
|
16947 | }
|
16948 |
|
16949 |
|
16950 | |
16951 |
|
16952 |
|
16953 |
|
16954 |
|
16955 |
|
16956 |
|
16957 |
|
16958 |
|
16959 | function pointInRect(p, rect, tolerance) {
|
16960 | tolerance = tolerance || 0;
|
16961 |
|
16962 | return p.x > rect.x - tolerance &&
|
16963 | p.y > rect.y - tolerance &&
|
16964 | p.x < rect.x + rect.width + tolerance &&
|
16965 | p.y < rect.y + rect.height + tolerance;
|
16966 | }
|
16967 |
|
16968 | |
16969 |
|
16970 |
|
16971 |
|
16972 |
|
16973 |
|
16974 |
|
16975 |
|
16976 | function getMidPoint(p, q) {
|
16977 | return {
|
16978 | x: Math.round(p.x + ((q.x - p.x) / 2.0)),
|
16979 | y: Math.round(p.y + ((q.y - p.y) / 2.0))
|
16980 | };
|
16981 | }
|
16982 |
|
16983 | |
16984 |
|
16985 |
|
16986 |
|
16987 |
|
16988 |
|
16989 |
|
16990 |
|
16991 | var has$1 = 'hasOwnProperty',
|
16992 | p2s = /,?([a-z]),?/gi,
|
16993 | toFloat = parseFloat,
|
16994 | math = Math,
|
16995 | PI = math.PI,
|
16996 | mmin = math.min,
|
16997 | mmax = math.max,
|
16998 | pow = math.pow,
|
16999 | abs = math.abs,
|
17000 | pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?[\s]*,?[\s]*)+)/ig,
|
17001 | pathValues = /(-?\d*\.?\d*(?:e[-+]?\\d+)?)[\s]*,?[\s]*/ig;
|
17002 |
|
17003 | function is$2(o, type) {
|
17004 | type = String.prototype.toLowerCase.call(type);
|
17005 |
|
17006 | if (type == 'finite') {
|
17007 | return isFinite(o);
|
17008 | }
|
17009 |
|
17010 | if (type == 'array' && (o instanceof Array || Array.isArray && Array.isArray(o))) {
|
17011 | return true;
|
17012 | }
|
17013 |
|
17014 | return (type == 'null' && o === null) ||
|
17015 | (type == typeof o && o !== null) ||
|
17016 | (type == 'object' && o === Object(o)) ||
|
17017 | Object.prototype.toString.call(o).slice(8, -1).toLowerCase() == type;
|
17018 | }
|
17019 |
|
17020 | function clone$1(obj) {
|
17021 |
|
17022 | if (typeof obj == 'function' || Object(obj) !== obj) {
|
17023 | return obj;
|
17024 | }
|
17025 |
|
17026 | var res = new obj.constructor;
|
17027 |
|
17028 | for (var key in obj) if (obj[has$1](key)) {
|
17029 | res[key] = clone$1(obj[key]);
|
17030 | }
|
17031 |
|
17032 | return res;
|
17033 | }
|
17034 |
|
17035 | function repush(array, item) {
|
17036 | for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
|
17037 | return array.push(array.splice(i, 1)[0]);
|
17038 | }
|
17039 | }
|
17040 |
|
17041 | function cacher(f, scope, postprocessor) {
|
17042 |
|
17043 | function newf() {
|
17044 |
|
17045 | var arg = Array.prototype.slice.call(arguments, 0),
|
17046 | args = arg.join('\u2400'),
|
17047 | cache = newf.cache = newf.cache || {},
|
17048 | count = newf.count = newf.count || [];
|
17049 |
|
17050 | if (cache[has$1](args)) {
|
17051 | repush(count, args);
|
17052 | return postprocessor ? postprocessor(cache[args]) : cache[args];
|
17053 | }
|
17054 |
|
17055 | count.length >= 1e3 && delete cache[count.shift()];
|
17056 | count.push(args);
|
17057 | cache[args] = f.apply(scope, arg);
|
17058 |
|
17059 | return postprocessor ? postprocessor(cache[args]) : cache[args];
|
17060 | }
|
17061 | return newf;
|
17062 | }
|
17063 |
|
17064 | function parsePathString(pathString) {
|
17065 |
|
17066 | if (!pathString) {
|
17067 | return null;
|
17068 | }
|
17069 |
|
17070 | var pth = paths(pathString);
|
17071 |
|
17072 | if (pth.arr) {
|
17073 | return clone$1(pth.arr);
|
17074 | }
|
17075 |
|
17076 | var paramCounts = { a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0 },
|
17077 | data = [];
|
17078 |
|
17079 | if (is$2(pathString, 'array') && is$2(pathString[0], 'array')) {
|
17080 | data = clone$1(pathString);
|
17081 | }
|
17082 |
|
17083 | if (!data.length) {
|
17084 |
|
17085 | String(pathString).replace(pathCommand, function(a, b, c) {
|
17086 | var params = [],
|
17087 | name = b.toLowerCase();
|
17088 |
|
17089 | c.replace(pathValues, function(a, b) {
|
17090 | b && params.push(+b);
|
17091 | });
|
17092 |
|
17093 | if (name == 'm' && params.length > 2) {
|
17094 | data.push([b].concat(params.splice(0, 2)));
|
17095 | name = 'l';
|
17096 | b = b == 'm' ? 'l' : 'L';
|
17097 | }
|
17098 |
|
17099 | if (name == 'o' && params.length == 1) {
|
17100 | data.push([b, params[0]]);
|
17101 | }
|
17102 |
|
17103 | if (name == 'r') {
|
17104 | data.push([b].concat(params));
|
17105 | } else while (params.length >= paramCounts[name]) {
|
17106 | data.push([b].concat(params.splice(0, paramCounts[name])));
|
17107 | if (!paramCounts[name]) {
|
17108 | break;
|
17109 | }
|
17110 | }
|
17111 | });
|
17112 | }
|
17113 |
|
17114 | data.toString = paths.toString;
|
17115 | pth.arr = clone$1(data);
|
17116 |
|
17117 | return data;
|
17118 | }
|
17119 |
|
17120 | function paths(ps) {
|
17121 | var p = paths.ps = paths.ps || {};
|
17122 |
|
17123 | if (p[ps]) {
|
17124 | p[ps].sleep = 100;
|
17125 | } else {
|
17126 | p[ps] = {
|
17127 | sleep: 100
|
17128 | };
|
17129 | }
|
17130 |
|
17131 | setTimeout(function() {
|
17132 | for (var key in p) if (p[has$1](key) && key != ps) {
|
17133 | p[key].sleep--;
|
17134 | !p[key].sleep && delete p[key];
|
17135 | }
|
17136 | });
|
17137 |
|
17138 | return p[ps];
|
17139 | }
|
17140 |
|
17141 | function box(x, y, width, height) {
|
17142 | if (x == null) {
|
17143 | x = y = width = height = 0;
|
17144 | }
|
17145 |
|
17146 | if (y == null) {
|
17147 | y = x.y;
|
17148 | width = x.width;
|
17149 | height = x.height;
|
17150 | x = x.x;
|
17151 | }
|
17152 |
|
17153 | return {
|
17154 | x: x,
|
17155 | y: y,
|
17156 | width: width,
|
17157 | w: width,
|
17158 | height: height,
|
17159 | h: height,
|
17160 | x2: x + width,
|
17161 | y2: y + height,
|
17162 | cx: x + width / 2,
|
17163 | cy: y + height / 2,
|
17164 | r1: math.min(width, height) / 2,
|
17165 | r2: math.max(width, height) / 2,
|
17166 | r0: math.sqrt(width * width + height * height) / 2,
|
17167 | path: rectPath(x, y, width, height),
|
17168 | vb: [x, y, width, height].join(' ')
|
17169 | };
|
17170 | }
|
17171 |
|
17172 | function pathToString() {
|
17173 | return this.join(',').replace(p2s, '$1');
|
17174 | }
|
17175 |
|
17176 | function pathClone(pathArray) {
|
17177 | var res = clone$1(pathArray);
|
17178 | res.toString = pathToString;
|
17179 | return res;
|
17180 | }
|
17181 |
|
17182 | function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
|
17183 | var t1 = 1 - t,
|
17184 | t13 = pow(t1, 3),
|
17185 | t12 = pow(t1, 2),
|
17186 | t2 = t * t,
|
17187 | t3 = t2 * t,
|
17188 | x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x,
|
17189 | y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y,
|
17190 | mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x),
|
17191 | my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y),
|
17192 | nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x),
|
17193 | ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y),
|
17194 | ax = t1 * p1x + t * c1x,
|
17195 | ay = t1 * p1y + t * c1y,
|
17196 | cx = t1 * c2x + t * p2x,
|
17197 | cy = t1 * c2y + t * p2y,
|
17198 | alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI);
|
17199 |
|
17200 | return {
|
17201 | x: x,
|
17202 | y: y,
|
17203 | m: { x: mx, y: my },
|
17204 | n: { x: nx, y: ny },
|
17205 | start: { x: ax, y: ay },
|
17206 | end: { x: cx, y: cy },
|
17207 | alpha: alpha
|
17208 | };
|
17209 | }
|
17210 |
|
17211 | function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
|
17212 |
|
17213 | if (!is$2(p1x, 'array')) {
|
17214 | p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y];
|
17215 | }
|
17216 |
|
17217 | var bbox = curveBBox.apply(null, p1x);
|
17218 |
|
17219 | return box(
|
17220 | bbox.min.x,
|
17221 | bbox.min.y,
|
17222 | bbox.max.x - bbox.min.x,
|
17223 | bbox.max.y - bbox.min.y
|
17224 | );
|
17225 | }
|
17226 |
|
17227 | function isPointInsideBBox(bbox, x, y) {
|
17228 | return x >= bbox.x &&
|
17229 | x <= bbox.x + bbox.width &&
|
17230 | y >= bbox.y &&
|
17231 | y <= bbox.y + bbox.height;
|
17232 | }
|
17233 |
|
17234 | function isBBoxIntersect(bbox1, bbox2) {
|
17235 | bbox1 = box(bbox1);
|
17236 | bbox2 = box(bbox2);
|
17237 | return isPointInsideBBox(bbox2, bbox1.x, bbox1.y)
|
17238 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y)
|
17239 | || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2)
|
17240 | || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2)
|
17241 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y)
|
17242 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y)
|
17243 | || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2)
|
17244 | || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2)
|
17245 | || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x
|
17246 | || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x)
|
17247 | && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y
|
17248 | || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
|
17249 | }
|
17250 |
|
17251 | function base3(t, p1, p2, p3, p4) {
|
17252 | var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4,
|
17253 | t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
|
17254 | return t * t2 - 3 * p1 + 3 * p2;
|
17255 | }
|
17256 |
|
17257 | function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
|
17258 |
|
17259 | if (z == null) {
|
17260 | z = 1;
|
17261 | }
|
17262 |
|
17263 | z = z > 1 ? 1 : z < 0 ? 0 : z;
|
17264 |
|
17265 | var z2 = z / 2,
|
17266 | n = 12,
|
17267 | Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],
|
17268 | Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472],
|
17269 | sum = 0;
|
17270 |
|
17271 | for (var i = 0; i < n; i++) {
|
17272 | var ct = z2 * Tvalues[i] + z2,
|
17273 | xbase = base3(ct, x1, x2, x3, x4),
|
17274 | ybase = base3(ct, y1, y2, y3, y4),
|
17275 | comb = xbase * xbase + ybase * ybase;
|
17276 |
|
17277 | sum += Cvalues[i] * math.sqrt(comb);
|
17278 | }
|
17279 |
|
17280 | return z2 * sum;
|
17281 | }
|
17282 |
|
17283 |
|
17284 | function intersectLines(x1, y1, x2, y2, x3, y3, x4, y4) {
|
17285 |
|
17286 | if (
|
17287 | mmax(x1, x2) < mmin(x3, x4) ||
|
17288 | mmin(x1, x2) > mmax(x3, x4) ||
|
17289 | mmax(y1, y2) < mmin(y3, y4) ||
|
17290 | mmin(y1, y2) > mmax(y3, y4)
|
17291 | ) {
|
17292 | return;
|
17293 | }
|
17294 |
|
17295 | var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4),
|
17296 | ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4),
|
17297 | denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
17298 |
|
17299 | if (!denominator) {
|
17300 | return;
|
17301 | }
|
17302 |
|
17303 | var px = nx / denominator,
|
17304 | py = ny / denominator,
|
17305 | px2 = +px.toFixed(2),
|
17306 | py2 = +py.toFixed(2);
|
17307 |
|
17308 | if (
|
17309 | px2 < +mmin(x1, x2).toFixed(2) ||
|
17310 | px2 > +mmax(x1, x2).toFixed(2) ||
|
17311 | px2 < +mmin(x3, x4).toFixed(2) ||
|
17312 | px2 > +mmax(x3, x4).toFixed(2) ||
|
17313 | py2 < +mmin(y1, y2).toFixed(2) ||
|
17314 | py2 > +mmax(y1, y2).toFixed(2) ||
|
17315 | py2 < +mmin(y3, y4).toFixed(2) ||
|
17316 | py2 > +mmax(y3, y4).toFixed(2)
|
17317 | ) {
|
17318 | return;
|
17319 | }
|
17320 |
|
17321 | return { x: px, y: py };
|
17322 | }
|
17323 |
|
17324 | function findBezierIntersections(bez1, bez2, justCount) {
|
17325 | var bbox1 = bezierBBox(bez1),
|
17326 | bbox2 = bezierBBox(bez2);
|
17327 |
|
17328 | if (!isBBoxIntersect(bbox1, bbox2)) {
|
17329 | return justCount ? 0 : [];
|
17330 | }
|
17331 |
|
17332 | var l1 = bezlen.apply(0, bez1),
|
17333 | l2 = bezlen.apply(0, bez2),
|
17334 | n1 = ~~(l1 / 5),
|
17335 | n2 = ~~(l2 / 5),
|
17336 | dots1 = [],
|
17337 | dots2 = [],
|
17338 | xy = {},
|
17339 | res = justCount ? 0 : [];
|
17340 |
|
17341 | for (var i = 0; i < n1 + 1; i++) {
|
17342 | var p = findDotsAtSegment.apply(0, bez1.concat(i / n1));
|
17343 | dots1.push({ x: p.x, y: p.y, t: i / n1 });
|
17344 | }
|
17345 |
|
17346 | for (i = 0; i < n2 + 1; i++) {
|
17347 | p = findDotsAtSegment.apply(0, bez2.concat(i / n2));
|
17348 | dots2.push({ x: p.x, y: p.y, t: i / n2 });
|
17349 | }
|
17350 |
|
17351 | for (i = 0; i < n1; i++) {
|
17352 |
|
17353 | for (var j = 0; j < n2; j++) {
|
17354 | var di = dots1[i],
|
17355 | di1 = dots1[i + 1],
|
17356 | dj = dots2[j],
|
17357 | dj1 = dots2[j + 1],
|
17358 | ci = abs(di1.x - di.x) < .01 ? 'y' : 'x',
|
17359 | cj = abs(dj1.x - dj.x) < .01 ? 'y' : 'x',
|
17360 | is = intersectLines(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y);
|
17361 |
|
17362 | if (is) {
|
17363 |
|
17364 | if (xy[is.x.toFixed(0)] == is.y.toFixed(0)) {
|
17365 | continue;
|
17366 | }
|
17367 |
|
17368 | xy[is.x.toFixed(0)] = is.y.toFixed(0);
|
17369 |
|
17370 | var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t),
|
17371 | t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
|
17372 |
|
17373 | if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
|
17374 |
|
17375 | if (justCount) {
|
17376 | res++;
|
17377 | } else {
|
17378 | res.push({
|
17379 | x: is.x,
|
17380 | y: is.y,
|
17381 | t1: t1,
|
17382 | t2: t2
|
17383 | });
|
17384 | }
|
17385 | }
|
17386 | }
|
17387 | }
|
17388 | }
|
17389 |
|
17390 | return res;
|
17391 | }
|
17392 |
|
17393 |
|
17394 | |
17395 |
|
17396 |
|
17397 |
|
17398 |
|
17399 |
|
17400 |
|
17401 |
|
17402 |
|
17403 |
|
17404 |
|
17405 |
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 |
|
17413 |
|
17414 |
|
17415 |
|
17416 |
|
17417 |
|
17418 |
|
17419 |
|
17420 |
|
17421 |
|
17422 |
|
17423 |
|
17424 | function findPathIntersections(path1, path2, justCount) {
|
17425 | path1 = pathToCurve(path1);
|
17426 | path2 = pathToCurve(path2);
|
17427 |
|
17428 | var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2,
|
17429 | res = justCount ? 0 : [];
|
17430 |
|
17431 | for (var i = 0, ii = path1.length; i < ii; i++) {
|
17432 | var pi = path1[i];
|
17433 |
|
17434 | if (pi[0] == 'M') {
|
17435 | x1 = x1m = pi[1];
|
17436 | y1 = y1m = pi[2];
|
17437 | } else {
|
17438 |
|
17439 | if (pi[0] == 'C') {
|
17440 | bez1 = [x1, y1].concat(pi.slice(1));
|
17441 | x1 = bez1[6];
|
17442 | y1 = bez1[7];
|
17443 | } else {
|
17444 | bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
|
17445 | x1 = x1m;
|
17446 | y1 = y1m;
|
17447 | }
|
17448 |
|
17449 | for (var j = 0, jj = path2.length; j < jj; j++) {
|
17450 | var pj = path2[j];
|
17451 |
|
17452 | if (pj[0] == 'M') {
|
17453 | x2 = x2m = pj[1];
|
17454 | y2 = y2m = pj[2];
|
17455 | } else {
|
17456 |
|
17457 | if (pj[0] == 'C') {
|
17458 | bez2 = [x2, y2].concat(pj.slice(1));
|
17459 | x2 = bez2[6];
|
17460 | y2 = bez2[7];
|
17461 | } else {
|
17462 | bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
|
17463 | x2 = x2m;
|
17464 | y2 = y2m;
|
17465 | }
|
17466 |
|
17467 | var intr = findBezierIntersections(bez1, bez2, justCount);
|
17468 |
|
17469 | if (justCount) {
|
17470 | res += intr;
|
17471 | } else {
|
17472 |
|
17473 | for (var k = 0, kk = intr.length; k < kk; k++) {
|
17474 | intr[k].segment1 = i;
|
17475 | intr[k].segment2 = j;
|
17476 | intr[k].bez1 = bez1;
|
17477 | intr[k].bez2 = bez2;
|
17478 | }
|
17479 |
|
17480 | res = res.concat(intr);
|
17481 | }
|
17482 | }
|
17483 | }
|
17484 | }
|
17485 | }
|
17486 |
|
17487 | return res;
|
17488 | }
|
17489 |
|
17490 |
|
17491 | function rectPath(x, y, w, h, r) {
|
17492 | if (r) {
|
17493 | return [
|
17494 | ['M', +x + (+r), y],
|
17495 | ['l', w - r * 2, 0],
|
17496 | ['a', r, r, 0, 0, 1, r, r],
|
17497 | ['l', 0, h - r * 2],
|
17498 | ['a', r, r, 0, 0, 1, -r, r],
|
17499 | ['l', r * 2 - w, 0],
|
17500 | ['a', r, r, 0, 0, 1, -r, -r],
|
17501 | ['l', 0, r * 2 - h],
|
17502 | ['a', r, r, 0, 0, 1, r, -r],
|
17503 | ['z']
|
17504 | ];
|
17505 | }
|
17506 |
|
17507 | var res = [['M', x, y], ['l', w, 0], ['l', 0, h], ['l', -w, 0], ['z']];
|
17508 | res.toString = pathToString;
|
17509 |
|
17510 | return res;
|
17511 | }
|
17512 |
|
17513 | function ellipsePath(x, y, rx, ry, a) {
|
17514 | if (a == null && ry == null) {
|
17515 | ry = rx;
|
17516 | }
|
17517 |
|
17518 | x = +x;
|
17519 | y = +y;
|
17520 | rx = +rx;
|
17521 | ry = +ry;
|
17522 |
|
17523 | if (a != null) {
|
17524 | var rad = Math.PI / 180,
|
17525 | x1 = x + rx * Math.cos(-ry * rad),
|
17526 | x2 = x + rx * Math.cos(-a * rad),
|
17527 | y1 = y + rx * Math.sin(-ry * rad),
|
17528 | y2 = y + rx * Math.sin(-a * rad),
|
17529 | res = [['M', x1, y1], ['A', rx, rx, 0, +(a - ry > 180), 0, x2, y2]];
|
17530 | } else {
|
17531 | res = [
|
17532 | ['M', x, y],
|
17533 | ['m', 0, -ry],
|
17534 | ['a', rx, ry, 0, 1, 1, 0, 2 * ry],
|
17535 | ['a', rx, ry, 0, 1, 1, 0, -2 * ry],
|
17536 | ['z']
|
17537 | ];
|
17538 | }
|
17539 |
|
17540 | res.toString = pathToString;
|
17541 |
|
17542 | return res;
|
17543 | }
|
17544 |
|
17545 |
|
17546 | function pathToAbsolute(pathArray) {
|
17547 | var pth = paths(pathArray);
|
17548 |
|
17549 | if (pth.abs) {
|
17550 | return pathClone(pth.abs);
|
17551 | }
|
17552 |
|
17553 | if (!is$2(pathArray, 'array') || !is$2(pathArray && pathArray[0], 'array')) {
|
17554 | pathArray = parsePathString(pathArray);
|
17555 | }
|
17556 |
|
17557 | if (!pathArray || !pathArray.length) {
|
17558 | return [['M', 0, 0]];
|
17559 | }
|
17560 |
|
17561 | var res = [],
|
17562 | x = 0,
|
17563 | y = 0,
|
17564 | mx = 0,
|
17565 | my = 0,
|
17566 | start = 0,
|
17567 | pa0;
|
17568 |
|
17569 | if (pathArray[0][0] == 'M') {
|
17570 | x = +pathArray[0][1];
|
17571 | y = +pathArray[0][2];
|
17572 | mx = x;
|
17573 | my = y;
|
17574 | start++;
|
17575 | res[0] = ['M', x, y];
|
17576 | }
|
17577 |
|
17578 | var crz = pathArray.length == 3 &&
|
17579 | pathArray[0][0] == 'M' &&
|
17580 | pathArray[1][0].toUpperCase() == 'R' &&
|
17581 | pathArray[2][0].toUpperCase() == 'Z';
|
17582 |
|
17583 | for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
|
17584 | res.push(r = []);
|
17585 | pa = pathArray[i];
|
17586 | pa0 = pa[0];
|
17587 |
|
17588 | if (pa0 != pa0.toUpperCase()) {
|
17589 | r[0] = pa0.toUpperCase();
|
17590 |
|
17591 | switch (r[0]) {
|
17592 | case 'A':
|
17593 | r[1] = pa[1];
|
17594 | r[2] = pa[2];
|
17595 | r[3] = pa[3];
|
17596 | r[4] = pa[4];
|
17597 | r[5] = pa[5];
|
17598 | r[6] = +pa[6] + x;
|
17599 | r[7] = +pa[7] + y;
|
17600 | break;
|
17601 | case 'V':
|
17602 | r[1] = +pa[1] + y;
|
17603 | break;
|
17604 | case 'H':
|
17605 | r[1] = +pa[1] + x;
|
17606 | break;
|
17607 | case 'R':
|
17608 | var dots = [x, y].concat(pa.slice(1));
|
17609 |
|
17610 | for (var j = 2, jj = dots.length; j < jj; j++) {
|
17611 | dots[j] = +dots[j] + x;
|
17612 | dots[++j] = +dots[j] + y;
|
17613 | }
|
17614 |
|
17615 | res.pop();
|
17616 | res = res.concat(catmulRomToBezier(dots, crz));
|
17617 | break;
|
17618 | case 'O':
|
17619 | res.pop();
|
17620 | dots = ellipsePath(x, y, pa[1], pa[2]);
|
17621 | dots.push(dots[0]);
|
17622 | res = res.concat(dots);
|
17623 | break;
|
17624 | case 'U':
|
17625 | res.pop();
|
17626 | res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
|
17627 | r = ['U'].concat(res[res.length - 1].slice(-2));
|
17628 | break;
|
17629 | case 'M':
|
17630 | mx = +pa[1] + x;
|
17631 | my = +pa[2] + y;
|
17632 | default:
|
17633 |
|
17634 | for (j = 1, jj = pa.length; j < jj; j++) {
|
17635 | r[j] = +pa[j] + ((j % 2) ? x : y);
|
17636 | }
|
17637 | }
|
17638 | } else if (pa0 == 'R') {
|
17639 | dots = [x, y].concat(pa.slice(1));
|
17640 | res.pop();
|
17641 | res = res.concat(catmulRomToBezier(dots, crz));
|
17642 | r = ['R'].concat(pa.slice(-2));
|
17643 | } else if (pa0 == 'O') {
|
17644 | res.pop();
|
17645 | dots = ellipsePath(x, y, pa[1], pa[2]);
|
17646 | dots.push(dots[0]);
|
17647 | res = res.concat(dots);
|
17648 | } else if (pa0 == 'U') {
|
17649 | res.pop();
|
17650 | res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3]));
|
17651 | r = ['U'].concat(res[res.length - 1].slice(-2));
|
17652 | } else {
|
17653 |
|
17654 | for (var k = 0, kk = pa.length; k < kk; k++) {
|
17655 | r[k] = pa[k];
|
17656 | }
|
17657 | }
|
17658 | pa0 = pa0.toUpperCase();
|
17659 |
|
17660 | if (pa0 != 'O') {
|
17661 | switch (r[0]) {
|
17662 | case 'Z':
|
17663 | x = +mx;
|
17664 | y = +my;
|
17665 | break;
|
17666 | case 'H':
|
17667 | x = r[1];
|
17668 | break;
|
17669 | case 'V':
|
17670 | y = r[1];
|
17671 | break;
|
17672 | case 'M':
|
17673 | mx = r[r.length - 2];
|
17674 | my = r[r.length - 1];
|
17675 | default:
|
17676 | x = r[r.length - 2];
|
17677 | y = r[r.length - 1];
|
17678 | }
|
17679 | }
|
17680 | }
|
17681 |
|
17682 | res.toString = pathToString;
|
17683 | pth.abs = pathClone(res);
|
17684 |
|
17685 | return res;
|
17686 | }
|
17687 |
|
17688 | function lineToCurve(x1, y1, x2, y2) {
|
17689 | return [
|
17690 | x1, y1, x2,
|
17691 | y2, x2, y2
|
17692 | ];
|
17693 | }
|
17694 |
|
17695 | function qubicToCurve(x1, y1, ax, ay, x2, y2) {
|
17696 | var _13 = 1 / 3,
|
17697 | _23 = 2 / 3;
|
17698 |
|
17699 | return [
|
17700 | _13 * x1 + _23 * ax,
|
17701 | _13 * y1 + _23 * ay,
|
17702 | _13 * x2 + _23 * ax,
|
17703 | _13 * y2 + _23 * ay,
|
17704 | x2,
|
17705 | y2
|
17706 | ];
|
17707 | }
|
17708 |
|
17709 | function arcToCurve(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
|
17710 |
|
17711 |
|
17712 |
|
17713 | var _120 = PI * 120 / 180,
|
17714 | rad = PI / 180 * (+angle || 0),
|
17715 | res = [],
|
17716 | xy,
|
17717 | rotate = cacher(function(x, y, rad) {
|
17718 | var X = x * math.cos(rad) - y * math.sin(rad),
|
17719 | Y = x * math.sin(rad) + y * math.cos(rad);
|
17720 |
|
17721 | return { x: X, y: Y };
|
17722 | });
|
17723 |
|
17724 | if (!recursive) {
|
17725 | xy = rotate(x1, y1, -rad);
|
17726 | x1 = xy.x;
|
17727 | y1 = xy.y;
|
17728 | xy = rotate(x2, y2, -rad);
|
17729 | x2 = xy.x;
|
17730 | y2 = xy.y;
|
17731 |
|
17732 | var x = (x1 - x2) / 2,
|
17733 | y = (y1 - y2) / 2;
|
17734 |
|
17735 | var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
17736 |
|
17737 | if (h > 1) {
|
17738 | h = math.sqrt(h);
|
17739 | rx = h * rx;
|
17740 | ry = h * ry;
|
17741 | }
|
17742 |
|
17743 | var rx2 = rx * rx,
|
17744 | ry2 = ry * ry,
|
17745 | k = (large_arc_flag == sweep_flag ? -1 : 1) *
|
17746 | math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))),
|
17747 | cx = k * rx * y / ry + (x1 + x2) / 2,
|
17748 | cy = k * -ry * x / rx + (y1 + y2) / 2,
|
17749 | f1 = math.asin(((y1 - cy) / ry).toFixed(9)),
|
17750 | f2 = math.asin(((y2 - cy) / ry).toFixed(9));
|
17751 |
|
17752 | f1 = x1 < cx ? PI - f1 : f1;
|
17753 | f2 = x2 < cx ? PI - f2 : f2;
|
17754 | f1 < 0 && (f1 = PI * 2 + f1);
|
17755 | f2 < 0 && (f2 = PI * 2 + f2);
|
17756 |
|
17757 | if (sweep_flag && f1 > f2) {
|
17758 | f1 = f1 - PI * 2;
|
17759 | }
|
17760 | if (!sweep_flag && f2 > f1) {
|
17761 | f2 = f2 - PI * 2;
|
17762 | }
|
17763 | } else {
|
17764 | f1 = recursive[0];
|
17765 | f2 = recursive[1];
|
17766 | cx = recursive[2];
|
17767 | cy = recursive[3];
|
17768 | }
|
17769 |
|
17770 | var df = f2 - f1;
|
17771 |
|
17772 | if (abs(df) > _120) {
|
17773 | var f2old = f2,
|
17774 | x2old = x2,
|
17775 | y2old = y2;
|
17776 |
|
17777 | f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
|
17778 | x2 = cx + rx * math.cos(f2);
|
17779 | y2 = cy + ry * math.sin(f2);
|
17780 | res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
|
17781 | }
|
17782 |
|
17783 | df = f2 - f1;
|
17784 |
|
17785 | var c1 = math.cos(f1),
|
17786 | s1 = math.sin(f1),
|
17787 | c2 = math.cos(f2),
|
17788 | s2 = math.sin(f2),
|
17789 | t = math.tan(df / 4),
|
17790 | hx = 4 / 3 * rx * t,
|
17791 | hy = 4 / 3 * ry * t,
|
17792 | m1 = [x1, y1],
|
17793 | m2 = [x1 + hx * s1, y1 - hy * c1],
|
17794 | m3 = [x2 + hx * s2, y2 - hy * c2],
|
17795 | m4 = [x2, y2];
|
17796 |
|
17797 | m2[0] = 2 * m1[0] - m2[0];
|
17798 | m2[1] = 2 * m1[1] - m2[1];
|
17799 |
|
17800 | if (recursive) {
|
17801 | return [m2, m3, m4].concat(res);
|
17802 | } else {
|
17803 | res = [m2, m3, m4].concat(res).join().split(',');
|
17804 | var newres = [];
|
17805 |
|
17806 | for (var i = 0, ii = res.length; i < ii; i++) {
|
17807 | newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
|
17808 | }
|
17809 |
|
17810 | return newres;
|
17811 | }
|
17812 | }
|
17813 |
|
17814 |
|
17815 | function catmulRomToBezier(crp, z) {
|
17816 | var d = [];
|
17817 |
|
17818 | for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) {
|
17819 | var p = [
|
17820 | { x: +crp[i - 2], y: +crp[i - 1] },
|
17821 | { x: +crp[i], y: +crp[i + 1] },
|
17822 | { x: +crp[i + 2], y: +crp[i + 3] },
|
17823 | { x: +crp[i + 4], y: +crp[i + 5] }
|
17824 | ];
|
17825 |
|
17826 | if (z) {
|
17827 |
|
17828 | if (!i) {
|
17829 | p[0] = { x: +crp[iLen - 2], y: +crp[iLen - 1] };
|
17830 | } else if (iLen - 4 == i) {
|
17831 | p[3] = { x: +crp[0], y: +crp[1] };
|
17832 | } else if (iLen - 2 == i) {
|
17833 | p[2] = { x: +crp[0], y: +crp[1] };
|
17834 | p[3] = { x: +crp[2], y: +crp[3] };
|
17835 | }
|
17836 |
|
17837 | } else {
|
17838 |
|
17839 | if (iLen - 4 == i) {
|
17840 | p[3] = p[2];
|
17841 | } else if (!i) {
|
17842 | p[0] = { x: +crp[i], y: +crp[i + 1] };
|
17843 | }
|
17844 |
|
17845 | }
|
17846 |
|
17847 | d.push(['C',
|
17848 | (-p[0].x + 6 * p[1].x + p[2].x) / 6,
|
17849 | (-p[0].y + 6 * p[1].y + p[2].y) / 6,
|
17850 | (p[1].x + 6 * p[2].x - p[3].x) / 6,
|
17851 | (p[1].y + 6*p[2].y - p[3].y) / 6,
|
17852 | p[2].x,
|
17853 | p[2].y
|
17854 | ]);
|
17855 | }
|
17856 |
|
17857 | return d;
|
17858 | }
|
17859 |
|
17860 |
|
17861 |
|
17862 |
|
17863 |
|
17864 | function curveBBox(x0, y0, x1, y1, x2, y2, x3, y3) {
|
17865 | var tvalues = [],
|
17866 | bounds = [[], []],
|
17867 | a, b, c, t, t1, t2, b2ac, sqrtb2ac;
|
17868 |
|
17869 | for (var i = 0; i < 2; ++i) {
|
17870 |
|
17871 | if (i == 0) {
|
17872 | b = 6 * x0 - 12 * x1 + 6 * x2;
|
17873 | a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
|
17874 | c = 3 * x1 - 3 * x0;
|
17875 | } else {
|
17876 | b = 6 * y0 - 12 * y1 + 6 * y2;
|
17877 | a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
|
17878 | c = 3 * y1 - 3 * y0;
|
17879 | }
|
17880 |
|
17881 | if (abs(a) < 1e-12) {
|
17882 |
|
17883 | if (abs(b) < 1e-12) {
|
17884 | continue;
|
17885 | }
|
17886 |
|
17887 | t = -c / b;
|
17888 |
|
17889 | if (0 < t && t < 1) {
|
17890 | tvalues.push(t);
|
17891 | }
|
17892 |
|
17893 | continue;
|
17894 | }
|
17895 |
|
17896 | b2ac = b * b - 4 * c * a;
|
17897 | sqrtb2ac = math.sqrt(b2ac);
|
17898 |
|
17899 | if (b2ac < 0) {
|
17900 | continue;
|
17901 | }
|
17902 |
|
17903 | t1 = (-b + sqrtb2ac) / (2 * a);
|
17904 |
|
17905 | if (0 < t1 && t1 < 1) {
|
17906 | tvalues.push(t1);
|
17907 | }
|
17908 |
|
17909 | t2 = (-b - sqrtb2ac) / (2 * a);
|
17910 |
|
17911 | if (0 < t2 && t2 < 1) {
|
17912 | tvalues.push(t2);
|
17913 | }
|
17914 | }
|
17915 |
|
17916 | var j = tvalues.length,
|
17917 | jlen = j,
|
17918 | mt;
|
17919 |
|
17920 | while (j--) {
|
17921 | t = tvalues[j];
|
17922 | mt = 1 - t;
|
17923 | bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
|
17924 | bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
|
17925 | }
|
17926 |
|
17927 | bounds[0][jlen] = x0;
|
17928 | bounds[1][jlen] = y0;
|
17929 | bounds[0][jlen + 1] = x3;
|
17930 | bounds[1][jlen + 1] = y3;
|
17931 | bounds[0].length = bounds[1].length = jlen + 2;
|
17932 |
|
17933 | return {
|
17934 | min: { x: mmin.apply(0, bounds[0]), y: mmin.apply(0, bounds[1]) },
|
17935 | max: { x: mmax.apply(0, bounds[0]), y: mmax.apply(0, bounds[1]) }
|
17936 | };
|
17937 | }
|
17938 |
|
17939 | function pathToCurve(path, path2) {
|
17940 | var pth = !path2 && paths(path);
|
17941 |
|
17942 | if (!path2 && pth.curve) {
|
17943 | return pathClone(pth.curve);
|
17944 | }
|
17945 |
|
17946 | var p = pathToAbsolute(path),
|
17947 | p2 = path2 && pathToAbsolute(path2),
|
17948 | attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null },
|
17949 | attrs2 = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null },
|
17950 | processPath = function(path, d, pcom) {
|
17951 | var nx, ny;
|
17952 |
|
17953 | if (!path) {
|
17954 | return ['C', d.x, d.y, d.x, d.y, d.x, d.y];
|
17955 | }
|
17956 |
|
17957 | !(path[0] in { T: 1, Q: 1 }) && (d.qx = d.qy = null);
|
17958 |
|
17959 | switch (path[0]) {
|
17960 | case 'M':
|
17961 | d.X = path[1];
|
17962 | d.Y = path[2];
|
17963 | break;
|
17964 | case 'A':
|
17965 | path = ['C'].concat(arcToCurve.apply(0, [d.x, d.y].concat(path.slice(1))));
|
17966 | break;
|
17967 | case 'S':
|
17968 | if (pcom == 'C' || pcom == 'S') {
|
17969 |
|
17970 | nx = d.x * 2 - d.bx;
|
17971 |
|
17972 | ny = d.y * 2 - d.by;
|
17973 |
|
17974 | }
|
17975 | else {
|
17976 |
|
17977 | nx = d.x;
|
17978 | ny = d.y;
|
17979 | }
|
17980 | path = ['C', nx, ny].concat(path.slice(1));
|
17981 | break;
|
17982 | case 'T':
|
17983 | if (pcom == 'Q' || pcom == 'T') {
|
17984 |
|
17985 | d.qx = d.x * 2 - d.qx;
|
17986 |
|
17987 | d.qy = d.y * 2 - d.qy;
|
17988 |
|
17989 | }
|
17990 | else {
|
17991 |
|
17992 | d.qx = d.x;
|
17993 | d.qy = d.y;
|
17994 | }
|
17995 | path = ['C'].concat(qubicToCurve(d.x, d.y, d.qx, d.qy, path[1], path[2]));
|
17996 | break;
|
17997 | case 'Q':
|
17998 | d.qx = path[1];
|
17999 | d.qy = path[2];
|
18000 | path = ['C'].concat(qubicToCurve(d.x, d.y, path[1], path[2], path[3], path[4]));
|
18001 | break;
|
18002 | case 'L':
|
18003 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], path[2]));
|
18004 | break;
|
18005 | case 'H':
|
18006 | path = ['C'].concat(lineToCurve(d.x, d.y, path[1], d.y));
|
18007 | break;
|
18008 | case 'V':
|
18009 | path = ['C'].concat(lineToCurve(d.x, d.y, d.x, path[1]));
|
18010 | break;
|
18011 | case 'Z':
|
18012 | path = ['C'].concat(lineToCurve(d.x, d.y, d.X, d.Y));
|
18013 | break;
|
18014 | }
|
18015 |
|
18016 | return path;
|
18017 | },
|
18018 |
|
18019 | fixArc = function(pp, i) {
|
18020 |
|
18021 | if (pp[i].length > 7) {
|
18022 | pp[i].shift();
|
18023 | var pi = pp[i];
|
18024 |
|
18025 | while (pi.length) {
|
18026 | pcoms1[i] = 'A';
|
18027 | p2 && (pcoms2[i] = 'A');
|
18028 | pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6)));
|
18029 | }
|
18030 |
|
18031 | pp.splice(i, 1);
|
18032 | ii = mmax(p.length, p2 && p2.length || 0);
|
18033 | }
|
18034 | },
|
18035 |
|
18036 | fixM = function(path1, path2, a1, a2, i) {
|
18037 |
|
18038 | if (path1 && path2 && path1[i][0] == 'M' && path2[i][0] != 'M') {
|
18039 | path2.splice(i, 0, ['M', a2.x, a2.y]);
|
18040 | a1.bx = 0;
|
18041 | a1.by = 0;
|
18042 | a1.x = path1[i][1];
|
18043 | a1.y = path1[i][2];
|
18044 | ii = mmax(p.length, p2 && p2.length || 0);
|
18045 | }
|
18046 | },
|
18047 |
|
18048 | pcoms1 = [],
|
18049 | pcoms2 = [],
|
18050 | pfirst = '',
|
18051 | pcom = '';
|
18052 |
|
18053 | for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) {
|
18054 | p[i] && (pfirst = p[i][0]);
|
18055 |
|
18056 | if (pfirst != 'C')
|
18057 | {
|
18058 | pcoms1[i] = pfirst;
|
18059 | i && (pcom = pcoms1[i - 1]);
|
18060 | }
|
18061 | p[i] = processPath(p[i], attrs, pcom);
|
18062 |
|
18063 | if (pcoms1[i] != 'A' && pfirst == 'C') pcoms1[i] = 'C';
|
18064 |
|
18065 |
|
18066 |
|
18067 | fixArc(p, i);
|
18068 |
|
18069 | if (p2) {
|
18070 | p2[i] && (pfirst = p2[i][0]);
|
18071 |
|
18072 | if (pfirst != 'C') {
|
18073 | pcoms2[i] = pfirst;
|
18074 | i && (pcom = pcoms2[i - 1]);
|
18075 | }
|
18076 |
|
18077 | p2[i] = processPath(p2[i], attrs2, pcom);
|
18078 |
|
18079 | if (pcoms2[i] != 'A' && pfirst == 'C') {
|
18080 | pcoms2[i] = 'C';
|
18081 | }
|
18082 |
|
18083 | fixArc(p2, i);
|
18084 | }
|
18085 |
|
18086 | fixM(p, p2, attrs, attrs2, i);
|
18087 | fixM(p2, p, attrs2, attrs, i);
|
18088 |
|
18089 | var seg = p[i],
|
18090 | seg2 = p2 && p2[i],
|
18091 | seglen = seg.length,
|
18092 | seg2len = p2 && seg2.length;
|
18093 |
|
18094 | attrs.x = seg[seglen - 2];
|
18095 | attrs.y = seg[seglen - 1];
|
18096 | attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
|
18097 | attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
|
18098 | attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x);
|
18099 | attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y);
|
18100 | attrs2.x = p2 && seg2[seg2len - 2];
|
18101 | attrs2.y = p2 && seg2[seg2len - 1];
|
18102 | }
|
18103 |
|
18104 | if (!p2) {
|
18105 | pth.curve = pathClone(p);
|
18106 | }
|
18107 |
|
18108 | return p2 ? [p, p2] : p;
|
18109 | }
|
18110 |
|
18111 | var intersect = findPathIntersections;
|
18112 |
|
18113 | function roundBounds(bounds) {
|
18114 | return {
|
18115 | x: Math.round(bounds.x),
|
18116 | y: Math.round(bounds.y),
|
18117 | width: Math.round(bounds.width),
|
18118 | height: Math.round(bounds.height)
|
18119 | };
|
18120 | }
|
18121 |
|
18122 |
|
18123 | function roundPoint(point) {
|
18124 |
|
18125 | return {
|
18126 | x: Math.round(point.x),
|
18127 | y: Math.round(point.y)
|
18128 | };
|
18129 | }
|
18130 |
|
18131 |
|
18132 | |
18133 |
|
18134 |
|
18135 |
|
18136 |
|
18137 |
|
18138 |
|
18139 | function asTRBL(bounds) {
|
18140 | return {
|
18141 | top: bounds.y,
|
18142 | right: bounds.x + (bounds.width || 0),
|
18143 | bottom: bounds.y + (bounds.height || 0),
|
18144 | left: bounds.x
|
18145 | };
|
18146 | }
|
18147 |
|
18148 |
|
18149 | |
18150 |
|
18151 |
|
18152 |
|
18153 |
|
18154 |
|
18155 |
|
18156 | function asBounds(trbl) {
|
18157 | return {
|
18158 | x: trbl.left,
|
18159 | y: trbl.top,
|
18160 | width: trbl.right - trbl.left,
|
18161 | height: trbl.bottom - trbl.top
|
18162 | };
|
18163 | }
|
18164 |
|
18165 |
|
18166 | |
18167 |
|
18168 |
|
18169 |
|
18170 |
|
18171 |
|
18172 |
|
18173 | function getMid(bounds) {
|
18174 | return roundPoint({
|
18175 | x: bounds.x + (bounds.width || 0) / 2,
|
18176 | y: bounds.y + (bounds.height || 0) / 2
|
18177 | });
|
18178 | }
|
18179 |
|
18180 |
|
18181 |
|
18182 |
|
18183 | |
18184 |
|
18185 |
|
18186 |
|
18187 |
|
18188 |
|
18189 |
|
18190 |
|
18191 |
|
18192 |
|
18193 |
|
18194 |
|
18195 |
|
18196 | function getOrientation(rect, reference, padding) {
|
18197 |
|
18198 | padding = padding || 0;
|
18199 |
|
18200 |
|
18201 |
|
18202 | if (!isObject(padding)) {
|
18203 | padding = { x: padding, y: padding };
|
18204 | }
|
18205 |
|
18206 |
|
18207 | var rectOrientation = asTRBL(rect),
|
18208 | referenceOrientation = asTRBL(reference);
|
18209 |
|
18210 | var top = rectOrientation.bottom + padding.y <= referenceOrientation.top,
|
18211 | right = rectOrientation.left - padding.x >= referenceOrientation.right,
|
18212 | bottom = rectOrientation.top - padding.y >= referenceOrientation.bottom,
|
18213 | left = rectOrientation.right + padding.x <= referenceOrientation.left;
|
18214 |
|
18215 | var vertical = top ? 'top' : (bottom ? 'bottom' : null),
|
18216 | horizontal = left ? 'left' : (right ? 'right' : null);
|
18217 |
|
18218 | if (horizontal && vertical) {
|
18219 | return vertical + '-' + horizontal;
|
18220 | } else {
|
18221 | return horizontal || vertical || 'intersect';
|
18222 | }
|
18223 | }
|
18224 |
|
18225 |
|
18226 |
|
18227 |
|
18228 | |
18229 |
|
18230 |
|
18231 |
|
18232 |
|
18233 |
|
18234 |
|
18235 |
|
18236 |
|
18237 | function getElementLineIntersection(elementPath, linePath, cropStart) {
|
18238 |
|
18239 | var intersections = getIntersections(elementPath, linePath);
|
18240 |
|
18241 |
|
18242 |
|
18243 |
|
18244 |
|
18245 |
|
18246 | if (intersections.length === 1) {
|
18247 | return roundPoint(intersections[0]);
|
18248 | } else if (intersections.length === 2 && pointDistance(intersections[0], intersections[1]) < 1) {
|
18249 | return roundPoint(intersections[0]);
|
18250 | } else if (intersections.length > 1) {
|
18251 |
|
18252 |
|
18253 |
|
18254 | intersections = sortBy(intersections, function(i) {
|
18255 | var distance = Math.floor(i.t2 * 100) || 1;
|
18256 |
|
18257 | distance = 100 - distance;
|
18258 |
|
18259 | distance = (distance < 10 ? '0' : '') + distance;
|
18260 |
|
18261 |
|
18262 |
|
18263 |
|
18264 | return i.segment2 + '#' + distance;
|
18265 | });
|
18266 |
|
18267 | return roundPoint(intersections[cropStart ? 0 : intersections.length - 1]);
|
18268 | }
|
18269 |
|
18270 | return null;
|
18271 | }
|
18272 |
|
18273 |
|
18274 | function getIntersections(a, b) {
|
18275 | return intersect(a, b);
|
18276 | }
|
18277 |
|
18278 | function elementData(semantic, attrs) {
|
18279 | return assign({
|
18280 | id: semantic.id,
|
18281 | type: semantic.$type,
|
18282 | businessObject: semantic
|
18283 | }, attrs);
|
18284 | }
|
18285 |
|
18286 | function collectWaypoints(waypoints) {
|
18287 | return map(waypoints, function(p) {
|
18288 | return { x: p.x, y: p.y };
|
18289 | });
|
18290 | }
|
18291 |
|
18292 | function notYetDrawn(translate, semantic, refSemantic, property) {
|
18293 | return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
|
18294 | element: elementToString(refSemantic),
|
18295 | referenced: elementToString(semantic),
|
18296 | property: property
|
18297 | }));
|
18298 | }
|
18299 |
|
18300 |
|
18301 | |
18302 |
|
18303 |
|
18304 |
|
18305 |
|
18306 |
|
18307 |
|
18308 |
|
18309 |
|
18310 |
|
18311 | function BpmnImporter(
|
18312 | eventBus, canvas, elementFactory,
|
18313 | elementRegistry, translate, textRenderer) {
|
18314 |
|
18315 | this._eventBus = eventBus;
|
18316 | this._canvas = canvas;
|
18317 | this._elementFactory = elementFactory;
|
18318 | this._elementRegistry = elementRegistry;
|
18319 | this._translate = translate;
|
18320 | this._textRenderer = textRenderer;
|
18321 | }
|
18322 |
|
18323 | BpmnImporter.$inject = [
|
18324 | 'eventBus',
|
18325 | 'canvas',
|
18326 | 'elementFactory',
|
18327 | 'elementRegistry',
|
18328 | 'translate',
|
18329 | 'textRenderer'
|
18330 | ];
|
18331 |
|
18332 |
|
18333 | |
18334 |
|
18335 |
|
18336 |
|
18337 | BpmnImporter.prototype.add = function(semantic, parentElement) {
|
18338 |
|
18339 | var di = semantic.di,
|
18340 | element,
|
18341 | translate = this._translate,
|
18342 | hidden;
|
18343 |
|
18344 | var parentIndex;
|
18345 |
|
18346 |
|
18347 |
|
18348 |
|
18349 | if (is$1(di, 'bpmndi:BPMNPlane')) {
|
18350 |
|
18351 |
|
18352 | element = this._elementFactory.createRoot(elementData(semantic));
|
18353 |
|
18354 | this._canvas.setRootElement(element);
|
18355 | }
|
18356 |
|
18357 |
|
18358 | else if (is$1(di, 'bpmndi:BPMNShape')) {
|
18359 |
|
18360 | var collapsed = !isExpanded(semantic);
|
18361 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
18362 |
|
18363 | var bounds = semantic.di.bounds;
|
18364 |
|
18365 | element = this._elementFactory.createShape(elementData(semantic, {
|
18366 | collapsed: collapsed,
|
18367 | hidden: hidden,
|
18368 | x: Math.round(bounds.x),
|
18369 | y: Math.round(bounds.y),
|
18370 | width: Math.round(bounds.width),
|
18371 | height: Math.round(bounds.height)
|
18372 | }));
|
18373 |
|
18374 | if (is$1(semantic, 'bpmn:BoundaryEvent')) {
|
18375 | this._attachBoundary(semantic, element);
|
18376 | }
|
18377 |
|
18378 |
|
18379 | if (is$1(semantic, 'bpmn:Lane')) {
|
18380 | parentIndex = 0;
|
18381 | }
|
18382 |
|
18383 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
18384 |
|
18385 |
|
18386 | if (!isPointInsideBBox$1(parentElement, getMid(bounds))) {
|
18387 | parentElement = this._canvas.getRootElement();
|
18388 | }
|
18389 | }
|
18390 |
|
18391 | this._canvas.addShape(element, parentElement, parentIndex);
|
18392 | }
|
18393 |
|
18394 |
|
18395 | else if (is$1(di, 'bpmndi:BPMNEdge')) {
|
18396 |
|
18397 | var source = this._getSource(semantic),
|
18398 | target = this._getTarget(semantic);
|
18399 |
|
18400 | hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
18401 |
|
18402 | element = this._elementFactory.createConnection(elementData(semantic, {
|
18403 | hidden: hidden,
|
18404 | source: source,
|
18405 | target: target,
|
18406 | waypoints: collectWaypoints(semantic.di.waypoint)
|
18407 | }));
|
18408 |
|
18409 | if (is$1(semantic, 'bpmn:DataAssociation')) {
|
18410 |
|
18411 |
|
18412 |
|
18413 |
|
18414 |
|
18415 | parentElement = null;
|
18416 | }
|
18417 |
|
18418 |
|
18419 | if (is$1(semantic, 'bpmn:SequenceFlow')) {
|
18420 | parentIndex = 0;
|
18421 | }
|
18422 |
|
18423 | this._canvas.addConnection(element, parentElement, parentIndex);
|
18424 | } else {
|
18425 | throw new Error(translate('unknown di {di} for element {semantic}', {
|
18426 | di: elementToString(di),
|
18427 | semantic: elementToString(semantic)
|
18428 | }));
|
18429 | }
|
18430 |
|
18431 | if (isLabelExternal(semantic) && semantic.name) {
|
18432 | this.addLabel(semantic, element);
|
18433 | }
|
18434 |
|
18435 |
|
18436 | this._eventBus.fire('bpmnElement.added', { element: element });
|
18437 |
|
18438 | return element;
|
18439 | };
|
18440 |
|
18441 |
|
18442 | |
18443 |
|
18444 |
|
18445 |
|
18446 |
|
18447 |
|
18448 | BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
|
18449 | var translate = this._translate;
|
18450 | var hostSemantic = boundarySemantic.attachedToRef;
|
18451 |
|
18452 | if (!hostSemantic) {
|
18453 | throw new Error(translate('missing {semantic}#attachedToRef', {
|
18454 | semantic: elementToString(boundarySemantic)
|
18455 | }));
|
18456 | }
|
18457 |
|
18458 | var host = this._elementRegistry.get(hostSemantic.id),
|
18459 | attachers = host && host.attachers;
|
18460 |
|
18461 | if (!host) {
|
18462 | throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
|
18463 | }
|
18464 |
|
18465 |
|
18466 | boundaryElement.host = host;
|
18467 |
|
18468 | if (!attachers) {
|
18469 | host.attachers = attachers = [];
|
18470 | }
|
18471 |
|
18472 | if (attachers.indexOf(boundaryElement) === -1) {
|
18473 | attachers.push(boundaryElement);
|
18474 | }
|
18475 | };
|
18476 |
|
18477 |
|
18478 | |
18479 |
|
18480 |
|
18481 | BpmnImporter.prototype.addLabel = function(semantic, element) {
|
18482 | var bounds,
|
18483 | text,
|
18484 | label;
|
18485 |
|
18486 | bounds = getExternalLabelBounds(semantic, element);
|
18487 |
|
18488 | text = semantic.name;
|
18489 |
|
18490 | if (text) {
|
18491 |
|
18492 | bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
|
18493 | }
|
18494 |
|
18495 | label = this._elementFactory.createLabel(elementData(semantic, {
|
18496 | id: semantic.id + '_label',
|
18497 | labelTarget: element,
|
18498 | type: 'label',
|
18499 | hidden: element.hidden || !semantic.name,
|
18500 | x: Math.round(bounds.x),
|
18501 | y: Math.round(bounds.y),
|
18502 | width: Math.round(bounds.width),
|
18503 | height: Math.round(bounds.height)
|
18504 | }));
|
18505 |
|
18506 | return this._canvas.addShape(label, element.parent);
|
18507 | };
|
18508 |
|
18509 | |
18510 |
|
18511 |
|
18512 |
|
18513 |
|
18514 | BpmnImporter.prototype._getEnd = function(semantic, side) {
|
18515 |
|
18516 | var element,
|
18517 | refSemantic,
|
18518 | type = semantic.$type,
|
18519 | translate = this._translate;
|
18520 |
|
18521 | refSemantic = semantic[side + 'Ref'];
|
18522 |
|
18523 |
|
18524 | if (side === 'source' && type === 'bpmn:DataInputAssociation') {
|
18525 | refSemantic = refSemantic && refSemantic[0];
|
18526 | }
|
18527 |
|
18528 |
|
18529 | if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
|
18530 | side === 'target' && type === 'bpmn:DataInputAssociation') {
|
18531 |
|
18532 | refSemantic = semantic.$parent;
|
18533 | }
|
18534 |
|
18535 | element = refSemantic && this._getElement(refSemantic);
|
18536 |
|
18537 | if (element) {
|
18538 | return element;
|
18539 | }
|
18540 |
|
18541 | if (refSemantic) {
|
18542 | throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
|
18543 | } else {
|
18544 | throw new Error(translate('{semantic}#{side} Ref not specified', {
|
18545 | semantic: elementToString(semantic),
|
18546 | side: side
|
18547 | }));
|
18548 | }
|
18549 | };
|
18550 |
|
18551 | BpmnImporter.prototype._getSource = function(semantic) {
|
18552 | return this._getEnd(semantic, 'source');
|
18553 | };
|
18554 |
|
18555 | BpmnImporter.prototype._getTarget = function(semantic) {
|
18556 | return this._getEnd(semantic, 'target');
|
18557 | };
|
18558 |
|
18559 |
|
18560 | BpmnImporter.prototype._getElement = function(semantic) {
|
18561 | return this._elementRegistry.get(semantic.id);
|
18562 | };
|
18563 |
|
18564 |
|
18565 |
|
18566 |
|
18567 | function isPointInsideBBox$1(bbox, point) {
|
18568 | var x = point.x,
|
18569 | y = point.y;
|
18570 |
|
18571 | return x >= bbox.x &&
|
18572 | x <= bbox.x + bbox.width &&
|
18573 | y >= bbox.y &&
|
18574 | y <= bbox.y + bbox.height;
|
18575 | }
|
18576 |
|
18577 | var ImportModule = {
|
18578 | __depends__: [
|
18579 | translate$2
|
18580 | ],
|
18581 | bpmnImporter: [ 'type', BpmnImporter ]
|
18582 | };
|
18583 |
|
18584 | var CoreModule$1 = {
|
18585 | __depends__: [
|
18586 | DrawModule$1,
|
18587 | ImportModule
|
18588 | ]
|
18589 | };
|
18590 |
|
18591 | function __stopPropagation(event) {
|
18592 | if (!event || typeof event.stopPropagation !== 'function') {
|
18593 | return;
|
18594 | }
|
18595 |
|
18596 | event.stopPropagation();
|
18597 | }
|
18598 |
|
18599 |
|
18600 | function getOriginal(event) {
|
18601 | return event.originalEvent || event.srcEvent;
|
18602 | }
|
18603 |
|
18604 |
|
18605 | function stopPropagation(event, immediate) {
|
18606 | __stopPropagation(event, immediate);
|
18607 | __stopPropagation(getOriginal(event), immediate);
|
18608 | }
|
18609 |
|
18610 |
|
18611 | function toPoint(event) {
|
18612 |
|
18613 | if (event.pointers && event.pointers.length) {
|
18614 | event = event.pointers[0];
|
18615 | }
|
18616 |
|
18617 | if (event.touches && event.touches.length) {
|
18618 | event = event.touches[0];
|
18619 | }
|
18620 |
|
18621 | return event ? {
|
18622 | x: event.clientX,
|
18623 | y: event.clientY
|
18624 | } : null;
|
18625 | }
|
18626 |
|
18627 | function isMac() {
|
18628 | return (/mac/i).test(navigator.platform);
|
18629 | }
|
18630 |
|
18631 | function isPrimaryButton(event) {
|
18632 |
|
18633 | return !(getOriginal(event) || event).button;
|
18634 | }
|
18635 |
|
18636 | function hasPrimaryModifier(event) {
|
18637 | var originalEvent = getOriginal(event) || event;
|
18638 |
|
18639 | if (!isPrimaryButton(event)) {
|
18640 | return false;
|
18641 | }
|
18642 |
|
18643 |
|
18644 | if (isMac()) {
|
18645 | return originalEvent.metaKey;
|
18646 | } else {
|
18647 | return originalEvent.ctrlKey;
|
18648 | }
|
18649 | }
|
18650 |
|
18651 |
|
18652 | function hasSecondaryModifier(event) {
|
18653 | var originalEvent = getOriginal(event) || event;
|
18654 |
|
18655 | return isPrimaryButton(event) && originalEvent.shiftKey;
|
18656 | }
|
18657 |
|
18658 | function allowAll(e) { return true; }
|
18659 |
|
18660 | var LOW_PRIORITY = 500;
|
18661 |
|
18662 | |
18663 |
|
18664 |
|
18665 |
|
18666 |
|
18667 |
|
18668 |
|
18669 |
|
18670 |
|
18671 |
|
18672 |
|
18673 |
|
18674 |
|
18675 |
|
18676 |
|
18677 |
|
18678 |
|
18679 |
|
18680 |
|
18681 | function InteractionEvents(eventBus, elementRegistry, styles) {
|
18682 |
|
18683 | var HIT_STYLE = styles.cls('djs-hit', [ 'no-fill', 'no-border' ], {
|
18684 | stroke: 'white',
|
18685 | strokeWidth: 15
|
18686 | });
|
18687 |
|
18688 | |
18689 |
|
18690 |
|
18691 |
|
18692 |
|
18693 |
|
18694 |
|
18695 |
|
18696 | function fire(type, event, element) {
|
18697 |
|
18698 | if (isIgnored(type, event)) {
|
18699 | return;
|
18700 | }
|
18701 |
|
18702 | var target, gfx, returnValue;
|
18703 |
|
18704 | if (!element) {
|
18705 | target = event.delegateTarget || event.target;
|
18706 |
|
18707 | if (target) {
|
18708 | gfx = target;
|
18709 | element = elementRegistry.get(gfx);
|
18710 | }
|
18711 | } else {
|
18712 | gfx = elementRegistry.getGraphics(element);
|
18713 | }
|
18714 |
|
18715 | if (!gfx || !element) {
|
18716 | return;
|
18717 | }
|
18718 |
|
18719 | returnValue = eventBus.fire(type, {
|
18720 | element: element,
|
18721 | gfx: gfx,
|
18722 | originalEvent: event
|
18723 | });
|
18724 |
|
18725 | if (returnValue === false) {
|
18726 | event.stopPropagation();
|
18727 | event.preventDefault();
|
18728 | }
|
18729 | }
|
18730 |
|
18731 |
|
18732 | var handlers = {};
|
18733 |
|
18734 | function mouseHandler(localEventName) {
|
18735 | return handlers[localEventName];
|
18736 | }
|
18737 |
|
18738 | function isIgnored(localEventName, event) {
|
18739 |
|
18740 | var filter$$1 = ignoredFilters[localEventName] || isPrimaryButton;
|
18741 |
|
18742 |
|
18743 |
|
18744 |
|
18745 | return !filter$$1(event);
|
18746 | }
|
18747 |
|
18748 | var bindings = {
|
18749 | mouseover: 'element.hover',
|
18750 | mouseout: 'element.out',
|
18751 | click: 'element.click',
|
18752 | dblclick: 'element.dblclick',
|
18753 | mousedown: 'element.mousedown',
|
18754 | mouseup: 'element.mouseup',
|
18755 | contextmenu: 'element.contextmenu'
|
18756 | };
|
18757 |
|
18758 | var ignoredFilters = {
|
18759 | 'element.contextmenu': allowAll
|
18760 | };
|
18761 |
|
18762 |
|
18763 |
|
18764 |
|
18765 | |
18766 |
|
18767 |
|
18768 |
|
18769 |
|
18770 |
|
18771 |
|
18772 |
|
18773 | function triggerMouseEvent(eventName, event, targetElement) {
|
18774 |
|
18775 |
|
18776 | var localEventName = bindings[eventName];
|
18777 |
|
18778 | if (!localEventName) {
|
18779 | throw new Error('unmapped DOM event name <' + eventName + '>');
|
18780 | }
|
18781 |
|
18782 | return fire(localEventName, event, targetElement);
|
18783 | }
|
18784 |
|
18785 |
|
18786 | var elementSelector = 'svg, .djs-element';
|
18787 |
|
18788 |
|
18789 |
|
18790 | function registerEvent(node, event, localEvent, ignoredFilter) {
|
18791 |
|
18792 | var handler = handlers[localEvent] = function(event) {
|
18793 | fire(localEvent, event);
|
18794 | };
|
18795 |
|
18796 | if (ignoredFilter) {
|
18797 | ignoredFilters[localEvent] = ignoredFilter;
|
18798 | }
|
18799 |
|
18800 | handler.$delegate = delegateEvents.bind(node, elementSelector, event, handler);
|
18801 | }
|
18802 |
|
18803 | function unregisterEvent(node, event, localEvent) {
|
18804 |
|
18805 | var handler = mouseHandler(localEvent);
|
18806 |
|
18807 | if (!handler) {
|
18808 | return;
|
18809 | }
|
18810 |
|
18811 | delegateEvents.unbind(node, event, handler.$delegate);
|
18812 | }
|
18813 |
|
18814 | function registerEvents(svg) {
|
18815 | forEach(bindings, function(val, key) {
|
18816 | registerEvent(svg, key, val);
|
18817 | });
|
18818 | }
|
18819 |
|
18820 | function unregisterEvents(svg) {
|
18821 | forEach(bindings, function(val, key) {
|
18822 | unregisterEvent(svg, key, val);
|
18823 | });
|
18824 | }
|
18825 |
|
18826 | eventBus.on('canvas.destroy', function(event) {
|
18827 | unregisterEvents(event.svg);
|
18828 | });
|
18829 |
|
18830 | eventBus.on('canvas.init', function(event) {
|
18831 | registerEvents(event.svg);
|
18832 | });
|
18833 |
|
18834 |
|
18835 | eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
|
18836 | var element = event.element,
|
18837 | gfx = event.gfx,
|
18838 | hit;
|
18839 |
|
18840 | if (element.waypoints) {
|
18841 | hit = createLine(element.waypoints);
|
18842 | } else {
|
18843 | hit = create('rect');
|
18844 | attr$1(hit, {
|
18845 | x: 0,
|
18846 | y: 0,
|
18847 | width: element.width,
|
18848 | height: element.height
|
18849 | });
|
18850 | }
|
18851 |
|
18852 | attr$1(hit, HIT_STYLE);
|
18853 |
|
18854 | append(gfx, hit);
|
18855 | });
|
18856 |
|
18857 |
|
18858 |
|
18859 |
|
18860 | eventBus.on('shape.changed', LOW_PRIORITY, function(event) {
|
18861 |
|
18862 | var element = event.element,
|
18863 | gfx = event.gfx,
|
18864 | hit = query('.djs-hit', gfx);
|
18865 |
|
18866 | attr$1(hit, {
|
18867 | width: element.width,
|
18868 | height: element.height
|
18869 | });
|
18870 | });
|
18871 |
|
18872 | eventBus.on('connection.changed', function(event) {
|
18873 |
|
18874 | var element = event.element,
|
18875 | gfx = event.gfx,
|
18876 | hit = query('.djs-hit', gfx);
|
18877 |
|
18878 | updateLine(hit, element.waypoints);
|
18879 | });
|
18880 |
|
18881 |
|
18882 |
|
18883 |
|
18884 | this.fire = fire;
|
18885 |
|
18886 | this.triggerMouseEvent = triggerMouseEvent;
|
18887 |
|
18888 | this.mouseHandler = mouseHandler;
|
18889 |
|
18890 | this.registerEvent = registerEvent;
|
18891 | this.unregisterEvent = unregisterEvent;
|
18892 | }
|
18893 |
|
18894 |
|
18895 | InteractionEvents.$inject = [
|
18896 | 'eventBus',
|
18897 | 'elementRegistry',
|
18898 | 'styles'
|
18899 | ];
|
18900 |
|
18901 |
|
18902 | |
18903 |
|
18904 |
|
18905 |
|
18906 |
|
18907 |
|
18908 |
|
18909 |
|
18910 |
|
18911 |
|
18912 |
|
18913 | |
18914 |
|
18915 |
|
18916 |
|
18917 |
|
18918 |
|
18919 |
|
18920 |
|
18921 |
|
18922 |
|
18923 |
|
18924 | |
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 |
|
18930 |
|
18931 |
|
18932 |
|
18933 |
|
18934 |
|
18935 | |
18936 |
|
18937 |
|
18938 |
|
18939 |
|
18940 |
|
18941 |
|
18942 |
|
18943 |
|
18944 |
|
18945 |
|
18946 | |
18947 |
|
18948 |
|
18949 |
|
18950 |
|
18951 |
|
18952 |
|
18953 |
|
18954 |
|
18955 |
|
18956 |
|
18957 | |
18958 |
|
18959 |
|
18960 |
|
18961 |
|
18962 |
|
18963 |
|
18964 |
|
18965 |
|
18966 |
|
18967 |
|
18968 | |
18969 |
|
18970 |
|
18971 |
|
18972 |
|
18973 |
|
18974 |
|
18975 |
|
18976 |
|
18977 |
|
18978 |
|
18979 |
|
18980 | var InteractionEventsModule = {
|
18981 | __init__: [ 'interactionEvents' ],
|
18982 | interactionEvents: [ 'type', InteractionEvents ]
|
18983 | };
|
18984 |
|
18985 | var LOW_PRIORITY$1 = 500;
|
18986 |
|
18987 |
|
18988 | |
18989 |
|
18990 |
|
18991 |
|
18992 |
|
18993 |
|
18994 |
|
18995 |
|
18996 |
|
18997 |
|
18998 | function Outline(eventBus, styles, elementRegistry) {
|
18999 |
|
19000 | this.offset = 6;
|
19001 |
|
19002 | var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
|
19003 |
|
19004 | var self = this;
|
19005 |
|
19006 | function createOutline(gfx, bounds) {
|
19007 | var outline = create('rect');
|
19008 |
|
19009 | attr$1(outline, assign({
|
19010 | x: 10,
|
19011 | y: 10,
|
19012 | width: 100,
|
19013 | height: 100
|
19014 | }, OUTLINE_STYLE));
|
19015 |
|
19016 | append(gfx, outline);
|
19017 |
|
19018 | return outline;
|
19019 | }
|
19020 |
|
19021 |
|
19022 |
|
19023 | eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$1, function(event) {
|
19024 | var element = event.element,
|
19025 | gfx = event.gfx;
|
19026 |
|
19027 | var outline = query('.djs-outline', gfx);
|
19028 |
|
19029 | if (!outline) {
|
19030 | outline = createOutline(gfx, element);
|
19031 | }
|
19032 |
|
19033 | self.updateShapeOutline(outline, element);
|
19034 | });
|
19035 |
|
19036 | eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
|
19037 | var element = event.element,
|
19038 | gfx = event.gfx;
|
19039 |
|
19040 | var outline = query('.djs-outline', gfx);
|
19041 |
|
19042 | if (!outline) {
|
19043 | outline = createOutline(gfx, element);
|
19044 | }
|
19045 |
|
19046 | self.updateConnectionOutline(outline, element);
|
19047 | });
|
19048 | }
|
19049 |
|
19050 |
|
19051 | |
19052 |
|
19053 |
|
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 | Outline.prototype.updateShapeOutline = function(outline, element) {
|
19059 |
|
19060 | attr$1(outline, {
|
19061 | x: -this.offset,
|
19062 | y: -this.offset,
|
19063 | width: element.width + this.offset * 2,
|
19064 | height: element.height + this.offset * 2
|
19065 | });
|
19066 |
|
19067 | };
|
19068 |
|
19069 |
|
19070 | |
19071 |
|
19072 |
|
19073 |
|
19074 |
|
19075 |
|
19076 |
|
19077 | Outline.prototype.updateConnectionOutline = function(outline, connection) {
|
19078 |
|
19079 | var bbox = getBBox(connection);
|
19080 |
|
19081 | attr$1(outline, {
|
19082 | x: bbox.x - this.offset,
|
19083 | y: bbox.y - this.offset,
|
19084 | width: bbox.width + this.offset * 2,
|
19085 | height: bbox.height + this.offset * 2
|
19086 | });
|
19087 |
|
19088 | };
|
19089 |
|
19090 |
|
19091 | Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
|
19092 |
|
19093 | var OutlineModule = {
|
19094 | __init__: [ 'outline' ],
|
19095 | outline: [ 'type', Outline ]
|
19096 | };
|
19097 |
|
19098 | |
19099 |
|
19100 |
|
19101 |
|
19102 |
|
19103 |
|
19104 |
|
19105 |
|
19106 | function Selection(eventBus) {
|
19107 |
|
19108 | this._eventBus = eventBus;
|
19109 |
|
19110 | this._selectedElements = [];
|
19111 |
|
19112 | var self = this;
|
19113 |
|
19114 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
19115 | var element = e.element;
|
19116 | self.deselect(element);
|
19117 | });
|
19118 |
|
19119 | eventBus.on([ 'diagram.clear' ], function(e) {
|
19120 | self.select(null);
|
19121 | });
|
19122 | }
|
19123 |
|
19124 | Selection.$inject = [ 'eventBus' ];
|
19125 |
|
19126 |
|
19127 | Selection.prototype.deselect = function(element) {
|
19128 | var selectedElements = this._selectedElements;
|
19129 |
|
19130 | var idx = selectedElements.indexOf(element);
|
19131 |
|
19132 | if (idx !== -1) {
|
19133 | var oldSelection = selectedElements.slice();
|
19134 |
|
19135 | selectedElements.splice(idx, 1);
|
19136 |
|
19137 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
19138 | }
|
19139 | };
|
19140 |
|
19141 |
|
19142 | Selection.prototype.get = function() {
|
19143 | return this._selectedElements;
|
19144 | };
|
19145 |
|
19146 | Selection.prototype.isSelected = function(element) {
|
19147 | return this._selectedElements.indexOf(element) !== -1;
|
19148 | };
|
19149 |
|
19150 |
|
19151 | |
19152 |
|
19153 |
|
19154 |
|
19155 |
|
19156 |
|
19157 |
|
19158 |
|
19159 |
|
19160 |
|
19161 |
|
19162 | Selection.prototype.select = function(elements, add) {
|
19163 | var selectedElements = this._selectedElements,
|
19164 | oldSelection = selectedElements.slice();
|
19165 |
|
19166 | if (!isArray(elements)) {
|
19167 | elements = elements ? [ elements ] : [];
|
19168 | }
|
19169 |
|
19170 |
|
19171 |
|
19172 | if (add) {
|
19173 | forEach(elements, function(element) {
|
19174 | if (selectedElements.indexOf(element) !== -1) {
|
19175 |
|
19176 | return;
|
19177 | } else {
|
19178 | selectedElements.push(element);
|
19179 | }
|
19180 | });
|
19181 | } else {
|
19182 | this._selectedElements = selectedElements = elements.slice();
|
19183 | }
|
19184 |
|
19185 | this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
|
19186 | };
|
19187 |
|
19188 | var MARKER_HOVER = 'hover',
|
19189 | MARKER_SELECTED = 'selected';
|
19190 |
|
19191 |
|
19192 | |
19193 |
|
19194 |
|
19195 |
|
19196 |
|
19197 |
|
19198 |
|
19199 |
|
19200 |
|
19201 |
|
19202 |
|
19203 |
|
19204 | function SelectionVisuals(events, canvas, selection, styles) {
|
19205 |
|
19206 | this._multiSelectionBox = null;
|
19207 |
|
19208 | function addMarker(e, cls) {
|
19209 | canvas.addMarker(e, cls);
|
19210 | }
|
19211 |
|
19212 | function removeMarker(e, cls) {
|
19213 | canvas.removeMarker(e, cls);
|
19214 | }
|
19215 |
|
19216 | events.on('element.hover', function(event) {
|
19217 | addMarker(event.element, MARKER_HOVER);
|
19218 | });
|
19219 |
|
19220 | events.on('element.out', function(event) {
|
19221 | removeMarker(event.element, MARKER_HOVER);
|
19222 | });
|
19223 |
|
19224 | events.on('selection.changed', function(event) {
|
19225 |
|
19226 | function deselect(s) {
|
19227 | removeMarker(s, MARKER_SELECTED);
|
19228 | }
|
19229 |
|
19230 | function select(s) {
|
19231 | addMarker(s, MARKER_SELECTED);
|
19232 | }
|
19233 |
|
19234 | var oldSelection = event.oldSelection,
|
19235 | newSelection = event.newSelection;
|
19236 |
|
19237 | forEach(oldSelection, function(e) {
|
19238 | if (newSelection.indexOf(e) === -1) {
|
19239 | deselect(e);
|
19240 | }
|
19241 | });
|
19242 |
|
19243 | forEach(newSelection, function(e) {
|
19244 | if (oldSelection.indexOf(e) === -1) {
|
19245 | select(e);
|
19246 | }
|
19247 | });
|
19248 | });
|
19249 | }
|
19250 |
|
19251 | SelectionVisuals.$inject = [
|
19252 | 'eventBus',
|
19253 | 'canvas',
|
19254 | 'selection',
|
19255 | 'styles'
|
19256 | ];
|
19257 |
|
19258 | function SelectionBehavior(
|
19259 | eventBus, selection, canvas,
|
19260 | elementRegistry) {
|
19261 |
|
19262 | eventBus.on('create.end', 500, function(e) {
|
19263 |
|
19264 |
|
19265 |
|
19266 | if (e.context.canExecute) {
|
19267 | selection.select(e.context.shape);
|
19268 | }
|
19269 | });
|
19270 |
|
19271 | eventBus.on('connect.end', 500, function(e) {
|
19272 |
|
19273 |
|
19274 |
|
19275 | if (e.context.canExecute && e.context.target) {
|
19276 | selection.select(e.context.target);
|
19277 | }
|
19278 | });
|
19279 |
|
19280 | eventBus.on('shape.move.end', 500, function(e) {
|
19281 | var previousSelection = e.previousSelection || [];
|
19282 |
|
19283 | var shape = elementRegistry.get(e.context.shape.id);
|
19284 |
|
19285 |
|
19286 |
|
19287 | var inSelection = find(previousSelection, function(selectedShape) {
|
19288 | return shape.id === selectedShape.id;
|
19289 | });
|
19290 |
|
19291 | if (!inSelection) {
|
19292 | selection.select(shape);
|
19293 | }
|
19294 | });
|
19295 |
|
19296 |
|
19297 | eventBus.on('element.click', function(event) {
|
19298 |
|
19299 | var element = event.element;
|
19300 |
|
19301 |
|
19302 |
|
19303 | if (element === canvas.getRootElement()) {
|
19304 | element = null;
|
19305 | }
|
19306 |
|
19307 | var isSelected = selection.isSelected(element),
|
19308 | isMultiSelect = selection.get().length > 1;
|
19309 |
|
19310 |
|
19311 | var add = hasPrimaryModifier(event);
|
19312 |
|
19313 |
|
19314 | if (isSelected && isMultiSelect) {
|
19315 | if (add) {
|
19316 | return selection.deselect(element);
|
19317 | } else {
|
19318 | return selection.select(element);
|
19319 | }
|
19320 | } else
|
19321 | if (!isSelected) {
|
19322 | selection.select(element, add);
|
19323 | } else {
|
19324 | selection.deselect(element);
|
19325 | }
|
19326 | });
|
19327 | }
|
19328 |
|
19329 | SelectionBehavior.$inject = [
|
19330 | 'eventBus',
|
19331 | 'selection',
|
19332 | 'canvas',
|
19333 | 'elementRegistry'
|
19334 | ];
|
19335 |
|
19336 | var SelectionModule = {
|
19337 | __init__: [ 'selectionVisuals', 'selectionBehavior' ],
|
19338 | __depends__: [
|
19339 | InteractionEventsModule,
|
19340 | OutlineModule
|
19341 | ],
|
19342 | selection: [ 'type', Selection ],
|
19343 | selectionVisuals: [ 'type', SelectionVisuals ],
|
19344 | selectionBehavior: [ 'type', SelectionBehavior ]
|
19345 | };
|
19346 |
|
19347 | |
19348 |
|
19349 |
|
19350 |
|
19351 |
|
19352 |
|
19353 |
|
19354 |
|
19355 |
|
19356 |
|
19357 |
|
19358 | function IdGenerator(prefix) {
|
19359 |
|
19360 | this._counter = 0;
|
19361 | this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
|
19362 | }
|
19363 |
|
19364 | |
19365 |
|
19366 |
|
19367 |
|
19368 |
|
19369 |
|
19370 |
|
19371 | IdGenerator.prototype.next = function() {
|
19372 | return this._prefix + (++this._counter);
|
19373 | };
|
19374 |
|
19375 |
|
19376 | var ids$1 = new IdGenerator('ov');
|
19377 |
|
19378 | var LOW_PRIORITY$2 = 500;
|
19379 |
|
19380 |
|
19381 | |
19382 |
|
19383 |
|
19384 |
|
19385 |
|
19386 |
|
19387 |
|
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 |
|
19397 |
|
19398 |
|
19399 |
|
19400 |
|
19401 |
|
19402 |
|
19403 |
|
19404 |
|
19405 |
|
19406 |
|
19407 |
|
19408 |
|
19409 |
|
19410 |
|
19411 |
|
19412 |
|
19413 |
|
19414 |
|
19415 |
|
19416 |
|
19417 |
|
19418 |
|
19419 |
|
19420 |
|
19421 |
|
19422 |
|
19423 |
|
19424 |
|
19425 |
|
19426 |
|
19427 |
|
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 |
|
19434 |
|
19435 |
|
19436 |
|
19437 |
|
19438 |
|
19439 |
|
19440 |
|
19441 |
|
19442 |
|
19443 |
|
19444 |
|
19445 | function Overlays(config, eventBus, canvas, elementRegistry) {
|
19446 |
|
19447 | this._eventBus = eventBus;
|
19448 | this._canvas = canvas;
|
19449 | this._elementRegistry = elementRegistry;
|
19450 |
|
19451 | this._ids = ids$1;
|
19452 |
|
19453 | this._overlayDefaults = assign({
|
19454 |
|
19455 | show: null,
|
19456 |
|
19457 |
|
19458 | scale: true
|
19459 | }, config && config.defaults);
|
19460 |
|
19461 | |
19462 |
|
19463 |
|
19464 | this._overlays = {};
|
19465 |
|
19466 | |
19467 |
|
19468 |
|
19469 | this._overlayContainers = [];
|
19470 |
|
19471 |
|
19472 | this._overlayRoot = createRoot(canvas.getContainer());
|
19473 |
|
19474 | this._init();
|
19475 | }
|
19476 |
|
19477 |
|
19478 | Overlays.$inject = [
|
19479 | 'config.overlays',
|
19480 | 'eventBus',
|
19481 | 'canvas',
|
19482 | 'elementRegistry'
|
19483 | ];
|
19484 |
|
19485 |
|
19486 | |
19487 |
|
19488 |
|
19489 |
|
19490 |
|
19491 |
|
19492 |
|
19493 |
|
19494 |
|
19495 |
|
19496 |
|
19497 |
|
19498 |
|
19499 |
|
19500 |
|
19501 |
|
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 |
|
19507 |
|
19508 |
|
19509 |
|
19510 |
|
19511 |
|
19512 | Overlays.prototype.get = function(search) {
|
19513 |
|
19514 | if (isString(search)) {
|
19515 | search = { id: search };
|
19516 | }
|
19517 |
|
19518 | if (isString(search.element)) {
|
19519 | search.element = this._elementRegistry.get(search.element);
|
19520 | }
|
19521 |
|
19522 | if (search.element) {
|
19523 | var container = this._getOverlayContainer(search.element, true);
|
19524 |
|
19525 |
|
19526 | if (container) {
|
19527 | return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
|
19528 | } else {
|
19529 | return [];
|
19530 | }
|
19531 | } else
|
19532 | if (search.type) {
|
19533 | return filter(this._overlays, matchPattern({ type: search.type }));
|
19534 | } else {
|
19535 |
|
19536 | return search.id ? this._overlays[search.id] : null;
|
19537 | }
|
19538 | };
|
19539 |
|
19540 | |
19541 |
|
19542 |
|
19543 |
|
19544 |
|
19545 |
|
19546 |
|
19547 |
|
19548 |
|
19549 |
|
19550 |
|
19551 |
|
19552 |
|
19553 |
|
19554 |
|
19555 |
|
19556 |
|
19557 |
|
19558 |
|
19559 |
|
19560 |
|
19561 |
|
19562 |
|
19563 | Overlays.prototype.add = function(element, type, overlay) {
|
19564 |
|
19565 | if (isObject(type)) {
|
19566 | overlay = type;
|
19567 | type = null;
|
19568 | }
|
19569 |
|
19570 | if (!element.id) {
|
19571 | element = this._elementRegistry.get(element);
|
19572 | }
|
19573 |
|
19574 | if (!overlay.position) {
|
19575 | throw new Error('must specifiy overlay position');
|
19576 | }
|
19577 |
|
19578 | if (!overlay.html) {
|
19579 | throw new Error('must specifiy overlay html');
|
19580 | }
|
19581 |
|
19582 | if (!element) {
|
19583 | throw new Error('invalid element specified');
|
19584 | }
|
19585 |
|
19586 | var id = this._ids.next();
|
19587 |
|
19588 | overlay = assign({}, this._overlayDefaults, overlay, {
|
19589 | id: id,
|
19590 | type: type,
|
19591 | element: element,
|
19592 | html: overlay.html
|
19593 | });
|
19594 |
|
19595 | this._addOverlay(overlay);
|
19596 |
|
19597 | return id;
|
19598 | };
|
19599 |
|
19600 |
|
19601 | |
19602 |
|
19603 |
|
19604 |
|
19605 |
|
19606 |
|
19607 |
|
19608 |
|
19609 | Overlays.prototype.remove = function(filter$$1) {
|
19610 |
|
19611 | var overlays = this.get(filter$$1) || [];
|
19612 |
|
19613 | if (!isArray(overlays)) {
|
19614 | overlays = [ overlays ];
|
19615 | }
|
19616 |
|
19617 | var self = this;
|
19618 |
|
19619 | forEach(overlays, function(overlay) {
|
19620 |
|
19621 | var container = self._getOverlayContainer(overlay.element, true);
|
19622 |
|
19623 | if (overlay) {
|
19624 | remove(overlay.html);
|
19625 | remove(overlay.htmlContainer);
|
19626 |
|
19627 | delete overlay.htmlContainer;
|
19628 | delete overlay.element;
|
19629 |
|
19630 | delete self._overlays[overlay.id];
|
19631 | }
|
19632 |
|
19633 | if (container) {
|
19634 | var idx = container.overlays.indexOf(overlay);
|
19635 | if (idx !== -1) {
|
19636 | container.overlays.splice(idx, 1);
|
19637 | }
|
19638 | }
|
19639 | });
|
19640 |
|
19641 | };
|
19642 |
|
19643 |
|
19644 | Overlays.prototype.show = function() {
|
19645 | setVisible(this._overlayRoot);
|
19646 | };
|
19647 |
|
19648 |
|
19649 | Overlays.prototype.hide = function() {
|
19650 | setVisible(this._overlayRoot, false);
|
19651 | };
|
19652 |
|
19653 | Overlays.prototype.clear = function() {
|
19654 | this._overlays = {};
|
19655 |
|
19656 | this._overlayContainers = [];
|
19657 |
|
19658 | clear(this._overlayRoot);
|
19659 | };
|
19660 |
|
19661 | Overlays.prototype._updateOverlayContainer = function(container) {
|
19662 | var element = container.element,
|
19663 | html = container.html;
|
19664 |
|
19665 |
|
19666 |
|
19667 |
|
19668 | var x = element.x,
|
19669 | y = element.y;
|
19670 |
|
19671 | if (element.waypoints) {
|
19672 | var bbox = getBBox(element);
|
19673 | x = bbox.x;
|
19674 | y = bbox.y;
|
19675 | }
|
19676 |
|
19677 | setPosition(html, x, y);
|
19678 |
|
19679 | attr(container.html, 'data-container-id', element.id);
|
19680 | };
|
19681 |
|
19682 |
|
19683 | Overlays.prototype._updateOverlay = function(overlay) {
|
19684 |
|
19685 | var position = overlay.position,
|
19686 | htmlContainer = overlay.htmlContainer,
|
19687 | element = overlay.element;
|
19688 |
|
19689 |
|
19690 |
|
19691 |
|
19692 |
|
19693 | var left = position.left,
|
19694 | top = position.top;
|
19695 |
|
19696 | if (position.right !== undefined) {
|
19697 |
|
19698 | var width;
|
19699 |
|
19700 | if (element.waypoints) {
|
19701 | width = getBBox(element).width;
|
19702 | } else {
|
19703 | width = element.width;
|
19704 | }
|
19705 |
|
19706 | left = position.right * -1 + width;
|
19707 | }
|
19708 |
|
19709 | if (position.bottom !== undefined) {
|
19710 |
|
19711 | var height;
|
19712 |
|
19713 | if (element.waypoints) {
|
19714 | height = getBBox(element).height;
|
19715 | } else {
|
19716 | height = element.height;
|
19717 | }
|
19718 |
|
19719 | top = position.bottom * -1 + height;
|
19720 | }
|
19721 |
|
19722 | setPosition(htmlContainer, left || 0, top || 0);
|
19723 | };
|
19724 |
|
19725 |
|
19726 | Overlays.prototype._createOverlayContainer = function(element) {
|
19727 | var html = domify('<div class="djs-overlays" style="position: absolute" />');
|
19728 |
|
19729 | this._overlayRoot.appendChild(html);
|
19730 |
|
19731 | var container = {
|
19732 | html: html,
|
19733 | element: element,
|
19734 | overlays: []
|
19735 | };
|
19736 |
|
19737 | this._updateOverlayContainer(container);
|
19738 |
|
19739 | this._overlayContainers.push(container);
|
19740 |
|
19741 | return container;
|
19742 | };
|
19743 |
|
19744 |
|
19745 | Overlays.prototype._updateRoot = function(viewbox) {
|
19746 | var scale = viewbox.scale || 1;
|
19747 |
|
19748 | var matrix = 'matrix(' +
|
19749 | [
|
19750 | scale,
|
19751 | 0,
|
19752 | 0,
|
19753 | scale,
|
19754 | -1 * viewbox.x * scale,
|
19755 | -1 * viewbox.y * scale
|
19756 | ].join(',') +
|
19757 | ')';
|
19758 |
|
19759 | setTransform(this._overlayRoot, matrix);
|
19760 | };
|
19761 |
|
19762 |
|
19763 | Overlays.prototype._getOverlayContainer = function(element, raw) {
|
19764 | var container = find(this._overlayContainers, function(c) {
|
19765 | return c.element === element;
|
19766 | });
|
19767 |
|
19768 |
|
19769 | if (!container && !raw) {
|
19770 | return this._createOverlayContainer(element);
|
19771 | }
|
19772 |
|
19773 | return container;
|
19774 | };
|
19775 |
|
19776 |
|
19777 | Overlays.prototype._addOverlay = function(overlay) {
|
19778 |
|
19779 | var id = overlay.id,
|
19780 | element = overlay.element,
|
19781 | html = overlay.html,
|
19782 | htmlContainer,
|
19783 | overlayContainer;
|
19784 |
|
19785 |
|
19786 | if (html.get && html.constructor.prototype.jquery) {
|
19787 | html = html.get(0);
|
19788 | }
|
19789 |
|
19790 |
|
19791 |
|
19792 | if (isString(html)) {
|
19793 | html = domify(html);
|
19794 | }
|
19795 |
|
19796 | overlayContainer = this._getOverlayContainer(element);
|
19797 |
|
19798 | htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
|
19799 |
|
19800 | htmlContainer.appendChild(html);
|
19801 |
|
19802 | if (overlay.type) {
|
19803 | classes(htmlContainer).add('djs-overlay-' + overlay.type);
|
19804 | }
|
19805 |
|
19806 | overlay.htmlContainer = htmlContainer;
|
19807 |
|
19808 | overlayContainer.overlays.push(overlay);
|
19809 | overlayContainer.html.appendChild(htmlContainer);
|
19810 |
|
19811 | this._overlays[id] = overlay;
|
19812 |
|
19813 | this._updateOverlay(overlay);
|
19814 | this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
|
19815 | };
|
19816 |
|
19817 |
|
19818 | Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
|
19819 | var show = overlay.show,
|
19820 | minZoom = show && show.minZoom,
|
19821 | maxZoom = show && show.maxZoom,
|
19822 | htmlContainer = overlay.htmlContainer,
|
19823 | visible = true;
|
19824 |
|
19825 | if (show) {
|
19826 | if (
|
19827 | (isDefined(minZoom) && minZoom > viewbox.scale) ||
|
19828 | (isDefined(maxZoom) && maxZoom < viewbox.scale)
|
19829 | ) {
|
19830 | visible = false;
|
19831 | }
|
19832 |
|
19833 | setVisible(htmlContainer, visible);
|
19834 | }
|
19835 |
|
19836 | this._updateOverlayScale(overlay, viewbox);
|
19837 | };
|
19838 |
|
19839 |
|
19840 | Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
|
19841 | var shouldScale = overlay.scale,
|
19842 | minScale,
|
19843 | maxScale,
|
19844 | htmlContainer = overlay.htmlContainer;
|
19845 |
|
19846 | var scale, transform = '';
|
19847 |
|
19848 | if (shouldScale !== true) {
|
19849 |
|
19850 | if (shouldScale === false) {
|
19851 | minScale = 1;
|
19852 | maxScale = 1;
|
19853 | } else {
|
19854 | minScale = shouldScale.min;
|
19855 | maxScale = shouldScale.max;
|
19856 | }
|
19857 |
|
19858 | if (isDefined(minScale) && viewbox.scale < minScale) {
|
19859 | scale = (1 / viewbox.scale || 1) * minScale;
|
19860 | }
|
19861 |
|
19862 | if (isDefined(maxScale) && viewbox.scale > maxScale) {
|
19863 | scale = (1 / viewbox.scale || 1) * maxScale;
|
19864 | }
|
19865 | }
|
19866 |
|
19867 | if (isDefined(scale)) {
|
19868 | transform = 'scale(' + scale + ',' + scale + ')';
|
19869 | }
|
19870 |
|
19871 | setTransform(htmlContainer, transform);
|
19872 | };
|
19873 |
|
19874 |
|
19875 | Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
|
19876 |
|
19877 | var self = this;
|
19878 |
|
19879 | forEach(this._overlays, function(overlay) {
|
19880 | self._updateOverlayVisibilty(overlay, viewbox);
|
19881 | });
|
19882 | };
|
19883 |
|
19884 |
|
19885 | Overlays.prototype._init = function() {
|
19886 |
|
19887 | var eventBus = this._eventBus;
|
19888 |
|
19889 | var self = this;
|
19890 |
|
19891 |
|
19892 |
|
19893 |
|
19894 | function updateViewbox(viewbox) {
|
19895 | self._updateRoot(viewbox);
|
19896 | self._updateOverlaysVisibilty(viewbox);
|
19897 |
|
19898 | self.show();
|
19899 | }
|
19900 |
|
19901 | eventBus.on('canvas.viewbox.changing', function(event) {
|
19902 | self.hide();
|
19903 | });
|
19904 |
|
19905 | eventBus.on('canvas.viewbox.changed', function(event) {
|
19906 | updateViewbox(event.viewbox);
|
19907 | });
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 | eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
|
19913 | var element = e.element;
|
19914 | var overlays = self.get({ element: element });
|
19915 |
|
19916 | forEach(overlays, function(o) {
|
19917 | self.remove(o.id);
|
19918 | });
|
19919 |
|
19920 | var container = self._getOverlayContainer(element);
|
19921 |
|
19922 | if (container) {
|
19923 | remove(container.html);
|
19924 | var i = self._overlayContainers.indexOf(container);
|
19925 | if (i !== -1) {
|
19926 | self._overlayContainers.splice(i, 1);
|
19927 | }
|
19928 | }
|
19929 | });
|
19930 |
|
19931 |
|
19932 |
|
19933 |
|
19934 | eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
|
19935 | var element = e.element;
|
19936 |
|
19937 | var container = self._getOverlayContainer(element, true);
|
19938 |
|
19939 | if (container) {
|
19940 | forEach(container.overlays, function(overlay) {
|
19941 | self._updateOverlay(overlay);
|
19942 | });
|
19943 |
|
19944 | self._updateOverlayContainer(container);
|
19945 | }
|
19946 | });
|
19947 |
|
19948 |
|
19949 |
|
19950 |
|
19951 | eventBus.on('element.marker.update', function(e) {
|
19952 | var container = self._getOverlayContainer(e.element, true);
|
19953 | if (container) {
|
19954 | classes(container.html)[e.add ? 'add' : 'remove'](e.marker);
|
19955 | }
|
19956 | });
|
19957 |
|
19958 |
|
19959 |
|
19960 |
|
19961 | eventBus.on('diagram.clear', this.clear, this);
|
19962 | };
|
19963 |
|
19964 |
|
19965 |
|
19966 |
|
19967 |
|
19968 | function createRoot(parent) {
|
19969 | var root = domify('<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />');
|
19970 | parent.insertBefore(root, parent.firstChild);
|
19971 |
|
19972 | return root;
|
19973 | }
|
19974 |
|
19975 | function setPosition(el, x, y) {
|
19976 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
19977 | }
|
19978 |
|
19979 | function setVisible(el, visible) {
|
19980 | el.style.display = visible === false ? 'none' : '';
|
19981 | }
|
19982 |
|
19983 | function setTransform(el, transform) {
|
19984 |
|
19985 | el.style['transform-origin'] = 'top left';
|
19986 |
|
19987 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
19988 | el.style[prefix + 'transform'] = transform;
|
19989 | });
|
19990 | }
|
19991 |
|
19992 | var OverlaysModule = {
|
19993 | __init__: [ 'overlays' ],
|
19994 | overlays: [ 'type', Overlays ]
|
19995 | };
|
19996 |
|
19997 | |
19998 |
|
19999 |
|
20000 |
|
20001 |
|
20002 |
|
20003 |
|
20004 |
|
20005 | var BPMNIO_LOGO_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 960"><path fill="#fff" d="M960 60v839c0 33-27 61-60 61H60c-33 0-60-27-60-60V60C0 27 27 0 60 0h839c34 0 61 27 61 60z"/><path fill="#52b415" d="M217 548a205 205 0 0 0-144 58 202 202 0 0 0-4 286 202 202 0 0 0 285 3 200 200 0 0 0 48-219 203 203 0 0 0-185-128zM752 6a206 206 0 0 0-192 285 206 206 0 0 0 269 111 207 207 0 0 0 111-260A204 204 0 0 0 752 6zM62 0A62 62 0 0 0 0 62v398l60 46a259 259 0 0 1 89-36c5-28 10-57 14-85l99 2 12 85a246 246 0 0 1 88 38l70-52 69 71-52 68c17 30 29 58 35 90l86 14-2 100-86 12a240 240 0 0 1-38 89l43 58h413c37 0 60-27 60-61V407a220 220 0 0 1-44 40l21 85-93 39-45-76a258 258 0 0 1-98 1l-45 76-94-39 22-85a298 298 0 0 1-70-69l-86 22-38-94 76-45a258 258 0 0 1-1-98l-76-45 40-94 85 22a271 271 0 0 1 41-47z"/></svg>';
|
20006 |
|
20007 | var BPMNIO_LOGO_URL = 'data:image/svg+xml,' + encodeURIComponent(BPMNIO_LOGO_SVG);
|
20008 |
|
20009 | var BPMNIO_IMG = '<img width="52" height="52" src="' + BPMNIO_LOGO_URL + '" />';
|
20010 |
|
20011 | function css(attrs) {
|
20012 | return attrs.join(';');
|
20013 | }
|
20014 |
|
20015 | var LIGHTBOX_STYLES = css([
|
20016 | 'z-index: 1001',
|
20017 | 'position: fixed',
|
20018 | 'top: 0',
|
20019 | 'left: 0',
|
20020 | 'right: 0',
|
20021 | 'bottom: 0'
|
20022 | ]);
|
20023 |
|
20024 | var BACKDROP_STYLES = css([
|
20025 | 'width: 100%',
|
20026 | 'height: 100%',
|
20027 | 'background: rgba(0,0,0,0.2)'
|
20028 | ]);
|
20029 |
|
20030 | var NOTICE_STYLES = css([
|
20031 | 'position: absolute',
|
20032 | 'left: 50%',
|
20033 | 'top: 40%',
|
20034 | 'margin: 0 -130px',
|
20035 | 'width: 260px',
|
20036 | 'padding: 10px',
|
20037 | 'background: white',
|
20038 | 'border: solid 1px #AAA',
|
20039 | 'border-radius: 3px',
|
20040 | 'font-family: Helvetica, Arial, sans-serif',
|
20041 | 'font-size: 14px',
|
20042 | 'line-height: 1.2em'
|
20043 | ]);
|
20044 |
|
20045 | var LIGHTBOX_MARKUP =
|
20046 | '<div class="bjs-powered-by-lightbox" style="' + LIGHTBOX_STYLES + '">' +
|
20047 | '<div class="backdrop" style="' + BACKDROP_STYLES + '"></div>' +
|
20048 | '<div class="notice" style="' + NOTICE_STYLES + '">' +
|
20049 | '<a href="http://bpmn.io" target="_blank" style="float: left; margin-right: 10px">' +
|
20050 | BPMNIO_IMG +
|
20051 | '</a>' +
|
20052 | 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
|
20053 | 'powered by <a href="http://bpmn.io" target="_blank">bpmn.io</a>.' +
|
20054 | '</div>' +
|
20055 | '</div>';
|
20056 |
|
20057 |
|
20058 | var lightbox;
|
20059 |
|
20060 | function open() {
|
20061 |
|
20062 | if (!lightbox) {
|
20063 | lightbox = domify(LIGHTBOX_MARKUP);
|
20064 |
|
20065 | delegateEvents.bind(lightbox, '.backdrop', 'click', function(event) {
|
20066 | document.body.removeChild(lightbox);
|
20067 | });
|
20068 | }
|
20069 |
|
20070 | document.body.appendChild(lightbox);
|
20071 | }
|
20072 |
|
20073 | |
20074 |
|
20075 |
|
20076 |
|
20077 |
|
20078 |
|
20079 |
|
20080 |
|
20081 | function checkValidationError(err) {
|
20082 |
|
20083 |
|
20084 |
|
20085 |
|
20086 | var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
20087 | var match = pattern.exec(err.message);
|
20088 |
|
20089 | if (match) {
|
20090 | err.message =
|
20091 | 'unparsable content <' + match[1] + '> detected; ' +
|
20092 | 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
|
20093 | }
|
20094 |
|
20095 | return err;
|
20096 | }
|
20097 |
|
20098 | var DEFAULT_OPTIONS = {
|
20099 | width: '100%',
|
20100 | height: '100%',
|
20101 | position: 'relative'
|
20102 | };
|
20103 |
|
20104 |
|
20105 | |
20106 |
|
20107 |
|
20108 | function ensureUnit(val) {
|
20109 | return val + (isNumber(val) ? 'px' : '');
|
20110 | }
|
20111 |
|
20112 | |
20113 |
|
20114 |
|
20115 |
|
20116 |
|
20117 |
|
20118 |
|
20119 |
|
20120 |
|
20121 |
|
20122 |
|
20123 |
|
20124 |
|
20125 |
|
20126 |
|
20127 |
|
20128 |
|
20129 |
|
20130 |
|
20131 |
|
20132 |
|
20133 |
|
20134 |
|
20135 |
|
20136 |
|
20137 |
|
20138 |
|
20139 |
|
20140 |
|
20141 |
|
20142 |
|
20143 |
|
20144 |
|
20145 |
|
20146 |
|
20147 |
|
20148 |
|
20149 |
|
20150 |
|
20151 |
|
20152 |
|
20153 |
|
20154 |
|
20155 |
|
20156 |
|
20157 |
|
20158 |
|
20159 | function Viewer(options) {
|
20160 |
|
20161 | options = assign({}, DEFAULT_OPTIONS, options);
|
20162 |
|
20163 | this._moddle = this._createModdle(options);
|
20164 |
|
20165 | this._container = this._createContainer(options);
|
20166 |
|
20167 |
|
20168 |
|
20169 | addProjectLogo(this._container);
|
20170 |
|
20171 |
|
20172 |
|
20173 | this._init(this._container, this._moddle, options);
|
20174 | }
|
20175 |
|
20176 | inherits_browser(Viewer, diagramJs);
|
20177 |
|
20178 |
|
20179 | |
20180 |
|
20181 |
|
20182 |
|
20183 |
|
20184 |
|
20185 |
|
20186 |
|
20187 |
|
20188 |
|
20189 |
|
20190 |
|
20191 |
|
20192 |
|
20193 |
|
20194 |
|
20195 |
|
20196 |
|
20197 |
|
20198 |
|
20199 |
|
20200 | Viewer.prototype.importXML = function(xml, done) {
|
20201 |
|
20202 |
|
20203 | done = done || function() {};
|
20204 |
|
20205 | var self = this;
|
20206 |
|
20207 |
|
20208 |
|
20209 | xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
20210 |
|
20211 | this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
|
20212 |
|
20213 |
|
20214 |
|
20215 | definitions = self._emit('import.parse.complete', {
|
20216 | error: err,
|
20217 | definitions: definitions,
|
20218 | context: context
|
20219 | }) || definitions;
|
20220 |
|
20221 | var parseWarnings = context.warnings;
|
20222 |
|
20223 | if (err) {
|
20224 | err = checkValidationError(err);
|
20225 |
|
20226 | self._emit('import.done', { error: err, warnings: parseWarnings });
|
20227 |
|
20228 | return done(err, parseWarnings);
|
20229 | }
|
20230 |
|
20231 | self.importDefinitions(definitions, function(err, importWarnings) {
|
20232 | var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
20233 |
|
20234 | self._emit('import.done', { error: err, warnings: allWarnings });
|
20235 |
|
20236 | done(err, allWarnings);
|
20237 | });
|
20238 | });
|
20239 | };
|
20240 |
|
20241 | |
20242 |
|
20243 |
|
20244 |
|
20245 |
|
20246 |
|
20247 |
|
20248 |
|
20249 |
|
20250 |
|
20251 |
|
20252 |
|
20253 |
|
20254 |
|
20255 |
|
20256 |
|
20257 |
|
20258 |
|
20259 |
|
20260 |
|
20261 | Viewer.prototype.saveXML = function(options, done) {
|
20262 |
|
20263 | if (!done) {
|
20264 | done = options;
|
20265 | options = {};
|
20266 | }
|
20267 |
|
20268 | var self = this;
|
20269 |
|
20270 | var definitions = this._definitions;
|
20271 |
|
20272 | if (!definitions) {
|
20273 | return done(new Error('no definitions loaded'));
|
20274 | }
|
20275 |
|
20276 |
|
20277 | definitions = this._emit('saveXML.start', {
|
20278 | definitions: definitions
|
20279 | }) || definitions;
|
20280 |
|
20281 | this._moddle.toXML(definitions, options, function(err, xml) {
|
20282 |
|
20283 | try {
|
20284 | xml = self._emit('saveXML.serialized', {
|
20285 | error: err,
|
20286 | xml: xml
|
20287 | }) || xml;
|
20288 |
|
20289 | self._emit('saveXML.done', {
|
20290 | error: err,
|
20291 | xml: xml
|
20292 | });
|
20293 | } catch (e) {
|
20294 | console.error('error in saveXML life-cycle listener', e);
|
20295 | }
|
20296 |
|
20297 | done(err, xml);
|
20298 | });
|
20299 | };
|
20300 |
|
20301 | |
20302 |
|
20303 |
|
20304 |
|
20305 |
|
20306 |
|
20307 |
|
20308 |
|
20309 |
|
20310 |
|
20311 |
|
20312 |
|
20313 |
|
20314 |
|
20315 |
|
20316 |
|
20317 | Viewer.prototype.saveSVG = function(options, done) {
|
20318 |
|
20319 | if (!done) {
|
20320 | done = options;
|
20321 | options = {};
|
20322 | }
|
20323 |
|
20324 | this._emit('saveSVG.start');
|
20325 |
|
20326 | var svg, err;
|
20327 |
|
20328 | try {
|
20329 | var canvas = this.get('canvas');
|
20330 |
|
20331 | var contentNode = canvas.getDefaultLayer(),
|
20332 | defsNode = query('defs', canvas._svg);
|
20333 |
|
20334 | var contents = innerSVG(contentNode),
|
20335 | defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
|
20336 |
|
20337 | var bbox = contentNode.getBBox();
|
20338 |
|
20339 | svg =
|
20340 | '<?xml version="1.0" encoding="utf-8"?>\n' +
|
20341 | '<!-- created with bpmn-js / http://bpmn.io -->\n' +
|
20342 | '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
20343 | '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
20344 | 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
20345 | 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
20346 | defs + contents +
|
20347 | '</svg>';
|
20348 | } catch (e) {
|
20349 | err = e;
|
20350 | }
|
20351 |
|
20352 | this._emit('saveSVG.done', {
|
20353 | error: err,
|
20354 | svg: svg
|
20355 | });
|
20356 |
|
20357 | done(err, svg);
|
20358 | };
|
20359 |
|
20360 | |
20361 |
|
20362 |
|
20363 |
|
20364 |
|
20365 |
|
20366 |
|
20367 |
|
20368 |
|
20369 |
|
20370 |
|
20371 |
|
20372 |
|
20373 |
|
20374 |
|
20375 | |
20376 |
|
20377 |
|
20378 |
|
20379 |
|
20380 |
|
20381 |
|
20382 |
|
20383 |
|
20384 |
|
20385 |
|
20386 |
|
20387 |
|
20388 |
|
20389 |
|
20390 |
|
20391 | |
20392 |
|
20393 |
|
20394 |
|
20395 |
|
20396 |
|
20397 |
|
20398 |
|
20399 |
|
20400 | Viewer.prototype.importDefinitions = function(definitions, done) {
|
20401 |
|
20402 |
|
20403 | try {
|
20404 | if (this._definitions) {
|
20405 |
|
20406 | this.clear();
|
20407 | }
|
20408 |
|
20409 |
|
20410 | this._definitions = definitions;
|
20411 | } catch (e) {
|
20412 | return done(e);
|
20413 | }
|
20414 |
|
20415 |
|
20416 | return importBpmnDiagram(this, definitions, done);
|
20417 | };
|
20418 |
|
20419 | Viewer.prototype.getModules = function() {
|
20420 | return this._modules;
|
20421 | };
|
20422 |
|
20423 | |
20424 |
|
20425 |
|
20426 |
|
20427 | Viewer.prototype.destroy = function() {
|
20428 |
|
20429 |
|
20430 | diagramJs.prototype.destroy.call(this);
|
20431 |
|
20432 |
|
20433 | remove(this._container);
|
20434 | };
|
20435 |
|
20436 | |
20437 |
|
20438 |
|
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 |
|
20444 |
|
20445 |
|
20446 | Viewer.prototype.on = function(event$$1, priority, callback, target) {
|
20447 | return this.get('eventBus').on(event$$1, priority, callback, target);
|
20448 | };
|
20449 |
|
20450 | |
20451 |
|
20452 |
|
20453 |
|
20454 |
|
20455 |
|
20456 | Viewer.prototype.off = function(event$$1, callback) {
|
20457 | this.get('eventBus').off(event$$1, callback);
|
20458 | };
|
20459 |
|
20460 | Viewer.prototype.attachTo = function(parentNode) {
|
20461 |
|
20462 | if (!parentNode) {
|
20463 | throw new Error('parentNode required');
|
20464 | }
|
20465 |
|
20466 |
|
20467 |
|
20468 | this.detach();
|
20469 |
|
20470 |
|
20471 | if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
20472 | parentNode = parentNode.get(0);
|
20473 | }
|
20474 |
|
20475 | if (typeof parentNode === 'string') {
|
20476 | parentNode = query(parentNode);
|
20477 | }
|
20478 |
|
20479 | parentNode.appendChild(this._container);
|
20480 |
|
20481 | this._emit('attach', {});
|
20482 |
|
20483 | this.get('canvas').resized();
|
20484 | };
|
20485 |
|
20486 | Viewer.prototype.getDefinitions = function() {
|
20487 | return this._definitions;
|
20488 | };
|
20489 |
|
20490 | Viewer.prototype.detach = function() {
|
20491 |
|
20492 | var container = this._container,
|
20493 | parentNode = container.parentNode;
|
20494 |
|
20495 | if (!parentNode) {
|
20496 | return;
|
20497 | }
|
20498 |
|
20499 | this._emit('detach', {});
|
20500 |
|
20501 | parentNode.removeChild(container);
|
20502 | };
|
20503 |
|
20504 | Viewer.prototype._init = function(container, moddle, options) {
|
20505 |
|
20506 | var baseModules = options.modules || this.getModules(),
|
20507 | additionalModules = options.additionalModules || [],
|
20508 | staticModules = [
|
20509 | {
|
20510 | bpmnjs: [ 'value', this ],
|
20511 | moddle: [ 'value', moddle ]
|
20512 | }
|
20513 | ];
|
20514 |
|
20515 | var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
20516 |
|
20517 | var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
|
20518 | canvas: assign({}, options.canvas, { container: container }),
|
20519 | modules: diagramModules
|
20520 | });
|
20521 |
|
20522 |
|
20523 | diagramJs.call(this, diagramOptions);
|
20524 |
|
20525 | if (options && options.container) {
|
20526 | this.attachTo(options.container);
|
20527 | }
|
20528 | };
|
20529 |
|
20530 | |
20531 |
|
20532 |
|
20533 |
|
20534 |
|
20535 |
|
20536 |
|
20537 |
|
20538 | Viewer.prototype._emit = function(type, event$$1) {
|
20539 | return this.get('eventBus').fire(type, event$$1);
|
20540 | };
|
20541 |
|
20542 | Viewer.prototype._createContainer = function(options) {
|
20543 |
|
20544 | var container = domify('<div class="bjs-container"></div>');
|
20545 |
|
20546 | assign(container.style, {
|
20547 | width: ensureUnit(options.width),
|
20548 | height: ensureUnit(options.height),
|
20549 | position: options.position
|
20550 | });
|
20551 |
|
20552 | return container;
|
20553 | };
|
20554 |
|
20555 | Viewer.prototype._createModdle = function(options) {
|
20556 | var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
20557 |
|
20558 | return new BpmnModdle$1(moddleOptions);
|
20559 | };
|
20560 |
|
20561 |
|
20562 | Viewer.prototype._modules = [
|
20563 | CoreModule$1,
|
20564 | translate$2,
|
20565 | SelectionModule,
|
20566 | OverlaysModule
|
20567 | ];
|
20568 |
|
20569 |
|
20570 | Viewer.prototype._moddleExtensions = {};
|
20571 |
|
20572 | |
20573 |
|
20574 |
|
20575 |
|
20576 |
|
20577 |
|
20578 |
|
20579 |
|
20580 | function addProjectLogo(container) {
|
20581 | var img = BPMNIO_IMG;
|
20582 |
|
20583 | var linkMarkup =
|
20584 | '<a href="http://bpmn.io" ' +
|
20585 | 'target="_blank" ' +
|
20586 | 'class="bjs-powered-by" ' +
|
20587 | 'title="Powered by bpmn.io" ' +
|
20588 | 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
|
20589 | img +
|
20590 | '</a>';
|
20591 |
|
20592 | var linkElement = domify(linkMarkup);
|
20593 |
|
20594 | container.appendChild(linkElement);
|
20595 |
|
20596 | componentEvent.bind(linkElement, 'click', function(event$$1) {
|
20597 | open();
|
20598 |
|
20599 | event$$1.preventDefault();
|
20600 | });
|
20601 | }
|
20602 |
|
20603 |
|
20604 |
|
20605 | |
20606 |
|
20607 |
|
20608 |
|
20609 | function hasModifier(event) {
|
20610 | return (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey);
|
20611 | }
|
20612 |
|
20613 | |
20614 |
|
20615 |
|
20616 | function isCmd(event) {
|
20617 |
|
20618 |
|
20619 |
|
20620 | if (event.altKey) {
|
20621 | return false;
|
20622 | }
|
20623 |
|
20624 | return event.ctrlKey || event.metaKey;
|
20625 | }
|
20626 |
|
20627 | |
20628 |
|
20629 |
|
20630 |
|
20631 |
|
20632 |
|
20633 | function isKey(keys$$1, event) {
|
20634 | keys$$1 = isArray(keys$$1) ? keys$$1 : [ keys$$1 ];
|
20635 |
|
20636 | return keys$$1.indexOf(event.key) > -1;
|
20637 | }
|
20638 |
|
20639 | |
20640 |
|
20641 |
|
20642 | function isShift(event) {
|
20643 | return event.shiftKey;
|
20644 | }
|
20645 |
|
20646 | var KEYDOWN_EVENT = 'keyboard.keydown';
|
20647 |
|
20648 | var DEFAULT_PRIORITY$1 = 1000;
|
20649 |
|
20650 |
|
20651 | |
20652 |
|
20653 |
|
20654 |
|
20655 |
|
20656 |
|
20657 |
|
20658 |
|
20659 |
|
20660 |
|
20661 |
|
20662 |
|
20663 |
|
20664 |
|
20665 |
|
20666 |
|
20667 |
|
20668 |
|
20669 |
|
20670 |
|
20671 |
|
20672 |
|
20673 |
|
20674 |
|
20675 | function Keyboard(config, eventBus) {
|
20676 | var self = this;
|
20677 |
|
20678 | this._config = config || {};
|
20679 | this._eventBus = eventBus;
|
20680 |
|
20681 | this._keyHandler = this._keyHandler.bind(this);
|
20682 |
|
20683 |
|
20684 | eventBus.on('diagram.destroy', function() {
|
20685 | self._fire('destroy');
|
20686 |
|
20687 | self.unbind();
|
20688 | });
|
20689 |
|
20690 | eventBus.on('diagram.init', function() {
|
20691 | self._fire('init');
|
20692 | });
|
20693 |
|
20694 | eventBus.on('attach', function() {
|
20695 | if (config && config.bindTo) {
|
20696 | self.bind(config.bindTo);
|
20697 | }
|
20698 | });
|
20699 |
|
20700 | eventBus.on('detach', function() {
|
20701 | self.unbind();
|
20702 | });
|
20703 | }
|
20704 |
|
20705 | Keyboard.$inject = [
|
20706 | 'config.keyboard',
|
20707 | 'eventBus'
|
20708 | ];
|
20709 |
|
20710 | Keyboard.prototype._keyHandler = function(event$$1) {
|
20711 |
|
20712 | var target = event$$1.target,
|
20713 | eventBusResult;
|
20714 |
|
20715 | if (isInput(target)) {
|
20716 | return;
|
20717 | }
|
20718 |
|
20719 | var context = {
|
20720 | keyEvent: event$$1
|
20721 | };
|
20722 |
|
20723 | eventBusResult = this._eventBus.fire(KEYDOWN_EVENT, context);
|
20724 |
|
20725 | if (eventBusResult) {
|
20726 | event$$1.preventDefault();
|
20727 | }
|
20728 | };
|
20729 |
|
20730 | Keyboard.prototype.bind = function(node) {
|
20731 |
|
20732 |
|
20733 | this.unbind();
|
20734 |
|
20735 | this._node = node;
|
20736 |
|
20737 |
|
20738 | componentEvent.bind(node, 'keydown', this._keyHandler, true);
|
20739 |
|
20740 | this._fire('bind');
|
20741 | };
|
20742 |
|
20743 | Keyboard.prototype.getBinding = function() {
|
20744 | return this._node;
|
20745 | };
|
20746 |
|
20747 | Keyboard.prototype.unbind = function() {
|
20748 | var node = this._node;
|
20749 |
|
20750 | if (node) {
|
20751 | this._fire('unbind');
|
20752 |
|
20753 |
|
20754 | componentEvent.unbind(node, 'keydown', this._keyHandler, true);
|
20755 | }
|
20756 |
|
20757 | this._node = null;
|
20758 | };
|
20759 |
|
20760 | Keyboard.prototype._fire = function(event$$1) {
|
20761 | this._eventBus.fire('keyboard.' + event$$1, { node: this._node });
|
20762 | };
|
20763 |
|
20764 | |
20765 |
|
20766 |
|
20767 |
|
20768 |
|
20769 |
|
20770 |
|
20771 |
|
20772 | Keyboard.prototype.addListener = function(priority, listener) {
|
20773 | if (isFunction(priority)) {
|
20774 | listener = priority;
|
20775 | priority = DEFAULT_PRIORITY$1;
|
20776 | }
|
20777 |
|
20778 | this._eventBus.on(KEYDOWN_EVENT, priority, listener);
|
20779 | };
|
20780 |
|
20781 | Keyboard.prototype.hasModifier = hasModifier;
|
20782 | Keyboard.prototype.isCmd = isCmd;
|
20783 | Keyboard.prototype.isShift = isShift;
|
20784 | Keyboard.prototype.isKey = isKey;
|
20785 |
|
20786 |
|
20787 |
|
20788 |
|
20789 |
|
20790 | function isInput(target) {
|
20791 | return target && (matchesSelector$1(target, 'input, textarea') || target.contentEditable === 'true');
|
20792 | }
|
20793 |
|
20794 | var LOW_PRIORITY$3 = 500;
|
20795 |
|
20796 |
|
20797 | |
20798 |
|
20799 |
|
20800 |
|
20801 |
|
20802 |
|
20803 |
|
20804 |
|
20805 |
|
20806 | function KeyboardBindings(eventBus, keyboard) {
|
20807 |
|
20808 | var self = this;
|
20809 |
|
20810 | eventBus.on('editorActions.init', LOW_PRIORITY$3, function(event) {
|
20811 |
|
20812 | var editorActions = event.editorActions;
|
20813 |
|
20814 | self.registerBindings(keyboard, editorActions);
|
20815 | });
|
20816 | }
|
20817 |
|
20818 | KeyboardBindings.$inject = [
|
20819 | 'eventBus',
|
20820 | 'keyboard'
|
20821 | ];
|
20822 |
|
20823 |
|
20824 | |
20825 |
|
20826 |
|
20827 |
|
20828 |
|
20829 |
|
20830 | KeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
20831 |
|
20832 | |
20833 |
|
20834 |
|
20835 |
|
20836 |
|
20837 |
|
20838 |
|
20839 | function addListener(action, fn) {
|
20840 |
|
20841 | if (editorActions.isRegistered(action)) {
|
20842 | keyboard.addListener(fn);
|
20843 | }
|
20844 | }
|
20845 |
|
20846 |
|
20847 |
|
20848 |
|
20849 | addListener('undo', function(context) {
|
20850 |
|
20851 | var event = context.keyEvent;
|
20852 |
|
20853 | if (isCmd(event) && !isShift(event) && isKey(['z', 'Z'], event)) {
|
20854 | editorActions.trigger('undo');
|
20855 |
|
20856 | return true;
|
20857 | }
|
20858 | });
|
20859 |
|
20860 |
|
20861 |
|
20862 |
|
20863 | addListener('redo', function(context) {
|
20864 |
|
20865 | var event = context.keyEvent;
|
20866 |
|
20867 | if (isCmd(event) && (isKey(['y', 'Y'], event) || (isKey(['z', 'Z'], event) && isShift(event)))) {
|
20868 | editorActions.trigger('redo');
|
20869 |
|
20870 | return true;
|
20871 | }
|
20872 | });
|
20873 |
|
20874 |
|
20875 |
|
20876 | addListener('copy', function(context) {
|
20877 |
|
20878 | var event = context.keyEvent;
|
20879 |
|
20880 | if (isCmd(event) && isKey(['c', 'C'], event)) {
|
20881 | editorActions.trigger('copy');
|
20882 |
|
20883 | return true;
|
20884 | }
|
20885 | });
|
20886 |
|
20887 |
|
20888 |
|
20889 | addListener('paste', function(context) {
|
20890 |
|
20891 | var event = context.keyEvent;
|
20892 |
|
20893 | if (isCmd(event) && isKey(['v', 'V'], event)) {
|
20894 | editorActions.trigger('paste');
|
20895 |
|
20896 | return true;
|
20897 | }
|
20898 | });
|
20899 |
|
20900 |
|
20901 |
|
20902 | addListener('stepZoom', function(context) {
|
20903 |
|
20904 | var event = context.keyEvent;
|
20905 |
|
20906 | if (isKey([ '+', 'Add' ], event) && isCmd(event)) {
|
20907 | editorActions.trigger('stepZoom', { value: 1 });
|
20908 |
|
20909 | return true;
|
20910 | }
|
20911 | });
|
20912 |
|
20913 |
|
20914 |
|
20915 | addListener('stepZoom', function(context) {
|
20916 |
|
20917 | var event = context.keyEvent;
|
20918 |
|
20919 | if (isKey([ '-', 'Subtract' ], event) && isCmd(event)) {
|
20920 | editorActions.trigger('stepZoom', { value: -1 });
|
20921 |
|
20922 | return true;
|
20923 | }
|
20924 | });
|
20925 |
|
20926 |
|
20927 |
|
20928 | addListener('zoom', function(context) {
|
20929 |
|
20930 | var event = context.keyEvent;
|
20931 |
|
20932 | if (isKey('0', event) && isCmd(event)) {
|
20933 | editorActions.trigger('zoom', { value: 1 });
|
20934 |
|
20935 | return true;
|
20936 | }
|
20937 | });
|
20938 |
|
20939 |
|
20940 |
|
20941 | addListener('removeSelection', function(context) {
|
20942 |
|
20943 | var event = context.keyEvent;
|
20944 |
|
20945 | if (isKey([ 'Delete', 'Del' ], event)) {
|
20946 | editorActions.trigger('removeSelection');
|
20947 |
|
20948 | return true;
|
20949 | }
|
20950 | });
|
20951 | };
|
20952 |
|
20953 | var KeyboardModule = {
|
20954 | __init__: [ 'keyboard', 'keyboardBindings' ],
|
20955 | keyboard: [ 'type', Keyboard ],
|
20956 | keyboardBindings: [ 'type', KeyboardBindings ]
|
20957 | };
|
20958 |
|
20959 | var DEFAULT_CONFIG = {
|
20960 | moveSpeed: 50,
|
20961 | moveSpeedAccelerated: 200
|
20962 | };
|
20963 |
|
20964 |
|
20965 | |
20966 |
|
20967 |
|
20968 |
|
20969 |
|
20970 |
|
20971 |
|
20972 |
|
20973 |
|
20974 | function KeyboardMove(
|
20975 | config,
|
20976 | keyboard,
|
20977 | canvas
|
20978 | ) {
|
20979 |
|
20980 | var self = this;
|
20981 |
|
20982 | this._config = assign({}, DEFAULT_CONFIG, config || {});
|
20983 |
|
20984 | keyboard.addListener(arrowsListener);
|
20985 |
|
20986 |
|
20987 | function arrowsListener(context) {
|
20988 |
|
20989 | var event = context.keyEvent,
|
20990 | config = self._config;
|
20991 |
|
20992 | if (!keyboard.isCmd(event)) {
|
20993 | return;
|
20994 | }
|
20995 |
|
20996 | if (keyboard.isKey([
|
20997 | 'ArrowLeft', 'Left',
|
20998 | 'ArrowUp', 'Up',
|
20999 | 'ArrowDown', 'Down',
|
21000 | 'ArrowRight', 'Right'
|
21001 | ], event)) {
|
21002 |
|
21003 | var speed = (
|
21004 | keyboard.isShift(event) ?
|
21005 | config.moveSpeedAccelerated :
|
21006 | config.moveSpeed
|
21007 | );
|
21008 |
|
21009 | var direction;
|
21010 |
|
21011 | switch (event.key) {
|
21012 | case 'ArrowLeft':
|
21013 | case 'Left':
|
21014 | direction = 'left';
|
21015 | break;
|
21016 | case 'ArrowUp':
|
21017 | case 'Up':
|
21018 | direction = 'up';
|
21019 | break;
|
21020 | case 'ArrowRight':
|
21021 | case 'Right':
|
21022 | direction = 'right';
|
21023 | break;
|
21024 | case 'ArrowDown':
|
21025 | case 'Down':
|
21026 | direction = 'down';
|
21027 | break;
|
21028 | }
|
21029 |
|
21030 | self.moveCanvas({
|
21031 | speed: speed,
|
21032 | direction: direction
|
21033 | });
|
21034 |
|
21035 | return true;
|
21036 | }
|
21037 | }
|
21038 |
|
21039 | this.moveCanvas = function(opts) {
|
21040 |
|
21041 | var dx = 0,
|
21042 | dy = 0,
|
21043 | speed = opts.speed;
|
21044 |
|
21045 | var actualSpeed = speed / Math.min(Math.sqrt(canvas.viewbox().scale), 1);
|
21046 |
|
21047 | switch (opts.direction) {
|
21048 | case 'left':
|
21049 | dx = actualSpeed;
|
21050 | break;
|
21051 | case 'up':
|
21052 | dy = actualSpeed;
|
21053 | break;
|
21054 | case 'right':
|
21055 | dx = -actualSpeed;
|
21056 | break;
|
21057 | case 'down':
|
21058 | dy = -actualSpeed;
|
21059 | break;
|
21060 | }
|
21061 |
|
21062 | canvas.scroll({
|
21063 | dx: dx,
|
21064 | dy: dy
|
21065 | });
|
21066 | };
|
21067 |
|
21068 | }
|
21069 |
|
21070 |
|
21071 | KeyboardMove.$inject = [
|
21072 | 'config.keyboardMove',
|
21073 | 'keyboard',
|
21074 | 'canvas'
|
21075 | ];
|
21076 |
|
21077 | var KeyboardMoveModule = {
|
21078 | __depends__: [
|
21079 | KeyboardModule
|
21080 | ],
|
21081 | __init__: [ 'keyboardMove' ],
|
21082 | keyboardMove: [ 'type', KeyboardMove ]
|
21083 | };
|
21084 |
|
21085 | var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/;
|
21086 |
|
21087 |
|
21088 | function set$1(mode) {
|
21089 | var classes$$1 = classes(document.body);
|
21090 |
|
21091 | classes$$1.removeMatching(CURSOR_CLS_PATTERN);
|
21092 |
|
21093 | if (mode) {
|
21094 | classes$$1.add('djs-cursor-' + mode);
|
21095 | }
|
21096 | }
|
21097 |
|
21098 | function unset() {
|
21099 | set$1(null);
|
21100 | }
|
21101 |
|
21102 | var TRAP_PRIORITY = 5000;
|
21103 |
|
21104 | /**
|
21105 | * Installs a click trap that prevents a ghost click following a dragging operation.
|
21106 | *
|
21107 | * @return {Function} a function to immediately remove the installed trap.
|
21108 | */
|
21109 | function install(eventBus, eventName) {
|
21110 |
|
21111 | eventName = eventName || 'element.click';
|
21112 |
|
21113 | function trap() {
|
21114 | return false;
|
21115 | }
|
21116 |
|
21117 | eventBus.once(eventName, TRAP_PRIORITY, trap);
|
21118 |
|
21119 | return function() {
|
21120 | eventBus.off(eventName, trap);
|
21121 | };
|
21122 | }
|
21123 |
|
21124 | function center(bounds) {
|
21125 | return {
|
21126 | x: bounds.x + (bounds.width / 2),
|
21127 | y: bounds.y + (bounds.height / 2)
|
21128 | };
|
21129 | }
|
21130 |
|
21131 |
|
21132 | function delta(a, b) {
|
21133 | return {
|
21134 | x: a.x - b.x,
|
21135 | y: a.y - b.y
|
21136 | };
|
21137 | }
|
21138 |
|
21139 | var THRESHOLD = 15;
|
21140 |
|
21141 |
|
21142 | |
21143 |
|
21144 |
|
21145 |
|
21146 |
|
21147 |
|
21148 | function MoveCanvas(eventBus, canvas) {
|
21149 |
|
21150 | var context;
|
21151 |
|
21152 |
|
21153 |
|
21154 |
|
21155 |
|
21156 | eventBus.on('element.mousedown', 500, function(e) {
|
21157 | return handleStart(e.originalEvent);
|
21158 | });
|
21159 |
|
21160 |
|
21161 | function handleMove(event$$1) {
|
21162 |
|
21163 | var start = context.start,
|
21164 | position = toPoint(event$$1),
|
21165 | delta$$1 = delta(position, start);
|
21166 |
|
21167 | if (!context.dragging && length(delta$$1) > THRESHOLD) {
|
21168 | context.dragging = true;
|
21169 |
|
21170 | install(eventBus);
|
21171 |
|
21172 | set$1('grab');
|
21173 | }
|
21174 |
|
21175 | if (context.dragging) {
|
21176 |
|
21177 | var lastPosition = context.last || context.start;
|
21178 |
|
21179 | delta$$1 = delta(position, lastPosition);
|
21180 |
|
21181 | canvas.scroll({
|
21182 | dx: delta$$1.x,
|
21183 | dy: delta$$1.y
|
21184 | });
|
21185 |
|
21186 | context.last = position;
|
21187 | }
|
21188 |
|
21189 |
|
21190 | event$$1.preventDefault();
|
21191 | }
|
21192 |
|
21193 |
|
21194 | function handleEnd(event$$1) {
|
21195 | componentEvent.unbind(document, 'mousemove', handleMove);
|
21196 | componentEvent.unbind(document, 'mouseup', handleEnd);
|
21197 |
|
21198 | context = null;
|
21199 |
|
21200 | unset();
|
21201 | }
|
21202 |
|
21203 | function handleStart(event$$1) {
|
21204 |
|
21205 | if (closest(event$$1.target, '.djs-draggable')) {
|
21206 | return;
|
21207 | }
|
21208 |
|
21209 |
|
21210 |
|
21211 | if (event$$1.button || event$$1.ctrlKey || event$$1.shiftKey || event$$1.altKey) {
|
21212 | return;
|
21213 | }
|
21214 |
|
21215 | context = {
|
21216 | start: toPoint(event$$1)
|
21217 | };
|
21218 |
|
21219 | componentEvent.bind(document, 'mousemove', handleMove);
|
21220 | componentEvent.bind(document, 'mouseup', handleEnd);
|
21221 |
|
21222 |
|
21223 | return true;
|
21224 | }
|
21225 | }
|
21226 |
|
21227 |
|
21228 | MoveCanvas.$inject = [
|
21229 | 'eventBus',
|
21230 | 'canvas'
|
21231 | ];
|
21232 |
|
21233 |
|
21234 |
|
21235 |
|
21236 |
|
21237 | function length(point) {
|
21238 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
21239 | }
|
21240 |
|
21241 | var MoveCanvasModule = {
|
21242 | __init__: [ 'moveCanvas' ],
|
21243 | moveCanvas: [ 'type', MoveCanvas ]
|
21244 | };
|
21245 |
|
21246 | |
21247 |
|
21248 |
|
21249 |
|
21250 | function log10(x) {
|
21251 | return Math.log(x) / Math.log(10);
|
21252 | }
|
21253 |
|
21254 | |
21255 |
|
21256 |
|
21257 |
|
21258 |
|
21259 |
|
21260 |
|
21261 | function getStepSize(range, steps) {
|
21262 |
|
21263 | var minLinearRange = log10(range.min),
|
21264 | maxLinearRange = log10(range.max);
|
21265 |
|
21266 | var absoluteLinearRange = Math.abs(minLinearRange) + Math.abs(maxLinearRange);
|
21267 |
|
21268 | return absoluteLinearRange / steps;
|
21269 | }
|
21270 |
|
21271 | function cap(range, scale) {
|
21272 | return Math.max(range.min, Math.min(range.max, scale));
|
21273 | }
|
21274 |
|
21275 | var sign = Math.sign || function(n) {
|
21276 | return n >= 0 ? 1 : -1;
|
21277 | };
|
21278 |
|
21279 | var RANGE = { min: 0.2, max: 4 },
|
21280 | NUM_STEPS = 10;
|
21281 |
|
21282 | var DELTA_THRESHOLD = 0.1;
|
21283 |
|
21284 | var DEFAULT_SCALE = 0.75;
|
21285 |
|
21286 | |
21287 |
|
21288 |
|
21289 |
|
21290 |
|
21291 |
|
21292 |
|
21293 |
|
21294 |
|
21295 |
|
21296 |
|
21297 |
|
21298 |
|
21299 | function ZoomScroll(config, eventBus, canvas) {
|
21300 |
|
21301 | config = config || {};
|
21302 |
|
21303 | this._enabled = false;
|
21304 |
|
21305 | this._canvas = canvas;
|
21306 | this._container = canvas._container;
|
21307 |
|
21308 | this._handleWheel = bind(this._handleWheel, this);
|
21309 |
|
21310 | this._totalDelta = 0;
|
21311 | this._scale = config.scale || DEFAULT_SCALE;
|
21312 |
|
21313 | var self = this;
|
21314 |
|
21315 | eventBus.on('canvas.init', function(e) {
|
21316 | self._init(config.enabled !== false);
|
21317 | });
|
21318 | }
|
21319 |
|
21320 | ZoomScroll.$inject = [
|
21321 | 'config.zoomScroll',
|
21322 | 'eventBus',
|
21323 | 'canvas'
|
21324 | ];
|
21325 |
|
21326 | ZoomScroll.prototype.scroll = function scroll(delta$$1) {
|
21327 | this._canvas.scroll(delta$$1);
|
21328 | };
|
21329 |
|
21330 |
|
21331 | ZoomScroll.prototype.reset = function reset() {
|
21332 | this._canvas.zoom('fit-viewport');
|
21333 | };
|
21334 |
|
21335 | |
21336 |
|
21337 |
|
21338 |
|
21339 |
|
21340 |
|
21341 | ZoomScroll.prototype.zoom = function zoom(delta$$1, position) {
|
21342 |
|
21343 |
|
21344 | var stepSize = getStepSize(RANGE, NUM_STEPS * 2);
|
21345 |
|
21346 |
|
21347 | this._totalDelta += delta$$1;
|
21348 |
|
21349 | if (Math.abs(this._totalDelta) > DELTA_THRESHOLD) {
|
21350 | this._zoom(delta$$1, position, stepSize);
|
21351 |
|
21352 |
|
21353 | this._totalDelta = 0;
|
21354 | }
|
21355 | };
|
21356 |
|
21357 |
|
21358 | ZoomScroll.prototype._handleWheel = function handleWheel(event$$1) {
|
21359 |
|
21360 | if (closest(event$$1.target, '.djs-scrollable', true)) {
|
21361 | return;
|
21362 | }
|
21363 |
|
21364 | var element = this._container;
|
21365 |
|
21366 | event$$1.preventDefault();
|
21367 |
|
21368 |
|
21369 |
|
21370 |
|
21371 | var isZoom = event$$1.ctrlKey;
|
21372 |
|
21373 | var isHorizontalScroll = event$$1.shiftKey;
|
21374 |
|
21375 | var factor = -1 * this._scale,
|
21376 | delta$$1;
|
21377 |
|
21378 | if (isZoom) {
|
21379 | factor *= event$$1.deltaMode === 0 ? 0.020 : 0.32;
|
21380 | } else {
|
21381 | factor *= event$$1.deltaMode === 0 ? 1.0 : 16.0;
|
21382 | }
|
21383 |
|
21384 | if (isZoom) {
|
21385 | var elementRect = element.getBoundingClientRect();
|
21386 |
|
21387 | var offset = {
|
21388 | x: event$$1.clientX - elementRect.left,
|
21389 | y: event$$1.clientY - elementRect.top
|
21390 | };
|
21391 |
|
21392 | delta$$1 = (
|
21393 | Math.sqrt(
|
21394 | Math.pow(event$$1.deltaY, 2) +
|
21395 | Math.pow(event$$1.deltaX, 2)
|
21396 | ) * sign(event$$1.deltaY) * factor
|
21397 | );
|
21398 |
|
21399 |
|
21400 | this.zoom(delta$$1, offset);
|
21401 | } else {
|
21402 |
|
21403 | if (isHorizontalScroll) {
|
21404 | delta$$1 = {
|
21405 | dx: factor * event$$1.deltaY,
|
21406 | dy: 0
|
21407 | };
|
21408 | } else {
|
21409 | delta$$1 = {
|
21410 | dx: factor * event$$1.deltaX,
|
21411 | dy: factor * event$$1.deltaY
|
21412 | };
|
21413 | }
|
21414 |
|
21415 | this.scroll(delta$$1);
|
21416 | }
|
21417 | };
|
21418 |
|
21419 | |
21420 |
|
21421 |
|
21422 |
|
21423 |
|
21424 |
|
21425 | ZoomScroll.prototype.stepZoom = function stepZoom(delta$$1, position) {
|
21426 |
|
21427 | var stepSize = getStepSize(RANGE, NUM_STEPS);
|
21428 |
|
21429 | this._zoom(delta$$1, position, stepSize);
|
21430 | };
|
21431 |
|
21432 |
|
21433 | |
21434 |
|
21435 |
|
21436 |
|
21437 |
|
21438 |
|
21439 |
|
21440 | ZoomScroll.prototype._zoom = function(delta$$1, position, stepSize) {
|
21441 | var canvas = this._canvas;
|
21442 |
|
21443 | var direction = delta$$1 > 0 ? 1 : -1;
|
21444 |
|
21445 | var currentLinearZoomLevel = log10(canvas.zoom());
|
21446 |
|
21447 |
|
21448 | var newLinearZoomLevel = Math.round(currentLinearZoomLevel / stepSize) * stepSize;
|
21449 |
|
21450 |
|
21451 | newLinearZoomLevel += stepSize * direction;
|
21452 |
|
21453 |
|
21454 |
|
21455 | var newLogZoomLevel = Math.pow(10, newLinearZoomLevel);
|
21456 |
|
21457 | canvas.zoom(cap(RANGE, newLogZoomLevel), position);
|
21458 | };
|
21459 |
|
21460 |
|
21461 | |
21462 |
|
21463 |
|
21464 |
|
21465 |
|
21466 | ZoomScroll.prototype.toggle = function toggle(newEnabled) {
|
21467 |
|
21468 | var element = this._container;
|
21469 | var handleWheel = this._handleWheel;
|
21470 |
|
21471 | var oldEnabled = this._enabled;
|
21472 |
|
21473 | if (typeof newEnabled === 'undefined') {
|
21474 | newEnabled = !oldEnabled;
|
21475 | }
|
21476 |
|
21477 |
|
21478 | if (oldEnabled !== newEnabled) {
|
21479 |
|
21480 |
|
21481 |
|
21482 | componentEvent[newEnabled ? 'bind' : 'unbind'](element, 'wheel', handleWheel, false);
|
21483 | }
|
21484 |
|
21485 | this._enabled = newEnabled;
|
21486 |
|
21487 | return newEnabled;
|
21488 | };
|
21489 |
|
21490 |
|
21491 | ZoomScroll.prototype._init = function(newEnabled) {
|
21492 | this.toggle(newEnabled);
|
21493 | };
|
21494 |
|
21495 | var ZoomScrollModule = {
|
21496 | __init__: [ 'zoomScroll' ],
|
21497 | zoomScroll: [ 'type', ZoomScroll ]
|
21498 | };
|
21499 |
|
21500 | |
21501 |
|
21502 |
|
21503 |
|
21504 |
|
21505 | function NavigatedViewer(options) {
|
21506 | Viewer.call(this, options);
|
21507 | }
|
21508 |
|
21509 | inherits_browser(NavigatedViewer, Viewer);
|
21510 |
|
21511 | NavigatedViewer.prototype._navigationModules = [
|
21512 | KeyboardMoveModule,
|
21513 | MoveCanvasModule,
|
21514 | ZoomScrollModule
|
21515 | ];
|
21516 |
|
21517 | NavigatedViewer.prototype._modules = [].concat(
|
21518 | NavigatedViewer.prototype._modules,
|
21519 | NavigatedViewer.prototype._navigationModules);
|
21520 |
|
21521 | var hammer = createCommonjsModule(function (module) {
|
21522 | |
21523 |
|
21524 |
|
21525 |
|
21526 |
|
21527 | (function(window, document, exportName, undefined) {
|
21528 |
|
21529 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
21530 | var TEST_ELEMENT = document.createElement('div');
|
21531 |
|
21532 | var TYPE_FUNCTION = 'function';
|
21533 |
|
21534 | var round = Math.round;
|
21535 | var abs = Math.abs;
|
21536 | var now = Date.now;
|
21537 |
|
21538 | |
21539 |
|
21540 |
|
21541 |
|
21542 |
|
21543 |
|
21544 |
|
21545 | function setTimeoutContext(fn, timeout, context) {
|
21546 | return setTimeout(bindFn(fn, context), timeout);
|
21547 | }
|
21548 |
|
21549 | |
21550 |
|
21551 |
|
21552 |
|
21553 |
|
21554 |
|
21555 |
|
21556 |
|
21557 |
|
21558 | function invokeArrayArg(arg, fn, context) {
|
21559 | if (Array.isArray(arg)) {
|
21560 | each(arg, context[fn], context);
|
21561 | return true;
|
21562 | }
|
21563 | return false;
|
21564 | }
|
21565 |
|
21566 | |
21567 |
|
21568 |
|
21569 |
|
21570 |
|
21571 |
|
21572 | function each(obj, iterator, context) {
|
21573 | var i;
|
21574 |
|
21575 | if (!obj) {
|
21576 | return;
|
21577 | }
|
21578 |
|
21579 | if (obj.forEach) {
|
21580 | obj.forEach(iterator, context);
|
21581 | } else if (obj.length !== undefined) {
|
21582 | i = 0;
|
21583 | while (i < obj.length) {
|
21584 | iterator.call(context, obj[i], i, obj);
|
21585 | i++;
|
21586 | }
|
21587 | } else {
|
21588 | for (i in obj) {
|
21589 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
21590 | }
|
21591 | }
|
21592 | }
|
21593 |
|
21594 | |
21595 |
|
21596 |
|
21597 |
|
21598 |
|
21599 |
|
21600 |
|
21601 | function deprecate(method, name, message) {
|
21602 | var deprecationMessage = 'DEPRECATED METHOD: ' + name + '\n' + message + ' AT \n';
|
21603 | return function() {
|
21604 | var e = new Error('get-stack-trace');
|
21605 | var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '')
|
21606 | .replace(/^\s+at\s+/gm, '')
|
21607 | .replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
21608 |
|
21609 | var log = window.console && (window.console.warn || window.console.log);
|
21610 | if (log) {
|
21611 | log.call(window.console, deprecationMessage, stack);
|
21612 | }
|
21613 | return method.apply(this, arguments);
|
21614 | };
|
21615 | }
|
21616 |
|
21617 | |
21618 |
|
21619 |
|
21620 |
|
21621 |
|
21622 |
|
21623 |
|
21624 | var assign;
|
21625 | if (typeof Object.assign !== 'function') {
|
21626 | assign = function assign(target) {
|
21627 | if (target === undefined || target === null) {
|
21628 | throw new TypeError('Cannot convert undefined or null to object');
|
21629 | }
|
21630 |
|
21631 | var output = Object(target);
|
21632 | for (var index = 1; index < arguments.length; index++) {
|
21633 | var source = arguments[index];
|
21634 | if (source !== undefined && source !== null) {
|
21635 | for (var nextKey in source) {
|
21636 | if (source.hasOwnProperty(nextKey)) {
|
21637 | output[nextKey] = source[nextKey];
|
21638 | }
|
21639 | }
|
21640 | }
|
21641 | }
|
21642 | return output;
|
21643 | };
|
21644 | } else {
|
21645 | assign = Object.assign;
|
21646 | }
|
21647 |
|
21648 | |
21649 |
|
21650 |
|
21651 |
|
21652 |
|
21653 |
|
21654 |
|
21655 |
|
21656 | var extend = deprecate(function extend(dest, src, merge) {
|
21657 | var keys = Object.keys(src);
|
21658 | var i = 0;
|
21659 | while (i < keys.length) {
|
21660 | if (!merge || (merge && dest[keys[i]] === undefined)) {
|
21661 | dest[keys[i]] = src[keys[i]];
|
21662 | }
|
21663 | i++;
|
21664 | }
|
21665 | return dest;
|
21666 | }, 'extend', 'Use `assign`.');
|
21667 |
|
21668 | |
21669 |
|
21670 |
|
21671 |
|
21672 |
|
21673 |
|
21674 |
|
21675 | var merge = deprecate(function merge(dest, src) {
|
21676 | return extend(dest, src, true);
|
21677 | }, 'merge', 'Use `assign`.');
|
21678 |
|
21679 | |
21680 |
|
21681 |
|
21682 |
|
21683 |
|
21684 |
|
21685 | function inherit(child, base, properties) {
|
21686 | var baseP = base.prototype,
|
21687 | childP;
|
21688 |
|
21689 | childP = child.prototype = Object.create(baseP);
|
21690 | childP.constructor = child;
|
21691 | childP._super = baseP;
|
21692 |
|
21693 | if (properties) {
|
21694 | assign(childP, properties);
|
21695 | }
|
21696 | }
|
21697 |
|
21698 | |
21699 |
|
21700 |
|
21701 |
|
21702 |
|
21703 |
|
21704 | function bindFn(fn, context) {
|
21705 | return function boundFn() {
|
21706 | return fn.apply(context, arguments);
|
21707 | };
|
21708 | }
|
21709 |
|
21710 | |
21711 |
|
21712 |
|
21713 |
|
21714 |
|
21715 |
|
21716 |
|
21717 | function boolOrFn(val, args) {
|
21718 | if (typeof val == TYPE_FUNCTION) {
|
21719 | return val.apply(args ? args[0] || undefined : undefined, args);
|
21720 | }
|
21721 | return val;
|
21722 | }
|
21723 |
|
21724 | |
21725 |
|
21726 |
|
21727 |
|
21728 |
|
21729 |
|
21730 | function ifUndefined(val1, val2) {
|
21731 | return (val1 === undefined) ? val2 : val1;
|
21732 | }
|
21733 |
|
21734 | |
21735 |
|
21736 |
|
21737 |
|
21738 |
|
21739 |
|
21740 | function addEventListeners(target, types, handler) {
|
21741 | each(splitStr(types), function(type) {
|
21742 | target.addEventListener(type, handler, false);
|
21743 | });
|
21744 | }
|
21745 |
|
21746 | |
21747 |
|
21748 |
|
21749 |
|
21750 |
|
21751 |
|
21752 | function removeEventListeners(target, types, handler) {
|
21753 | each(splitStr(types), function(type) {
|
21754 | target.removeEventListener(type, handler, false);
|
21755 | });
|
21756 | }
|
21757 |
|
21758 | |
21759 |
|
21760 |
|
21761 |
|
21762 |
|
21763 |
|
21764 |
|
21765 | function hasParent(node, parent) {
|
21766 | while (node) {
|
21767 | if (node == parent) {
|
21768 | return true;
|
21769 | }
|
21770 | node = node.parentNode;
|
21771 | }
|
21772 | return false;
|
21773 | }
|
21774 |
|
21775 | |
21776 |
|
21777 |
|
21778 |
|
21779 |
|
21780 |
|
21781 | function inStr(str, find) {
|
21782 | return str.indexOf(find) > -1;
|
21783 | }
|
21784 |
|
21785 | |
21786 |
|
21787 |
|
21788 |
|
21789 |
|
21790 | function splitStr(str) {
|
21791 | return str.trim().split(/\s+/g);
|
21792 | }
|
21793 |
|
21794 | |
21795 |
|
21796 |
|
21797 |
|
21798 |
|
21799 |
|
21800 |
|
21801 | function inArray(src, find, findByKey) {
|
21802 | if (src.indexOf && !findByKey) {
|
21803 | return src.indexOf(find);
|
21804 | } else {
|
21805 | var i = 0;
|
21806 | while (i < src.length) {
|
21807 | if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
|
21808 | return i;
|
21809 | }
|
21810 | i++;
|
21811 | }
|
21812 | return -1;
|
21813 | }
|
21814 | }
|
21815 |
|
21816 | |
21817 |
|
21818 |
|
21819 |
|
21820 |
|
21821 | function toArray(obj) {
|
21822 | return Array.prototype.slice.call(obj, 0);
|
21823 | }
|
21824 |
|
21825 | |
21826 |
|
21827 |
|
21828 |
|
21829 |
|
21830 |
|
21831 |
|
21832 | function uniqueArray(src, key, sort) {
|
21833 | var results = [];
|
21834 | var values = [];
|
21835 | var i = 0;
|
21836 |
|
21837 | while (i < src.length) {
|
21838 | var val = key ? src[i][key] : src[i];
|
21839 | if (inArray(values, val) < 0) {
|
21840 | results.push(src[i]);
|
21841 | }
|
21842 | values[i] = val;
|
21843 | i++;
|
21844 | }
|
21845 |
|
21846 | if (sort) {
|
21847 | if (!key) {
|
21848 | results = results.sort();
|
21849 | } else {
|
21850 | results = results.sort(function sortUniqueArray(a, b) {
|
21851 | return a[key] > b[key];
|
21852 | });
|
21853 | }
|
21854 | }
|
21855 |
|
21856 | return results;
|
21857 | }
|
21858 |
|
21859 | |
21860 |
|
21861 |
|
21862 |
|
21863 |
|
21864 |
|
21865 | function prefixed(obj, property) {
|
21866 | var prefix, prop;
|
21867 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
21868 |
|
21869 | var i = 0;
|
21870 | while (i < VENDOR_PREFIXES.length) {
|
21871 | prefix = VENDOR_PREFIXES[i];
|
21872 | prop = (prefix) ? prefix + camelProp : property;
|
21873 |
|
21874 | if (prop in obj) {
|
21875 | return prop;
|
21876 | }
|
21877 | i++;
|
21878 | }
|
21879 | return undefined;
|
21880 | }
|
21881 |
|
21882 | |
21883 |
|
21884 |
|
21885 |
|
21886 | var _uniqueId = 1;
|
21887 | function uniqueId() {
|
21888 | return _uniqueId++;
|
21889 | }
|
21890 |
|
21891 | |
21892 |
|
21893 |
|
21894 |
|
21895 |
|
21896 | function getWindowForElement(element) {
|
21897 | var doc = element.ownerDocument || element;
|
21898 | return (doc.defaultView || doc.parentWindow || window);
|
21899 | }
|
21900 |
|
21901 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
21902 |
|
21903 | var SUPPORT_TOUCH = ('ontouchstart' in window);
|
21904 | var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
|
21905 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
|
21906 |
|
21907 | var INPUT_TYPE_TOUCH = 'touch';
|
21908 | var INPUT_TYPE_PEN = 'pen';
|
21909 | var INPUT_TYPE_MOUSE = 'mouse';
|
21910 | var INPUT_TYPE_KINECT = 'kinect';
|
21911 |
|
21912 | var COMPUTE_INTERVAL = 25;
|
21913 |
|
21914 | var INPUT_START = 1;
|
21915 | var INPUT_MOVE = 2;
|
21916 | var INPUT_END = 4;
|
21917 | var INPUT_CANCEL = 8;
|
21918 |
|
21919 | var DIRECTION_NONE = 1;
|
21920 | var DIRECTION_LEFT = 2;
|
21921 | var DIRECTION_RIGHT = 4;
|
21922 | var DIRECTION_UP = 8;
|
21923 | var DIRECTION_DOWN = 16;
|
21924 |
|
21925 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
21926 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
21927 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
21928 |
|
21929 | var PROPS_XY = ['x', 'y'];
|
21930 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
21931 |
|
21932 | |
21933 |
|
21934 |
|
21935 |
|
21936 |
|
21937 |
|
21938 |
|
21939 | function Input(manager, callback) {
|
21940 | var self = this;
|
21941 | this.manager = manager;
|
21942 | this.callback = callback;
|
21943 | this.element = manager.element;
|
21944 | this.target = manager.options.inputTarget;
|
21945 |
|
21946 |
|
21947 |
|
21948 | this.domHandler = function(ev) {
|
21949 | if (boolOrFn(manager.options.enable, [manager])) {
|
21950 | self.handler(ev);
|
21951 | }
|
21952 | };
|
21953 |
|
21954 | this.init();
|
21955 |
|
21956 | }
|
21957 |
|
21958 | Input.prototype = {
|
21959 | |
21960 |
|
21961 |
|
21962 |
|
21963 | handler: function() { },
|
21964 |
|
21965 | |
21966 |
|
21967 |
|
21968 | init: function() {
|
21969 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
21970 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
21971 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
21972 | },
|
21973 |
|
21974 | |
21975 |
|
21976 |
|
21977 | destroy: function() {
|
21978 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
21979 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
21980 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
21981 | }
|
21982 | };
|
21983 |
|
21984 | |
21985 |
|
21986 |
|
21987 |
|
21988 |
|
21989 |
|
21990 | function createInputInstance(manager) {
|
21991 | var Type;
|
21992 | var inputClass = manager.options.inputClass;
|
21993 |
|
21994 | if (inputClass) {
|
21995 | Type = inputClass;
|
21996 | } else if (SUPPORT_POINTER_EVENTS) {
|
21997 | Type = PointerEventInput;
|
21998 | } else if (SUPPORT_ONLY_TOUCH) {
|
21999 | Type = TouchInput;
|
22000 | } else if (!SUPPORT_TOUCH) {
|
22001 | Type = MouseInput;
|
22002 | } else {
|
22003 | Type = TouchMouseInput;
|
22004 | }
|
22005 | return new (Type)(manager, inputHandler);
|
22006 | }
|
22007 |
|
22008 | |
22009 |
|
22010 |
|
22011 |
|
22012 |
|
22013 |
|
22014 | function inputHandler(manager, eventType, input) {
|
22015 | var pointersLen = input.pointers.length;
|
22016 | var changedPointersLen = input.changedPointers.length;
|
22017 | var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
|
22018 | var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
|
22019 |
|
22020 | input.isFirst = !!isFirst;
|
22021 | input.isFinal = !!isFinal;
|
22022 |
|
22023 | if (isFirst) {
|
22024 | manager.session = {};
|
22025 | }
|
22026 |
|
22027 |
|
22028 |
|
22029 | input.eventType = eventType;
|
22030 |
|
22031 |
|
22032 | computeInputData(manager, input);
|
22033 |
|
22034 |
|
22035 | manager.emit('hammer.input', input);
|
22036 |
|
22037 | manager.recognize(input);
|
22038 | manager.session.prevInput = input;
|
22039 | }
|
22040 |
|
22041 | |
22042 |
|
22043 |
|
22044 |
|
22045 |
|
22046 | function computeInputData(manager, input) {
|
22047 | var session = manager.session;
|
22048 | var pointers = input.pointers;
|
22049 | var pointersLength = pointers.length;
|
22050 |
|
22051 |
|
22052 | if (!session.firstInput) {
|
22053 | session.firstInput = simpleCloneInputData(input);
|
22054 | }
|
22055 |
|
22056 |
|
22057 | if (pointersLength > 1 && !session.firstMultiple) {
|
22058 | session.firstMultiple = simpleCloneInputData(input);
|
22059 | } else if (pointersLength === 1) {
|
22060 | session.firstMultiple = false;
|
22061 | }
|
22062 |
|
22063 | var firstInput = session.firstInput;
|
22064 | var firstMultiple = session.firstMultiple;
|
22065 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
22066 |
|
22067 | var center = input.center = getCenter(pointers);
|
22068 | input.timeStamp = now();
|
22069 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
22070 |
|
22071 | input.angle = getAngle(offsetCenter, center);
|
22072 | input.distance = getDistance(offsetCenter, center);
|
22073 |
|
22074 | computeDeltaXY(session, input);
|
22075 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
22076 |
|
22077 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
22078 | input.overallVelocityX = overallVelocity.x;
|
22079 | input.overallVelocityY = overallVelocity.y;
|
22080 | input.overallVelocity = (abs(overallVelocity.x) > abs(overallVelocity.y)) ? overallVelocity.x : overallVelocity.y;
|
22081 |
|
22082 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
22083 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
22084 |
|
22085 | input.maxPointers = !session.prevInput ? input.pointers.length : ((input.pointers.length >
|
22086 | session.prevInput.maxPointers) ? input.pointers.length : session.prevInput.maxPointers);
|
22087 |
|
22088 | computeIntervalInputData(session, input);
|
22089 |
|
22090 |
|
22091 | var target = manager.element;
|
22092 | if (hasParent(input.srcEvent.target, target)) {
|
22093 | target = input.srcEvent.target;
|
22094 | }
|
22095 | input.target = target;
|
22096 | }
|
22097 |
|
22098 | function computeDeltaXY(session, input) {
|
22099 | var center = input.center;
|
22100 | var offset = session.offsetDelta || {};
|
22101 | var prevDelta = session.prevDelta || {};
|
22102 | var prevInput = session.prevInput || {};
|
22103 |
|
22104 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
22105 | prevDelta = session.prevDelta = {
|
22106 | x: prevInput.deltaX || 0,
|
22107 | y: prevInput.deltaY || 0
|
22108 | };
|
22109 |
|
22110 | offset = session.offsetDelta = {
|
22111 | x: center.x,
|
22112 | y: center.y
|
22113 | };
|
22114 | }
|
22115 |
|
22116 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
22117 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
22118 | }
|
22119 |
|
22120 | |
22121 |
|
22122 |
|
22123 |
|
22124 |
|
22125 | function computeIntervalInputData(session, input) {
|
22126 | var last = session.lastInterval || input,
|
22127 | deltaTime = input.timeStamp - last.timeStamp,
|
22128 | velocity, velocityX, velocityY, direction;
|
22129 |
|
22130 | if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
|
22131 | var deltaX = input.deltaX - last.deltaX;
|
22132 | var deltaY = input.deltaY - last.deltaY;
|
22133 |
|
22134 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
22135 | velocityX = v.x;
|
22136 | velocityY = v.y;
|
22137 | velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
|
22138 | direction = getDirection(deltaX, deltaY);
|
22139 |
|
22140 | session.lastInterval = input;
|
22141 | } else {
|
22142 |
|
22143 | velocity = last.velocity;
|
22144 | velocityX = last.velocityX;
|
22145 | velocityY = last.velocityY;
|
22146 | direction = last.direction;
|
22147 | }
|
22148 |
|
22149 | input.velocity = velocity;
|
22150 | input.velocityX = velocityX;
|
22151 | input.velocityY = velocityY;
|
22152 | input.direction = direction;
|
22153 | }
|
22154 |
|
22155 | |
22156 |
|
22157 |
|
22158 |
|
22159 |
|
22160 | function simpleCloneInputData(input) {
|
22161 |
|
22162 |
|
22163 | var pointers = [];
|
22164 | var i = 0;
|
22165 | while (i < input.pointers.length) {
|
22166 | pointers[i] = {
|
22167 | clientX: round(input.pointers[i].clientX),
|
22168 | clientY: round(input.pointers[i].clientY)
|
22169 | };
|
22170 | i++;
|
22171 | }
|
22172 |
|
22173 | return {
|
22174 | timeStamp: now(),
|
22175 | pointers: pointers,
|
22176 | center: getCenter(pointers),
|
22177 | deltaX: input.deltaX,
|
22178 | deltaY: input.deltaY
|
22179 | };
|
22180 | }
|
22181 |
|
22182 | |
22183 |
|
22184 |
|
22185 |
|
22186 |
|
22187 | function getCenter(pointers) {
|
22188 | var pointersLength = pointers.length;
|
22189 |
|
22190 |
|
22191 | if (pointersLength === 1) {
|
22192 | return {
|
22193 | x: round(pointers[0].clientX),
|
22194 | y: round(pointers[0].clientY)
|
22195 | };
|
22196 | }
|
22197 |
|
22198 | var x = 0, y = 0, i = 0;
|
22199 | while (i < pointersLength) {
|
22200 | x += pointers[i].clientX;
|
22201 | y += pointers[i].clientY;
|
22202 | i++;
|
22203 | }
|
22204 |
|
22205 | return {
|
22206 | x: round(x / pointersLength),
|
22207 | y: round(y / pointersLength)
|
22208 | };
|
22209 | }
|
22210 |
|
22211 | |
22212 |
|
22213 |
|
22214 |
|
22215 |
|
22216 |
|
22217 |
|
22218 | function getVelocity(deltaTime, x, y) {
|
22219 | return {
|
22220 | x: x / deltaTime || 0,
|
22221 | y: y / deltaTime || 0
|
22222 | };
|
22223 | }
|
22224 |
|
22225 | |
22226 |
|
22227 |
|
22228 |
|
22229 |
|
22230 |
|
22231 | function getDirection(x, y) {
|
22232 | if (x === y) {
|
22233 | return DIRECTION_NONE;
|
22234 | }
|
22235 |
|
22236 | if (abs(x) >= abs(y)) {
|
22237 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
22238 | }
|
22239 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
22240 | }
|
22241 |
|
22242 | |
22243 |
|
22244 |
|
22245 |
|
22246 |
|
22247 |
|
22248 |
|
22249 | function getDistance(p1, p2, props) {
|
22250 | if (!props) {
|
22251 | props = PROPS_XY;
|
22252 | }
|
22253 | var x = p2[props[0]] - p1[props[0]],
|
22254 | y = p2[props[1]] - p1[props[1]];
|
22255 |
|
22256 | return Math.sqrt((x * x) + (y * y));
|
22257 | }
|
22258 |
|
22259 | |
22260 |
|
22261 |
|
22262 |
|
22263 |
|
22264 |
|
22265 |
|
22266 | function getAngle(p1, p2, props) {
|
22267 | if (!props) {
|
22268 | props = PROPS_XY;
|
22269 | }
|
22270 | var x = p2[props[0]] - p1[props[0]],
|
22271 | y = p2[props[1]] - p1[props[1]];
|
22272 | return Math.atan2(y, x) * 180 / Math.PI;
|
22273 | }
|
22274 |
|
22275 | |
22276 |
|
22277 |
|
22278 |
|
22279 |
|
22280 |
|
22281 | function getRotation(start, end) {
|
22282 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
22283 | }
|
22284 |
|
22285 | |
22286 |
|
22287 |
|
22288 |
|
22289 |
|
22290 |
|
22291 |
|
22292 | function getScale(start, end) {
|
22293 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
22294 | }
|
22295 |
|
22296 | var MOUSE_INPUT_MAP = {
|
22297 | mousedown: INPUT_START,
|
22298 | mousemove: INPUT_MOVE,
|
22299 | mouseup: INPUT_END
|
22300 | };
|
22301 |
|
22302 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
22303 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
22304 |
|
22305 | |
22306 |
|
22307 |
|
22308 |
|
22309 |
|
22310 | function MouseInput() {
|
22311 | this.evEl = MOUSE_ELEMENT_EVENTS;
|
22312 | this.evWin = MOUSE_WINDOW_EVENTS;
|
22313 |
|
22314 | this.pressed = false;
|
22315 |
|
22316 | Input.apply(this, arguments);
|
22317 | }
|
22318 |
|
22319 | inherit(MouseInput, Input, {
|
22320 | |
22321 |
|
22322 |
|
22323 |
|
22324 | handler: function MEhandler(ev) {
|
22325 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
22326 |
|
22327 |
|
22328 | if (eventType & INPUT_START && ev.button === 0) {
|
22329 | this.pressed = true;
|
22330 | }
|
22331 |
|
22332 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
22333 | eventType = INPUT_END;
|
22334 | }
|
22335 |
|
22336 |
|
22337 | if (!this.pressed) {
|
22338 | return;
|
22339 | }
|
22340 |
|
22341 | if (eventType & INPUT_END) {
|
22342 | this.pressed = false;
|
22343 | }
|
22344 |
|
22345 | this.callback(this.manager, eventType, {
|
22346 | pointers: [ev],
|
22347 | changedPointers: [ev],
|
22348 | pointerType: INPUT_TYPE_MOUSE,
|
22349 | srcEvent: ev
|
22350 | });
|
22351 | }
|
22352 | });
|
22353 |
|
22354 | var POINTER_INPUT_MAP = {
|
22355 | pointerdown: INPUT_START,
|
22356 | pointermove: INPUT_MOVE,
|
22357 | pointerup: INPUT_END,
|
22358 | pointercancel: INPUT_CANCEL,
|
22359 | pointerout: INPUT_CANCEL
|
22360 | };
|
22361 |
|
22362 |
|
22363 | var IE10_POINTER_TYPE_ENUM = {
|
22364 | 2: INPUT_TYPE_TOUCH,
|
22365 | 3: INPUT_TYPE_PEN,
|
22366 | 4: INPUT_TYPE_MOUSE,
|
22367 | 5: INPUT_TYPE_KINECT
|
22368 | };
|
22369 |
|
22370 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
22371 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
22372 |
|
22373 |
|
22374 | if (window.MSPointerEvent && !window.PointerEvent) {
|
22375 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
22376 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
22377 | }
|
22378 |
|
22379 | |
22380 |
|
22381 |
|
22382 |
|
22383 |
|
22384 | function PointerEventInput() {
|
22385 | this.evEl = POINTER_ELEMENT_EVENTS;
|
22386 | this.evWin = POINTER_WINDOW_EVENTS;
|
22387 |
|
22388 | Input.apply(this, arguments);
|
22389 |
|
22390 | this.store = (this.manager.session.pointerEvents = []);
|
22391 | }
|
22392 |
|
22393 | inherit(PointerEventInput, Input, {
|
22394 | |
22395 |
|
22396 |
|
22397 |
|
22398 | handler: function PEhandler(ev) {
|
22399 | var store = this.store;
|
22400 | var removePointer = false;
|
22401 |
|
22402 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
22403 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
22404 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
22405 |
|
22406 | var isTouch = (pointerType == INPUT_TYPE_TOUCH);
|
22407 |
|
22408 |
|
22409 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
22410 |
|
22411 |
|
22412 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
22413 | if (storeIndex < 0) {
|
22414 | store.push(ev);
|
22415 | storeIndex = store.length - 1;
|
22416 | }
|
22417 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
22418 | removePointer = true;
|
22419 | }
|
22420 |
|
22421 |
|
22422 | if (storeIndex < 0) {
|
22423 | return;
|
22424 | }
|
22425 |
|
22426 |
|
22427 | store[storeIndex] = ev;
|
22428 |
|
22429 | this.callback(this.manager, eventType, {
|
22430 | pointers: store,
|
22431 | changedPointers: [ev],
|
22432 | pointerType: pointerType,
|
22433 | srcEvent: ev
|
22434 | });
|
22435 |
|
22436 | if (removePointer) {
|
22437 |
|
22438 | store.splice(storeIndex, 1);
|
22439 | }
|
22440 | }
|
22441 | });
|
22442 |
|
22443 | var SINGLE_TOUCH_INPUT_MAP = {
|
22444 | touchstart: INPUT_START,
|
22445 | touchmove: INPUT_MOVE,
|
22446 | touchend: INPUT_END,
|
22447 | touchcancel: INPUT_CANCEL
|
22448 | };
|
22449 |
|
22450 | var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
22451 | var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
22452 |
|
22453 | |
22454 |
|
22455 |
|
22456 |
|
22457 |
|
22458 | function SingleTouchInput() {
|
22459 | this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
22460 | this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
22461 | this.started = false;
|
22462 |
|
22463 | Input.apply(this, arguments);
|
22464 | }
|
22465 |
|
22466 | inherit(SingleTouchInput, Input, {
|
22467 | handler: function TEhandler(ev) {
|
22468 | var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
|
22469 |
|
22470 |
|
22471 | if (type === INPUT_START) {
|
22472 | this.started = true;
|
22473 | }
|
22474 |
|
22475 | if (!this.started) {
|
22476 | return;
|
22477 | }
|
22478 |
|
22479 | var touches = normalizeSingleTouches.call(this, ev, type);
|
22480 |
|
22481 |
|
22482 | if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
22483 | this.started = false;
|
22484 | }
|
22485 |
|
22486 | this.callback(this.manager, type, {
|
22487 | pointers: touches[0],
|
22488 | changedPointers: touches[1],
|
22489 | pointerType: INPUT_TYPE_TOUCH,
|
22490 | srcEvent: ev
|
22491 | });
|
22492 | }
|
22493 | });
|
22494 |
|
22495 | |
22496 |
|
22497 |
|
22498 |
|
22499 |
|
22500 |
|
22501 | function normalizeSingleTouches(ev, type) {
|
22502 | var all = toArray(ev.touches);
|
22503 | var changed = toArray(ev.changedTouches);
|
22504 |
|
22505 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
22506 | all = uniqueArray(all.concat(changed), 'identifier', true);
|
22507 | }
|
22508 |
|
22509 | return [all, changed];
|
22510 | }
|
22511 |
|
22512 | var TOUCH_INPUT_MAP = {
|
22513 | touchstart: INPUT_START,
|
22514 | touchmove: INPUT_MOVE,
|
22515 | touchend: INPUT_END,
|
22516 | touchcancel: INPUT_CANCEL
|
22517 | };
|
22518 |
|
22519 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
22520 |
|
22521 | |
22522 |
|
22523 |
|
22524 |
|
22525 |
|
22526 | function TouchInput() {
|
22527 | this.evTarget = TOUCH_TARGET_EVENTS;
|
22528 | this.targetIds = {};
|
22529 |
|
22530 | Input.apply(this, arguments);
|
22531 | }
|
22532 |
|
22533 | inherit(TouchInput, Input, {
|
22534 | handler: function MTEhandler(ev) {
|
22535 | var type = TOUCH_INPUT_MAP[ev.type];
|
22536 | var touches = getTouches.call(this, ev, type);
|
22537 | if (!touches) {
|
22538 | return;
|
22539 | }
|
22540 |
|
22541 | this.callback(this.manager, type, {
|
22542 | pointers: touches[0],
|
22543 | changedPointers: touches[1],
|
22544 | pointerType: INPUT_TYPE_TOUCH,
|
22545 | srcEvent: ev
|
22546 | });
|
22547 | }
|
22548 | });
|
22549 |
|
22550 | |
22551 |
|
22552 |
|
22553 |
|
22554 |
|
22555 |
|
22556 | function getTouches(ev, type) {
|
22557 | var allTouches = toArray(ev.touches);
|
22558 | var targetIds = this.targetIds;
|
22559 |
|
22560 |
|
22561 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
22562 | targetIds[allTouches[0].identifier] = true;
|
22563 | return [allTouches, allTouches];
|
22564 | }
|
22565 |
|
22566 | var i,
|
22567 | targetTouches,
|
22568 | changedTouches = toArray(ev.changedTouches),
|
22569 | changedTargetTouches = [],
|
22570 | target = this.target;
|
22571 |
|
22572 |
|
22573 | targetTouches = allTouches.filter(function(touch) {
|
22574 | return hasParent(touch.target, target);
|
22575 | });
|
22576 |
|
22577 |
|
22578 | if (type === INPUT_START) {
|
22579 | i = 0;
|
22580 | while (i < targetTouches.length) {
|
22581 | targetIds[targetTouches[i].identifier] = true;
|
22582 | i++;
|
22583 | }
|
22584 | }
|
22585 |
|
22586 |
|
22587 | i = 0;
|
22588 | while (i < changedTouches.length) {
|
22589 | if (targetIds[changedTouches[i].identifier]) {
|
22590 | changedTargetTouches.push(changedTouches[i]);
|
22591 | }
|
22592 |
|
22593 |
|
22594 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
22595 | delete targetIds[changedTouches[i].identifier];
|
22596 | }
|
22597 | i++;
|
22598 | }
|
22599 |
|
22600 | if (!changedTargetTouches.length) {
|
22601 | return;
|
22602 | }
|
22603 |
|
22604 | return [
|
22605 |
|
22606 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
|
22607 | changedTargetTouches
|
22608 | ];
|
22609 | }
|
22610 |
|
22611 | |
22612 |
|
22613 |
|
22614 |
|
22615 |
|
22616 |
|
22617 |
|
22618 |
|
22619 |
|
22620 |
|
22621 | var DEDUP_TIMEOUT = 2500;
|
22622 | var DEDUP_DISTANCE = 25;
|
22623 |
|
22624 | function TouchMouseInput() {
|
22625 | Input.apply(this, arguments);
|
22626 |
|
22627 | var handler = bindFn(this.handler, this);
|
22628 | this.touch = new TouchInput(this.manager, handler);
|
22629 | this.mouse = new MouseInput(this.manager, handler);
|
22630 |
|
22631 | this.primaryTouch = null;
|
22632 | this.lastTouches = [];
|
22633 | }
|
22634 |
|
22635 | inherit(TouchMouseInput, Input, {
|
22636 | |
22637 |
|
22638 |
|
22639 |
|
22640 |
|
22641 |
|
22642 | handler: function TMEhandler(manager, inputEvent, inputData) {
|
22643 | var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
|
22644 | isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
|
22645 |
|
22646 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
22647 | return;
|
22648 | }
|
22649 |
|
22650 |
|
22651 | if (isTouch) {
|
22652 | recordTouches.call(this, inputEvent, inputData);
|
22653 | } else if (isMouse && isSyntheticEvent.call(this, inputData)) {
|
22654 | return;
|
22655 | }
|
22656 |
|
22657 | this.callback(manager, inputEvent, inputData);
|
22658 | },
|
22659 |
|
22660 | |
22661 |
|
22662 |
|
22663 | destroy: function destroy() {
|
22664 | this.touch.destroy();
|
22665 | this.mouse.destroy();
|
22666 | }
|
22667 | });
|
22668 |
|
22669 | function recordTouches(eventType, eventData) {
|
22670 | if (eventType & INPUT_START) {
|
22671 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
22672 | setLastTouch.call(this, eventData);
|
22673 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
22674 | setLastTouch.call(this, eventData);
|
22675 | }
|
22676 | }
|
22677 |
|
22678 | function setLastTouch(eventData) {
|
22679 | var touch = eventData.changedPointers[0];
|
22680 |
|
22681 | if (touch.identifier === this.primaryTouch) {
|
22682 | var lastTouch = {x: touch.clientX, y: touch.clientY};
|
22683 | this.lastTouches.push(lastTouch);
|
22684 | var lts = this.lastTouches;
|
22685 | var removeLastTouch = function() {
|
22686 | var i = lts.indexOf(lastTouch);
|
22687 | if (i > -1) {
|
22688 | lts.splice(i, 1);
|
22689 | }
|
22690 | };
|
22691 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
22692 | }
|
22693 | }
|
22694 |
|
22695 | function isSyntheticEvent(eventData) {
|
22696 | var x = eventData.srcEvent.clientX, y = eventData.srcEvent.clientY;
|
22697 | for (var i = 0; i < this.lastTouches.length; i++) {
|
22698 | var t = this.lastTouches[i];
|
22699 | var dx = Math.abs(x - t.x), dy = Math.abs(y - t.y);
|
22700 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
22701 | return true;
|
22702 | }
|
22703 | }
|
22704 | return false;
|
22705 | }
|
22706 |
|
22707 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
22708 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
|
22709 |
|
22710 |
|
22711 | var TOUCH_ACTION_COMPUTE = 'compute';
|
22712 | var TOUCH_ACTION_AUTO = 'auto';
|
22713 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
22714 | var TOUCH_ACTION_NONE = 'none';
|
22715 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
22716 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
22717 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
22718 |
|
22719 | |
22720 |
|
22721 |
|
22722 |
|
22723 |
|
22724 |
|
22725 |
|
22726 | function TouchAction(manager, value) {
|
22727 | this.manager = manager;
|
22728 | this.set(value);
|
22729 | }
|
22730 |
|
22731 | TouchAction.prototype = {
|
22732 | |
22733 |
|
22734 |
|
22735 |
|
22736 | set: function(value) {
|
22737 |
|
22738 | if (value == TOUCH_ACTION_COMPUTE) {
|
22739 | value = this.compute();
|
22740 | }
|
22741 |
|
22742 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
22743 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
22744 | }
|
22745 | this.actions = value.toLowerCase().trim();
|
22746 | },
|
22747 |
|
22748 | |
22749 |
|
22750 |
|
22751 | update: function() {
|
22752 | this.set(this.manager.options.touchAction);
|
22753 | },
|
22754 |
|
22755 | |
22756 |
|
22757 |
|
22758 |
|
22759 | compute: function() {
|
22760 | var actions = [];
|
22761 | each(this.manager.recognizers, function(recognizer) {
|
22762 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
22763 | actions = actions.concat(recognizer.getTouchAction());
|
22764 | }
|
22765 | });
|
22766 | return cleanTouchActions(actions.join(' '));
|
22767 | },
|
22768 |
|
22769 | |
22770 |
|
22771 |
|
22772 |
|
22773 | preventDefaults: function(input) {
|
22774 | var srcEvent = input.srcEvent;
|
22775 | var direction = input.offsetDirection;
|
22776 |
|
22777 |
|
22778 | if (this.manager.session.prevented) {
|
22779 | srcEvent.preventDefault();
|
22780 | return;
|
22781 | }
|
22782 |
|
22783 | var actions = this.actions;
|
22784 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
22785 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
22786 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
22787 |
|
22788 | if (hasNone) {
|
22789 |
|
22790 |
|
22791 | var isTapPointer = input.pointers.length === 1;
|
22792 | var isTapMovement = input.distance < 2;
|
22793 | var isTapTouchTime = input.deltaTime < 250;
|
22794 |
|
22795 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
22796 | return;
|
22797 | }
|
22798 | }
|
22799 |
|
22800 | if (hasPanX && hasPanY) {
|
22801 |
|
22802 | return;
|
22803 | }
|
22804 |
|
22805 | if (hasNone ||
|
22806 | (hasPanY && direction & DIRECTION_HORIZONTAL) ||
|
22807 | (hasPanX && direction & DIRECTION_VERTICAL)) {
|
22808 | return this.preventSrc(srcEvent);
|
22809 | }
|
22810 | },
|
22811 |
|
22812 | |
22813 |
|
22814 |
|
22815 |
|
22816 | preventSrc: function(srcEvent) {
|
22817 | this.manager.session.prevented = true;
|
22818 | srcEvent.preventDefault();
|
22819 | }
|
22820 | };
|
22821 |
|
22822 | |
22823 |
|
22824 |
|
22825 |
|
22826 |
|
22827 | function cleanTouchActions(actions) {
|
22828 |
|
22829 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
22830 | return TOUCH_ACTION_NONE;
|
22831 | }
|
22832 |
|
22833 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
22834 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
22835 |
|
22836 |
|
22837 |
|
22838 |
|
22839 |
|
22840 | if (hasPanX && hasPanY) {
|
22841 | return TOUCH_ACTION_NONE;
|
22842 | }
|
22843 |
|
22844 |
|
22845 | if (hasPanX || hasPanY) {
|
22846 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
22847 | }
|
22848 |
|
22849 |
|
22850 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
22851 | return TOUCH_ACTION_MANIPULATION;
|
22852 | }
|
22853 |
|
22854 | return TOUCH_ACTION_AUTO;
|
22855 | }
|
22856 |
|
22857 | function getTouchActionProps() {
|
22858 | if (!NATIVE_TOUCH_ACTION) {
|
22859 | return false;
|
22860 | }
|
22861 | var touchMap = {};
|
22862 | var cssSupports = window.CSS && window.CSS.supports;
|
22863 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function(val) {
|
22864 |
|
22865 |
|
22866 |
|
22867 | touchMap[val] = cssSupports ? window.CSS.supports('touch-action', val) : true;
|
22868 | });
|
22869 | return touchMap;
|
22870 | }
|
22871 |
|
22872 | |
22873 |
|
22874 |
|
22875 |
|
22876 |
|
22877 |
|
22878 |
|
22879 |
|
22880 |
|
22881 |
|
22882 |
|
22883 |
|
22884 |
|
22885 |
|
22886 |
|
22887 |
|
22888 |
|
22889 |
|
22890 |
|
22891 |
|
22892 |
|
22893 |
|
22894 |
|
22895 |
|
22896 |
|
22897 |
|
22898 |
|
22899 | var STATE_POSSIBLE = 1;
|
22900 | var STATE_BEGAN = 2;
|
22901 | var STATE_CHANGED = 4;
|
22902 | var STATE_ENDED = 8;
|
22903 | var STATE_RECOGNIZED = STATE_ENDED;
|
22904 | var STATE_CANCELLED = 16;
|
22905 | var STATE_FAILED = 32;
|
22906 |
|
22907 | |
22908 |
|
22909 |
|
22910 |
|
22911 |
|
22912 |
|
22913 | function Recognizer(options) {
|
22914 | this.options = assign({}, this.defaults, options || {});
|
22915 |
|
22916 | this.id = uniqueId();
|
22917 |
|
22918 | this.manager = null;
|
22919 |
|
22920 |
|
22921 | this.options.enable = ifUndefined(this.options.enable, true);
|
22922 |
|
22923 | this.state = STATE_POSSIBLE;
|
22924 |
|
22925 | this.simultaneous = {};
|
22926 | this.requireFail = [];
|
22927 | }
|
22928 |
|
22929 | Recognizer.prototype = {
|
22930 | |
22931 |
|
22932 |
|
22933 |
|
22934 | defaults: {},
|
22935 |
|
22936 | |
22937 |
|
22938 |
|
22939 |
|
22940 |
|
22941 | set: function(options) {
|
22942 | assign(this.options, options);
|
22943 |
|
22944 |
|
22945 | this.manager && this.manager.touchAction.update();
|
22946 | return this;
|
22947 | },
|
22948 |
|
22949 | |
22950 |
|
22951 |
|
22952 |
|
22953 |
|
22954 | recognizeWith: function(otherRecognizer) {
|
22955 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
22956 | return this;
|
22957 | }
|
22958 |
|
22959 | var simultaneous = this.simultaneous;
|
22960 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
22961 | if (!simultaneous[otherRecognizer.id]) {
|
22962 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
22963 | otherRecognizer.recognizeWith(this);
|
22964 | }
|
22965 | return this;
|
22966 | },
|
22967 |
|
22968 | |
22969 |
|
22970 |
|
22971 |
|
22972 |
|
22973 | dropRecognizeWith: function(otherRecognizer) {
|
22974 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
22975 | return this;
|
22976 | }
|
22977 |
|
22978 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
22979 | delete this.simultaneous[otherRecognizer.id];
|
22980 | return this;
|
22981 | },
|
22982 |
|
22983 | |
22984 |
|
22985 |
|
22986 |
|
22987 |
|
22988 | requireFailure: function(otherRecognizer) {
|
22989 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
22990 | return this;
|
22991 | }
|
22992 |
|
22993 | var requireFail = this.requireFail;
|
22994 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
22995 | if (inArray(requireFail, otherRecognizer) === -1) {
|
22996 | requireFail.push(otherRecognizer);
|
22997 | otherRecognizer.requireFailure(this);
|
22998 | }
|
22999 | return this;
|
23000 | },
|
23001 |
|
23002 | |
23003 |
|
23004 |
|
23005 |
|
23006 |
|
23007 | dropRequireFailure: function(otherRecognizer) {
|
23008 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
23009 | return this;
|
23010 | }
|
23011 |
|
23012 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
23013 | var index = inArray(this.requireFail, otherRecognizer);
|
23014 | if (index > -1) {
|
23015 | this.requireFail.splice(index, 1);
|
23016 | }
|
23017 | return this;
|
23018 | },
|
23019 |
|
23020 | |
23021 |
|
23022 |
|
23023 |
|
23024 | hasRequireFailures: function() {
|
23025 | return this.requireFail.length > 0;
|
23026 | },
|
23027 |
|
23028 | |
23029 |
|
23030 |
|
23031 |
|
23032 |
|
23033 | canRecognizeWith: function(otherRecognizer) {
|
23034 | return !!this.simultaneous[otherRecognizer.id];
|
23035 | },
|
23036 |
|
23037 | |
23038 |
|
23039 |
|
23040 |
|
23041 |
|
23042 | emit: function(input) {
|
23043 | var self = this;
|
23044 | var state = this.state;
|
23045 |
|
23046 | function emit(event) {
|
23047 | self.manager.emit(event, input);
|
23048 | }
|
23049 |
|
23050 |
|
23051 | if (state < STATE_ENDED) {
|
23052 | emit(self.options.event + stateStr(state));
|
23053 | }
|
23054 |
|
23055 | emit(self.options.event);
|
23056 |
|
23057 | if (input.additionalEvent) {
|
23058 | emit(input.additionalEvent);
|
23059 | }
|
23060 |
|
23061 |
|
23062 | if (state >= STATE_ENDED) {
|
23063 | emit(self.options.event + stateStr(state));
|
23064 | }
|
23065 | },
|
23066 |
|
23067 | |
23068 |
|
23069 |
|
23070 |
|
23071 |
|
23072 |
|
23073 | tryEmit: function(input) {
|
23074 | if (this.canEmit()) {
|
23075 | return this.emit(input);
|
23076 | }
|
23077 |
|
23078 | this.state = STATE_FAILED;
|
23079 | },
|
23080 |
|
23081 | |
23082 |
|
23083 |
|
23084 |
|
23085 | canEmit: function() {
|
23086 | var i = 0;
|
23087 | while (i < this.requireFail.length) {
|
23088 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
23089 | return false;
|
23090 | }
|
23091 | i++;
|
23092 | }
|
23093 | return true;
|
23094 | },
|
23095 |
|
23096 | |
23097 |
|
23098 |
|
23099 |
|
23100 | recognize: function(inputData) {
|
23101 |
|
23102 |
|
23103 | var inputDataClone = assign({}, inputData);
|
23104 |
|
23105 |
|
23106 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
23107 | this.reset();
|
23108 | this.state = STATE_FAILED;
|
23109 | return;
|
23110 | }
|
23111 |
|
23112 |
|
23113 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
23114 | this.state = STATE_POSSIBLE;
|
23115 | }
|
23116 |
|
23117 | this.state = this.process(inputDataClone);
|
23118 |
|
23119 |
|
23120 |
|
23121 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
23122 | this.tryEmit(inputDataClone);
|
23123 | }
|
23124 | },
|
23125 |
|
23126 | |
23127 |
|
23128 |
|
23129 |
|
23130 |
|
23131 |
|
23132 |
|
23133 | process: function(inputData) { },
|
23134 |
|
23135 | |
23136 |
|
23137 |
|
23138 |
|
23139 |
|
23140 | getTouchAction: function() { },
|
23141 |
|
23142 | |
23143 |
|
23144 |
|
23145 |
|
23146 |
|
23147 | reset: function() { }
|
23148 | };
|
23149 |
|
23150 | |
23151 |
|
23152 |
|
23153 |
|
23154 |
|
23155 | function stateStr(state) {
|
23156 | if (state & STATE_CANCELLED) {
|
23157 | return 'cancel';
|
23158 | } else if (state & STATE_ENDED) {
|
23159 | return 'end';
|
23160 | } else if (state & STATE_CHANGED) {
|
23161 | return 'move';
|
23162 | } else if (state & STATE_BEGAN) {
|
23163 | return 'start';
|
23164 | }
|
23165 | return '';
|
23166 | }
|
23167 |
|
23168 | |
23169 |
|
23170 |
|
23171 |
|
23172 |
|
23173 | function directionStr(direction) {
|
23174 | if (direction == DIRECTION_DOWN) {
|
23175 | return 'down';
|
23176 | } else if (direction == DIRECTION_UP) {
|
23177 | return 'up';
|
23178 | } else if (direction == DIRECTION_LEFT) {
|
23179 | return 'left';
|
23180 | } else if (direction == DIRECTION_RIGHT) {
|
23181 | return 'right';
|
23182 | }
|
23183 | return '';
|
23184 | }
|
23185 |
|
23186 | |
23187 |
|
23188 |
|
23189 |
|
23190 |
|
23191 |
|
23192 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
23193 | var manager = recognizer.manager;
|
23194 | if (manager) {
|
23195 | return manager.get(otherRecognizer);
|
23196 | }
|
23197 | return otherRecognizer;
|
23198 | }
|
23199 |
|
23200 | |
23201 |
|
23202 |
|
23203 |
|
23204 |
|
23205 | function AttrRecognizer() {
|
23206 | Recognizer.apply(this, arguments);
|
23207 | }
|
23208 |
|
23209 | inherit(AttrRecognizer, Recognizer, {
|
23210 | |
23211 |
|
23212 |
|
23213 |
|
23214 | defaults: {
|
23215 | |
23216 |
|
23217 |
|
23218 |
|
23219 | pointers: 1
|
23220 | },
|
23221 |
|
23222 | |
23223 |
|
23224 |
|
23225 |
|
23226 |
|
23227 |
|
23228 | attrTest: function(input) {
|
23229 | var optionPointers = this.options.pointers;
|
23230 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
23231 | },
|
23232 |
|
23233 | |
23234 |
|
23235 |
|
23236 |
|
23237 |
|
23238 |
|
23239 | process: function(input) {
|
23240 | var state = this.state;
|
23241 | var eventType = input.eventType;
|
23242 |
|
23243 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
23244 | var isValid = this.attrTest(input);
|
23245 |
|
23246 |
|
23247 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
23248 | return state | STATE_CANCELLED;
|
23249 | } else if (isRecognized || isValid) {
|
23250 | if (eventType & INPUT_END) {
|
23251 | return state | STATE_ENDED;
|
23252 | } else if (!(state & STATE_BEGAN)) {
|
23253 | return STATE_BEGAN;
|
23254 | }
|
23255 | return state | STATE_CHANGED;
|
23256 | }
|
23257 | return STATE_FAILED;
|
23258 | }
|
23259 | });
|
23260 |
|
23261 | |
23262 |
|
23263 |
|
23264 |
|
23265 |
|
23266 |
|
23267 | function PanRecognizer() {
|
23268 | AttrRecognizer.apply(this, arguments);
|
23269 |
|
23270 | this.pX = null;
|
23271 | this.pY = null;
|
23272 | }
|
23273 |
|
23274 | inherit(PanRecognizer, AttrRecognizer, {
|
23275 | |
23276 |
|
23277 |
|
23278 |
|
23279 | defaults: {
|
23280 | event: 'pan',
|
23281 | threshold: 10,
|
23282 | pointers: 1,
|
23283 | direction: DIRECTION_ALL
|
23284 | },
|
23285 |
|
23286 | getTouchAction: function() {
|
23287 | var direction = this.options.direction;
|
23288 | var actions = [];
|
23289 | if (direction & DIRECTION_HORIZONTAL) {
|
23290 | actions.push(TOUCH_ACTION_PAN_Y);
|
23291 | }
|
23292 | if (direction & DIRECTION_VERTICAL) {
|
23293 | actions.push(TOUCH_ACTION_PAN_X);
|
23294 | }
|
23295 | return actions;
|
23296 | },
|
23297 |
|
23298 | directionTest: function(input) {
|
23299 | var options = this.options;
|
23300 | var hasMoved = true;
|
23301 | var distance = input.distance;
|
23302 | var direction = input.direction;
|
23303 | var x = input.deltaX;
|
23304 | var y = input.deltaY;
|
23305 |
|
23306 |
|
23307 | if (!(direction & options.direction)) {
|
23308 | if (options.direction & DIRECTION_HORIZONTAL) {
|
23309 | direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
23310 | hasMoved = x != this.pX;
|
23311 | distance = Math.abs(input.deltaX);
|
23312 | } else {
|
23313 | direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
|
23314 | hasMoved = y != this.pY;
|
23315 | distance = Math.abs(input.deltaY);
|
23316 | }
|
23317 | }
|
23318 | input.direction = direction;
|
23319 | return hasMoved && distance > options.threshold && direction & options.direction;
|
23320 | },
|
23321 |
|
23322 | attrTest: function(input) {
|
23323 | return AttrRecognizer.prototype.attrTest.call(this, input) &&
|
23324 | (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
|
23325 | },
|
23326 |
|
23327 | emit: function(input) {
|
23328 |
|
23329 | this.pX = input.deltaX;
|
23330 | this.pY = input.deltaY;
|
23331 |
|
23332 | var direction = directionStr(input.direction);
|
23333 |
|
23334 | if (direction) {
|
23335 | input.additionalEvent = this.options.event + direction;
|
23336 | }
|
23337 | this._super.emit.call(this, input);
|
23338 | }
|
23339 | });
|
23340 |
|
23341 | |
23342 |
|
23343 |
|
23344 |
|
23345 |
|
23346 |
|
23347 | function PinchRecognizer() {
|
23348 | AttrRecognizer.apply(this, arguments);
|
23349 | }
|
23350 |
|
23351 | inherit(PinchRecognizer, AttrRecognizer, {
|
23352 | |
23353 |
|
23354 |
|
23355 |
|
23356 | defaults: {
|
23357 | event: 'pinch',
|
23358 | threshold: 0,
|
23359 | pointers: 2
|
23360 | },
|
23361 |
|
23362 | getTouchAction: function() {
|
23363 | return [TOUCH_ACTION_NONE];
|
23364 | },
|
23365 |
|
23366 | attrTest: function(input) {
|
23367 | return this._super.attrTest.call(this, input) &&
|
23368 | (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
23369 | },
|
23370 |
|
23371 | emit: function(input) {
|
23372 | if (input.scale !== 1) {
|
23373 | var inOut = input.scale < 1 ? 'in' : 'out';
|
23374 | input.additionalEvent = this.options.event + inOut;
|
23375 | }
|
23376 | this._super.emit.call(this, input);
|
23377 | }
|
23378 | });
|
23379 |
|
23380 | |
23381 |
|
23382 |
|
23383 |
|
23384 |
|
23385 |
|
23386 | function PressRecognizer() {
|
23387 | Recognizer.apply(this, arguments);
|
23388 |
|
23389 | this._timer = null;
|
23390 | this._input = null;
|
23391 | }
|
23392 |
|
23393 | inherit(PressRecognizer, Recognizer, {
|
23394 | |
23395 |
|
23396 |
|
23397 |
|
23398 | defaults: {
|
23399 | event: 'press',
|
23400 | pointers: 1,
|
23401 | time: 251,
|
23402 | threshold: 9
|
23403 | },
|
23404 |
|
23405 | getTouchAction: function() {
|
23406 | return [TOUCH_ACTION_AUTO];
|
23407 | },
|
23408 |
|
23409 | process: function(input) {
|
23410 | var options = this.options;
|
23411 | var validPointers = input.pointers.length === options.pointers;
|
23412 | var validMovement = input.distance < options.threshold;
|
23413 | var validTime = input.deltaTime > options.time;
|
23414 |
|
23415 | this._input = input;
|
23416 |
|
23417 |
|
23418 |
|
23419 | if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
|
23420 | this.reset();
|
23421 | } else if (input.eventType & INPUT_START) {
|
23422 | this.reset();
|
23423 | this._timer = setTimeoutContext(function() {
|
23424 | this.state = STATE_RECOGNIZED;
|
23425 | this.tryEmit();
|
23426 | }, options.time, this);
|
23427 | } else if (input.eventType & INPUT_END) {
|
23428 | return STATE_RECOGNIZED;
|
23429 | }
|
23430 | return STATE_FAILED;
|
23431 | },
|
23432 |
|
23433 | reset: function() {
|
23434 | clearTimeout(this._timer);
|
23435 | },
|
23436 |
|
23437 | emit: function(input) {
|
23438 | if (this.state !== STATE_RECOGNIZED) {
|
23439 | return;
|
23440 | }
|
23441 |
|
23442 | if (input && (input.eventType & INPUT_END)) {
|
23443 | this.manager.emit(this.options.event + 'up', input);
|
23444 | } else {
|
23445 | this._input.timeStamp = now();
|
23446 | this.manager.emit(this.options.event, this._input);
|
23447 | }
|
23448 | }
|
23449 | });
|
23450 |
|
23451 | |
23452 |
|
23453 |
|
23454 |
|
23455 |
|
23456 |
|
23457 | function RotateRecognizer() {
|
23458 | AttrRecognizer.apply(this, arguments);
|
23459 | }
|
23460 |
|
23461 | inherit(RotateRecognizer, AttrRecognizer, {
|
23462 | |
23463 |
|
23464 |
|
23465 |
|
23466 | defaults: {
|
23467 | event: 'rotate',
|
23468 | threshold: 0,
|
23469 | pointers: 2
|
23470 | },
|
23471 |
|
23472 | getTouchAction: function() {
|
23473 | return [TOUCH_ACTION_NONE];
|
23474 | },
|
23475 |
|
23476 | attrTest: function(input) {
|
23477 | return this._super.attrTest.call(this, input) &&
|
23478 | (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
23479 | }
|
23480 | });
|
23481 |
|
23482 | |
23483 |
|
23484 |
|
23485 |
|
23486 |
|
23487 |
|
23488 | function SwipeRecognizer() {
|
23489 | AttrRecognizer.apply(this, arguments);
|
23490 | }
|
23491 |
|
23492 | inherit(SwipeRecognizer, AttrRecognizer, {
|
23493 | |
23494 |
|
23495 |
|
23496 |
|
23497 | defaults: {
|
23498 | event: 'swipe',
|
23499 | threshold: 10,
|
23500 | velocity: 0.3,
|
23501 | direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
23502 | pointers: 1
|
23503 | },
|
23504 |
|
23505 | getTouchAction: function() {
|
23506 | return PanRecognizer.prototype.getTouchAction.call(this);
|
23507 | },
|
23508 |
|
23509 | attrTest: function(input) {
|
23510 | var direction = this.options.direction;
|
23511 | var velocity;
|
23512 |
|
23513 | if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
23514 | velocity = input.overallVelocity;
|
23515 | } else if (direction & DIRECTION_HORIZONTAL) {
|
23516 | velocity = input.overallVelocityX;
|
23517 | } else if (direction & DIRECTION_VERTICAL) {
|
23518 | velocity = input.overallVelocityY;
|
23519 | }
|
23520 |
|
23521 | return this._super.attrTest.call(this, input) &&
|
23522 | direction & input.offsetDirection &&
|
23523 | input.distance > this.options.threshold &&
|
23524 | input.maxPointers == this.options.pointers &&
|
23525 | abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
|
23526 | },
|
23527 |
|
23528 | emit: function(input) {
|
23529 | var direction = directionStr(input.offsetDirection);
|
23530 | if (direction) {
|
23531 | this.manager.emit(this.options.event + direction, input);
|
23532 | }
|
23533 |
|
23534 | this.manager.emit(this.options.event, input);
|
23535 | }
|
23536 | });
|
23537 |
|
23538 | |
23539 |
|
23540 |
|
23541 |
|
23542 |
|
23543 |
|
23544 |
|
23545 |
|
23546 |
|
23547 |
|
23548 | function TapRecognizer() {
|
23549 | Recognizer.apply(this, arguments);
|
23550 |
|
23551 |
|
23552 |
|
23553 | this.pTime = false;
|
23554 | this.pCenter = false;
|
23555 |
|
23556 | this._timer = null;
|
23557 | this._input = null;
|
23558 | this.count = 0;
|
23559 | }
|
23560 |
|
23561 | inherit(TapRecognizer, Recognizer, {
|
23562 | |
23563 |
|
23564 |
|
23565 |
|
23566 | defaults: {
|
23567 | event: 'tap',
|
23568 | pointers: 1,
|
23569 | taps: 1,
|
23570 | interval: 300,
|
23571 | time: 250,
|
23572 | threshold: 9,
|
23573 | posThreshold: 10
|
23574 | },
|
23575 |
|
23576 | getTouchAction: function() {
|
23577 | return [TOUCH_ACTION_MANIPULATION];
|
23578 | },
|
23579 |
|
23580 | process: function(input) {
|
23581 | var options = this.options;
|
23582 |
|
23583 | var validPointers = input.pointers.length === options.pointers;
|
23584 | var validMovement = input.distance < options.threshold;
|
23585 | var validTouchTime = input.deltaTime < options.time;
|
23586 |
|
23587 | this.reset();
|
23588 |
|
23589 | if ((input.eventType & INPUT_START) && (this.count === 0)) {
|
23590 | return this.failTimeout();
|
23591 | }
|
23592 |
|
23593 |
|
23594 |
|
23595 | if (validMovement && validTouchTime && validPointers) {
|
23596 | if (input.eventType != INPUT_END) {
|
23597 | return this.failTimeout();
|
23598 | }
|
23599 |
|
23600 | var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
|
23601 | var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
23602 |
|
23603 | this.pTime = input.timeStamp;
|
23604 | this.pCenter = input.center;
|
23605 |
|
23606 | if (!validMultiTap || !validInterval) {
|
23607 | this.count = 1;
|
23608 | } else {
|
23609 | this.count += 1;
|
23610 | }
|
23611 |
|
23612 | this._input = input;
|
23613 |
|
23614 |
|
23615 |
|
23616 | var tapCount = this.count % options.taps;
|
23617 | if (tapCount === 0) {
|
23618 |
|
23619 |
|
23620 | if (!this.hasRequireFailures()) {
|
23621 | return STATE_RECOGNIZED;
|
23622 | } else {
|
23623 | this._timer = setTimeoutContext(function() {
|
23624 | this.state = STATE_RECOGNIZED;
|
23625 | this.tryEmit();
|
23626 | }, options.interval, this);
|
23627 | return STATE_BEGAN;
|
23628 | }
|
23629 | }
|
23630 | }
|
23631 | return STATE_FAILED;
|
23632 | },
|
23633 |
|
23634 | failTimeout: function() {
|
23635 | this._timer = setTimeoutContext(function() {
|
23636 | this.state = STATE_FAILED;
|
23637 | }, this.options.interval, this);
|
23638 | return STATE_FAILED;
|
23639 | },
|
23640 |
|
23641 | reset: function() {
|
23642 | clearTimeout(this._timer);
|
23643 | },
|
23644 |
|
23645 | emit: function() {
|
23646 | if (this.state == STATE_RECOGNIZED) {
|
23647 | this._input.tapCount = this.count;
|
23648 | this.manager.emit(this.options.event, this._input);
|
23649 | }
|
23650 | }
|
23651 | });
|
23652 |
|
23653 | |
23654 |
|
23655 |
|
23656 |
|
23657 |
|
23658 |
|
23659 | function Hammer(element, options) {
|
23660 | options = options || {};
|
23661 | options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
|
23662 | return new Manager(element, options);
|
23663 | }
|
23664 |
|
23665 | |
23666 |
|
23667 |
|
23668 | Hammer.VERSION = '2.0.7';
|
23669 |
|
23670 | |
23671 |
|
23672 |
|
23673 |
|
23674 | Hammer.defaults = {
|
23675 | |
23676 |
|
23677 |
|
23678 |
|
23679 |
|
23680 |
|
23681 | domEvents: false,
|
23682 |
|
23683 | |
23684 |
|
23685 |
|
23686 |
|
23687 |
|
23688 |
|
23689 | touchAction: TOUCH_ACTION_COMPUTE,
|
23690 |
|
23691 | |
23692 |
|
23693 |
|
23694 |
|
23695 | enable: true,
|
23696 |
|
23697 | |
23698 |
|
23699 |
|
23700 |
|
23701 |
|
23702 |
|
23703 |
|
23704 | inputTarget: null,
|
23705 |
|
23706 | |
23707 |
|
23708 |
|
23709 |
|
23710 |
|
23711 | inputClass: null,
|
23712 |
|
23713 | |
23714 |
|
23715 |
|
23716 |
|
23717 |
|
23718 | preset: [
|
23719 |
|
23720 | [RotateRecognizer, {enable: false}],
|
23721 | [PinchRecognizer, {enable: false}, ['rotate']],
|
23722 | [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
|
23723 | [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
|
23724 | [TapRecognizer],
|
23725 | [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
|
23726 | [PressRecognizer]
|
23727 | ],
|
23728 |
|
23729 | |
23730 |
|
23731 |
|
23732 |
|
23733 |
|
23734 | cssProps: {
|
23735 | |
23736 |
|
23737 |
|
23738 |
|
23739 |
|
23740 | userSelect: 'none',
|
23741 |
|
23742 | |
23743 |
|
23744 |
|
23745 |
|
23746 |
|
23747 | touchSelect: 'none',
|
23748 |
|
23749 | |
23750 |
|
23751 |
|
23752 |
|
23753 |
|
23754 |
|
23755 |
|
23756 | touchCallout: 'none',
|
23757 |
|
23758 | |
23759 |
|
23760 |
|
23761 |
|
23762 |
|
23763 | contentZooming: 'none',
|
23764 |
|
23765 | |
23766 |
|
23767 |
|
23768 |
|
23769 |
|
23770 | userDrag: 'none',
|
23771 |
|
23772 | |
23773 |
|
23774 |
|
23775 |
|
23776 |
|
23777 |
|
23778 | tapHighlightColor: 'rgba(0,0,0,0)'
|
23779 | }
|
23780 | };
|
23781 |
|
23782 | var STOP = 1;
|
23783 | var FORCED_STOP = 2;
|
23784 |
|
23785 | |
23786 |
|
23787 |
|
23788 |
|
23789 |
|
23790 |
|
23791 | function Manager(element, options) {
|
23792 | this.options = assign({}, Hammer.defaults, options || {});
|
23793 |
|
23794 | this.options.inputTarget = this.options.inputTarget || element;
|
23795 |
|
23796 | this.handlers = {};
|
23797 | this.session = {};
|
23798 | this.recognizers = [];
|
23799 | this.oldCssProps = {};
|
23800 |
|
23801 | this.element = element;
|
23802 | this.input = createInputInstance(this);
|
23803 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
23804 |
|
23805 | toggleCssProps(this, true);
|
23806 |
|
23807 | each(this.options.recognizers, function(item) {
|
23808 | var recognizer = this.add(new (item[0])(item[1]));
|
23809 | item[2] && recognizer.recognizeWith(item[2]);
|
23810 | item[3] && recognizer.requireFailure(item[3]);
|
23811 | }, this);
|
23812 | }
|
23813 |
|
23814 | Manager.prototype = {
|
23815 | |
23816 |
|
23817 |
|
23818 |
|
23819 |
|
23820 | set: function(options) {
|
23821 | assign(this.options, options);
|
23822 |
|
23823 |
|
23824 | if (options.touchAction) {
|
23825 | this.touchAction.update();
|
23826 | }
|
23827 | if (options.inputTarget) {
|
23828 |
|
23829 | this.input.destroy();
|
23830 | this.input.target = options.inputTarget;
|
23831 | this.input.init();
|
23832 | }
|
23833 | return this;
|
23834 | },
|
23835 |
|
23836 | |
23837 |
|
23838 |
|
23839 |
|
23840 |
|
23841 |
|
23842 | stop: function(force) {
|
23843 | this.session.stopped = force ? FORCED_STOP : STOP;
|
23844 | },
|
23845 |
|
23846 | |
23847 |
|
23848 |
|
23849 |
|
23850 |
|
23851 |
|
23852 | recognize: function(inputData) {
|
23853 | var session = this.session;
|
23854 | if (session.stopped) {
|
23855 | return;
|
23856 | }
|
23857 |
|
23858 |
|
23859 | this.touchAction.preventDefaults(inputData);
|
23860 |
|
23861 | var recognizer;
|
23862 | var recognizers = this.recognizers;
|
23863 |
|
23864 |
|
23865 |
|
23866 |
|
23867 | var curRecognizer = session.curRecognizer;
|
23868 |
|
23869 |
|
23870 |
|
23871 | if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
|
23872 | curRecognizer = session.curRecognizer = null;
|
23873 | }
|
23874 |
|
23875 | var i = 0;
|
23876 | while (i < recognizers.length) {
|
23877 | recognizer = recognizers[i];
|
23878 |
|
23879 |
|
23880 |
|
23881 |
|
23882 |
|
23883 |
|
23884 |
|
23885 | if (session.stopped !== FORCED_STOP && (
|
23886 | !curRecognizer || recognizer == curRecognizer ||
|
23887 | recognizer.canRecognizeWith(curRecognizer))) {
|
23888 | recognizer.recognize(inputData);
|
23889 | } else {
|
23890 | recognizer.reset();
|
23891 | }
|
23892 |
|
23893 |
|
23894 |
|
23895 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
23896 | curRecognizer = session.curRecognizer = recognizer;
|
23897 | }
|
23898 | i++;
|
23899 | }
|
23900 | },
|
23901 |
|
23902 | |
23903 |
|
23904 |
|
23905 |
|
23906 |
|
23907 | get: function(recognizer) {
|
23908 | if (recognizer instanceof Recognizer) {
|
23909 | return recognizer;
|
23910 | }
|
23911 |
|
23912 | var recognizers = this.recognizers;
|
23913 | for (var i = 0; i < recognizers.length; i++) {
|
23914 | if (recognizers[i].options.event == recognizer) {
|
23915 | return recognizers[i];
|
23916 | }
|
23917 | }
|
23918 | return null;
|
23919 | },
|
23920 |
|
23921 | |
23922 |
|
23923 |
|
23924 |
|
23925 |
|
23926 |
|
23927 | add: function(recognizer) {
|
23928 | if (invokeArrayArg(recognizer, 'add', this)) {
|
23929 | return this;
|
23930 | }
|
23931 |
|
23932 |
|
23933 | var existing = this.get(recognizer.options.event);
|
23934 | if (existing) {
|
23935 | this.remove(existing);
|
23936 | }
|
23937 |
|
23938 | this.recognizers.push(recognizer);
|
23939 | recognizer.manager = this;
|
23940 |
|
23941 | this.touchAction.update();
|
23942 | return recognizer;
|
23943 | },
|
23944 |
|
23945 | |
23946 |
|
23947 |
|
23948 |
|
23949 |
|
23950 | remove: function(recognizer) {
|
23951 | if (invokeArrayArg(recognizer, 'remove', this)) {
|
23952 | return this;
|
23953 | }
|
23954 |
|
23955 | recognizer = this.get(recognizer);
|
23956 |
|
23957 |
|
23958 | if (recognizer) {
|
23959 | var recognizers = this.recognizers;
|
23960 | var index = inArray(recognizers, recognizer);
|
23961 |
|
23962 | if (index !== -1) {
|
23963 | recognizers.splice(index, 1);
|
23964 | this.touchAction.update();
|
23965 | }
|
23966 | }
|
23967 |
|
23968 | return this;
|
23969 | },
|
23970 |
|
23971 | |
23972 |
|
23973 |
|
23974 |
|
23975 |
|
23976 |
|
23977 | on: function(events, handler) {
|
23978 | if (events === undefined) {
|
23979 | return;
|
23980 | }
|
23981 | if (handler === undefined) {
|
23982 | return;
|
23983 | }
|
23984 |
|
23985 | var handlers = this.handlers;
|
23986 | each(splitStr(events), function(event) {
|
23987 | handlers[event] = handlers[event] || [];
|
23988 | handlers[event].push(handler);
|
23989 | });
|
23990 | return this;
|
23991 | },
|
23992 |
|
23993 | |
23994 |
|
23995 |
|
23996 |
|
23997 |
|
23998 |
|
23999 | off: function(events, handler) {
|
24000 | if (events === undefined) {
|
24001 | return;
|
24002 | }
|
24003 |
|
24004 | var handlers = this.handlers;
|
24005 | each(splitStr(events), function(event) {
|
24006 | if (!handler) {
|
24007 | delete handlers[event];
|
24008 | } else {
|
24009 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
24010 | }
|
24011 | });
|
24012 | return this;
|
24013 | },
|
24014 |
|
24015 | |
24016 |
|
24017 |
|
24018 |
|
24019 |
|
24020 | emit: function(event, data) {
|
24021 |
|
24022 | if (this.options.domEvents) {
|
24023 | triggerDomEvent(event, data);
|
24024 | }
|
24025 |
|
24026 |
|
24027 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
24028 | if (!handlers || !handlers.length) {
|
24029 | return;
|
24030 | }
|
24031 |
|
24032 | data.type = event;
|
24033 | data.preventDefault = function() {
|
24034 | data.srcEvent.preventDefault();
|
24035 | };
|
24036 |
|
24037 | var i = 0;
|
24038 | while (i < handlers.length) {
|
24039 | handlers[i](data);
|
24040 | i++;
|
24041 | }
|
24042 | },
|
24043 |
|
24044 | |
24045 |
|
24046 |
|
24047 |
|
24048 | destroy: function() {
|
24049 | this.element && toggleCssProps(this, false);
|
24050 |
|
24051 | this.handlers = {};
|
24052 | this.session = {};
|
24053 | this.input.destroy();
|
24054 | this.element = null;
|
24055 | }
|
24056 | };
|
24057 |
|
24058 | |
24059 |
|
24060 |
|
24061 |
|
24062 |
|
24063 | function toggleCssProps(manager, add) {
|
24064 | var element = manager.element;
|
24065 | if (!element.style) {
|
24066 | return;
|
24067 | }
|
24068 | var prop;
|
24069 | each(manager.options.cssProps, function(value, name) {
|
24070 | prop = prefixed(element.style, name);
|
24071 | if (add) {
|
24072 | manager.oldCssProps[prop] = element.style[prop];
|
24073 | element.style[prop] = value;
|
24074 | } else {
|
24075 | element.style[prop] = manager.oldCssProps[prop] || '';
|
24076 | }
|
24077 | });
|
24078 | if (!add) {
|
24079 | manager.oldCssProps = {};
|
24080 | }
|
24081 | }
|
24082 |
|
24083 | |
24084 |
|
24085 |
|
24086 |
|
24087 |
|
24088 | function triggerDomEvent(event, data) {
|
24089 | var gestureEvent = document.createEvent('Event');
|
24090 | gestureEvent.initEvent(event, true, true);
|
24091 | gestureEvent.gesture = data;
|
24092 | data.target.dispatchEvent(gestureEvent);
|
24093 | }
|
24094 |
|
24095 | assign(Hammer, {
|
24096 | INPUT_START: INPUT_START,
|
24097 | INPUT_MOVE: INPUT_MOVE,
|
24098 | INPUT_END: INPUT_END,
|
24099 | INPUT_CANCEL: INPUT_CANCEL,
|
24100 |
|
24101 | STATE_POSSIBLE: STATE_POSSIBLE,
|
24102 | STATE_BEGAN: STATE_BEGAN,
|
24103 | STATE_CHANGED: STATE_CHANGED,
|
24104 | STATE_ENDED: STATE_ENDED,
|
24105 | STATE_RECOGNIZED: STATE_RECOGNIZED,
|
24106 | STATE_CANCELLED: STATE_CANCELLED,
|
24107 | STATE_FAILED: STATE_FAILED,
|
24108 |
|
24109 | DIRECTION_NONE: DIRECTION_NONE,
|
24110 | DIRECTION_LEFT: DIRECTION_LEFT,
|
24111 | DIRECTION_RIGHT: DIRECTION_RIGHT,
|
24112 | DIRECTION_UP: DIRECTION_UP,
|
24113 | DIRECTION_DOWN: DIRECTION_DOWN,
|
24114 | DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
|
24115 | DIRECTION_VERTICAL: DIRECTION_VERTICAL,
|
24116 | DIRECTION_ALL: DIRECTION_ALL,
|
24117 |
|
24118 | Manager: Manager,
|
24119 | Input: Input,
|
24120 | TouchAction: TouchAction,
|
24121 |
|
24122 | TouchInput: TouchInput,
|
24123 | MouseInput: MouseInput,
|
24124 | PointerEventInput: PointerEventInput,
|
24125 | TouchMouseInput: TouchMouseInput,
|
24126 | SingleTouchInput: SingleTouchInput,
|
24127 |
|
24128 | Recognizer: Recognizer,
|
24129 | AttrRecognizer: AttrRecognizer,
|
24130 | Tap: TapRecognizer,
|
24131 | Pan: PanRecognizer,
|
24132 | Swipe: SwipeRecognizer,
|
24133 | Pinch: PinchRecognizer,
|
24134 | Rotate: RotateRecognizer,
|
24135 | Press: PressRecognizer,
|
24136 |
|
24137 | on: addEventListeners,
|
24138 | off: removeEventListeners,
|
24139 | each: each,
|
24140 | merge: merge,
|
24141 | extend: extend,
|
24142 | assign: assign,
|
24143 | inherit: inherit,
|
24144 | bindFn: bindFn,
|
24145 | prefixed: prefixed
|
24146 | });
|
24147 |
|
24148 |
|
24149 |
|
24150 | var freeGlobal = (typeof window !== 'undefined' ? window : (typeof self !== 'undefined' ? self : {}));
|
24151 | freeGlobal.Hammer = Hammer;
|
24152 |
|
24153 | if (typeof undefined === 'function' && undefined.amd) {
|
24154 | undefined(function() {
|
24155 | return Hammer;
|
24156 | });
|
24157 | } else if (module.exports) {
|
24158 | module.exports = Hammer;
|
24159 | } else {
|
24160 | window[exportName] = Hammer;
|
24161 | }
|
24162 |
|
24163 | })(window, document, 'Hammer');
|
24164 | });
|
24165 |
|
24166 | var MIN_ZOOM = 0.2,
|
24167 | MAX_ZOOM = 4;
|
24168 |
|
24169 | var mouseEvents = [
|
24170 | 'mousedown',
|
24171 | 'mouseup',
|
24172 | 'mouseover',
|
24173 | 'mouseout',
|
24174 | 'click',
|
24175 | 'dblclick'
|
24176 | ];
|
24177 |
|
24178 | function get$1(service, injector) {
|
24179 | return injector.get(service, false);
|
24180 | }
|
24181 |
|
24182 | function stopEvent(event$$1) {
|
24183 |
|
24184 | event$$1.preventDefault();
|
24185 | event$$1.stopPropagation();
|
24186 |
|
24187 | if (typeof event$$1.stopImmediatePropagation === 'function') {
|
24188 | event$$1.stopImmediatePropagation();
|
24189 | }
|
24190 | }
|
24191 |
|
24192 |
|
24193 | function createTouchRecognizer(node) {
|
24194 |
|
24195 | function stopMouse(event$$1) {
|
24196 |
|
24197 | forEach(mouseEvents, function(e) {
|
24198 | componentEvent.bind(node, e, stopEvent, true);
|
24199 | });
|
24200 | }
|
24201 |
|
24202 | function allowMouse(event$$1) {
|
24203 | setTimeout(function() {
|
24204 | forEach(mouseEvents, function(e) {
|
24205 | componentEvent.unbind(node, e, stopEvent, true);
|
24206 | });
|
24207 | }, 500);
|
24208 | }
|
24209 |
|
24210 | componentEvent.bind(node, 'touchstart', stopMouse, true);
|
24211 | componentEvent.bind(node, 'touchend', allowMouse, true);
|
24212 | componentEvent.bind(node, 'touchcancel', allowMouse, true);
|
24213 |
|
24214 |
|
24215 |
|
24216 |
|
24217 |
|
24218 | var recognizer = new hammer.Manager(node, {
|
24219 | inputClass: hammer.TouchInput,
|
24220 | recognizers: []
|
24221 | });
|
24222 |
|
24223 |
|
24224 | var tap = new hammer.Tap();
|
24225 | var pan = new hammer.Pan({ threshold: 10 });
|
24226 | var press = new hammer.Press();
|
24227 | var pinch = new hammer.Pinch();
|
24228 |
|
24229 | var doubleTap = new hammer.Tap({ event: 'doubletap', taps: 2 });
|
24230 |
|
24231 | pinch.requireFailure(pan);
|
24232 | pinch.requireFailure(press);
|
24233 |
|
24234 | recognizer.add([ pan, press, pinch, doubleTap, tap ]);
|
24235 |
|
24236 | recognizer.reset = function(force) {
|
24237 | var recognizers = this.recognizers,
|
24238 | session = this.session;
|
24239 |
|
24240 | if (session.stopped) {
|
24241 | return;
|
24242 | }
|
24243 |
|
24244 | recognizer.stop(force);
|
24245 |
|
24246 | setTimeout(function() {
|
24247 | var i, r;
|
24248 | for (i = 0; (r = recognizers[i]); i++) {
|
24249 | r.reset();
|
24250 | r.state = 8;
|
24251 | }
|
24252 |
|
24253 | session.curRecognizer = null;
|
24254 | }, 0);
|
24255 | };
|
24256 |
|
24257 | recognizer.on('hammer.input', function(event$$1) {
|
24258 | if (event$$1.srcEvent.defaultPrevented) {
|
24259 | recognizer.reset(true);
|
24260 | }
|
24261 | });
|
24262 |
|
24263 | return recognizer;
|
24264 | }
|
24265 |
|
24266 | |
24267 |
|
24268 |
|
24269 |
|
24270 |
|
24271 |
|
24272 | function TouchInteractionEvents(
|
24273 | injector, canvas, eventBus,
|
24274 | elementRegistry, interactionEvents) {
|
24275 |
|
24276 |
|
24277 | var dragging = get$1('dragging', injector),
|
24278 | move = get$1('move', injector),
|
24279 | contextPad = get$1('contextPad', injector),
|
24280 | palette = get$1('palette', injector);
|
24281 |
|
24282 | // the touch recognizer
|
24283 | var recognizer;
|
24284 |
|
24285 | function handler(type) {
|
24286 |
|
24287 | return function(event$$1) {
|
24288 |
|
24289 | interactionEvents.fire(type, event$$1);
|
24290 | };
|
24291 | }
|
24292 |
|
24293 | function getGfx(target) {
|
24294 | var node = closest(target, 'svg, .djs-element', true);
|
24295 | return node;
|
24296 | }
|
24297 |
|
24298 | function initEvents(svg) {
|
24299 |
|
24300 |
|
24301 | recognizer = createTouchRecognizer(svg);
|
24302 |
|
24303 | recognizer.on('doubletap', handler('element.dblclick'));
|
24304 |
|
24305 | recognizer.on('tap', handler('element.click'));
|
24306 |
|
24307 | function startGrabCanvas(event$$1) {
|
24308 |
|
24309 | var lx = 0, ly = 0;
|
24310 |
|
24311 | function update(e) {
|
24312 |
|
24313 | var dx = e.deltaX - lx,
|
24314 | dy = e.deltaY - ly;
|
24315 |
|
24316 | canvas.scroll({ dx: dx, dy: dy });
|
24317 |
|
24318 | lx = e.deltaX;
|
24319 | ly = e.deltaY;
|
24320 | }
|
24321 |
|
24322 | function end(e) {
|
24323 | recognizer.off('panmove', update);
|
24324 | recognizer.off('panend', end);
|
24325 | recognizer.off('pancancel', end);
|
24326 | }
|
24327 |
|
24328 | recognizer.on('panmove', update);
|
24329 | recognizer.on('panend', end);
|
24330 | recognizer.on('pancancel', end);
|
24331 | }
|
24332 |
|
24333 | function startGrab(event$$1) {
|
24334 |
|
24335 | var gfx = getGfx(event$$1.target),
|
24336 | element = gfx && elementRegistry.get(gfx);
|
24337 |
|
24338 |
|
24339 | if (move && canvas.getRootElement() !== element) {
|
24340 | return move.start(event$$1, element, true);
|
24341 | } else {
|
24342 | startGrabCanvas(event$$1);
|
24343 | }
|
24344 | }
|
24345 |
|
24346 | function startZoom(e) {
|
24347 |
|
24348 | var zoom = canvas.zoom(),
|
24349 | mid = e.center;
|
24350 |
|
24351 | function update(e) {
|
24352 |
|
24353 | var ratio = 1 - (1 - e.scale) / 1.50,
|
24354 | newZoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, ratio * zoom));
|
24355 |
|
24356 | canvas.zoom(newZoom, mid);
|
24357 |
|
24358 | stopEvent(e);
|
24359 | }
|
24360 |
|
24361 | function end(e) {
|
24362 | recognizer.off('pinchmove', update);
|
24363 | recognizer.off('pinchend', end);
|
24364 | recognizer.off('pinchcancel', end);
|
24365 |
|
24366 | recognizer.reset(true);
|
24367 | }
|
24368 |
|
24369 | recognizer.on('pinchmove', update);
|
24370 | recognizer.on('pinchend', end);
|
24371 | recognizer.on('pinchcancel', end);
|
24372 | }
|
24373 |
|
24374 | recognizer.on('panstart', startGrab);
|
24375 | recognizer.on('press', startGrab);
|
24376 |
|
24377 | recognizer.on('pinchstart', startZoom);
|
24378 | }
|
24379 |
|
24380 | if (dragging) {
|
24381 |
|
24382 |
|
24383 | eventBus.on('drag.move', function(event$$1) {
|
24384 |
|
24385 | var originalEvent = event$$1.originalEvent;
|
24386 |
|
24387 | if (!originalEvent || originalEvent instanceof MouseEvent) {
|
24388 | return;
|
24389 | }
|
24390 |
|
24391 | var position = toPoint(originalEvent);
|
24392 |
|
24393 |
|
24394 | var node = document.elementFromPoint(position.x, position.y),
|
24395 | gfx = getGfx(node),
|
24396 | element = gfx && elementRegistry.get(gfx);
|
24397 |
|
24398 | if (element !== event$$1.hover) {
|
24399 | if (event$$1.hover) {
|
24400 | dragging.out(event$$1);
|
24401 | }
|
24402 |
|
24403 | if (element) {
|
24404 | dragging.hover({ element: element, gfx: gfx });
|
24405 |
|
24406 | event$$1.hover = element;
|
24407 | event$$1.hoverGfx = gfx;
|
24408 | }
|
24409 | }
|
24410 | });
|
24411 | }
|
24412 |
|
24413 | if (contextPad) {
|
24414 |
|
24415 | eventBus.on('contextPad.create', function(event$$1) {
|
24416 | var node = event$$1.pad.html;
|
24417 |
|
24418 |
|
24419 | var padRecognizer = createTouchRecognizer(node);
|
24420 |
|
24421 | padRecognizer.on('panstart', function(event$$1) {
|
24422 | contextPad.trigger('dragstart', event$$1, true);
|
24423 | });
|
24424 |
|
24425 | padRecognizer.on('press', function(event$$1) {
|
24426 | contextPad.trigger('dragstart', event$$1, true);
|
24427 | });
|
24428 |
|
24429 | padRecognizer.on('tap', function(event$$1) {
|
24430 | contextPad.trigger('click', event$$1);
|
24431 | });
|
24432 | });
|
24433 | }
|
24434 |
|
24435 | if (palette) {
|
24436 | eventBus.on('palette.create', function(event$$1) {
|
24437 | var node = event$$1.container;
|
24438 |
|
24439 |
|
24440 | var padRecognizer = createTouchRecognizer(node);
|
24441 |
|
24442 | padRecognizer.on('panstart', function(event$$1) {
|
24443 | palette.trigger('dragstart', event$$1, true);
|
24444 | });
|
24445 |
|
24446 | padRecognizer.on('press', function(event$$1) {
|
24447 | palette.trigger('dragstart', event$$1, true);
|
24448 | });
|
24449 |
|
24450 | padRecognizer.on('tap', function(event$$1) {
|
24451 | palette.trigger('click', event$$1);
|
24452 | });
|
24453 | });
|
24454 | }
|
24455 |
|
24456 | eventBus.on('canvas.init', function(event$$1) {
|
24457 | initEvents(event$$1.svg);
|
24458 | });
|
24459 | }
|
24460 |
|
24461 |
|
24462 | TouchInteractionEvents.$inject = [
|
24463 | 'injector',
|
24464 | 'canvas',
|
24465 | 'eventBus',
|
24466 | 'elementRegistry',
|
24467 | 'interactionEvents',
|
24468 | 'touchFix'
|
24469 | ];
|
24470 |
|
24471 | function TouchFix(canvas, eventBus) {
|
24472 |
|
24473 | var self = this;
|
24474 |
|
24475 | eventBus.on('canvas.init', function(e) {
|
24476 | self.addBBoxMarker(e.svg);
|
24477 | });
|
24478 | }
|
24479 |
|
24480 | TouchFix.$inject = [ 'canvas', 'eventBus' ];
|
24481 |
|
24482 |
|
24483 | |
24484 |
|
24485 |
|
24486 |
|
24487 |
|
24488 |
|
24489 |
|
24490 | TouchFix.prototype.addBBoxMarker = function(svg) {
|
24491 |
|
24492 | var markerStyle = {
|
24493 | fill: 'none',
|
24494 | class: 'outer-bound-marker'
|
24495 | };
|
24496 |
|
24497 | var rect1 = create('rect');
|
24498 | attr$1(rect1, {
|
24499 | x: -10000,
|
24500 | y: 10000,
|
24501 | width: 10,
|
24502 | height: 10
|
24503 | });
|
24504 | attr$1(rect1, markerStyle);
|
24505 |
|
24506 | append(svg, rect1);
|
24507 |
|
24508 | var rect2 = create('rect');
|
24509 | attr$1(rect2, {
|
24510 | x: 10000,
|
24511 | y: 10000,
|
24512 | width: 10,
|
24513 | height: 10
|
24514 | });
|
24515 | attr$1(rect2, markerStyle);
|
24516 |
|
24517 | append(svg, rect2);
|
24518 | };
|
24519 |
|
24520 | var TouchModule = {
|
24521 | __depends__: [ InteractionEventsModule ],
|
24522 | __init__: [ 'touchInteractionEvents' ],
|
24523 | touchInteractionEvents: [ 'type', TouchInteractionEvents ],
|
24524 | touchFix: [ 'type', TouchFix ]
|
24525 | };
|
24526 |
|
24527 | var TouchModule$1 = {
|
24528 | __depends__: [
|
24529 | TouchModule
|
24530 | ]
|
24531 | };
|
24532 |
|
24533 | function last(arr) {
|
24534 | return arr && arr[arr.length - 1];
|
24535 | }
|
24536 |
|
24537 | function sortTopOrMiddle(element) {
|
24538 | return element.y;
|
24539 | }
|
24540 |
|
24541 | function sortLeftOrCenter(element) {
|
24542 | return element.x;
|
24543 | }
|
24544 |
|
24545 | |
24546 |
|
24547 |
|
24548 |
|
24549 |
|
24550 |
|
24551 |
|
24552 | var ALIGNMENT_SORTING = {
|
24553 | left: sortLeftOrCenter,
|
24554 | center: sortLeftOrCenter,
|
24555 | right: function(element) {
|
24556 | return element.x + element.width;
|
24557 | },
|
24558 | top: sortTopOrMiddle,
|
24559 | middle: sortTopOrMiddle,
|
24560 | bottom: function(element) {
|
24561 | return element.y + element.height;
|
24562 | }
|
24563 | };
|
24564 |
|
24565 |
|
24566 | function AlignElements(modeling) {
|
24567 | this._modeling = modeling;
|
24568 | }
|
24569 |
|
24570 | AlignElements.$inject = [ 'modeling' ];
|
24571 |
|
24572 |
|
24573 | |
24574 |
|
24575 |
|
24576 |
|
24577 |
|
24578 |
|
24579 |
|
24580 | AlignElements.prototype._getOrientationDetails = function(type) {
|
24581 | var vertical = [ 'top', 'bottom', 'middle' ],
|
24582 | axis = 'x',
|
24583 | dimension = 'width';
|
24584 |
|
24585 | if (vertical.indexOf(type) !== -1) {
|
24586 | axis = 'y';
|
24587 | dimension = 'height';
|
24588 | }
|
24589 |
|
24590 | return {
|
24591 | axis: axis,
|
24592 | dimension: dimension
|
24593 | };
|
24594 | };
|
24595 |
|
24596 | AlignElements.prototype._isType = function(type, types) {
|
24597 | return types.indexOf(type) !== -1;
|
24598 | };
|
24599 |
|
24600 | |
24601 |
|
24602 |
|
24603 |
|
24604 |
|
24605 |
|
24606 |
|
24607 |
|
24608 | AlignElements.prototype._alignmentPosition = function(type, sortedElements) {
|
24609 | var orientation = this._getOrientationDetails(type),
|
24610 | axis = orientation.axis,
|
24611 | dimension = orientation.dimension,
|
24612 | alignment = {},
|
24613 | centers = {},
|
24614 | hasSharedCenters = false,
|
24615 | centeredElements,
|
24616 | firstElement,
|
24617 | lastElement;
|
24618 |
|
24619 | function getMiddleOrTop(first, last) {
|
24620 | return Math.round((first[axis] + last[axis] + last[dimension]) / 2);
|
24621 | }
|
24622 |
|
24623 | if (this._isType(type, [ 'left', 'top' ])) {
|
24624 | alignment[type] = sortedElements[0][axis];
|
24625 |
|
24626 | } else if (this._isType(type, [ 'right', 'bottom' ])) {
|
24627 | lastElement = last(sortedElements);
|
24628 |
|
24629 | alignment[type] = lastElement[axis] + lastElement[dimension];
|
24630 |
|
24631 | } else if (this._isType(type, [ 'center', 'middle' ])) {
|
24632 |
|
24633 |
|
24634 |
|
24635 | forEach(sortedElements, function(element) {
|
24636 | var center = element[axis] + Math.round(element[dimension] / 2);
|
24637 |
|
24638 | if (centers[center]) {
|
24639 | centers[center].elements.push(element);
|
24640 | } else {
|
24641 | centers[center] = {
|
24642 | elements: [ element ],
|
24643 | center: center
|
24644 | };
|
24645 | }
|
24646 | });
|
24647 |
|
24648 | centeredElements = sortBy(centers, function(center) {
|
24649 | if (center.elements.length > 1) {
|
24650 | hasSharedCenters = true;
|
24651 | }
|
24652 |
|
24653 | return center.elements.length;
|
24654 | });
|
24655 |
|
24656 | if (hasSharedCenters) {
|
24657 | alignment[type] = last(centeredElements).center;
|
24658 |
|
24659 | return alignment;
|
24660 | }
|
24661 |
|
24662 | firstElement = sortedElements[0];
|
24663 |
|
24664 | sortedElements = sortBy(sortedElements, function(element) {
|
24665 | return element[axis] + element[dimension];
|
24666 | });
|
24667 |
|
24668 | lastElement = last(sortedElements);
|
24669 |
|
24670 | alignment[type] = getMiddleOrTop(firstElement, lastElement);
|
24671 | }
|
24672 |
|
24673 | return alignment;
|
24674 | };
|
24675 |
|
24676 | |
24677 |
|
24678 |
|
24679 |
|
24680 |
|
24681 |
|
24682 | AlignElements.prototype.trigger = function(elements, type) {
|
24683 | var modeling = this._modeling;
|
24684 |
|
24685 | var filteredElements = filter(elements, function(element) {
|
24686 | return !(element.waypoints || element.host || element.labelTarget);
|
24687 | });
|
24688 |
|
24689 | var sortFn = ALIGNMENT_SORTING[type];
|
24690 |
|
24691 | var sortedElements = sortBy(filteredElements, sortFn);
|
24692 |
|
24693 | var alignment = this._alignmentPosition(type, sortedElements);
|
24694 |
|
24695 | modeling.alignElements(sortedElements, alignment);
|
24696 | };
|
24697 |
|
24698 | var AlignElementsModule = {
|
24699 | __init__: [ 'alignElements' ],
|
24700 | alignElements: [ 'type', AlignElements ]
|
24701 | };
|
24702 |
|
24703 | |
24704 |
|
24705 |
|
24706 |
|
24707 |
|
24708 |
|
24709 |
|
24710 |
|
24711 | function isAny(element, types) {
|
24712 | return some(types, function(t) {
|
24713 | return is$1(element, t);
|
24714 | });
|
24715 | }
|
24716 |
|
24717 |
|
24718 | |
24719 |
|
24720 |
|
24721 |
|
24722 |
|
24723 |
|
24724 |
|
24725 |
|
24726 | function getParent(element, anyType) {
|
24727 |
|
24728 | if (typeof anyType === 'string') {
|
24729 | anyType = [ anyType ];
|
24730 | }
|
24731 |
|
24732 | while ((element = element.parent)) {
|
24733 | if (isAny(element, anyType)) {
|
24734 | return element;
|
24735 | }
|
24736 | }
|
24737 |
|
24738 | return null;
|
24739 | }
|
24740 |
|
24741 | var DEFAULT_HORIZONTAL_DISTANCE = 50;
|
24742 |
|
24743 | var MAX_HORIZONTAL_DISTANCE = 250;
|
24744 |
|
24745 |
|
24746 | var PLACEMENT_DETECTION_PAD = 10;
|
24747 |
|
24748 |
|
24749 | |
24750 |
|
24751 |
|
24752 |
|
24753 | function getFlowNodePosition(source, element) {
|
24754 |
|
24755 | var sourceTrbl = asTRBL(source);
|
24756 | var sourceMid = getMid(source);
|
24757 |
|
24758 | var horizontalDistance = getFlowNodeDistance(source, element);
|
24759 |
|
24760 | var orientation = 'left',
|
24761 | rowSize = 80,
|
24762 | margin = 30;
|
24763 |
|
24764 | if (is$1(source, 'bpmn:BoundaryEvent')) {
|
24765 | orientation = getOrientation(source, source.host, -25);
|
24766 |
|
24767 | if (orientation.indexOf('top') !== -1) {
|
24768 | margin *= -1;
|
24769 | }
|
24770 | }
|
24771 |
|
24772 | function getVerticalDistance(orient) {
|
24773 | if (orient.indexOf('top') != -1) {
|
24774 | return -1 * rowSize;
|
24775 | } else if (orient.indexOf('bottom') != -1) {
|
24776 | return rowSize;
|
24777 | } else {
|
24778 | return 0;
|
24779 | }
|
24780 | }
|
24781 |
|
24782 | var position = {
|
24783 | x: sourceTrbl.right + horizontalDistance + element.width / 2,
|
24784 | y: sourceMid.y + getVerticalDistance(orientation)
|
24785 | };
|
24786 |
|
24787 | var escapeDirection = {
|
24788 | y: {
|
24789 | margin: margin,
|
24790 | rowSize: rowSize
|
24791 | }
|
24792 | };
|
24793 |
|
24794 | return deconflictPosition(source, element, position, escapeDirection);
|
24795 | }
|
24796 |
|
24797 |
|
24798 | |
24799 |
|
24800 |
|
24801 |
|
24802 |
|
24803 |
|
24804 |
|
24805 |
|
24806 |
|
24807 | function getFlowNodeDistance(source, element) {
|
24808 |
|
24809 | var sourceTrbl = asTRBL(source);
|
24810 |
|
24811 |
|
24812 | function isReference(c) {
|
24813 | return is$1(c, 'bpmn:SequenceFlow');
|
24814 | }
|
24815 |
|
24816 | function toTargetNode(weight) {
|
24817 |
|
24818 | return function(shape) {
|
24819 | return {
|
24820 | shape: shape,
|
24821 | weight: weight,
|
24822 | distanceTo: function(shape) {
|
24823 | var shapeTrbl = asTRBL(shape);
|
24824 |
|
24825 | return shapeTrbl.left - sourceTrbl.right;
|
24826 | }
|
24827 | };
|
24828 | };
|
24829 | }
|
24830 |
|
24831 | function toSourceNode(weight) {
|
24832 | return function(shape) {
|
24833 | return {
|
24834 | shape: shape,
|
24835 | weight: weight,
|
24836 | distanceTo: function(shape) {
|
24837 | var shapeTrbl = asTRBL(shape);
|
24838 |
|
24839 | return sourceTrbl.left - shapeTrbl.right;
|
24840 | }
|
24841 | };
|
24842 | };
|
24843 | }
|
24844 |
|
24845 |
|
24846 |
|
24847 |
|
24848 |
|
24849 |
|
24850 |
|
24851 | var nodes = reduce([].concat(
|
24852 | getTargets(source, isReference).map(toTargetNode(5)),
|
24853 | getSources(source, isReference).map(toSourceNode(1))
|
24854 | ), function(nodes, node) {
|
24855 |
|
24856 | nodes[node.shape.id + '__weight_' + node.weight] = node;
|
24857 |
|
24858 | return nodes;
|
24859 | }, {});
|
24860 |
|
24861 |
|
24862 |
|
24863 |
|
24864 | var distancesGrouped = reduce(nodes, function(result, node) {
|
24865 |
|
24866 | var shape = node.shape,
|
24867 | weight = node.weight,
|
24868 | distanceTo = node.distanceTo;
|
24869 |
|
24870 | var fav = result.fav,
|
24871 | currentDistance,
|
24872 | currentDistanceCount,
|
24873 | currentDistanceEntry;
|
24874 |
|
24875 | currentDistance = distanceTo(shape);
|
24876 |
|
24877 |
|
24878 |
|
24879 | if (currentDistance < 0 || currentDistance > MAX_HORIZONTAL_DISTANCE) {
|
24880 | return result;
|
24881 | }
|
24882 |
|
24883 | currentDistanceEntry = result[String(currentDistance)] =
|
24884 | result[String(currentDistance)] || {
|
24885 | value: currentDistance,
|
24886 | count: 0
|
24887 | };
|
24888 |
|
24889 |
|
24890 | currentDistanceCount = currentDistanceEntry.count += 1 * weight;
|
24891 |
|
24892 | if (!fav || fav.count < currentDistanceCount) {
|
24893 | result.fav = currentDistanceEntry;
|
24894 | }
|
24895 |
|
24896 | return result;
|
24897 | }, { });
|
24898 |
|
24899 |
|
24900 | if (distancesGrouped.fav) {
|
24901 | return distancesGrouped.fav.value;
|
24902 | } else {
|
24903 | return DEFAULT_HORIZONTAL_DISTANCE;
|
24904 | }
|
24905 | }
|
24906 |
|
24907 |
|
24908 | |
24909 |
|
24910 |
|
24911 | function getTextAnnotationPosition(source, element) {
|
24912 |
|
24913 | var sourceTrbl = asTRBL(source);
|
24914 |
|
24915 | var position = {
|
24916 | x: sourceTrbl.right + element.width / 2,
|
24917 | y: sourceTrbl.top - 50 - element.height / 2
|
24918 | };
|
24919 |
|
24920 | var escapeDirection = {
|
24921 | y: {
|
24922 | margin: -30,
|
24923 | rowSize: 20
|
24924 | }
|
24925 | };
|
24926 |
|
24927 | return deconflictPosition(source, element, position, escapeDirection);
|
24928 | }
|
24929 |
|
24930 |
|
24931 | |
24932 |
|
24933 |
|
24934 | function getDataElementPosition(source, element) {
|
24935 |
|
24936 | var sourceTrbl = asTRBL(source);
|
24937 |
|
24938 | var position = {
|
24939 | x: sourceTrbl.right - 10 + element.width / 2,
|
24940 | y: sourceTrbl.bottom + 40 + element.width / 2
|
24941 | };
|
24942 |
|
24943 | var escapeDirection = {
|
24944 | x: {
|
24945 | margin: 30,
|
24946 | rowSize: 30
|
24947 | }
|
24948 | };
|
24949 |
|
24950 | return deconflictPosition(source, element, position, escapeDirection);
|
24951 | }
|
24952 |
|
24953 |
|
24954 | |
24955 |
|
24956 |
|
24957 | function getDefaultPosition(source, element) {
|
24958 |
|
24959 | var sourceTrbl = asTRBL(source);
|
24960 |
|
24961 | var sourceMid = getMid(source);
|
24962 |
|
24963 |
|
24964 | return {
|
24965 | x: sourceTrbl.right + DEFAULT_HORIZONTAL_DISTANCE + element.width / 2,
|
24966 | y: sourceMid.y
|
24967 | };
|
24968 | }
|
24969 |
|
24970 |
|
24971 | |
24972 |
|
24973 |
|
24974 |
|
24975 |
|
24976 |
|
24977 |
|
24978 |
|
24979 |
|
24980 |
|
24981 |
|
24982 |
|
24983 |
|
24984 |
|
24985 | function getAutoPlaceClosure(source, element) {
|
24986 |
|
24987 | var allConnected = getConnected(source);
|
24988 |
|
24989 | if (source.host) {
|
24990 | allConnected = allConnected.concat(getConnected(source.host));
|
24991 | }
|
24992 |
|
24993 | if (source.attachers) {
|
24994 | allConnected = allConnected.concat(source.attachers.reduce(function(shapes, attacher) {
|
24995 | return shapes.concat(getConnected(attacher));
|
24996 | }, []));
|
24997 | }
|
24998 |
|
24999 | return allConnected;
|
25000 | }
|
25001 |
|
25002 | |
25003 |
|
25004 |
|
25005 |
|
25006 |
|
25007 |
|
25008 | function getConnectedAtPosition(source, position, element) {
|
25009 |
|
25010 | var bounds = {
|
25011 | x: position.x - (element.width / 2),
|
25012 | y: position.y - (element.height / 2),
|
25013 | width: element.width,
|
25014 | height: element.height
|
25015 | };
|
25016 |
|
25017 | var closure = getAutoPlaceClosure(source, element);
|
25018 |
|
25019 | return find(closure, function(target) {
|
25020 |
|
25021 | if (target === element) {
|
25022 | return false;
|
25023 | }
|
25024 |
|
25025 | var orientation = getOrientation(target, bounds, PLACEMENT_DETECTION_PAD);
|
25026 |
|
25027 | return orientation === 'intersect';
|
25028 | });
|
25029 | }
|
25030 |
|
25031 |
|
25032 | |
25033 |
|
25034 |
|
25035 |
|
25036 |
|
25037 |
|
25038 |
|
25039 |
|
25040 |
|
25041 |
|
25042 |
|
25043 |
|
25044 |
|
25045 |
|
25046 |
|
25047 | function deconflictPosition(source, element, position, escapeDelta) {
|
25048 |
|
25049 | function nextPosition(existingElement) {
|
25050 |
|
25051 | var newPosition = {
|
25052 | x: position.x,
|
25053 | y: position.y
|
25054 | };
|
25055 |
|
25056 | [ 'x', 'y' ].forEach(function(axis) {
|
25057 |
|
25058 | var axisDelta = escapeDelta[axis];
|
25059 |
|
25060 | if (!axisDelta) {
|
25061 | return;
|
25062 | }
|
25063 |
|
25064 | var dimension = axis === 'x' ? 'width' : 'height';
|
25065 |
|
25066 | var margin = axisDelta.margin,
|
25067 | rowSize = axisDelta.rowSize;
|
25068 |
|
25069 | if (margin < 0) {
|
25070 | newPosition[axis] = Math.min(
|
25071 | existingElement[axis] + margin - element[dimension] / 2,
|
25072 | position[axis] - rowSize + margin
|
25073 | );
|
25074 | } else {
|
25075 | newPosition[axis] = Math.max(
|
25076 | existingTarget[axis] + existingTarget[dimension] + margin + element[dimension] / 2,
|
25077 | position[axis] + rowSize + margin
|
25078 | );
|
25079 | }
|
25080 | });
|
25081 |
|
25082 | return newPosition;
|
25083 | }
|
25084 |
|
25085 | var existingTarget;
|
25086 |
|
25087 |
|
25088 | while ((existingTarget = getConnectedAtPosition(source, position, element))) {
|
25089 | position = nextPosition(existingTarget);
|
25090 | }
|
25091 |
|
25092 | return position;
|
25093 | }
|
25094 |
|
25095 |
|
25096 |
|
25097 |
|
25098 |
|
25099 | function noneFilter() {
|
25100 | return true;
|
25101 | }
|
25102 |
|
25103 | function getConnected(element, connectionFilter) {
|
25104 | return [].concat(
|
25105 | getTargets(element, connectionFilter),
|
25106 | getSources(element, connectionFilter)
|
25107 | );
|
25108 | }
|
25109 |
|
25110 | function getSources(shape, connectionFilter) {
|
25111 |
|
25112 | if (!connectionFilter) {
|
25113 | connectionFilter = noneFilter;
|
25114 | }
|
25115 |
|
25116 | return shape.incoming.filter(connectionFilter).map(function(c) {
|
25117 | return c.source;
|
25118 | });
|
25119 | }
|
25120 |
|
25121 | function getTargets(shape, connectionFilter) {
|
25122 |
|
25123 | if (!connectionFilter) {
|
25124 | connectionFilter = noneFilter;
|
25125 | }
|
25126 |
|
25127 | return shape.outgoing.filter(connectionFilter).map(function(c) {
|
25128 | return c.target;
|
25129 | });
|
25130 | }
|
25131 |
|
25132 | |
25133 |
|
25134 |
|
25135 |
|
25136 |
|
25137 |
|
25138 |
|
25139 | function AutoPlace(eventBus, modeling) {
|
25140 |
|
25141 | function emit(event, payload) {
|
25142 | return eventBus.fire(event, payload);
|
25143 | }
|
25144 |
|
25145 |
|
25146 | |
25147 |
|
25148 |
|
25149 |
|
25150 |
|
25151 |
|
25152 |
|
25153 |
|
25154 | this.append = function(source, shape) {
|
25155 |
|
25156 |
|
25157 | var position = emit('autoPlace', {
|
25158 | source: source,
|
25159 | shape: shape
|
25160 | });
|
25161 |
|
25162 | if (!position) {
|
25163 | position = getNewShapePosition(source, shape);
|
25164 | }
|
25165 |
|
25166 | var newShape = modeling.appendShape(source, shape, position, source.parent);
|
25167 |
|
25168 |
|
25169 | emit('autoPlace.end', {
|
25170 | shape: newShape
|
25171 | });
|
25172 |
|
25173 | return newShape;
|
25174 | };
|
25175 |
|
25176 | }
|
25177 |
|
25178 | AutoPlace.$inject = [
|
25179 | 'eventBus',
|
25180 | 'modeling'
|
25181 | ];
|
25182 |
|
25183 |
|
25184 |
|
25185 |
|
25186 | |
25187 |
|
25188 |
|
25189 |
|
25190 |
|
25191 |
|
25192 |
|
25193 |
|
25194 |
|
25195 | function getNewShapePosition(source, element) {
|
25196 |
|
25197 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
25198 | return getTextAnnotationPosition(source, element);
|
25199 | }
|
25200 |
|
25201 | if (isAny(element, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
25202 | return getDataElementPosition(source, element);
|
25203 | }
|
25204 |
|
25205 | if (is$1(element, 'bpmn:FlowNode')) {
|
25206 | return getFlowNodePosition(source, element);
|
25207 | }
|
25208 |
|
25209 | return getDefaultPosition(source, element);
|
25210 | }
|
25211 |
|
25212 | |
25213 |
|
25214 |
|
25215 |
|
25216 |
|
25217 |
|
25218 | function AutoPlaceSelectionBehavior(eventBus, selection) {
|
25219 |
|
25220 | eventBus.on('autoPlace.end', 500, function(e) {
|
25221 | selection.select(e.shape);
|
25222 | });
|
25223 |
|
25224 | }
|
25225 |
|
25226 | AutoPlaceSelectionBehavior.$inject = [
|
25227 | 'eventBus',
|
25228 | 'selection'
|
25229 | ];
|
25230 |
|
25231 | var AutoPlaceModule = {
|
25232 | __init__: [ 'autoPlaceSelectionBehavior' ],
|
25233 | autoPlace: [ 'type', AutoPlace ],
|
25234 | autoPlaceSelectionBehavior: [ 'type', AutoPlaceSelectionBehavior ]
|
25235 | };
|
25236 |
|
25237 | var DEFAULT_PRIORITY$2 = 1000;
|
25238 |
|
25239 | |
25240 |
|
25241 |
|
25242 |
|
25243 |
|
25244 |
|
25245 |
|
25246 |
|
25247 |
|
25248 |
|
25249 |
|
25250 |
|
25251 |
|
25252 |
|
25253 |
|
25254 |
|
25255 |
|
25256 |
|
25257 |
|
25258 |
|
25259 |
|
25260 |
|
25261 |
|
25262 | function CommandInterceptor(eventBus) {
|
25263 | this._eventBus = eventBus;
|
25264 | }
|
25265 |
|
25266 | CommandInterceptor.$inject = [ 'eventBus' ];
|
25267 |
|
25268 | function unwrapEvent(fn, that) {
|
25269 | return function(event) {
|
25270 | return fn.call(that || null, event.context, event.command, event);
|
25271 | };
|
25272 | }
|
25273 |
|
25274 | |
25275 |
|
25276 |
|
25277 |
|
25278 |
|
25279 |
|
25280 |
|
25281 |
|
25282 |
|
25283 |
|
25284 |
|
25285 | CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
|
25286 |
|
25287 | if (isFunction(hook) || isNumber(hook)) {
|
25288 | that = unwrap;
|
25289 | unwrap = handlerFn;
|
25290 | handlerFn = priority;
|
25291 | priority = hook;
|
25292 | hook = null;
|
25293 | }
|
25294 |
|
25295 | if (isFunction(priority)) {
|
25296 | that = unwrap;
|
25297 | unwrap = handlerFn;
|
25298 | handlerFn = priority;
|
25299 | priority = DEFAULT_PRIORITY$2;
|
25300 | }
|
25301 |
|
25302 | if (isObject(unwrap)) {
|
25303 | that = unwrap;
|
25304 | unwrap = false;
|
25305 | }
|
25306 |
|
25307 | if (!isFunction(handlerFn)) {
|
25308 | throw new Error('handlerFn must be a function');
|
25309 | }
|
25310 |
|
25311 | if (!isArray(events)) {
|
25312 | events = [ events ];
|
25313 | }
|
25314 |
|
25315 | var eventBus = this._eventBus;
|
25316 |
|
25317 | forEach(events, function(event) {
|
25318 |
|
25319 | var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
|
25320 |
|
25321 | eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
|
25322 | });
|
25323 | };
|
25324 |
|
25325 |
|
25326 | var hooks = [
|
25327 | 'canExecute',
|
25328 | 'preExecute',
|
25329 | 'preExecuted',
|
25330 | 'execute',
|
25331 | 'executed',
|
25332 | 'postExecute',
|
25333 | 'postExecuted',
|
25334 | 'revert',
|
25335 | 'reverted'
|
25336 | ];
|
25337 |
|
25338 | |
25339 |
|
25340 |
|
25341 |
|
25342 |
|
25343 |
|
25344 | forEach(hooks, function(hook) {
|
25345 |
|
25346 | |
25347 |
|
25348 |
|
25349 |
|
25350 |
|
25351 |
|
25352 |
|
25353 |
|
25354 |
|
25355 |
|
25356 |
|
25357 |
|
25358 | CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
|
25359 |
|
25360 | if (isFunction(events) || isNumber(events)) {
|
25361 | that = unwrap;
|
25362 | unwrap = handlerFn;
|
25363 | handlerFn = priority;
|
25364 | priority = events;
|
25365 | events = null;
|
25366 | }
|
25367 |
|
25368 | this.on(events, hook, priority, handlerFn, unwrap, that);
|
25369 | };
|
25370 | });
|
25371 |
|
25372 | |
25373 |
|
25374 |
|
25375 |
|
25376 |
|
25377 |
|
25378 |
|
25379 |
|
25380 |
|
25381 | function AutoResize(eventBus, elementRegistry, modeling, rules) {
|
25382 |
|
25383 | CommandInterceptor.call(this, eventBus);
|
25384 |
|
25385 | this._elementRegistry = elementRegistry;
|
25386 | this._modeling = modeling;
|
25387 | this._rules = rules;
|
25388 |
|
25389 | var self = this;
|
25390 |
|
25391 | this.postExecuted([ 'shape.create' ], function(event) {
|
25392 | var context = event.context,
|
25393 | hints = context.hints,
|
25394 | shape = context.shape,
|
25395 | parent = context.parent || context.newParent;
|
25396 |
|
25397 | if (hints && (hints.root === false || hints.autoResize === false)) {
|
25398 | return;
|
25399 | }
|
25400 |
|
25401 | self._expand([ shape ], parent);
|
25402 | });
|
25403 |
|
25404 | this.postExecuted([ 'elements.move' ], function(event) {
|
25405 | var context = event.context,
|
25406 | elements = flatten(values(context.closure.topLevel)),
|
25407 | hints = context.hints;
|
25408 |
|
25409 | var autoResize = hints ? hints.autoResize : true;
|
25410 |
|
25411 | if (autoResize === false) {
|
25412 | return;
|
25413 | }
|
25414 |
|
25415 | var expandings = groupBy(elements, function(element) {
|
25416 | return element.parent.id;
|
25417 | });
|
25418 |
|
25419 | forEach(expandings, function(elements, parentId) {
|
25420 |
|
25421 |
|
25422 | if (isArray(autoResize)) {
|
25423 | elements = elements.filter(function(element) {
|
25424 | return autoResize.indexOf(element) !== -1;
|
25425 | });
|
25426 | }
|
25427 |
|
25428 | self._expand(elements, parentId);
|
25429 | });
|
25430 | });
|
25431 |
|
25432 | this.postExecuted([ 'shape.toggleCollapse' ], function(event) {
|
25433 | var context = event.context,
|
25434 | hints = context.hints,
|
25435 | shape = context.shape;
|
25436 |
|
25437 | if (hints && (hints.root === false || hints.autoResize === false)) {
|
25438 | return;
|
25439 | }
|
25440 |
|
25441 | if (shape.collapsed) {
|
25442 | return;
|
25443 | }
|
25444 |
|
25445 | self._expand(shape.children || [], shape);
|
25446 | });
|
25447 |
|
25448 | this.postExecuted([ 'shape.resize' ], function(event) {
|
25449 | var context = event.context,
|
25450 | hints = context.hints,
|
25451 | shape = context.shape,
|
25452 | parent = shape.parent;
|
25453 |
|
25454 | if (hints && (hints.root === false || hints.autoResize === false)) {
|
25455 | return;
|
25456 | }
|
25457 |
|
25458 | if (parent) {
|
25459 | self._expand([ shape ], parent);
|
25460 | }
|
25461 | });
|
25462 |
|
25463 | }
|
25464 |
|
25465 | AutoResize.$inject = [
|
25466 | 'eventBus',
|
25467 | 'elementRegistry',
|
25468 | 'modeling',
|
25469 | 'rules'
|
25470 | ];
|
25471 |
|
25472 | inherits_browser(AutoResize, CommandInterceptor);
|
25473 |
|
25474 |
|
25475 | |
25476 |
|
25477 |
|
25478 |
|
25479 |
|
25480 |
|
25481 |
|
25482 |
|
25483 |
|
25484 |
|
25485 | AutoResize.prototype._getOptimalBounds = function(elements, target) {
|
25486 |
|
25487 | var offset = this.getOffset(target),
|
25488 | padding = this.getPadding(target);
|
25489 |
|
25490 | var elementsTrbl = asTRBL(getBBox(elements)),
|
25491 | targetTrbl = asTRBL(target);
|
25492 |
|
25493 | var newTrbl = {};
|
25494 |
|
25495 | if (elementsTrbl.top - targetTrbl.top < padding.top) {
|
25496 | newTrbl.top = elementsTrbl.top - offset.top;
|
25497 | }
|
25498 |
|
25499 | if (elementsTrbl.left - targetTrbl.left < padding.left) {
|
25500 | newTrbl.left = elementsTrbl.left - offset.left;
|
25501 | }
|
25502 |
|
25503 | if (targetTrbl.right - elementsTrbl.right < padding.right) {
|
25504 | newTrbl.right = elementsTrbl.right + offset.right;
|
25505 | }
|
25506 |
|
25507 | if (targetTrbl.bottom - elementsTrbl.bottom < padding.bottom) {
|
25508 | newTrbl.bottom = elementsTrbl.bottom + offset.bottom;
|
25509 | }
|
25510 |
|
25511 | return asBounds(assign({}, targetTrbl, newTrbl));
|
25512 | };
|
25513 |
|
25514 |
|
25515 | |
25516 |
|
25517 |
|
25518 |
|
25519 |
|
25520 |
|
25521 | AutoResize.prototype._expand = function(elements, target) {
|
25522 |
|
25523 | if (typeof target === 'string') {
|
25524 | target = this._elementRegistry.get(target);
|
25525 | }
|
25526 |
|
25527 | var allowed = this._rules.allowed('element.autoResize', {
|
25528 | elements: elements,
|
25529 | target: target
|
25530 | });
|
25531 |
|
25532 | if (!allowed) {
|
25533 | return;
|
25534 | }
|
25535 |
|
25536 |
|
25537 | var newBounds = this._getOptimalBounds(elements, target);
|
25538 |
|
25539 | if (!boundsChanged(newBounds, target)) {
|
25540 | return;
|
25541 | }
|
25542 |
|
25543 |
|
25544 | this.resize(target, newBounds);
|
25545 |
|
25546 | var parent = target.parent;
|
25547 |
|
25548 |
|
25549 | if (parent) {
|
25550 | this._expand([ target ], parent);
|
25551 | }
|
25552 | };
|
25553 |
|
25554 |
|
25555 | |
25556 |
|
25557 |
|
25558 |
|
25559 |
|
25560 |
|
25561 |
|
25562 | AutoResize.prototype.getOffset = function(shape) {
|
25563 | return { top: 60, bottom: 60, left: 100, right: 100 };
|
25564 | };
|
25565 |
|
25566 |
|
25567 | |
25568 |
|
25569 |
|
25570 |
|
25571 |
|
25572 |
|
25573 |
|
25574 |
|
25575 | AutoResize.prototype.getPadding = function(shape) {
|
25576 | return { top: 2, bottom: 2, left: 15, right: 15 };
|
25577 | };
|
25578 |
|
25579 |
|
25580 | |
25581 |
|
25582 |
|
25583 |
|
25584 |
|
25585 |
|
25586 | AutoResize.prototype.resize = function(target, newBounds) {
|
25587 | this._modeling.resizeShape(target, newBounds);
|
25588 | };
|
25589 |
|
25590 |
|
25591 | function boundsChanged(newBounds, oldBounds) {
|
25592 | return (
|
25593 | newBounds.x !== oldBounds.x ||
|
25594 | newBounds.y !== oldBounds.y ||
|
25595 | newBounds.width !== oldBounds.width ||
|
25596 | newBounds.height !== oldBounds.height
|
25597 | );
|
25598 | }
|
25599 |
|
25600 | |
25601 |
|
25602 |
|
25603 |
|
25604 | function BpmnAutoResize(injector) {
|
25605 |
|
25606 | injector.invoke(AutoResize, this);
|
25607 | }
|
25608 |
|
25609 | BpmnAutoResize.$inject = [
|
25610 | 'injector'
|
25611 | ];
|
25612 |
|
25613 | inherits_browser(BpmnAutoResize, AutoResize);
|
25614 |
|
25615 |
|
25616 | |
25617 |
|
25618 |
|
25619 |
|
25620 |
|
25621 |
|
25622 | BpmnAutoResize.prototype.resize = function(target, newBounds) {
|
25623 |
|
25624 | if (is$1(target, 'bpmn:Participant')) {
|
25625 | this._modeling.resizeLane(target, newBounds);
|
25626 | } else {
|
25627 | this._modeling.resizeShape(target, newBounds);
|
25628 | }
|
25629 | };
|
25630 |
|
25631 | |
25632 |
|
25633 |
|
25634 |
|
25635 |
|
25636 |
|
25637 |
|
25638 |
|
25639 | function RuleProvider(eventBus) {
|
25640 | CommandInterceptor.call(this, eventBus);
|
25641 |
|
25642 | this.init();
|
25643 | }
|
25644 |
|
25645 | RuleProvider.$inject = [ 'eventBus' ];
|
25646 |
|
25647 | inherits_browser(RuleProvider, CommandInterceptor);
|
25648 |
|
25649 |
|
25650 | |
25651 |
|
25652 |
|
25653 |
|
25654 |
|
25655 |
|
25656 |
|
25657 |
|
25658 |
|
25659 |
|
25660 |
|
25661 |
|
25662 |
|
25663 |
|
25664 |
|
25665 |
|
25666 |
|
25667 |
|
25668 |
|
25669 |
|
25670 |
|
25671 |
|
25672 |
|
25673 |
|
25674 |
|
25675 |
|
25676 |
|
25677 |
|
25678 |
|
25679 |
|
25680 |
|
25681 |
|
25682 |
|
25683 |
|
25684 |
|
25685 |
|
25686 |
|
25687 |
|
25688 |
|
25689 |
|
25690 |
|
25691 |
|
25692 |
|
25693 |
|
25694 | RuleProvider.prototype.addRule = function(actions, priority, fn) {
|
25695 |
|
25696 | var self = this;
|
25697 |
|
25698 | if (typeof actions === 'string') {
|
25699 | actions = [ actions ];
|
25700 | }
|
25701 |
|
25702 | actions.forEach(function(action) {
|
25703 |
|
25704 | self.canExecute(action, priority, function(context, action, event) {
|
25705 | return fn(context);
|
25706 | }, true);
|
25707 | });
|
25708 | };
|
25709 |
|
25710 | |
25711 |
|
25712 |
|
25713 | RuleProvider.prototype.init = function() {};
|
25714 |
|
25715 | |
25716 |
|
25717 |
|
25718 | function AutoResizeProvider(eventBus) {
|
25719 |
|
25720 | RuleProvider.call(this, eventBus);
|
25721 |
|
25722 | var self = this;
|
25723 |
|
25724 | this.addRule('element.autoResize', function(context) {
|
25725 | return self.canResize(context.elements, context.target);
|
25726 | });
|
25727 | }
|
25728 |
|
25729 | AutoResizeProvider.$inject = [ 'eventBus' ];
|
25730 |
|
25731 | inherits_browser(AutoResizeProvider, RuleProvider);
|
25732 |
|
25733 | |
25734 |
|
25735 |
|
25736 |
|
25737 |
|
25738 |
|
25739 |
|
25740 |
|
25741 | AutoResizeProvider.prototype.canResize = function(elements, target) {
|
25742 | return false;
|
25743 | };
|
25744 |
|
25745 | |
25746 |
|
25747 |
|
25748 | function BpmnAutoResizeProvider(eventBus, modeling) {
|
25749 | AutoResizeProvider.call(this, eventBus);
|
25750 |
|
25751 | this._modeling = modeling;
|
25752 | }
|
25753 |
|
25754 | inherits_browser(BpmnAutoResizeProvider, AutoResizeProvider);
|
25755 |
|
25756 | BpmnAutoResizeProvider.$inject = [
|
25757 | 'eventBus',
|
25758 | 'modeling'
|
25759 | ];
|
25760 |
|
25761 |
|
25762 | |
25763 |
|
25764 |
|
25765 |
|
25766 |
|
25767 |
|
25768 |
|
25769 | BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
|
25770 |
|
25771 | if (!is$1(target, 'bpmn:Participant') && !is$1(target, 'bpmn:Lane') && !(is$1(target, 'bpmn:SubProcess'))) {
|
25772 | return false;
|
25773 | }
|
25774 |
|
25775 | var canResize = true;
|
25776 |
|
25777 | forEach(elements, function(element) {
|
25778 |
|
25779 | if (is$1(element, 'bpmn:Lane') || element.labelTarget) {
|
25780 | canResize = false;
|
25781 | return;
|
25782 | }
|
25783 | });
|
25784 |
|
25785 | return canResize;
|
25786 | };
|
25787 |
|
25788 | var AutoResizeModule = {
|
25789 | __init__: [
|
25790 | 'bpmnAutoResize',
|
25791 | 'bpmnAutoResizeProvider'
|
25792 | ],
|
25793 | bpmnAutoResize: [ 'type', BpmnAutoResize ],
|
25794 | bpmnAutoResizeProvider: [ 'type', BpmnAutoResizeProvider ]
|
25795 | };
|
25796 |
|
25797 |
|
25798 |
|
25799 | var round$1 = Math.round;
|
25800 |
|
25801 | var DRAG_ACTIVE_CLS = 'djs-drag-active';
|
25802 |
|
25803 |
|
25804 | function preventDefault(event$$1) {
|
25805 | event$$1.preventDefault();
|
25806 | }
|
25807 |
|
25808 | function isTouchEvent(event$$1) {
|
25809 |
|
25810 |
|
25811 | return typeof TouchEvent !== 'undefined' && event$$1 instanceof TouchEvent;
|
25812 | }
|
25813 |
|
25814 | function getLength(point) {
|
25815 | return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
|
25816 | }
|
25817 |
|
25818 | |
25819 |
|
25820 |
|
25821 |
|
25822 |
|
25823 |
|
25824 |
|
25825 |
|
25826 |
|
25827 |
|
25828 |
|
25829 |
|
25830 |
|
25831 |
|
25832 |
|
25833 |
|
25834 |
|
25835 |
|
25836 |
|
25837 |
|
25838 |
|
25839 |
|
25840 |
|
25841 |
|
25842 |
|
25843 |
|
25844 |
|
25845 |
|
25846 |
|
25847 |
|
25848 |
|
25849 |
|
25850 |
|
25851 |
|
25852 |
|
25853 |
|
25854 |
|
25855 |
|
25856 |
|
25857 |
|
25858 |
|
25859 |
|
25860 |
|
25861 |
|
25862 |
|
25863 |
|
25864 |
|
25865 |
|
25866 |
|
25867 |
|
25868 |
|
25869 |
|
25870 |
|
25871 |
|
25872 |
|
25873 |
|
25874 |
|
25875 |
|
25876 |
|
25877 |
|
25878 |
|
25879 |
|
25880 |
|
25881 |
|
25882 |
|
25883 |
|
25884 |
|
25885 |
|
25886 |
|
25887 |
|
25888 |
|
25889 |
|
25890 |
|
25891 |
|
25892 |
|
25893 |
|
25894 |
|
25895 |
|
25896 | function Dragging(eventBus, canvas, selection) {
|
25897 |
|
25898 | var defaultOptions = {
|
25899 | threshold: 5,
|
25900 | trapClick: true
|
25901 | };
|
25902 |
|
25903 |
|
25904 |
|
25905 |
|
25906 |
|
25907 | var context;
|
25908 |
|
25909 |
|
25910 | function toLocalPoint(globalPosition) {
|
25911 |
|
25912 | var viewbox = canvas.viewbox();
|
25913 |
|
25914 | var clientRect = canvas._container.getBoundingClientRect();
|
25915 |
|
25916 | return {
|
25917 | x: viewbox.x + (globalPosition.x - clientRect.left) / viewbox.scale,
|
25918 | y: viewbox.y + (globalPosition.y - clientRect.top) / viewbox.scale
|
25919 | };
|
25920 | }
|
25921 |
|
25922 |
|
25923 |
|
25924 | function fire(type, dragContext) {
|
25925 | dragContext = dragContext || context;
|
25926 |
|
25927 | var event$$1 = eventBus.createEvent(
|
25928 | assign(
|
25929 | {},
|
25930 | dragContext.payload,
|
25931 | dragContext.data,
|
25932 | { isTouch: dragContext.isTouch }
|
25933 | )
|
25934 | );
|
25935 |
|
25936 |
|
25937 | if (eventBus.fire('drag.' + type, event$$1) === false) {
|
25938 | return false;
|
25939 | }
|
25940 |
|
25941 | return eventBus.fire(dragContext.prefix + '.' + type, event$$1);
|
25942 | }
|
25943 |
|
25944 |
|
25945 |
|
25946 | function move(event$$1, activate) {
|
25947 | var payload = context.payload,
|
25948 | displacement = context.displacement;
|
25949 |
|
25950 | var globalStart = context.globalStart,
|
25951 | globalCurrent = toPoint(event$$1),
|
25952 | globalDelta = delta(globalCurrent, globalStart);
|
25953 |
|
25954 | var localStart = context.localStart,
|
25955 | localCurrent = toLocalPoint(globalCurrent),
|
25956 | localDelta = delta(localCurrent, localStart);
|
25957 |
|
25958 |
|
25959 |
|
25960 | if (!context.active && (activate || getLength(globalDelta) > context.threshold)) {
|
25961 |
|
25962 |
|
25963 |
|
25964 |
|
25965 | assign(payload, {
|
25966 | x: round$1(localStart.x + displacement.x),
|
25967 | y: round$1(localStart.y + displacement.y),
|
25968 | dx: 0,
|
25969 | dy: 0
|
25970 | }, { originalEvent: event$$1 });
|
25971 |
|
25972 | if (false === fire('start')) {
|
25973 | return cancel();
|
25974 | }
|
25975 |
|
25976 | context.active = true;
|
25977 |
|
25978 |
|
25979 |
|
25980 |
|
25981 | if (!context.keepSelection) {
|
25982 | payload.previousSelection = selection.get();
|
25983 | selection.select(null);
|
25984 | }
|
25985 |
|
25986 |
|
25987 | if (context.cursor) {
|
25988 | set$1(context.cursor);
|
25989 | }
|
25990 |
|
25991 | // indicate dragging via marker on root element
|
25992 | canvas.addMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
25993 | }
|
25994 |
|
25995 | stopPropagation(event$$1);
|
25996 |
|
25997 | if (context.active) {
|
25998 |
|
25999 |
|
26000 | assign(payload, {
|
26001 | x: round$1(localCurrent.x + displacement.x),
|
26002 | y: round$1(localCurrent.y + displacement.y),
|
26003 | dx: round$1(localDelta.x),
|
26004 | dy: round$1(localDelta.y)
|
26005 | }, { originalEvent: event$$1 });
|
26006 |
|
26007 |
|
26008 | fire('move');
|
26009 | }
|
26010 | }
|
26011 |
|
26012 | function end(event$$1) {
|
26013 | var previousContext,
|
26014 | returnValue = true;
|
26015 |
|
26016 | if (context.active) {
|
26017 |
|
26018 | if (event$$1) {
|
26019 | context.payload.originalEvent = event$$1;
|
26020 |
|
26021 |
|
26022 |
|
26023 | stopPropagation(event$$1);
|
26024 | }
|
26025 |
|
26026 |
|
26027 |
|
26028 |
|
26029 | returnValue = fire('end');
|
26030 | }
|
26031 |
|
26032 | if (returnValue === false) {
|
26033 | fire('rejected');
|
26034 | }
|
26035 |
|
26036 | previousContext = cleanup(returnValue !== true);
|
26037 |
|
26038 |
|
26039 |
|
26040 | fire('ended', previousContext);
|
26041 | }
|
26042 |
|
26043 |
|
26044 |
|
26045 |
|
26046 |
|
26047 | function checkCancel(event$$1) {
|
26048 |
|
26049 | if (event$$1.which === 27) {
|
26050 | preventDefault(event$$1);
|
26051 |
|
26052 | cancel();
|
26053 | }
|
26054 | }
|
26055 |
|
26056 |
|
26057 |
|
26058 |
|
26059 |
|
26060 | function trapClickAndEnd(event$$1) {
|
26061 |
|
26062 | var untrap;
|
26063 |
|
26064 |
|
26065 |
|
26066 |
|
26067 | if (context.active) {
|
26068 |
|
26069 | untrap = install(eventBus);
|
26070 |
|
26071 |
|
26072 | setTimeout(untrap, 400);
|
26073 |
|
26074 |
|
26075 | preventDefault(event$$1);
|
26076 | }
|
26077 |
|
26078 | end(event$$1);
|
26079 | }
|
26080 |
|
26081 | function trapTouch(event$$1) {
|
26082 | move(event$$1);
|
26083 | }
|
26084 |
|
26085 |
|
26086 |
|
26087 |
|
26088 |
|
26089 | function hover(event$$1) {
|
26090 | var payload = context.payload;
|
26091 |
|
26092 | payload.hoverGfx = event$$1.gfx;
|
26093 | payload.hover = event$$1.element;
|
26094 |
|
26095 | fire('hover');
|
26096 | }
|
26097 |
|
26098 | function out(event$$1) {
|
26099 | fire('out');
|
26100 |
|
26101 | var payload = context.payload;
|
26102 |
|
26103 | payload.hoverGfx = null;
|
26104 | payload.hover = null;
|
26105 | }
|
26106 |
|
26107 |
|
26108 |
|
26109 |
|
26110 | function cancel(restore) {
|
26111 | var previousContext;
|
26112 |
|
26113 | if (!context) {
|
26114 | return;
|
26115 | }
|
26116 |
|
26117 | var wasActive = context.active;
|
26118 |
|
26119 | if (wasActive) {
|
26120 | fire('cancel');
|
26121 | }
|
26122 |
|
26123 | previousContext = cleanup(restore);
|
26124 |
|
26125 | if (wasActive) {
|
26126 |
|
26127 |
|
26128 | fire('canceled', previousContext);
|
26129 | }
|
26130 | }
|
26131 |
|
26132 | function cleanup(restore) {
|
26133 | var previousContext,
|
26134 | endDrag;
|
26135 |
|
26136 | fire('cleanup');
|
26137 |
|
26138 |
|
26139 | unset();
|
26140 |
|
26141 | if (context.trapClick) {
|
26142 | endDrag = trapClickAndEnd;
|
26143 | } else {
|
26144 | endDrag = end;
|
26145 | }
|
26146 |
|
26147 |
|
26148 | componentEvent.unbind(document, 'mousemove', move);
|
26149 |
|
26150 | componentEvent.unbind(document, 'dragstart', preventDefault);
|
26151 | componentEvent.unbind(document, 'selectstart', preventDefault);
|
26152 |
|
26153 | componentEvent.unbind(document, 'mousedown', endDrag, true);
|
26154 | componentEvent.unbind(document, 'mouseup', endDrag, true);
|
26155 |
|
26156 | componentEvent.unbind(document, 'keyup', checkCancel);
|
26157 |
|
26158 | componentEvent.unbind(document, 'touchstart', trapTouch, true);
|
26159 | componentEvent.unbind(document, 'touchcancel', cancel, true);
|
26160 | componentEvent.unbind(document, 'touchmove', move, true);
|
26161 | componentEvent.unbind(document, 'touchend', end, true);
|
26162 |
|
26163 | eventBus.off('element.hover', hover);
|
26164 | eventBus.off('element.out', out);
|
26165 |
|
26166 |
|
26167 | canvas.removeMarker(canvas.getRootElement(), DRAG_ACTIVE_CLS);
|
26168 |
|
26169 |
|
26170 | var previousSelection = context.payload.previousSelection;
|
26171 |
|
26172 | if (restore !== false && previousSelection && !selection.get().length) {
|
26173 | selection.select(previousSelection);
|
26174 | }
|
26175 |
|
26176 | previousContext = context;
|
26177 |
|
26178 | context = null;
|
26179 |
|
26180 | return previousContext;
|
26181 | }
|
26182 |
|
26183 | |
26184 |
|
26185 |
|
26186 |
|
26187 |
|
26188 |
|
26189 |
|
26190 |
|
26191 |
|
26192 |
|
26193 |
|
26194 | function init(event$$1, relativeTo, prefix, options) {
|
26195 |
|
26196 |
|
26197 | if (context) {
|
26198 | cancel(false);
|
26199 | }
|
26200 |
|
26201 | if (typeof relativeTo === 'string') {
|
26202 | options = prefix;
|
26203 | prefix = relativeTo;
|
26204 | relativeTo = null;
|
26205 | }
|
26206 |
|
26207 | options = assign({}, defaultOptions, options || {});
|
26208 |
|
26209 | var data = options.data || {},
|
26210 | originalEvent,
|
26211 | globalStart,
|
26212 | localStart,
|
26213 | endDrag,
|
26214 | isTouch;
|
26215 |
|
26216 | if (options.trapClick) {
|
26217 | endDrag = trapClickAndEnd;
|
26218 | } else {
|
26219 | endDrag = end;
|
26220 | }
|
26221 |
|
26222 | if (event$$1) {
|
26223 | originalEvent = getOriginal(event$$1) || event$$1;
|
26224 | globalStart = toPoint(event$$1);
|
26225 |
|
26226 | stopPropagation(event$$1);
|
26227 |
|
26228 |
|
26229 | if (originalEvent.type === 'dragstart') {
|
26230 | preventDefault(originalEvent);
|
26231 | }
|
26232 | } else {
|
26233 | originalEvent = null;
|
26234 | globalStart = { x: 0, y: 0 };
|
26235 | }
|
26236 |
|
26237 | localStart = toLocalPoint(globalStart);
|
26238 |
|
26239 | if (!relativeTo) {
|
26240 | relativeTo = localStart;
|
26241 | }
|
26242 |
|
26243 | isTouch = isTouchEvent(originalEvent);
|
26244 |
|
26245 | context = assign({
|
26246 | prefix: prefix,
|
26247 | data: data,
|
26248 | payload: {},
|
26249 | globalStart: globalStart,
|
26250 | displacement: delta(relativeTo, localStart),
|
26251 | localStart: localStart,
|
26252 | isTouch: isTouch
|
26253 | }, options);
|
26254 |
|
26255 |
|
26256 |
|
26257 | if (!options.manual) {
|
26258 |
|
26259 |
|
26260 |
|
26261 | if (isTouch) {
|
26262 | componentEvent.bind(document, 'touchstart', trapTouch, true);
|
26263 | componentEvent.bind(document, 'touchcancel', cancel, true);
|
26264 | componentEvent.bind(document, 'touchmove', move, true);
|
26265 | componentEvent.bind(document, 'touchend', end, true);
|
26266 | } else {
|
26267 |
|
26268 | componentEvent.bind(document, 'mousemove', move);
|
26269 |
|
26270 |
|
26271 | componentEvent.bind(document, 'dragstart', preventDefault);
|
26272 | componentEvent.bind(document, 'selectstart', preventDefault);
|
26273 |
|
26274 | componentEvent.bind(document, 'mousedown', endDrag, true);
|
26275 | componentEvent.bind(document, 'mouseup', endDrag, true);
|
26276 | }
|
26277 |
|
26278 | componentEvent.bind(document, 'keyup', checkCancel);
|
26279 |
|
26280 | eventBus.on('element.hover', hover);
|
26281 | eventBus.on('element.out', out);
|
26282 | }
|
26283 |
|
26284 | fire('init');
|
26285 |
|
26286 | if (options.autoActivate) {
|
26287 | move(event$$1, true);
|
26288 | }
|
26289 | }
|
26290 |
|
26291 |
|
26292 | eventBus.on('diagram.destroy', cancel);
|
26293 |
|
26294 |
|
26295 |
|
26296 |
|
26297 | this.init = init;
|
26298 | this.move = move;
|
26299 | this.hover = hover;
|
26300 | this.out = out;
|
26301 | this.end = end;
|
26302 |
|
26303 | this.cancel = cancel;
|
26304 |
|
26305 |
|
26306 |
|
26307 | this.context = function() {
|
26308 | return context;
|
26309 | };
|
26310 |
|
26311 | this.setOptions = function(options) {
|
26312 | assign(defaultOptions, options);
|
26313 | };
|
26314 | }
|
26315 |
|
26316 | Dragging.$inject = [
|
26317 | 'eventBus',
|
26318 | 'canvas',
|
26319 | 'selection'
|
26320 | ];
|
26321 |
|
26322 | function getGfx(target) {
|
26323 | var node = closest(target, 'svg, .djs-element', true);
|
26324 | return node;
|
26325 | }
|
26326 |
|
26327 |
|
26328 | |
26329 |
|
26330 |
|
26331 |
|
26332 |
|
26333 |
|
26334 |
|
26335 |
|
26336 |
|
26337 |
|
26338 |
|
26339 |
|
26340 |
|
26341 | function HoverFix(eventBus, dragging, elementRegistry) {
|
26342 |
|
26343 | var self = this;
|
26344 |
|
26345 |
|
26346 |
|
26347 |
|
26348 |
|
26349 |
|
26350 |
|
26351 |
|
26352 |
|
26353 |
|
26354 | eventBus.on('drag.start', function(event) {
|
26355 |
|
26356 | eventBus.once('drag.move', function() {
|
26357 |
|
26358 | eventBus.once('drag.move', function(event) {
|
26359 |
|
26360 | self.ensureHover(event);
|
26361 | });
|
26362 | });
|
26363 | });
|
26364 |
|
26365 | |
26366 |
|
26367 |
|
26368 |
|
26369 |
|
26370 | this.ensureHover = function(event) {
|
26371 |
|
26372 | if (event.hover) {
|
26373 | return;
|
26374 | }
|
26375 |
|
26376 | var originalEvent = event.originalEvent,
|
26377 | position,
|
26378 | target,
|
26379 | element,
|
26380 | gfx;
|
26381 |
|
26382 | if (!(originalEvent instanceof MouseEvent)) {
|
26383 | return;
|
26384 | }
|
26385 |
|
26386 | position = toPoint(originalEvent);
|
26387 |
|
26388 |
|
26389 | target = document.elementFromPoint(position.x, position.y);
|
26390 |
|
26391 | gfx = getGfx(target);
|
26392 |
|
26393 | if (gfx) {
|
26394 | element = elementRegistry.get(gfx);
|
26395 |
|
26396 | dragging.hover({ element: element, gfx: gfx });
|
26397 | }
|
26398 | };
|
26399 |
|
26400 | }
|
26401 |
|
26402 | HoverFix.$inject = [
|
26403 | 'eventBus',
|
26404 | 'dragging',
|
26405 | 'elementRegistry'
|
26406 | ];
|
26407 |
|
26408 | var DraggingModule = {
|
26409 | __init__: [
|
26410 | 'hoverFix'
|
26411 | ],
|
26412 | __depends__: [
|
26413 | SelectionModule
|
26414 | ],
|
26415 | dragging: [ 'type', Dragging ],
|
26416 | hoverFix: [ 'type', HoverFix ]
|
26417 | };
|
26418 |
|
26419 | function MouseTracking(eventBus, canvas) {
|
26420 | this._eventBus = eventBus;
|
26421 | this._canvas = canvas;
|
26422 |
|
26423 | this._init();
|
26424 | }
|
26425 |
|
26426 | MouseTracking.$inject = [
|
26427 | 'eventBus',
|
26428 | 'canvas'
|
26429 | ];
|
26430 |
|
26431 |
|
26432 | MouseTracking.prototype.getHoverContext = function() {
|
26433 | var viewbox = this._canvas.viewbox();
|
26434 |
|
26435 | return {
|
26436 | element: this._hoverElement,
|
26437 | point: {
|
26438 | x: viewbox.x + Math.round(this._mouseX / viewbox.scale),
|
26439 | y: viewbox.y + Math.round(this._mouseY / viewbox.scale)
|
26440 | }
|
26441 | };
|
26442 | };
|
26443 |
|
26444 | MouseTracking.prototype._init = function() {
|
26445 | var eventBus = this._eventBus,
|
26446 | canvas = this._canvas;
|
26447 |
|
26448 | var container = canvas.getContainer();
|
26449 |
|
26450 | this._setMousePosition = bind(this._setMousePosition, this);
|
26451 |
|
26452 | container.addEventListener('mousemove', this._setMousePosition);
|
26453 |
|
26454 | eventBus.on('diagram.destroy', function() {
|
26455 | container.removeEventListener('mousemove', this._setMousePosition);
|
26456 | }, this);
|
26457 |
|
26458 | eventBus.on('element.hover', this._setHoverElement, this);
|
26459 | };
|
26460 |
|
26461 |
|
26462 | MouseTracking.prototype._setHoverElement = function(event) {
|
26463 | this._hoverElement = event.element;
|
26464 | };
|
26465 |
|
26466 |
|
26467 | MouseTracking.prototype._setMousePosition = function(event) {
|
26468 | this._mouseX = event.layerX;
|
26469 | this._mouseY = event.layerY;
|
26470 | };
|
26471 |
|
26472 | var MouseTrackingModule = {
|
26473 | __init__: [ 'mouseTracking' ],
|
26474 | mouseTracking: [ 'type', MouseTracking ]
|
26475 | };
|
26476 |
|
26477 | |
26478 |
|
26479 |
|
26480 |
|
26481 |
|
26482 |
|
26483 |
|
26484 |
|
26485 |
|
26486 |
|
26487 |
|
26488 |
|
26489 |
|
26490 |
|
26491 | function AutoScroll(config, eventBus, canvas, mouseTracking) {
|
26492 |
|
26493 | this._canvas = canvas;
|
26494 | this._mouseTracking = mouseTracking;
|
26495 |
|
26496 | this._opts = assign({
|
26497 | scrollThresholdIn: [ 20, 20, 20, 20 ],
|
26498 | scrollThresholdOut: [ 0, 0, 0, 0 ],
|
26499 | scrollRepeatTimeout: 15,
|
26500 | scrollStep: 10
|
26501 | }, config);
|
26502 |
|
26503 | var self = this;
|
26504 |
|
26505 | eventBus.on('drag.move', function(e) {
|
26506 | var point = self._toBorderPoint(e);
|
26507 |
|
26508 | self.startScroll(point);
|
26509 | });
|
26510 |
|
26511 | eventBus.on([ 'drag.cleanup' ], function() {
|
26512 | self.stopScroll();
|
26513 | });
|
26514 | }
|
26515 |
|
26516 | AutoScroll.$inject = [
|
26517 | 'config.autoScroll',
|
26518 | 'eventBus',
|
26519 | 'canvas',
|
26520 | 'mouseTracking'
|
26521 | ];
|
26522 |
|
26523 |
|
26524 | |
26525 |
|
26526 |
|
26527 |
|
26528 |
|
26529 |
|
26530 | AutoScroll.prototype.startScroll = function(point) {
|
26531 |
|
26532 | var canvas = this._canvas;
|
26533 | var opts = this._opts;
|
26534 | var self = this;
|
26535 |
|
26536 | var clientRect = canvas.getContainer().getBoundingClientRect();
|
26537 |
|
26538 | var diff = [
|
26539 | point.x,
|
26540 | point.y,
|
26541 | clientRect.width - point.x,
|
26542 | clientRect.height - point.y
|
26543 | ];
|
26544 |
|
26545 | this.stopScroll();
|
26546 |
|
26547 | var dx = 0,
|
26548 | dy = 0;
|
26549 |
|
26550 | for (var i = 0; i < 4; i++) {
|
26551 | if (between(diff[i], opts.scrollThresholdOut[i], opts.scrollThresholdIn[i])) {
|
26552 | if (i === 0) {
|
26553 | dx = opts.scrollStep;
|
26554 | } else if (i == 1) {
|
26555 | dy = opts.scrollStep;
|
26556 | } else if (i == 2) {
|
26557 | dx = -opts.scrollStep;
|
26558 | } else if (i == 3) {
|
26559 | dy = -opts.scrollStep;
|
26560 | }
|
26561 | }
|
26562 | }
|
26563 |
|
26564 | if (dx !== 0 || dy !== 0) {
|
26565 | canvas.scroll({ dx: dx, dy: dy });
|
26566 |
|
26567 | this._scrolling = setTimeout(function() {
|
26568 | self.startScroll(point);
|
26569 | }, opts.scrollRepeatTimeout);
|
26570 | }
|
26571 | };
|
26572 |
|
26573 | function between(val, start, end) {
|
26574 | if (start < val && val < end) {
|
26575 | return true;
|
26576 | }
|
26577 |
|
26578 | return false;
|
26579 | }
|
26580 |
|
26581 |
|
26582 | |
26583 |
|
26584 |
|
26585 | AutoScroll.prototype.stopScroll = function() {
|
26586 | clearTimeout(this._scrolling);
|
26587 | };
|
26588 |
|
26589 |
|
26590 | |
26591 |
|
26592 |
|
26593 |
|
26594 |
|
26595 | AutoScroll.prototype.setOptions = function(options) {
|
26596 | this._opts = assign({}, this._opts, options);
|
26597 | };
|
26598 |
|
26599 |
|
26600 | |
26601 |
|
26602 |
|
26603 |
|
26604 |
|
26605 |
|
26606 | AutoScroll.prototype._toBorderPoint = function(event) {
|
26607 | var clientRect = this._canvas._container.getBoundingClientRect();
|
26608 |
|
26609 | var globalPosition = toPoint(event.originalEvent);
|
26610 |
|
26611 | return {
|
26612 | x: globalPosition.x - clientRect.left,
|
26613 | y: globalPosition.y - clientRect.top
|
26614 | };
|
26615 | };
|
26616 |
|
26617 | var AutoScrollModule = {
|
26618 | __depends__: [
|
26619 | DraggingModule,
|
26620 | MouseTrackingModule
|
26621 | ],
|
26622 | __init__: [ 'autoScroll' ],
|
26623 | autoScroll: [ 'type', AutoScroll ]
|
26624 | };
|
26625 |
|
26626 | |
26627 |
|
26628 |
|
26629 |
|
26630 |
|
26631 |
|
26632 |
|
26633 |
|
26634 |
|
26635 |
|
26636 |
|
26637 |
|
26638 |
|
26639 |
|
26640 | function Rules(injector) {
|
26641 | this._commandStack = injector.get('commandStack', false);
|
26642 | }
|
26643 |
|
26644 | Rules.$inject = [ 'injector' ];
|
26645 |
|
26646 |
|
26647 | |
26648 |
|
26649 |
|
26650 |
|
26651 |
|
26652 |
|
26653 |
|
26654 |
|
26655 |
|
26656 |
|
26657 |
|
26658 |
|
26659 |
|
26660 | Rules.prototype.allowed = function(action, context) {
|
26661 | var allowed = true;
|
26662 |
|
26663 | var commandStack = this._commandStack;
|
26664 |
|
26665 | if (commandStack) {
|
26666 | allowed = commandStack.canExecute(action, context);
|
26667 | }
|
26668 |
|
26669 |
|
26670 | return allowed === undefined ? true : allowed;
|
26671 | };
|
26672 |
|
26673 | var RulesModule = {
|
26674 | __init__: [ 'rules' ],
|
26675 | rules: [ 'type', Rules ]
|
26676 | };
|
26677 |
|
26678 | var BENDPOINT_CLS = 'djs-bendpoint';
|
26679 | var SEGMENT_DRAGGER_CLS = 'djs-segment-dragger';
|
26680 |
|
26681 | function toCanvasCoordinates(canvas, event) {
|
26682 |
|
26683 | var position = toPoint(event),
|
26684 | clientRect = canvas._container.getBoundingClientRect(),
|
26685 | offset;
|
26686 |
|
26687 |
|
26688 |
|
26689 | offset = {
|
26690 | x: clientRect.left,
|
26691 | y: clientRect.top
|
26692 | };
|
26693 |
|
26694 |
|
26695 |
|
26696 | var viewbox = canvas.viewbox();
|
26697 |
|
26698 | return {
|
26699 | x: viewbox.x + (position.x - offset.x) / viewbox.scale,
|
26700 | y: viewbox.y + (position.y - offset.y) / viewbox.scale
|
26701 | };
|
26702 | }
|
26703 |
|
26704 | function addBendpoint(parentGfx, cls) {
|
26705 | var groupGfx = create('g');
|
26706 | classes$1(groupGfx).add(BENDPOINT_CLS);
|
26707 |
|
26708 | append(parentGfx, groupGfx);
|
26709 |
|
26710 | var visual = create('circle');
|
26711 | attr$1(visual, {
|
26712 | cx: 0,
|
26713 | cy: 0,
|
26714 | r: 4
|
26715 | });
|
26716 | classes$1(visual).add('djs-visual');
|
26717 |
|
26718 | append(groupGfx, visual);
|
26719 |
|
26720 | var hit = create('circle');
|
26721 | attr$1(hit, {
|
26722 | cx: 0,
|
26723 | cy: 0,
|
26724 | r: 10
|
26725 | });
|
26726 | classes$1(hit).add('djs-hit');
|
26727 |
|
26728 | append(groupGfx, hit);
|
26729 |
|
26730 | if (cls) {
|
26731 | classes$1(groupGfx).add(cls);
|
26732 | }
|
26733 |
|
26734 | return groupGfx;
|
26735 | }
|
26736 |
|
26737 | function createParallelDragger(parentGfx, position, alignment) {
|
26738 | var draggerGfx = create('g');
|
26739 |
|
26740 | append(parentGfx, draggerGfx);
|
26741 |
|
26742 | var width = 14,
|
26743 | height = 3,
|
26744 | padding = 6,
|
26745 | hitWidth = width + padding,
|
26746 | hitHeight = height + padding;
|
26747 |
|
26748 | var visual = create('rect');
|
26749 | attr$1(visual, {
|
26750 | x: -width / 2,
|
26751 | y: -height / 2,
|
26752 | width: width,
|
26753 | height: height
|
26754 | });
|
26755 | classes$1(visual).add('djs-visual');
|
26756 |
|
26757 | append(draggerGfx, visual);
|
26758 |
|
26759 | var hit = create('rect');
|
26760 | attr$1(hit, {
|
26761 | x: -hitWidth / 2,
|
26762 | y: -hitHeight / 2,
|
26763 | width: hitWidth,
|
26764 | height: hitHeight
|
26765 | });
|
26766 | classes$1(hit).add('djs-hit');
|
26767 |
|
26768 | append(draggerGfx, hit);
|
26769 |
|
26770 | rotate(draggerGfx, alignment === 'h' ? 90 : 0, 0, 0);
|
26771 |
|
26772 | return draggerGfx;
|
26773 | }
|
26774 |
|
26775 |
|
26776 | function addSegmentDragger(parentGfx, segmentStart, segmentEnd) {
|
26777 |
|
26778 | var groupGfx = create('g'),
|
26779 | mid = getMidPoint(segmentStart, segmentEnd),
|
26780 | alignment = pointsAligned(segmentStart, segmentEnd);
|
26781 |
|
26782 | append(parentGfx, groupGfx);
|
26783 |
|
26784 | createParallelDragger(groupGfx, mid, alignment);
|
26785 |
|
26786 | classes$1(groupGfx).add(SEGMENT_DRAGGER_CLS);
|
26787 | classes$1(groupGfx).add(alignment === 'h' ? 'vertical' : 'horizontal');
|
26788 |
|
26789 | translate(groupGfx, mid.x, mid.y);
|
26790 |
|
26791 | return groupGfx;
|
26792 | }
|
26793 |
|
26794 | var css_escape = createCommonjsModule(function (module, exports) {
|
26795 | (function(root, factory) {
|
26796 |
|
26797 | {
|
26798 |
|
26799 | module.exports = factory(root);
|
26800 | }
|
26801 | }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
|
26802 |
|
26803 | if (root.CSS && root.CSS.escape) {
|
26804 | return root.CSS.escape;
|
26805 | }
|
26806 |
|
26807 |
|
26808 | var cssEscape = function(value) {
|
26809 | if (arguments.length == 0) {
|
26810 | throw new TypeError('`CSS.escape` requires an argument.');
|
26811 | }
|
26812 | var string = String(value);
|
26813 | var length = string.length;
|
26814 | var index = -1;
|
26815 | var codeUnit;
|
26816 | var result = '';
|
26817 | var firstCodeUnit = string.charCodeAt(0);
|
26818 | while (++index < length) {
|
26819 | codeUnit = string.charCodeAt(index);
|
26820 |
|
26821 |
|
26822 |
|
26823 |
|
26824 |
|
26825 | if (codeUnit == 0x0000) {
|
26826 | result += '\uFFFD';
|
26827 | continue;
|
26828 | }
|
26829 |
|
26830 | if (
|
26831 |
|
26832 |
|
26833 | (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
|
26834 |
|
26835 |
|
26836 | (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
|
26837 |
|
26838 |
|
26839 | (
|
26840 | index == 1 &&
|
26841 | codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
|
26842 | firstCodeUnit == 0x002D
|
26843 | )
|
26844 | ) {
|
26845 |
|
26846 | result += '\\' + codeUnit.toString(16) + ' ';
|
26847 | continue;
|
26848 | }
|
26849 |
|
26850 | if (
|
26851 |
|
26852 |
|
26853 | index == 0 &&
|
26854 | length == 1 &&
|
26855 | codeUnit == 0x002D
|
26856 | ) {
|
26857 | result += '\\' + string.charAt(index);
|
26858 | continue;
|
26859 | }
|
26860 |
|
26861 |
|
26862 |
|
26863 |
|
26864 |
|
26865 | if (
|
26866 | codeUnit >= 0x0080 ||
|
26867 | codeUnit == 0x002D ||
|
26868 | codeUnit == 0x005F ||
|
26869 | codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
|
26870 | codeUnit >= 0x0041 && codeUnit <= 0x005A ||
|
26871 | codeUnit >= 0x0061 && codeUnit <= 0x007A
|
26872 | ) {
|
26873 |
|
26874 | result += string.charAt(index);
|
26875 | continue;
|
26876 | }
|
26877 |
|
26878 |
|
26879 |
|
26880 | result += '\\' + string.charAt(index);
|
26881 |
|
26882 | }
|
26883 | return result;
|
26884 | };
|
26885 |
|
26886 | if (!root.CSS) {
|
26887 | root.CSS = {};
|
26888 | }
|
26889 |
|
26890 | root.CSS.escape = cssEscape;
|
26891 | return cssEscape;
|
26892 |
|
26893 | }));
|
26894 | });
|
26895 |
|
26896 | var round$2 = Math.round,
|
26897 | max = Math.max;
|
26898 |
|
26899 |
|
26900 | function circlePath(center, r) {
|
26901 | var x = center.x,
|
26902 | y = center.y;
|
26903 |
|
26904 | return [
|
26905 | ['M', x, y],
|
26906 | ['m', 0, -r],
|
26907 | ['a', r, r, 0, 1, 1, 0, 2 * r],
|
26908 | ['a', r, r, 0, 1, 1, 0, -2 * r],
|
26909 | ['z']
|
26910 | ];
|
26911 | }
|
26912 |
|
26913 | function linePath(points) {
|
26914 | var segments = [];
|
26915 |
|
26916 | points.forEach(function(p, idx) {
|
26917 | segments.push([ idx === 0 ? 'M' : 'L', p.x, p.y ]);
|
26918 | });
|
26919 |
|
26920 | return segments;
|
26921 | }
|
26922 |
|
26923 |
|
26924 | var INTERSECTION_THRESHOLD = 10;
|
26925 |
|
26926 | function getBendpointIntersection(waypoints, reference) {
|
26927 |
|
26928 | var i, w;
|
26929 |
|
26930 | for (i = 0; (w = waypoints[i]); i++) {
|
26931 |
|
26932 | if (pointDistance(w, reference) <= INTERSECTION_THRESHOLD) {
|
26933 | return {
|
26934 | point: waypoints[i],
|
26935 | bendpoint: true,
|
26936 | index: i
|
26937 | };
|
26938 | }
|
26939 | }
|
26940 |
|
26941 | return null;
|
26942 | }
|
26943 |
|
26944 | function getPathIntersection(waypoints, reference) {
|
26945 |
|
26946 | var intersections = intersect(circlePath(reference, INTERSECTION_THRESHOLD), linePath(waypoints));
|
26947 |
|
26948 | var a = intersections[0],
|
26949 | b = intersections[intersections.length - 1],
|
26950 | idx;
|
26951 |
|
26952 | if (!a) {
|
26953 |
|
26954 | return null;
|
26955 | }
|
26956 |
|
26957 | if (a !== b) {
|
26958 |
|
26959 | if (a.segment2 !== b.segment2) {
|
26960 |
|
26961 |
|
26962 |
|
26963 | idx = max(a.segment2, b.segment2) - 1;
|
26964 |
|
26965 | return {
|
26966 | point: waypoints[idx],
|
26967 | bendpoint: true,
|
26968 | index: idx
|
26969 | };
|
26970 | }
|
26971 |
|
26972 | return {
|
26973 | point: {
|
26974 | x: (round$2(a.x + b.x) / 2),
|
26975 | y: (round$2(a.y + b.y) / 2)
|
26976 | },
|
26977 | index: a.segment2
|
26978 | };
|
26979 | }
|
26980 |
|
26981 | return {
|
26982 | point: {
|
26983 | x: round$2(a.x),
|
26984 | y: round$2(a.y)
|
26985 | },
|
26986 | index: a.segment2
|
26987 | };
|
26988 | }
|
26989 |
|
26990 | |
26991 |
|
26992 |
|
26993 |
|
26994 |
|
26995 |
|
26996 |
|
26997 |
|
26998 | function getApproxIntersection(waypoints, reference) {
|
26999 | return getBendpointIntersection(waypoints, reference) || getPathIntersection(waypoints, reference);
|
27000 | }
|
27001 |
|
27002 | |
27003 |
|
27004 |
|
27005 | function Bendpoints(
|
27006 | eventBus, canvas, interactionEvents,
|
27007 | bendpointMove, connectionSegmentMove) {
|
27008 |
|
27009 | function getConnectionIntersection(waypoints, event$$1) {
|
27010 | var localPosition = toCanvasCoordinates(canvas, event$$1),
|
27011 | intersection = getApproxIntersection(waypoints, localPosition);
|
27012 |
|
27013 | return intersection;
|
27014 | }
|
27015 |
|
27016 | function isIntersectionMiddle(intersection, waypoints, treshold) {
|
27017 | var idx = intersection.index,
|
27018 | p = intersection.point,
|
27019 | p0, p1, mid, aligned, xDelta, yDelta;
|
27020 |
|
27021 | if (idx <= 0 || intersection.bendpoint) {
|
27022 | return false;
|
27023 | }
|
27024 |
|
27025 | p0 = waypoints[idx - 1];
|
27026 | p1 = waypoints[idx];
|
27027 | mid = getMidPoint(p0, p1),
|
27028 | aligned = pointsAligned(p0, p1);
|
27029 | xDelta = Math.abs(p.x - mid.x);
|
27030 | yDelta = Math.abs(p.y - mid.y);
|
27031 |
|
27032 | return aligned && xDelta <= treshold && yDelta <= treshold;
|
27033 | }
|
27034 |
|
27035 | function activateBendpointMove(event$$1, connection) {
|
27036 | var waypoints = connection.waypoints,
|
27037 | intersection = getConnectionIntersection(waypoints, event$$1);
|
27038 |
|
27039 | if (!intersection) {
|
27040 | return;
|
27041 | }
|
27042 |
|
27043 | if (isIntersectionMiddle(intersection, waypoints, 10)) {
|
27044 | connectionSegmentMove.start(event$$1, connection, intersection.index);
|
27045 | } else {
|
27046 | bendpointMove.start(event$$1, connection, intersection.index, !intersection.bendpoint);
|
27047 | }
|
27048 |
|
27049 |
|
27050 | return true;
|
27051 | }
|
27052 |
|
27053 | function bindInteractionEvents(node, eventName, element) {
|
27054 |
|
27055 | componentEvent.bind(node, eventName, function(event$$1) {
|
27056 | interactionEvents.triggerMouseEvent(eventName, event$$1, element);
|
27057 | event$$1.stopPropagation();
|
27058 | });
|
27059 | }
|
27060 |
|
27061 | function getBendpointsContainer(element, create$$1) {
|
27062 |
|
27063 | var layer = canvas.getLayer('overlays'),
|
27064 | gfx = query('.djs-bendpoints[data-element-id="' + css_escape(element.id) + '"]', layer);
|
27065 |
|
27066 | if (!gfx && create$$1) {
|
27067 | gfx = create('g');
|
27068 | attr$1(gfx, { 'data-element-id': element.id });
|
27069 | classes$1(gfx).add('djs-bendpoints');
|
27070 |
|
27071 | append(layer, gfx);
|
27072 |
|
27073 | bindInteractionEvents(gfx, 'mousedown', element);
|
27074 | bindInteractionEvents(gfx, 'click', element);
|
27075 | bindInteractionEvents(gfx, 'dblclick', element);
|
27076 | }
|
27077 |
|
27078 | return gfx;
|
27079 | }
|
27080 |
|
27081 | function createBendpoints(gfx, connection) {
|
27082 | connection.waypoints.forEach(function(p, idx) {
|
27083 | var bendpoint = addBendpoint(gfx);
|
27084 |
|
27085 | append(gfx, bendpoint);
|
27086 |
|
27087 | translate(bendpoint, p.x, p.y);
|
27088 | });
|
27089 |
|
27090 |
|
27091 | addBendpoint(gfx, 'floating');
|
27092 | }
|
27093 |
|
27094 | function createSegmentDraggers(gfx, connection) {
|
27095 |
|
27096 | var waypoints = connection.waypoints;
|
27097 |
|
27098 | var segmentStart,
|
27099 | segmentEnd;
|
27100 |
|
27101 | for (var i = 1; i < waypoints.length; i++) {
|
27102 |
|
27103 | segmentStart = waypoints[i - 1];
|
27104 | segmentEnd = waypoints[i];
|
27105 |
|
27106 | if (pointsAligned(segmentStart, segmentEnd)) {
|
27107 | addSegmentDragger(gfx, segmentStart, segmentEnd);
|
27108 | }
|
27109 | }
|
27110 | }
|
27111 |
|
27112 | function clearBendpoints(gfx) {
|
27113 | forEach(all('.' + BENDPOINT_CLS, gfx), function(node) {
|
27114 | remove$1(node);
|
27115 | });
|
27116 | }
|
27117 |
|
27118 | function clearSegmentDraggers(gfx) {
|
27119 | forEach(all('.' + SEGMENT_DRAGGER_CLS, gfx), function(node) {
|
27120 | remove$1(node);
|
27121 | });
|
27122 | }
|
27123 |
|
27124 | function addHandles(connection) {
|
27125 |
|
27126 | var gfx = getBendpointsContainer(connection);
|
27127 |
|
27128 | if (!gfx) {
|
27129 | gfx = getBendpointsContainer(connection, true);
|
27130 |
|
27131 | createBendpoints(gfx, connection);
|
27132 | createSegmentDraggers(gfx, connection);
|
27133 | }
|
27134 |
|
27135 | return gfx;
|
27136 | }
|
27137 |
|
27138 | function updateHandles(connection) {
|
27139 |
|
27140 | var gfx = getBendpointsContainer(connection);
|
27141 |
|
27142 | if (gfx) {
|
27143 | clearSegmentDraggers(gfx);
|
27144 | clearBendpoints(gfx);
|
27145 | createSegmentDraggers(gfx, connection);
|
27146 | createBendpoints(gfx, connection);
|
27147 | }
|
27148 | }
|
27149 |
|
27150 | eventBus.on('connection.changed', function(event$$1) {
|
27151 | updateHandles(event$$1.element);
|
27152 | });
|
27153 |
|
27154 | eventBus.on('connection.remove', function(event$$1) {
|
27155 | var gfx = getBendpointsContainer(event$$1.element);
|
27156 |
|
27157 | if (gfx) {
|
27158 | remove$1(gfx);
|
27159 | }
|
27160 | });
|
27161 |
|
27162 | eventBus.on('element.marker.update', function(event$$1) {
|
27163 |
|
27164 | var element = event$$1.element,
|
27165 | bendpointsGfx;
|
27166 |
|
27167 | if (!element.waypoints) {
|
27168 | return;
|
27169 | }
|
27170 |
|
27171 | bendpointsGfx = addHandles(element);
|
27172 |
|
27173 | if (event$$1.add) {
|
27174 | classes$1(bendpointsGfx).add(event$$1.marker);
|
27175 | } else {
|
27176 | classes$1(bendpointsGfx).remove(event$$1.marker);
|
27177 | }
|
27178 | });
|
27179 |
|
27180 | eventBus.on('element.mousemove', function(event$$1) {
|
27181 |
|
27182 | var element = event$$1.element,
|
27183 | waypoints = element.waypoints,
|
27184 | bendpointsGfx,
|
27185 | floating,
|
27186 | intersection;
|
27187 |
|
27188 | if (waypoints) {
|
27189 | bendpointsGfx = getBendpointsContainer(element, true);
|
27190 | floating = query('.floating', bendpointsGfx);
|
27191 |
|
27192 | if (!floating) {
|
27193 | return;
|
27194 | }
|
27195 |
|
27196 | intersection = getConnectionIntersection(waypoints, event$$1.originalEvent);
|
27197 |
|
27198 | if (intersection) {
|
27199 | translate(floating, intersection.point.x, intersection.point.y);
|
27200 | }
|
27201 | }
|
27202 | });
|
27203 |
|
27204 | eventBus.on('element.mousedown', function(event$$1) {
|
27205 |
|
27206 | var originalEvent = event$$1.originalEvent,
|
27207 | element = event$$1.element,
|
27208 | waypoints = element.waypoints;
|
27209 |
|
27210 | if (!waypoints) {
|
27211 | return;
|
27212 | }
|
27213 |
|
27214 | return activateBendpointMove(originalEvent, element, waypoints);
|
27215 | });
|
27216 |
|
27217 | eventBus.on('selection.changed', function(event$$1) {
|
27218 | var newSelection = event$$1.newSelection,
|
27219 | primary = newSelection[0];
|
27220 |
|
27221 | if (primary && primary.waypoints) {
|
27222 | addHandles(primary);
|
27223 | }
|
27224 | });
|
27225 |
|
27226 | eventBus.on('element.hover', function(event$$1) {
|
27227 | var element = event$$1.element;
|
27228 |
|
27229 | if (element.waypoints) {
|
27230 | addHandles(element);
|
27231 | interactionEvents.registerEvent(event$$1.gfx, 'mousemove', 'element.mousemove');
|
27232 | }
|
27233 | });
|
27234 |
|
27235 | eventBus.on('element.out', function(event$$1) {
|
27236 | interactionEvents.unregisterEvent(event$$1.gfx, 'mousemove', 'element.mousemove');
|
27237 | });
|
27238 |
|
27239 |
|
27240 | eventBus.on('element.updateId', function(context) {
|
27241 | var element = context.element,
|
27242 | newId = context.newId;
|
27243 |
|
27244 | if (element.waypoints) {
|
27245 | var bendpointContainer = getBendpointsContainer(element);
|
27246 |
|
27247 | if (bendpointContainer) {
|
27248 | attr$1(bendpointContainer, { 'data-element-id': newId });
|
27249 | }
|
27250 | }
|
27251 | });
|
27252 |
|
27253 |
|
27254 |
|
27255 | this.addHandles = addHandles;
|
27256 | this.updateHandles = updateHandles;
|
27257 | this.getBendpointsContainer = getBendpointsContainer;
|
27258 | }
|
27259 |
|
27260 | Bendpoints.$inject = [
|
27261 | 'eventBus',
|
27262 | 'canvas',
|
27263 | 'interactionEvents',
|
27264 | 'bendpointMove',
|
27265 | 'connectionSegmentMove'
|
27266 | ];
|
27267 |
|
27268 | var MARKER_OK = 'connect-ok',
|
27269 | MARKER_NOT_OK = 'connect-not-ok',
|
27270 | MARKER_CONNECT_HOVER = 'connect-hover',
|
27271 | MARKER_CONNECT_UPDATING = 'djs-updating';
|
27272 |
|
27273 | var COMMAND_BENDPOINT_UPDATE = 'connection.updateWaypoints',
|
27274 | COMMAND_RECONNECT_START = 'connection.reconnectStart',
|
27275 | COMMAND_RECONNECT_END = 'connection.reconnectEnd';
|
27276 |
|
27277 | var round$3 = Math.round;
|
27278 |
|
27279 |
|
27280 | |
27281 |
|
27282 |
|
27283 | function BendpointMove(
|
27284 | injector, eventBus, canvas,
|
27285 | dragging, graphicsFactory, rules,
|
27286 | modeling) {
|
27287 |
|
27288 |
|
27289 |
|
27290 | var connectionDocking = injector.get('connectionDocking', false);
|
27291 |
|
27292 |
|
27293 |
|
27294 |
|
27295 | this.start = function(event, connection, bendpointIndex, insert) {
|
27296 |
|
27297 | var type,
|
27298 | context,
|
27299 | waypoints = connection.waypoints,
|
27300 | gfx = canvas.getGraphics(connection);
|
27301 |
|
27302 | if (!insert && bendpointIndex === 0) {
|
27303 | type = COMMAND_RECONNECT_START;
|
27304 | } else
|
27305 | if (!insert && bendpointIndex === waypoints.length - 1) {
|
27306 | type = COMMAND_RECONNECT_END;
|
27307 | } else {
|
27308 | type = COMMAND_BENDPOINT_UPDATE;
|
27309 | }
|
27310 |
|
27311 | context = {
|
27312 | connection: connection,
|
27313 | bendpointIndex: bendpointIndex,
|
27314 | insert: insert,
|
27315 | type: type
|
27316 | };
|
27317 |
|
27318 | dragging.init(event, 'bendpoint.move', {
|
27319 | data: {
|
27320 | connection: connection,
|
27321 | connectionGfx: gfx,
|
27322 | context: context
|
27323 | }
|
27324 | });
|
27325 | };
|
27326 |
|
27327 |
|
27328 |
|
27329 |
|
27330 |
|
27331 | function redrawConnection(data) {
|
27332 | graphicsFactory.update('connection', data.connection, data.connectionGfx);
|
27333 | }
|
27334 |
|
27335 | function filterRedundantWaypoints(waypoints) {
|
27336 |
|
27337 |
|
27338 | waypoints = waypoints.slice();
|
27339 |
|
27340 | var idx = 0,
|
27341 | point,
|
27342 | previousPoint,
|
27343 | nextPoint;
|
27344 |
|
27345 | while (waypoints[idx]) {
|
27346 | point = waypoints[idx];
|
27347 | previousPoint = waypoints[idx - 1];
|
27348 | nextPoint = waypoints[idx + 1];
|
27349 |
|
27350 | if (pointDistance(point, nextPoint) === 0 ||
|
27351 | pointsOnLine(previousPoint, nextPoint, point)) {
|
27352 |
|
27353 |
|
27354 |
|
27355 | waypoints.splice(idx, 1);
|
27356 | } else {
|
27357 | idx++;
|
27358 | }
|
27359 | }
|
27360 |
|
27361 | return waypoints;
|
27362 | }
|
27363 |
|
27364 | eventBus.on('bendpoint.move.start', function(e) {
|
27365 |
|
27366 | var context = e.context,
|
27367 | connection = context.connection,
|
27368 | originalWaypoints = connection.waypoints,
|
27369 | waypoints = originalWaypoints.slice(),
|
27370 | insert = context.insert,
|
27371 | idx = context.bendpointIndex;
|
27372 |
|
27373 | context.originalWaypoints = originalWaypoints;
|
27374 |
|
27375 | if (insert) {
|
27376 |
|
27377 | waypoints.splice(idx, 0, null);
|
27378 | }
|
27379 |
|
27380 | connection.waypoints = waypoints;
|
27381 |
|
27382 |
|
27383 | context.draggerGfx = addBendpoint(canvas.getLayer('overlays'));
|
27384 | classes$1(context.draggerGfx).add('djs-dragging');
|
27385 |
|
27386 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING);
|
27387 | });
|
27388 |
|
27389 | eventBus.on('bendpoint.move.hover', function(e) {
|
27390 | var context = e.context;
|
27391 |
|
27392 | context.hover = e.hover;
|
27393 |
|
27394 | if (e.hover) {
|
27395 | canvas.addMarker(e.hover, MARKER_CONNECT_HOVER);
|
27396 |
|
27397 |
|
27398 |
|
27399 | var allowed = context.allowed = rules.allowed(context.type, context);
|
27400 |
|
27401 | if (allowed) {
|
27402 | canvas.removeMarker(context.hover, MARKER_NOT_OK);
|
27403 | canvas.addMarker(context.hover, MARKER_OK);
|
27404 |
|
27405 | context.target = context.hover;
|
27406 | } else if (allowed === false) {
|
27407 | canvas.removeMarker(context.hover, MARKER_OK);
|
27408 | canvas.addMarker(context.hover, MARKER_NOT_OK);
|
27409 |
|
27410 | context.target = null;
|
27411 | }
|
27412 | }
|
27413 | });
|
27414 |
|
27415 | eventBus.on([
|
27416 | 'bendpoint.move.out',
|
27417 | 'bendpoint.move.cleanup'
|
27418 | ], function(e) {
|
27419 |
|
27420 |
|
27421 |
|
27422 | var hover = e.context.hover;
|
27423 |
|
27424 | if (hover) {
|
27425 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER);
|
27426 | canvas.removeMarker(hover, e.context.target ? MARKER_OK : MARKER_NOT_OK);
|
27427 | }
|
27428 | });
|
27429 |
|
27430 | eventBus.on('bendpoint.move.move', function(e) {
|
27431 |
|
27432 | var context = e.context,
|
27433 | moveType = context.type,
|
27434 | connection = e.connection,
|
27435 | source, target;
|
27436 |
|
27437 | connection.waypoints[context.bendpointIndex] = { x: e.x, y: e.y };
|
27438 |
|
27439 | if (connectionDocking) {
|
27440 |
|
27441 | if (context.hover) {
|
27442 | if (moveType === COMMAND_RECONNECT_START) {
|
27443 | source = context.hover;
|
27444 | }
|
27445 |
|
27446 | if (moveType === COMMAND_RECONNECT_END) {
|
27447 | target = context.hover;
|
27448 | }
|
27449 | }
|
27450 |
|
27451 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection, source, target);
|
27452 | }
|
27453 |
|
27454 |
|
27455 | translate(context.draggerGfx, e.x, e.y);
|
27456 |
|
27457 | redrawConnection(e);
|
27458 | });
|
27459 |
|
27460 | eventBus.on([
|
27461 | 'bendpoint.move.end',
|
27462 | 'bendpoint.move.cancel'
|
27463 | ], function(e) {
|
27464 |
|
27465 | var context = e.context,
|
27466 | hover = context.hover,
|
27467 | connection = context.connection;
|
27468 |
|
27469 |
|
27470 | remove$1(context.draggerGfx);
|
27471 | context.newWaypoints = connection.waypoints.slice();
|
27472 | connection.waypoints = context.originalWaypoints;
|
27473 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING);
|
27474 |
|
27475 | if (hover) {
|
27476 | canvas.removeMarker(hover, MARKER_OK);
|
27477 | canvas.removeMarker(hover, MARKER_NOT_OK);
|
27478 | }
|
27479 | });
|
27480 |
|
27481 | eventBus.on('bendpoint.move.end', function(e) {
|
27482 |
|
27483 | var context = e.context,
|
27484 | waypoints = context.newWaypoints,
|
27485 | bendpointIndex = context.bendpointIndex,
|
27486 | bendpoint = waypoints[bendpointIndex],
|
27487 | allowed = context.allowed,
|
27488 | hints;
|
27489 |
|
27490 |
|
27491 |
|
27492 | bendpoint.x = round$3(bendpoint.x);
|
27493 | bendpoint.y = round$3(bendpoint.y);
|
27494 |
|
27495 | if (allowed && context.type === COMMAND_RECONNECT_START) {
|
27496 | modeling.reconnectStart(context.connection, context.target, bendpoint);
|
27497 | } else
|
27498 | if (allowed && context.type === COMMAND_RECONNECT_END) {
|
27499 | modeling.reconnectEnd(context.connection, context.target, bendpoint);
|
27500 | } else
|
27501 | if (allowed !== false && context.type === COMMAND_BENDPOINT_UPDATE) {
|
27502 |
|
27503 |
|
27504 |
|
27505 | hints = {
|
27506 | bendpointMove: {
|
27507 | insert: e.context.insert,
|
27508 | bendpointIndex: bendpointIndex
|
27509 | }
|
27510 | };
|
27511 |
|
27512 | modeling.updateWaypoints(context.connection, filterRedundantWaypoints(waypoints), hints);
|
27513 | } else {
|
27514 | redrawConnection(e);
|
27515 |
|
27516 | return false;
|
27517 | }
|
27518 | });
|
27519 |
|
27520 | eventBus.on('bendpoint.move.cancel', function(e) {
|
27521 | redrawConnection(e);
|
27522 | });
|
27523 | }
|
27524 |
|
27525 | BendpointMove.$inject = [
|
27526 | 'injector',
|
27527 | 'eventBus',
|
27528 | 'canvas',
|
27529 | 'dragging',
|
27530 | 'graphicsFactory',
|
27531 | 'rules',
|
27532 | 'modeling'
|
27533 | ];
|
27534 |
|
27535 | var MARKER_CONNECT_HOVER$1 = 'connect-hover',
|
27536 | MARKER_CONNECT_UPDATING$1 = 'djs-updating';
|
27537 |
|
27538 |
|
27539 | function axisAdd(point, axis, delta) {
|
27540 | return axisSet(point, axis, point[axis] + delta);
|
27541 | }
|
27542 |
|
27543 | function axisSet(point, axis, value) {
|
27544 | return {
|
27545 | x: (axis === 'x' ? value : point.x),
|
27546 | y: (axis === 'y' ? value : point.y)
|
27547 | };
|
27548 | }
|
27549 |
|
27550 | function axisFenced(position, segmentStart, segmentEnd, axis) {
|
27551 |
|
27552 | var maxValue = Math.max(segmentStart[axis], segmentEnd[axis]),
|
27553 | minValue = Math.min(segmentStart[axis], segmentEnd[axis]);
|
27554 |
|
27555 | var padding = 20;
|
27556 |
|
27557 | var fencedValue = Math.min(Math.max(minValue + padding, position[axis]), maxValue - padding);
|
27558 |
|
27559 | return axisSet(segmentStart, axis, fencedValue);
|
27560 | }
|
27561 |
|
27562 | function flipAxis(axis) {
|
27563 | return axis === 'x' ? 'y' : 'x';
|
27564 | }
|
27565 |
|
27566 | |
27567 |
|
27568 |
|
27569 |
|
27570 |
|
27571 |
|
27572 |
|
27573 |
|
27574 |
|
27575 |
|
27576 |
|
27577 | function getDocking(point, referenceElement, moveAxis) {
|
27578 |
|
27579 | var referenceMid,
|
27580 | inverseAxis;
|
27581 |
|
27582 | if (point.original) {
|
27583 | return point.original;
|
27584 | } else {
|
27585 | referenceMid = getMid(referenceElement);
|
27586 | inverseAxis = flipAxis(moveAxis);
|
27587 |
|
27588 | return axisSet(point, inverseAxis, referenceMid[inverseAxis]);
|
27589 | }
|
27590 | }
|
27591 |
|
27592 | |
27593 |
|
27594 |
|
27595 | function ConnectionSegmentMove(
|
27596 | injector, eventBus, canvas,
|
27597 | dragging, graphicsFactory, rules,
|
27598 | modeling) {
|
27599 |
|
27600 |
|
27601 | var connectionDocking = injector.get('connectionDocking', false);
|
27602 |
|
27603 |
|
27604 |
|
27605 |
|
27606 | this.start = function(event, connection, idx) {
|
27607 |
|
27608 | var context,
|
27609 | gfx = canvas.getGraphics(connection),
|
27610 | segmentStartIndex = idx - 1,
|
27611 | segmentEndIndex = idx,
|
27612 | waypoints = connection.waypoints,
|
27613 | segmentStart = waypoints[segmentStartIndex],
|
27614 | segmentEnd = waypoints[segmentEndIndex],
|
27615 | direction,
|
27616 | axis;
|
27617 |
|
27618 | direction = pointsAligned(segmentStart, segmentEnd);
|
27619 |
|
27620 |
|
27621 | if (!direction) {
|
27622 | return;
|
27623 | }
|
27624 |
|
27625 |
|
27626 | axis = direction === 'v' ? 'y' : 'x';
|
27627 |
|
27628 | if (segmentStartIndex === 0) {
|
27629 | segmentStart = getDocking(segmentStart, connection.source, axis);
|
27630 | }
|
27631 |
|
27632 | if (segmentEndIndex === waypoints.length - 1) {
|
27633 | segmentEnd = getDocking(segmentEnd, connection.target, axis);
|
27634 | }
|
27635 |
|
27636 | context = {
|
27637 | connection: connection,
|
27638 | segmentStartIndex: segmentStartIndex,
|
27639 | segmentEndIndex: segmentEndIndex,
|
27640 | segmentStart: segmentStart,
|
27641 | segmentEnd: segmentEnd,
|
27642 | axis: axis
|
27643 | };
|
27644 |
|
27645 | dragging.init(event, {
|
27646 | x: (segmentStart.x + segmentEnd.x)/2,
|
27647 | y: (segmentStart.y + segmentEnd.y)/2
|
27648 | }, 'connectionSegment.move', {
|
27649 | cursor: axis === 'x' ? 'resize-ew' : 'resize-ns',
|
27650 | data: {
|
27651 | connection: connection,
|
27652 | connectionGfx: gfx,
|
27653 | context: context
|
27654 | }
|
27655 | });
|
27656 | };
|
27657 |
|
27658 | |
27659 |
|
27660 |
|
27661 |
|
27662 |
|
27663 |
|
27664 |
|
27665 |
|
27666 | function cropConnection(connection, newWaypoints) {
|
27667 |
|
27668 |
|
27669 | if (!connectionDocking) {
|
27670 | return newWaypoints;
|
27671 | }
|
27672 |
|
27673 | var oldWaypoints = connection.waypoints,
|
27674 | croppedWaypoints;
|
27675 |
|
27676 |
|
27677 | connection.waypoints = newWaypoints;
|
27678 |
|
27679 | croppedWaypoints = connectionDocking.getCroppedWaypoints(connection);
|
27680 |
|
27681 |
|
27682 | connection.waypoints = oldWaypoints;
|
27683 |
|
27684 | return croppedWaypoints;
|
27685 | }
|
27686 |
|
27687 |
|
27688 |
|
27689 | function redrawConnection(data) {
|
27690 | graphicsFactory.update('connection', data.connection, data.connectionGfx);
|
27691 | }
|
27692 |
|
27693 | function updateDragger(context, segmentOffset, event) {
|
27694 |
|
27695 | var newWaypoints = context.newWaypoints,
|
27696 | segmentStartIndex = context.segmentStartIndex + segmentOffset,
|
27697 | segmentStart = newWaypoints[segmentStartIndex],
|
27698 | segmentEndIndex = context.segmentEndIndex + segmentOffset,
|
27699 | segmentEnd = newWaypoints[segmentEndIndex],
|
27700 | axis = flipAxis(context.axis);
|
27701 |
|
27702 |
|
27703 |
|
27704 | var draggerPosition = axisFenced(event, segmentStart, segmentEnd, axis);
|
27705 |
|
27706 |
|
27707 | translate(context.draggerGfx, draggerPosition.x, draggerPosition.y);
|
27708 | }
|
27709 |
|
27710 | |
27711 |
|
27712 |
|
27713 |
|
27714 |
|
27715 |
|
27716 |
|
27717 |
|
27718 |
|
27719 | function filterRedundantWaypoints(waypoints, segmentStartIndex) {
|
27720 |
|
27721 | var segmentOffset = 0;
|
27722 |
|
27723 | var filteredWaypoints = waypoints.filter(function(r, idx) {
|
27724 | if (pointsOnLine(waypoints[idx - 1], waypoints[idx + 1], r)) {
|
27725 |
|
27726 |
|
27727 | segmentOffset = idx <= segmentStartIndex ? segmentOffset - 1 : segmentOffset;
|
27728 | return false;
|
27729 | }
|
27730 |
|
27731 |
|
27732 | return true;
|
27733 | });
|
27734 |
|
27735 | return {
|
27736 | waypoints: filteredWaypoints,
|
27737 | segmentOffset: segmentOffset
|
27738 | };
|
27739 | }
|
27740 |
|
27741 | eventBus.on('connectionSegment.move.start', function(e) {
|
27742 |
|
27743 | var context = e.context,
|
27744 | connection = e.connection,
|
27745 | layer = canvas.getLayer('overlays');
|
27746 |
|
27747 | context.originalWaypoints = connection.waypoints.slice();
|
27748 |
|
27749 |
|
27750 | context.draggerGfx = addSegmentDragger(layer, context.segmentStart, context.segmentEnd);
|
27751 | classes$1(context.draggerGfx).add('djs-dragging');
|
27752 |
|
27753 | canvas.addMarker(connection, MARKER_CONNECT_UPDATING$1);
|
27754 | });
|
27755 |
|
27756 | eventBus.on('connectionSegment.move.move', function(e) {
|
27757 |
|
27758 | var context = e.context,
|
27759 | connection = context.connection,
|
27760 | segmentStartIndex = context.segmentStartIndex,
|
27761 | segmentEndIndex = context.segmentEndIndex,
|
27762 | segmentStart = context.segmentStart,
|
27763 | segmentEnd = context.segmentEnd,
|
27764 | axis = context.axis;
|
27765 |
|
27766 | var newWaypoints = context.originalWaypoints.slice(),
|
27767 | newSegmentStart = axisAdd(segmentStart, axis, e['d' + axis]),
|
27768 | newSegmentEnd = axisAdd(segmentEnd, axis, e['d' + axis]);
|
27769 |
|
27770 |
|
27771 |
|
27772 |
|
27773 | var waypointCount = newWaypoints.length,
|
27774 | segmentOffset = 0;
|
27775 |
|
27776 |
|
27777 | newWaypoints[segmentStartIndex] = newSegmentStart;
|
27778 | newWaypoints[segmentEndIndex] = newSegmentEnd;
|
27779 |
|
27780 | var sourceToSegmentOrientation,
|
27781 | targetToSegmentOrientation;
|
27782 |
|
27783 |
|
27784 | if (segmentStartIndex < 2) {
|
27785 | sourceToSegmentOrientation = getOrientation(connection.source, newSegmentStart);
|
27786 |
|
27787 |
|
27788 | if (segmentStartIndex === 1) {
|
27789 |
|
27790 | if (sourceToSegmentOrientation === 'intersect') {
|
27791 | newWaypoints.shift();
|
27792 | newWaypoints[0] = newSegmentStart;
|
27793 | segmentOffset--;
|
27794 | }
|
27795 | }
|
27796 |
|
27797 |
|
27798 | else {
|
27799 | if (sourceToSegmentOrientation !== 'intersect') {
|
27800 | newWaypoints.unshift(segmentStart);
|
27801 | segmentOffset++;
|
27802 | }
|
27803 | }
|
27804 | }
|
27805 |
|
27806 |
|
27807 | if (segmentEndIndex > waypointCount - 3) {
|
27808 | targetToSegmentOrientation = getOrientation(connection.target, newSegmentEnd);
|
27809 |
|
27810 |
|
27811 | if (segmentEndIndex === waypointCount - 2) {
|
27812 |
|
27813 | if (targetToSegmentOrientation === 'intersect') {
|
27814 | newWaypoints.pop();
|
27815 | newWaypoints[newWaypoints.length - 1] = newSegmentEnd;
|
27816 | }
|
27817 | }
|
27818 |
|
27819 |
|
27820 | else {
|
27821 | if (targetToSegmentOrientation !== 'intersect') {
|
27822 | newWaypoints.push(segmentEnd);
|
27823 | }
|
27824 | }
|
27825 | }
|
27826 |
|
27827 |
|
27828 | context.newWaypoints = connection.waypoints = cropConnection(connection, newWaypoints);
|
27829 |
|
27830 |
|
27831 | updateDragger(context, segmentOffset, e);
|
27832 |
|
27833 |
|
27834 | context.newSegmentStartIndex = segmentStartIndex + segmentOffset;
|
27835 |
|
27836 |
|
27837 | redrawConnection(e);
|
27838 | });
|
27839 |
|
27840 | eventBus.on('connectionSegment.move.hover', function(e) {
|
27841 |
|
27842 | e.context.hover = e.hover;
|
27843 | canvas.addMarker(e.hover, MARKER_CONNECT_HOVER$1);
|
27844 | });
|
27845 |
|
27846 | eventBus.on([
|
27847 | 'connectionSegment.move.out',
|
27848 | 'connectionSegment.move.cleanup'
|
27849 | ], function(e) {
|
27850 |
|
27851 |
|
27852 |
|
27853 | var hover = e.context.hover;
|
27854 |
|
27855 | if (hover) {
|
27856 | canvas.removeMarker(hover, MARKER_CONNECT_HOVER$1);
|
27857 | }
|
27858 | });
|
27859 |
|
27860 | eventBus.on('connectionSegment.move.cleanup', function(e) {
|
27861 |
|
27862 | var context = e.context,
|
27863 | connection = context.connection;
|
27864 |
|
27865 |
|
27866 | if (context.draggerGfx) {
|
27867 | remove$1(context.draggerGfx);
|
27868 | }
|
27869 |
|
27870 | canvas.removeMarker(connection, MARKER_CONNECT_UPDATING$1);
|
27871 | });
|
27872 |
|
27873 | eventBus.on([
|
27874 | 'connectionSegment.move.cancel',
|
27875 | 'connectionSegment.move.end'
|
27876 | ], function(e) {
|
27877 | var context = e.context,
|
27878 | connection = context.connection;
|
27879 |
|
27880 | connection.waypoints = context.originalWaypoints;
|
27881 |
|
27882 | redrawConnection(e);
|
27883 | });
|
27884 |
|
27885 | eventBus.on('connectionSegment.move.end', function(e) {
|
27886 |
|
27887 | var context = e.context,
|
27888 | connection = context.connection,
|
27889 | newWaypoints = context.newWaypoints,
|
27890 | newSegmentStartIndex = context.newSegmentStartIndex;
|
27891 |
|
27892 |
|
27893 |
|
27894 | newWaypoints = newWaypoints.map(function(p) {
|
27895 | return {
|
27896 | original: p.original,
|
27897 | x: Math.round(p.x),
|
27898 | y: Math.round(p.y)
|
27899 | };
|
27900 | });
|
27901 |
|
27902 |
|
27903 | var filtered = filterRedundantWaypoints(newWaypoints, newSegmentStartIndex);
|
27904 |
|
27905 |
|
27906 | var filteredWaypoints = filtered.waypoints,
|
27907 | croppedWaypoints = cropConnection(connection, filteredWaypoints),
|
27908 | segmentOffset = filtered.segmentOffset;
|
27909 |
|
27910 | var hints = {
|
27911 | segmentMove: {
|
27912 | segmentStartIndex: context.segmentStartIndex,
|
27913 | newSegmentStartIndex: newSegmentStartIndex + segmentOffset
|
27914 | }
|
27915 | };
|
27916 |
|
27917 | modeling.updateWaypoints(connection, croppedWaypoints, hints);
|
27918 | });
|
27919 | }
|
27920 |
|
27921 | ConnectionSegmentMove.$inject = [
|
27922 | 'injector',
|
27923 | 'eventBus',
|
27924 | 'canvas',
|
27925 | 'dragging',
|
27926 | 'graphicsFactory',
|
27927 | 'rules',
|
27928 | 'modeling'
|
27929 | ];
|
27930 |
|
27931 | var abs$1= Math.abs,
|
27932 | round$4 = Math.round;
|
27933 |
|
27934 | var TOLERANCE = 10;
|
27935 |
|
27936 |
|
27937 | function BendpointSnapping(eventBus) {
|
27938 |
|
27939 | function snapTo(values$$1, value) {
|
27940 |
|
27941 | if (isArray(values$$1)) {
|
27942 | var i = values$$1.length;
|
27943 |
|
27944 | while (i--) if (abs$1(values$$1[i] - value) <= TOLERANCE) {
|
27945 | return values$$1[i];
|
27946 | }
|
27947 | } else {
|
27948 | values$$1 = +values$$1;
|
27949 | var rem = value % values$$1;
|
27950 |
|
27951 | if (rem < TOLERANCE) {
|
27952 | return value - rem;
|
27953 | }
|
27954 |
|
27955 | if (rem > values$$1 - TOLERANCE) {
|
27956 | return value - rem + values$$1;
|
27957 | }
|
27958 | }
|
27959 |
|
27960 | return value;
|
27961 | }
|
27962 |
|
27963 | function mid(element) {
|
27964 | if (element.width) {
|
27965 | return {
|
27966 | x: round$4(element.width / 2 + element.x),
|
27967 | y: round$4(element.height / 2 + element.y)
|
27968 | };
|
27969 | }
|
27970 | }
|
27971 |
|
27972 |
|
27973 |
|
27974 | function getConnectionSegmentSnaps(context) {
|
27975 |
|
27976 | var snapPoints = context.snapPoints,
|
27977 | connection = context.connection,
|
27978 | waypoints = connection.waypoints,
|
27979 | segmentStart = context.segmentStart,
|
27980 | segmentStartIndex = context.segmentStartIndex,
|
27981 | segmentEnd = context.segmentEnd,
|
27982 | segmentEndIndex = context.segmentEndIndex,
|
27983 | axis = context.axis;
|
27984 |
|
27985 | if (snapPoints) {
|
27986 | return snapPoints;
|
27987 | }
|
27988 |
|
27989 | var referenceWaypoints = [
|
27990 | waypoints[segmentStartIndex - 1],
|
27991 | segmentStart,
|
27992 | segmentEnd,
|
27993 | waypoints[segmentEndIndex + 1]
|
27994 | ];
|
27995 |
|
27996 | if (segmentStartIndex < 2) {
|
27997 | referenceWaypoints.unshift(mid(connection.source));
|
27998 | }
|
27999 |
|
28000 | if (segmentEndIndex > waypoints.length - 3) {
|
28001 | referenceWaypoints.unshift(mid(connection.target));
|
28002 | }
|
28003 |
|
28004 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28005 |
|
28006 | forEach(referenceWaypoints, function(p) {
|
28007 |
|
28008 |
|
28009 | if (p) {
|
28010 | p = p.original || p;
|
28011 |
|
28012 | if (axis === 'y') {
|
28013 | snapPoints.horizontal.push(p.y);
|
28014 | }
|
28015 |
|
28016 | if (axis === 'x') {
|
28017 | snapPoints.vertical.push(p.x);
|
28018 | }
|
28019 | }
|
28020 | });
|
28021 |
|
28022 | return snapPoints;
|
28023 | }
|
28024 |
|
28025 | eventBus.on('connectionSegment.move.move', 1500, function(event) {
|
28026 | var context = event.context,
|
28027 | snapPoints = getConnectionSegmentSnaps(context),
|
28028 | x = event.x,
|
28029 | y = event.y,
|
28030 | sx, sy;
|
28031 |
|
28032 | if (!snapPoints) {
|
28033 | return;
|
28034 | }
|
28035 |
|
28036 |
|
28037 | sx = snapTo(snapPoints.vertical, x);
|
28038 | sy = snapTo(snapPoints.horizontal, y);
|
28039 |
|
28040 |
|
28041 |
|
28042 | var cx = (x - sx),
|
28043 | cy = (y - sy);
|
28044 |
|
28045 |
|
28046 | assign(event, {
|
28047 | dx: event.dx - cx,
|
28048 | dy: event.dy - cy,
|
28049 | x: sx,
|
28050 | y: sy
|
28051 | });
|
28052 | });
|
28053 |
|
28054 |
|
28055 |
|
28056 |
|
28057 | function getBendpointSnaps(context) {
|
28058 |
|
28059 | var snapPoints = context.snapPoints,
|
28060 | waypoints = context.connection.waypoints,
|
28061 | bendpointIndex = context.bendpointIndex;
|
28062 |
|
28063 | if (snapPoints) {
|
28064 | return snapPoints;
|
28065 | }
|
28066 |
|
28067 | var referenceWaypoints = [ waypoints[bendpointIndex - 1], waypoints[bendpointIndex + 1] ];
|
28068 |
|
28069 | context.snapPoints = snapPoints = { horizontal: [] , vertical: [] };
|
28070 |
|
28071 | forEach(referenceWaypoints, function(p) {
|
28072 |
|
28073 |
|
28074 | if (p) {
|
28075 | p = p.original || p;
|
28076 |
|
28077 | snapPoints.horizontal.push(p.y);
|
28078 | snapPoints.vertical.push(p.x);
|
28079 | }
|
28080 | });
|
28081 |
|
28082 | return snapPoints;
|
28083 | }
|
28084 |
|
28085 |
|
28086 | eventBus.on('bendpoint.move.move', 1500, function(event) {
|
28087 |
|
28088 | var context = event.context,
|
28089 | snapPoints = getBendpointSnaps(context),
|
28090 | target = context.target,
|
28091 | targetMid = target && mid(target),
|
28092 | x = event.x,
|
28093 | y = event.y,
|
28094 | sx, sy;
|
28095 |
|
28096 | if (!snapPoints) {
|
28097 | return;
|
28098 | }
|
28099 |
|
28100 |
|
28101 | sx = snapTo(targetMid ? snapPoints.vertical.concat([ targetMid.x ]) : snapPoints.vertical, x);
|
28102 | sy = snapTo(targetMid ? snapPoints.horizontal.concat([ targetMid.y ]) : snapPoints.horizontal, y);
|
28103 |
|
28104 |
|
28105 |
|
28106 | var cx = (x - sx),
|
28107 | cy = (y - sy);
|
28108 |
|
28109 |
|
28110 | assign(event, {
|
28111 | dx: event.dx - cx,
|
28112 | dy: event.dy - cy,
|
28113 | x: event.x - cx,
|
28114 | y: event.y - cy
|
28115 | });
|
28116 | });
|
28117 | }
|
28118 |
|
28119 |
|
28120 | BendpointSnapping.$inject = [ 'eventBus' ];
|
28121 |
|
28122 | var BendpointsModule = {
|
28123 | __depends__: [
|
28124 | DraggingModule,
|
28125 | RulesModule
|
28126 | ],
|
28127 | __init__: [ 'bendpoints', 'bendpointSnapping' ],
|
28128 | bendpoints: [ 'type', Bendpoints ],
|
28129 | bendpointMove: [ 'type', BendpointMove ],
|
28130 | connectionSegmentMove: [ 'type', ConnectionSegmentMove ],
|
28131 | bendpointSnapping: [ 'type', BendpointSnapping ]
|
28132 | };
|
28133 |
|
28134 | var min = Math.min,
|
28135 | max$1 = Math.max;
|
28136 |
|
28137 | function preventDefault$1(e) {
|
28138 | e.preventDefault();
|
28139 | }
|
28140 |
|
28141 | function stopPropagation$1(e) {
|
28142 | e.stopPropagation();
|
28143 | }
|
28144 |
|
28145 | function isTextNode(node) {
|
28146 | return node.nodeType === Node.TEXT_NODE;
|
28147 | }
|
28148 |
|
28149 | function toArray(nodeList) {
|
28150 | return [].slice.call(nodeList);
|
28151 | }
|
28152 |
|
28153 | |
28154 |
|
28155 |
|
28156 |
|
28157 |
|
28158 |
|
28159 |
|
28160 |
|
28161 |
|
28162 |
|
28163 |
|
28164 |
|
28165 |
|
28166 |
|
28167 |
|
28168 | function TextBox(options) {
|
28169 | this.container = options.container;
|
28170 |
|
28171 | this.parent = domify(
|
28172 | '<div class="djs-direct-editing-parent">' +
|
28173 | '<div class="djs-direct-editing-content" contenteditable="true"></div>' +
|
28174 | '</div>'
|
28175 | );
|
28176 |
|
28177 | this.content = query('[contenteditable]', this.parent);
|
28178 |
|
28179 | this.keyHandler = options.keyHandler || function() {};
|
28180 | this.resizeHandler = options.resizeHandler || function() {};
|
28181 |
|
28182 | this.autoResize = bind(this.autoResize, this);
|
28183 | this.handlePaste = bind(this.handlePaste, this);
|
28184 | }
|
28185 |
|
28186 |
|
28187 | |
28188 |
|
28189 |
|
28190 |
|
28191 |
|
28192 |
|
28193 |
|
28194 |
|
28195 |
|
28196 |
|
28197 |
|
28198 |
|
28199 |
|
28200 |
|
28201 |
|
28202 |
|
28203 |
|
28204 | TextBox.prototype.create = function(bounds, style, value, options) {
|
28205 | var self = this;
|
28206 |
|
28207 | var parent = this.parent,
|
28208 | content = this.content,
|
28209 | container = this.container;
|
28210 |
|
28211 | options = this.options = options || {};
|
28212 |
|
28213 | style = this.style = style || {};
|
28214 |
|
28215 | var parentStyle = pick(style, [
|
28216 | 'width',
|
28217 | 'height',
|
28218 | 'maxWidth',
|
28219 | 'maxHeight',
|
28220 | 'minWidth',
|
28221 | 'minHeight',
|
28222 | 'left',
|
28223 | 'top',
|
28224 | 'backgroundColor',
|
28225 | 'position',
|
28226 | 'overflow',
|
28227 | 'border',
|
28228 | 'wordWrap',
|
28229 | 'textAlign',
|
28230 | 'outline',
|
28231 | 'transform'
|
28232 | ]);
|
28233 |
|
28234 | assign(parent.style, {
|
28235 | width: bounds.width + 'px',
|
28236 | height: bounds.height + 'px',
|
28237 | maxWidth: bounds.maxWidth + 'px',
|
28238 | maxHeight: bounds.maxHeight + 'px',
|
28239 | minWidth: bounds.minWidth + 'px',
|
28240 | minHeight: bounds.minHeight + 'px',
|
28241 | left: bounds.x + 'px',
|
28242 | top: bounds.y + 'px',
|
28243 | backgroundColor: '#ffffff',
|
28244 | position: 'absolute',
|
28245 | overflow: 'visible',
|
28246 | border: '1px solid #ccc',
|
28247 | boxSizing: 'border-box',
|
28248 | wordWrap: 'normal',
|
28249 | textAlign: 'center',
|
28250 | outline: 'none'
|
28251 | }, parentStyle);
|
28252 |
|
28253 | var contentStyle = pick(style, [
|
28254 | 'fontFamily',
|
28255 | 'fontSize',
|
28256 | 'fontWeight',
|
28257 | 'lineHeight',
|
28258 | 'padding',
|
28259 | 'paddingTop',
|
28260 | 'paddingRight',
|
28261 | 'paddingBottom',
|
28262 | 'paddingLeft'
|
28263 | ]);
|
28264 |
|
28265 | assign(content.style, {
|
28266 | boxSizing: 'border-box',
|
28267 | width: '100%',
|
28268 | outline: 'none',
|
28269 | wordWrap: 'break-word'
|
28270 | }, contentStyle);
|
28271 |
|
28272 | if (options.centerVertically) {
|
28273 | assign(content.style, {
|
28274 | position: 'absolute',
|
28275 | top: '50%',
|
28276 | transform: 'translate(0, -50%)'
|
28277 | }, contentStyle);
|
28278 | }
|
28279 |
|
28280 | content.innerText = value;
|
28281 |
|
28282 | componentEvent.bind(content, 'keydown', this.keyHandler);
|
28283 | componentEvent.bind(content, 'mousedown', stopPropagation$1);
|
28284 | componentEvent.bind(content, 'paste', self.handlePaste);
|
28285 |
|
28286 | if (options.autoResize) {
|
28287 | componentEvent.bind(content, 'input', this.autoResize);
|
28288 | }
|
28289 |
|
28290 | if (options.resizable) {
|
28291 | this.resizable(style);
|
28292 | }
|
28293 |
|
28294 | container.appendChild(parent);
|
28295 |
|
28296 |
|
28297 | this.setSelection(content.lastChild, content.lastChild && content.lastChild.length);
|
28298 |
|
28299 | return parent;
|
28300 | };
|
28301 |
|
28302 | |
28303 |
|
28304 |
|
28305 | TextBox.prototype.handlePaste = function(e) {
|
28306 | var self = this;
|
28307 |
|
28308 | var options = this.options,
|
28309 | style = this.style;
|
28310 |
|
28311 | e.preventDefault();
|
28312 |
|
28313 | var text;
|
28314 |
|
28315 | if (e.clipboardData) {
|
28316 |
|
28317 |
|
28318 | text = e.clipboardData.getData('text/plain');
|
28319 | } else {
|
28320 |
|
28321 |
|
28322 | text = window.clipboardData.getData('Text');
|
28323 | }
|
28324 |
|
28325 |
|
28326 | var success = document.execCommand('insertHTML', false, text);
|
28327 |
|
28328 | if (!success) {
|
28329 |
|
28330 |
|
28331 | var range = this.getSelection(),
|
28332 | startContainer = range.startContainer,
|
28333 | endContainer = range.endContainer,
|
28334 | startOffset = range.startOffset,
|
28335 | endOffset = range.endOffset,
|
28336 | commonAncestorContainer = range.commonAncestorContainer;
|
28337 |
|
28338 | var childNodesArray = toArray(commonAncestorContainer.childNodes);
|
28339 |
|
28340 | var container,
|
28341 | offset;
|
28342 |
|
28343 | if (isTextNode(commonAncestorContainer)) {
|
28344 | var containerTextContent = startContainer.textContent;
|
28345 |
|
28346 | startContainer.textContent =
|
28347 | containerTextContent.substring(0, startOffset)
|
28348 | + text
|
28349 | + containerTextContent.substring(endOffset);
|
28350 |
|
28351 | container = startContainer;
|
28352 | offset = startOffset + text.length;
|
28353 |
|
28354 | } else if (startContainer === this.content && endContainer === this.content) {
|
28355 | var textNode = document.createTextNode(text);
|
28356 |
|
28357 | this.content.insertBefore(textNode, childNodesArray[startOffset]);
|
28358 |
|
28359 | container = textNode;
|
28360 | offset = textNode.textContent.length;
|
28361 | } else {
|
28362 | var startContainerChildIndex = childNodesArray.indexOf(startContainer),
|
28363 | endContainerChildIndex = childNodesArray.indexOf(endContainer);
|
28364 |
|
28365 | childNodesArray.forEach(function(childNode, index) {
|
28366 |
|
28367 | if (index === startContainerChildIndex) {
|
28368 | childNode.textContent =
|
28369 | startContainer.textContent.substring(0, startOffset) +
|
28370 | text +
|
28371 | endContainer.textContent.substring(endOffset);
|
28372 | } else if (index > startContainerChildIndex && index <= endContainerChildIndex) {
|
28373 | remove(childNode);
|
28374 | }
|
28375 | });
|
28376 |
|
28377 | container = startContainer;
|
28378 | offset = startOffset + text.length;
|
28379 | }
|
28380 |
|
28381 | if (container && offset !== undefined) {
|
28382 |
|
28383 |
|
28384 | setTimeout(function() {
|
28385 | self.setSelection(container, offset);
|
28386 | });
|
28387 | }
|
28388 | }
|
28389 |
|
28390 | if (options.autoResize) {
|
28391 | var hasResized = this.autoResize(style);
|
28392 |
|
28393 | if (hasResized) {
|
28394 | this.resizeHandler(hasResized);
|
28395 | }
|
28396 | }
|
28397 | };
|
28398 |
|
28399 | |
28400 |
|
28401 |
|
28402 | TextBox.prototype.autoResize = function() {
|
28403 | var parent = this.parent,
|
28404 | content = this.content;
|
28405 |
|
28406 | var fontSize = parseInt(this.style.fontSize) || 12;
|
28407 |
|
28408 | if (content.scrollHeight > parent.offsetHeight ||
|
28409 | content.scrollHeight < parent.offsetHeight - fontSize) {
|
28410 | var bounds = parent.getBoundingClientRect();
|
28411 |
|
28412 | var height = content.scrollHeight;
|
28413 | parent.style.height = height + 'px';
|
28414 |
|
28415 | this.resizeHandler({
|
28416 | width: bounds.width,
|
28417 | height: bounds.height,
|
28418 | dx: 0,
|
28419 | dy: height - bounds.height
|
28420 | });
|
28421 | }
|
28422 | };
|
28423 |
|
28424 | |
28425 |
|
28426 |
|
28427 | TextBox.prototype.resizable = function() {
|
28428 | var self = this;
|
28429 |
|
28430 | var parent = this.parent,
|
28431 | resizeHandle = this.resizeHandle;
|
28432 |
|
28433 | var minWidth = parseInt(this.style.minWidth) || 0,
|
28434 | minHeight = parseInt(this.style.minHeight) || 0,
|
28435 | maxWidth = parseInt(this.style.maxWidth) || Infinity,
|
28436 | maxHeight = parseInt(this.style.maxHeight) || Infinity;
|
28437 |
|
28438 | if (!resizeHandle) {
|
28439 | resizeHandle = this.resizeHandle = domify(
|
28440 | '<div class="djs-direct-editing-resize-handle"></div>'
|
28441 | );
|
28442 |
|
28443 | var startX, startY, startWidth, startHeight;
|
28444 |
|
28445 | var onMouseDown = function(e) {
|
28446 | preventDefault$1(e);
|
28447 | stopPropagation$1(e);
|
28448 |
|
28449 | startX = e.clientX;
|
28450 | startY = e.clientY;
|
28451 |
|
28452 | var bounds = parent.getBoundingClientRect();
|
28453 |
|
28454 | startWidth = bounds.width;
|
28455 | startHeight = bounds.height;
|
28456 |
|
28457 | componentEvent.bind(document, 'mousemove', onMouseMove);
|
28458 | componentEvent.bind(document, 'mouseup', onMouseUp);
|
28459 | };
|
28460 |
|
28461 | var onMouseMove = function(e) {
|
28462 | preventDefault$1(e);
|
28463 | stopPropagation$1(e);
|
28464 |
|
28465 | var newWidth = min(max$1(startWidth + e.clientX - startX, minWidth), maxWidth);
|
28466 | var newHeight = min(max$1(startHeight + e.clientY - startY, minHeight), maxHeight);
|
28467 |
|
28468 | parent.style.width = newWidth + 'px';
|
28469 | parent.style.height = newHeight + 'px';
|
28470 |
|
28471 | self.resizeHandler({
|
28472 | width: startWidth,
|
28473 | height: startHeight,
|
28474 | dx: e.clientX - startX,
|
28475 | dy: e.clientY - startY
|
28476 | });
|
28477 | };
|
28478 |
|
28479 | var onMouseUp = function(e) {
|
28480 | preventDefault$1(e);
|
28481 | stopPropagation$1(e);
|
28482 |
|
28483 | componentEvent.unbind(document,'mousemove', onMouseMove, false);
|
28484 | componentEvent.unbind(document, 'mouseup', onMouseUp, false);
|
28485 | };
|
28486 |
|
28487 | componentEvent.bind(resizeHandle, 'mousedown', onMouseDown);
|
28488 | }
|
28489 |
|
28490 | assign(resizeHandle.style, {
|
28491 | position: 'absolute',
|
28492 | bottom: '0px',
|
28493 | right: '0px',
|
28494 | cursor: 'nwse-resize',
|
28495 | width: '0',
|
28496 | height: '0',
|
28497 | borderTop: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent',
|
28498 | borderRight: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
28499 | borderBottom: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid #ccc',
|
28500 | borderLeft: (parseInt(this.style.fontSize) / 4 || 3) + 'px solid transparent'
|
28501 | });
|
28502 |
|
28503 | parent.appendChild(resizeHandle);
|
28504 | };
|
28505 |
|
28506 |
|
28507 | |
28508 |
|
28509 |
|
28510 |
|
28511 | TextBox.prototype.destroy = function() {
|
28512 | var parent = this.parent,
|
28513 | content = this.content,
|
28514 | resizeHandle = this.resizeHandle;
|
28515 |
|
28516 |
|
28517 | content.innerText = '';
|
28518 |
|
28519 |
|
28520 | parent.removeAttribute('style');
|
28521 | content.removeAttribute('style');
|
28522 |
|
28523 | componentEvent.unbind(content, 'keydown', this.keyHandler);
|
28524 | componentEvent.unbind(content, 'mousedown', stopPropagation$1);
|
28525 | componentEvent.unbind(content, 'input', this.autoResize);
|
28526 | componentEvent.unbind(content, 'paste', this.handlePaste);
|
28527 |
|
28528 | if (resizeHandle) {
|
28529 | resizeHandle.removeAttribute('style');
|
28530 |
|
28531 | remove(resizeHandle);
|
28532 | }
|
28533 |
|
28534 | remove(parent);
|
28535 | };
|
28536 |
|
28537 |
|
28538 | TextBox.prototype.getValue = function() {
|
28539 | return this.content.innerText;
|
28540 | };
|
28541 |
|
28542 |
|
28543 | TextBox.prototype.getSelection = function() {
|
28544 | var selection = window.getSelection(),
|
28545 | range = selection.getRangeAt(0);
|
28546 |
|
28547 | return range;
|
28548 | };
|
28549 |
|
28550 |
|
28551 | TextBox.prototype.setSelection = function(container, offset) {
|
28552 | var range = document.createRange();
|
28553 |
|
28554 | if (container === null) {
|
28555 | range.selectNodeContents(this.content);
|
28556 | } else {
|
28557 | range.setStart(container, offset);
|
28558 | range.setEnd(container, offset);
|
28559 | }
|
28560 |
|
28561 | var selection = window.getSelection();
|
28562 |
|
28563 | selection.removeAllRanges();
|
28564 | selection.addRange(range);
|
28565 | };
|
28566 |
|
28567 | |
28568 |
|
28569 |
|
28570 |
|
28571 |
|
28572 |
|
28573 | function DirectEditing(eventBus, canvas) {
|
28574 |
|
28575 | this._eventBus = eventBus;
|
28576 |
|
28577 | this._providers = [];
|
28578 | this._textbox = new TextBox({
|
28579 | container: canvas.getContainer(),
|
28580 | keyHandler: bind(this._handleKey, this),
|
28581 | resizeHandler: bind(this._handleResize, this)
|
28582 | });
|
28583 | }
|
28584 |
|
28585 | DirectEditing.$inject = [ 'eventBus', 'canvas' ];
|
28586 |
|
28587 |
|
28588 | |
28589 |
|
28590 |
|
28591 |
|
28592 |
|
28593 |
|
28594 |
|
28595 |
|
28596 |
|
28597 | DirectEditing.prototype.registerProvider = function(provider) {
|
28598 | this._providers.push(provider);
|
28599 | };
|
28600 |
|
28601 |
|
28602 | |
28603 |
|
28604 |
|
28605 |
|
28606 |
|
28607 | DirectEditing.prototype.isActive = function() {
|
28608 | return !!this._active;
|
28609 | };
|
28610 |
|
28611 |
|
28612 | |
28613 |
|
28614 |
|
28615 | DirectEditing.prototype.cancel = function() {
|
28616 | if (!this._active) {
|
28617 | return;
|
28618 | }
|
28619 |
|
28620 | this._fire('cancel');
|
28621 | this.close();
|
28622 | };
|
28623 |
|
28624 |
|
28625 | DirectEditing.prototype._fire = function(event, context) {
|
28626 | this._eventBus.fire('directEditing.' + event, context || { active: this._active });
|
28627 | };
|
28628 |
|
28629 | DirectEditing.prototype.close = function() {
|
28630 | this._textbox.destroy();
|
28631 |
|
28632 | this._fire('deactivate');
|
28633 |
|
28634 | this._active = null;
|
28635 |
|
28636 | this.resizable = undefined;
|
28637 | };
|
28638 |
|
28639 |
|
28640 | DirectEditing.prototype.complete = function() {
|
28641 |
|
28642 | var active = this._active;
|
28643 |
|
28644 | if (!active) {
|
28645 | return;
|
28646 | }
|
28647 |
|
28648 | var text = this.getValue();
|
28649 |
|
28650 | var bounds = this.$textbox.getBoundingClientRect();
|
28651 |
|
28652 | if (text !== active.context.text || this.resizable) {
|
28653 | active.provider.update(active.element, text, active.context.text, {
|
28654 | x: bounds.top,
|
28655 | y: bounds.left,
|
28656 | width: bounds.width,
|
28657 | height: bounds.height
|
28658 | });
|
28659 | }
|
28660 |
|
28661 | this._fire('complete');
|
28662 |
|
28663 | this.close();
|
28664 | };
|
28665 |
|
28666 |
|
28667 | DirectEditing.prototype.getValue = function() {
|
28668 | return this._textbox.getValue();
|
28669 | };
|
28670 |
|
28671 |
|
28672 | DirectEditing.prototype._handleKey = function(e) {
|
28673 |
|
28674 |
|
28675 | e.stopPropagation();
|
28676 |
|
28677 | var key = e.keyCode || e.charCode;
|
28678 |
|
28679 |
|
28680 | if (key === 27) {
|
28681 | e.preventDefault();
|
28682 | return this.cancel();
|
28683 | }
|
28684 |
|
28685 |
|
28686 | if (key === 13 && !e.shiftKey) {
|
28687 | e.preventDefault();
|
28688 | return this.complete();
|
28689 | }
|
28690 | };
|
28691 |
|
28692 |
|
28693 | DirectEditing.prototype._handleResize = function(event) {
|
28694 | this._fire('resize', event);
|
28695 | };
|
28696 |
|
28697 |
|
28698 | |
28699 |
|
28700 |
|
28701 |
|
28702 |
|
28703 |
|
28704 | DirectEditing.prototype.activate = function(element) {
|
28705 | if (this.isActive()) {
|
28706 | this.cancel();
|
28707 | }
|
28708 |
|
28709 |
|
28710 | var context;
|
28711 |
|
28712 | var provider = find(this._providers, function(p) {
|
28713 | return (context = p.activate(element)) ? p : null;
|
28714 | });
|
28715 |
|
28716 |
|
28717 | if (context) {
|
28718 | this.$textbox = this._textbox.create(
|
28719 | context.bounds,
|
28720 | context.style,
|
28721 | context.text,
|
28722 | context.options
|
28723 | );
|
28724 |
|
28725 | this._active = {
|
28726 | element: element,
|
28727 | context: context,
|
28728 | provider: provider
|
28729 | };
|
28730 |
|
28731 | if (context.options && context.options.resizable) {
|
28732 | this.resizable = true;
|
28733 | }
|
28734 |
|
28735 | this._fire('activate');
|
28736 | }
|
28737 |
|
28738 | return !!context;
|
28739 | };
|
28740 |
|
28741 | var DirectEditingModule = {
|
28742 | __depends__: [
|
28743 | InteractionEventsModule
|
28744 | ],
|
28745 | __init__: [ 'directEditing' ],
|
28746 | directEditing: [ 'type', DirectEditing ]
|
28747 | };
|
28748 |
|
28749 | var entrySelector = '.entry';
|
28750 |
|
28751 |
|
28752 | |
28753 |
|
28754 |
|
28755 |
|
28756 |
|
28757 |
|
28758 |
|
28759 |
|
28760 |
|
28761 |
|
28762 |
|
28763 | function ContextPad(config, eventBus, overlays) {
|
28764 |
|
28765 | this._providers = [];
|
28766 |
|
28767 | this._eventBus = eventBus;
|
28768 | this._overlays = overlays;
|
28769 |
|
28770 | var scale = isDefined(config && config.scale) ? config.scale : {
|
28771 | min: 1,
|
28772 | max: 1.5
|
28773 | };
|
28774 |
|
28775 | this._overlaysConfig = {
|
28776 | position: {
|
28777 | right: -9,
|
28778 | top: -6
|
28779 | },
|
28780 | scale: scale
|
28781 | };
|
28782 |
|
28783 | this._current = null;
|
28784 |
|
28785 | this._init();
|
28786 | }
|
28787 |
|
28788 | ContextPad.$inject = [
|
28789 | 'config.contextPad',
|
28790 | 'eventBus',
|
28791 | 'overlays'
|
28792 | ];
|
28793 |
|
28794 |
|
28795 | |
28796 |
|
28797 |
|
28798 | ContextPad.prototype._init = function() {
|
28799 |
|
28800 | var eventBus = this._eventBus;
|
28801 |
|
28802 | var self = this;
|
28803 |
|
28804 | eventBus.on('selection.changed', function(e) {
|
28805 |
|
28806 | var selection = e.newSelection;
|
28807 |
|
28808 | if (selection.length === 1) {
|
28809 | self.open(selection[0]);
|
28810 | } else {
|
28811 | self.close();
|
28812 | }
|
28813 | });
|
28814 |
|
28815 | eventBus.on('elements.delete', function(event$$1) {
|
28816 | var elements = event$$1.elements;
|
28817 |
|
28818 | forEach(elements, function(e) {
|
28819 | if (self.isOpen(e)) {
|
28820 | self.close();
|
28821 | }
|
28822 | });
|
28823 | });
|
28824 |
|
28825 | eventBus.on('element.changed', function(event$$1) {
|
28826 | var element = event$$1.element,
|
28827 | current = self._current;
|
28828 |
|
28829 |
|
28830 | if (current && current.element === element) {
|
28831 | self.open(element, true);
|
28832 | }
|
28833 | });
|
28834 | };
|
28835 |
|
28836 |
|
28837 | |
28838 |
|
28839 |
|
28840 |
|
28841 |
|
28842 | ContextPad.prototype.registerProvider = function(provider) {
|
28843 | this._providers.push(provider);
|
28844 | };
|
28845 |
|
28846 |
|
28847 | |
28848 |
|
28849 |
|
28850 |
|
28851 |
|
28852 |
|
28853 |
|
28854 | ContextPad.prototype.getEntries = function(element) {
|
28855 | var entries = {};
|
28856 |
|
28857 |
|
28858 |
|
28859 | forEach(this._providers, function(provider) {
|
28860 | var e = provider.getContextPadEntries(element);
|
28861 |
|
28862 | forEach(e, function(entry, id) {
|
28863 | entries[id] = entry;
|
28864 | });
|
28865 | });
|
28866 |
|
28867 | return entries;
|
28868 | };
|
28869 |
|
28870 |
|
28871 | |
28872 |
|
28873 |
|
28874 |
|
28875 |
|
28876 |
|
28877 |
|
28878 | ContextPad.prototype.trigger = function(action, event$$1, autoActivate) {
|
28879 |
|
28880 | var element = this._current.element,
|
28881 | entries = this._current.entries,
|
28882 | entry,
|
28883 | handler,
|
28884 | originalEvent,
|
28885 | button = event$$1.delegateTarget || event$$1.target;
|
28886 |
|
28887 | if (!button) {
|
28888 | return event$$1.preventDefault();
|
28889 | }
|
28890 |
|
28891 | entry = entries[attr(button, 'data-action')];
|
28892 | handler = entry.action;
|
28893 |
|
28894 | originalEvent = event$$1.originalEvent || event$$1;
|
28895 |
|
28896 |
|
28897 | if (isFunction(handler)) {
|
28898 | if (action === 'click') {
|
28899 | return handler(originalEvent, element, autoActivate);
|
28900 | }
|
28901 | } else {
|
28902 | if (handler[action]) {
|
28903 | return handler[action](originalEvent, element, autoActivate);
|
28904 | }
|
28905 | }
|
28906 |
|
28907 |
|
28908 | event$$1.preventDefault();
|
28909 | };
|
28910 |
|
28911 |
|
28912 | |
28913 |
|
28914 |
|
28915 |
|
28916 |
|
28917 |
|
28918 | ContextPad.prototype.open = function(element, force) {
|
28919 | if (!force && this.isOpen(element)) {
|
28920 | return;
|
28921 | }
|
28922 |
|
28923 | this.close();
|
28924 | this._updateAndOpen(element);
|
28925 | };
|
28926 |
|
28927 |
|
28928 | ContextPad.prototype._updateAndOpen = function(element) {
|
28929 |
|
28930 | var entries = this.getEntries(element),
|
28931 | pad = this.getPad(element),
|
28932 | html = pad.html;
|
28933 |
|
28934 | forEach(entries, function(entry, id) {
|
28935 | var grouping = entry.group || 'default',
|
28936 | control = domify(entry.html || '<div class="entry" draggable="true"></div>'),
|
28937 | container;
|
28938 |
|
28939 | attr(control, 'data-action', id);
|
28940 |
|
28941 | container = query('[data-group=' + grouping + ']', html);
|
28942 | if (!container) {
|
28943 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
28944 | html.appendChild(container);
|
28945 | }
|
28946 |
|
28947 | container.appendChild(control);
|
28948 |
|
28949 | if (entry.className) {
|
28950 | addClasses(control, entry.className);
|
28951 | }
|
28952 |
|
28953 | if (entry.title) {
|
28954 | attr(control, 'title', entry.title);
|
28955 | }
|
28956 |
|
28957 | if (entry.imageUrl) {
|
28958 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
28959 | }
|
28960 | });
|
28961 |
|
28962 | classes(html).add('open');
|
28963 |
|
28964 | this._current = {
|
28965 | element: element,
|
28966 | pad: pad,
|
28967 | entries: entries
|
28968 | };
|
28969 |
|
28970 | this._eventBus.fire('contextPad.open', { current: this._current });
|
28971 | };
|
28972 |
|
28973 |
|
28974 | ContextPad.prototype.getPad = function(element) {
|
28975 | if (this.isOpen()) {
|
28976 | return this._current.pad;
|
28977 | }
|
28978 |
|
28979 | var self = this;
|
28980 |
|
28981 | var overlays = this._overlays;
|
28982 |
|
28983 | var html = domify('<div class="djs-context-pad"></div>');
|
28984 |
|
28985 | var overlaysConfig = assign({
|
28986 | html: html
|
28987 | }, this._overlaysConfig);
|
28988 |
|
28989 | delegateEvents.bind(html, entrySelector, 'click', function(event$$1) {
|
28990 | self.trigger('click', event$$1);
|
28991 | });
|
28992 |
|
28993 | delegateEvents.bind(html, entrySelector, 'dragstart', function(event$$1) {
|
28994 | self.trigger('dragstart', event$$1);
|
28995 | });
|
28996 |
|
28997 |
|
28998 | componentEvent.bind(html, 'mousedown', function(event$$1) {
|
28999 | event$$1.stopPropagation();
|
29000 | });
|
29001 |
|
29002 | this._overlayId = overlays.add(element, 'context-pad', overlaysConfig);
|
29003 |
|
29004 | var pad = overlays.get(this._overlayId);
|
29005 |
|
29006 | this._eventBus.fire('contextPad.create', { element: element, pad: pad });
|
29007 |
|
29008 | return pad;
|
29009 | };
|
29010 |
|
29011 |
|
29012 | |
29013 |
|
29014 |
|
29015 | ContextPad.prototype.close = function() {
|
29016 | if (!this.isOpen()) {
|
29017 | return;
|
29018 | }
|
29019 |
|
29020 | this._overlays.remove(this._overlayId);
|
29021 |
|
29022 | this._overlayId = null;
|
29023 |
|
29024 | this._eventBus.fire('contextPad.close', { current: this._current });
|
29025 |
|
29026 | this._current = null;
|
29027 | };
|
29028 |
|
29029 | |
29030 |
|
29031 |
|
29032 |
|
29033 |
|
29034 |
|
29035 |
|
29036 | ContextPad.prototype.isOpen = function(element) {
|
29037 | return !!this._current && (!element ? true : this._current.element === element);
|
29038 | };
|
29039 |
|
29040 |
|
29041 |
|
29042 |
|
29043 |
|
29044 |
|
29045 | function addClasses(element, classNames) {
|
29046 |
|
29047 | var classes$$1 = classes(element);
|
29048 |
|
29049 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
29050 | actualClassNames.forEach(function(cls) {
|
29051 | classes$$1.add(cls);
|
29052 | });
|
29053 | }
|
29054 |
|
29055 | var ContextPadModule = {
|
29056 | __depends__: [
|
29057 | InteractionEventsModule,
|
29058 | OverlaysModule
|
29059 | ],
|
29060 | contextPad: [ 'type', ContextPad ]
|
29061 | };
|
29062 |
|
29063 | var MARKER_OK$1 = 'connect-ok',
|
29064 | MARKER_NOT_OK$1 = 'connect-not-ok';
|
29065 |
|
29066 |
|
29067 | function Connect(
|
29068 | eventBus, dragging, modeling,
|
29069 | rules, canvas, graphicsFactory) {
|
29070 |
|
29071 |
|
29072 |
|
29073 |
|
29074 |
|
29075 | function canConnect(source, target) {
|
29076 | return rules.allowed('connection.create', {
|
29077 | source: source,
|
29078 | target: target
|
29079 | });
|
29080 | }
|
29081 |
|
29082 |
|
29083 |
|
29084 |
|
29085 | function crop(start, end, source, target) {
|
29086 |
|
29087 | var sourcePath = graphicsFactory.getShapePath(source),
|
29088 | targetPath = target && graphicsFactory.getShapePath(target),
|
29089 | connectionPath = graphicsFactory.getConnectionPath({ waypoints: [ start, end ] });
|
29090 |
|
29091 | start = getElementLineIntersection(sourcePath, connectionPath, true) || start;
|
29092 | end = (target && getElementLineIntersection(targetPath, connectionPath, false)) || end;
|
29093 |
|
29094 | return [ start, end ];
|
29095 | }
|
29096 |
|
29097 |
|
29098 |
|
29099 |
|
29100 | eventBus.on('connect.move', function(event) {
|
29101 |
|
29102 | var context = event.context,
|
29103 | source = context.source,
|
29104 | target = context.target,
|
29105 | visual = context.visual,
|
29106 | sourcePosition = context.sourcePosition,
|
29107 | endPosition,
|
29108 | waypoints;
|
29109 |
|
29110 |
|
29111 |
|
29112 | endPosition = {
|
29113 | x: event.x,
|
29114 | y: event.y
|
29115 | };
|
29116 |
|
29117 | waypoints = crop(sourcePosition, endPosition, source, target);
|
29118 |
|
29119 | attr$1(visual, { 'points': [ waypoints[0].x, waypoints[0].y, waypoints[1].x, waypoints[1].y ] });
|
29120 | });
|
29121 |
|
29122 | eventBus.on('connect.hover', function(event) {
|
29123 | var context = event.context,
|
29124 | source = context.source,
|
29125 | hover = event.hover,
|
29126 | canExecute;
|
29127 |
|
29128 | canExecute = context.canExecute = canConnect(source, hover);
|
29129 |
|
29130 |
|
29131 | if (canExecute === null) {
|
29132 | return;
|
29133 | }
|
29134 |
|
29135 | context.target = hover;
|
29136 |
|
29137 | canvas.addMarker(hover, canExecute ? MARKER_OK$1 : MARKER_NOT_OK$1);
|
29138 | });
|
29139 |
|
29140 | eventBus.on([ 'connect.out', 'connect.cleanup' ], function(event) {
|
29141 | var context = event.context;
|
29142 |
|
29143 | if (context.target) {
|
29144 | canvas.removeMarker(context.target, context.canExecute ? MARKER_OK$1 : MARKER_NOT_OK$1);
|
29145 | }
|
29146 |
|
29147 | context.target = null;
|
29148 | context.canExecute = false;
|
29149 | });
|
29150 |
|
29151 | eventBus.on('connect.cleanup', function(event) {
|
29152 | var context = event.context;
|
29153 |
|
29154 | if (context.visual) {
|
29155 | remove$1(context.visual);
|
29156 | }
|
29157 | });
|
29158 |
|
29159 | eventBus.on('connect.start', function(event) {
|
29160 | var context = event.context,
|
29161 | visual;
|
29162 |
|
29163 | visual = create('polyline');
|
29164 | attr$1(visual, {
|
29165 | 'stroke': '#333',
|
29166 | 'strokeDasharray': [ 1 ],
|
29167 | 'strokeWidth': 2,
|
29168 | 'pointer-events': 'none'
|
29169 | });
|
29170 |
|
29171 | append(canvas.getDefaultLayer(), visual);
|
29172 |
|
29173 | context.visual = visual;
|
29174 | });
|
29175 |
|
29176 | eventBus.on('connect.end', function(event) {
|
29177 |
|
29178 | var context = event.context,
|
29179 | source = context.source,
|
29180 | sourcePosition = context.sourcePosition,
|
29181 | target = context.target,
|
29182 | targetPosition = {
|
29183 | x: event.x,
|
29184 | y: event.y
|
29185 | },
|
29186 | canExecute = context.canExecute || canConnect(source, target);
|
29187 |
|
29188 | if (!canExecute) {
|
29189 | return false;
|
29190 | }
|
29191 |
|
29192 | var attrs = null,
|
29193 | hints = {
|
29194 | connectionStart: sourcePosition,
|
29195 | connectionEnd: targetPosition
|
29196 | };
|
29197 |
|
29198 | if (typeof canExecute === 'object') {
|
29199 | attrs = canExecute;
|
29200 | }
|
29201 |
|
29202 | modeling.connect(source, target, attrs, hints);
|
29203 | });
|
29204 |
|
29205 |
|
29206 |
|
29207 |
|
29208 | |
29209 |
|
29210 |
|
29211 |
|
29212 |
|
29213 |
|
29214 |
|
29215 |
|
29216 | this.start = function(event, source, sourcePosition, autoActivate) {
|
29217 |
|
29218 | if (typeof sourcePosition !== 'object') {
|
29219 | autoActivate = sourcePosition;
|
29220 | sourcePosition = getMid(source);
|
29221 | }
|
29222 |
|
29223 | dragging.init(event, 'connect', {
|
29224 | autoActivate: autoActivate,
|
29225 | data: {
|
29226 | shape: source,
|
29227 | context: {
|
29228 | source: source,
|
29229 | sourcePosition: sourcePosition
|
29230 | }
|
29231 | }
|
29232 | });
|
29233 | };
|
29234 | }
|
29235 |
|
29236 | Connect.$inject = [
|
29237 | 'eventBus',
|
29238 | 'dragging',
|
29239 | 'modeling',
|
29240 | 'rules',
|
29241 | 'canvas',
|
29242 | 'graphicsFactory'
|
29243 | ];
|
29244 |
|
29245 | var ConnectModule = {
|
29246 | __depends__: [
|
29247 | SelectionModule,
|
29248 | RulesModule,
|
29249 | DraggingModule
|
29250 | ],
|
29251 | connect: [ 'type', Connect ]
|
29252 | };
|
29253 |
|
29254 | var LOW_PRIORITY$4 = 750;
|
29255 |
|
29256 | var MARKER_OK$2 = 'drop-ok',
|
29257 | MARKER_NOT_OK$2 = 'drop-not-ok',
|
29258 | MARKER_ATTACH = 'attach-ok',
|
29259 | MARKER_NEW_PARENT = 'new-parent';
|
29260 |
|
29261 |
|
29262 | |
29263 |
|
29264 |
|
29265 |
|
29266 |
|
29267 |
|
29268 |
|
29269 |
|
29270 |
|
29271 |
|
29272 |
|
29273 |
|
29274 |
|
29275 |
|
29276 |
|
29277 |
|
29278 |
|
29279 |
|
29280 |
|
29281 |
|
29282 |
|
29283 |
|
29284 |
|
29285 |
|
29286 |
|
29287 |
|
29288 |
|
29289 |
|
29290 |
|
29291 |
|
29292 |
|
29293 |
|
29294 |
|
29295 |
|
29296 |
|
29297 |
|
29298 |
|
29299 |
|
29300 |
|
29301 |
|
29302 |
|
29303 |
|
29304 |
|
29305 |
|
29306 |
|
29307 |
|
29308 |
|
29309 | function Create(
|
29310 | eventBus, dragging, rules, modeling,
|
29311 | canvas, styles, graphicsFactory) {
|
29312 |
|
29313 |
|
29314 |
|
29315 | function canCreate(shape, target, source, position) {
|
29316 |
|
29317 | if (!target) {
|
29318 | return false;
|
29319 | }
|
29320 |
|
29321 | var ctx = {
|
29322 | source: source,
|
29323 | shape: shape,
|
29324 | target: target,
|
29325 | position: position
|
29326 | };
|
29327 |
|
29328 | var create$$1,
|
29329 | attach,
|
29330 | connect;
|
29331 |
|
29332 | attach = rules.allowed('shape.attach', ctx);
|
29333 |
|
29334 | if (!attach) {
|
29335 | create$$1 = rules.allowed('shape.create', ctx);
|
29336 | }
|
29337 |
|
29338 | if (create$$1 || attach) {
|
29339 |
|
29340 | connect = source && rules.allowed('connection.create', {
|
29341 | source: source,
|
29342 | target: shape,
|
29343 | hints: {
|
29344 | targetParent: target,
|
29345 | targetAttach: attach
|
29346 | }
|
29347 | });
|
29348 | }
|
29349 |
|
29350 | if (create$$1 || attach) {
|
29351 | return {
|
29352 | attach: attach,
|
29353 | connect: connect
|
29354 | };
|
29355 | }
|
29356 |
|
29357 | return false;
|
29358 | }
|
29359 |
|
29360 |
|
29361 |
|
29362 | function setMarker(element, marker) {
|
29363 |
|
29364 | [ MARKER_ATTACH, MARKER_OK$2, MARKER_NOT_OK$2, MARKER_NEW_PARENT ].forEach(function(m) {
|
29365 |
|
29366 | if (m === marker) {
|
29367 | canvas.addMarker(element, m);
|
29368 | } else {
|
29369 | canvas.removeMarker(element, m);
|
29370 | }
|
29371 | });
|
29372 | }
|
29373 |
|
29374 |
|
29375 |
|
29376 |
|
29377 | function createVisual(shape) {
|
29378 | var group, preview, visual;
|
29379 |
|
29380 | group = create('g');
|
29381 | attr$1(group, styles.cls('djs-drag-group', [ 'no-events' ]));
|
29382 |
|
29383 | append(canvas.getDefaultLayer(), group);
|
29384 |
|
29385 | preview = create('g');
|
29386 | classes$1(preview).add('djs-dragger');
|
29387 |
|
29388 | append(group, preview);
|
29389 |
|
29390 | translate(preview, shape.width / -2, shape.height / -2);
|
29391 |
|
29392 | var visualGroup = create('g');
|
29393 | classes$1(visualGroup).add('djs-visual');
|
29394 |
|
29395 | append(preview, visualGroup);
|
29396 |
|
29397 | visual = visualGroup;
|
29398 |
|
29399 |
|
29400 | graphicsFactory.drawShape(visual, shape);
|
29401 |
|
29402 | return group;
|
29403 | }
|
29404 |
|
29405 |
|
29406 |
|
29407 |
|
29408 | eventBus.on('create.move', function(event) {
|
29409 |
|
29410 | var context = event.context,
|
29411 | hover = event.hover,
|
29412 | shape = context.shape,
|
29413 | source = context.source,
|
29414 | canExecute;
|
29415 |
|
29416 | var position = {
|
29417 | x: event.x,
|
29418 | y: event.y
|
29419 | };
|
29420 |
|
29421 | canExecute = context.canExecute = hover && canCreate(shape, hover, source, position);
|
29422 |
|
29423 |
|
29424 | if (hover && canExecute !== null) {
|
29425 | context.target = hover;
|
29426 |
|
29427 | if (canExecute && canExecute.attach) {
|
29428 | setMarker(hover, MARKER_ATTACH);
|
29429 | } else {
|
29430 | setMarker(hover, canExecute ? MARKER_NEW_PARENT : MARKER_NOT_OK$2);
|
29431 | }
|
29432 | }
|
29433 | });
|
29434 |
|
29435 | eventBus.on('create.move', LOW_PRIORITY$4, function(event) {
|
29436 |
|
29437 | var context = event.context,
|
29438 | shape = context.shape,
|
29439 | visual = context.visual;
|
29440 |
|
29441 |
|
29442 |
|
29443 | if (!visual) {
|
29444 | visual = context.visual = createVisual(shape);
|
29445 | }
|
29446 |
|
29447 | translate(visual, event.x, event.y);
|
29448 | });
|
29449 |
|
29450 |
|
29451 | eventBus.on([ 'create.end', 'create.out', 'create.cleanup' ], function(event) {
|
29452 | var context = event.context,
|
29453 | target = context.target;
|
29454 |
|
29455 | if (target) {
|
29456 | setMarker(target, null);
|
29457 | }
|
29458 | });
|
29459 |
|
29460 | eventBus.on('create.end', function(event) {
|
29461 | var context = event.context,
|
29462 | source = context.source,
|
29463 | shape = context.shape,
|
29464 | target = context.target,
|
29465 | canExecute = context.canExecute,
|
29466 | attach = canExecute && canExecute.attach,
|
29467 | connect = canExecute && canExecute.connect,
|
29468 | position = {
|
29469 | x: event.x,
|
29470 | y: event.y
|
29471 | };
|
29472 |
|
29473 | if (!canExecute) {
|
29474 | return false;
|
29475 | }
|
29476 |
|
29477 | if (connect) {
|
29478 |
|
29479 | shape = modeling.appendShape(source, shape, position, target, {
|
29480 | attach: attach,
|
29481 | connection: connect === true ? {} : connect
|
29482 | });
|
29483 | } else {
|
29484 |
|
29485 | shape = modeling.createShape(shape, position, target, {
|
29486 | attach: attach
|
29487 | });
|
29488 | }
|
29489 |
|
29490 |
|
29491 |
|
29492 |
|
29493 |
|
29494 | context.shape = shape;
|
29495 | });
|
29496 |
|
29497 |
|
29498 | eventBus.on('create.cleanup', function(event) {
|
29499 | var context = event.context;
|
29500 |
|
29501 | if (context.visual) {
|
29502 | remove$1(context.visual);
|
29503 | }
|
29504 | });
|
29505 |
|
29506 |
|
29507 |
|
29508 | this.start = function(event, shape, source) {
|
29509 |
|
29510 | dragging.init(event, 'create', {
|
29511 | cursor: 'grabbing',
|
29512 | autoActivate: true,
|
29513 | data: {
|
29514 | shape: shape,
|
29515 | context: {
|
29516 | shape: shape,
|
29517 | source: source
|
29518 | }
|
29519 | }
|
29520 | });
|
29521 | };
|
29522 | }
|
29523 |
|
29524 | Create.$inject = [
|
29525 | 'eventBus',
|
29526 | 'dragging',
|
29527 | 'rules',
|
29528 | 'modeling',
|
29529 | 'canvas',
|
29530 | 'styles',
|
29531 | 'graphicsFactory'
|
29532 | ];
|
29533 |
|
29534 | var CreateModule = {
|
29535 | __depends__: [
|
29536 | DraggingModule,
|
29537 | SelectionModule,
|
29538 | RulesModule
|
29539 | ],
|
29540 | create: [ 'type', Create ]
|
29541 | };
|
29542 |
|
29543 | var DATA_REF = 'data-id';
|
29544 |
|
29545 |
|
29546 | |
29547 |
|
29548 |
|
29549 |
|
29550 |
|
29551 |
|
29552 |
|
29553 |
|
29554 |
|
29555 |
|
29556 |
|
29557 |
|
29558 |
|
29559 | function PopupMenu(config, eventBus, canvas) {
|
29560 |
|
29561 | var scale = isDefined(config && config.scale) ? config.scale : {
|
29562 | min: 1,
|
29563 | max: 1.5
|
29564 | };
|
29565 |
|
29566 | this._config = {
|
29567 | scale: scale
|
29568 | };
|
29569 |
|
29570 | this._eventBus = eventBus;
|
29571 | this._canvas = canvas;
|
29572 | this._providers = {};
|
29573 | this._current = {};
|
29574 | }
|
29575 |
|
29576 | PopupMenu.$inject = [
|
29577 | 'config.popupMenu',
|
29578 | 'eventBus',
|
29579 | 'canvas'
|
29580 | ];
|
29581 |
|
29582 | |
29583 |
|
29584 |
|
29585 |
|
29586 |
|
29587 |
|
29588 |
|
29589 |
|
29590 |
|
29591 |
|
29592 |
|
29593 |
|
29594 |
|
29595 |
|
29596 |
|
29597 |
|
29598 |
|
29599 |
|
29600 |
|
29601 |
|
29602 | PopupMenu.prototype.registerProvider = function(id, provider) {
|
29603 | this._providers[id] = provider;
|
29604 | };
|
29605 |
|
29606 |
|
29607 | |
29608 |
|
29609 |
|
29610 |
|
29611 |
|
29612 | PopupMenu.prototype.isEmpty = function(element, providerId) {
|
29613 | if (!element) {
|
29614 | throw new Error('element parameter is missing');
|
29615 | }
|
29616 |
|
29617 | if (!providerId) {
|
29618 | throw new Error('providerId parameter is missing');
|
29619 | }
|
29620 |
|
29621 | var provider = this._providers[providerId];
|
29622 |
|
29623 | var entries = provider.getEntries(element),
|
29624 | headerEntries = provider.getHeaderEntries && provider.getHeaderEntries(element);
|
29625 |
|
29626 | var hasEntries = entries.length > 0,
|
29627 | hasHeaderEntries = headerEntries && headerEntries.length > 0;
|
29628 |
|
29629 | return !hasEntries && !hasHeaderEntries;
|
29630 | };
|
29631 |
|
29632 |
|
29633 | |
29634 |
|
29635 |
|
29636 |
|
29637 |
|
29638 |
|
29639 |
|
29640 |
|
29641 |
|
29642 | PopupMenu.prototype.open = function(element, id, position) {
|
29643 |
|
29644 | var provider = this._providers[id];
|
29645 |
|
29646 | if (!element) {
|
29647 | throw new Error('Element is missing');
|
29648 | }
|
29649 |
|
29650 | if (!provider) {
|
29651 | throw new Error('Provider is not registered: ' + id);
|
29652 | }
|
29653 |
|
29654 | if (!position) {
|
29655 | throw new Error('the position argument is missing');
|
29656 | }
|
29657 |
|
29658 | if (this.isOpen()) {
|
29659 | this.close();
|
29660 | }
|
29661 |
|
29662 | this._emit('open');
|
29663 |
|
29664 | var current = this._current = {
|
29665 | provider: provider,
|
29666 | className: id,
|
29667 | element: element,
|
29668 | position: position
|
29669 | };
|
29670 |
|
29671 | if (provider.getHeaderEntries) {
|
29672 | current.headerEntries = provider.getHeaderEntries(element);
|
29673 | }
|
29674 |
|
29675 | current.entries = provider.getEntries(element);
|
29676 |
|
29677 | current.container = this._createContainer();
|
29678 |
|
29679 | var headerEntries = current.headerEntries || [],
|
29680 | entries = current.entries || [];
|
29681 |
|
29682 | if (headerEntries.length) {
|
29683 | current.container.appendChild(
|
29684 | this._createEntries(current.headerEntries, 'djs-popup-header')
|
29685 | );
|
29686 | }
|
29687 |
|
29688 | if (entries.length) {
|
29689 | current.container.appendChild(
|
29690 | this._createEntries(current.entries, 'djs-popup-body')
|
29691 | );
|
29692 | }
|
29693 |
|
29694 | var canvas = this._canvas,
|
29695 | parent = canvas.getContainer();
|
29696 |
|
29697 | this._attachContainer(current.container, parent, position.cursor);
|
29698 | };
|
29699 |
|
29700 |
|
29701 | |
29702 |
|
29703 |
|
29704 | PopupMenu.prototype.close = function() {
|
29705 |
|
29706 | if (!this.isOpen()) {
|
29707 | return;
|
29708 | }
|
29709 |
|
29710 | this._emit('close');
|
29711 |
|
29712 | this._unbindHandlers();
|
29713 | remove(this._current.container);
|
29714 | this._current.container = null;
|
29715 | };
|
29716 |
|
29717 |
|
29718 | |
29719 |
|
29720 |
|
29721 |
|
29722 |
|
29723 | PopupMenu.prototype.isOpen = function() {
|
29724 | return !!this._current.container;
|
29725 | };
|
29726 |
|
29727 |
|
29728 | |
29729 |
|
29730 |
|
29731 |
|
29732 |
|
29733 |
|
29734 |
|
29735 | PopupMenu.prototype.trigger = function(event) {
|
29736 |
|
29737 |
|
29738 | event.preventDefault();
|
29739 |
|
29740 | var element = event.delegateTarget || event.target,
|
29741 | entryId = attr(element, DATA_REF);
|
29742 |
|
29743 | var entry = this._getEntry(entryId);
|
29744 |
|
29745 | if (entry.action) {
|
29746 | return entry.action.call(null, event, entry);
|
29747 | }
|
29748 | };
|
29749 |
|
29750 | |
29751 |
|
29752 |
|
29753 |
|
29754 |
|
29755 |
|
29756 |
|
29757 | PopupMenu.prototype._getEntry = function(entryId) {
|
29758 |
|
29759 | var search = matchPattern({ id: entryId });
|
29760 |
|
29761 | var entry = find(this._current.entries, search) || find(this._current.headerEntries, search);
|
29762 |
|
29763 | if (!entry) {
|
29764 | throw new Error('entry not found');
|
29765 | }
|
29766 |
|
29767 | return entry;
|
29768 | };
|
29769 |
|
29770 | PopupMenu.prototype._emit = function(eventName) {
|
29771 | this._eventBus.fire('popupMenu.' + eventName);
|
29772 | };
|
29773 |
|
29774 | |
29775 |
|
29776 |
|
29777 |
|
29778 |
|
29779 | PopupMenu.prototype._createContainer = function() {
|
29780 | var container = domify('<div class="djs-popup">'),
|
29781 | position = this._current.position,
|
29782 | className = this._current.className;
|
29783 |
|
29784 | assign(container.style, {
|
29785 | position: 'absolute',
|
29786 | left: position.x + 'px',
|
29787 | top: position.y + 'px',
|
29788 | visibility: 'hidden'
|
29789 | });
|
29790 |
|
29791 | classes(container).add(className);
|
29792 |
|
29793 | return container;
|
29794 | };
|
29795 |
|
29796 |
|
29797 | |
29798 |
|
29799 |
|
29800 |
|
29801 |
|
29802 |
|
29803 | PopupMenu.prototype._attachContainer = function(container, parent, cursor) {
|
29804 | var self = this;
|
29805 |
|
29806 |
|
29807 | delegateEvents.bind(container, '.entry' ,'click', function(event) {
|
29808 | self.trigger(event);
|
29809 | });
|
29810 |
|
29811 | this._updateScale(container);
|
29812 |
|
29813 |
|
29814 | parent.appendChild(container);
|
29815 |
|
29816 | if (cursor) {
|
29817 | this._assureIsInbounds(container, cursor);
|
29818 | }
|
29819 |
|
29820 |
|
29821 | this._bindHandlers();
|
29822 | };
|
29823 |
|
29824 |
|
29825 | |
29826 |
|
29827 |
|
29828 |
|
29829 |
|
29830 |
|
29831 |
|
29832 | PopupMenu.prototype._updateScale = function(container) {
|
29833 | var zoom = this._canvas.zoom();
|
29834 |
|
29835 | var scaleConfig = this._config.scale,
|
29836 | minScale,
|
29837 | maxScale,
|
29838 | scale = zoom;
|
29839 |
|
29840 | if (scaleConfig !== true) {
|
29841 |
|
29842 | if (scaleConfig === false) {
|
29843 | minScale = 1;
|
29844 | maxScale = 1;
|
29845 | } else {
|
29846 | minScale = scaleConfig.min;
|
29847 | maxScale = scaleConfig.max;
|
29848 | }
|
29849 |
|
29850 | if (isDefined(minScale) && zoom < minScale) {
|
29851 | scale = minScale;
|
29852 | }
|
29853 |
|
29854 | if (isDefined(maxScale) && zoom > maxScale) {
|
29855 | scale = maxScale;
|
29856 | }
|
29857 |
|
29858 | }
|
29859 |
|
29860 | setTransform$1(container, 'scale(' + scale + ')');
|
29861 | };
|
29862 |
|
29863 |
|
29864 | |
29865 |
|
29866 |
|
29867 |
|
29868 |
|
29869 |
|
29870 |
|
29871 |
|
29872 | PopupMenu.prototype._assureIsInbounds = function(container, cursor) {
|
29873 | var canvas = this._canvas,
|
29874 | clientRect = canvas._container.getBoundingClientRect();
|
29875 |
|
29876 | var containerX = container.offsetLeft,
|
29877 | containerY = container.offsetTop,
|
29878 | containerWidth = container.scrollWidth,
|
29879 | containerHeight = container.scrollHeight,
|
29880 | overAxis = {},
|
29881 | left, top;
|
29882 |
|
29883 | var cursorPosition = {
|
29884 | x: cursor.x - clientRect.left,
|
29885 | y: cursor.y - clientRect.top
|
29886 | };
|
29887 |
|
29888 | if (containerX + containerWidth > clientRect.width) {
|
29889 | overAxis.x = true;
|
29890 | }
|
29891 |
|
29892 | if (containerY + containerHeight > clientRect.height) {
|
29893 | overAxis.y = true;
|
29894 | }
|
29895 |
|
29896 | if (overAxis.x && overAxis.y) {
|
29897 | left = cursorPosition.x - containerWidth + 'px';
|
29898 | top = cursorPosition.y - containerHeight + 'px';
|
29899 | } else if (overAxis.x) {
|
29900 | left = cursorPosition.x - containerWidth + 'px';
|
29901 | top = cursorPosition.y + 'px';
|
29902 | } else if (overAxis.y && cursorPosition.y < containerHeight) {
|
29903 | left = cursorPosition.x + 'px';
|
29904 | top = 10 + 'px';
|
29905 | } else if (overAxis.y) {
|
29906 | left = cursorPosition.x + 'px';
|
29907 | top = cursorPosition.y - containerHeight + 'px';
|
29908 | }
|
29909 |
|
29910 | assign(container.style, { left: left, top: top }, { visibility: 'visible', 'z-index': 1000 });
|
29911 | };
|
29912 |
|
29913 |
|
29914 | |
29915 |
|
29916 |
|
29917 |
|
29918 |
|
29919 |
|
29920 |
|
29921 |
|
29922 | PopupMenu.prototype._createEntries = function(entries, className) {
|
29923 |
|
29924 | var entriesContainer = domify('<div>'),
|
29925 | self = this;
|
29926 |
|
29927 | classes(entriesContainer).add(className);
|
29928 |
|
29929 | forEach(entries, function(entry) {
|
29930 | var entryContainer = self._createEntry(entry, entriesContainer);
|
29931 | entriesContainer.appendChild(entryContainer);
|
29932 | });
|
29933 |
|
29934 | return entriesContainer;
|
29935 | };
|
29936 |
|
29937 |
|
29938 | |
29939 |
|
29940 |
|
29941 |
|
29942 |
|
29943 |
|
29944 |
|
29945 | PopupMenu.prototype._createEntry = function(entry) {
|
29946 |
|
29947 | if (!entry.id) {
|
29948 | throw new Error ('every entry must have the id property set');
|
29949 | }
|
29950 |
|
29951 | var entryContainer = domify('<div>'),
|
29952 | entryClasses = classes(entryContainer);
|
29953 |
|
29954 | entryClasses.add('entry');
|
29955 |
|
29956 | if (entry.className) {
|
29957 | entry.className.split(' ').forEach(function(className) {
|
29958 | entryClasses.add(className);
|
29959 | });
|
29960 | }
|
29961 |
|
29962 | attr(entryContainer, DATA_REF, entry.id);
|
29963 |
|
29964 | if (entry.label) {
|
29965 | var label = domify('<span>');
|
29966 | label.textContent = entry.label;
|
29967 | entryContainer.appendChild(label);
|
29968 | }
|
29969 |
|
29970 | if (entry.imageUrl) {
|
29971 | entryContainer.appendChild(domify('<img src="' + entry.imageUrl + '" />'));
|
29972 | }
|
29973 |
|
29974 | if (entry.active === true) {
|
29975 | entryClasses.add('active');
|
29976 | }
|
29977 |
|
29978 | if (entry.disabled === true) {
|
29979 | entryClasses.add('disabled');
|
29980 | }
|
29981 |
|
29982 | if (entry.title) {
|
29983 | entryContainer.title = entry.title;
|
29984 | }
|
29985 |
|
29986 | return entryContainer;
|
29987 | };
|
29988 |
|
29989 |
|
29990 | |
29991 |
|
29992 |
|
29993 | PopupMenu.prototype._bindHandlers = function() {
|
29994 |
|
29995 | var eventBus = this._eventBus,
|
29996 | self = this;
|
29997 |
|
29998 | function close() {
|
29999 | self.close();
|
30000 | }
|
30001 |
|
30002 | eventBus.once('contextPad.close', close);
|
30003 | eventBus.once('canvas.viewbox.changing', close);
|
30004 | eventBus.once('commandStack.changed', close);
|
30005 | };
|
30006 |
|
30007 |
|
30008 | |
30009 |
|
30010 |
|
30011 | PopupMenu.prototype._unbindHandlers = function() {
|
30012 |
|
30013 | var eventBus = this._eventBus,
|
30014 | self = this;
|
30015 |
|
30016 | function close() {
|
30017 | self.close();
|
30018 | }
|
30019 |
|
30020 | eventBus.off('contextPad.close', close);
|
30021 | eventBus.off('canvas.viewbox.changed', close);
|
30022 | eventBus.off('commandStack.changed', close);
|
30023 | };
|
30024 |
|
30025 |
|
30026 |
|
30027 |
|
30028 |
|
30029 | function setTransform$1(element, transform) {
|
30030 | element.style['transform-origin'] = 'top left';
|
30031 |
|
30032 | [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
|
30033 | element.style[prefix + 'transform'] = transform;
|
30034 | });
|
30035 | }
|
30036 |
|
30037 | var PopupMenuModule = {
|
30038 | __init__: [ 'popupMenu' ],
|
30039 | popupMenu: [ 'type', PopupMenu ]
|
30040 | };
|
30041 |
|
30042 | var round$5 = Math.round;
|
30043 |
|
30044 | |
30045 |
|
30046 |
|
30047 | function Replace(modeling) {
|
30048 |
|
30049 | this._modeling = modeling;
|
30050 | }
|
30051 |
|
30052 | Replace.$inject = [ 'modeling' ];
|
30053 |
|
30054 | |
30055 |
|
30056 |
|
30057 |
|
30058 |
|
30059 |
|
30060 |
|
30061 |
|
30062 | Replace.prototype.replaceElement = function(oldElement, newElementData, options) {
|
30063 |
|
30064 | var modeling = this._modeling;
|
30065 |
|
30066 | var newElement = null;
|
30067 |
|
30068 | if (oldElement.waypoints) ; else {
|
30069 |
|
30070 |
|
30071 | newElementData.x = round$5(oldElement.x + (newElementData.width || oldElement.width) / 2);
|
30072 | newElementData.y = round$5(oldElement.y + (newElementData.height || oldElement.height) / 2);
|
30073 |
|
30074 | newElement = modeling.replaceShape(oldElement, newElementData, options);
|
30075 | }
|
30076 |
|
30077 | return newElement;
|
30078 | };
|
30079 |
|
30080 | var ReplaceModule = {
|
30081 | __init__: [ 'replace' ],
|
30082 | replace: [ 'type', Replace ]
|
30083 | };
|
30084 |
|
30085 | |
30086 |
|
30087 |
|
30088 |
|
30089 |
|
30090 | var IGNORED_PROPERTIES = [
|
30091 | 'lanes',
|
30092 | 'incoming',
|
30093 | 'outgoing',
|
30094 | 'artifacts',
|
30095 | 'default',
|
30096 | 'flowElements',
|
30097 | 'dataInputAssociations',
|
30098 | 'dataOutputAssociations'
|
30099 | ];
|
30100 |
|
30101 |
|
30102 | function getProperties(descriptor, keepDefault) {
|
30103 | var properties = [];
|
30104 |
|
30105 | forEach(descriptor.properties, function(property) {
|
30106 |
|
30107 | if (keepDefault && property.default) {
|
30108 | return;
|
30109 | }
|
30110 |
|
30111 | properties.push(property.ns.name);
|
30112 | });
|
30113 |
|
30114 | return properties;
|
30115 | }
|
30116 |
|
30117 | function isAllowedIn(extProp, type) {
|
30118 | var allowedIn = extProp.meta.allowedIn;
|
30119 |
|
30120 |
|
30121 | if (allowedIn.length === 1 && allowedIn[0] === '*') {
|
30122 | return true;
|
30123 | }
|
30124 |
|
30125 | return allowedIn.indexOf(type) !== -1;
|
30126 | }
|
30127 |
|
30128 | function isType(element, types) {
|
30129 | return some(types, function(type) {
|
30130 | return typeof element === type;
|
30131 | });
|
30132 | }
|
30133 |
|
30134 | |
30135 |
|
30136 |
|
30137 |
|
30138 | function ModelCloneHelper(eventBus, bpmnFactory) {
|
30139 | this._eventBus = eventBus;
|
30140 | this._bpmnFactory = bpmnFactory;
|
30141 | }
|
30142 |
|
30143 |
|
30144 | ModelCloneHelper.prototype.clone = function(refElement, newElement, properties) {
|
30145 |
|
30146 | var self = this;
|
30147 |
|
30148 |
|
30149 |
|
30150 | var context = {
|
30151 | newElement: newElement,
|
30152 | hasNestedProperty: false
|
30153 | };
|
30154 |
|
30155 |
|
30156 |
|
30157 | properties = sortBy(properties, function(prop) {
|
30158 | return prop === 'bpmn:extensionElements';
|
30159 | });
|
30160 |
|
30161 | forEach(properties, function(propName) {
|
30162 | var refElementProp = refElement.get(propName),
|
30163 | newElementProp = newElement.get(propName),
|
30164 | propDescriptor = newElement.$model.getPropertyDescriptor(newElement, propName),
|
30165 | newProperty, name;
|
30166 |
|
30167 |
|
30168 |
|
30169 |
|
30170 |
|
30171 | if (newElementProp === refElementProp) {
|
30172 | return;
|
30173 | }
|
30174 |
|
30175 | if (propDescriptor && (propDescriptor.isId || propDescriptor.isReference)) {
|
30176 | return;
|
30177 | }
|
30178 |
|
30179 |
|
30180 | if (isType(refElementProp, [ 'boolean', 'string', 'number' ]) || refElementProp === null) {
|
30181 | newElement.set(propName, refElementProp);
|
30182 |
|
30183 | return;
|
30184 | }
|
30185 |
|
30186 | if (isArray(refElementProp)) {
|
30187 |
|
30188 | forEach(refElementProp, function(extElement) {
|
30189 | var newProp;
|
30190 |
|
30191 | context.refTopLevelProperty = extElement;
|
30192 |
|
30193 | newProp = self._deepClone(extElement, context);
|
30194 |
|
30195 | if (context.hasNestedProperty) {
|
30196 | newProp.$parent = newElement;
|
30197 |
|
30198 | newElementProp.push(newProp);
|
30199 | }
|
30200 |
|
30201 | context.hasNestedProperty = false;
|
30202 | });
|
30203 |
|
30204 | } else {
|
30205 | name = propName.replace(/bpmn:/, '');
|
30206 |
|
30207 | context.refTopLevelProperty = refElementProp;
|
30208 |
|
30209 | newProperty = self._deepClone(refElementProp, context);
|
30210 |
|
30211 | if (context.hasNestedProperty) {
|
30212 | newProperty.$parent = newElement;
|
30213 |
|
30214 | newElement.set(name, newProperty);
|
30215 | }
|
30216 |
|
30217 | context.hasNestedProperty = false;
|
30218 | }
|
30219 | });
|
30220 |
|
30221 | return newElement;
|
30222 | };
|
30223 |
|
30224 | ModelCloneHelper.prototype._deepClone = function _deepClone(propertyElement, context) {
|
30225 | var self = this;
|
30226 |
|
30227 | var eventBus = this._eventBus;
|
30228 | var bpmnFactory = this._bpmnFactory;
|
30229 |
|
30230 | var newProp = bpmnFactory.create(propertyElement.$type);
|
30231 |
|
30232 | var properties = filter(Object.keys(propertyElement), function(prop) {
|
30233 | var descriptor = newProp.$model.getPropertyDescriptor(newProp, prop);
|
30234 |
|
30235 | if (descriptor && (descriptor.isId || descriptor.isReference)) {
|
30236 | return false;
|
30237 | }
|
30238 |
|
30239 |
|
30240 |
|
30241 | if (IGNORED_PROPERTIES.indexOf(prop) !== -1) {
|
30242 | return false;
|
30243 | }
|
30244 |
|
30245 |
|
30246 | return prop !== '$type';
|
30247 | });
|
30248 |
|
30249 | if (!properties.length) {
|
30250 | context.hasNestedProperty = true;
|
30251 | }
|
30252 |
|
30253 | forEach(properties, function(propName) {
|
30254 |
|
30255 | if (propertyElement[propName] !== undefined &&
|
30256 | (propertyElement[propName].$type || isArray(propertyElement[propName]))) {
|
30257 |
|
30258 | if (isArray(propertyElement[propName])) {
|
30259 | newProp[propName] = [];
|
30260 |
|
30261 | forEach(propertyElement[propName], function(property) {
|
30262 | var extProp = propertyElement.$model.getTypeDescriptor(property.$type),
|
30263 | newDeepProp;
|
30264 |
|
30265 |
|
30266 | if (!extProp) {
|
30267 | return;
|
30268 | }
|
30269 |
|
30270 | var canClone = eventBus.fire('property.clone', {
|
30271 | newElement: context.newElement,
|
30272 | refTopLevelProperty: context.refTopLevelProperty,
|
30273 | propertyDescriptor: extProp
|
30274 | });
|
30275 |
|
30276 | if (!canClone) {
|
30277 |
|
30278 |
|
30279 | if (propertyElement.$type === 'bpmn:ExtensionElements' &&
|
30280 | extProp.meta && extProp.meta.allowedIn &&
|
30281 | !isAllowedIn(extProp, context.newElement.$type)) {
|
30282 | return false;
|
30283 | }
|
30284 | }
|
30285 |
|
30286 | newDeepProp = self._deepClone(property, context);
|
30287 |
|
30288 | newDeepProp.$parent = newProp;
|
30289 |
|
30290 | if (!newProp[propName]) {
|
30291 | newProp[propName] = [];
|
30292 | }
|
30293 |
|
30294 | context.hasNestedProperty = true;
|
30295 |
|
30296 | newProp[propName].push(newDeepProp);
|
30297 | });
|
30298 |
|
30299 | } else if (propertyElement[propName].$type) {
|
30300 | newProp[propName] = self._deepClone(propertyElement[propName], context);
|
30301 |
|
30302 | if (newProp[propName]) {
|
30303 | context.hasNestedProperty = true;
|
30304 |
|
30305 | newProp[propName].$parent = newProp;
|
30306 | }
|
30307 | }
|
30308 | } else {
|
30309 | context.hasNestedProperty = true;
|
30310 |
|
30311 |
|
30312 | newProp[propName] = propertyElement[propName];
|
30313 | }
|
30314 | });
|
30315 |
|
30316 | return newProp;
|
30317 | };
|
30318 |
|
30319 | var CUSTOM_PROPERTIES = [
|
30320 | 'cancelActivity',
|
30321 | 'instantiate',
|
30322 | 'eventGatewayType',
|
30323 | 'triggeredByEvent',
|
30324 | 'isInterrupting'
|
30325 | ];
|
30326 |
|
30327 |
|
30328 | function toggeling(element, target) {
|
30329 |
|
30330 | var oldCollapsed = (
|
30331 | element && has(element, 'collapsed') ? element.collapsed : !isExpanded(element)
|
30332 | );
|
30333 |
|
30334 | var targetCollapsed;
|
30335 |
|
30336 | if (target && (has(target, 'collapsed') || has(target, 'isExpanded'))) {
|
30337 |
|
30338 | targetCollapsed = (
|
30339 | has(target, 'collapsed') ? target.collapsed : !target.isExpanded
|
30340 | );
|
30341 | } else {
|
30342 |
|
30343 | targetCollapsed = oldCollapsed;
|
30344 | }
|
30345 |
|
30346 | if (oldCollapsed !== targetCollapsed) {
|
30347 | element.collapsed = oldCollapsed;
|
30348 | return true;
|
30349 | }
|
30350 |
|
30351 | return false;
|
30352 | }
|
30353 |
|
30354 |
|
30355 |
|
30356 | |
30357 |
|
30358 |
|
30359 | function BpmnReplace(
|
30360 | bpmnFactory, replace, selection,
|
30361 | modeling, eventBus) {
|
30362 |
|
30363 | var helper = new ModelCloneHelper(eventBus, bpmnFactory);
|
30364 |
|
30365 | |
30366 |
|
30367 |
|
30368 |
|
30369 |
|
30370 |
|
30371 |
|
30372 |
|
30373 |
|
30374 |
|
30375 | function replaceElement(element, target, hints) {
|
30376 |
|
30377 | hints = hints || {};
|
30378 |
|
30379 | var type = target.type,
|
30380 | oldBusinessObject = element.businessObject;
|
30381 |
|
30382 | if (isSubProcess(oldBusinessObject)) {
|
30383 | if (type === 'bpmn:SubProcess') {
|
30384 | if (toggeling(element, target)) {
|
30385 |
|
30386 | modeling.toggleCollapse(element);
|
30387 |
|
30388 | return element;
|
30389 | }
|
30390 | }
|
30391 | }
|
30392 |
|
30393 | var newBusinessObject = bpmnFactory.create(type);
|
30394 |
|
30395 | var newElement = {
|
30396 | type: type,
|
30397 | businessObject: newBusinessObject
|
30398 | };
|
30399 |
|
30400 | var elementProps = getProperties(oldBusinessObject.$descriptor),
|
30401 | newElementProps = getProperties(newBusinessObject.$descriptor, true),
|
30402 | copyProps = intersection(elementProps, newElementProps);
|
30403 |
|
30404 |
|
30405 | assign(newBusinessObject, pick(target, CUSTOM_PROPERTIES));
|
30406 |
|
30407 | var properties = filter(copyProps, function(property) {
|
30408 | var propName = property.replace(/bpmn:/, '');
|
30409 |
|
30410 |
|
30411 | if (propName === 'eventDefinitions') {
|
30412 | return hasEventDefinition$1(element, target.eventDefinitionType);
|
30413 | }
|
30414 |
|
30415 |
|
30416 |
|
30417 | if (propName === 'loopCharacteristics') {
|
30418 | return !isEventSubProcess(newBusinessObject);
|
30419 | }
|
30420 |
|
30421 |
|
30422 | if (property in newBusinessObject) {
|
30423 | return false;
|
30424 | }
|
30425 |
|
30426 | if (propName === 'processRef' && target.isExpanded === false) {
|
30427 | return false;
|
30428 | }
|
30429 |
|
30430 | if (propName === 'triggeredByEvent') {
|
30431 | return false;
|
30432 | }
|
30433 |
|
30434 | return IGNORED_PROPERTIES.indexOf(propName) === -1;
|
30435 | });
|
30436 |
|
30437 | newBusinessObject = helper.clone(oldBusinessObject, newBusinessObject, properties);
|
30438 |
|
30439 |
|
30440 | if (target.eventDefinitionType) {
|
30441 |
|
30442 |
|
30443 |
|
30444 |
|
30445 | if (!hasEventDefinition$1(newBusinessObject, target.eventDefinitionType)) {
|
30446 | newElement.eventDefinitionType = target.eventDefinitionType;
|
30447 | }
|
30448 | }
|
30449 |
|
30450 | if (is$1(oldBusinessObject, 'bpmn:Activity')) {
|
30451 |
|
30452 | if (isSubProcess(oldBusinessObject)) {
|
30453 |
|
30454 | newElement.isExpanded = isExpanded(oldBusinessObject);
|
30455 | }
|
30456 |
|
30457 | else if (target && has(target, 'isExpanded')) {
|
30458 | newElement.isExpanded = target.isExpanded;
|
30459 | }
|
30460 |
|
30461 |
|
30462 |
|
30463 |
|
30464 | if ((isExpanded(oldBusinessObject) && !is$1(oldBusinessObject, 'bpmn:Task')) && newElement.isExpanded) {
|
30465 | newElement.width = element.width;
|
30466 | newElement.height = element.height;
|
30467 | }
|
30468 | }
|
30469 |
|
30470 |
|
30471 | if (isSubProcess(oldBusinessObject) && !isSubProcess(newBusinessObject)) {
|
30472 | hints.moveChildren = false;
|
30473 | }
|
30474 |
|
30475 |
|
30476 | if (is$1(oldBusinessObject, 'bpmn:Participant')) {
|
30477 |
|
30478 |
|
30479 | if (target.isExpanded === true) {
|
30480 | newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
30481 | } else {
|
30482 |
|
30483 | hints.moveChildren = false;
|
30484 | }
|
30485 |
|
30486 |
|
30487 | newElement.width = element.width;
|
30488 | newElement.height = element.height;
|
30489 | }
|
30490 |
|
30491 | newBusinessObject.name = oldBusinessObject.name;
|
30492 |
|
30493 |
|
30494 | if (
|
30495 | isAny(oldBusinessObject, [
|
30496 | 'bpmn:ExclusiveGateway',
|
30497 | 'bpmn:InclusiveGateway',
|
30498 | 'bpmn:Activity'
|
30499 | ]) &&
|
30500 | isAny(newBusinessObject, [
|
30501 | 'bpmn:ExclusiveGateway',
|
30502 | 'bpmn:InclusiveGateway',
|
30503 | 'bpmn:Activity'
|
30504 | ])
|
30505 | ) {
|
30506 | newBusinessObject.default = oldBusinessObject.default;
|
30507 | }
|
30508 |
|
30509 | if ('fill' in oldBusinessObject.di || 'stroke' in oldBusinessObject.di) {
|
30510 | assign(newElement, { colors: pick(oldBusinessObject.di, [ 'fill', 'stroke' ]) });
|
30511 | }
|
30512 |
|
30513 | newElement = replace.replaceElement(element, newElement, hints);
|
30514 |
|
30515 | if (hints.select !== false) {
|
30516 | selection.select(newElement);
|
30517 | }
|
30518 |
|
30519 | return newElement;
|
30520 | }
|
30521 |
|
30522 | this.replaceElement = replaceElement;
|
30523 | }
|
30524 |
|
30525 | BpmnReplace.$inject = [
|
30526 | 'bpmnFactory',
|
30527 | 'replace',
|
30528 | 'selection',
|
30529 | 'modeling',
|
30530 | 'eventBus'
|
30531 | ];
|
30532 |
|
30533 |
|
30534 | function isSubProcess(bo) {
|
30535 | return is$1(bo, 'bpmn:SubProcess');
|
30536 | }
|
30537 |
|
30538 | function hasEventDefinition$1(element, type) {
|
30539 |
|
30540 | var bo = getBusinessObject(element);
|
30541 |
|
30542 | return type && bo.get('eventDefinitions').some(function(definition) {
|
30543 | return is$1(definition, type);
|
30544 | });
|
30545 | }
|
30546 |
|
30547 | |
30548 |
|
30549 |
|
30550 | function intersection(a1, a2) {
|
30551 | return a1.filter(function(el) {
|
30552 | return a2.indexOf(el) !== -1;
|
30553 | });
|
30554 | }
|
30555 |
|
30556 | var ReplaceModule$1 = {
|
30557 | __depends__: [
|
30558 | SelectionModule,
|
30559 | ReplaceModule
|
30560 | ],
|
30561 | bpmnReplace: [ 'type', BpmnReplace ]
|
30562 | };
|
30563 |
|
30564 | |
30565 |
|
30566 |
|
30567 |
|
30568 |
|
30569 |
|
30570 |
|
30571 |
|
30572 |
|
30573 | function isDifferentType(element) {
|
30574 |
|
30575 | return function(entry) {
|
30576 | var target = entry.target;
|
30577 |
|
30578 | var businessObject = getBusinessObject(element),
|
30579 | eventDefinition = businessObject.eventDefinitions && businessObject.eventDefinitions[0];
|
30580 |
|
30581 | var isTypeEqual = businessObject.$type === target.type;
|
30582 |
|
30583 | var isEventDefinitionEqual = (
|
30584 | (eventDefinition && eventDefinition.$type) === target.eventDefinitionType
|
30585 | );
|
30586 |
|
30587 | var isTriggeredByEventEqual = (
|
30588 | businessObject.triggeredByEvent === target.triggeredByEvent
|
30589 | );
|
30590 |
|
30591 | var isExpandedEqual = (
|
30592 | target.isExpanded === undefined ||
|
30593 | target.isExpanded === isExpanded(businessObject)
|
30594 | );
|
30595 |
|
30596 | return !isTypeEqual || !isEventDefinitionEqual || !isTriggeredByEventEqual || !isExpandedEqual;
|
30597 | };
|
30598 | }
|
30599 |
|
30600 | var START_EVENT = [
|
30601 | {
|
30602 | label: 'Start Event',
|
30603 | actionName: 'replace-with-none-start',
|
30604 | className: 'bpmn-icon-start-event-none',
|
30605 | target: {
|
30606 | type: 'bpmn:StartEvent'
|
30607 | }
|
30608 | },
|
30609 | {
|
30610 | label: 'Intermediate Throw Event',
|
30611 | actionName: 'replace-with-none-intermediate-throwing',
|
30612 | className: 'bpmn-icon-intermediate-event-none',
|
30613 | target: {
|
30614 | type: 'bpmn:IntermediateThrowEvent'
|
30615 | }
|
30616 | },
|
30617 | {
|
30618 | label: 'End Event',
|
30619 | actionName: 'replace-with-none-end',
|
30620 | className: 'bpmn-icon-end-event-none',
|
30621 | target: {
|
30622 | type: 'bpmn:EndEvent'
|
30623 | }
|
30624 | },
|
30625 | {
|
30626 | label: 'Message Start Event',
|
30627 | actionName: 'replace-with-message-start',
|
30628 | className: 'bpmn-icon-start-event-message',
|
30629 | target: {
|
30630 | type: 'bpmn:StartEvent',
|
30631 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
30632 | }
|
30633 | },
|
30634 | {
|
30635 | label: 'Timer Start Event',
|
30636 | actionName: 'replace-with-timer-start',
|
30637 | className: 'bpmn-icon-start-event-timer',
|
30638 | target: {
|
30639 | type: 'bpmn:StartEvent',
|
30640 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
30641 | }
|
30642 | },
|
30643 | {
|
30644 | label: 'Conditional Start Event',
|
30645 | actionName: 'replace-with-conditional-start',
|
30646 | className: 'bpmn-icon-start-event-condition',
|
30647 | target: {
|
30648 | type: 'bpmn:StartEvent',
|
30649 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
30650 | }
|
30651 | },
|
30652 | {
|
30653 | label: 'Signal Start Event',
|
30654 | actionName: 'replace-with-signal-start',
|
30655 | className: 'bpmn-icon-start-event-signal',
|
30656 | target: {
|
30657 | type: 'bpmn:StartEvent',
|
30658 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
30659 | }
|
30660 | }
|
30661 | ];
|
30662 |
|
30663 | var INTERMEDIATE_EVENT = [
|
30664 | {
|
30665 | label: 'Start Event',
|
30666 | actionName: 'replace-with-none-start',
|
30667 | className: 'bpmn-icon-start-event-none',
|
30668 | target: {
|
30669 | type: 'bpmn:StartEvent'
|
30670 | }
|
30671 | },
|
30672 | {
|
30673 | label: 'Intermediate Throw Event',
|
30674 | actionName: 'replace-with-none-intermediate-throw',
|
30675 | className: 'bpmn-icon-intermediate-event-none',
|
30676 | target: {
|
30677 | type: 'bpmn:IntermediateThrowEvent'
|
30678 | }
|
30679 | },
|
30680 | {
|
30681 | label: 'End Event',
|
30682 | actionName: 'replace-with-none-end',
|
30683 | className: 'bpmn-icon-end-event-none',
|
30684 | target: {
|
30685 | type: 'bpmn:EndEvent'
|
30686 | }
|
30687 | },
|
30688 | {
|
30689 | label: 'Message Intermediate Catch Event',
|
30690 | actionName: 'replace-with-message-intermediate-catch',
|
30691 | className: 'bpmn-icon-intermediate-event-catch-message',
|
30692 | target: {
|
30693 | type: 'bpmn:IntermediateCatchEvent',
|
30694 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
30695 | }
|
30696 | },
|
30697 | {
|
30698 | label: 'Message Intermediate Throw Event',
|
30699 | actionName: 'replace-with-message-intermediate-throw',
|
30700 | className: 'bpmn-icon-intermediate-event-throw-message',
|
30701 | target: {
|
30702 | type: 'bpmn:IntermediateThrowEvent',
|
30703 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
30704 | }
|
30705 | },
|
30706 | {
|
30707 | label: 'Timer Intermediate Catch Event',
|
30708 | actionName: 'replace-with-timer-intermediate-catch',
|
30709 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
30710 | target: {
|
30711 | type: 'bpmn:IntermediateCatchEvent',
|
30712 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
30713 | }
|
30714 | },
|
30715 | {
|
30716 | label: 'Escalation Intermediate Throw Event',
|
30717 | actionName: 'replace-with-escalation-intermediate-throw',
|
30718 | className: 'bpmn-icon-intermediate-event-throw-escalation',
|
30719 | target: {
|
30720 | type: 'bpmn:IntermediateThrowEvent',
|
30721 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
30722 | }
|
30723 | },
|
30724 | {
|
30725 | label: 'Conditional Intermediate Catch Event',
|
30726 | actionName: 'replace-with-conditional-intermediate-catch',
|
30727 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
30728 | target: {
|
30729 | type: 'bpmn:IntermediateCatchEvent',
|
30730 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
30731 | }
|
30732 | },
|
30733 | {
|
30734 | label: 'Link Intermediate Catch Event',
|
30735 | actionName: 'replace-with-link-intermediate-catch',
|
30736 | className: 'bpmn-icon-intermediate-event-catch-link',
|
30737 | target: {
|
30738 | type: 'bpmn:IntermediateCatchEvent',
|
30739 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
30740 | }
|
30741 | },
|
30742 | {
|
30743 | label: 'Link Intermediate Throw Event',
|
30744 | actionName: 'replace-with-link-intermediate-throw',
|
30745 | className: 'bpmn-icon-intermediate-event-throw-link',
|
30746 | target: {
|
30747 | type: 'bpmn:IntermediateThrowEvent',
|
30748 | eventDefinitionType: 'bpmn:LinkEventDefinition'
|
30749 | }
|
30750 | },
|
30751 | {
|
30752 | label: 'Compensation Intermediate Throw Event',
|
30753 | actionName: 'replace-with-compensation-intermediate-throw',
|
30754 | className: 'bpmn-icon-intermediate-event-throw-compensation',
|
30755 | target: {
|
30756 | type: 'bpmn:IntermediateThrowEvent',
|
30757 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
30758 | }
|
30759 | },
|
30760 | {
|
30761 | label: 'Signal Intermediate Catch Event',
|
30762 | actionName: 'replace-with-signal-intermediate-catch',
|
30763 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
30764 | target: {
|
30765 | type: 'bpmn:IntermediateCatchEvent',
|
30766 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
30767 | }
|
30768 | },
|
30769 | {
|
30770 | label: 'Signal Intermediate Throw Event',
|
30771 | actionName: 'replace-with-signal-intermediate-throw',
|
30772 | className: 'bpmn-icon-intermediate-event-throw-signal',
|
30773 | target: {
|
30774 | type: 'bpmn:IntermediateThrowEvent',
|
30775 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
30776 | }
|
30777 | }
|
30778 | ];
|
30779 |
|
30780 | var END_EVENT = [
|
30781 | {
|
30782 | label: 'Start Event',
|
30783 | actionName: 'replace-with-none-start',
|
30784 | className: 'bpmn-icon-start-event-none',
|
30785 | target: {
|
30786 | type: 'bpmn:StartEvent'
|
30787 | }
|
30788 | },
|
30789 | {
|
30790 | label: 'Intermediate Throw Event',
|
30791 | actionName: 'replace-with-none-intermediate-throw',
|
30792 | className: 'bpmn-icon-intermediate-event-none',
|
30793 | target: {
|
30794 | type: 'bpmn:IntermediateThrowEvent'
|
30795 | }
|
30796 | },
|
30797 | {
|
30798 | label: 'End Event',
|
30799 | actionName: 'replace-with-none-end',
|
30800 | className: 'bpmn-icon-end-event-none',
|
30801 | target: {
|
30802 | type: 'bpmn:EndEvent'
|
30803 | }
|
30804 | },
|
30805 | {
|
30806 | label: 'Message End Event',
|
30807 | actionName: 'replace-with-message-end',
|
30808 | className: 'bpmn-icon-end-event-message',
|
30809 | target: {
|
30810 | type: 'bpmn:EndEvent',
|
30811 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
30812 | }
|
30813 | },
|
30814 | {
|
30815 | label: 'Escalation End Event',
|
30816 | actionName: 'replace-with-escalation-end',
|
30817 | className: 'bpmn-icon-end-event-escalation',
|
30818 | target: {
|
30819 | type: 'bpmn:EndEvent',
|
30820 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
30821 | }
|
30822 | },
|
30823 | {
|
30824 | label: 'Error End Event',
|
30825 | actionName: 'replace-with-error-end',
|
30826 | className: 'bpmn-icon-end-event-error',
|
30827 | target: {
|
30828 | type: 'bpmn:EndEvent',
|
30829 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
30830 | }
|
30831 | },
|
30832 | {
|
30833 | label: 'Cancel End Event',
|
30834 | actionName: 'replace-with-cancel-end',
|
30835 | className: 'bpmn-icon-end-event-cancel',
|
30836 | target: {
|
30837 | type: 'bpmn:EndEvent',
|
30838 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
30839 | }
|
30840 | },
|
30841 | {
|
30842 | label: 'Compensation End Event',
|
30843 | actionName: 'replace-with-compensation-end',
|
30844 | className: 'bpmn-icon-end-event-compensation',
|
30845 | target: {
|
30846 | type: 'bpmn:EndEvent',
|
30847 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
30848 | }
|
30849 | },
|
30850 | {
|
30851 | label: 'Signal End Event',
|
30852 | actionName: 'replace-with-signal-end',
|
30853 | className: 'bpmn-icon-end-event-signal',
|
30854 | target: {
|
30855 | type: 'bpmn:EndEvent',
|
30856 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
30857 | }
|
30858 | },
|
30859 | {
|
30860 | label: 'Terminate End Event',
|
30861 | actionName: 'replace-with-terminate-end',
|
30862 | className: 'bpmn-icon-end-event-terminate',
|
30863 | target: {
|
30864 | type: 'bpmn:EndEvent',
|
30865 | eventDefinitionType: 'bpmn:TerminateEventDefinition'
|
30866 | }
|
30867 | }
|
30868 | ];
|
30869 |
|
30870 | var GATEWAY = [
|
30871 | {
|
30872 | label: 'Exclusive Gateway',
|
30873 | actionName: 'replace-with-exclusive-gateway',
|
30874 | className: 'bpmn-icon-gateway-xor',
|
30875 | target: {
|
30876 | type: 'bpmn:ExclusiveGateway'
|
30877 | }
|
30878 | },
|
30879 | {
|
30880 | label: 'Parallel Gateway',
|
30881 | actionName: 'replace-with-parallel-gateway',
|
30882 | className: 'bpmn-icon-gateway-parallel',
|
30883 | target: {
|
30884 | type: 'bpmn:ParallelGateway'
|
30885 | }
|
30886 | },
|
30887 | {
|
30888 | label: 'Inclusive Gateway',
|
30889 | actionName: 'replace-with-inclusive-gateway',
|
30890 | className: 'bpmn-icon-gateway-or',
|
30891 | target: {
|
30892 | type: 'bpmn:InclusiveGateway'
|
30893 | }
|
30894 | },
|
30895 | {
|
30896 | label: 'Complex Gateway',
|
30897 | actionName: 'replace-with-complex-gateway',
|
30898 | className: 'bpmn-icon-gateway-complex',
|
30899 | target: {
|
30900 | type: 'bpmn:ComplexGateway'
|
30901 | }
|
30902 | },
|
30903 | {
|
30904 | label: 'Event based Gateway',
|
30905 | actionName: 'replace-with-event-based-gateway',
|
30906 | className: 'bpmn-icon-gateway-eventbased',
|
30907 | target: {
|
30908 | type: 'bpmn:EventBasedGateway',
|
30909 | instantiate: false,
|
30910 | eventGatewayType: 'Exclusive'
|
30911 | }
|
30912 | }
|
30913 |
|
30914 |
|
30915 |
|
30916 |
|
30917 |
|
30918 |
|
30919 |
|
30920 |
|
30921 |
|
30922 |
|
30923 |
|
30924 |
|
30925 |
|
30926 |
|
30927 |
|
30928 |
|
30929 |
|
30930 |
|
30931 |
|
30932 |
|
30933 |
|
30934 |
|
30935 |
|
30936 | ];
|
30937 |
|
30938 | var SUBPROCESS_EXPANDED = [
|
30939 | {
|
30940 | label: 'Transaction',
|
30941 | actionName: 'replace-with-transaction',
|
30942 | className: 'bpmn-icon-transaction',
|
30943 | target: {
|
30944 | type: 'bpmn:Transaction',
|
30945 | isExpanded: true
|
30946 | }
|
30947 | },
|
30948 | {
|
30949 | label: 'Event Sub Process',
|
30950 | actionName: 'replace-with-event-subprocess',
|
30951 | className: 'bpmn-icon-event-subprocess-expanded',
|
30952 | target: {
|
30953 | type: 'bpmn:SubProcess',
|
30954 | triggeredByEvent: true,
|
30955 | isExpanded: true
|
30956 | }
|
30957 | },
|
30958 | {
|
30959 | label: 'Sub Process (collapsed)',
|
30960 | actionName: 'replace-with-collapsed-subprocess',
|
30961 | className: 'bpmn-icon-subprocess-collapsed',
|
30962 | target: {
|
30963 | type: 'bpmn:SubProcess',
|
30964 | isExpanded: false
|
30965 | }
|
30966 | }
|
30967 | ];
|
30968 |
|
30969 | var TRANSACTION = [
|
30970 | {
|
30971 | label: 'Sub Process',
|
30972 | actionName: 'replace-with-subprocess',
|
30973 | className: 'bpmn-icon-subprocess-expanded',
|
30974 | target: {
|
30975 | type: 'bpmn:SubProcess',
|
30976 | isExpanded: true
|
30977 | }
|
30978 | },
|
30979 | {
|
30980 | label: 'Event Sub Process',
|
30981 | actionName: 'replace-with-event-subprocess',
|
30982 | className: 'bpmn-icon-event-subprocess-expanded',
|
30983 | target: {
|
30984 | type: 'bpmn:SubProcess',
|
30985 | triggeredByEvent: true,
|
30986 | isExpanded: true
|
30987 | }
|
30988 | }
|
30989 | ];
|
30990 |
|
30991 | var EVENT_SUB_PROCESS = [
|
30992 | {
|
30993 | label: 'Sub Process',
|
30994 | actionName: 'replace-with-subprocess',
|
30995 | className: 'bpmn-icon-subprocess-expanded',
|
30996 | target: {
|
30997 | type: 'bpmn:SubProcess',
|
30998 | isExpanded: true
|
30999 | }
|
31000 | },
|
31001 | {
|
31002 | label: 'Transaction',
|
31003 | actionName: 'replace-with-transaction',
|
31004 | className: 'bpmn-icon-transaction',
|
31005 | target: {
|
31006 | type: 'bpmn:Transaction',
|
31007 | isExpanded: true
|
31008 | }
|
31009 | }
|
31010 | ];
|
31011 |
|
31012 | var TASK = [
|
31013 | {
|
31014 | label: 'Task',
|
31015 | actionName: 'replace-with-task',
|
31016 | className: 'bpmn-icon-task',
|
31017 | target: {
|
31018 | type: 'bpmn:Task'
|
31019 | }
|
31020 | },
|
31021 | {
|
31022 | label: 'Send Task',
|
31023 | actionName: 'replace-with-send-task',
|
31024 | className: 'bpmn-icon-send',
|
31025 | target: {
|
31026 | type: 'bpmn:SendTask'
|
31027 | }
|
31028 | },
|
31029 | {
|
31030 | label: 'Receive Task',
|
31031 | actionName: 'replace-with-receive-task',
|
31032 | className: 'bpmn-icon-receive',
|
31033 | target: {
|
31034 | type: 'bpmn:ReceiveTask'
|
31035 | }
|
31036 | },
|
31037 | {
|
31038 | label: 'User Task',
|
31039 | actionName: 'replace-with-user-task',
|
31040 | className: 'bpmn-icon-user',
|
31041 | target: {
|
31042 | type: 'bpmn:UserTask'
|
31043 | }
|
31044 | },
|
31045 | {
|
31046 | label: 'Manual Task',
|
31047 | actionName: 'replace-with-manual-task',
|
31048 | className: 'bpmn-icon-manual',
|
31049 | target: {
|
31050 | type: 'bpmn:ManualTask'
|
31051 | }
|
31052 | },
|
31053 | {
|
31054 | label: 'Business Rule Task',
|
31055 | actionName: 'replace-with-rule-task',
|
31056 | className: 'bpmn-icon-business-rule',
|
31057 | target: {
|
31058 | type: 'bpmn:BusinessRuleTask'
|
31059 | }
|
31060 | },
|
31061 | {
|
31062 | label: 'Service Task',
|
31063 | actionName: 'replace-with-service-task',
|
31064 | className: 'bpmn-icon-service',
|
31065 | target: {
|
31066 | type: 'bpmn:ServiceTask'
|
31067 | }
|
31068 | },
|
31069 | {
|
31070 | label: 'Script Task',
|
31071 | actionName: 'replace-with-script-task',
|
31072 | className: 'bpmn-icon-script',
|
31073 | target: {
|
31074 | type: 'bpmn:ScriptTask'
|
31075 | }
|
31076 | },
|
31077 | {
|
31078 | label: 'Call Activity',
|
31079 | actionName: 'replace-with-call-activity',
|
31080 | className: 'bpmn-icon-call-activity',
|
31081 | target: {
|
31082 | type: 'bpmn:CallActivity'
|
31083 | }
|
31084 | },
|
31085 | {
|
31086 | label: 'Sub Process (collapsed)',
|
31087 | actionName: 'replace-with-collapsed-subprocess',
|
31088 | className: 'bpmn-icon-subprocess-collapsed',
|
31089 | target: {
|
31090 | type: 'bpmn:SubProcess',
|
31091 | isExpanded: false
|
31092 | }
|
31093 | },
|
31094 | {
|
31095 | label: 'Sub Process (expanded)',
|
31096 | actionName: 'replace-with-expanded-subprocess',
|
31097 | className: 'bpmn-icon-subprocess-expanded',
|
31098 | target: {
|
31099 | type: 'bpmn:SubProcess',
|
31100 | isExpanded: true
|
31101 | }
|
31102 | }
|
31103 | ];
|
31104 |
|
31105 | var BOUNDARY_EVENT = [
|
31106 | {
|
31107 | label: 'Message Boundary Event',
|
31108 | actionName: 'replace-with-message-boundary',
|
31109 | className: 'bpmn-icon-intermediate-event-catch-message',
|
31110 | target: {
|
31111 | type: 'bpmn:BoundaryEvent',
|
31112 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
31113 | }
|
31114 | },
|
31115 | {
|
31116 | label: 'Timer Boundary Event',
|
31117 | actionName: 'replace-with-timer-boundary',
|
31118 | className: 'bpmn-icon-intermediate-event-catch-timer',
|
31119 | target: {
|
31120 | type: 'bpmn:BoundaryEvent',
|
31121 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
31122 | }
|
31123 | },
|
31124 | {
|
31125 | label: 'Escalation Boundary Event',
|
31126 | actionName: 'replace-with-escalation-boundary',
|
31127 | className: 'bpmn-icon-intermediate-event-catch-escalation',
|
31128 | target: {
|
31129 | type: 'bpmn:BoundaryEvent',
|
31130 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
31131 | }
|
31132 | },
|
31133 | {
|
31134 | label: 'Conditional Boundary Event',
|
31135 | actionName: 'replace-with-conditional-boundary',
|
31136 | className: 'bpmn-icon-intermediate-event-catch-condition',
|
31137 | target: {
|
31138 | type: 'bpmn:BoundaryEvent',
|
31139 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
31140 | }
|
31141 | },
|
31142 | {
|
31143 | label: 'Error Boundary Event',
|
31144 | actionName: 'replace-with-error-boundary',
|
31145 | className: 'bpmn-icon-intermediate-event-catch-error',
|
31146 | target: {
|
31147 | type: 'bpmn:BoundaryEvent',
|
31148 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
31149 | }
|
31150 | },
|
31151 | {
|
31152 | label: 'Cancel Boundary Event',
|
31153 | actionName: 'replace-with-cancel-boundary',
|
31154 | className: 'bpmn-icon-intermediate-event-catch-cancel',
|
31155 | target: {
|
31156 | type: 'bpmn:BoundaryEvent',
|
31157 | eventDefinitionType: 'bpmn:CancelEventDefinition'
|
31158 | }
|
31159 | },
|
31160 | {
|
31161 | label: 'Signal Boundary Event',
|
31162 | actionName: 'replace-with-signal-boundary',
|
31163 | className: 'bpmn-icon-intermediate-event-catch-signal',
|
31164 | target: {
|
31165 | type: 'bpmn:BoundaryEvent',
|
31166 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
31167 | }
|
31168 | },
|
31169 | {
|
31170 | label: 'Compensation Boundary Event',
|
31171 | actionName: 'replace-with-compensation-boundary',
|
31172 | className: 'bpmn-icon-intermediate-event-catch-compensation',
|
31173 | target: {
|
31174 | type: 'bpmn:BoundaryEvent',
|
31175 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
31176 | }
|
31177 | },
|
31178 | {
|
31179 | label: 'Message Boundary Event (non-interrupting)',
|
31180 | actionName: 'replace-with-non-interrupting-message-boundary',
|
31181 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-message',
|
31182 | target: {
|
31183 | type: 'bpmn:BoundaryEvent',
|
31184 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
31185 | cancelActivity: false
|
31186 | }
|
31187 | },
|
31188 | {
|
31189 | label: 'Timer Boundary Event (non-interrupting)',
|
31190 | actionName: 'replace-with-non-interrupting-timer-boundary',
|
31191 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-timer',
|
31192 | target: {
|
31193 | type: 'bpmn:BoundaryEvent',
|
31194 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
31195 | cancelActivity: false
|
31196 | }
|
31197 | },
|
31198 | {
|
31199 | label: 'Escalation Boundary Event (non-interrupting)',
|
31200 | actionName: 'replace-with-non-interrupting-escalation-boundary',
|
31201 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-escalation',
|
31202 | target: {
|
31203 | type: 'bpmn:BoundaryEvent',
|
31204 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
31205 | cancelActivity: false
|
31206 | }
|
31207 | },
|
31208 | {
|
31209 | label: 'Conditional Boundary Event (non-interrupting)',
|
31210 | actionName: 'replace-with-non-interrupting-conditional-boundary',
|
31211 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-condition',
|
31212 | target: {
|
31213 | type: 'bpmn:BoundaryEvent',
|
31214 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
31215 | cancelActivity: false
|
31216 | }
|
31217 | },
|
31218 | {
|
31219 | label: 'Signal Boundary Event (non-interrupting)',
|
31220 | actionName: 'replace-with-non-interrupting-signal-boundary',
|
31221 | className: 'bpmn-icon-intermediate-event-catch-non-interrupting-signal',
|
31222 | target: {
|
31223 | type: 'bpmn:BoundaryEvent',
|
31224 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
31225 | cancelActivity: false
|
31226 | }
|
31227 | }
|
31228 | ];
|
31229 |
|
31230 | var EVENT_SUB_PROCESS_START_EVENT = [
|
31231 | {
|
31232 | label: 'Message Start Event',
|
31233 | actionName: 'replace-with-message-start',
|
31234 | className: 'bpmn-icon-start-event-message',
|
31235 | target: {
|
31236 | type: 'bpmn:StartEvent',
|
31237 | eventDefinitionType: 'bpmn:MessageEventDefinition'
|
31238 | }
|
31239 | },
|
31240 | {
|
31241 | label: 'Timer Start Event',
|
31242 | actionName: 'replace-with-timer-start',
|
31243 | className: 'bpmn-icon-start-event-timer',
|
31244 | target: {
|
31245 | type: 'bpmn:StartEvent',
|
31246 | eventDefinitionType: 'bpmn:TimerEventDefinition'
|
31247 | }
|
31248 | },
|
31249 | {
|
31250 | label: 'Conditional Start Event',
|
31251 | actionName: 'replace-with-conditional-start',
|
31252 | className: 'bpmn-icon-start-event-condition',
|
31253 | target: {
|
31254 | type: 'bpmn:StartEvent',
|
31255 | eventDefinitionType: 'bpmn:ConditionalEventDefinition'
|
31256 | }
|
31257 | },
|
31258 | {
|
31259 | label: 'Signal Start Event',
|
31260 | actionName: 'replace-with-signal-start',
|
31261 | className: 'bpmn-icon-start-event-signal',
|
31262 | target: {
|
31263 | type: 'bpmn:StartEvent',
|
31264 | eventDefinitionType: 'bpmn:SignalEventDefinition'
|
31265 | }
|
31266 | },
|
31267 | {
|
31268 | label: 'Error Start Event',
|
31269 | actionName: 'replace-with-error-start',
|
31270 | className: 'bpmn-icon-start-event-error',
|
31271 | target: {
|
31272 | type: 'bpmn:StartEvent',
|
31273 | eventDefinitionType: 'bpmn:ErrorEventDefinition'
|
31274 | }
|
31275 | },
|
31276 | {
|
31277 | label: 'Escalation Start Event',
|
31278 | actionName: 'replace-with-escalation-start',
|
31279 | className: 'bpmn-icon-start-event-escalation',
|
31280 | target: {
|
31281 | type: 'bpmn:StartEvent',
|
31282 | eventDefinitionType: 'bpmn:EscalationEventDefinition'
|
31283 | }
|
31284 | },
|
31285 | {
|
31286 | label: 'Compensation Start Event',
|
31287 | actionName: 'replace-with-compensation-start',
|
31288 | className: 'bpmn-icon-start-event-compensation',
|
31289 | target: {
|
31290 | type: 'bpmn:StartEvent',
|
31291 | eventDefinitionType: 'bpmn:CompensateEventDefinition'
|
31292 | }
|
31293 | },
|
31294 | {
|
31295 | label: 'Message Start Event (non-interrupting)',
|
31296 | actionName: 'replace-with-non-interrupting-message-start',
|
31297 | className: 'bpmn-icon-start-event-non-interrupting-message',
|
31298 | target: {
|
31299 | type: 'bpmn:StartEvent',
|
31300 | eventDefinitionType: 'bpmn:MessageEventDefinition',
|
31301 | isInterrupting: false
|
31302 | }
|
31303 | },
|
31304 | {
|
31305 | label: 'Timer Start Event (non-interrupting)',
|
31306 | actionName: 'replace-with-non-interrupting-timer-start',
|
31307 | className: 'bpmn-icon-start-event-non-interrupting-timer',
|
31308 | target: {
|
31309 | type: 'bpmn:StartEvent',
|
31310 | eventDefinitionType: 'bpmn:TimerEventDefinition',
|
31311 | isInterrupting: false
|
31312 | }
|
31313 | },
|
31314 | {
|
31315 | label: 'Conditional Start Event (non-interrupting)',
|
31316 | actionName: 'replace-with-non-interrupting-conditional-start',
|
31317 | className: 'bpmn-icon-start-event-non-interrupting-condition',
|
31318 | target: {
|
31319 | type: 'bpmn:StartEvent',
|
31320 | eventDefinitionType: 'bpmn:ConditionalEventDefinition',
|
31321 | isInterrupting: false
|
31322 | }
|
31323 | },
|
31324 | {
|
31325 | label: 'Signal Start Event (non-interrupting)',
|
31326 | actionName: 'replace-with-non-interrupting-signal-start',
|
31327 | className: 'bpmn-icon-start-event-non-interrupting-signal',
|
31328 | target: {
|
31329 | type: 'bpmn:StartEvent',
|
31330 | eventDefinitionType: 'bpmn:SignalEventDefinition',
|
31331 | isInterrupting: false
|
31332 | }
|
31333 | },
|
31334 | {
|
31335 | label: 'Escalation Start Event (non-interrupting)',
|
31336 | actionName: 'replace-with-non-interrupting-escalation-start',
|
31337 | className: 'bpmn-icon-start-event-non-interrupting-escalation',
|
31338 | target: {
|
31339 | type: 'bpmn:StartEvent',
|
31340 | eventDefinitionType: 'bpmn:EscalationEventDefinition',
|
31341 | isInterrupting: false
|
31342 | }
|
31343 | }
|
31344 | ];
|
31345 |
|
31346 | var SEQUENCE_FLOW = [
|
31347 | {
|
31348 | label: 'Sequence Flow',
|
31349 | actionName: 'replace-with-sequence-flow',
|
31350 | className: 'bpmn-icon-connection'
|
31351 | },
|
31352 | {
|
31353 | label: 'Default Flow',
|
31354 | actionName: 'replace-with-default-flow',
|
31355 | className: 'bpmn-icon-default-flow'
|
31356 | },
|
31357 | {
|
31358 | label: 'Conditional Flow',
|
31359 | actionName: 'replace-with-conditional-flow',
|
31360 | className: 'bpmn-icon-conditional-flow'
|
31361 | }
|
31362 | ];
|
31363 |
|
31364 | var PARTICIPANT = [
|
31365 | {
|
31366 | label: 'Expanded Pool',
|
31367 | actionName: 'replace-with-expanded-pool',
|
31368 | className: 'bpmn-icon-participant',
|
31369 | target: {
|
31370 | type: 'bpmn:Participant',
|
31371 | isExpanded: true
|
31372 | }
|
31373 | },
|
31374 | {
|
31375 | label: 'Collapsed Pool',
|
31376 | actionName: 'replace-with-collapsed-pool',
|
31377 |
|
31378 | className: 'bpmn-icon-lane',
|
31379 | target: {
|
31380 | type: 'bpmn:Participant',
|
31381 | isExpanded: false
|
31382 | }
|
31383 | }
|
31384 | ];
|
31385 |
|
31386 | |
31387 |
|
31388 |
|
31389 | function ReplaceMenuProvider(
|
31390 | popupMenu, modeling, moddle,
|
31391 | bpmnReplace, rules, translate) {
|
31392 |
|
31393 | this._popupMenu = popupMenu;
|
31394 | this._modeling = modeling;
|
31395 | this._moddle = moddle;
|
31396 | this._bpmnReplace = bpmnReplace;
|
31397 | this._rules = rules;
|
31398 | this._translate = translate;
|
31399 |
|
31400 | this.register();
|
31401 | }
|
31402 |
|
31403 | ReplaceMenuProvider.$inject = [
|
31404 | 'popupMenu',
|
31405 | 'modeling',
|
31406 | 'moddle',
|
31407 | 'bpmnReplace',
|
31408 | 'rules',
|
31409 | 'translate'
|
31410 | ];
|
31411 |
|
31412 |
|
31413 | |
31414 |
|
31415 |
|
31416 | ReplaceMenuProvider.prototype.register = function() {
|
31417 | this._popupMenu.registerProvider('bpmn-replace', this);
|
31418 | };
|
31419 |
|
31420 |
|
31421 | |
31422 |
|
31423 |
|
31424 |
|
31425 |
|
31426 |
|
31427 |
|
31428 |
|
31429 | ReplaceMenuProvider.prototype.getEntries = function(element) {
|
31430 |
|
31431 | var businessObject = element.businessObject;
|
31432 |
|
31433 | var rules = this._rules;
|
31434 |
|
31435 | var entries;
|
31436 |
|
31437 | if (!rules.allowed('shape.replace', { element: element })) {
|
31438 | return [];
|
31439 | }
|
31440 |
|
31441 | var differentType = isDifferentType(element);
|
31442 |
|
31443 |
|
31444 | if (is$1(businessObject, 'bpmn:StartEvent') && !isEventSubProcess(businessObject.$parent)) {
|
31445 |
|
31446 | entries = filter(START_EVENT, differentType);
|
31447 |
|
31448 | return this._createEntries(element, entries);
|
31449 | }
|
31450 |
|
31451 |
|
31452 | if (is$1(businessObject, 'bpmn:Participant')) {
|
31453 |
|
31454 | entries = filter(PARTICIPANT, function(entry) {
|
31455 | return isExpanded(businessObject) !== entry.target.isExpanded;
|
31456 | });
|
31457 |
|
31458 | return this._createEntries(element, entries);
|
31459 | }
|
31460 |
|
31461 |
|
31462 | if (is$1(businessObject, 'bpmn:StartEvent') && isEventSubProcess(businessObject.$parent)) {
|
31463 |
|
31464 | entries = filter(EVENT_SUB_PROCESS_START_EVENT, function(entry) {
|
31465 |
|
31466 | var target = entry.target;
|
31467 |
|
31468 | var isInterrupting$$1 = target.isInterrupting !== false;
|
31469 |
|
31470 | var isInterruptingEqual = getBusinessObject(element).isInterrupting === isInterrupting$$1;
|
31471 |
|
31472 |
|
31473 | return differentType(entry) || !differentType(entry) && !isInterruptingEqual;
|
31474 |
|
31475 | });
|
31476 |
|
31477 | return this._createEntries(element, entries);
|
31478 | }
|
31479 |
|
31480 |
|
31481 | if (is$1(businessObject, 'bpmn:EndEvent')) {
|
31482 |
|
31483 | entries = filter(END_EVENT, function(entry) {
|
31484 | var target = entry.target;
|
31485 |
|
31486 |
|
31487 | if (target.eventDefinitionType == 'bpmn:CancelEventDefinition' && !is$1(businessObject.$parent, 'bpmn:Transaction')) {
|
31488 | return false;
|
31489 | }
|
31490 |
|
31491 | return differentType(entry);
|
31492 | });
|
31493 |
|
31494 | return this._createEntries(element, entries);
|
31495 | }
|
31496 |
|
31497 |
|
31498 | if (is$1(businessObject, 'bpmn:BoundaryEvent')) {
|
31499 |
|
31500 | entries = filter(BOUNDARY_EVENT, function(entry) {
|
31501 |
|
31502 | var target = entry.target;
|
31503 |
|
31504 | if (target.eventDefinition == 'bpmn:CancelEventDefinition' &&
|
31505 | !is$1(businessObject.attachedToRef, 'bpmn:Transaction')) {
|
31506 | return false;
|
31507 | }
|
31508 | var cancelActivity = target.cancelActivity !== false;
|
31509 |
|
31510 | var isCancelActivityEqual = businessObject.cancelActivity == cancelActivity;
|
31511 |
|
31512 | return differentType(entry) || !differentType(entry) && !isCancelActivityEqual;
|
31513 | });
|
31514 |
|
31515 | return this._createEntries(element, entries);
|
31516 | }
|
31517 |
|
31518 |
|
31519 | if (is$1(businessObject, 'bpmn:IntermediateCatchEvent') ||
|
31520 | is$1(businessObject, 'bpmn:IntermediateThrowEvent')) {
|
31521 |
|
31522 | entries = filter(INTERMEDIATE_EVENT, differentType);
|
31523 |
|
31524 | return this._createEntries(element, entries);
|
31525 | }
|
31526 |
|
31527 |
|
31528 | if (is$1(businessObject, 'bpmn:Gateway')) {
|
31529 |
|
31530 | entries = filter(GATEWAY, differentType);
|
31531 |
|
31532 | return this._createEntries(element, entries);
|
31533 | }
|
31534 |
|
31535 |
|
31536 | if (is$1(businessObject, 'bpmn:Transaction')) {
|
31537 |
|
31538 | entries = filter(TRANSACTION, differentType);
|
31539 |
|
31540 | return this._createEntries(element, entries);
|
31541 | }
|
31542 |
|
31543 |
|
31544 | if (isEventSubProcess(businessObject) && isExpanded(businessObject)) {
|
31545 |
|
31546 | entries = filter(EVENT_SUB_PROCESS, differentType);
|
31547 |
|
31548 | return this._createEntries(element, entries);
|
31549 | }
|
31550 |
|
31551 |
|
31552 | if (is$1(businessObject, 'bpmn:SubProcess') && isExpanded(businessObject)) {
|
31553 |
|
31554 | entries = filter(SUBPROCESS_EXPANDED, differentType);
|
31555 |
|
31556 | return this._createEntries(element, entries);
|
31557 | }
|
31558 |
|
31559 |
|
31560 | if (is$1(businessObject, 'bpmn:AdHocSubProcess') && !isExpanded(businessObject)) {
|
31561 |
|
31562 | entries = filter(TASK, function(entry) {
|
31563 |
|
31564 | var target = entry.target;
|
31565 |
|
31566 | var isTargetSubProcess = target.type === 'bpmn:SubProcess';
|
31567 |
|
31568 | var isTargetExpanded = target.isExpanded === true;
|
31569 |
|
31570 | return isDifferentType(element, target) && (!isTargetSubProcess || isTargetExpanded);
|
31571 | });
|
31572 |
|
31573 | return this._createEntries(element, entries);
|
31574 | }
|
31575 |
|
31576 |
|
31577 | if (is$1(businessObject, 'bpmn:SequenceFlow')) {
|
31578 | return this._createSequenceFlowEntries(element, SEQUENCE_FLOW);
|
31579 | }
|
31580 |
|
31581 |
|
31582 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
31583 | entries = filter(TASK, differentType);
|
31584 |
|
31585 |
|
31586 | if (is$1(businessObject, 'bpmn:SubProcess') && !isExpanded(businessObject)) {
|
31587 | entries = filter(entries, function(entry) {
|
31588 | return entry.label !== 'Sub Process (collapsed)';
|
31589 | });
|
31590 | }
|
31591 |
|
31592 | return this._createEntries(element, entries);
|
31593 | }
|
31594 |
|
31595 | return [];
|
31596 | };
|
31597 |
|
31598 |
|
31599 | |
31600 |
|
31601 |
|
31602 |
|
31603 |
|
31604 |
|
31605 |
|
31606 |
|
31607 | ReplaceMenuProvider.prototype.getHeaderEntries = function(element) {
|
31608 |
|
31609 | var headerEntries = [];
|
31610 |
|
31611 | if (is$1(element, 'bpmn:Activity') && !isEventSubProcess(element)) {
|
31612 | headerEntries = headerEntries.concat(this._getLoopEntries(element));
|
31613 | }
|
31614 |
|
31615 | if (is$1(element, 'bpmn:SubProcess') &&
|
31616 | !is$1(element, 'bpmn:Transaction') &&
|
31617 | !isEventSubProcess(element)) {
|
31618 | headerEntries.push(this._getAdHocEntry(element));
|
31619 | }
|
31620 |
|
31621 | return headerEntries;
|
31622 | };
|
31623 |
|
31624 |
|
31625 | |
31626 |
|
31627 |
|
31628 |
|
31629 |
|
31630 |
|
31631 |
|
31632 |
|
31633 |
|
31634 | ReplaceMenuProvider.prototype._createEntries = function(element, replaceOptions) {
|
31635 | var menuEntries = [];
|
31636 |
|
31637 | var self = this;
|
31638 |
|
31639 | forEach(replaceOptions, function(definition) {
|
31640 | var entry = self._createMenuEntry(definition, element);
|
31641 |
|
31642 | menuEntries.push(entry);
|
31643 | });
|
31644 |
|
31645 | return menuEntries;
|
31646 | };
|
31647 |
|
31648 | |
31649 |
|
31650 |
|
31651 |
|
31652 |
|
31653 |
|
31654 |
|
31655 |
|
31656 | ReplaceMenuProvider.prototype._createSequenceFlowEntries = function(element, replaceOptions) {
|
31657 |
|
31658 | var businessObject = getBusinessObject(element);
|
31659 |
|
31660 | var menuEntries = [];
|
31661 |
|
31662 | var modeling = this._modeling,
|
31663 | moddle = this._moddle;
|
31664 |
|
31665 | var self = this;
|
31666 |
|
31667 | forEach(replaceOptions, function(entry) {
|
31668 |
|
31669 | switch (entry.actionName) {
|
31670 | case 'replace-with-default-flow':
|
31671 | if (businessObject.sourceRef.default !== businessObject &&
|
31672 | (is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
31673 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
31674 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
31675 | is$1(businessObject.sourceRef, 'bpmn:Activity'))) {
|
31676 |
|
31677 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
31678 | modeling.updateProperties(element.source, { default: businessObject });
|
31679 | }));
|
31680 | }
|
31681 | break;
|
31682 | case 'replace-with-conditional-flow':
|
31683 | if (!businessObject.conditionExpression && is$1(businessObject.sourceRef, 'bpmn:Activity')) {
|
31684 |
|
31685 | menuEntries.push(self._createMenuEntry(entry, element, function() {
|
31686 | var conditionExpression = moddle.create('bpmn:FormalExpression', { body: '' });
|
31687 |
|
31688 | modeling.updateProperties(element, { conditionExpression: conditionExpression });
|
31689 | }));
|
31690 | }
|
31691 | break;
|
31692 | default:
|
31693 |
|
31694 | if (is$1(businessObject.sourceRef, 'bpmn:Activity') && businessObject.conditionExpression) {
|
31695 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
31696 | modeling.updateProperties(element, { conditionExpression: undefined });
|
31697 | }));
|
31698 | }
|
31699 |
|
31700 | if ((is$1(businessObject.sourceRef, 'bpmn:ExclusiveGateway') ||
|
31701 | is$1(businessObject.sourceRef, 'bpmn:InclusiveGateway') ||
|
31702 | is$1(businessObject.sourceRef, 'bpmn:ComplexGateway') ||
|
31703 | is$1(businessObject.sourceRef, 'bpmn:Activity')) &&
|
31704 | businessObject.sourceRef.default === businessObject) {
|
31705 |
|
31706 | return menuEntries.push(self._createMenuEntry(entry, element, function() {
|
31707 | modeling.updateProperties(element.source, { default: undefined });
|
31708 | }));
|
31709 | }
|
31710 | }
|
31711 | });
|
31712 |
|
31713 | return menuEntries;
|
31714 | };
|
31715 |
|
31716 |
|
31717 | |
31718 |
|
31719 |
|
31720 |
|
31721 |
|
31722 |
|
31723 |
|
31724 |
|
31725 |
|
31726 |
|
31727 | ReplaceMenuProvider.prototype._createMenuEntry = function(definition, element, action) {
|
31728 | var translate = this._translate;
|
31729 | var replaceElement = this._bpmnReplace.replaceElement;
|
31730 |
|
31731 | var replaceAction = function() {
|
31732 | return replaceElement(element, definition.target);
|
31733 | };
|
31734 |
|
31735 | action = action || replaceAction;
|
31736 |
|
31737 | var menuEntry = {
|
31738 | label: translate(definition.label),
|
31739 | className: definition.className,
|
31740 | id: definition.actionName,
|
31741 | action: action
|
31742 | };
|
31743 |
|
31744 | return menuEntry;
|
31745 | };
|
31746 |
|
31747 | |
31748 |
|
31749 |
|
31750 |
|
31751 |
|
31752 |
|
31753 |
|
31754 | ReplaceMenuProvider.prototype._getLoopEntries = function(element) {
|
31755 |
|
31756 | var self = this;
|
31757 | var translate = this._translate;
|
31758 |
|
31759 | function toggleLoopEntry(event, entry) {
|
31760 | var loopCharacteristics;
|
31761 |
|
31762 | if (entry.active) {
|
31763 | loopCharacteristics = undefined;
|
31764 | } else {
|
31765 | loopCharacteristics = self._moddle.create(entry.options.loopCharacteristics);
|
31766 |
|
31767 | if (entry.options.isSequential) {
|
31768 | loopCharacteristics.isSequential = entry.options.isSequential;
|
31769 | }
|
31770 | }
|
31771 | self._modeling.updateProperties(element, { loopCharacteristics: loopCharacteristics });
|
31772 | }
|
31773 |
|
31774 | var businessObject = getBusinessObject(element),
|
31775 | loopCharacteristics = businessObject.loopCharacteristics;
|
31776 |
|
31777 | var isSequential,
|
31778 | isLoop,
|
31779 | isParallel;
|
31780 |
|
31781 | if (loopCharacteristics) {
|
31782 | isSequential = loopCharacteristics.isSequential;
|
31783 | isLoop = loopCharacteristics.isSequential === undefined;
|
31784 | isParallel = loopCharacteristics.isSequential !== undefined && !loopCharacteristics.isSequential;
|
31785 | }
|
31786 |
|
31787 |
|
31788 | var loopEntries = [
|
31789 | {
|
31790 | id: 'toggle-parallel-mi',
|
31791 | className: 'bpmn-icon-parallel-mi-marker',
|
31792 | title: translate('Parallel Multi Instance'),
|
31793 | active: isParallel,
|
31794 | action: toggleLoopEntry,
|
31795 | options: {
|
31796 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
31797 | isSequential: false
|
31798 | }
|
31799 | },
|
31800 | {
|
31801 | id: 'toggle-sequential-mi',
|
31802 | className: 'bpmn-icon-sequential-mi-marker',
|
31803 | title: translate('Sequential Multi Instance'),
|
31804 | active: isSequential,
|
31805 | action: toggleLoopEntry,
|
31806 | options: {
|
31807 | loopCharacteristics: 'bpmn:MultiInstanceLoopCharacteristics',
|
31808 | isSequential: true
|
31809 | }
|
31810 | },
|
31811 | {
|
31812 | id: 'toggle-loop',
|
31813 | className: 'bpmn-icon-loop-marker',
|
31814 | title: translate('Loop'),
|
31815 | active: isLoop,
|
31816 | action: toggleLoopEntry,
|
31817 | options: {
|
31818 | loopCharacteristics: 'bpmn:StandardLoopCharacteristics'
|
31819 | }
|
31820 | }
|
31821 | ];
|
31822 | return loopEntries;
|
31823 | };
|
31824 |
|
31825 |
|
31826 | |
31827 |
|
31828 |
|
31829 |
|
31830 |
|
31831 |
|
31832 |
|
31833 | ReplaceMenuProvider.prototype._getAdHocEntry = function(element) {
|
31834 | var translate = this._translate;
|
31835 | var businessObject = getBusinessObject(element);
|
31836 |
|
31837 | var isAdHoc = is$1(businessObject, 'bpmn:AdHocSubProcess');
|
31838 |
|
31839 | var replaceElement = this._bpmnReplace.replaceElement;
|
31840 |
|
31841 | var adHocEntry = {
|
31842 | id: 'toggle-adhoc',
|
31843 | className: 'bpmn-icon-ad-hoc-marker',
|
31844 | title: translate('Ad-hoc'),
|
31845 | active: isAdHoc,
|
31846 | action: function(event, entry) {
|
31847 | if (isAdHoc) {
|
31848 | return replaceElement(element, { type: 'bpmn:SubProcess' });
|
31849 | } else {
|
31850 | return replaceElement(element, { type: 'bpmn:AdHocSubProcess' });
|
31851 | }
|
31852 | }
|
31853 | };
|
31854 |
|
31855 | return adHocEntry;
|
31856 | };
|
31857 |
|
31858 | var PopupMenuModule$1 = {
|
31859 | __depends__: [
|
31860 | PopupMenuModule,
|
31861 | ReplaceModule$1
|
31862 | ],
|
31863 | __init__: [ 'replaceMenuProvider' ],
|
31864 | replaceMenuProvider: [ 'type', ReplaceMenuProvider ]
|
31865 | };
|
31866 |
|
31867 | var max$2 = Math.max,
|
31868 | min$1 = Math.min;
|
31869 |
|
31870 | var DEFAULT_CHILD_BOX_PADDING = 20;
|
31871 |
|
31872 |
|
31873 | |
31874 |
|
31875 |
|
31876 |
|
31877 |
|
31878 |
|
31879 |
|
31880 |
|
31881 | function substractTRBL(trblA, trblB) {
|
31882 | return {
|
31883 | top: trblA.top - trblB.top,
|
31884 | right: trblA.right - trblB.right,
|
31885 | bottom: trblA.bottom - trblB.bottom,
|
31886 | left: trblA.left - trblB.left
|
31887 | };
|
31888 | }
|
31889 |
|
31890 | |
31891 |
|
31892 |
|
31893 |
|
31894 |
|
31895 |
|
31896 |
|
31897 |
|
31898 |
|
31899 | function resizeBounds(bounds, direction, delta) {
|
31900 |
|
31901 | var dx = delta.x,
|
31902 | dy = delta.y;
|
31903 |
|
31904 | switch (direction) {
|
31905 |
|
31906 | case 'nw':
|
31907 | return {
|
31908 | x: bounds.x + dx,
|
31909 | y: bounds.y + dy,
|
31910 | width: bounds.width - dx,
|
31911 | height: bounds.height - dy
|
31912 | };
|
31913 |
|
31914 | case 'sw':
|
31915 | return {
|
31916 | x: bounds.x + dx,
|
31917 | y: bounds.y,
|
31918 | width: bounds.width - dx,
|
31919 | height: bounds.height + dy
|
31920 | };
|
31921 |
|
31922 | case 'ne':
|
31923 | return {
|
31924 | x: bounds.x,
|
31925 | y: bounds.y + dy,
|
31926 | width: bounds.width + dx,
|
31927 | height: bounds.height - dy
|
31928 | };
|
31929 |
|
31930 | case 'se':
|
31931 | return {
|
31932 | x: bounds.x,
|
31933 | y: bounds.y,
|
31934 | width: bounds.width + dx,
|
31935 | height: bounds.height + dy
|
31936 | };
|
31937 |
|
31938 | default:
|
31939 | throw new Error('unrecognized direction: ' + direction);
|
31940 | }
|
31941 | }
|
31942 |
|
31943 |
|
31944 | |
31945 |
|
31946 |
|
31947 |
|
31948 |
|
31949 |
|
31950 |
|
31951 |
|
31952 |
|
31953 | function resizeTRBL(bounds, resize) {
|
31954 | return {
|
31955 | x: bounds.x + (resize.left || 0),
|
31956 | y: bounds.y + (resize.top || 0),
|
31957 | width: bounds.width - (resize.left || 0) + (resize.right || 0),
|
31958 | height: bounds.height - (resize.top || 0) + (resize.bottom || 0)
|
31959 | };
|
31960 | }
|
31961 |
|
31962 |
|
31963 | function applyConstraints(attr, trbl, resizeConstraints) {
|
31964 |
|
31965 | var value = trbl[attr],
|
31966 | minValue = resizeConstraints.min && resizeConstraints.min[attr],
|
31967 | maxValue = resizeConstraints.max && resizeConstraints.max[attr];
|
31968 |
|
31969 | if (isNumber(minValue)) {
|
31970 | value = (/top|left/.test(attr) ? min$1 : max$2)(value, minValue);
|
31971 | }
|
31972 |
|
31973 | if (isNumber(maxValue)) {
|
31974 | value = (/top|left/.test(attr) ? max$2 : min$1)(value, maxValue);
|
31975 | }
|
31976 |
|
31977 | return value;
|
31978 | }
|
31979 |
|
31980 | function ensureConstraints(currentBounds, resizeConstraints) {
|
31981 |
|
31982 | if (!resizeConstraints) {
|
31983 | return currentBounds;
|
31984 | }
|
31985 |
|
31986 | var currentTrbl = asTRBL(currentBounds);
|
31987 |
|
31988 | return asBounds({
|
31989 | top: applyConstraints('top', currentTrbl, resizeConstraints),
|
31990 | right: applyConstraints('right', currentTrbl, resizeConstraints),
|
31991 | bottom: applyConstraints('bottom', currentTrbl, resizeConstraints),
|
31992 | left: applyConstraints('left', currentTrbl, resizeConstraints)
|
31993 | });
|
31994 | }
|
31995 |
|
31996 |
|
31997 | function getMinResizeBounds(direction, currentBounds, minDimensions, childrenBounds) {
|
31998 |
|
31999 | var currentBox = asTRBL(currentBounds);
|
32000 |
|
32001 | var minBox = {
|
32002 | top: /n/.test(direction) ? currentBox.bottom - minDimensions.height : currentBox.top,
|
32003 | left: /w/.test(direction) ? currentBox.right - minDimensions.width : currentBox.left,
|
32004 | bottom: /s/.test(direction) ? currentBox.top + minDimensions.height : currentBox.bottom,
|
32005 | right: /e/.test(direction) ? currentBox.left + minDimensions.width : currentBox.right
|
32006 | };
|
32007 |
|
32008 | var childrenBox = childrenBounds ? asTRBL(childrenBounds) : minBox;
|
32009 |
|
32010 | var combinedBox = {
|
32011 | top: min$1(minBox.top, childrenBox.top),
|
32012 | left: min$1(minBox.left, childrenBox.left),
|
32013 | bottom: max$2(minBox.bottom, childrenBox.bottom),
|
32014 | right: max$2(minBox.right, childrenBox.right)
|
32015 | };
|
32016 |
|
32017 | return asBounds(combinedBox);
|
32018 | }
|
32019 |
|
32020 | function asPadding(mayBePadding, defaultValue) {
|
32021 | if (typeof mayBePadding !== 'undefined') {
|
32022 | return mayBePadding;
|
32023 | } else {
|
32024 | return DEFAULT_CHILD_BOX_PADDING;
|
32025 | }
|
32026 | }
|
32027 |
|
32028 | function addPadding(bbox, padding) {
|
32029 | var left, right, top, bottom;
|
32030 |
|
32031 | if (typeof padding === 'object') {
|
32032 | left = asPadding(padding.left);
|
32033 | right = asPadding(padding.right);
|
32034 | top = asPadding(padding.top);
|
32035 | bottom = asPadding(padding.bottom);
|
32036 | } else {
|
32037 | left = right = top = bottom = asPadding(padding);
|
32038 | }
|
32039 |
|
32040 | return {
|
32041 | x: bbox.x - left,
|
32042 | y: bbox.y - top,
|
32043 | width: bbox.width + left + right,
|
32044 | height: bbox.height + top + bottom
|
32045 | };
|
32046 | }
|
32047 |
|
32048 |
|
32049 | |
32050 |
|
32051 |
|
32052 |
|
32053 |
|
32054 |
|
32055 |
|
32056 |
|
32057 |
|
32058 | function isBBoxChild(element) {
|
32059 |
|
32060 |
|
32061 | if (element.waypoints) {
|
32062 | return false;
|
32063 | }
|
32064 |
|
32065 |
|
32066 | if (element.type === 'label') {
|
32067 | return false;
|
32068 | }
|
32069 |
|
32070 | return true;
|
32071 | }
|
32072 |
|
32073 | |
32074 |
|
32075 |
|
32076 |
|
32077 |
|
32078 |
|
32079 |
|
32080 |
|
32081 |
|
32082 | function computeChildrenBBox(shapeOrChildren, padding) {
|
32083 |
|
32084 | var elements;
|
32085 |
|
32086 |
|
32087 | if (shapeOrChildren.length === undefined) {
|
32088 |
|
32089 |
|
32090 | elements = filter(shapeOrChildren.children, isBBoxChild);
|
32091 |
|
32092 | } else {
|
32093 | elements = shapeOrChildren;
|
32094 | }
|
32095 |
|
32096 | if (elements.length) {
|
32097 | return addPadding(getBBox(elements), padding);
|
32098 | }
|
32099 | }
|
32100 |
|
32101 | var abs$2 = Math.abs;
|
32102 |
|
32103 |
|
32104 | function getTRBLResize(oldBounds, newBounds) {
|
32105 | return substractTRBL(asTRBL(newBounds), asTRBL(oldBounds));
|
32106 | }
|
32107 |
|
32108 |
|
32109 | var LANE_PARENTS = [
|
32110 | 'bpmn:Participant',
|
32111 | 'bpmn:Process',
|
32112 | 'bpmn:SubProcess'
|
32113 | ];
|
32114 |
|
32115 | var LANE_INDENTATION = 30;
|
32116 |
|
32117 |
|
32118 | |
32119 |
|
32120 |
|
32121 |
|
32122 |
|
32123 |
|
32124 |
|
32125 |
|
32126 | function collectLanes(shape, collectedShapes) {
|
32127 |
|
32128 | collectedShapes = collectedShapes || [];
|
32129 |
|
32130 | shape.children.filter(function(s) {
|
32131 | if (is$1(s, 'bpmn:Lane')) {
|
32132 | collectLanes(s, collectedShapes);
|
32133 |
|
32134 | collectedShapes.push(s);
|
32135 | }
|
32136 | });
|
32137 |
|
32138 | return collectedShapes;
|
32139 | }
|
32140 |
|
32141 |
|
32142 | |
32143 |
|
32144 |
|
32145 |
|
32146 |
|
32147 |
|
32148 |
|
32149 | function getChildLanes(shape) {
|
32150 | return shape.children.filter(function(c) {
|
32151 | return is$1(c, 'bpmn:Lane');
|
32152 | });
|
32153 | }
|
32154 |
|
32155 |
|
32156 | |
32157 |
|
32158 |
|
32159 |
|
32160 |
|
32161 |
|
32162 |
|
32163 | function getLanesRoot(shape) {
|
32164 | return getParent(shape, LANE_PARENTS) || shape;
|
32165 | }
|
32166 |
|
32167 |
|
32168 | |
32169 |
|
32170 |
|
32171 |
|
32172 |
|
32173 |
|
32174 |
|
32175 |
|
32176 |
|
32177 |
|
32178 | function computeLanesResize(shape, newBounds) {
|
32179 |
|
32180 | var rootElement = getLanesRoot(shape);
|
32181 |
|
32182 | var initialShapes = is$1(rootElement, 'bpmn:Process') ? [] : [ rootElement ];
|
32183 |
|
32184 | var allLanes = collectLanes(rootElement, initialShapes),
|
32185 | shapeTrbl = asTRBL(shape),
|
32186 | shapeNewTrbl = asTRBL(newBounds),
|
32187 | trblResize = getTRBLResize(shape, newBounds),
|
32188 | resizeNeeded = [];
|
32189 |
|
32190 | allLanes.forEach(function(other) {
|
32191 |
|
32192 | if (other === shape) {
|
32193 | return;
|
32194 | }
|
32195 |
|
32196 | var topResize = 0,
|
32197 | rightResize = trblResize.right,
|
32198 | bottomResize = 0,
|
32199 | leftResize = trblResize.left;
|
32200 |
|
32201 | var otherTrbl = asTRBL(other);
|
32202 |
|
32203 | if (trblResize.top) {
|
32204 | if (abs$2(otherTrbl.bottom - shapeTrbl.top) < 10) {
|
32205 | bottomResize = shapeNewTrbl.top - otherTrbl.bottom;
|
32206 | }
|
32207 |
|
32208 | if (abs$2(otherTrbl.top - shapeTrbl.top) < 5) {
|
32209 | topResize = shapeNewTrbl.top - otherTrbl.top;
|
32210 | }
|
32211 | }
|
32212 |
|
32213 | if (trblResize.bottom) {
|
32214 | if (abs$2(otherTrbl.top - shapeTrbl.bottom) < 10) {
|
32215 | topResize = shapeNewTrbl.bottom - otherTrbl.top;
|
32216 | }
|
32217 |
|
32218 | if (abs$2(otherTrbl.bottom - shapeTrbl.bottom) < 5) {
|
32219 | bottomResize = shapeNewTrbl.bottom - otherTrbl.bottom;
|
32220 | }
|
32221 | }
|
32222 |
|
32223 | if (topResize || rightResize || bottomResize || leftResize) {
|
32224 |
|
32225 | resizeNeeded.push({
|
32226 | shape: other,
|
32227 | newBounds: resizeTRBL(other, {
|
32228 | top: topResize,
|
32229 | right: rightResize,
|
32230 | bottom: bottomResize,
|
32231 | left: leftResize
|
32232 | })
|
32233 | });
|
32234 | }
|
32235 |
|
32236 | });
|
32237 |
|
32238 | return resizeNeeded;
|
32239 | }
|
32240 |
|
32241 | |
32242 |
|
32243 |
|
32244 | function ContextPadProvider(
|
32245 | config, injector, eventBus,
|
32246 | contextPad, modeling, elementFactory,
|
32247 | connect, create, popupMenu,
|
32248 | canvas, rules, translate) {
|
32249 |
|
32250 | config = config || {};
|
32251 |
|
32252 | contextPad.registerProvider(this);
|
32253 |
|
32254 | this._contextPad = contextPad;
|
32255 |
|
32256 | this._modeling = modeling;
|
32257 |
|
32258 | this._elementFactory = elementFactory;
|
32259 | this._connect = connect;
|
32260 | this._create = create;
|
32261 | this._popupMenu = popupMenu;
|
32262 | this._canvas = canvas;
|
32263 | this._rules = rules;
|
32264 | this._translate = translate;
|
32265 |
|
32266 | if (config.autoPlace !== false) {
|
32267 | this._autoPlace = injector.get('autoPlace', false);
|
32268 | }
|
32269 |
|
32270 | eventBus.on('create.end', 250, function(event) {
|
32271 | var shape = event.context.shape;
|
32272 |
|
32273 | if (!hasPrimaryModifier(event)) {
|
32274 | return;
|
32275 | }
|
32276 |
|
32277 | var entries = contextPad.getEntries(shape);
|
32278 |
|
32279 | if (entries.replace) {
|
32280 | entries.replace.action.click(event, shape);
|
32281 | }
|
32282 | });
|
32283 | }
|
32284 |
|
32285 | ContextPadProvider.$inject = [
|
32286 | 'config.contextPad',
|
32287 | 'injector',
|
32288 | 'eventBus',
|
32289 | 'contextPad',
|
32290 | 'modeling',
|
32291 | 'elementFactory',
|
32292 | 'connect',
|
32293 | 'create',
|
32294 | 'popupMenu',
|
32295 | 'canvas',
|
32296 | 'rules',
|
32297 | 'translate'
|
32298 | ];
|
32299 |
|
32300 |
|
32301 | ContextPadProvider.prototype.getContextPadEntries = function(element) {
|
32302 |
|
32303 | var contextPad = this._contextPad,
|
32304 | modeling = this._modeling,
|
32305 |
|
32306 | elementFactory = this._elementFactory,
|
32307 | connect = this._connect,
|
32308 | create = this._create,
|
32309 | popupMenu = this._popupMenu,
|
32310 | canvas = this._canvas,
|
32311 | rules = this._rules,
|
32312 | autoPlace = this._autoPlace,
|
32313 | translate = this._translate;
|
32314 |
|
32315 | var actions = {};
|
32316 |
|
32317 | if (element.type === 'label') {
|
32318 | return actions;
|
32319 | }
|
32320 |
|
32321 | var businessObject = element.businessObject;
|
32322 |
|
32323 | function startConnect(event, element) {
|
32324 | connect.start(event, element);
|
32325 | }
|
32326 |
|
32327 | function removeElement(e) {
|
32328 | modeling.removeElements([ element ]);
|
32329 | }
|
32330 |
|
32331 | function getReplaceMenuPosition(element) {
|
32332 |
|
32333 | var Y_OFFSET = 5;
|
32334 |
|
32335 | var diagramContainer = canvas.getContainer(),
|
32336 | pad = contextPad.getPad(element).html;
|
32337 |
|
32338 | var diagramRect = diagramContainer.getBoundingClientRect(),
|
32339 | padRect = pad.getBoundingClientRect();
|
32340 |
|
32341 | var top = padRect.top - diagramRect.top;
|
32342 | var left = padRect.left - diagramRect.left;
|
32343 |
|
32344 | var pos = {
|
32345 | x: left,
|
32346 | y: top + padRect.height + Y_OFFSET
|
32347 | };
|
32348 |
|
32349 | return pos;
|
32350 | }
|
32351 |
|
32352 |
|
32353 | |
32354 |
|
32355 |
|
32356 |
|
32357 |
|
32358 |
|
32359 |
|
32360 |
|
32361 |
|
32362 |
|
32363 | function appendAction(type, className, title, options) {
|
32364 |
|
32365 | if (typeof title !== 'string') {
|
32366 | options = title;
|
32367 | title = translate('Append {type}', { type: type.replace(/^bpmn:/, '') });
|
32368 | }
|
32369 |
|
32370 | function appendStart(event, element) {
|
32371 |
|
32372 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
32373 | create.start(event, shape, element);
|
32374 | }
|
32375 |
|
32376 |
|
32377 | var append = autoPlace ? function(event, element) {
|
32378 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
32379 |
|
32380 | autoPlace.append(element, shape);
|
32381 | } : appendStart;
|
32382 |
|
32383 |
|
32384 | return {
|
32385 | group: 'model',
|
32386 | className: className,
|
32387 | title: title,
|
32388 | action: {
|
32389 | dragstart: appendStart,
|
32390 | click: append
|
32391 | }
|
32392 | };
|
32393 | }
|
32394 |
|
32395 | function splitLaneHandler(count) {
|
32396 |
|
32397 | return function(event, element) {
|
32398 |
|
32399 | modeling.splitLane(element, count);
|
32400 |
|
32401 |
|
32402 |
|
32403 | contextPad.open(element, true);
|
32404 | };
|
32405 | }
|
32406 |
|
32407 |
|
32408 | if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(businessObject)) {
|
32409 |
|
32410 | var childLanes = getChildLanes(element);
|
32411 |
|
32412 | assign(actions, {
|
32413 | 'lane-insert-above': {
|
32414 | group: 'lane-insert-above',
|
32415 | className: 'bpmn-icon-lane-insert-above',
|
32416 | title: translate('Add Lane above'),
|
32417 | action: {
|
32418 | click: function(event, element) {
|
32419 | modeling.addLane(element, 'top');
|
32420 | }
|
32421 | }
|
32422 | }
|
32423 | });
|
32424 |
|
32425 | if (childLanes.length < 2) {
|
32426 |
|
32427 | if (element.height >= 120) {
|
32428 | assign(actions, {
|
32429 | 'lane-divide-two': {
|
32430 | group: 'lane-divide',
|
32431 | className: 'bpmn-icon-lane-divide-two',
|
32432 | title: translate('Divide into two Lanes'),
|
32433 | action: {
|
32434 | click: splitLaneHandler(2)
|
32435 | }
|
32436 | }
|
32437 | });
|
32438 | }
|
32439 |
|
32440 | if (element.height >= 180) {
|
32441 | assign(actions, {
|
32442 | 'lane-divide-three': {
|
32443 | group: 'lane-divide',
|
32444 | className: 'bpmn-icon-lane-divide-three',
|
32445 | title: translate('Divide into three Lanes'),
|
32446 | action: {
|
32447 | click: splitLaneHandler(3)
|
32448 | }
|
32449 | }
|
32450 | });
|
32451 | }
|
32452 | }
|
32453 |
|
32454 | assign(actions, {
|
32455 | 'lane-insert-below': {
|
32456 | group: 'lane-insert-below',
|
32457 | className: 'bpmn-icon-lane-insert-below',
|
32458 | title: translate('Add Lane below'),
|
32459 | action: {
|
32460 | click: function(event, element) {
|
32461 | modeling.addLane(element, 'bottom');
|
32462 | }
|
32463 | }
|
32464 | }
|
32465 | });
|
32466 |
|
32467 | }
|
32468 |
|
32469 | if (is$1(businessObject, 'bpmn:FlowNode')) {
|
32470 |
|
32471 | if (is$1(businessObject, 'bpmn:EventBasedGateway')) {
|
32472 |
|
32473 | assign(actions, {
|
32474 | 'append.receive-task': appendAction(
|
32475 | 'bpmn:ReceiveTask',
|
32476 | 'bpmn-icon-receive-task'
|
32477 | ),
|
32478 | 'append.message-intermediate-event': appendAction(
|
32479 | 'bpmn:IntermediateCatchEvent',
|
32480 | 'bpmn-icon-intermediate-event-catch-message',
|
32481 | translate('Append MessageIntermediateCatchEvent'),
|
32482 | { eventDefinitionType: 'bpmn:MessageEventDefinition' }
|
32483 | ),
|
32484 | 'append.timer-intermediate-event': appendAction(
|
32485 | 'bpmn:IntermediateCatchEvent',
|
32486 | 'bpmn-icon-intermediate-event-catch-timer',
|
32487 | translate('Append TimerIntermediateCatchEvent'),
|
32488 | { eventDefinitionType: 'bpmn:TimerEventDefinition' }
|
32489 | ),
|
32490 | 'append.condtion-intermediate-event': appendAction(
|
32491 | 'bpmn:IntermediateCatchEvent',
|
32492 | 'bpmn-icon-intermediate-event-catch-condition',
|
32493 | translate('Append ConditionIntermediateCatchEvent'),
|
32494 | { eventDefinitionType: 'bpmn:ConditionalEventDefinition' }
|
32495 | ),
|
32496 | 'append.signal-intermediate-event': appendAction(
|
32497 | 'bpmn:IntermediateCatchEvent',
|
32498 | 'bpmn-icon-intermediate-event-catch-signal',
|
32499 | translate('Append SignalIntermediateCatchEvent'),
|
32500 | { eventDefinitionType: 'bpmn:SignalEventDefinition' }
|
32501 | )
|
32502 | });
|
32503 | } else
|
32504 |
|
32505 | if (isEventType(businessObject, 'bpmn:BoundaryEvent', 'bpmn:CompensateEventDefinition')) {
|
32506 |
|
32507 | assign(actions, {
|
32508 | 'append.compensation-activity':
|
32509 | appendAction(
|
32510 | 'bpmn:Task',
|
32511 | 'bpmn-icon-task',
|
32512 | translate('Append compensation activity'),
|
32513 | {
|
32514 | isForCompensation: true
|
32515 | }
|
32516 | )
|
32517 | });
|
32518 | } else
|
32519 |
|
32520 | if (!is$1(businessObject, 'bpmn:EndEvent') &&
|
32521 | !businessObject.isForCompensation &&
|
32522 | !isEventType(businessObject, 'bpmn:IntermediateThrowEvent', 'bpmn:LinkEventDefinition') &&
|
32523 | !isEventSubProcess(businessObject)) {
|
32524 |
|
32525 | assign(actions, {
|
32526 | 'append.end-event': appendAction(
|
32527 | 'bpmn:EndEvent',
|
32528 | 'bpmn-icon-end-event-none'
|
32529 | ),
|
32530 | 'append.gateway': appendAction(
|
32531 | 'bpmn:ExclusiveGateway',
|
32532 | 'bpmn-icon-gateway-none',
|
32533 | translate('Append Gateway')
|
32534 | ),
|
32535 | 'append.append-task': appendAction(
|
32536 | 'bpmn:Task',
|
32537 | 'bpmn-icon-task'
|
32538 | ),
|
32539 | 'append.intermediate-event': appendAction(
|
32540 | 'bpmn:IntermediateThrowEvent',
|
32541 | 'bpmn-icon-intermediate-event-none',
|
32542 | translate('Append Intermediate/Boundary Event')
|
32543 | )
|
32544 | });
|
32545 | }
|
32546 | }
|
32547 |
|
32548 | if (!popupMenu.isEmpty(element, 'bpmn-replace')) {
|
32549 |
|
32550 | assign(actions, {
|
32551 | 'replace': {
|
32552 | group: 'edit',
|
32553 | className: 'bpmn-icon-screw-wrench',
|
32554 | title: translate('Change type'),
|
32555 | action: {
|
32556 | click: function(event, element) {
|
32557 |
|
32558 | var position = assign(getReplaceMenuPosition(element), {
|
32559 | cursor: { x: event.x, y: event.y }
|
32560 | });
|
32561 |
|
32562 | popupMenu.open(element, 'bpmn-replace', position);
|
32563 | }
|
32564 | }
|
32565 | }
|
32566 | });
|
32567 | }
|
32568 |
|
32569 | if (isAny(businessObject, [
|
32570 | 'bpmn:FlowNode',
|
32571 | 'bpmn:InteractionNode',
|
32572 | 'bpmn:DataObjectReference',
|
32573 | 'bpmn:DataStoreReference'
|
32574 | ])) {
|
32575 |
|
32576 | assign(actions, {
|
32577 | 'append.text-annotation': appendAction('bpmn:TextAnnotation', 'bpmn-icon-text-annotation'),
|
32578 |
|
32579 | 'connect': {
|
32580 | group: 'connect',
|
32581 | className: 'bpmn-icon-connection-multi',
|
32582 | title: translate('Connect using ' +
|
32583 | (businessObject.isForCompensation ? '' : 'Sequence/MessageFlow or ') +
|
32584 | 'Association'),
|
32585 | action: {
|
32586 | click: startConnect,
|
32587 | dragstart: startConnect
|
32588 | }
|
32589 | }
|
32590 | });
|
32591 | }
|
32592 |
|
32593 | if (isAny(businessObject, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ])) {
|
32594 | assign(actions, {
|
32595 | 'connect': {
|
32596 | group: 'connect',
|
32597 | className: 'bpmn-icon-connection-multi',
|
32598 | title: translate('Connect using DataInputAssociation'),
|
32599 | action: {
|
32600 | click: startConnect,
|
32601 | dragstart: startConnect
|
32602 | }
|
32603 | }
|
32604 | });
|
32605 | }
|
32606 |
|
32607 |
|
32608 | var deleteAllowed = rules.allowed('elements.delete', { elements: [ element ] });
|
32609 |
|
32610 | if (isArray(deleteAllowed)) {
|
32611 |
|
32612 | deleteAllowed = deleteAllowed[0] === element;
|
32613 | }
|
32614 |
|
32615 | if (deleteAllowed) {
|
32616 | assign(actions, {
|
32617 | 'delete': {
|
32618 | group: 'edit',
|
32619 | className: 'bpmn-icon-trash',
|
32620 | title: translate('Remove'),
|
32621 | action: {
|
32622 | click: removeElement
|
32623 | }
|
32624 | }
|
32625 | });
|
32626 | }
|
32627 |
|
32628 | return actions;
|
32629 | };
|
32630 |
|
32631 | function isEventType(eventBo, type, definition) {
|
32632 |
|
32633 | var isType = eventBo.$instanceOf(type);
|
32634 | var isDefinition = false;
|
32635 |
|
32636 | var definitions = eventBo.eventDefinitions || [];
|
32637 | forEach(definitions, function(def) {
|
32638 | if (def.$type === definition) {
|
32639 | isDefinition = true;
|
32640 | }
|
32641 | });
|
32642 |
|
32643 | return isType && isDefinition;
|
32644 | }
|
32645 |
|
32646 | var ContextPadModule$1 = {
|
32647 | __depends__: [
|
32648 | DirectEditingModule,
|
32649 | ContextPadModule,
|
32650 | SelectionModule,
|
32651 | ConnectModule,
|
32652 | CreateModule,
|
32653 | PopupMenuModule$1
|
32654 | ],
|
32655 | __init__: [ 'contextPadProvider' ],
|
32656 | contextPadProvider: [ 'type', ContextPadProvider ]
|
32657 | };
|
32658 |
|
32659 | |
32660 |
|
32661 |
|
32662 | function Clipboard() {}
|
32663 |
|
32664 |
|
32665 | Clipboard.prototype.get = function() {
|
32666 | return this._data;
|
32667 | };
|
32668 |
|
32669 | Clipboard.prototype.set = function(data) {
|
32670 | this._data = data;
|
32671 | };
|
32672 |
|
32673 | Clipboard.prototype.clear = function() {
|
32674 | var data = this._data;
|
32675 |
|
32676 | delete this._data;
|
32677 |
|
32678 | return data;
|
32679 | };
|
32680 |
|
32681 | Clipboard.prototype.isEmpty = function() {
|
32682 | return !this._data;
|
32683 | };
|
32684 |
|
32685 | var ClipboardModule = {
|
32686 | clipboard: [ 'type', Clipboard ]
|
32687 | };
|
32688 |
|
32689 | function getTopLevel(elements) {
|
32690 | var topLevel = {},
|
32691 | parents = [],
|
32692 | result = [],
|
32693 | clearedParents = [];
|
32694 |
|
32695 | forEach(elements, function(element) {
|
32696 | var parent = element.parent;
|
32697 |
|
32698 | if (!topLevel[parent.id]) {
|
32699 | topLevel[parent.id] = [];
|
32700 | }
|
32701 |
|
32702 | if (parents.indexOf(parent.id) === -1) {
|
32703 | parents.push(parent.id);
|
32704 | }
|
32705 |
|
32706 | topLevel[parent.id].push(element);
|
32707 | });
|
32708 |
|
32709 | forEach(parents, function(parent) {
|
32710 | forEach(topLevel[parent], function(element) {
|
32711 | if (topLevel[element.id]) {
|
32712 | clearedParents.push(element.id);
|
32713 | }
|
32714 | });
|
32715 | });
|
32716 |
|
32717 | forEach(parents, function(parent) {
|
32718 | var idx = clearedParents.indexOf(parent);
|
32719 |
|
32720 | if (idx === -1) {
|
32721 | result = result.concat(topLevel[parent]);
|
32722 | }
|
32723 | });
|
32724 |
|
32725 | return result;
|
32726 | }
|
32727 |
|
32728 | function CopyPaste(
|
32729 | eventBus, modeling, elementFactory,
|
32730 | rules, clipboard, canvas) {
|
32731 |
|
32732 | this._eventBus = eventBus;
|
32733 | this._modeling = modeling;
|
32734 | this._elementFactory = elementFactory;
|
32735 | this._rules = rules;
|
32736 | this._canvas = canvas;
|
32737 |
|
32738 | this._clipboard = clipboard;
|
32739 |
|
32740 | this._descriptors = [];
|
32741 |
|
32742 |
|
32743 |
|
32744 |
|
32745 |
|
32746 |
|
32747 |
|
32748 | this.registerDescriptor(function(element, descriptor) {
|
32749 |
|
32750 | descriptor.priority = 1;
|
32751 |
|
32752 | descriptor.id = element.id;
|
32753 |
|
32754 | if (element.parent) {
|
32755 | descriptor.parent = element.parent.id;
|
32756 | }
|
32757 |
|
32758 | if (element.labelTarget) {
|
32759 |
|
32760 | descriptor.priority = 4;
|
32761 | descriptor.labelTarget = element.labelTarget.id;
|
32762 | }
|
32763 |
|
32764 | if (element.host) {
|
32765 |
|
32766 | descriptor.priority = 2;
|
32767 | descriptor.host = element.host.id;
|
32768 | }
|
32769 |
|
32770 | if (typeof element.x === 'number') {
|
32771 | descriptor.x = element.x;
|
32772 | descriptor.y = element.y;
|
32773 | }
|
32774 |
|
32775 | if (element.width) {
|
32776 | descriptor.width = element.width;
|
32777 | descriptor.height = element.height;
|
32778 | }
|
32779 |
|
32780 | if (element.waypoints) {
|
32781 |
|
32782 | descriptor.priority = 3;
|
32783 | descriptor.waypoints = [];
|
32784 |
|
32785 | forEach(element.waypoints, function(waypoint) {
|
32786 | var wp = {
|
32787 | x: waypoint.x,
|
32788 | y: waypoint.y
|
32789 | };
|
32790 |
|
32791 | if (waypoint.original) {
|
32792 | wp.original = {
|
32793 | x: waypoint.original.x,
|
32794 | y: waypoint.original.y
|
32795 | };
|
32796 | }
|
32797 |
|
32798 | descriptor.waypoints.push(wp);
|
32799 | });
|
32800 | }
|
32801 |
|
32802 | if (element.source && element.target) {
|
32803 | descriptor.source = element.source.id;
|
32804 | descriptor.target = element.target.id;
|
32805 | }
|
32806 |
|
32807 | return descriptor;
|
32808 | });
|
32809 | }
|
32810 |
|
32811 | CopyPaste.$inject = [
|
32812 | 'eventBus',
|
32813 | 'modeling',
|
32814 | 'elementFactory',
|
32815 | 'rules',
|
32816 | 'clipboard',
|
32817 | 'canvas'
|
32818 | ];
|
32819 |
|
32820 |
|
32821 | |
32822 |
|
32823 |
|
32824 |
|
32825 |
|
32826 |
|
32827 |
|
32828 | CopyPaste.prototype.copy = function(selectedElements) {
|
32829 | var clipboard = this._clipboard,
|
32830 | tree, bbox;
|
32831 |
|
32832 | if (!isArray(selectedElements)) {
|
32833 | selectedElements = selectedElements ? [ selectedElements ] : [];
|
32834 | }
|
32835 |
|
32836 | if (!selectedElements.length) {
|
32837 | return;
|
32838 | }
|
32839 |
|
32840 | tree = this.createTree(selectedElements);
|
32841 |
|
32842 | bbox = this._bbox = center(getBBox(tree.allShapes));
|
32843 |
|
32844 |
|
32845 | delete tree.allShapes;
|
32846 |
|
32847 | forEach(tree, function(elements) {
|
32848 |
|
32849 | forEach(elements, function(element) {
|
32850 | var delta$$1, labelTarget;
|
32851 |
|
32852 |
|
32853 | if (element.labelTarget) {
|
32854 | labelTarget = find(elements, matchPattern({ id: element.labelTarget }));
|
32855 |
|
32856 |
|
32857 | if (labelTarget.waypoints) {
|
32858 | delta$$1 = delta(element, labelTarget.waypoints[0]);
|
32859 | } else {
|
32860 | delta$$1 = delta(element, labelTarget);
|
32861 | }
|
32862 |
|
32863 | } else
|
32864 | if (element.priority === 3) {
|
32865 |
|
32866 | delta$$1 = [];
|
32867 |
|
32868 | forEach(element.waypoints, function(waypoint) {
|
32869 | var waypointDelta = delta(waypoint, bbox);
|
32870 |
|
32871 | delta$$1.push(waypointDelta);
|
32872 | });
|
32873 | } else {
|
32874 | delta$$1 = delta(element, bbox);
|
32875 | }
|
32876 |
|
32877 | element.delta = delta$$1;
|
32878 | });
|
32879 | });
|
32880 |
|
32881 | this._eventBus.fire('elements.copy', { context: { tree: tree } });
|
32882 |
|
32883 |
|
32884 | if (Object.keys(tree).length === 0) {
|
32885 | clipboard.clear();
|
32886 | } else {
|
32887 | clipboard.set(tree);
|
32888 | }
|
32889 |
|
32890 | this._eventBus.fire('elements.copied', { context: { tree: tree } });
|
32891 |
|
32892 | return tree;
|
32893 | };
|
32894 |
|
32895 |
|
32896 |
|
32897 | CopyPaste.prototype.paste = function(context) {
|
32898 | var clipboard = this._clipboard,
|
32899 | modeling = this._modeling,
|
32900 | eventBus = this._eventBus,
|
32901 | rules = this._rules;
|
32902 |
|
32903 | var tree = clipboard.get(),
|
32904 | topParent = context.element,
|
32905 | position = context.point,
|
32906 | newTree, canPaste;
|
32907 |
|
32908 | if (clipboard.isEmpty()) {
|
32909 | return;
|
32910 | }
|
32911 |
|
32912 | newTree = reduce(tree, function(pasteTree, elements, depthStr) {
|
32913 | var depth = parseInt(depthStr, 10);
|
32914 |
|
32915 | if (isNaN(depth)) {
|
32916 | return pasteTree;
|
32917 | }
|
32918 |
|
32919 | pasteTree[depth] = elements;
|
32920 |
|
32921 | return pasteTree;
|
32922 | }, {});
|
32923 |
|
32924 |
|
32925 | canPaste = rules.allowed('elements.paste', {
|
32926 | tree: newTree,
|
32927 | target: topParent
|
32928 | });
|
32929 |
|
32930 | if (!canPaste) {
|
32931 | eventBus.fire('elements.paste.rejected', {
|
32932 | context: {
|
32933 | tree: newTree,
|
32934 | position: position,
|
32935 | target: topParent
|
32936 | }
|
32937 | });
|
32938 |
|
32939 | return;
|
32940 | }
|
32941 |
|
32942 | modeling.pasteElements(newTree, topParent, position);
|
32943 | };
|
32944 |
|
32945 |
|
32946 | CopyPaste.prototype._computeDelta = function(elements, element) {
|
32947 | var bbox = this._bbox,
|
32948 | delta$$1 = {};
|
32949 |
|
32950 |
|
32951 | if (element.labelTarget) {
|
32952 | return delta(element, element.labelTarget);
|
32953 | }
|
32954 |
|
32955 |
|
32956 | if (element.priority === 3) {
|
32957 | delta$$1 = [];
|
32958 |
|
32959 | forEach(element.waypoints, function(waypoint) {
|
32960 | var waypointDelta = delta(waypoint, bbox);
|
32961 |
|
32962 | delta$$1.push(waypointDelta);
|
32963 | });
|
32964 | } else {
|
32965 | delta$$1 = delta(element, bbox);
|
32966 | }
|
32967 |
|
32968 | return delta$$1;
|
32969 | };
|
32970 |
|
32971 |
|
32972 | |
32973 |
|
32974 |
|
32975 |
|
32976 |
|
32977 |
|
32978 |
|
32979 |
|
32980 |
|
32981 | CopyPaste.prototype.hasRelations = function(elements, element) {
|
32982 | var source, target, labelTarget;
|
32983 |
|
32984 | if (element.waypoints) {
|
32985 | source = find(elements, matchPattern({ id: element.source.id }));
|
32986 | target = find(elements, matchPattern({ id: element.target.id }));
|
32987 |
|
32988 | if (!source || !target) {
|
32989 | return false;
|
32990 | }
|
32991 | }
|
32992 |
|
32993 | if (element.labelTarget) {
|
32994 | labelTarget = find(elements, matchPattern({ id: element.labelTarget.id }));
|
32995 |
|
32996 | if (!labelTarget) {
|
32997 | return false;
|
32998 | }
|
32999 | }
|
33000 |
|
33001 | return true;
|
33002 | };
|
33003 |
|
33004 |
|
33005 | CopyPaste.prototype.registerDescriptor = function(descriptor) {
|
33006 | if (typeof descriptor !== 'function') {
|
33007 | throw new Error('the descriptor must be a function');
|
33008 | }
|
33009 |
|
33010 | if (this._descriptors.indexOf(descriptor) !== -1) {
|
33011 | throw new Error('this descriptor is already registered');
|
33012 | }
|
33013 |
|
33014 | this._descriptors.push(descriptor);
|
33015 | };
|
33016 |
|
33017 |
|
33018 | CopyPaste.prototype._executeDescriptors = function(data) {
|
33019 | if (!data.descriptor) {
|
33020 | data.descriptor = {};
|
33021 | }
|
33022 |
|
33023 | forEach(this._descriptors, function(descriptor) {
|
33024 | data.descriptor = descriptor(data.element, data.descriptor);
|
33025 | });
|
33026 |
|
33027 | return data;
|
33028 | };
|
33029 |
|
33030 | |
33031 |
|
33032 |
|
33033 |
|
33034 |
|
33035 |
|
33036 |
|
33037 |
|
33038 |
|
33039 |
|
33040 |
|
33041 |
|
33042 |
|
33043 |
|
33044 |
|
33045 |
|
33046 | CopyPaste.prototype.createTree = function(elements) {
|
33047 | var rules = this._rules,
|
33048 | self = this;
|
33049 |
|
33050 | var tree = {},
|
33051 | includedElements = [],
|
33052 | _elements;
|
33053 |
|
33054 | var topLevel = getTopLevel(elements);
|
33055 |
|
33056 | tree.allShapes = [];
|
33057 |
|
33058 | function canCopy(collection, element) {
|
33059 | return rules.allowed('element.copy', {
|
33060 | collection: collection,
|
33061 | element: element
|
33062 | });
|
33063 | }
|
33064 |
|
33065 | function includeElement(data) {
|
33066 | var idx = findIndex(includedElements, matchPattern({ element: data.element })),
|
33067 | element;
|
33068 |
|
33069 | if (idx !== -1) {
|
33070 | element = includedElements[idx];
|
33071 | } else {
|
33072 | return includedElements.push(data);
|
33073 | }
|
33074 |
|
33075 |
|
33076 | if (element.depth < data.depth) {
|
33077 | includedElements.splice(idx, 1);
|
33078 |
|
33079 | includedElements.push(data);
|
33080 | }
|
33081 | }
|
33082 |
|
33083 |
|
33084 | eachElement(topLevel, function(element, i, depth) {
|
33085 | var nestedChildren = element.children;
|
33086 |
|
33087 |
|
33088 | if (element.labelTarget) {
|
33089 | return;
|
33090 | }
|
33091 |
|
33092 | function getNested(lists) {
|
33093 | forEach(lists, function(list) {
|
33094 | if (list && list.length) {
|
33095 |
|
33096 | forEach(list, function(elem) {
|
33097 |
|
33098 | forEach(elem.labels, function(label) {
|
33099 | includeElement({
|
33100 | element: label,
|
33101 | depth: depth
|
33102 | });
|
33103 | });
|
33104 |
|
33105 | includeElement({
|
33106 | element: elem,
|
33107 | depth: depth
|
33108 | });
|
33109 | });
|
33110 | }
|
33111 | });
|
33112 | }
|
33113 |
|
33114 |
|
33115 | forEach(element.labels, function(label) {
|
33116 |
|
33117 | includeElement({
|
33118 | element: label,
|
33119 | depth: depth
|
33120 | });
|
33121 | });
|
33122 |
|
33123 | getNested([ element.attachers, element.incoming, element.outgoing ]);
|
33124 |
|
33125 | includeElement({
|
33126 | element: element,
|
33127 | depth: depth
|
33128 | });
|
33129 |
|
33130 | if (nestedChildren) {
|
33131 | return nestedChildren;
|
33132 | }
|
33133 | });
|
33134 |
|
33135 | includedElements = map(includedElements, function(data) {
|
33136 |
|
33137 | return self._executeDescriptors(data);
|
33138 | });
|
33139 |
|
33140 |
|
33141 |
|
33142 | includedElements = sortBy(includedElements, function(data) {
|
33143 | return data.descriptor.priority;
|
33144 | });
|
33145 |
|
33146 | _elements = map(includedElements, function(data) {
|
33147 | return data.element;
|
33148 | });
|
33149 |
|
33150 | forEach(includedElements, function(data) {
|
33151 | var depth = data.depth;
|
33152 |
|
33153 | if (!self.hasRelations(tree.allShapes, data.element)) {
|
33154 | return;
|
33155 | }
|
33156 |
|
33157 | if (!canCopy(_elements, data.element)) {
|
33158 | return;
|
33159 | }
|
33160 |
|
33161 | tree.allShapes.push(data.element);
|
33162 |
|
33163 |
|
33164 | if (!tree[depth]) {
|
33165 | tree[depth] = [];
|
33166 | }
|
33167 |
|
33168 | tree[depth].push(data.descriptor);
|
33169 | });
|
33170 |
|
33171 | return tree;
|
33172 | };
|
33173 |
|
33174 | var CopyPasteModule = {
|
33175 | __depends__: [
|
33176 | ClipboardModule,
|
33177 | RulesModule,
|
33178 | MouseTrackingModule
|
33179 | ],
|
33180 | __init__: [ 'copyPaste' ],
|
33181 | copyPaste: [ 'type', CopyPaste ]
|
33182 | };
|
33183 |
|
33184 | function setProperties(descriptor, data, properties) {
|
33185 | forEach(properties, function(property) {
|
33186 | if (data[property] !== undefined) {
|
33187 | descriptor[property] = data[property];
|
33188 | }
|
33189 | });
|
33190 | }
|
33191 |
|
33192 | function removeProperties(element, properties) {
|
33193 | forEach(properties, function(prop) {
|
33194 | if (element[prop]) {
|
33195 | delete element[prop];
|
33196 | }
|
33197 | });
|
33198 | }
|
33199 |
|
33200 | function BpmnCopyPaste(
|
33201 | bpmnFactory, eventBus, copyPaste,
|
33202 | clipboard, canvas, bpmnRules) {
|
33203 |
|
33204 | var helper = new ModelCloneHelper(eventBus, bpmnFactory);
|
33205 |
|
33206 | copyPaste.registerDescriptor(function(element, descriptor) {
|
33207 | var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
|
33208 |
|
33209 | var colors = {};
|
33210 |
|
33211 | descriptor.type = element.type;
|
33212 |
|
33213 | setProperties(descriptor, businessObject.di, [ 'isExpanded' ]);
|
33214 |
|
33215 | setProperties(colors, businessObject.di, [ 'fill', 'stroke' ]);
|
33216 |
|
33217 | descriptor.colors = colors;
|
33218 |
|
33219 | if (element.type === 'label') {
|
33220 | return descriptor;
|
33221 | }
|
33222 |
|
33223 | setProperties(descriptor, businessObject, [
|
33224 | 'processRef',
|
33225 | 'triggeredByEvent'
|
33226 | ]);
|
33227 |
|
33228 | if (businessObject.default) {
|
33229 | descriptor.default = businessObject.default.id;
|
33230 | }
|
33231 |
|
33232 | return descriptor;
|
33233 | });
|
33234 |
|
33235 | eventBus.on('element.paste', function(context) {
|
33236 | var descriptor = context.descriptor,
|
33237 | createdElements = context.createdElements,
|
33238 | parent = descriptor.parent,
|
33239 | rootElement = canvas.getRootElement(),
|
33240 | oldBusinessObject = descriptor.oldBusinessObject,
|
33241 | newBusinessObject,
|
33242 | source,
|
33243 | target,
|
33244 | canConnect;
|
33245 |
|
33246 | newBusinessObject = bpmnFactory.create(oldBusinessObject.$type);
|
33247 |
|
33248 | var properties = getProperties(oldBusinessObject.$descriptor);
|
33249 |
|
33250 | properties = filter(properties, function(property) {
|
33251 | return IGNORED_PROPERTIES.indexOf(property.replace(/bpmn:/, '')) === -1;
|
33252 | });
|
33253 |
|
33254 | descriptor.businessObject = helper.clone(oldBusinessObject, newBusinessObject, properties);
|
33255 |
|
33256 | if (descriptor.type === 'label') {
|
33257 | return;
|
33258 | }
|
33259 |
|
33260 | if (is$1(parent, 'bpmn:Process')) {
|
33261 | descriptor.parent = is$1(rootElement, 'bpmn:Collaboration') ? rootElement : parent;
|
33262 | }
|
33263 |
|
33264 | if (descriptor.type === 'bpmn:DataOutputAssociation' ||
|
33265 | descriptor.type === 'bpmn:DataInputAssociation' ||
|
33266 | descriptor.type === 'bpmn:MessageFlow') {
|
33267 | descriptor.parent = rootElement;
|
33268 | }
|
33269 |
|
33270 | if (is$1(parent, 'bpmn:Lane')) {
|
33271 | descriptor.parent = parent.parent;
|
33272 | }
|
33273 |
|
33274 |
|
33275 | if (descriptor.waypoints) {
|
33276 | source = createdElements[descriptor.source];
|
33277 | target = createdElements[descriptor.target];
|
33278 |
|
33279 | if (source && target) {
|
33280 | source = source.element;
|
33281 | target = target.element;
|
33282 | }
|
33283 |
|
33284 | canConnect = bpmnRules.canConnect(source, target);
|
33285 |
|
33286 | if (canConnect) {
|
33287 | descriptor.type = canConnect.type;
|
33288 | }
|
33289 | }
|
33290 |
|
33291 |
|
33292 | delete newBusinessObject.id;
|
33293 |
|
33294 |
|
33295 | bpmnFactory._ensureId(newBusinessObject);
|
33296 |
|
33297 | if (descriptor.type === 'bpmn:Participant' && descriptor.processRef) {
|
33298 | descriptor.processRef = newBusinessObject.processRef = bpmnFactory.create('bpmn:Process');
|
33299 | }
|
33300 |
|
33301 | setProperties(newBusinessObject, descriptor, [
|
33302 | 'isExpanded',
|
33303 | 'triggeredByEvent'
|
33304 | ]);
|
33305 |
|
33306 | removeProperties(descriptor, [
|
33307 | 'triggeredByEvent'
|
33308 | ]);
|
33309 | });
|
33310 |
|
33311 | }
|
33312 |
|
33313 |
|
33314 | BpmnCopyPaste.$inject = [
|
33315 | 'bpmnFactory',
|
33316 | 'eventBus',
|
33317 | 'copyPaste',
|
33318 | 'clipboard',
|
33319 | 'canvas',
|
33320 | 'bpmnRules'
|
33321 | ];
|
33322 |
|
33323 | var CopyPasteModule$1 = {
|
33324 | __depends__: [
|
33325 | CopyPasteModule
|
33326 | ],
|
33327 | __init__: [ 'bpmnCopyPaste' ],
|
33328 | bpmnCopyPaste: [ 'type', BpmnCopyPaste ]
|
33329 | };
|
33330 |
|
33331 | var AXIS_DIMENSIONS = {
|
33332 | horizontal: [ 'x', 'width' ],
|
33333 | vertical: [ 'y', 'height' ]
|
33334 | };
|
33335 |
|
33336 | var THRESHOLD$1 = 5;
|
33337 |
|
33338 |
|
33339 | |
33340 |
|
33341 |
|
33342 | function DistributeElements(modeling) {
|
33343 | this._modeling = modeling;
|
33344 |
|
33345 | this._filters = [];
|
33346 |
|
33347 |
|
33348 | this.registerFilter(function(elements, axis, dimension) {
|
33349 | var elementsSize = 0,
|
33350 | numOfShapes = 0,
|
33351 | avgDimension;
|
33352 |
|
33353 | forEach(elements, function(element) {
|
33354 | if (element.waypoints || element.labelTarget) {
|
33355 | return;
|
33356 | }
|
33357 |
|
33358 | elementsSize += element[dimension];
|
33359 |
|
33360 | numOfShapes += 1;
|
33361 | });
|
33362 |
|
33363 | avgDimension = Math.round(elementsSize / numOfShapes);
|
33364 |
|
33365 | return filter(elements, function(element) {
|
33366 | return element[dimension] < (avgDimension + 50);
|
33367 | });
|
33368 | });
|
33369 |
|
33370 | }
|
33371 |
|
33372 | DistributeElements.$inject = [ 'modeling' ];
|
33373 |
|
33374 |
|
33375 | |
33376 |
|
33377 |
|
33378 |
|
33379 |
|
33380 |
|
33381 | DistributeElements.prototype.registerFilter = function(filterFn) {
|
33382 | if (typeof filterFn !== 'function') {
|
33383 | throw new Error('the filter has to be a function');
|
33384 | }
|
33385 |
|
33386 | this._filters.push(filterFn);
|
33387 | };
|
33388 |
|
33389 | |
33390 |
|
33391 |
|
33392 |
|
33393 |
|
33394 |
|
33395 | DistributeElements.prototype.trigger = function(elements, orientation) {
|
33396 | var modeling = this._modeling;
|
33397 |
|
33398 | var groups,
|
33399 | distributableElements;
|
33400 |
|
33401 | if (elements.length < 3) {
|
33402 | return;
|
33403 | }
|
33404 |
|
33405 | this._setOrientation(orientation);
|
33406 |
|
33407 | distributableElements = this._filterElements(elements);
|
33408 |
|
33409 | groups = this._createGroups(distributableElements);
|
33410 |
|
33411 |
|
33412 | if (groups.length <= 2) {
|
33413 | return;
|
33414 | }
|
33415 |
|
33416 | modeling.distributeElements(groups, this._axis, this._dimension);
|
33417 |
|
33418 | return groups;
|
33419 | };
|
33420 |
|
33421 | |
33422 |
|
33423 |
|
33424 |
|
33425 |
|
33426 |
|
33427 |
|
33428 | DistributeElements.prototype._filterElements = function(elements) {
|
33429 | var filters = this._filters,
|
33430 | axis = this._axis,
|
33431 | dimension = this._dimension,
|
33432 | distributableElements = [].concat(elements);
|
33433 |
|
33434 | if (!filters.length) {
|
33435 | return elements;
|
33436 | }
|
33437 |
|
33438 | forEach(filters, function(filterFn) {
|
33439 | distributableElements = filterFn(distributableElements, axis, dimension);
|
33440 | });
|
33441 |
|
33442 | return distributableElements;
|
33443 | };
|
33444 |
|
33445 |
|
33446 | |
33447 |
|
33448 |
|
33449 |
|
33450 |
|
33451 |
|
33452 |
|
33453 |
|
33454 |
|
33455 |
|
33456 |
|
33457 |
|
33458 |
|
33459 |
|
33460 |
|
33461 |
|
33462 |
|
33463 |
|
33464 |
|
33465 | DistributeElements.prototype._createGroups = function(elements) {
|
33466 | var rangeGroups = [],
|
33467 | self = this,
|
33468 | axis = this._axis,
|
33469 | dimension = this._dimension;
|
33470 |
|
33471 | if (!axis) {
|
33472 | throw new Error('must have a defined "axis" and "dimension"');
|
33473 | }
|
33474 |
|
33475 |
|
33476 | var sortedElements = sortBy(elements, axis);
|
33477 |
|
33478 | forEach(sortedElements, function(element, idx) {
|
33479 | var elementRange = self._findRange(element, axis, dimension),
|
33480 | range;
|
33481 |
|
33482 | var previous = rangeGroups[rangeGroups.length - 1];
|
33483 |
|
33484 | if (previous && self._hasIntersection(previous.range, elementRange)) {
|
33485 | rangeGroups[rangeGroups.length - 1].elements.push(element);
|
33486 | } else {
|
33487 | range = { range: elementRange, elements: [ element ] };
|
33488 |
|
33489 | rangeGroups.push(range);
|
33490 | }
|
33491 | });
|
33492 |
|
33493 | return rangeGroups;
|
33494 | };
|
33495 |
|
33496 |
|
33497 | |
33498 |
|
33499 |
|
33500 |
|
33501 |
|
33502 | DistributeElements.prototype._setOrientation = function(direction) {
|
33503 | var orientation = AXIS_DIMENSIONS[direction];
|
33504 |
|
33505 | this._axis = orientation[0];
|
33506 | this._dimension = orientation[1];
|
33507 | };
|
33508 |
|
33509 |
|
33510 | |
33511 |
|
33512 |
|
33513 |
|
33514 |
|
33515 |
|
33516 |
|
33517 |
|
33518 | DistributeElements.prototype._hasIntersection = function(rangeA, rangeB) {
|
33519 | return Math.max(rangeA.min, rangeA.max) >= Math.min(rangeB.min, rangeB.max) &&
|
33520 | Math.min(rangeA.min, rangeA.max) <= Math.max(rangeB.min, rangeB.max);
|
33521 | };
|
33522 |
|
33523 |
|
33524 | |
33525 |
|
33526 |
|
33527 |
|
33528 |
|
33529 |
|
33530 |
|
33531 |
|
33532 |
|
33533 | DistributeElements.prototype._findRange = function(element) {
|
33534 | var axis = element[this._axis],
|
33535 | dimension = element[this._dimension];
|
33536 |
|
33537 | return {
|
33538 | min: axis + THRESHOLD$1,
|
33539 | max: axis + dimension - THRESHOLD$1
|
33540 | };
|
33541 | };
|
33542 |
|
33543 | var DistributeElementsModule = {
|
33544 | __init__: [ 'distributeElements' ],
|
33545 | distributeElements: [ 'type', DistributeElements ]
|
33546 | };
|
33547 |
|
33548 | |
33549 |
|
33550 |
|
33551 |
|
33552 | function BpmnDistributeElements(distributeElements) {
|
33553 |
|
33554 | distributeElements.registerFilter(function(elements) {
|
33555 | return filter(elements, function(element) {
|
33556 | var cannotDistribute = isAny(element, [
|
33557 | 'bpmn:Association',
|
33558 | 'bpmn:BoundaryEvent',
|
33559 | 'bpmn:DataInputAssociation',
|
33560 | 'bpmn:DataOutputAssociation',
|
33561 | 'bpmn:Lane',
|
33562 | 'bpmn:MessageFlow',
|
33563 | 'bpmn:Participant',
|
33564 | 'bpmn:SequenceFlow',
|
33565 | 'bpmn:TextAnnotation'
|
33566 | ]);
|
33567 |
|
33568 | return !(element.labelTarget || cannotDistribute);
|
33569 | });
|
33570 | });
|
33571 | }
|
33572 |
|
33573 | BpmnDistributeElements.$inject = [ 'distributeElements' ];
|
33574 |
|
33575 | var DistributeElementsModule$1 = {
|
33576 | __depends__: [
|
33577 | DistributeElementsModule
|
33578 | ],
|
33579 | __init__: [ 'bpmnDistributeElements' ],
|
33580 | bpmnDistributeElements: [ 'type', BpmnDistributeElements ]
|
33581 | };
|
33582 |
|
33583 | var NOT_REGISTERED_ERROR = 'is not a registered action',
|
33584 | IS_REGISTERED_ERROR = 'is already registered';
|
33585 |
|
33586 |
|
33587 | |
33588 |
|
33589 |
|
33590 |
|
33591 |
|
33592 |
|
33593 |
|
33594 |
|
33595 |
|
33596 |
|
33597 |
|
33598 |
|
33599 |
|
33600 |
|
33601 |
|
33602 |
|
33603 |
|
33604 |
|
33605 |
|
33606 |
|
33607 | function EditorActions(eventBus, injector) {
|
33608 |
|
33609 |
|
33610 | this._actions = {};
|
33611 |
|
33612 | var self = this;
|
33613 |
|
33614 | eventBus.on('diagram.init', function() {
|
33615 |
|
33616 |
|
33617 |
|
33618 | self._registerDefaultActions(injector);
|
33619 |
|
33620 |
|
33621 |
|
33622 | eventBus.fire('editorActions.init', {
|
33623 | editorActions: self
|
33624 | });
|
33625 | });
|
33626 |
|
33627 | }
|
33628 |
|
33629 | EditorActions.$inject = [
|
33630 | 'eventBus',
|
33631 | 'injector'
|
33632 | ];
|
33633 |
|
33634 | |
33635 |
|
33636 |
|
33637 |
|
33638 |
|
33639 | EditorActions.prototype._registerDefaultActions = function(injector) {
|
33640 |
|
33641 |
|
33642 |
|
33643 | var commandStack = injector.get('commandStack', false);
|
33644 | var modeling = injector.get('modeling', false);
|
33645 | var selection = injector.get('selection', false);
|
33646 | var zoomScroll = injector.get('zoomScroll', false);
|
33647 | var copyPaste = injector.get('copyPaste', false);
|
33648 | var canvas = injector.get('canvas', false);
|
33649 | var rules = injector.get('rules', false);
|
33650 | var mouseTracking = injector.get('mouseTracking', false);
|
33651 | var keyboardMove = injector.get('keyboardMove', false);
|
33652 | var keyboardMoveSelection = injector.get('keyboardMoveSelection', false);
|
33653 |
|
33654 |
|
33655 |
|
33656 | if (commandStack) {
|
33657 | this.register('undo', function() {
|
33658 | commandStack.undo();
|
33659 | });
|
33660 |
|
33661 | this.register('redo', function() {
|
33662 | commandStack.redo();
|
33663 | });
|
33664 | }
|
33665 |
|
33666 | if (copyPaste && selection) {
|
33667 | this.register('copy', function() {
|
33668 | var selectedElements = selection.get();
|
33669 |
|
33670 | copyPaste.copy(selectedElements);
|
33671 | });
|
33672 | }
|
33673 |
|
33674 | if (mouseTracking && copyPaste) {
|
33675 | this.register('paste', function() {
|
33676 | var context = mouseTracking.getHoverContext();
|
33677 |
|
33678 | copyPaste.paste(context);
|
33679 | });
|
33680 | }
|
33681 |
|
33682 | if (zoomScroll) {
|
33683 | this.register('stepZoom', function(opts) {
|
33684 | zoomScroll.stepZoom(opts.value);
|
33685 | });
|
33686 | }
|
33687 |
|
33688 | if (canvas) {
|
33689 | this.register('zoom', function(opts) {
|
33690 | canvas.zoom(opts.value);
|
33691 | });
|
33692 | }
|
33693 |
|
33694 | if (modeling && selection && rules) {
|
33695 | this.register('removeSelection', function() {
|
33696 |
|
33697 | var selectedElements = selection.get();
|
33698 |
|
33699 | if (!selectedElements.length) {
|
33700 | return;
|
33701 | }
|
33702 |
|
33703 | var allowed = rules.allowed('elements.delete', { elements: selectedElements }),
|
33704 | removableElements;
|
33705 |
|
33706 | if (allowed === false) {
|
33707 | return;
|
33708 | }
|
33709 | else if (isArray(allowed)) {
|
33710 | removableElements = allowed;
|
33711 | }
|
33712 | else {
|
33713 | removableElements = selectedElements;
|
33714 | }
|
33715 |
|
33716 | if (removableElements.length) {
|
33717 | modeling.removeElements(removableElements.slice());
|
33718 | }
|
33719 | });
|
33720 | }
|
33721 |
|
33722 | if (keyboardMove) {
|
33723 | this.register('moveCanvas', function(opts) {
|
33724 | keyboardMove.moveCanvas(opts);
|
33725 | });
|
33726 | }
|
33727 |
|
33728 | if (keyboardMoveSelection) {
|
33729 | this.register('moveSelection', function(opts) {
|
33730 | keyboardMoveSelection.moveSelection(opts.direction, opts.accelerated);
|
33731 | });
|
33732 | }
|
33733 |
|
33734 | };
|
33735 |
|
33736 |
|
33737 | |
33738 |
|
33739 |
|
33740 |
|
33741 |
|
33742 |
|
33743 |
|
33744 |
|
33745 | EditorActions.prototype.trigger = function(action, opts) {
|
33746 | if (!this._actions[action]) {
|
33747 | throw error$2(action, NOT_REGISTERED_ERROR);
|
33748 | }
|
33749 |
|
33750 | return this._actions[action](opts);
|
33751 | };
|
33752 |
|
33753 |
|
33754 | |
33755 |
|
33756 |
|
33757 |
|
33758 |
|
33759 |
|
33760 |
|
33761 |
|
33762 |
|
33763 |
|
33764 |
|
33765 |
|
33766 |
|
33767 |
|
33768 |
|
33769 |
|
33770 |
|
33771 |
|
33772 |
|
33773 |
|
33774 |
|
33775 |
|
33776 | EditorActions.prototype.register = function(actions, listener) {
|
33777 | var self = this;
|
33778 |
|
33779 | if (typeof actions === 'string') {
|
33780 | return this._registerAction(actions, listener);
|
33781 | }
|
33782 |
|
33783 | forEach(actions, function(listener, action) {
|
33784 | self._registerAction(action, listener);
|
33785 | });
|
33786 | };
|
33787 |
|
33788 | |
33789 |
|
33790 |
|
33791 |
|
33792 |
|
33793 |
|
33794 | EditorActions.prototype._registerAction = function(action, listener) {
|
33795 | if (this.isRegistered(action)) {
|
33796 | throw error$2(action, IS_REGISTERED_ERROR);
|
33797 | }
|
33798 |
|
33799 | this._actions[action] = listener;
|
33800 | };
|
33801 |
|
33802 | |
33803 |
|
33804 |
|
33805 |
|
33806 |
|
33807 | EditorActions.prototype.unregister = function(action) {
|
33808 | if (!this.isRegistered(action)) {
|
33809 | throw error$2(action, NOT_REGISTERED_ERROR);
|
33810 | }
|
33811 |
|
33812 | this._actions[action] = undefined;
|
33813 | };
|
33814 |
|
33815 | |
33816 |
|
33817 |
|
33818 |
|
33819 |
|
33820 | EditorActions.prototype.getActions = function() {
|
33821 | return Object.keys(this._actions);
|
33822 | };
|
33823 |
|
33824 | |
33825 |
|
33826 |
|
33827 |
|
33828 |
|
33829 |
|
33830 |
|
33831 | EditorActions.prototype.isRegistered = function(action) {
|
33832 | return !!this._actions[action];
|
33833 | };
|
33834 |
|
33835 |
|
33836 | function error$2(action, message) {
|
33837 | return new Error(action + ' ' + message);
|
33838 | }
|
33839 |
|
33840 | var EditorActionsModule = {
|
33841 | __init__: [ 'editorActions' ],
|
33842 | editorActions: [ 'type', EditorActions ]
|
33843 | };
|
33844 |
|
33845 | |
33846 |
|
33847 |
|
33848 |
|
33849 |
|
33850 | function BpmnEditorActions(injector) {
|
33851 | injector.invoke(EditorActions, this);
|
33852 | }
|
33853 |
|
33854 | inherits_browser(BpmnEditorActions, EditorActions);
|
33855 |
|
33856 | BpmnEditorActions.$inject = [
|
33857 | 'injector'
|
33858 | ];
|
33859 |
|
33860 | |
33861 |
|
33862 |
|
33863 |
|
33864 |
|
33865 | BpmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
33866 |
|
33867 |
|
33868 |
|
33869 | EditorActions.prototype._registerDefaultActions.call(this, injector);
|
33870 |
|
33871 |
|
33872 |
|
33873 | var canvas = injector.get('canvas', false);
|
33874 | var elementRegistry = injector.get('elementRegistry', false);
|
33875 | var selection = injector.get('selection', false);
|
33876 | var spaceTool = injector.get('spaceTool', false);
|
33877 | var lassoTool = injector.get('lassoTool', false);
|
33878 | var handTool = injector.get('handTool', false);
|
33879 | var globalConnect = injector.get('globalConnect', false);
|
33880 | var distributeElements = injector.get('distributeElements', false);
|
33881 | var alignElements = injector.get('alignElements', false);
|
33882 | var directEditing = injector.get('directEditing', false);
|
33883 | var searchPad = injector.get('searchPad', false);
|
33884 | var modeling = injector.get('modeling', false);
|
33885 |
|
33886 |
|
33887 |
|
33888 | if (canvas && elementRegistry && selection) {
|
33889 | this._registerAction('selectElements', function() {
|
33890 |
|
33891 |
|
33892 | var rootElement = canvas.getRootElement();
|
33893 |
|
33894 | var elements = elementRegistry.filter(function(element) {
|
33895 | return element !== rootElement;
|
33896 | });
|
33897 |
|
33898 | selection.select(elements);
|
33899 |
|
33900 | return elements;
|
33901 | });
|
33902 | }
|
33903 |
|
33904 | if (spaceTool) {
|
33905 | this._registerAction('spaceTool', function() {
|
33906 | spaceTool.toggle();
|
33907 | });
|
33908 | }
|
33909 |
|
33910 | if (lassoTool) {
|
33911 | this._registerAction('lassoTool', function() {
|
33912 | lassoTool.toggle();
|
33913 | });
|
33914 | }
|
33915 |
|
33916 | if (handTool) {
|
33917 | this._registerAction('handTool', function() {
|
33918 | handTool.toggle();
|
33919 | });
|
33920 | }
|
33921 |
|
33922 | if (globalConnect) {
|
33923 | this._registerAction('globalConnectTool', function() {
|
33924 | globalConnect.toggle();
|
33925 | });
|
33926 | }
|
33927 |
|
33928 | if (selection && distributeElements) {
|
33929 | this._registerAction('distributeElements', function(opts) {
|
33930 | var currentSelection = selection.get(),
|
33931 | type = opts.type;
|
33932 |
|
33933 | if (currentSelection.length) {
|
33934 | distributeElements.trigger(currentSelection, type);
|
33935 | }
|
33936 | });
|
33937 | }
|
33938 |
|
33939 | if (selection && alignElements) {
|
33940 | this._registerAction('alignElements', function(opts) {
|
33941 | var currentSelection = selection.get(),
|
33942 | aligneableElements = [],
|
33943 | type = opts.type;
|
33944 |
|
33945 | if (currentSelection.length) {
|
33946 | aligneableElements = filter(currentSelection, function(element) {
|
33947 | return !is$1(element, 'bpmn:Lane');
|
33948 | });
|
33949 |
|
33950 | alignElements.trigger(aligneableElements, type);
|
33951 | }
|
33952 | });
|
33953 | }
|
33954 |
|
33955 | if (selection && modeling) {
|
33956 | this._registerAction('setColor', function(opts) {
|
33957 | var currentSelection = selection.get();
|
33958 |
|
33959 | if (currentSelection.length) {
|
33960 | modeling.setColor(currentSelection, opts);
|
33961 | }
|
33962 | });
|
33963 | }
|
33964 |
|
33965 | if (selection && directEditing) {
|
33966 | this._registerAction('directEditing', function() {
|
33967 | var currentSelection = selection.get();
|
33968 |
|
33969 | if (currentSelection.length) {
|
33970 | directEditing.activate(currentSelection[0]);
|
33971 | }
|
33972 | });
|
33973 | }
|
33974 |
|
33975 | if (searchPad) {
|
33976 | this._registerAction('find', function() {
|
33977 | searchPad.toggle();
|
33978 | });
|
33979 | }
|
33980 |
|
33981 | if (canvas && modeling) {
|
33982 | this._registerAction('moveToOrigin', function() {
|
33983 | var rootElement = canvas.getRootElement(),
|
33984 | boundingBox,
|
33985 | elements;
|
33986 |
|
33987 | if (is$1(rootElement, 'bpmn:Collaboration')) {
|
33988 | elements = elementRegistry.filter(function(element) {
|
33989 | return is$1(element.parent, 'bpmn:Collaboration');
|
33990 | });
|
33991 | } else {
|
33992 | elements = elementRegistry.filter(function(element) {
|
33993 | return element !== rootElement && !is$1(element.parent, 'bpmn:SubProcess');
|
33994 | });
|
33995 | }
|
33996 |
|
33997 | boundingBox = getBBox(elements);
|
33998 |
|
33999 | modeling.moveElements(
|
34000 | elements,
|
34001 | { x: -boundingBox.x, y: -boundingBox.y },
|
34002 | rootElement
|
34003 | );
|
34004 | });
|
34005 | }
|
34006 |
|
34007 | };
|
34008 |
|
34009 | var EditorActionsModule$1 = {
|
34010 | __depends__: [
|
34011 | EditorActionsModule
|
34012 | ],
|
34013 | editorActions: [ 'type', BpmnEditorActions ]
|
34014 | };
|
34015 |
|
34016 | |
34017 |
|
34018 |
|
34019 |
|
34020 |
|
34021 | function BpmnKeyboardBindings(injector) {
|
34022 | injector.invoke(KeyboardBindings, this);
|
34023 | }
|
34024 |
|
34025 | inherits_browser(BpmnKeyboardBindings, KeyboardBindings);
|
34026 |
|
34027 | BpmnKeyboardBindings.$inject = [
|
34028 | 'injector'
|
34029 | ];
|
34030 |
|
34031 |
|
34032 | |
34033 |
|
34034 |
|
34035 |
|
34036 |
|
34037 |
|
34038 | BpmnKeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
34039 |
|
34040 |
|
34041 | KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
|
34042 |
|
34043 | |
34044 |
|
34045 |
|
34046 |
|
34047 |
|
34048 |
|
34049 |
|
34050 | function addListener(action, fn) {
|
34051 |
|
34052 | if (editorActions.isRegistered(action)) {
|
34053 | keyboard.addListener(fn);
|
34054 | }
|
34055 | }
|
34056 |
|
34057 |
|
34058 |
|
34059 | addListener('selectElements', function(context) {
|
34060 |
|
34061 | var event = context.keyEvent;
|
34062 |
|
34063 | if (keyboard.isKey(['a', 'A'], event) && keyboard.isCmd(event)) {
|
34064 | editorActions.trigger('selectElements');
|
34065 |
|
34066 | return true;
|
34067 | }
|
34068 | });
|
34069 |
|
34070 |
|
34071 |
|
34072 | addListener('find', function(context) {
|
34073 |
|
34074 | var event = context.keyEvent;
|
34075 |
|
34076 | if (keyboard.isKey(['f', 'F'], event) && keyboard.isCmd(event)) {
|
34077 | editorActions.trigger('find');
|
34078 |
|
34079 | return true;
|
34080 | }
|
34081 | });
|
34082 |
|
34083 |
|
34084 |
|
34085 | addListener('spaceTool', function(context) {
|
34086 |
|
34087 | var event = context.keyEvent;
|
34088 |
|
34089 | if (keyboard.hasModifier(event)) {
|
34090 | return;
|
34091 | }
|
34092 |
|
34093 | if (keyboard.isKey(['s', 'S'], event)) {
|
34094 | editorActions.trigger('spaceTool');
|
34095 |
|
34096 | return true;
|
34097 | }
|
34098 | });
|
34099 |
|
34100 |
|
34101 |
|
34102 | addListener('lassoTool', function(context) {
|
34103 |
|
34104 | var event = context.keyEvent;
|
34105 |
|
34106 | if (keyboard.hasModifier(event)) {
|
34107 | return;
|
34108 | }
|
34109 |
|
34110 | if (keyboard.isKey(['l', 'L'], event)) {
|
34111 | editorActions.trigger('lassoTool');
|
34112 |
|
34113 | return true;
|
34114 | }
|
34115 | });
|
34116 |
|
34117 |
|
34118 |
|
34119 | addListener('handTool', function(context) {
|
34120 |
|
34121 | var event = context.keyEvent;
|
34122 |
|
34123 | if (keyboard.hasModifier(event)) {
|
34124 | return;
|
34125 | }
|
34126 |
|
34127 | if (keyboard.isKey(['h', 'H'], event)) {
|
34128 | editorActions.trigger('handTool');
|
34129 |
|
34130 | return true;
|
34131 | }
|
34132 | });
|
34133 |
|
34134 |
|
34135 |
|
34136 | addListener('globalConnectTool', function(context) {
|
34137 |
|
34138 | var event = context.keyEvent;
|
34139 |
|
34140 | if (keyboard.hasModifier(event)) {
|
34141 | return;
|
34142 | }
|
34143 |
|
34144 | if (keyboard.isKey(['c', 'C'], event)) {
|
34145 | editorActions.trigger('globalConnectTool');
|
34146 |
|
34147 | return true;
|
34148 | }
|
34149 | });
|
34150 |
|
34151 |
|
34152 |
|
34153 | addListener('directEditing', function(context) {
|
34154 |
|
34155 | var event = context.keyEvent;
|
34156 |
|
34157 | if (keyboard.hasModifier(event)) {
|
34158 | return;
|
34159 | }
|
34160 |
|
34161 | if (keyboard.isKey(['e', 'E'], event)) {
|
34162 | editorActions.trigger('directEditing');
|
34163 |
|
34164 | return true;
|
34165 | }
|
34166 | });
|
34167 |
|
34168 | };
|
34169 |
|
34170 | var KeyboardModule$1 = {
|
34171 | __depends__: [
|
34172 | KeyboardModule
|
34173 | ],
|
34174 | __init__: [ 'keyboardBindings' ],
|
34175 | keyboardBindings: [ 'type', BpmnKeyboardBindings ]
|
34176 | };
|
34177 |
|
34178 | var DEFAULT_CONFIG$1 = {
|
34179 | moveSpeed: 1,
|
34180 | moveSpeedAccelerated: 10
|
34181 | };
|
34182 |
|
34183 | var HIGHER_PRIORITY = 1500;
|
34184 |
|
34185 | var LEFT = 'left';
|
34186 | var UP = 'up';
|
34187 | var RIGHT = 'right';
|
34188 | var DOWN = 'down';
|
34189 |
|
34190 | var KEY_TO_DIRECTION = {
|
34191 | ArrowLeft: LEFT,
|
34192 | Left: LEFT,
|
34193 | ArrowUp: UP,
|
34194 | Up: UP,
|
34195 | ArrowRight: RIGHT,
|
34196 | Right: RIGHT,
|
34197 | ArrowDown: DOWN,
|
34198 | Down: DOWN
|
34199 | };
|
34200 |
|
34201 | var DIRECTIONS_DELTA = {
|
34202 | left: function(speed) {
|
34203 | return {
|
34204 | x: -speed,
|
34205 | y: 0
|
34206 | };
|
34207 | },
|
34208 | up: function(speed) {
|
34209 | return {
|
34210 | x: 0,
|
34211 | y: -speed
|
34212 | };
|
34213 | },
|
34214 | right: function(speed) {
|
34215 | return {
|
34216 | x: speed,
|
34217 | y: 0
|
34218 | };
|
34219 | },
|
34220 | down: function(speed) {
|
34221 | return {
|
34222 | x: 0,
|
34223 | y: speed
|
34224 | };
|
34225 | }
|
34226 | };
|
34227 |
|
34228 |
|
34229 | |
34230 |
|
34231 |
|
34232 |
|
34233 |
|
34234 |
|
34235 |
|
34236 |
|
34237 |
|
34238 |
|
34239 |
|
34240 |
|
34241 | function KeyboardMoveSelection(
|
34242 | config, keyboard,
|
34243 | modeling, selection
|
34244 | ) {
|
34245 |
|
34246 | var self = this;
|
34247 |
|
34248 | this._config = assign({}, DEFAULT_CONFIG$1, config || {});
|
34249 |
|
34250 | keyboard.addListener(HIGHER_PRIORITY, function(event) {
|
34251 |
|
34252 | var keyEvent = event.keyEvent;
|
34253 |
|
34254 | var direction = KEY_TO_DIRECTION[keyEvent.key];
|
34255 |
|
34256 | if (!direction) {
|
34257 | return;
|
34258 | }
|
34259 |
|
34260 | if (keyboard.isCmd(keyEvent)) {
|
34261 | return;
|
34262 | }
|
34263 |
|
34264 | var accelerated = keyboard.isShift(keyEvent);
|
34265 |
|
34266 | self.moveSelection(direction, accelerated);
|
34267 |
|
34268 | return true;
|
34269 | });
|
34270 |
|
34271 |
|
34272 | |
34273 |
|
34274 |
|
34275 |
|
34276 |
|
34277 |
|
34278 |
|
34279 | this.moveSelection = function(direction, accelerated) {
|
34280 |
|
34281 | var selectedElements = selection.get();
|
34282 |
|
34283 | if (!selectedElements.length) {
|
34284 | return;
|
34285 | }
|
34286 |
|
34287 | var speed = this._config[
|
34288 | accelerated ?
|
34289 | 'moveSpeedAccelerated' :
|
34290 | 'moveSpeed'
|
34291 | ];
|
34292 |
|
34293 | var delta = DIRECTIONS_DELTA[direction](speed);
|
34294 |
|
34295 | modeling.moveElements(selectedElements, delta);
|
34296 | };
|
34297 |
|
34298 | }
|
34299 |
|
34300 | KeyboardMoveSelection.$inject = [
|
34301 | 'config.keyboardMoveSelection',
|
34302 | 'keyboard',
|
34303 | 'modeling',
|
34304 | 'selection'
|
34305 | ];
|
34306 |
|
34307 | var KeyboardMoveSelectionModule = {
|
34308 | __depends__: [
|
34309 | KeyboardModule,
|
34310 | SelectionModule
|
34311 | ],
|
34312 | __init__: [
|
34313 | 'keyboardMoveSelection'
|
34314 | ],
|
34315 | keyboardMoveSelection: [ 'type', KeyboardMoveSelection ]
|
34316 | };
|
34317 |
|
34318 | |
34319 |
|
34320 |
|
34321 |
|
34322 |
|
34323 |
|
34324 |
|
34325 |
|
34326 |
|
34327 |
|
34328 |
|
34329 |
|
34330 | function ChangeSupport(
|
34331 | eventBus, canvas, elementRegistry,
|
34332 | graphicsFactory) {
|
34333 |
|
34334 |
|
34335 |
|
34336 |
|
34337 | eventBus.on('element.changed', function(event) {
|
34338 |
|
34339 | var element = event.element;
|
34340 |
|
34341 |
|
34342 |
|
34343 | if (element.parent || element === canvas.getRootElement()) {
|
34344 | event.gfx = elementRegistry.getGraphics(element);
|
34345 | }
|
34346 |
|
34347 |
|
34348 | if (!event.gfx) {
|
34349 | return;
|
34350 | }
|
34351 |
|
34352 | eventBus.fire(getType(element) + '.changed', event);
|
34353 | });
|
34354 |
|
34355 | eventBus.on('elements.changed', function(event) {
|
34356 |
|
34357 | var elements = event.elements;
|
34358 |
|
34359 | elements.forEach(function(e) {
|
34360 | eventBus.fire('element.changed', { element: e });
|
34361 | });
|
34362 |
|
34363 | graphicsFactory.updateContainments(elements);
|
34364 | });
|
34365 |
|
34366 | eventBus.on('shape.changed', function(event) {
|
34367 | graphicsFactory.update('shape', event.element, event.gfx);
|
34368 | });
|
34369 |
|
34370 | eventBus.on('connection.changed', function(event) {
|
34371 | graphicsFactory.update('connection', event.element, event.gfx);
|
34372 | });
|
34373 | }
|
34374 |
|
34375 | ChangeSupport.$inject = [
|
34376 | 'eventBus',
|
34377 | 'canvas',
|
34378 | 'elementRegistry',
|
34379 | 'graphicsFactory'
|
34380 | ];
|
34381 |
|
34382 | var ChangeSupportModule = {
|
34383 | __init__: [ 'changeSupport'],
|
34384 | changeSupport: [ 'type', ChangeSupport ]
|
34385 | };
|
34386 |
|
34387 | |
34388 |
|
34389 |
|
34390 | function PreviewSupport(elementRegistry, canvas, styles) {
|
34391 | this._elementRegistry = elementRegistry;
|
34392 | this._canvas = canvas;
|
34393 | this._styles = styles;
|
34394 | }
|
34395 |
|
34396 | PreviewSupport.$inject = [
|
34397 | 'elementRegistry',
|
34398 | 'canvas',
|
34399 | 'styles'
|
34400 | ];
|
34401 |
|
34402 |
|
34403 | |
34404 |
|
34405 |
|
34406 |
|
34407 |
|
34408 |
|
34409 |
|
34410 | PreviewSupport.prototype.getGfx = function(element) {
|
34411 | return this._elementRegistry.getGraphics(element);
|
34412 | };
|
34413 |
|
34414 | |
34415 |
|
34416 |
|
34417 |
|
34418 |
|
34419 |
|
34420 |
|
34421 |
|
34422 | PreviewSupport.prototype.addDragger = function(shape, group) {
|
34423 | var gfx = this.getGfx(shape);
|
34424 |
|
34425 |
|
34426 | var dragger = clone(gfx);
|
34427 | var bbox = gfx.getBoundingClientRect();
|
34428 |
|
34429 |
|
34430 | if (isConnection(shape)) {
|
34431 | removeMarkers(dragger);
|
34432 | }
|
34433 |
|
34434 | attr$1(dragger, this._styles.cls('djs-dragger', [], {
|
34435 | x: bbox.top,
|
34436 | y: bbox.left
|
34437 | }));
|
34438 |
|
34439 | append(group, dragger);
|
34440 |
|
34441 | return dragger;
|
34442 | };
|
34443 |
|
34444 | |
34445 |
|
34446 |
|
34447 |
|
34448 |
|
34449 |
|
34450 |
|
34451 |
|
34452 | PreviewSupport.prototype.addFrame = function(shape, group) {
|
34453 |
|
34454 | var frame = create('rect', {
|
34455 | class: 'djs-resize-overlay',
|
34456 | width: shape.width,
|
34457 | height: shape.height,
|
34458 | x: shape.x,
|
34459 | y: shape.y
|
34460 | });
|
34461 |
|
34462 | append(group, frame);
|
34463 |
|
34464 | return frame;
|
34465 | };
|
34466 |
|
34467 |
|
34468 |
|
34469 |
|
34470 | |
34471 |
|
34472 |
|
34473 |
|
34474 |
|
34475 | function removeMarkers(gfx) {
|
34476 |
|
34477 | if (gfx.children) {
|
34478 |
|
34479 | forEach(gfx.children, function(child) {
|
34480 |
|
34481 |
|
34482 | removeMarkers(child);
|
34483 |
|
34484 | });
|
34485 |
|
34486 | }
|
34487 |
|
34488 | gfx.style.markerStart = '';
|
34489 | gfx.style.markerEnd = '';
|
34490 |
|
34491 | }
|
34492 |
|
34493 | |
34494 |
|
34495 |
|
34496 | function isConnection(element) {
|
34497 | return element.waypoints;
|
34498 | }
|
34499 |
|
34500 | var PreviewSupportModule = {
|
34501 | __init__: [ 'previewSupport' ],
|
34502 | previewSupport: [ 'type', PreviewSupport ]
|
34503 | };
|
34504 |
|
34505 | var DEFAULT_MIN_WIDTH = 10;
|
34506 |
|
34507 |
|
34508 | |
34509 |
|
34510 |
|
34511 |
|
34512 |
|
34513 |
|
34514 |
|
34515 |
|
34516 |
|
34517 |
|
34518 |
|
34519 |
|
34520 |
|
34521 |
|
34522 |
|
34523 |
|
34524 |
|
34525 |
|
34526 |
|
34527 |
|
34528 |
|
34529 |
|
34530 |
|
34531 |
|
34532 |
|
34533 |
|
34534 |
|
34535 |
|
34536 |
|
34537 |
|
34538 |
|
34539 |
|
34540 |
|
34541 |
|
34542 |
|
34543 |
|
34544 |
|
34545 | function Resize(eventBus, rules, modeling, dragging) {
|
34546 |
|
34547 | this._dragging = dragging;
|
34548 | this._rules = rules;
|
34549 |
|
34550 | var self = this;
|
34551 |
|
34552 |
|
34553 | |
34554 |
|
34555 |
|
34556 |
|
34557 |
|
34558 |
|
34559 | function handleMove(context, delta) {
|
34560 |
|
34561 | var shape = context.shape,
|
34562 | direction = context.direction,
|
34563 | resizeConstraints = context.resizeConstraints,
|
34564 | newBounds;
|
34565 |
|
34566 | context.delta = delta;
|
34567 |
|
34568 | newBounds = resizeBounds(shape, direction, delta);
|
34569 |
|
34570 |
|
34571 | context.newBounds = ensureConstraints(newBounds, resizeConstraints);
|
34572 |
|
34573 |
|
34574 | context.canExecute = self.canResize(context);
|
34575 | }
|
34576 |
|
34577 | |
34578 |
|
34579 |
|
34580 |
|
34581 |
|
34582 | function handleStart(context) {
|
34583 |
|
34584 | var resizeConstraints = context.resizeConstraints,
|
34585 |
|
34586 | minBounds = context.minBounds;
|
34587 |
|
34588 | if (resizeConstraints !== undefined) {
|
34589 | return;
|
34590 | }
|
34591 |
|
34592 | if (minBounds === undefined) {
|
34593 | minBounds = self.computeMinResizeBox(context);
|
34594 | }
|
34595 |
|
34596 | context.resizeConstraints = {
|
34597 | min: asTRBL(minBounds)
|
34598 | };
|
34599 | }
|
34600 |
|
34601 | |
34602 |
|
34603 |
|
34604 |
|
34605 |
|
34606 | function handleEnd(context) {
|
34607 | var shape = context.shape,
|
34608 | canExecute = context.canExecute,
|
34609 | newBounds = context.newBounds;
|
34610 |
|
34611 | if (canExecute) {
|
34612 |
|
34613 |
|
34614 | newBounds = roundBounds(newBounds);
|
34615 |
|
34616 |
|
34617 | modeling.resizeShape(shape, newBounds);
|
34618 | }
|
34619 | }
|
34620 |
|
34621 |
|
34622 | eventBus.on('resize.start', function(event) {
|
34623 | handleStart(event.context);
|
34624 | });
|
34625 |
|
34626 | eventBus.on('resize.move', function(event) {
|
34627 | var delta = {
|
34628 | x: event.dx,
|
34629 | y: event.dy
|
34630 | };
|
34631 |
|
34632 | handleMove(event.context, delta);
|
34633 | });
|
34634 |
|
34635 | eventBus.on('resize.end', function(event) {
|
34636 | handleEnd(event.context);
|
34637 | });
|
34638 |
|
34639 | }
|
34640 |
|
34641 |
|
34642 | Resize.prototype.canResize = function(context) {
|
34643 | var rules = this._rules;
|
34644 |
|
34645 | var ctx = pick(context, [ 'newBounds', 'shape', 'delta', 'direction' ]);
|
34646 |
|
34647 | return rules.allowed('shape.resize', ctx);
|
34648 | };
|
34649 |
|
34650 | |
34651 |
|
34652 |
|
34653 |
|
34654 |
|
34655 |
|
34656 |
|
34657 |
|
34658 |
|
34659 |
|
34660 | Resize.prototype.activate = function(event, shape, contextOrDirection) {
|
34661 | var dragging = this._dragging,
|
34662 | context,
|
34663 | direction;
|
34664 |
|
34665 | if (typeof contextOrDirection === 'string') {
|
34666 | contextOrDirection = {
|
34667 | direction: contextOrDirection
|
34668 | };
|
34669 | }
|
34670 |
|
34671 | context = assign({ shape: shape }, contextOrDirection);
|
34672 |
|
34673 | direction = context.direction;
|
34674 |
|
34675 | if (!direction) {
|
34676 | throw new Error('must provide a direction (nw|se|ne|sw)');
|
34677 | }
|
34678 |
|
34679 | dragging.init(event, 'resize', {
|
34680 | autoActivate: true,
|
34681 | cursor: 'resize-' + (/nw|se/.test(direction) ? 'nwse' : 'nesw'),
|
34682 | data: {
|
34683 | shape: shape,
|
34684 | context: context
|
34685 | }
|
34686 | });
|
34687 | };
|
34688 |
|
34689 | Resize.prototype.computeMinResizeBox = function(context) {
|
34690 | var shape = context.shape,
|
34691 | direction = context.direction,
|
34692 | minDimensions,
|
34693 | childrenBounds;
|
34694 |
|
34695 | minDimensions = context.minDimensions || {
|
34696 | width: DEFAULT_MIN_WIDTH,
|
34697 | height: DEFAULT_MIN_WIDTH
|
34698 | };
|
34699 |
|
34700 |
|
34701 | childrenBounds = computeChildrenBBox(shape, context.childrenBoxPadding);
|
34702 |
|
34703 |
|
34704 |
|
34705 | return getMinResizeBounds(direction, shape, minDimensions, childrenBounds);
|
34706 | };
|
34707 |
|
34708 |
|
34709 | Resize.$inject = [
|
34710 | 'eventBus',
|
34711 | 'rules',
|
34712 | 'modeling',
|
34713 | 'dragging'
|
34714 | ];
|
34715 |
|
34716 | var MARKER_RESIZING = 'djs-resizing',
|
34717 | MARKER_RESIZE_NOT_OK = 'resize-not-ok';
|
34718 |
|
34719 | var LOW_PRIORITY$5 = 500;
|
34720 |
|
34721 |
|
34722 | |
34723 |
|
34724 |
|
34725 |
|
34726 |
|
34727 |
|
34728 |
|
34729 | function ResizePreview(eventBus, canvas, previewSupport) {
|
34730 |
|
34731 | |
34732 |
|
34733 |
|
34734 |
|
34735 |
|
34736 | function updateFrame(context) {
|
34737 |
|
34738 | var shape = context.shape,
|
34739 | bounds = context.newBounds,
|
34740 | frame = context.frame;
|
34741 |
|
34742 | if (!frame) {
|
34743 | frame = context.frame = previewSupport.addFrame(shape, canvas.getDefaultLayer());
|
34744 |
|
34745 | canvas.addMarker(shape, MARKER_RESIZING);
|
34746 | }
|
34747 |
|
34748 | if (bounds.width > 5) {
|
34749 | attr$1(frame, { x: bounds.x, width: bounds.width });
|
34750 | }
|
34751 |
|
34752 | if (bounds.height > 5) {
|
34753 | attr$1(frame, { y: bounds.y, height: bounds.height });
|
34754 | }
|
34755 |
|
34756 | if (context.canExecute) {
|
34757 | classes$1(frame).remove(MARKER_RESIZE_NOT_OK);
|
34758 | } else {
|
34759 | classes$1(frame).add(MARKER_RESIZE_NOT_OK);
|
34760 | }
|
34761 | }
|
34762 |
|
34763 | |
34764 |
|
34765 |
|
34766 |
|
34767 |
|
34768 | function removeFrame(context) {
|
34769 | var shape = context.shape,
|
34770 | frame = context.frame;
|
34771 |
|
34772 | if (frame) {
|
34773 | remove$1(context.frame);
|
34774 | }
|
34775 |
|
34776 | canvas.removeMarker(shape, MARKER_RESIZING);
|
34777 | }
|
34778 |
|
34779 |
|
34780 | eventBus.on('resize.move', LOW_PRIORITY$5, function(event) {
|
34781 | updateFrame(event.context);
|
34782 | });
|
34783 |
|
34784 |
|
34785 | eventBus.on('resize.cleanup', function(event) {
|
34786 | removeFrame(event.context);
|
34787 | });
|
34788 |
|
34789 | }
|
34790 |
|
34791 | ResizePreview.$inject = [
|
34792 | 'eventBus',
|
34793 | 'canvas',
|
34794 | 'previewSupport'
|
34795 | ];
|
34796 |
|
34797 | var HANDLE_OFFSET = -2,
|
34798 | HANDLE_SIZE = 5,
|
34799 | HANDLE_HIT_SIZE = 20;
|
34800 |
|
34801 | var CLS_RESIZER = 'djs-resizer';
|
34802 |
|
34803 |
|
34804 | |
34805 |
|
34806 |
|
34807 |
|
34808 |
|
34809 |
|
34810 |
|
34811 |
|
34812 | function ResizeHandles(eventBus, canvas, selection, resize) {
|
34813 |
|
34814 | this._resize = resize;
|
34815 | this._canvas = canvas;
|
34816 |
|
34817 | var self = this;
|
34818 |
|
34819 | eventBus.on('selection.changed', function(e) {
|
34820 | var newSelection = e.newSelection;
|
34821 |
|
34822 |
|
34823 | self.removeResizers();
|
34824 |
|
34825 |
|
34826 | if (newSelection.length === 1) {
|
34827 | forEach(newSelection, bind(self.addResizer, self));
|
34828 | }
|
34829 | });
|
34830 |
|
34831 | eventBus.on('shape.changed', function(e) {
|
34832 | var shape = e.element;
|
34833 |
|
34834 | if (selection.isSelected(shape)) {
|
34835 | self.removeResizers();
|
34836 |
|
34837 | self.addResizer(shape);
|
34838 | }
|
34839 | });
|
34840 | }
|
34841 |
|
34842 |
|
34843 | ResizeHandles.prototype.makeDraggable = function(element, gfx, direction) {
|
34844 | var resize = this._resize;
|
34845 |
|
34846 | function startResize(event$$1) {
|
34847 |
|
34848 | if (isPrimaryButton(event$$1)) {
|
34849 | resize.activate(event$$1, element, direction);
|
34850 | }
|
34851 | }
|
34852 |
|
34853 | componentEvent.bind(gfx, 'mousedown', startResize);
|
34854 | componentEvent.bind(gfx, 'touchstart', startResize);
|
34855 | };
|
34856 |
|
34857 |
|
34858 | ResizeHandles.prototype._createResizer = function(element, x, y, rotation, direction) {
|
34859 | var resizersParent = this._getResizersParent();
|
34860 |
|
34861 | var group = create('g');
|
34862 | classes$1(group).add(CLS_RESIZER);
|
34863 | classes$1(group).add(CLS_RESIZER + '-' + element.id);
|
34864 | classes$1(group).add(CLS_RESIZER + '-' + direction);
|
34865 |
|
34866 | append(resizersParent, group);
|
34867 |
|
34868 | var origin = -HANDLE_SIZE + HANDLE_OFFSET;
|
34869 |
|
34870 |
|
34871 | var visual = create('rect');
|
34872 | attr$1(visual, {
|
34873 | x: origin,
|
34874 | y: origin,
|
34875 | width: HANDLE_SIZE,
|
34876 | height: HANDLE_SIZE
|
34877 | });
|
34878 | classes$1(visual).add(CLS_RESIZER + '-visual');
|
34879 |
|
34880 | append(group, visual);
|
34881 |
|
34882 | var hit = create('rect');
|
34883 | attr$1(hit, {
|
34884 | x: origin,
|
34885 | y: origin,
|
34886 | width: HANDLE_HIT_SIZE,
|
34887 | height: HANDLE_HIT_SIZE
|
34888 | });
|
34889 | classes$1(hit).add(CLS_RESIZER + '-hit');
|
34890 |
|
34891 | append(group, hit);
|
34892 |
|
34893 | transform$1(group, x, y, rotation);
|
34894 |
|
34895 | return group;
|
34896 | };
|
34897 |
|
34898 | ResizeHandles.prototype.createResizer = function(element, direction) {
|
34899 | var resizer;
|
34900 |
|
34901 | var trbl = asTRBL(element);
|
34902 |
|
34903 | if (direction === 'nw') {
|
34904 | resizer = this._createResizer(element, trbl.left, trbl.top, 0, direction);
|
34905 | } else if (direction === 'ne') {
|
34906 | resizer = this._createResizer(element, trbl.right, trbl.top, 90, direction);
|
34907 | } else if (direction === 'se') {
|
34908 | resizer = this._createResizer(element, trbl.right, trbl.bottom, 180, direction);
|
34909 | } else {
|
34910 | resizer = this._createResizer(element, trbl.left, trbl.bottom, 270, direction);
|
34911 | }
|
34912 |
|
34913 | this.makeDraggable(element, resizer, direction);
|
34914 | };
|
34915 |
|
34916 |
|
34917 |
|
34918 | |
34919 |
|
34920 |
|
34921 |
|
34922 |
|
34923 | ResizeHandles.prototype.addResizer = function(shape) {
|
34924 | var resize = this._resize;
|
34925 |
|
34926 | if (!resize.canResize({ shape: shape })) {
|
34927 | return;
|
34928 | }
|
34929 |
|
34930 | this.createResizer(shape, 'nw');
|
34931 | this.createResizer(shape, 'ne');
|
34932 | this.createResizer(shape, 'se');
|
34933 | this.createResizer(shape, 'sw');
|
34934 | };
|
34935 |
|
34936 | |
34937 |
|
34938 |
|
34939 | ResizeHandles.prototype.removeResizers = function() {
|
34940 | var resizersParent = this._getResizersParent();
|
34941 |
|
34942 | clear$1(resizersParent);
|
34943 | };
|
34944 |
|
34945 | ResizeHandles.prototype._getResizersParent = function() {
|
34946 | return this._canvas.getLayer('resizers');
|
34947 | };
|
34948 |
|
34949 | ResizeHandles.$inject = [
|
34950 | 'eventBus',
|
34951 | 'canvas',
|
34952 | 'selection',
|
34953 | 'resize'
|
34954 | ];
|
34955 |
|
34956 | var ResizeModule = {
|
34957 | __depends__: [
|
34958 | RulesModule,
|
34959 | DraggingModule,
|
34960 | PreviewSupportModule
|
34961 | ],
|
34962 | __init__: [
|
34963 | 'resize',
|
34964 | 'resizePreview',
|
34965 | 'resizeHandles'
|
34966 | ],
|
34967 | resize: [ 'type', Resize ],
|
34968 | resizePreview: [ 'type', ResizePreview ],
|
34969 | resizeHandles: [ 'type', ResizeHandles ]
|
34970 | };
|
34971 |
|
34972 | function getLabelAttr(semantic) {
|
34973 | if (is$1(semantic, 'bpmn:FlowElement') ||
|
34974 | is$1(semantic, 'bpmn:Participant') ||
|
34975 | is$1(semantic, 'bpmn:Lane') ||
|
34976 | is$1(semantic, 'bpmn:SequenceFlow') ||
|
34977 | is$1(semantic, 'bpmn:MessageFlow')) {
|
34978 |
|
34979 | return 'name';
|
34980 | }
|
34981 |
|
34982 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
34983 | return 'text';
|
34984 | }
|
34985 | }
|
34986 |
|
34987 | function getLabel(element) {
|
34988 | var semantic = element.businessObject,
|
34989 | attr = getLabelAttr(semantic);
|
34990 |
|
34991 | if (attr) {
|
34992 | return semantic[attr] || '';
|
34993 | }
|
34994 | }
|
34995 |
|
34996 |
|
34997 | function setLabel(element, text, isExternal) {
|
34998 | var semantic = element.businessObject,
|
34999 | attr = getLabelAttr(semantic);
|
35000 |
|
35001 | if (attr) {
|
35002 | semantic[attr] = text;
|
35003 | }
|
35004 |
|
35005 | return element;
|
35006 | }
|
35007 |
|
35008 | function LabelEditingProvider(
|
35009 | eventBus, canvas, directEditing,
|
35010 | modeling, resizeHandles, textRenderer) {
|
35011 |
|
35012 | this._canvas = canvas;
|
35013 | this._modeling = modeling;
|
35014 | this._textRenderer = textRenderer;
|
35015 |
|
35016 | directEditing.registerProvider(this);
|
35017 |
|
35018 |
|
35019 | eventBus.on('element.dblclick', function(event) {
|
35020 | activateDirectEdit(event.element, true);
|
35021 | });
|
35022 |
|
35023 |
|
35024 | eventBus.on([
|
35025 | 'element.mousedown',
|
35026 | 'drag.init',
|
35027 | 'canvas.viewbox.changing',
|
35028 | 'autoPlace',
|
35029 | 'popupMenu.open'
|
35030 | ], function(event) {
|
35031 |
|
35032 | if (directEditing.isActive()) {
|
35033 | directEditing.complete();
|
35034 | }
|
35035 | });
|
35036 |
|
35037 |
|
35038 | eventBus.on([ 'commandStack.changed' ], function(e) {
|
35039 | if (directEditing.isActive()) {
|
35040 | directEditing.cancel();
|
35041 | }
|
35042 | });
|
35043 |
|
35044 |
|
35045 | eventBus.on('directEditing.activate', function(event) {
|
35046 | resizeHandles.removeResizers();
|
35047 | });
|
35048 |
|
35049 | eventBus.on('create.end', 500, function(event) {
|
35050 |
|
35051 | var element = event.shape,
|
35052 | canExecute = event.context.canExecute,
|
35053 | isTouch = event.isTouch;
|
35054 |
|
35055 |
|
35056 |
|
35057 |
|
35058 |
|
35059 |
|
35060 |
|
35061 |
|
35062 |
|
35063 | if (isTouch) {
|
35064 | return;
|
35065 | }
|
35066 |
|
35067 | if (!canExecute) {
|
35068 | return;
|
35069 | }
|
35070 |
|
35071 | activateDirectEdit(element);
|
35072 | });
|
35073 |
|
35074 | eventBus.on('autoPlace.end', 500, function(event) {
|
35075 | activateDirectEdit(event.shape);
|
35076 | });
|
35077 |
|
35078 |
|
35079 | function activateDirectEdit(element, force) {
|
35080 | if (force ||
|
35081 | isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation' ]) ||
|
35082 | isCollapsedSubProcess(element)) {
|
35083 |
|
35084 | directEditing.activate(element);
|
35085 | }
|
35086 | }
|
35087 |
|
35088 | }
|
35089 |
|
35090 | LabelEditingProvider.$inject = [
|
35091 | 'eventBus',
|
35092 | 'canvas',
|
35093 | 'directEditing',
|
35094 | 'modeling',
|
35095 | 'resizeHandles',
|
35096 | 'textRenderer'
|
35097 | ];
|
35098 |
|
35099 |
|
35100 | |
35101 |
|
35102 |
|
35103 |
|
35104 |
|
35105 |
|
35106 |
|
35107 | LabelEditingProvider.prototype.activate = function(element) {
|
35108 |
|
35109 |
|
35110 | var text = getLabel(element);
|
35111 |
|
35112 | if (text === undefined) {
|
35113 | return;
|
35114 | }
|
35115 |
|
35116 | var context = {
|
35117 | text: text
|
35118 | };
|
35119 |
|
35120 |
|
35121 | var bounds = this.getEditingBBox(element);
|
35122 |
|
35123 | assign(context, bounds);
|
35124 |
|
35125 | var options = {};
|
35126 |
|
35127 |
|
35128 | if (
|
35129 | isAny(element, [
|
35130 | 'bpmn:Task',
|
35131 | 'bpmn:Participant',
|
35132 | 'bpmn:Lane',
|
35133 | 'bpmn:CallActivity'
|
35134 | ]) ||
|
35135 | isCollapsedSubProcess(element)
|
35136 | ) {
|
35137 | assign(options, {
|
35138 | centerVertically: true
|
35139 | });
|
35140 | }
|
35141 |
|
35142 |
|
35143 | if (isLabelExternal(element)) {
|
35144 | assign(options, {
|
35145 | autoResize: true
|
35146 | });
|
35147 | }
|
35148 |
|
35149 |
|
35150 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
35151 | assign(options, {
|
35152 | resizable: true,
|
35153 | autoResize: true
|
35154 | });
|
35155 | }
|
35156 |
|
35157 | assign(context, {
|
35158 | options: options
|
35159 | });
|
35160 |
|
35161 | return context;
|
35162 | };
|
35163 |
|
35164 |
|
35165 | |
35166 |
|
35167 |
|
35168 |
|
35169 |
|
35170 |
|
35171 |
|
35172 |
|
35173 | LabelEditingProvider.prototype.getEditingBBox = function(element) {
|
35174 | var canvas = this._canvas;
|
35175 |
|
35176 | var target = element.label || element;
|
35177 |
|
35178 | var bbox = canvas.getAbsoluteBBox(target);
|
35179 |
|
35180 | var mid = {
|
35181 | x: bbox.x + bbox.width / 2,
|
35182 | y: bbox.y + bbox.height / 2
|
35183 | };
|
35184 |
|
35185 |
|
35186 | var bounds = { x: bbox.x, y: bbox.y };
|
35187 |
|
35188 | var zoom = canvas.zoom();
|
35189 |
|
35190 | var defaultStyle = this._textRenderer.getDefaultStyle(),
|
35191 | externalStyle = this._textRenderer.getExternalStyle();
|
35192 |
|
35193 |
|
35194 | var externalFontSize = externalStyle.fontSize * zoom,
|
35195 | externalLineHeight = externalStyle.lineHeight,
|
35196 | defaultFontSize = defaultStyle.fontSize * zoom,
|
35197 | defaultLineHeight = defaultStyle.lineHeight;
|
35198 |
|
35199 | var style = {
|
35200 | fontFamily: this._textRenderer.getDefaultStyle().fontFamily,
|
35201 | fontWeight: this._textRenderer.getDefaultStyle().fontWeight
|
35202 | };
|
35203 |
|
35204 |
|
35205 | if (is$1(element, 'bpmn:Lane') || isExpandedPool(element)) {
|
35206 |
|
35207 | assign(bounds, {
|
35208 | width: bbox.height,
|
35209 | height: 30 * zoom,
|
35210 | x: bbox.x - bbox.height / 2 + (15 * zoom),
|
35211 | y: mid.y - (30 * zoom) / 2
|
35212 | });
|
35213 |
|
35214 | assign(style, {
|
35215 | fontSize: defaultFontSize + 'px',
|
35216 | lineHeight: defaultLineHeight,
|
35217 | paddingTop: (7 * zoom) + 'px',
|
35218 | paddingBottom: (7 * zoom) + 'px',
|
35219 | paddingLeft: (5 * zoom) + 'px',
|
35220 | paddingRight: (5 * zoom) + 'px',
|
35221 | transform: 'rotate(-90deg)'
|
35222 | });
|
35223 | }
|
35224 |
|
35225 |
|
35226 |
|
35227 |
|
35228 | if (isAny(element, [ 'bpmn:Task', 'bpmn:CallActivity']) ||
|
35229 | isCollapsedPool(element) ||
|
35230 | isCollapsedSubProcess(element)) {
|
35231 |
|
35232 | assign(bounds, {
|
35233 | width: bbox.width,
|
35234 | height: bbox.height
|
35235 | });
|
35236 |
|
35237 | assign(style, {
|
35238 | fontSize: defaultFontSize + 'px',
|
35239 | lineHeight: defaultLineHeight,
|
35240 | paddingTop: (7 * zoom) + 'px',
|
35241 | paddingBottom: (7 * zoom) + 'px',
|
35242 | paddingLeft: (5 * zoom) + 'px',
|
35243 | paddingRight: (5 * zoom) + 'px'
|
35244 | });
|
35245 | }
|
35246 |
|
35247 |
|
35248 |
|
35249 | if (isExpandedSubProcess(element)) {
|
35250 | assign(bounds, {
|
35251 | width: bbox.width,
|
35252 | x: bbox.x
|
35253 | });
|
35254 |
|
35255 | assign(style, {
|
35256 | fontSize: defaultFontSize + 'px',
|
35257 | lineHeight: defaultLineHeight,
|
35258 | paddingTop: (7 * zoom) + 'px',
|
35259 | paddingBottom: (7 * zoom) + 'px',
|
35260 | paddingLeft: (5 * zoom) + 'px',
|
35261 | paddingRight: (5 * zoom) + 'px'
|
35262 | });
|
35263 | }
|
35264 |
|
35265 | var width = 90 * zoom,
|
35266 | paddingTop = 7 * zoom,
|
35267 | paddingBottom = 4 * zoom;
|
35268 |
|
35269 |
|
35270 | if (target.labelTarget) {
|
35271 | assign(bounds, {
|
35272 | width: width,
|
35273 | height: bbox.height + paddingTop + paddingBottom,
|
35274 | x: mid.x - width / 2,
|
35275 | y: bbox.y - paddingTop
|
35276 | });
|
35277 |
|
35278 | assign(style, {
|
35279 | fontSize: externalFontSize + 'px',
|
35280 | lineHeight: externalLineHeight,
|
35281 | paddingTop: paddingTop + 'px',
|
35282 | paddingBottom: paddingBottom + 'px'
|
35283 | });
|
35284 | }
|
35285 |
|
35286 |
|
35287 | if (isLabelExternal(target)
|
35288 | && !hasExternalLabel(target)
|
35289 | && !isLabel(target)) {
|
35290 |
|
35291 | var externalLabelMid = getExternalLabelMid(element);
|
35292 |
|
35293 | var absoluteBBox = canvas.getAbsoluteBBox({
|
35294 | x: externalLabelMid.x,
|
35295 | y: externalLabelMid.y,
|
35296 | width: 0,
|
35297 | height: 0
|
35298 | });
|
35299 |
|
35300 | var height = externalFontSize + paddingTop + paddingBottom;
|
35301 |
|
35302 | assign(bounds, {
|
35303 | width: width,
|
35304 | height: height,
|
35305 | x: absoluteBBox.x - width / 2,
|
35306 | y: absoluteBBox.y - height / 2
|
35307 | });
|
35308 |
|
35309 | assign(style, {
|
35310 | fontSize: externalFontSize + 'px',
|
35311 | lineHeight: externalLineHeight,
|
35312 | paddingTop: paddingTop + 'px',
|
35313 | paddingBottom: paddingBottom + 'px'
|
35314 | });
|
35315 | }
|
35316 |
|
35317 |
|
35318 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
35319 | assign(bounds, {
|
35320 | width: bbox.width,
|
35321 | height: bbox.height,
|
35322 | minWidth: 30 * zoom,
|
35323 | minHeight: 10 * zoom
|
35324 | });
|
35325 |
|
35326 | assign(style, {
|
35327 | textAlign: 'left',
|
35328 | paddingTop: (5 * zoom) + 'px',
|
35329 | paddingBottom: (7 * zoom) + 'px',
|
35330 | paddingLeft: (7 * zoom) + 'px',
|
35331 | paddingRight: (5 * zoom) + 'px',
|
35332 | fontSize: defaultFontSize + 'px',
|
35333 | lineHeight: defaultLineHeight
|
35334 | });
|
35335 | }
|
35336 |
|
35337 | return { bounds: bounds, style: style };
|
35338 | };
|
35339 |
|
35340 |
|
35341 | LabelEditingProvider.prototype.update = function(
|
35342 | element, newLabel,
|
35343 | activeContextText, bounds) {
|
35344 |
|
35345 | var newBounds,
|
35346 | bbox;
|
35347 |
|
35348 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
35349 |
|
35350 | bbox = this._canvas.getAbsoluteBBox(element);
|
35351 |
|
35352 | newBounds = {
|
35353 | x: element.x,
|
35354 | y: element.y,
|
35355 | width: element.width / bbox.width * bounds.width,
|
35356 | height: element.height / bbox.height * bounds.height
|
35357 | };
|
35358 | }
|
35359 |
|
35360 | if (isEmptyText(newLabel)) {
|
35361 | newLabel = null;
|
35362 | }
|
35363 |
|
35364 | this._modeling.updateLabel(element, newLabel, newBounds);
|
35365 | };
|
35366 |
|
35367 |
|
35368 |
|
35369 |
|
35370 |
|
35371 | function isCollapsedSubProcess(element) {
|
35372 | return is$1(element, 'bpmn:SubProcess') && !isExpanded(element);
|
35373 | }
|
35374 |
|
35375 | function isExpandedSubProcess(element) {
|
35376 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
35377 | }
|
35378 |
|
35379 | function isCollapsedPool(element) {
|
35380 | return is$1(element, 'bpmn:Participant') && !isExpanded(element);
|
35381 | }
|
35382 |
|
35383 | function isExpandedPool(element) {
|
35384 | return is$1(element, 'bpmn:Participant') && isExpanded(element);
|
35385 | }
|
35386 |
|
35387 | function isEmptyText(label) {
|
35388 | return !label || !label.trim();
|
35389 | }
|
35390 |
|
35391 | var MARKER_HIDDEN = 'djs-element-hidden',
|
35392 | MARKER_LABEL_HIDDEN = 'djs-label-hidden';
|
35393 |
|
35394 |
|
35395 | function LabelEditingPreview(
|
35396 | eventBus, canvas, elementRegistry,
|
35397 | pathMap) {
|
35398 |
|
35399 | var self = this;
|
35400 |
|
35401 | var defaultLayer = canvas.getDefaultLayer();
|
35402 |
|
35403 | var element, absoluteElementBBox, gfx;
|
35404 |
|
35405 | eventBus.on('directEditing.activate', function(context) {
|
35406 | var activeProvider = context.active;
|
35407 |
|
35408 | element = activeProvider.element.label || activeProvider.element;
|
35409 |
|
35410 |
|
35411 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
35412 | absoluteElementBBox = canvas.getAbsoluteBBox(element);
|
35413 |
|
35414 | gfx = create('g');
|
35415 |
|
35416 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
35417 | xScaleFactor: 1,
|
35418 | yScaleFactor: 1,
|
35419 | containerWidth: element.width,
|
35420 | containerHeight: element.height,
|
35421 | position: {
|
35422 | mx: 0.0,
|
35423 | my: 0.0
|
35424 | }
|
35425 | });
|
35426 |
|
35427 | var path = self.path = create('path');
|
35428 |
|
35429 | attr$1(path, {
|
35430 | d: textPathData,
|
35431 | strokeWidth: 2,
|
35432 | stroke: getStrokeColor$1(element)
|
35433 | });
|
35434 |
|
35435 | append(gfx, path);
|
35436 |
|
35437 | append(defaultLayer, gfx);
|
35438 |
|
35439 | translate(gfx, element.x, element.y);
|
35440 | }
|
35441 |
|
35442 | if (is$1(element, 'bpmn:TextAnnotation') ||
|
35443 | element.labelTarget) {
|
35444 | canvas.addMarker(element, MARKER_HIDDEN);
|
35445 | } else if (is$1(element, 'bpmn:Task') ||
|
35446 | is$1(element, 'bpmn:CallActivity') ||
|
35447 | is$1(element, 'bpmn:SubProcess') ||
|
35448 | is$1(element, 'bpmn:Participant')) {
|
35449 | canvas.addMarker(element, MARKER_LABEL_HIDDEN);
|
35450 | }
|
35451 | });
|
35452 |
|
35453 | eventBus.on('directEditing.resize', function(context) {
|
35454 |
|
35455 |
|
35456 | if (is$1(element, 'bpmn:TextAnnotation')) {
|
35457 | var height = context.height,
|
35458 | dy = context.dy;
|
35459 |
|
35460 | var newElementHeight = Math.max(element.height / absoluteElementBBox.height * (height + dy), 0);
|
35461 |
|
35462 | var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
|
35463 | xScaleFactor: 1,
|
35464 | yScaleFactor: 1,
|
35465 | containerWidth: element.width,
|
35466 | containerHeight: newElementHeight,
|
35467 | position: {
|
35468 | mx: 0.0,
|
35469 | my: 0.0
|
35470 | }
|
35471 | });
|
35472 |
|
35473 | attr$1(self.path, {
|
35474 | d: textPathData
|
35475 | });
|
35476 | }
|
35477 | });
|
35478 |
|
35479 | eventBus.on([ 'directEditing.complete', 'directEditing.cancel' ], function(context) {
|
35480 | var activeProvider = context.active;
|
35481 |
|
35482 | if (activeProvider) {
|
35483 | canvas.removeMarker(activeProvider.element.label || activeProvider.element, MARKER_HIDDEN);
|
35484 | canvas.removeMarker(element, MARKER_LABEL_HIDDEN);
|
35485 | }
|
35486 |
|
35487 | element = undefined;
|
35488 | absoluteElementBBox = undefined;
|
35489 |
|
35490 | if (gfx) {
|
35491 | remove$1(gfx);
|
35492 |
|
35493 | gfx = undefined;
|
35494 | }
|
35495 | });
|
35496 | }
|
35497 |
|
35498 | LabelEditingPreview.$inject = [
|
35499 | 'eventBus',
|
35500 | 'canvas',
|
35501 | 'elementRegistry',
|
35502 | 'pathMap'
|
35503 | ];
|
35504 |
|
35505 |
|
35506 |
|
35507 |
|
35508 | function getStrokeColor$1(element, defaultColor) {
|
35509 | var bo = getBusinessObject(element);
|
35510 |
|
35511 | return bo.di.get('stroke') || defaultColor || 'black';
|
35512 | }
|
35513 |
|
35514 | var LabelEditingModule = {
|
35515 | __depends__: [
|
35516 | ChangeSupportModule,
|
35517 | ResizeModule,
|
35518 | DirectEditingModule
|
35519 | ],
|
35520 | __init__: [
|
35521 | 'labelEditingProvider',
|
35522 | 'labelEditingPreview'
|
35523 | ],
|
35524 | labelEditingProvider: [ 'type', LabelEditingProvider ],
|
35525 | labelEditingPreview: [ 'type', LabelEditingPreview ]
|
35526 | };
|
35527 |
|
35528 | |
35529 |
|
35530 |
|
35531 |
|
35532 |
|
35533 |
|
35534 |
|
35535 |
|
35536 | function AdaptiveLabelPositioningBehavior(eventBus, modeling) {
|
35537 |
|
35538 | CommandInterceptor.call(this, eventBus);
|
35539 |
|
35540 | this.postExecuted([
|
35541 | 'connection.create',
|
35542 | 'connection.layout',
|
35543 | 'connection.reconnectEnd',
|
35544 | 'connection.reconnectStart',
|
35545 | 'connection.updateWaypoints'
|
35546 | ], function(event) {
|
35547 |
|
35548 | var context = event.context,
|
35549 | connection = context.connection;
|
35550 |
|
35551 | var source = connection.source,
|
35552 | target = connection.target;
|
35553 |
|
35554 | checkLabelAdjustment(source);
|
35555 | checkLabelAdjustment(target);
|
35556 | });
|
35557 |
|
35558 |
|
35559 | this.postExecuted([
|
35560 | 'label.create'
|
35561 | ], function(event) {
|
35562 | checkLabelAdjustment(event.context.shape.labelTarget);
|
35563 | });
|
35564 |
|
35565 |
|
35566 | function checkLabelAdjustment(element) {
|
35567 |
|
35568 |
|
35569 | if (!hasExternalLabel(element)) {
|
35570 | return;
|
35571 | }
|
35572 |
|
35573 | var optimalPosition = getOptimalPosition(element);
|
35574 |
|
35575 |
|
35576 | if (!optimalPosition) {
|
35577 | return;
|
35578 | }
|
35579 |
|
35580 | adjustLabelPosition(element, optimalPosition);
|
35581 | }
|
35582 |
|
35583 | var ELEMENT_LABEL_DISTANCE = 10;
|
35584 |
|
35585 | function adjustLabelPosition(element, orientation) {
|
35586 |
|
35587 | var elementMid = getMid(element),
|
35588 | label = element.label,
|
35589 | labelMid = getMid(label);
|
35590 |
|
35591 | var elementTrbl = asTRBL(element);
|
35592 |
|
35593 | var newLabelMid;
|
35594 |
|
35595 | switch (orientation) {
|
35596 | case 'top':
|
35597 | newLabelMid = {
|
35598 | x: elementMid.x,
|
35599 | y: elementTrbl.top - ELEMENT_LABEL_DISTANCE - label.height / 2
|
35600 | };
|
35601 |
|
35602 | break;
|
35603 |
|
35604 | case 'left':
|
35605 |
|
35606 | newLabelMid = {
|
35607 | x: elementTrbl.left - ELEMENT_LABEL_DISTANCE - label.width / 2,
|
35608 | y: elementMid.y
|
35609 | };
|
35610 |
|
35611 | break;
|
35612 |
|
35613 | case 'bottom':
|
35614 |
|
35615 | newLabelMid = {
|
35616 | x: elementMid.x,
|
35617 | y: elementTrbl.bottom + ELEMENT_LABEL_DISTANCE + label.height / 2
|
35618 | };
|
35619 |
|
35620 | break;
|
35621 |
|
35622 | case 'right':
|
35623 |
|
35624 | newLabelMid = {
|
35625 | x: elementTrbl.right + ELEMENT_LABEL_DISTANCE + label.width / 2,
|
35626 | y: elementMid.y
|
35627 | };
|
35628 |
|
35629 | break;
|
35630 | }
|
35631 |
|
35632 |
|
35633 | var delta$$1 = delta(newLabelMid, labelMid);
|
35634 |
|
35635 | modeling.moveShape(label, delta$$1);
|
35636 | }
|
35637 |
|
35638 | }
|
35639 |
|
35640 | inherits_browser(AdaptiveLabelPositioningBehavior, CommandInterceptor);
|
35641 |
|
35642 | AdaptiveLabelPositioningBehavior.$inject = [
|
35643 | 'eventBus',
|
35644 | 'modeling'
|
35645 | ];
|
35646 |
|
35647 |
|
35648 | |
35649 |
|
35650 |
|
35651 |
|
35652 |
|
35653 |
|
35654 |
|
35655 |
|
35656 | function getOptimalPosition(element) {
|
35657 |
|
35658 | var labelMid = getMid(element.label);
|
35659 |
|
35660 | var elementMid = getMid(element);
|
35661 |
|
35662 | var labelOrientation = getApproximateOrientation(elementMid, labelMid);
|
35663 |
|
35664 | if (!isAligned(labelOrientation)) {
|
35665 | return;
|
35666 | }
|
35667 |
|
35668 | var takenAlignments = [].concat(
|
35669 | element.incoming.map(function(c) {
|
35670 | return c.waypoints[c.waypoints.length - 2 ];
|
35671 | }),
|
35672 | element.outgoing.map(function(c) {
|
35673 | return c.waypoints[1];
|
35674 | })
|
35675 | ).map(function(point) {
|
35676 | return getApproximateOrientation(elementMid, point);
|
35677 | });
|
35678 |
|
35679 | var freeAlignments = ALIGNMENTS.filter(function(alignment) {
|
35680 |
|
35681 | return takenAlignments.indexOf(alignment) === -1;
|
35682 | });
|
35683 |
|
35684 |
|
35685 | if (freeAlignments.indexOf(labelOrientation) !== -1) {
|
35686 | return;
|
35687 | }
|
35688 |
|
35689 | return freeAlignments[0];
|
35690 | }
|
35691 |
|
35692 | var ALIGNMENTS = [
|
35693 | 'top',
|
35694 | 'bottom',
|
35695 | 'left',
|
35696 | 'right'
|
35697 | ];
|
35698 |
|
35699 | function getApproximateOrientation(p0, p1) {
|
35700 | return getOrientation(p1, p0, 5);
|
35701 | }
|
35702 |
|
35703 | function isAligned(orientation) {
|
35704 | return ALIGNMENTS.indexOf(orientation) !== -1;
|
35705 | }
|
35706 |
|
35707 | function AppendBehavior(eventBus, elementFactory, bpmnRules) {
|
35708 |
|
35709 | CommandInterceptor.call(this, eventBus);
|
35710 |
|
35711 |
|
35712 |
|
35713 | this.preExecute('shape.append', function(context) {
|
35714 |
|
35715 | var source = context.source,
|
35716 | shape = context.shape;
|
35717 |
|
35718 | if (!context.position) {
|
35719 |
|
35720 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
35721 | context.position = {
|
35722 | x: source.x + source.width / 2 + 75,
|
35723 | y: source.y - (50) - shape.height / 2
|
35724 | };
|
35725 | } else {
|
35726 | context.position = {
|
35727 | x: source.x + source.width + 80 + shape.width / 2,
|
35728 | y: source.y + source.height / 2
|
35729 | };
|
35730 | }
|
35731 | }
|
35732 | }, true);
|
35733 | }
|
35734 |
|
35735 | inherits_browser(AppendBehavior, CommandInterceptor);
|
35736 |
|
35737 | AppendBehavior.$inject = [
|
35738 | 'eventBus',
|
35739 | 'elementFactory',
|
35740 | 'bpmnRules'
|
35741 | ];
|
35742 |
|
35743 | |
35744 |
|
35745 |
|
35746 | function BoundaryEventBehavior(eventBus, modeling) {
|
35747 |
|
35748 | CommandInterceptor.call(this, eventBus);
|
35749 |
|
35750 | function getBoundaryEvents(element) {
|
35751 | return filter(element.attachers, function(attacher) {
|
35752 | return is$1(attacher, 'bpmn:BoundaryEvent');
|
35753 | });
|
35754 | }
|
35755 |
|
35756 |
|
35757 | this.postExecute('connection.create', function(event) {
|
35758 | var source = event.context.source,
|
35759 | target = event.context.target,
|
35760 | boundaryEvents = getBoundaryEvents(target);
|
35761 |
|
35762 | if (
|
35763 | is$1(source, 'bpmn:EventBasedGateway') &&
|
35764 | is$1(target, 'bpmn:ReceiveTask') &&
|
35765 | boundaryEvents.length > 0
|
35766 | ) {
|
35767 | modeling.removeElements(boundaryEvents);
|
35768 | }
|
35769 |
|
35770 | });
|
35771 |
|
35772 |
|
35773 | this.postExecute('connection.reconnectStart', function(event) {
|
35774 | var oldSource = event.context.oldSource,
|
35775 | newSource = event.context.newSource;
|
35776 |
|
35777 | if (is$1(oldSource, 'bpmn:Gateway') &&
|
35778 | is$1(newSource, 'bpmn:EventBasedGateway')) {
|
35779 | forEach(newSource.outgoing, function(connection) {
|
35780 | var target = connection.target,
|
35781 | attachedboundaryEvents = getBoundaryEvents(target);
|
35782 |
|
35783 | if (is$1(target, 'bpmn:ReceiveTask') &&
|
35784 | attachedboundaryEvents.length > 0) {
|
35785 | modeling.removeElements(attachedboundaryEvents);
|
35786 | }
|
35787 | });
|
35788 | }
|
35789 | });
|
35790 | }
|
35791 |
|
35792 | BoundaryEventBehavior.$inject = [
|
35793 | 'eventBus',
|
35794 | 'modeling'
|
35795 | ];
|
35796 |
|
35797 | inherits_browser(BoundaryEventBehavior, CommandInterceptor);
|
35798 |
|
35799 | function CopyPasteBehavior(eventBus, modeling, canvas) {
|
35800 |
|
35801 | CommandInterceptor.call(this, eventBus);
|
35802 |
|
35803 | this.preExecute('elements.paste', 1500, function(context) {
|
35804 | var topParent = context.topParent;
|
35805 |
|
35806 |
|
35807 | if (!topParent.parent) {
|
35808 | context.topParent = canvas.getRootElement();
|
35809 | }
|
35810 |
|
35811 | if (is$1(topParent, 'bpmn:Lane')) {
|
35812 | do {
|
35813 |
|
35814 | topParent = context.topParent = topParent.parent;
|
35815 |
|
35816 | } while (is$1(topParent, 'bpmn:Lane') || !is$1(topParent, 'bpmn:Participant'));
|
35817 | }
|
35818 | }, true);
|
35819 |
|
35820 | this.postExecute('elements.paste', function(context) {
|
35821 |
|
35822 | var tree = context.tree,
|
35823 | createdElements = tree.createdElements;
|
35824 |
|
35825 | forEach(createdElements, function(data) {
|
35826 | var element = data.element,
|
35827 | businessObject = element.businessObject,
|
35828 | descriptor = data.descriptor,
|
35829 | defaultFlow;
|
35830 |
|
35831 | if ((is$1(businessObject, 'bpmn:ExclusiveGateway') || is$1(businessObject, 'bpmn:InclusiveGateway') ||
|
35832 | is$1(businessObject, 'bpmn:Activity')) && descriptor.default) {
|
35833 |
|
35834 | defaultFlow = createdElements[descriptor.default];
|
35835 |
|
35836 |
|
35837 | if (defaultFlow) {
|
35838 | defaultFlow = defaultFlow.element;
|
35839 | } else {
|
35840 | defaultFlow = undefined;
|
35841 | }
|
35842 |
|
35843 | delete element.default;
|
35844 |
|
35845 | modeling.updateProperties(element, { default: defaultFlow });
|
35846 | }
|
35847 | });
|
35848 | }, true);
|
35849 | }
|
35850 |
|
35851 |
|
35852 | CopyPasteBehavior.$inject = [
|
35853 | 'eventBus',
|
35854 | 'modeling',
|
35855 | 'canvas'
|
35856 | ];
|
35857 |
|
35858 | inherits_browser(CopyPasteBehavior, CommandInterceptor);
|
35859 |
|
35860 | |
35861 |
|
35862 |
|
35863 | function CreateBoundaryEventBehavior(
|
35864 | eventBus, modeling, elementFactory,
|
35865 | bpmnFactory) {
|
35866 |
|
35867 | CommandInterceptor.call(this, eventBus);
|
35868 |
|
35869 | |
35870 |
|
35871 |
|
35872 |
|
35873 |
|
35874 | this.preExecute('shape.create', function(context) {
|
35875 | var shape = context.shape,
|
35876 | host = context.host,
|
35877 | businessObject,
|
35878 | boundaryEvent;
|
35879 |
|
35880 | var attrs = {
|
35881 | cancelActivity: true
|
35882 | };
|
35883 |
|
35884 | if (host && is$1(shape, 'bpmn:IntermediateThrowEvent')) {
|
35885 | attrs.attachedToRef = host.businessObject;
|
35886 |
|
35887 | businessObject = bpmnFactory.create('bpmn:BoundaryEvent', attrs);
|
35888 |
|
35889 | boundaryEvent = {
|
35890 | type: 'bpmn:BoundaryEvent',
|
35891 | businessObject: businessObject
|
35892 | };
|
35893 |
|
35894 | context.shape = elementFactory.createShape(boundaryEvent);
|
35895 | }
|
35896 | }, true);
|
35897 | }
|
35898 |
|
35899 | CreateBoundaryEventBehavior.$inject = [
|
35900 | 'eventBus',
|
35901 | 'modeling',
|
35902 | 'elementFactory',
|
35903 | 'bpmnFactory'
|
35904 | ];
|
35905 |
|
35906 | inherits_browser(CreateBoundaryEventBehavior, CommandInterceptor);
|
35907 |
|
35908 | |
35909 |
|
35910 |
|
35911 | function CreateDataObjectBehavior(eventBus, bpmnFactory, moddle) {
|
35912 |
|
35913 | CommandInterceptor.call(this, eventBus);
|
35914 |
|
35915 | this.preExecute('shape.create', function(event) {
|
35916 |
|
35917 | var context = event.context,
|
35918 | shape = context.shape;
|
35919 |
|
35920 | if (is$1(shape, 'bpmn:DataObjectReference') && shape.type !== 'label') {
|
35921 |
|
35922 |
|
35923 | var dataObject = bpmnFactory.create('bpmn:DataObject');
|
35924 |
|
35925 |
|
35926 | shape.businessObject.dataObjectRef = dataObject;
|
35927 | }
|
35928 | });
|
35929 |
|
35930 | }
|
35931 |
|
35932 | CreateDataObjectBehavior.$inject = [
|
35933 | 'eventBus',
|
35934 | 'bpmnFactory',
|
35935 | 'moddle'
|
35936 | ];
|
35937 |
|
35938 | inherits_browser(CreateDataObjectBehavior, CommandInterceptor);
|
35939 |
|
35940 | |
35941 |
|
35942 |
|
35943 | function CreateParticipantBehavior(
|
35944 | eventBus, modeling, elementFactory,
|
35945 | bpmnFactory, canvas) {
|
35946 |
|
35947 | CommandInterceptor.call(this, eventBus);
|
35948 |
|
35949 | |
35950 |
|
35951 |
|
35952 |
|
35953 |
|
35954 | this.preExecute('shape.create', function(context) {
|
35955 |
|
35956 | var parent = context.parent,
|
35957 | shape = context.shape,
|
35958 | position = context.position;
|
35959 |
|
35960 | var rootElement = canvas.getRootElement();
|
35961 |
|
35962 | if (
|
35963 | is$1(parent, 'bpmn:Process') &&
|
35964 | is$1(shape, 'bpmn:Participant') &&
|
35965 | !is$1(rootElement, 'bpmn:Collaboration')
|
35966 | ) {
|
35967 |
|
35968 |
|
35969 |
|
35970 |
|
35971 | var collaborationElement = modeling.makeCollaboration();
|
35972 |
|
35973 |
|
35974 |
|
35975 |
|
35976 | context.position = position;
|
35977 | context.parent = collaborationElement;
|
35978 |
|
35979 | context.processRoot = parent;
|
35980 | }
|
35981 | }, true);
|
35982 |
|
35983 |
|
35984 | this.execute('shape.create', function(context) {
|
35985 |
|
35986 | var processRoot = context.processRoot,
|
35987 | shape = context.shape;
|
35988 |
|
35989 | if (processRoot) {
|
35990 | context.oldProcessRef = shape.businessObject.processRef;
|
35991 |
|
35992 |
|
35993 | shape.businessObject.processRef = processRoot.businessObject;
|
35994 | }
|
35995 | }, true);
|
35996 |
|
35997 |
|
35998 | this.revert('shape.create', function(context) {
|
35999 | var processRoot = context.processRoot,
|
36000 | shape = context.shape;
|
36001 |
|
36002 | if (processRoot) {
|
36003 |
|
36004 | shape.businessObject.processRef = context.oldProcessRef;
|
36005 | }
|
36006 | }, true);
|
36007 |
|
36008 |
|
36009 | this.postExecute('shape.create', function(context) {
|
36010 |
|
36011 | var processRoot = context.processRoot,
|
36012 | shape = context.shape;
|
36013 |
|
36014 | if (processRoot) {
|
36015 |
|
36016 | var processChildren = processRoot.children.slice();
|
36017 | modeling.moveElements(processChildren, { x: 0, y: 0 }, shape);
|
36018 | }
|
36019 |
|
36020 | }, true);
|
36021 |
|
36022 | }
|
36023 |
|
36024 | CreateParticipantBehavior.$inject = [
|
36025 | 'eventBus',
|
36026 | 'modeling',
|
36027 | 'elementFactory',
|
36028 | 'bpmnFactory',
|
36029 | 'canvas'
|
36030 | ];
|
36031 |
|
36032 | inherits_browser(CreateParticipantBehavior, CommandInterceptor);
|
36033 |
|
36034 | var TARGET_REF_PLACEHOLDER_NAME = '__targetRef_placeholder';
|
36035 |
|
36036 |
|
36037 | |
36038 |
|
36039 |
|
36040 |
|
36041 |
|
36042 |
|
36043 |
|
36044 |
|
36045 |
|
36046 |
|
36047 |
|
36048 |
|
36049 | function DataInputAssociationBehavior(eventBus, bpmnFactory) {
|
36050 |
|
36051 | CommandInterceptor.call(this, eventBus);
|
36052 |
|
36053 |
|
36054 | this.executed([
|
36055 | 'connection.create',
|
36056 | 'connection.delete',
|
36057 | 'connection.move',
|
36058 | 'connection.reconnectEnd'
|
36059 | ], ifDataInputAssociation(fixTargetRef));
|
36060 |
|
36061 | this.reverted([
|
36062 | 'connection.create',
|
36063 | 'connection.delete',
|
36064 | 'connection.move',
|
36065 | 'connection.reconnectEnd'
|
36066 | ], ifDataInputAssociation(fixTargetRef));
|
36067 |
|
36068 |
|
36069 | function usesTargetRef(element, targetRef, removedConnection) {
|
36070 |
|
36071 | var inputAssociations = element.get('dataInputAssociations');
|
36072 |
|
36073 | return find(inputAssociations, function(association) {
|
36074 | return association !== removedConnection &&
|
36075 | association.targetRef === targetRef;
|
36076 | });
|
36077 | }
|
36078 |
|
36079 | function getTargetRef(element, create) {
|
36080 |
|
36081 | var properties = element.get('properties');
|
36082 |
|
36083 | var targetRefProp = find(properties, function(p) {
|
36084 | return p.name === TARGET_REF_PLACEHOLDER_NAME;
|
36085 | });
|
36086 |
|
36087 | if (!targetRefProp && create) {
|
36088 | targetRefProp = bpmnFactory.create('bpmn:Property', {
|
36089 | name: TARGET_REF_PLACEHOLDER_NAME
|
36090 | });
|
36091 |
|
36092 | add(properties, targetRefProp);
|
36093 | }
|
36094 |
|
36095 | return targetRefProp;
|
36096 | }
|
36097 |
|
36098 | function cleanupTargetRef(element, connection) {
|
36099 |
|
36100 | var targetRefProp = getTargetRef(element);
|
36101 |
|
36102 | if (!targetRefProp) {
|
36103 | return;
|
36104 | }
|
36105 |
|
36106 | if (!usesTargetRef(element, targetRefProp, connection)) {
|
36107 | remove$2(element.get('properties'), targetRefProp);
|
36108 | }
|
36109 | }
|
36110 |
|
36111 | |
36112 |
|
36113 |
|
36114 |
|
36115 |
|
36116 |
|
36117 | function fixTargetRef(event) {
|
36118 |
|
36119 | var context = event.context,
|
36120 | connection = context.connection,
|
36121 | connectionBo = connection.businessObject,
|
36122 | target = connection.target,
|
36123 | targetBo = target && target.businessObject,
|
36124 | newTarget = context.newTarget,
|
36125 | newTargetBo = newTarget && newTarget.businessObject,
|
36126 | oldTarget = context.oldTarget || context.target,
|
36127 | oldTargetBo = oldTarget && oldTarget.businessObject;
|
36128 |
|
36129 | var dataAssociation = connection.businessObject,
|
36130 | targetRefProp;
|
36131 |
|
36132 | if (oldTargetBo && oldTargetBo !== targetBo) {
|
36133 | cleanupTargetRef(oldTargetBo, connectionBo);
|
36134 | }
|
36135 |
|
36136 | if (newTargetBo && newTargetBo !== targetBo) {
|
36137 | cleanupTargetRef(newTargetBo, connectionBo);
|
36138 | }
|
36139 |
|
36140 | if (targetBo) {
|
36141 | targetRefProp = getTargetRef(targetBo, true);
|
36142 | dataAssociation.targetRef = targetRefProp;
|
36143 | } else {
|
36144 | dataAssociation.targetRef = null;
|
36145 | }
|
36146 | }
|
36147 | }
|
36148 |
|
36149 | DataInputAssociationBehavior.$inject = [
|
36150 | 'eventBus',
|
36151 | 'bpmnFactory'
|
36152 | ];
|
36153 |
|
36154 | inherits_browser(DataInputAssociationBehavior, CommandInterceptor);
|
36155 |
|
36156 |
|
36157 | |
36158 |
|
36159 |
|
36160 |
|
36161 |
|
36162 |
|
36163 |
|
36164 | function ifDataInputAssociation(fn) {
|
36165 |
|
36166 | return function(event) {
|
36167 | var context = event.context,
|
36168 | connection = context.connection;
|
36169 |
|
36170 | if (is$1(connection, 'bpmn:DataInputAssociation')) {
|
36171 | return fn(event);
|
36172 | }
|
36173 | };
|
36174 | }
|
36175 |
|
36176 | function UpdateSemanticParentHandler(bpmnUpdater) {
|
36177 | this._bpmnUpdater = bpmnUpdater;
|
36178 | }
|
36179 |
|
36180 | UpdateSemanticParentHandler.$inject = [ 'bpmnUpdater' ];
|
36181 |
|
36182 |
|
36183 | UpdateSemanticParentHandler.prototype.execute = function(context) {
|
36184 | var dataStoreBo = context.dataStoreBo,
|
36185 | newSemanticParent = context.newSemanticParent,
|
36186 | newDiParent = context.newDiParent;
|
36187 |
|
36188 | context.oldSemanticParent = dataStoreBo.$parent;
|
36189 | context.oldDiParent = dataStoreBo.di.$parent;
|
36190 |
|
36191 |
|
36192 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, newSemanticParent);
|
36193 |
|
36194 |
|
36195 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, newDiParent);
|
36196 | };
|
36197 |
|
36198 | UpdateSemanticParentHandler.prototype.revert = function(context) {
|
36199 | var dataStoreBo = context.dataStoreBo,
|
36200 | oldSemanticParent = context.oldSemanticParent,
|
36201 | oldDiParent = context.oldDiParent;
|
36202 |
|
36203 |
|
36204 | this._bpmnUpdater.updateSemanticParent(dataStoreBo, oldSemanticParent);
|
36205 |
|
36206 |
|
36207 | this._bpmnUpdater.updateDiParent(dataStoreBo.di, oldDiParent);
|
36208 | };
|
36209 |
|
36210 | |
36211 |
|
36212 |
|
36213 | function DataStoreBehavior(
|
36214 | canvas, commandStack, elementRegistry,
|
36215 | eventBus) {
|
36216 |
|
36217 | CommandInterceptor.call(this, eventBus);
|
36218 |
|
36219 | commandStack.registerHandler('dataStore.updateContainment', UpdateSemanticParentHandler);
|
36220 |
|
36221 | function getFirstParticipant() {
|
36222 | return elementRegistry.filter(function(element) {
|
36223 | return is$1(element, 'bpmn:Participant');
|
36224 | })[0];
|
36225 | }
|
36226 |
|
36227 | function getDataStores(element) {
|
36228 | return element.children.filter(function(child) {
|
36229 | return is$1(child, 'bpmn:DataStoreReference') && !child.labelTarget;
|
36230 | });
|
36231 | }
|
36232 |
|
36233 | function updateDataStoreParent(dataStore, newDataStoreParent) {
|
36234 | var dataStoreBo = dataStore.businessObject || dataStore;
|
36235 |
|
36236 | newDataStoreParent = newDataStoreParent || getFirstParticipant();
|
36237 |
|
36238 | if (newDataStoreParent) {
|
36239 | var newDataStoreParentBo = newDataStoreParent.businessObject || newDataStoreParent;
|
36240 |
|
36241 | commandStack.execute('dataStore.updateContainment', {
|
36242 | dataStoreBo: dataStoreBo,
|
36243 | newSemanticParent: newDataStoreParentBo.processRef || newDataStoreParentBo,
|
36244 | newDiParent: newDataStoreParentBo.di
|
36245 | });
|
36246 | }
|
36247 | }
|
36248 |
|
36249 |
|
36250 |
|
36251 | this.preExecute('shape.create', function(event) {
|
36252 |
|
36253 | var context = event.context,
|
36254 | shape = context.shape;
|
36255 |
|
36256 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
36257 | shape.type !== 'label') {
|
36258 |
|
36259 | if (!context.hints) {
|
36260 | context.hints = {};
|
36261 | }
|
36262 |
|
36263 |
|
36264 | context.hints.autoResize = false;
|
36265 | }
|
36266 | });
|
36267 |
|
36268 |
|
36269 |
|
36270 | this.preExecute('elements.move', function(event) {
|
36271 | var context = event.context,
|
36272 | shapes = context.shapes;
|
36273 |
|
36274 | var dataStoreReferences = shapes.filter(function(shape) {
|
36275 | return is$1(shape, 'bpmn:DataStoreReference');
|
36276 | });
|
36277 |
|
36278 | if (dataStoreReferences.length) {
|
36279 | if (!context.hints) {
|
36280 | context.hints = {};
|
36281 | }
|
36282 |
|
36283 |
|
36284 | context.hints.autoResize = shapes.filter(function(shape) {
|
36285 | return !is$1(shape, 'bpmn:DataStoreReference');
|
36286 | });
|
36287 | }
|
36288 | });
|
36289 |
|
36290 |
|
36291 |
|
36292 | this.postExecute('shape.create', function(event) {
|
36293 | var context = event.context,
|
36294 | shape = context.shape,
|
36295 | parent = shape.parent;
|
36296 |
|
36297 |
|
36298 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
36299 | shape.type !== 'label' &&
|
36300 | is$1(parent, 'bpmn:Collaboration')) {
|
36301 |
|
36302 | updateDataStoreParent(shape);
|
36303 | }
|
36304 | });
|
36305 |
|
36306 |
|
36307 |
|
36308 | this.postExecute('shape.move', function(event) {
|
36309 | var context = event.context,
|
36310 | shape = context.shape,
|
36311 | oldParent = context.oldParent,
|
36312 | parent = shape.parent;
|
36313 |
|
36314 | if (is$1(oldParent, 'bpmn:Collaboration')) {
|
36315 |
|
36316 |
|
36317 | return;
|
36318 | }
|
36319 |
|
36320 | if (is$1(shape, 'bpmn:DataStoreReference') &&
|
36321 | shape.type !== 'label' &&
|
36322 | is$1(parent, 'bpmn:Collaboration')) {
|
36323 |
|
36324 | var participant = is$1(oldParent, 'bpmn:Participant') ?
|
36325 | oldParent :
|
36326 | getAncestor(oldParent, 'bpmn:Participant');
|
36327 |
|
36328 | updateDataStoreParent(shape, participant);
|
36329 | }
|
36330 | });
|
36331 |
|
36332 |
|
36333 |
|
36334 | this.postExecute('shape.delete', function(event) {
|
36335 | var context = event.context,
|
36336 | shape = context.shape,
|
36337 | rootElement = canvas.getRootElement();
|
36338 |
|
36339 | if (isAny(shape, [ 'bpmn:Participant', 'bpmn:SubProcess' ])
|
36340 | && is$1(rootElement, 'bpmn:Collaboration')) {
|
36341 | getDataStores(rootElement)
|
36342 | .filter(function(dataStore) {
|
36343 | return isDescendant(dataStore, shape);
|
36344 | })
|
36345 | .forEach(function(dataStore) {
|
36346 | updateDataStoreParent(dataStore);
|
36347 | });
|
36348 | }
|
36349 | });
|
36350 |
|
36351 |
|
36352 | this.postExecute('canvas.updateRoot', function(event) {
|
36353 | var context = event.context,
|
36354 | oldRoot = context.oldRoot,
|
36355 | newRoot = context.newRoot;
|
36356 |
|
36357 | var dataStores = getDataStores(oldRoot);
|
36358 |
|
36359 | dataStores.forEach(function(dataStore) {
|
36360 |
|
36361 | if (is$1(newRoot, 'bpmn:Process')) {
|
36362 | updateDataStoreParent(dataStore, newRoot);
|
36363 | }
|
36364 |
|
36365 | });
|
36366 | });
|
36367 | }
|
36368 |
|
36369 | DataStoreBehavior.$inject = [
|
36370 | 'canvas',
|
36371 | 'commandStack',
|
36372 | 'elementRegistry',
|
36373 | 'eventBus',
|
36374 | ];
|
36375 |
|
36376 | inherits_browser(DataStoreBehavior, CommandInterceptor);
|
36377 |
|
36378 |
|
36379 |
|
36380 |
|
36381 | function isDescendant(descendant, ancestor) {
|
36382 | var descendantBo = descendant.businessObject || descendant,
|
36383 | ancestorBo = ancestor.businessObject || ancestor;
|
36384 |
|
36385 | while (descendantBo.$parent) {
|
36386 | if (descendantBo.$parent === ancestorBo.processRef || ancestorBo) {
|
36387 | return true;
|
36388 | }
|
36389 |
|
36390 | descendantBo = descendantBo.$parent;
|
36391 | }
|
36392 |
|
36393 | return false;
|
36394 | }
|
36395 |
|
36396 | function getAncestor(element, type) {
|
36397 |
|
36398 | while (element.parent) {
|
36399 | if (is$1(element.parent, type)) {
|
36400 | return element.parent;
|
36401 | }
|
36402 |
|
36403 | element = element.parent;
|
36404 | }
|
36405 | }
|
36406 |
|
36407 | var LOW_PRIORITY$6 = 500;
|
36408 |
|
36409 |
|
36410 | |
36411 |
|
36412 |
|
36413 | function DeleteLaneBehavior(eventBus, modeling, spaceTool) {
|
36414 |
|
36415 | CommandInterceptor.call(this, eventBus);
|
36416 |
|
36417 |
|
36418 | function compensateLaneDelete(shape, oldParent) {
|
36419 |
|
36420 | var siblings = getChildLanes(oldParent);
|
36421 |
|
36422 | var topAffected = [];
|
36423 | var bottomAffected = [];
|
36424 |
|
36425 | eachElement(siblings, function(element) {
|
36426 |
|
36427 | if (element.y > shape.y) {
|
36428 | bottomAffected.push(element);
|
36429 | } else {
|
36430 | topAffected.push(element);
|
36431 | }
|
36432 |
|
36433 | return element.children;
|
36434 | });
|
36435 |
|
36436 | if (!siblings.length) {
|
36437 | return;
|
36438 | }
|
36439 |
|
36440 | var offset;
|
36441 |
|
36442 | if (bottomAffected.length && topAffected.length) {
|
36443 | offset = shape.height / 2;
|
36444 | } else {
|
36445 | offset = shape.height;
|
36446 | }
|
36447 |
|
36448 | var topAdjustments,
|
36449 | bottomAdjustments;
|
36450 |
|
36451 | if (topAffected.length) {
|
36452 | topAdjustments = spaceTool.calculateAdjustments(
|
36453 | topAffected, 'y', offset, shape.y - 10);
|
36454 |
|
36455 | spaceTool.makeSpace(
|
36456 | topAdjustments.movingShapes,
|
36457 | topAdjustments.resizingShapes,
|
36458 | { x: 0, y: offset }, 's');
|
36459 | }
|
36460 |
|
36461 | if (bottomAffected.length) {
|
36462 | bottomAdjustments = spaceTool.calculateAdjustments(
|
36463 | bottomAffected, 'y', -offset, shape.y + shape.height + 10);
|
36464 |
|
36465 | spaceTool.makeSpace(
|
36466 | bottomAdjustments.movingShapes,
|
36467 | bottomAdjustments.resizingShapes,
|
36468 | { x: 0, y: -offset }, 'n');
|
36469 | }
|
36470 | }
|
36471 |
|
36472 |
|
36473 | |
36474 |
|
36475 |
|
36476 | this.postExecuted('shape.delete', LOW_PRIORITY$6, function(event) {
|
36477 |
|
36478 | var context = event.context,
|
36479 | hints = context.hints,
|
36480 | shape = context.shape,
|
36481 | oldParent = context.oldParent;
|
36482 |
|
36483 |
|
36484 | if (!is$1(shape, 'bpmn:Lane')) {
|
36485 | return;
|
36486 | }
|
36487 |
|
36488 |
|
36489 | if (hints && hints.nested) {
|
36490 | return;
|
36491 | }
|
36492 |
|
36493 | compensateLaneDelete(shape, oldParent);
|
36494 | });
|
36495 | }
|
36496 |
|
36497 | DeleteLaneBehavior.$inject = [
|
36498 | 'eventBus',
|
36499 | 'modeling',
|
36500 | 'spaceTool'
|
36501 | ];
|
36502 |
|
36503 | inherits_browser(DeleteLaneBehavior, CommandInterceptor);
|
36504 |
|
36505 | function DropOnFlowBehavior(eventBus, bpmnRules, modeling) {
|
36506 |
|
36507 | CommandInterceptor.call(this, eventBus);
|
36508 |
|
36509 | |
36510 |
|
36511 |
|
36512 |
|
36513 |
|
36514 | function insertShape(shape, targetFlow, position) {
|
36515 | var waypoints = targetFlow.waypoints,
|
36516 | waypointsBefore,
|
36517 | waypointsAfter,
|
36518 | dockingPoint,
|
36519 | source,
|
36520 | target,
|
36521 | incomingConnection,
|
36522 | outgoingConnection,
|
36523 | oldOutgoing = shape.outgoing.slice(),
|
36524 | oldIncoming = shape.incoming.slice();
|
36525 |
|
36526 | var intersection = getApproxIntersection(waypoints, position);
|
36527 |
|
36528 | if (intersection) {
|
36529 | waypointsBefore = waypoints.slice(0, intersection.index);
|
36530 | waypointsAfter = waypoints.slice(intersection.index + (intersection.bendpoint ? 1 : 0));
|
36531 |
|
36532 |
|
36533 | if (!waypointsBefore.length || !waypointsAfter.length) {
|
36534 | return;
|
36535 | }
|
36536 |
|
36537 | dockingPoint = intersection.bendpoint ? waypoints[intersection.index] : position;
|
36538 |
|
36539 |
|
36540 | if (!isPointInsideBBox$2(shape, waypointsBefore[waypointsBefore.length-1])) {
|
36541 | waypointsBefore.push(copy(dockingPoint));
|
36542 | }
|
36543 |
|
36544 |
|
36545 | if (!isPointInsideBBox$2(shape, waypointsAfter[0])) {
|
36546 | waypointsAfter.unshift(copy(dockingPoint));
|
36547 | }
|
36548 | }
|
36549 |
|
36550 | source = targetFlow.source;
|
36551 | target = targetFlow.target;
|
36552 |
|
36553 | if (bpmnRules.canConnect(source, shape, targetFlow)) {
|
36554 |
|
36555 | modeling.reconnectEnd(targetFlow, shape, waypointsBefore || position);
|
36556 |
|
36557 | incomingConnection = targetFlow;
|
36558 | }
|
36559 |
|
36560 | if (bpmnRules.canConnect(shape, target, targetFlow)) {
|
36561 |
|
36562 | if (!incomingConnection) {
|
36563 |
|
36564 | modeling.reconnectStart(targetFlow, shape, waypointsAfter || position);
|
36565 |
|
36566 | outgoingConnection = targetFlow;
|
36567 | } else {
|
36568 | outgoingConnection = modeling.connect(
|
36569 | shape, target, { type: targetFlow.type, waypoints: waypointsAfter }
|
36570 | );
|
36571 | }
|
36572 | }
|
36573 |
|
36574 | var duplicateConnections = [].concat(
|
36575 |
|
36576 | incomingConnection && filter(oldIncoming, function(connection) {
|
36577 | return connection.source === incomingConnection.source;
|
36578 | }) || [],
|
36579 |
|
36580 | outgoingConnection && filter(oldOutgoing, function(connection) {
|
36581 | return connection.source === outgoingConnection.source;
|
36582 | }) || []
|
36583 | );
|
36584 |
|
36585 | if (duplicateConnections.length) {
|
36586 | modeling.removeElements(duplicateConnections);
|
36587 | }
|
36588 | }
|
36589 |
|
36590 | this.preExecute('elements.move', function(context) {
|
36591 |
|
36592 | var newParent = context.newParent,
|
36593 | shapes = context.shapes,
|
36594 | delta = context.delta,
|
36595 | shape = shapes[0];
|
36596 |
|
36597 | if (!shape || !newParent) {
|
36598 | return;
|
36599 | }
|
36600 |
|
36601 |
|
36602 |
|
36603 | if (newParent && newParent.waypoints) {
|
36604 | context.newParent = newParent = newParent.parent;
|
36605 | }
|
36606 |
|
36607 | var shapeMid = getMid$1(shape);
|
36608 | var newShapeMid = {
|
36609 | x: shapeMid.x + delta.x,
|
36610 | y: shapeMid.y + delta.y
|
36611 | };
|
36612 |
|
36613 |
|
36614 |
|
36615 | var connection = find(newParent.children, function(element) {
|
36616 | var canInsert = bpmnRules.canInsert(shapes, element);
|
36617 |
|
36618 | return canInsert && getApproxIntersection(element.waypoints, newShapeMid);
|
36619 | });
|
36620 |
|
36621 | if (connection) {
|
36622 | context.targetFlow = connection;
|
36623 | context.position = newShapeMid;
|
36624 | }
|
36625 |
|
36626 | }, true);
|
36627 |
|
36628 | this.postExecuted('elements.move', function(context) {
|
36629 |
|
36630 | var shapes = context.shapes,
|
36631 | targetFlow = context.targetFlow,
|
36632 | position = context.position;
|
36633 |
|
36634 | if (targetFlow) {
|
36635 | insertShape(shapes[0], targetFlow, position);
|
36636 | }
|
36637 |
|
36638 | }, true);
|
36639 |
|
36640 | this.preExecute('shape.create', function(context) {
|
36641 |
|
36642 | var parent = context.parent,
|
36643 | shape = context.shape;
|
36644 |
|
36645 | if (bpmnRules.canInsert(shape, parent)) {
|
36646 | context.targetFlow = parent;
|
36647 | context.parent = parent.parent;
|
36648 | }
|
36649 | }, true);
|
36650 |
|
36651 | this.postExecuted('shape.create', function(context) {
|
36652 |
|
36653 | var shape = context.shape,
|
36654 | targetFlow = context.targetFlow,
|
36655 | position = context.position;
|
36656 |
|
36657 | if (targetFlow) {
|
36658 | insertShape(shape, targetFlow, position);
|
36659 | }
|
36660 | }, true);
|
36661 | }
|
36662 |
|
36663 | inherits_browser(DropOnFlowBehavior, CommandInterceptor);
|
36664 |
|
36665 | DropOnFlowBehavior.$inject = [
|
36666 | 'eventBus',
|
36667 | 'bpmnRules',
|
36668 | 'modeling'
|
36669 | ];
|
36670 |
|
36671 |
|
36672 |
|
36673 |
|
36674 | function isPointInsideBBox$2(bbox, point) {
|
36675 | var x = point.x,
|
36676 | y = point.y;
|
36677 |
|
36678 | return x >= bbox.x &&
|
36679 | x <= bbox.x + bbox.width &&
|
36680 | y >= bbox.y &&
|
36681 | y <= bbox.y + bbox.height;
|
36682 | }
|
36683 |
|
36684 | function copy(obj) {
|
36685 | return assign({}, obj);
|
36686 | }
|
36687 |
|
36688 | function getMid$1(bounds) {
|
36689 |
|
36690 | return {
|
36691 | x: Math.round(bounds.x + bounds.width / 2),
|
36692 | y: Math.round(bounds.y + bounds.height / 2)
|
36693 | };
|
36694 | }
|
36695 |
|
36696 | |
36697 |
|
36698 |
|
36699 |
|
36700 |
|
36701 |
|
36702 |
|
36703 |
|
36704 |
|
36705 |
|
36706 | function lineIntersect(l1s, l1e, l2s, l2e) {
|
36707 |
|
36708 |
|
36709 |
|
36710 | var denominator, a, b, c, numerator;
|
36711 |
|
36712 | denominator = ((l2e.y - l2s.y) * (l1e.x - l1s.x)) - ((l2e.x - l2s.x) * (l1e.y - l1s.y));
|
36713 |
|
36714 | if (denominator == 0) {
|
36715 | return null;
|
36716 | }
|
36717 |
|
36718 | a = l1s.y - l2s.y;
|
36719 | b = l1s.x - l2s.x;
|
36720 | numerator = ((l2e.x - l2s.x) * a) - ((l2e.y - l2s.y) * b);
|
36721 |
|
36722 | c = numerator / denominator;
|
36723 |
|
36724 |
|
36725 |
|
36726 | return {
|
36727 | x: Math.round(l1s.x + (c * (l1e.x - l1s.x))),
|
36728 | y: Math.round(l1s.y + (c * (l1e.y - l1s.y)))
|
36729 | };
|
36730 | }
|
36731 |
|
36732 | |
36733 |
|
36734 |
|
36735 |
|
36736 |
|
36737 | function ImportDockingFix(eventBus) {
|
36738 |
|
36739 | function adjustDocking(startPoint, nextPoint, elementMid) {
|
36740 |
|
36741 | var elementTop = {
|
36742 | x: elementMid.x,
|
36743 | y: elementMid.y - 50
|
36744 | };
|
36745 |
|
36746 | var elementLeft = {
|
36747 | x: elementMid.x - 50,
|
36748 | y: elementMid.y
|
36749 | };
|
36750 |
|
36751 | var verticalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementTop),
|
36752 | horizontalIntersect = lineIntersect(startPoint, nextPoint, elementMid, elementLeft);
|
36753 |
|
36754 |
|
36755 | var centerIntersect;
|
36756 |
|
36757 | if (verticalIntersect && horizontalIntersect) {
|
36758 | if (getDistance(verticalIntersect, elementMid) > getDistance(horizontalIntersect, elementMid)) {
|
36759 | centerIntersect = horizontalIntersect;
|
36760 | } else {
|
36761 | centerIntersect = verticalIntersect;
|
36762 | }
|
36763 | } else {
|
36764 | centerIntersect = verticalIntersect || horizontalIntersect;
|
36765 | }
|
36766 |
|
36767 | startPoint.original = centerIntersect;
|
36768 | }
|
36769 |
|
36770 | function fixDockings(connection) {
|
36771 | var waypoints = connection.waypoints;
|
36772 |
|
36773 | adjustDocking(
|
36774 | waypoints[0],
|
36775 | waypoints[1],
|
36776 | getMid(connection.source)
|
36777 | );
|
36778 |
|
36779 | adjustDocking(
|
36780 | waypoints[waypoints.length - 1],
|
36781 | waypoints[waypoints.length - 2],
|
36782 | getMid(connection.target)
|
36783 | );
|
36784 | }
|
36785 |
|
36786 | eventBus.on('bpmnElement.added', function(e) {
|
36787 |
|
36788 | var element = e.element;
|
36789 |
|
36790 | if (element.waypoints) {
|
36791 | fixDockings(element);
|
36792 | }
|
36793 | });
|
36794 | }
|
36795 |
|
36796 | ImportDockingFix.$inject = [
|
36797 | 'eventBus'
|
36798 | ];
|
36799 |
|
36800 |
|
36801 |
|
36802 |
|
36803 | function getDistance(p1, p2) {
|
36804 | return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
36805 | }
|
36806 |
|
36807 | |
36808 |
|
36809 |
|
36810 |
|
36811 |
|
36812 |
|
36813 | function vectorLength(v) {
|
36814 | return Math.sqrt(Math.pow(v.x, 2) + Math.pow(v.y, 2));
|
36815 | }
|
36816 |
|
36817 |
|
36818 | |
36819 |
|
36820 |
|
36821 |
|
36822 |
|
36823 |
|
36824 | function getAngle(line) {
|
36825 |
|
36826 |
|
36827 | return Math.atan((line[1].y - line[0].y) / (line[1].x - line[0].x));
|
36828 | }
|
36829 |
|
36830 |
|
36831 | |
36832 |
|
36833 |
|
36834 |
|
36835 |
|
36836 |
|
36837 |
|
36838 | function rotateVector(vector, angle) {
|
36839 | return (!angle) ? vector : {
|
36840 | x: Math.cos(angle) * vector.x - Math.sin(angle) * vector.y,
|
36841 | y: Math.sin(angle) * vector.x + Math.cos(angle) * vector.y
|
36842 | };
|
36843 | }
|
36844 |
|
36845 |
|
36846 | |
36847 |
|
36848 |
|
36849 |
|
36850 |
|
36851 |
|
36852 |
|
36853 | function getDistancePointPoint(point1, point2) {
|
36854 |
|
36855 | return vectorLength({
|
36856 | x: point1.x - point2.x,
|
36857 | y: point1.y - point2.y
|
36858 | });
|
36859 | }
|
36860 |
|
36861 | var sqrt = Math.sqrt,
|
36862 | min$2 = Math.min,
|
36863 | max$3 = Math.max,
|
36864 | abs$3 = Math.abs;
|
36865 |
|
36866 | |
36867 |
|
36868 |
|
36869 |
|
36870 |
|
36871 |
|
36872 |
|
36873 | function sq(n) {
|
36874 | return Math.pow(n, 2);
|
36875 | }
|
36876 |
|
36877 | |
36878 |
|
36879 |
|
36880 |
|
36881 |
|
36882 |
|
36883 |
|
36884 |
|
36885 | function getDistance$1(p1, p2) {
|
36886 | return sqrt(sq(p1.x - p2.x) + sq(p1.y - p2.y));
|
36887 | }
|
36888 |
|
36889 | |
36890 |
|
36891 |
|
36892 |
|
36893 |
|
36894 |
|
36895 |
|
36896 |
|
36897 |
|
36898 |
|
36899 |
|
36900 |
|
36901 |
|
36902 |
|
36903 |
|
36904 |
|
36905 |
|
36906 |
|
36907 |
|
36908 |
|
36909 |
|
36910 |
|
36911 |
|
36912 |
|
36913 |
|
36914 |
|
36915 | function getAttachment(point, line) {
|
36916 |
|
36917 | var idx = 0,
|
36918 | segmentStart,
|
36919 | segmentEnd,
|
36920 | segmentStartDistance,
|
36921 | segmentEndDistance,
|
36922 | attachmentPosition,
|
36923 | minDistance,
|
36924 | intersections,
|
36925 | attachment,
|
36926 | attachmentDistance,
|
36927 | closestAttachmentDistance,
|
36928 | closestAttachment;
|
36929 |
|
36930 | for (idx = 0; idx < line.length - 1; idx++) {
|
36931 |
|
36932 | segmentStart = line[idx];
|
36933 | segmentEnd = line[idx + 1];
|
36934 |
|
36935 | if (pointsEqual(segmentStart, segmentEnd)) {
|
36936 | intersections = [ segmentStart ];
|
36937 | } else {
|
36938 | segmentStartDistance = getDistance$1(point, segmentStart);
|
36939 | segmentEndDistance = getDistance$1(point, segmentEnd);
|
36940 |
|
36941 | minDistance = min$2(segmentStartDistance, segmentEndDistance);
|
36942 |
|
36943 | intersections = getCircleSegmentIntersections(segmentStart, segmentEnd, point, minDistance);
|
36944 | }
|
36945 |
|
36946 | if (intersections.length < 1) {
|
36947 | throw new Error('expected between [1, 2] circle -> line intersections');
|
36948 | }
|
36949 |
|
36950 |
|
36951 | if (intersections.length === 1) {
|
36952 | attachment = {
|
36953 | type: 'bendpoint',
|
36954 | position: intersections[0],
|
36955 | segmentIndex: idx,
|
36956 | bendpointIndex: pointsEqual(segmentStart, intersections[0]) ? idx : idx + 1
|
36957 | };
|
36958 | }
|
36959 |
|
36960 |
|
36961 | if (intersections.length === 2) {
|
36962 |
|
36963 | attachmentPosition = mid(intersections[0], intersections[1]);
|
36964 |
|
36965 | attachment = {
|
36966 | type: 'segment',
|
36967 | position: attachmentPosition,
|
36968 | segmentIndex: idx,
|
36969 | relativeLocation: getDistance$1(segmentStart, attachmentPosition) / getDistance$1(segmentStart, segmentEnd)
|
36970 | };
|
36971 | }
|
36972 |
|
36973 | attachmentDistance = getDistance$1(attachment.position, point);
|
36974 |
|
36975 | if (!closestAttachment || closestAttachmentDistance > attachmentDistance) {
|
36976 | closestAttachment = attachment;
|
36977 | closestAttachmentDistance = attachmentDistance;
|
36978 | }
|
36979 | }
|
36980 |
|
36981 | return closestAttachment;
|
36982 | }
|
36983 |
|
36984 | |
36985 |
|
36986 |
|
36987 |
|
36988 |
|
36989 |
|
36990 |
|
36991 |
|
36992 |
|
36993 |
|
36994 | function getCircleSegmentIntersections(s1, s2, cc, cr) {
|
36995 |
|
36996 | var baX = s2.x - s1.x;
|
36997 | var baY = s2.y - s1.y;
|
36998 | var caX = cc.x - s1.x;
|
36999 | var caY = cc.y - s1.y;
|
37000 |
|
37001 | var a = baX * baX + baY * baY;
|
37002 | var bBy2 = baX * caX + baY * caY;
|
37003 | var c = caX * caX + caY * caY - cr * cr;
|
37004 |
|
37005 | var pBy2 = bBy2 / a;
|
37006 | var q = c / a;
|
37007 |
|
37008 | var disc = pBy2 * pBy2 - q;
|
37009 |
|
37010 |
|
37011 |
|
37012 |
|
37013 | if (disc < 0 && disc > -0.000001) {
|
37014 | disc = 0;
|
37015 | }
|
37016 |
|
37017 | if (disc < 0) {
|
37018 | return [];
|
37019 | }
|
37020 |
|
37021 |
|
37022 | var tmpSqrt = sqrt(disc);
|
37023 | var abScalingFactor1 = -pBy2 + tmpSqrt;
|
37024 | var abScalingFactor2 = -pBy2 - tmpSqrt;
|
37025 |
|
37026 | var i1 = {
|
37027 | x: s1.x - baX * abScalingFactor1,
|
37028 | y: s1.y - baY * abScalingFactor1
|
37029 | };
|
37030 |
|
37031 | if (disc === 0) {
|
37032 | return [ i1 ];
|
37033 | }
|
37034 |
|
37035 | var i2 = {
|
37036 | x: s1.x - baX * abScalingFactor2,
|
37037 | y: s1.y - baY * abScalingFactor2
|
37038 | };
|
37039 |
|
37040 |
|
37041 | return [ i1, i2 ].filter(function(p) {
|
37042 | return isPointInSegment(p, s1, s2);
|
37043 | });
|
37044 | }
|
37045 |
|
37046 |
|
37047 | function isPointInSegment(p, segmentStart, segmentEnd) {
|
37048 | return (
|
37049 | fenced(p.x, segmentStart.x, segmentEnd.x) &&
|
37050 | fenced(p.y, segmentStart.y, segmentEnd.y)
|
37051 | );
|
37052 | }
|
37053 |
|
37054 | function fenced(n, rangeStart, rangeEnd) {
|
37055 |
|
37056 |
|
37057 |
|
37058 |
|
37059 | return (
|
37060 | n >= min$2(rangeStart, rangeEnd) - EQUAL_THRESHOLD &&
|
37061 | n <= max$3(rangeStart, rangeEnd) + EQUAL_THRESHOLD
|
37062 | );
|
37063 | }
|
37064 |
|
37065 | |
37066 |
|
37067 |
|
37068 |
|
37069 |
|
37070 |
|
37071 |
|
37072 |
|
37073 | function mid(p1, p2) {
|
37074 |
|
37075 | return {
|
37076 | x: (p1.x + p2.x) / 2,
|
37077 | y: (p1.y + p2.y) / 2
|
37078 | };
|
37079 | }
|
37080 |
|
37081 | var EQUAL_THRESHOLD = 0.1;
|
37082 |
|
37083 | function pointsEqual(p1, p2) {
|
37084 |
|
37085 | return (
|
37086 | abs$3(p1.x - p2.x) <= EQUAL_THRESHOLD &&
|
37087 | abs$3(p1.y - p2.y) <= EQUAL_THRESHOLD
|
37088 | );
|
37089 | }
|
37090 |
|
37091 | function findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints) {
|
37092 |
|
37093 | var index = attachment.segmentIndex;
|
37094 |
|
37095 | var offset = newWaypoints.length - oldWaypoints.length;
|
37096 |
|
37097 |
|
37098 | if (hints.segmentMove) {
|
37099 |
|
37100 | var oldSegmentStartIndex = hints.segmentMove.segmentStartIndex,
|
37101 | newSegmentStartIndex = hints.segmentMove.newSegmentStartIndex;
|
37102 |
|
37103 |
|
37104 | if (index === oldSegmentStartIndex) {
|
37105 | return newSegmentStartIndex;
|
37106 | }
|
37107 |
|
37108 |
|
37109 | if (index >= newSegmentStartIndex) {
|
37110 | return (index+offset < newSegmentStartIndex) ? newSegmentStartIndex : index+offset;
|
37111 | }
|
37112 |
|
37113 |
|
37114 | return index;
|
37115 | }
|
37116 |
|
37117 |
|
37118 | if (hints.bendpointMove) {
|
37119 |
|
37120 | var insert = hints.bendpointMove.insert,
|
37121 | bendpointIndex = hints.bendpointMove.bendpointIndex,
|
37122 | newIndex;
|
37123 |
|
37124 |
|
37125 | if (offset === 0) {
|
37126 | return index;
|
37127 | }
|
37128 |
|
37129 |
|
37130 | if (index >= bendpointIndex) {
|
37131 | newIndex = insert ? index + 1 : index - 1;
|
37132 | }
|
37133 |
|
37134 |
|
37135 | if (index < bendpointIndex) {
|
37136 |
|
37137 | newIndex = index;
|
37138 |
|
37139 |
|
37140 | if (insert && attachment.type !== 'bendpoint' && bendpointIndex-1 === index) {
|
37141 |
|
37142 | var rel = relativePositionMidWaypoint(newWaypoints, bendpointIndex);
|
37143 |
|
37144 | if (rel < attachment.relativeLocation) {
|
37145 | newIndex++;
|
37146 | }
|
37147 | }
|
37148 | }
|
37149 |
|
37150 | return newIndex;
|
37151 | }
|
37152 |
|
37153 |
|
37154 | if (offset === 0) {
|
37155 | return index;
|
37156 | }
|
37157 |
|
37158 | if (hints.connectionStart) {
|
37159 | return (index === 0) ? 0 : null;
|
37160 | }
|
37161 |
|
37162 | if (hints.connectionEnd) {
|
37163 | return (index === oldWaypoints.length - 2) ? newWaypoints.length - 2 : null;
|
37164 | }
|
37165 |
|
37166 |
|
37167 | return null;
|
37168 | }
|
37169 |
|
37170 |
|
37171 | |
37172 |
|
37173 |
|
37174 |
|
37175 |
|
37176 |
|
37177 |
|
37178 |
|
37179 |
|
37180 |
|
37181 |
|
37182 | function getLabelAdjustment(label, newWaypoints, oldWaypoints, hints) {
|
37183 |
|
37184 | var x = 0,
|
37185 | y = 0;
|
37186 |
|
37187 | var labelPosition = getLabelMid(label);
|
37188 |
|
37189 |
|
37190 | var attachment = getAttachment(labelPosition, oldWaypoints),
|
37191 | oldLabelLineIndex = attachment.segmentIndex,
|
37192 | newLabelLineIndex = findNewLabelLineStartIndex(oldWaypoints, newWaypoints, attachment, hints);
|
37193 |
|
37194 | if (newLabelLineIndex === null) {
|
37195 | return { x: x, y: y };
|
37196 | }
|
37197 |
|
37198 |
|
37199 |
|
37200 | if (newLabelLineIndex < 0 ||
|
37201 | newLabelLineIndex > newWaypoints.length - 2) {
|
37202 | return { x: x, y: y };
|
37203 | }
|
37204 |
|
37205 | var oldLabelLine = getLine(oldWaypoints, oldLabelLineIndex),
|
37206 | newLabelLine = getLine(newWaypoints, newLabelLineIndex),
|
37207 | oldFoot = attachment.position;
|
37208 |
|
37209 | var relativeFootPosition = getRelativeFootPosition(oldLabelLine, oldFoot),
|
37210 | angleDelta = getAngleDelta(oldLabelLine, newLabelLine);
|
37211 |
|
37212 |
|
37213 | if (attachment.type === 'bendpoint') {
|
37214 |
|
37215 | var offset = newWaypoints.length - oldWaypoints.length,
|
37216 | oldBendpointIndex = attachment.bendpointIndex,
|
37217 | oldBendpoint = oldWaypoints[oldBendpointIndex];
|
37218 |
|
37219 |
|
37220 | if (newWaypoints.indexOf(oldBendpoint) !== -1) {
|
37221 | return { x: x, y: y };
|
37222 | }
|
37223 |
|
37224 |
|
37225 | if (offset === 0) {
|
37226 | var newBendpoint = newWaypoints[oldBendpointIndex];
|
37227 |
|
37228 | return {
|
37229 | x: newBendpoint.x - attachment.position.x,
|
37230 | y: newBendpoint.y - attachment.position.y
|
37231 | };
|
37232 | }
|
37233 |
|
37234 |
|
37235 | if (offset < 0 && oldBendpointIndex !== 0 && oldBendpointIndex < oldWaypoints.length - 1) {
|
37236 | relativeFootPosition = relativePositionMidWaypoint(oldWaypoints, oldBendpointIndex);
|
37237 | }
|
37238 | }
|
37239 |
|
37240 | var newFoot = {
|
37241 | x: (newLabelLine[1].x - newLabelLine[0].x) * relativeFootPosition + newLabelLine[0].x,
|
37242 | y: (newLabelLine[1].y - newLabelLine[0].y) * relativeFootPosition + newLabelLine[0].y
|
37243 | };
|
37244 |
|
37245 |
|
37246 | var newLabelVector = rotateVector({
|
37247 | x: labelPosition.x - oldFoot.x,
|
37248 | y: labelPosition.y - oldFoot.y
|
37249 | }, angleDelta);
|
37250 |
|
37251 |
|
37252 | x = newFoot.x + newLabelVector.x - labelPosition.x;
|
37253 | y = newFoot.y + newLabelVector.y - labelPosition.y;
|
37254 |
|
37255 | return roundPoint({
|
37256 | x: x,
|
37257 | y: y
|
37258 | });
|
37259 | }
|
37260 |
|
37261 |
|
37262 |
|
37263 |
|
37264 | function relativePositionMidWaypoint(waypoints, idx) {
|
37265 |
|
37266 | var distanceSegment1 = getDistancePointPoint(waypoints[idx-1], waypoints[idx]),
|
37267 | distanceSegment2 = getDistancePointPoint(waypoints[idx], waypoints[idx+1]);
|
37268 |
|
37269 | var relativePosition = distanceSegment1 / (distanceSegment1 + distanceSegment2);
|
37270 |
|
37271 | return relativePosition;
|
37272 | }
|
37273 |
|
37274 | function getLabelMid(label) {
|
37275 | return {
|
37276 | x: label.x + label.width / 2,
|
37277 | y: label.y + label.height / 2
|
37278 | };
|
37279 | }
|
37280 |
|
37281 | function getAngleDelta(l1, l2) {
|
37282 | var a1 = getAngle(l1),
|
37283 | a2 = getAngle(l2);
|
37284 | return a2 - a1;
|
37285 | }
|
37286 |
|
37287 | function getLine(waypoints, idx) {
|
37288 | return [ waypoints[idx], waypoints[idx+1] ];
|
37289 | }
|
37290 |
|
37291 | function getRelativeFootPosition(line, foot) {
|
37292 |
|
37293 | var length = getDistancePointPoint(line[0], line[1]),
|
37294 | lengthToFoot = getDistancePointPoint(line[0], foot);
|
37295 |
|
37296 | return length === 0 ? 0 : lengthToFoot / length;
|
37297 | }
|
37298 |
|
37299 | var DEFAULT_LABEL_DIMENSIONS = {
|
37300 | width: 90,
|
37301 | height: 20
|
37302 | };
|
37303 |
|
37304 | var NAME_PROPERTY = 'name';
|
37305 | var TEXT_PROPERTY = 'text';
|
37306 |
|
37307 | |
37308 |
|
37309 |
|
37310 |
|
37311 |
|
37312 |
|
37313 |
|
37314 |
|
37315 |
|
37316 |
|
37317 | function LabelBehavior(
|
37318 | eventBus, modeling, bpmnFactory,
|
37319 | textRenderer) {
|
37320 |
|
37321 | CommandInterceptor.call(this, eventBus);
|
37322 |
|
37323 |
|
37324 | this.postExecute('element.updateProperties', function(e) {
|
37325 | var context = e.context,
|
37326 | element = context.element,
|
37327 | properties = context.properties;
|
37328 |
|
37329 | if (NAME_PROPERTY in properties) {
|
37330 | modeling.updateLabel(element, properties[NAME_PROPERTY]);
|
37331 | }
|
37332 |
|
37333 | if (TEXT_PROPERTY in properties
|
37334 | && is$1(element, 'bpmn:TextAnnotation')) {
|
37335 |
|
37336 | var newBounds = textRenderer.getTextAnnotationBounds(
|
37337 | {
|
37338 | x: element.x,
|
37339 | y: element.y,
|
37340 | width: element.width,
|
37341 | height: element.height
|
37342 | },
|
37343 | properties[TEXT_PROPERTY] || ''
|
37344 | );
|
37345 |
|
37346 | modeling.updateLabel(element, properties.text, newBounds);
|
37347 | }
|
37348 | });
|
37349 |
|
37350 |
|
37351 | this.postExecute([ 'shape.create', 'connection.create' ], function(e) {
|
37352 | var context = e.context;
|
37353 |
|
37354 | var element = context.shape || context.connection,
|
37355 | businessObject = element.businessObject;
|
37356 |
|
37357 | if (!isLabelExternal(element)) {
|
37358 | return;
|
37359 | }
|
37360 |
|
37361 |
|
37362 | if (!businessObject.name) {
|
37363 | return;
|
37364 | }
|
37365 |
|
37366 | var labelCenter = getExternalLabelMid(element);
|
37367 |
|
37368 |
|
37369 | var labelDimensions = textRenderer.getExternalLabelBounds(
|
37370 | DEFAULT_LABEL_DIMENSIONS,
|
37371 | businessObject.name || ''
|
37372 | );
|
37373 |
|
37374 | modeling.createLabel(element, labelCenter, {
|
37375 | id: businessObject.id + '_label',
|
37376 | businessObject: businessObject,
|
37377 | width: labelDimensions.width,
|
37378 | height: labelDimensions.height
|
37379 | });
|
37380 | });
|
37381 |
|
37382 |
|
37383 | this.postExecute('shape.delete', function(event) {
|
37384 | var context = event.context,
|
37385 | labelTarget = context.labelTarget,
|
37386 | hints = context.hints || {};
|
37387 |
|
37388 |
|
37389 | if (labelTarget && hints.unsetLabel !== false) {
|
37390 | modeling.updateLabel(labelTarget, null, null, { removeShape: false });
|
37391 | }
|
37392 | });
|
37393 |
|
37394 |
|
37395 | this.postExecute([ 'label.create' ], function(event) {
|
37396 |
|
37397 | var context = event.context,
|
37398 | element = context.shape,
|
37399 | businessObject,
|
37400 | di;
|
37401 |
|
37402 |
|
37403 | if (!element.labelTarget) {
|
37404 | return;
|
37405 | }
|
37406 |
|
37407 |
|
37408 | if (!is$1(element.labelTarget || element, 'bpmn:BaseElement')) {
|
37409 | return;
|
37410 | }
|
37411 |
|
37412 | businessObject = element.businessObject,
|
37413 | di = businessObject.di;
|
37414 |
|
37415 |
|
37416 | if (!di.label) {
|
37417 | di.label = bpmnFactory.create('bpmndi:BPMNLabel', {
|
37418 | bounds: bpmnFactory.create('dc:Bounds')
|
37419 | });
|
37420 | }
|
37421 |
|
37422 | assign(di.label.bounds, {
|
37423 | x: element.x,
|
37424 | y: element.y,
|
37425 | width: element.width,
|
37426 | height: element.height
|
37427 | });
|
37428 | });
|
37429 |
|
37430 | function getVisibleLabelAdjustment(event) {
|
37431 |
|
37432 | var command = event.command,
|
37433 | context = event.context,
|
37434 | connection = context.connection,
|
37435 | label = connection.label,
|
37436 | hints = assign({}, context.hints),
|
37437 | newWaypoints = context.newWaypoints || connection.waypoints,
|
37438 | oldWaypoints = context.oldWaypoints;
|
37439 |
|
37440 |
|
37441 | if (typeof hints.startChanged === 'undefined') {
|
37442 | hints.startChanged = (command === 'connection.reconnectStart');
|
37443 | }
|
37444 |
|
37445 | if (typeof hints.endChanged === 'undefined') {
|
37446 | hints.endChanged = (command === 'connection.reconnectEnd');
|
37447 | }
|
37448 |
|
37449 | return getLabelAdjustment(label, newWaypoints, oldWaypoints, hints);
|
37450 | }
|
37451 |
|
37452 | this.postExecute([
|
37453 | 'connection.layout',
|
37454 | 'connection.reconnectEnd',
|
37455 | 'connection.reconnectStart',
|
37456 | 'connection.updateWaypoints'
|
37457 | ], function(event) {
|
37458 |
|
37459 | var label = event.context.connection.label,
|
37460 | labelAdjustment;
|
37461 |
|
37462 | if (!label) {
|
37463 | return;
|
37464 | }
|
37465 |
|
37466 | labelAdjustment = getVisibleLabelAdjustment(event);
|
37467 |
|
37468 | modeling.moveShape(label, labelAdjustment);
|
37469 | });
|
37470 |
|
37471 |
|
37472 |
|
37473 | this.postExecute([ 'shape.replace' ], function(event) {
|
37474 | var context = event.context,
|
37475 | newShape = context.newShape,
|
37476 | oldShape = context.oldShape;
|
37477 |
|
37478 | var businessObject = getBusinessObject(newShape);
|
37479 |
|
37480 | if (businessObject
|
37481 | && isLabelExternal(businessObject)
|
37482 | && oldShape.label
|
37483 | && newShape.label) {
|
37484 | newShape.label.x = oldShape.label.x;
|
37485 | newShape.label.y = oldShape.label.y;
|
37486 | }
|
37487 | });
|
37488 |
|
37489 | }
|
37490 |
|
37491 | inherits_browser(LabelBehavior, CommandInterceptor);
|
37492 |
|
37493 | LabelBehavior.$inject = [
|
37494 | 'eventBus',
|
37495 | 'modeling',
|
37496 | 'bpmnFactory',
|
37497 | 'textRenderer'
|
37498 | ];
|
37499 |
|
37500 | var COLLAB_ERR_MSG = 'flow elements must be children of pools/participants',
|
37501 | PROCESS_ERR_MSG = 'participants cannot be pasted onto a non-empty process diagram';
|
37502 |
|
37503 |
|
37504 | function ModelingFeedback(eventBus, tooltips, translate) {
|
37505 |
|
37506 | function showError(position, message, timeout) {
|
37507 | tooltips.add({
|
37508 | position: {
|
37509 | x: position.x + 5,
|
37510 | y: position.y + 5
|
37511 | },
|
37512 | type: 'error',
|
37513 | timeout: timeout || 2000,
|
37514 | html: '<div>' + message + '</div>'
|
37515 | });
|
37516 | }
|
37517 |
|
37518 | eventBus.on([ 'shape.move.rejected', 'create.rejected' ], function(event) {
|
37519 | var context = event.context,
|
37520 | shape = context.shape,
|
37521 | target = context.target;
|
37522 |
|
37523 | if (is$1(target, 'bpmn:Collaboration') && is$1(shape, 'bpmn:FlowNode')) {
|
37524 | showError(event, translate(COLLAB_ERR_MSG));
|
37525 | }
|
37526 | });
|
37527 |
|
37528 | eventBus.on([ 'elements.paste.rejected' ], function(event) {
|
37529 | var context = event.context,
|
37530 | position = context.position,
|
37531 | target = context.target;
|
37532 |
|
37533 | if (is$1(target, 'bpmn:Collaboration')) {
|
37534 | showError(position, translate(COLLAB_ERR_MSG));
|
37535 | }
|
37536 |
|
37537 | if (is$1(target, 'bpmn:Process')) {
|
37538 | showError(position, translate(PROCESS_ERR_MSG), 3000);
|
37539 | }
|
37540 | });
|
37541 | }
|
37542 |
|
37543 | ModelingFeedback.$inject = [
|
37544 | 'eventBus',
|
37545 | 'tooltips',
|
37546 | 'translate'
|
37547 | ];
|
37548 |
|
37549 | function ReplaceConnectionBehavior(eventBus, modeling, bpmnRules) {
|
37550 |
|
37551 | CommandInterceptor.call(this, eventBus);
|
37552 |
|
37553 | function fixConnection(connection) {
|
37554 |
|
37555 | var source = connection.source,
|
37556 | target = connection.target,
|
37557 | parent = connection.parent;
|
37558 |
|
37559 |
|
37560 |
|
37561 |
|
37562 | if (!parent) {
|
37563 | return;
|
37564 | }
|
37565 |
|
37566 | var replacementType,
|
37567 | remove;
|
37568 |
|
37569 | |
37570 |
|
37571 |
|
37572 |
|
37573 |
|
37574 |
|
37575 |
|
37576 |
|
37577 | if (is$1(connection, 'bpmn:SequenceFlow')) {
|
37578 | if (!bpmnRules.canConnectSequenceFlow(source, target)) {
|
37579 | remove = true;
|
37580 | }
|
37581 |
|
37582 | if (bpmnRules.canConnectMessageFlow(source, target)) {
|
37583 | replacementType = 'bpmn:MessageFlow';
|
37584 | }
|
37585 | }
|
37586 |
|
37587 |
|
37588 |
|
37589 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
37590 |
|
37591 | if (!bpmnRules.canConnectMessageFlow(source, target)) {
|
37592 | remove = true;
|
37593 | }
|
37594 |
|
37595 | if (bpmnRules.canConnectSequenceFlow(source, target)) {
|
37596 | replacementType = 'bpmn:SequenceFlow';
|
37597 | }
|
37598 | }
|
37599 |
|
37600 | if (is$1(connection, 'bpmn:Association') && !bpmnRules.canConnectAssociation(source, target)) {
|
37601 | remove = true;
|
37602 | }
|
37603 |
|
37604 |
|
37605 |
|
37606 |
|
37607 | if (remove) {
|
37608 | modeling.removeConnection(connection);
|
37609 | }
|
37610 |
|
37611 |
|
37612 |
|
37613 | if (replacementType) {
|
37614 | modeling.connect(source, target, {
|
37615 | type: replacementType,
|
37616 | waypoints: connection.waypoints.slice()
|
37617 | });
|
37618 | }
|
37619 | }
|
37620 |
|
37621 | this.postExecuted('elements.move', function(context) {
|
37622 |
|
37623 | var closure = context.closure,
|
37624 | allConnections = closure.allConnections;
|
37625 |
|
37626 | forEach(allConnections, fixConnection);
|
37627 | }, true);
|
37628 |
|
37629 | this.postExecuted([
|
37630 | 'connection.reconnectStart',
|
37631 | 'connection.reconnectEnd'
|
37632 | ], function(event) {
|
37633 |
|
37634 | var connection = event.context.connection;
|
37635 |
|
37636 | fixConnection(connection);
|
37637 | });
|
37638 |
|
37639 | this.postExecuted('element.updateProperties', function(event) {
|
37640 | var context = event.context,
|
37641 | properties = context.properties,
|
37642 | element = context.element,
|
37643 | businessObject = element.businessObject,
|
37644 | connection;
|
37645 |
|
37646 |
|
37647 | if (properties.default) {
|
37648 | connection = find(
|
37649 | element.outgoing,
|
37650 | matchPattern({ id: element.businessObject.default.id })
|
37651 | );
|
37652 |
|
37653 | if (connection) {
|
37654 | modeling.updateProperties(connection, { conditionExpression: undefined });
|
37655 | }
|
37656 | }
|
37657 |
|
37658 |
|
37659 | if (properties.conditionExpression && businessObject.sourceRef.default === businessObject) {
|
37660 | modeling.updateProperties(element.source, { default: undefined });
|
37661 | }
|
37662 | });
|
37663 | }
|
37664 |
|
37665 | inherits_browser(ReplaceConnectionBehavior, CommandInterceptor);
|
37666 |
|
37667 | ReplaceConnectionBehavior.$inject = [
|
37668 | 'eventBus',
|
37669 | 'modeling',
|
37670 | 'bpmnRules'
|
37671 | ];
|
37672 |
|
37673 | |
37674 |
|
37675 |
|
37676 | function RemoveParticipantBehavior(eventBus, modeling) {
|
37677 |
|
37678 | CommandInterceptor.call(this, eventBus);
|
37679 |
|
37680 |
|
37681 | |
37682 |
|
37683 |
|
37684 |
|
37685 |
|
37686 | this.preExecute('shape.delete', function(context) {
|
37687 |
|
37688 | var shape = context.shape,
|
37689 | parent = shape.parent;
|
37690 |
|
37691 |
|
37692 |
|
37693 | if (is$1(shape, 'bpmn:Participant')) {
|
37694 | context.collaborationRoot = parent;
|
37695 | }
|
37696 | }, true);
|
37697 |
|
37698 | this.postExecute('shape.delete', function(context) {
|
37699 |
|
37700 | var collaborationRoot = context.collaborationRoot;
|
37701 |
|
37702 | if (collaborationRoot && !collaborationRoot.businessObject.participants.length) {
|
37703 |
|
37704 | modeling.makeProcess();
|
37705 | }
|
37706 | }, true);
|
37707 |
|
37708 | }
|
37709 |
|
37710 | RemoveParticipantBehavior.$inject = [ 'eventBus', 'modeling' ];
|
37711 |
|
37712 | inherits_browser(RemoveParticipantBehavior, CommandInterceptor);
|
37713 |
|
37714 | |
37715 |
|
37716 |
|
37717 |
|
37718 | function ReplaceElementBehaviour(
|
37719 | eventBus, bpmnReplace, bpmnRules,
|
37720 | elementRegistry, selection, modeling) {
|
37721 |
|
37722 | CommandInterceptor.call(this, eventBus);
|
37723 |
|
37724 | this._bpmnReplace = bpmnReplace;
|
37725 | this._elementRegistry = elementRegistry;
|
37726 | this._selection = selection;
|
37727 | this._modeling = modeling;
|
37728 |
|
37729 | this.postExecuted([ 'elements.move' ], 500, function(event) {
|
37730 |
|
37731 | var context = event.context,
|
37732 | target = context.newParent,
|
37733 | newHost = context.newHost,
|
37734 | elements = [];
|
37735 |
|
37736 | forEach(context.closure.topLevel, function(topLevelElements) {
|
37737 | if (isEventSubProcess(topLevelElements)) {
|
37738 | elements = elements.concat(topLevelElements.children);
|
37739 | } else {
|
37740 | elements = elements.concat(topLevelElements);
|
37741 | }
|
37742 | });
|
37743 |
|
37744 |
|
37745 | if (elements.length === 1 && newHost) {
|
37746 | target = newHost;
|
37747 | }
|
37748 |
|
37749 | var canReplace = bpmnRules.canReplace(elements, target);
|
37750 |
|
37751 | if (canReplace) {
|
37752 | this.replaceElements(elements, canReplace.replacements, newHost);
|
37753 | }
|
37754 | }, this);
|
37755 |
|
37756 |
|
37757 | this.postExecute([ 'shape.replace' ], 1500, function(e) {
|
37758 |
|
37759 | var context = e.context,
|
37760 | oldShape = context.oldShape,
|
37761 | newShape = context.newShape,
|
37762 | attachers = oldShape.attachers,
|
37763 | canReplace;
|
37764 |
|
37765 | if (attachers && attachers.length) {
|
37766 | canReplace = bpmnRules.canReplace(attachers, newShape);
|
37767 |
|
37768 | this.replaceElements(attachers, canReplace.replacements);
|
37769 | }
|
37770 |
|
37771 | }, this);
|
37772 |
|
37773 | this.postExecuted([ 'shape.replace' ], 1500, function(e) {
|
37774 | var context = e.context,
|
37775 | oldShape = context.oldShape,
|
37776 | newShape = context.newShape;
|
37777 |
|
37778 | modeling.unclaimId(oldShape.businessObject.id, oldShape.businessObject);
|
37779 | modeling.updateProperties(newShape, { id: oldShape.id });
|
37780 | });
|
37781 | }
|
37782 |
|
37783 | inherits_browser(ReplaceElementBehaviour, CommandInterceptor);
|
37784 |
|
37785 |
|
37786 | ReplaceElementBehaviour.prototype.replaceElements = function(elements, newElements, newHost) {
|
37787 | var elementRegistry = this._elementRegistry,
|
37788 | bpmnReplace = this._bpmnReplace,
|
37789 | selection = this._selection,
|
37790 | modeling = this._modeling;
|
37791 |
|
37792 | forEach(newElements, function(replacement) {
|
37793 |
|
37794 | var newElement = {
|
37795 | type: replacement.newElementType
|
37796 | };
|
37797 |
|
37798 | var oldElement = elementRegistry.get(replacement.oldElementId);
|
37799 |
|
37800 | if (newHost && is$1(oldElement, 'bpmn:BoundaryEvent')) {
|
37801 | modeling.updateAttachment(oldElement, null);
|
37802 | }
|
37803 |
|
37804 | var idx = elements.indexOf(oldElement);
|
37805 |
|
37806 | elements[idx] = bpmnReplace.replaceElement(oldElement, newElement, { select: false });
|
37807 |
|
37808 | if (newHost && is$1(elements[idx], 'bpmn:BoundaryEvent')) {
|
37809 | modeling.updateAttachment(elements[idx], newHost);
|
37810 | }
|
37811 | });
|
37812 |
|
37813 | if (newElements) {
|
37814 | selection.select(elements);
|
37815 | }
|
37816 | };
|
37817 |
|
37818 | ReplaceElementBehaviour.$inject = [
|
37819 | 'eventBus',
|
37820 | 'bpmnReplace',
|
37821 | 'bpmnRules',
|
37822 | 'elementRegistry',
|
37823 | 'selection',
|
37824 | 'modeling'
|
37825 | ];
|
37826 |
|
37827 | var SLIGHTLY_HIGHER_PRIORITY = 1001;
|
37828 |
|
37829 |
|
37830 | |
37831 |
|
37832 |
|
37833 |
|
37834 |
|
37835 | function ResizeLaneBehavior(eventBus, modeling) {
|
37836 |
|
37837 | eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
|
37838 | var context = event.context,
|
37839 | shape = context.shape;
|
37840 |
|
37841 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
37842 |
|
37843 |
|
37844 |
|
37845 | context.balanced = !hasPrimaryModifier(event);
|
37846 | }
|
37847 | });
|
37848 |
|
37849 | |
37850 |
|
37851 |
|
37852 | eventBus.on('resize.end', SLIGHTLY_HIGHER_PRIORITY, function(event) {
|
37853 | var context = event.context,
|
37854 | shape = context.shape,
|
37855 | canExecute = context.canExecute,
|
37856 | newBounds = context.newBounds;
|
37857 |
|
37858 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
37859 |
|
37860 | if (canExecute) {
|
37861 |
|
37862 |
|
37863 | newBounds = roundBounds(newBounds);
|
37864 |
|
37865 |
|
37866 | modeling.resizeLane(shape, newBounds, context.balanced);
|
37867 | }
|
37868 |
|
37869 |
|
37870 | return false;
|
37871 | }
|
37872 | });
|
37873 | }
|
37874 |
|
37875 | ResizeLaneBehavior.$inject = [
|
37876 | 'eventBus',
|
37877 | 'modeling'
|
37878 | ];
|
37879 |
|
37880 | function RemoveElementBehavior(eventBus, bpmnRules, modeling) {
|
37881 |
|
37882 | CommandInterceptor.call(this, eventBus);
|
37883 |
|
37884 | |
37885 |
|
37886 |
|
37887 |
|
37888 |
|
37889 | this.preExecute('shape.delete', function(e) {
|
37890 |
|
37891 | var shape = e.context.shape;
|
37892 |
|
37893 |
|
37894 | if (shape.incoming.length !== 1 || shape.outgoing.length !== 1) {
|
37895 | return;
|
37896 | }
|
37897 |
|
37898 | var inConnection = shape.incoming[0],
|
37899 | outConnection = shape.outgoing[0];
|
37900 |
|
37901 |
|
37902 | if (!is$1(inConnection, 'bpmn:SequenceFlow') || !is$1(outConnection, 'bpmn:SequenceFlow')) {
|
37903 | return;
|
37904 | }
|
37905 |
|
37906 | if (bpmnRules.canConnect(inConnection.source, outConnection.target, inConnection)) {
|
37907 |
|
37908 |
|
37909 | var newWaypoints = getNewWaypoints(inConnection.waypoints, outConnection.waypoints);
|
37910 |
|
37911 | modeling.reconnectEnd(inConnection, outConnection.target, newWaypoints);
|
37912 | }
|
37913 | });
|
37914 |
|
37915 | }
|
37916 |
|
37917 | inherits_browser(RemoveElementBehavior, CommandInterceptor);
|
37918 |
|
37919 | RemoveElementBehavior.$inject = [
|
37920 | 'eventBus',
|
37921 | 'bpmnRules',
|
37922 | 'modeling'
|
37923 | ];
|
37924 |
|
37925 |
|
37926 |
|
37927 |
|
37928 | function getDocking$1(point) {
|
37929 | return point.original || point;
|
37930 | }
|
37931 |
|
37932 |
|
37933 | function getNewWaypoints(inWaypoints, outWaypoints) {
|
37934 |
|
37935 | var intersection = lineIntersect(
|
37936 | getDocking$1(inWaypoints[inWaypoints.length - 2]),
|
37937 | getDocking$1(inWaypoints[inWaypoints.length - 1]),
|
37938 | getDocking$1(outWaypoints[1]),
|
37939 | getDocking$1(outWaypoints[0]));
|
37940 |
|
37941 | if (intersection) {
|
37942 | return [].concat(
|
37943 | inWaypoints.slice(0, inWaypoints.length - 1),
|
37944 | [ intersection ],
|
37945 | outWaypoints.slice(1));
|
37946 | } else {
|
37947 | return [
|
37948 | getDocking$1(inWaypoints[0]),
|
37949 | getDocking$1(outWaypoints[outWaypoints.length - 1])
|
37950 | ];
|
37951 | }
|
37952 | }
|
37953 |
|
37954 | var LOW_PRIORITY$7 = 500;
|
37955 |
|
37956 |
|
37957 | function ToggleElementCollapseBehaviour(
|
37958 | eventBus, elementFactory, modeling,
|
37959 | resize) {
|
37960 |
|
37961 | CommandInterceptor.call(this, eventBus);
|
37962 |
|
37963 |
|
37964 | function hideEmptyLables(children) {
|
37965 | if (children.length) {
|
37966 | children.forEach(function(child) {
|
37967 | if (child.type === 'label' && !child.businessObject.name) {
|
37968 | child.hidden = true;
|
37969 | }
|
37970 | });
|
37971 | }
|
37972 | }
|
37973 |
|
37974 | function expandedBounds(shape, defaultSize) {
|
37975 | var children = shape.children,
|
37976 | newBounds = defaultSize,
|
37977 | visibleElements,
|
37978 | visibleBBox;
|
37979 |
|
37980 | visibleElements = filterVisible(children).concat([ shape ]);
|
37981 |
|
37982 | visibleBBox = computeChildrenBBox(visibleElements);
|
37983 |
|
37984 | if (visibleBBox) {
|
37985 |
|
37986 | newBounds.width = Math.max(visibleBBox.width, newBounds.width);
|
37987 | newBounds.height = Math.max(visibleBBox.height, newBounds.height);
|
37988 |
|
37989 | newBounds.x = visibleBBox.x + (visibleBBox.width - newBounds.width) / 2;
|
37990 | newBounds.y = visibleBBox.y + (visibleBBox.height - newBounds.height) / 2;
|
37991 | } else {
|
37992 |
|
37993 | newBounds.x = shape.x + (shape.width - newBounds.width) / 2;
|
37994 | newBounds.y = shape.y + (shape.height - newBounds.height) / 2;
|
37995 | }
|
37996 |
|
37997 | return newBounds;
|
37998 | }
|
37999 |
|
38000 | function collapsedBounds(shape, defaultSize) {
|
38001 |
|
38002 | return {
|
38003 | x: shape.x + (shape.width - defaultSize.width) / 2,
|
38004 | y: shape.y + (shape.height - defaultSize.height) / 2,
|
38005 | width: defaultSize.width,
|
38006 | height: defaultSize.height
|
38007 | };
|
38008 | }
|
38009 |
|
38010 | this.executed([ 'shape.toggleCollapse' ], LOW_PRIORITY$7, function(e) {
|
38011 |
|
38012 | var context = e.context,
|
38013 | shape = context.shape;
|
38014 |
|
38015 | if (!is$1(shape, 'bpmn:SubProcess')) {
|
38016 | return;
|
38017 | }
|
38018 |
|
38019 | if (!shape.collapsed) {
|
38020 |
|
38021 | hideEmptyLables(shape.children);
|
38022 |
|
38023 |
|
38024 | getBusinessObject(shape).di.isExpanded = true;
|
38025 | } else {
|
38026 |
|
38027 | getBusinessObject(shape).di.isExpanded = false;
|
38028 | }
|
38029 | });
|
38030 |
|
38031 | this.reverted([ 'shape.toggleCollapse' ], LOW_PRIORITY$7, function(e) {
|
38032 |
|
38033 | var context = e.context;
|
38034 | var shape = context.shape;
|
38035 |
|
38036 |
|
38037 |
|
38038 | if (!shape.collapsed) {
|
38039 | getBusinessObject(shape).di.isExpanded = true;
|
38040 |
|
38041 | } else {
|
38042 | getBusinessObject(shape).di.isExpanded = false;
|
38043 | }
|
38044 | });
|
38045 |
|
38046 | this.postExecuted([ 'shape.toggleCollapse' ], LOW_PRIORITY$7, function(e) {
|
38047 | var shape = e.context.shape,
|
38048 | defaultSize = elementFactory._getDefaultSize(shape),
|
38049 | newBounds;
|
38050 |
|
38051 | if (shape.collapsed) {
|
38052 |
|
38053 |
|
38054 | newBounds = collapsedBounds(shape, defaultSize);
|
38055 | } else {
|
38056 |
|
38057 |
|
38058 | newBounds = expandedBounds(shape, defaultSize);
|
38059 | }
|
38060 |
|
38061 | modeling.resizeShape(shape, newBounds);
|
38062 | });
|
38063 |
|
38064 | }
|
38065 |
|
38066 |
|
38067 | inherits_browser(ToggleElementCollapseBehaviour, CommandInterceptor);
|
38068 |
|
38069 | ToggleElementCollapseBehaviour.$inject = [
|
38070 | 'eventBus',
|
38071 | 'elementFactory',
|
38072 | 'modeling'
|
38073 | ];
|
38074 |
|
38075 |
|
38076 |
|
38077 |
|
38078 | function filterVisible(elements) {
|
38079 | return elements.filter(function(e) {
|
38080 | return !e.hidden;
|
38081 | });
|
38082 | }
|
38083 |
|
38084 | |
38085 |
|
38086 |
|
38087 |
|
38088 |
|
38089 |
|
38090 | function UnclaimIdBehavior(eventBus, modeling) {
|
38091 |
|
38092 | CommandInterceptor.call(this, eventBus);
|
38093 |
|
38094 | this.preExecute('elements.delete', function(event) {
|
38095 | var context = event.context,
|
38096 | elements = context.elements;
|
38097 |
|
38098 | forEach(elements, function(element) {
|
38099 | modeling.unclaimId(element.businessObject.id, element.businessObject);
|
38100 | });
|
38101 |
|
38102 | });
|
38103 | }
|
38104 |
|
38105 | inherits_browser(UnclaimIdBehavior, CommandInterceptor);
|
38106 |
|
38107 | UnclaimIdBehavior.$inject = [ 'eventBus', 'modeling' ];
|
38108 |
|
38109 | var LOW_PRIORITY$8 = 500,
|
38110 | HIGH_PRIORITY = 5000;
|
38111 |
|
38112 |
|
38113 | |
38114 |
|
38115 |
|
38116 | function UpdateFlowNodeRefsBehavior(eventBus, modeling, translate) {
|
38117 |
|
38118 | CommandInterceptor.call(this, eventBus);
|
38119 |
|
38120 | |
38121 |
|
38122 |
|
38123 |
|
38124 |
|
38125 |
|
38126 |
|
38127 |
|
38128 |
|
38129 |
|
38130 |
|
38131 |
|
38132 |
|
38133 |
|
38134 | var context;
|
38135 |
|
38136 |
|
38137 | function initContext() {
|
38138 | context = context || new UpdateContext();
|
38139 | context.enter();
|
38140 |
|
38141 | return context;
|
38142 | }
|
38143 |
|
38144 | function getContext() {
|
38145 | if (!context) {
|
38146 | throw new Error(translate('out of bounds release'));
|
38147 | }
|
38148 |
|
38149 | return context;
|
38150 | }
|
38151 |
|
38152 | function releaseContext() {
|
38153 |
|
38154 | if (!context) {
|
38155 | throw new Error(translate('out of bounds release'));
|
38156 | }
|
38157 |
|
38158 | var triggerUpdate = context.leave();
|
38159 |
|
38160 | if (triggerUpdate) {
|
38161 | modeling.updateLaneRefs(context.flowNodes, context.lanes);
|
38162 |
|
38163 | context = null;
|
38164 | }
|
38165 |
|
38166 | return triggerUpdate;
|
38167 | }
|
38168 |
|
38169 |
|
38170 | var laneRefUpdateEvents = [
|
38171 | 'spaceTool',
|
38172 | 'lane.add',
|
38173 | 'lane.resize',
|
38174 | 'lane.split',
|
38175 | 'elements.move',
|
38176 | 'elements.delete',
|
38177 | 'shape.create',
|
38178 | 'shape.delete',
|
38179 | 'shape.move',
|
38180 | 'shape.resize'
|
38181 | ];
|
38182 |
|
38183 |
|
38184 |
|
38185 |
|
38186 | this.preExecute(laneRefUpdateEvents, HIGH_PRIORITY, function(event) {
|
38187 | initContext();
|
38188 | });
|
38189 |
|
38190 | this.postExecuted(laneRefUpdateEvents, LOW_PRIORITY$8, function(event) {
|
38191 | releaseContext();
|
38192 | });
|
38193 |
|
38194 |
|
38195 |
|
38196 |
|
38197 | this.preExecute([
|
38198 | 'shape.create',
|
38199 | 'shape.move',
|
38200 | 'shape.delete',
|
38201 | 'shape.resize'
|
38202 | ], function(event) {
|
38203 |
|
38204 | var context = event.context,
|
38205 | shape = context.shape;
|
38206 |
|
38207 | var updateContext = getContext();
|
38208 |
|
38209 |
|
38210 | if (shape.labelTarget) {
|
38211 | return;
|
38212 | }
|
38213 |
|
38214 | if (is$1(shape, 'bpmn:Lane')) {
|
38215 | updateContext.addLane(shape);
|
38216 | }
|
38217 |
|
38218 | if (is$1(shape, 'bpmn:FlowNode')) {
|
38219 | updateContext.addFlowNode(shape);
|
38220 | }
|
38221 | });
|
38222 | }
|
38223 |
|
38224 | UpdateFlowNodeRefsBehavior.$inject = [
|
38225 | 'eventBus',
|
38226 | 'modeling' ,
|
38227 | 'translate'
|
38228 | ];
|
38229 |
|
38230 | inherits_browser(UpdateFlowNodeRefsBehavior, CommandInterceptor);
|
38231 |
|
38232 |
|
38233 | function UpdateContext() {
|
38234 |
|
38235 | this.flowNodes = [];
|
38236 | this.lanes = [];
|
38237 |
|
38238 | this.counter = 0;
|
38239 |
|
38240 | this.addLane = function(lane) {
|
38241 | this.lanes.push(lane);
|
38242 | };
|
38243 |
|
38244 | this.addFlowNode = function(flowNode) {
|
38245 | this.flowNodes.push(flowNode);
|
38246 | };
|
38247 |
|
38248 | this.enter = function() {
|
38249 | this.counter++;
|
38250 | };
|
38251 |
|
38252 | this.leave = function() {
|
38253 | this.counter--;
|
38254 |
|
38255 | return !this.counter;
|
38256 | };
|
38257 | }
|
38258 |
|
38259 | |
38260 |
|
38261 |
|
38262 |
|
38263 |
|
38264 |
|
38265 |
|
38266 |
|
38267 | function DeleteSequenceFlowBehavior(eventBus, modeling) {
|
38268 |
|
38269 | CommandInterceptor.call(this, eventBus);
|
38270 |
|
38271 |
|
38272 | this.preExecute('connection.delete', function(event) {
|
38273 | var context = event.context,
|
38274 | connection = context.connection,
|
38275 | source = connection.source;
|
38276 |
|
38277 | if (isDefaultFlow(connection, source)) {
|
38278 | modeling.updateProperties(source, {
|
38279 | 'default': null
|
38280 | });
|
38281 | }
|
38282 | });
|
38283 | }
|
38284 |
|
38285 | inherits_browser(DeleteSequenceFlowBehavior, CommandInterceptor);
|
38286 |
|
38287 | DeleteSequenceFlowBehavior.$inject = [
|
38288 | 'eventBus',
|
38289 | 'modeling'
|
38290 | ];
|
38291 |
|
38292 |
|
38293 |
|
38294 |
|
38295 | function isDefaultFlow(connection, source) {
|
38296 |
|
38297 | if (!is$1(connection, 'bpmn:SequenceFlow')) {
|
38298 | return false;
|
38299 | }
|
38300 |
|
38301 | var sourceBo = getBusinessObject(source),
|
38302 | sequenceFlow = getBusinessObject(connection);
|
38303 |
|
38304 | return sourceBo.get('default') === sequenceFlow;
|
38305 | }
|
38306 |
|
38307 | var BehaviorModule = {
|
38308 | __init__: [
|
38309 | 'adaptiveLabelPositioningBehavior',
|
38310 | 'appendBehavior',
|
38311 | 'boundaryEventBehavior',
|
38312 | 'copyPasteBehavior',
|
38313 | 'createBoundaryEventBehavior',
|
38314 | 'createDataObjectBehavior',
|
38315 | 'dataStoreBehavior',
|
38316 | 'createParticipantBehavior',
|
38317 | 'dataInputAssociationBehavior',
|
38318 | 'deleteLaneBehavior',
|
38319 | 'dropOnFlowBehavior',
|
38320 | 'importDockingFix',
|
38321 | 'labelBehavior',
|
38322 | 'modelingFeedback',
|
38323 | 'removeElementBehavior',
|
38324 | 'removeParticipantBehavior',
|
38325 | 'replaceConnectionBehavior',
|
38326 | 'replaceElementBehaviour',
|
38327 | 'resizeLaneBehavior',
|
38328 | 'toggleElementCollapseBehaviour',
|
38329 | 'unclaimIdBehavior',
|
38330 | 'unsetDefaultFlowBehavior',
|
38331 | 'updateFlowNodeRefsBehavior'
|
38332 | ],
|
38333 | adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
|
38334 | appendBehavior: [ 'type', AppendBehavior ],
|
38335 | boundaryEventBehavior: [ 'type', BoundaryEventBehavior ],
|
38336 | copyPasteBehavior: [ 'type', CopyPasteBehavior ],
|
38337 | createBoundaryEventBehavior: [ 'type', CreateBoundaryEventBehavior ],
|
38338 | createDataObjectBehavior: [ 'type', CreateDataObjectBehavior ],
|
38339 | createParticipantBehavior: [ 'type', CreateParticipantBehavior ],
|
38340 | dataInputAssociationBehavior: [ 'type', DataInputAssociationBehavior ],
|
38341 | dataStoreBehavior: [ 'type', DataStoreBehavior ],
|
38342 | deleteLaneBehavior: [ 'type', DeleteLaneBehavior ],
|
38343 | dropOnFlowBehavior: [ 'type', DropOnFlowBehavior ],
|
38344 | importDockingFix: [ 'type', ImportDockingFix ],
|
38345 | labelBehavior: [ 'type', LabelBehavior ],
|
38346 | modelingFeedback: [ 'type', ModelingFeedback ],
|
38347 | replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
|
38348 | removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
|
38349 | replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
|
38350 | resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
|
38351 | removeElementBehavior: [ 'type', RemoveElementBehavior ],
|
38352 | toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],
|
38353 | unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
|
38354 | updateFlowNodeRefsBehavior: [ 'type', UpdateFlowNodeRefsBehavior ],
|
38355 | unsetDefaultFlowBehavior: [ 'type', DeleteSequenceFlowBehavior ]
|
38356 | };
|
38357 |
|
38358 | function getBoundaryAttachment(position, targetBounds) {
|
38359 |
|
38360 | var orientation = getOrientation(position, targetBounds, -15);
|
38361 |
|
38362 | if (orientation !== 'intersect') {
|
38363 | return orientation;
|
38364 | } else {
|
38365 | return null;
|
38366 | }
|
38367 | }
|
38368 |
|
38369 | var abs$4 = Math.abs,
|
38370 | min$3 = Math.min,
|
38371 | max$4 = Math.max;
|
38372 |
|
38373 |
|
38374 | function addToTrbl(trbl, attr, value, choice) {
|
38375 |
|
38376 | var current = trbl[attr];
|
38377 |
|
38378 |
|
38379 |
|
38380 |
|
38381 | trbl[attr] = current === undefined ? value : choice(value, current);
|
38382 | }
|
38383 |
|
38384 | function addMin(trbl, attr, value) {
|
38385 | return addToTrbl(trbl, attr, value, min$3);
|
38386 | }
|
38387 |
|
38388 | function addMax(trbl, attr, value) {
|
38389 | return addToTrbl(trbl, attr, value, max$4);
|
38390 | }
|
38391 |
|
38392 |
|
38393 | var LANE_MIN_HEIGHT = 60,
|
38394 | LANE_MIN_WIDTH = 300,
|
38395 | LANE_RIGHT_PADDING = 20,
|
38396 | LANE_LEFT_PADDING = 50,
|
38397 | LANE_TOP_PADDING = 20,
|
38398 | LANE_BOTTOM_PADDING = 20;
|
38399 |
|
38400 |
|
38401 | function getParticipantSizeConstraints(laneShape, resizeDirection, balanced) {
|
38402 |
|
38403 | var lanesRoot = getLanesRoot(laneShape);
|
38404 |
|
38405 | var isFirst = true,
|
38406 | isLast = true;
|
38407 |
|
38408 |
|
38409 |
|
38410 | var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
|
38411 |
|
38412 | var laneTrbl = asTRBL(laneShape);
|
38413 |
|
38414 | var maxTrbl = {},
|
38415 | minTrbl = {};
|
38416 |
|
38417 | if (/e/.test(resizeDirection)) {
|
38418 | minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
|
38419 | } else
|
38420 | if (/w/.test(resizeDirection)) {
|
38421 | minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
|
38422 | }
|
38423 |
|
38424 | allLanes.forEach(function(other) {
|
38425 |
|
38426 | var otherTrbl = asTRBL(other);
|
38427 |
|
38428 | if (/n/.test(resizeDirection)) {
|
38429 |
|
38430 | if (otherTrbl.top < (laneTrbl.top - 10)) {
|
38431 | isFirst = false;
|
38432 | }
|
38433 |
|
38434 |
|
38435 | if (balanced && abs$4(laneTrbl.top - otherTrbl.bottom) < 10) {
|
38436 | addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
|
38437 | }
|
38438 |
|
38439 |
|
38440 | if (abs$4(laneTrbl.top - otherTrbl.top) < 5) {
|
38441 | addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
38442 | }
|
38443 | }
|
38444 |
|
38445 | if (/s/.test(resizeDirection)) {
|
38446 |
|
38447 | if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
|
38448 | isLast = false;
|
38449 | }
|
38450 |
|
38451 |
|
38452 | if (balanced && abs$4(laneTrbl.bottom - otherTrbl.top) < 10) {
|
38453 | addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
|
38454 | }
|
38455 |
|
38456 |
|
38457 | if (abs$4(laneTrbl.bottom - otherTrbl.bottom) < 5) {
|
38458 | addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
|
38459 | }
|
38460 | }
|
38461 | });
|
38462 |
|
38463 |
|
38464 |
|
38465 |
|
38466 | var flowElements = lanesRoot.children.filter(function(s) {
|
38467 | return !s.hidden && !s.waypoints && (is$1(s, 'bpmn:FlowElement') || is$1(s, 'bpmn:Artifact'));
|
38468 | });
|
38469 |
|
38470 | flowElements.forEach(function(flowElement) {
|
38471 |
|
38472 | var flowElementTrbl = asTRBL(flowElement);
|
38473 |
|
38474 | if (isFirst && /n/.test(resizeDirection)) {
|
38475 | addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
|
38476 | }
|
38477 |
|
38478 | if (/e/.test(resizeDirection)) {
|
38479 | addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
|
38480 | }
|
38481 |
|
38482 | if (isLast && /s/.test(resizeDirection)) {
|
38483 | addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
|
38484 | }
|
38485 |
|
38486 | if (/w/.test(resizeDirection)) {
|
38487 | addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
|
38488 | }
|
38489 | });
|
38490 |
|
38491 |
|
38492 | return {
|
38493 | min: minTrbl,
|
38494 | max: maxTrbl
|
38495 | };
|
38496 | }
|
38497 |
|
38498 | |
38499 |
|
38500 |
|
38501 | function BpmnRules(eventBus) {
|
38502 | RuleProvider.call(this, eventBus);
|
38503 | }
|
38504 |
|
38505 | inherits_browser(BpmnRules, RuleProvider);
|
38506 |
|
38507 | BpmnRules.$inject = [ 'eventBus' ];
|
38508 |
|
38509 | BpmnRules.prototype.init = function() {
|
38510 |
|
38511 | this.addRule('connection.start', function(context) {
|
38512 | var source = context.source;
|
38513 |
|
38514 | return canStartConnection(source);
|
38515 | });
|
38516 |
|
38517 | this.addRule('connection.create', function(context) {
|
38518 | var source = context.source,
|
38519 | target = context.target,
|
38520 | hints = context.hints || {},
|
38521 | targetParent = hints.targetParent,
|
38522 | targetAttach = hints.targetAttach;
|
38523 |
|
38524 |
|
38525 |
|
38526 |
|
38527 | if (targetAttach) {
|
38528 | return false;
|
38529 | }
|
38530 |
|
38531 |
|
38532 |
|
38533 | if (targetParent) {
|
38534 | target.parent = targetParent;
|
38535 | }
|
38536 |
|
38537 | try {
|
38538 | return canConnect(source, target);
|
38539 | } finally {
|
38540 |
|
38541 | if (targetParent) {
|
38542 | target.parent = null;
|
38543 | }
|
38544 | }
|
38545 | });
|
38546 |
|
38547 | this.addRule('connection.reconnectStart', function(context) {
|
38548 |
|
38549 | var connection = context.connection,
|
38550 | source = context.hover || context.source,
|
38551 | target = connection.target;
|
38552 |
|
38553 | return canConnect(source, target, connection);
|
38554 | });
|
38555 |
|
38556 | this.addRule('connection.reconnectEnd', function(context) {
|
38557 |
|
38558 | var connection = context.connection,
|
38559 | source = connection.source,
|
38560 | target = context.hover || context.target;
|
38561 |
|
38562 | return canConnect(source, target, connection);
|
38563 | });
|
38564 |
|
38565 | this.addRule('connection.updateWaypoints', function(context) {
|
38566 |
|
38567 | return null;
|
38568 | });
|
38569 |
|
38570 | this.addRule('shape.resize', function(context) {
|
38571 |
|
38572 | var shape = context.shape,
|
38573 | newBounds = context.newBounds;
|
38574 |
|
38575 | return canResize(shape, newBounds);
|
38576 | });
|
38577 |
|
38578 | this.addRule('elements.move', function(context) {
|
38579 |
|
38580 | var target = context.target,
|
38581 | shapes = context.shapes,
|
38582 | position = context.position;
|
38583 |
|
38584 | return canAttach(shapes, target, null, position) ||
|
38585 | canReplace(shapes, target, position) ||
|
38586 | canMove(shapes, target, position) ||
|
38587 | canInsert(shapes, target, position);
|
38588 | });
|
38589 |
|
38590 | this.addRule('shape.create', function(context) {
|
38591 | return canCreate(
|
38592 | context.shape,
|
38593 | context.target,
|
38594 | context.source,
|
38595 | context.position
|
38596 | );
|
38597 | });
|
38598 |
|
38599 | this.addRule('shape.attach', function(context) {
|
38600 |
|
38601 | return canAttach(
|
38602 | context.shape,
|
38603 | context.target,
|
38604 | null,
|
38605 | context.position
|
38606 | );
|
38607 | });
|
38608 |
|
38609 | this.addRule('element.copy', function(context) {
|
38610 | var collection = context.collection,
|
38611 | element = context.element;
|
38612 |
|
38613 | return canCopy(collection, element);
|
38614 | });
|
38615 |
|
38616 | this.addRule('element.paste', function(context) {
|
38617 | var parent = context.parent,
|
38618 | element = context.element,
|
38619 | position = context.position,
|
38620 | source = context.source,
|
38621 | target = context.target;
|
38622 |
|
38623 | if (source || target) {
|
38624 | return canConnect(source, target);
|
38625 | }
|
38626 |
|
38627 | return canAttach([ element ], parent, null, position) || canCreate(element, parent, null, position);
|
38628 | });
|
38629 |
|
38630 | this.addRule('elements.paste', function(context) {
|
38631 | var tree = context.tree,
|
38632 | target = context.target;
|
38633 |
|
38634 | return canPaste(tree, target);
|
38635 | });
|
38636 | };
|
38637 |
|
38638 | BpmnRules.prototype.canConnectMessageFlow = canConnectMessageFlow;
|
38639 |
|
38640 | BpmnRules.prototype.canConnectSequenceFlow = canConnectSequenceFlow;
|
38641 |
|
38642 | BpmnRules.prototype.canConnectDataAssociation = canConnectDataAssociation;
|
38643 |
|
38644 | BpmnRules.prototype.canConnectAssociation = canConnectAssociation;
|
38645 |
|
38646 | BpmnRules.prototype.canMove = canMove;
|
38647 |
|
38648 | BpmnRules.prototype.canAttach = canAttach;
|
38649 |
|
38650 | BpmnRules.prototype.canReplace = canReplace;
|
38651 |
|
38652 | BpmnRules.prototype.canDrop = canDrop;
|
38653 |
|
38654 | BpmnRules.prototype.canInsert = canInsert;
|
38655 |
|
38656 | BpmnRules.prototype.canCreate = canCreate;
|
38657 |
|
38658 | BpmnRules.prototype.canConnect = canConnect;
|
38659 |
|
38660 | BpmnRules.prototype.canResize = canResize;
|
38661 |
|
38662 | BpmnRules.prototype.canCopy = canCopy;
|
38663 |
|
38664 | |
38665 |
|
38666 |
|
38667 |
|
38668 | |
38669 |
|
38670 |
|
38671 |
|
38672 |
|
38673 |
|
38674 | function canStartConnection(element) {
|
38675 | if (nonExistingOrLabel(element)) {
|
38676 | return null;
|
38677 | }
|
38678 |
|
38679 | return isAny(element, [
|
38680 | 'bpmn:FlowNode',
|
38681 | 'bpmn:InteractionNode',
|
38682 | 'bpmn:DataObjectReference',
|
38683 | 'bpmn:DataStoreReference'
|
38684 | ]);
|
38685 | }
|
38686 |
|
38687 | function nonExistingOrLabel(element) {
|
38688 | return !element || isLabel(element);
|
38689 | }
|
38690 |
|
38691 | function isSame(a, b) {
|
38692 | return a === b;
|
38693 | }
|
38694 |
|
38695 | function getOrganizationalParent(element) {
|
38696 |
|
38697 | do {
|
38698 | if (is$1(element, 'bpmn:Process')) {
|
38699 | return getBusinessObject(element);
|
38700 | }
|
38701 |
|
38702 | if (is$1(element, 'bpmn:Participant')) {
|
38703 | return (
|
38704 | getBusinessObject(element).processRef ||
|
38705 | getBusinessObject(element)
|
38706 | );
|
38707 | }
|
38708 | } while ((element = element.parent));
|
38709 |
|
38710 | }
|
38711 |
|
38712 | function isTextAnnotation(element) {
|
38713 | return is$1(element, 'bpmn:TextAnnotation');
|
38714 | }
|
38715 |
|
38716 | function isCompensationBoundary(element) {
|
38717 | return is$1(element, 'bpmn:BoundaryEvent') &&
|
38718 | hasEventDefinition$2(element, 'bpmn:CompensateEventDefinition');
|
38719 | }
|
38720 |
|
38721 | function isForCompensation(e) {
|
38722 | return getBusinessObject(e).isForCompensation;
|
38723 | }
|
38724 |
|
38725 | function isSameOrganization(a, b) {
|
38726 | var parentA = getOrganizationalParent(a),
|
38727 | parentB = getOrganizationalParent(b);
|
38728 |
|
38729 | return parentA === parentB;
|
38730 | }
|
38731 |
|
38732 | function isMessageFlowSource(element) {
|
38733 | return (
|
38734 | is$1(element, 'bpmn:InteractionNode') && (
|
38735 | !is$1(element, 'bpmn:Event') || (
|
38736 | is$1(element, 'bpmn:ThrowEvent') &&
|
38737 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
38738 | )
|
38739 | )
|
38740 | );
|
38741 | }
|
38742 |
|
38743 | function isMessageFlowTarget(element) {
|
38744 | return (
|
38745 | is$1(element, 'bpmn:InteractionNode') &&
|
38746 | !isForCompensation(element) && (
|
38747 | !is$1(element, 'bpmn:Event') || (
|
38748 | is$1(element, 'bpmn:CatchEvent') &&
|
38749 | hasEventDefinitionOrNone(element, 'bpmn:MessageEventDefinition')
|
38750 | )
|
38751 | )
|
38752 | );
|
38753 | }
|
38754 |
|
38755 | function getScopeParent(element) {
|
38756 |
|
38757 | var parent = element;
|
38758 |
|
38759 | while ((parent = parent.parent)) {
|
38760 |
|
38761 | if (is$1(parent, 'bpmn:FlowElementsContainer')) {
|
38762 | return getBusinessObject(parent);
|
38763 | }
|
38764 |
|
38765 | if (is$1(parent, 'bpmn:Participant')) {
|
38766 | return getBusinessObject(parent).processRef;
|
38767 | }
|
38768 | }
|
38769 |
|
38770 | return null;
|
38771 | }
|
38772 |
|
38773 | function isSameScope(a, b) {
|
38774 | var scopeParentA = getScopeParent(a),
|
38775 | scopeParentB = getScopeParent(b);
|
38776 |
|
38777 | return scopeParentA && (scopeParentA === scopeParentB);
|
38778 | }
|
38779 |
|
38780 | function hasEventDefinition$2(element, eventDefinition) {
|
38781 | var bo = getBusinessObject(element);
|
38782 |
|
38783 | return !!find(bo.eventDefinitions || [], function(definition) {
|
38784 | return is$1(definition, eventDefinition);
|
38785 | });
|
38786 | }
|
38787 |
|
38788 | function hasEventDefinitionOrNone(element, eventDefinition) {
|
38789 | var bo = getBusinessObject(element);
|
38790 |
|
38791 | return (bo.eventDefinitions || []).every(function(definition) {
|
38792 | return is$1(definition, eventDefinition);
|
38793 | });
|
38794 | }
|
38795 |
|
38796 | function isSequenceFlowSource(element) {
|
38797 | return (
|
38798 | is$1(element, 'bpmn:FlowNode') &&
|
38799 | !is$1(element, 'bpmn:EndEvent') &&
|
38800 | !isEventSubProcess(element) &&
|
38801 | !(is$1(element, 'bpmn:IntermediateThrowEvent') &&
|
38802 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
38803 | ) &&
|
38804 | !isCompensationBoundary(element) &&
|
38805 | !isForCompensation(element)
|
38806 | );
|
38807 | }
|
38808 |
|
38809 | function isSequenceFlowTarget(element) {
|
38810 | return (
|
38811 | is$1(element, 'bpmn:FlowNode') &&
|
38812 | !is$1(element, 'bpmn:StartEvent') &&
|
38813 | !is$1(element, 'bpmn:BoundaryEvent') &&
|
38814 | !isEventSubProcess(element) &&
|
38815 | !(is$1(element, 'bpmn:IntermediateCatchEvent') &&
|
38816 | hasEventDefinition$2(element, 'bpmn:LinkEventDefinition')
|
38817 | ) &&
|
38818 | !isForCompensation(element)
|
38819 | );
|
38820 | }
|
38821 |
|
38822 | function isEventBasedTarget(element) {
|
38823 | return (
|
38824 | is$1(element, 'bpmn:ReceiveTask') || (
|
38825 | is$1(element, 'bpmn:IntermediateCatchEvent') && (
|
38826 | hasEventDefinition$2(element, 'bpmn:MessageEventDefinition') ||
|
38827 | hasEventDefinition$2(element, 'bpmn:TimerEventDefinition') ||
|
38828 | hasEventDefinition$2(element, 'bpmn:ConditionalEventDefinition') ||
|
38829 | hasEventDefinition$2(element, 'bpmn:SignalEventDefinition')
|
38830 | )
|
38831 | )
|
38832 | );
|
38833 | }
|
38834 |
|
38835 | function isConnection$1(element) {
|
38836 | return element.waypoints;
|
38837 | }
|
38838 |
|
38839 | function getParents(element) {
|
38840 |
|
38841 | var parents = [];
|
38842 |
|
38843 | while (element) {
|
38844 | element = element.parent;
|
38845 |
|
38846 | if (element) {
|
38847 | parents.push(element);
|
38848 | }
|
38849 | }
|
38850 |
|
38851 | return parents;
|
38852 | }
|
38853 |
|
38854 | function isParent(possibleParent, element) {
|
38855 | var allParents = getParents(element);
|
38856 | return allParents.indexOf(possibleParent) !== -1;
|
38857 | }
|
38858 |
|
38859 | function canConnect(source, target, connection) {
|
38860 |
|
38861 | if (nonExistingOrLabel(source) || nonExistingOrLabel(target)) {
|
38862 | return null;
|
38863 | }
|
38864 |
|
38865 | if (!is$1(connection, 'bpmn:DataAssociation')) {
|
38866 |
|
38867 | if (canConnectMessageFlow(source, target)) {
|
38868 | return { type: 'bpmn:MessageFlow' };
|
38869 | }
|
38870 |
|
38871 | if (canConnectSequenceFlow(source, target)) {
|
38872 | return { type: 'bpmn:SequenceFlow' };
|
38873 | }
|
38874 | }
|
38875 |
|
38876 | var connectDataAssociation = canConnectDataAssociation(source, target);
|
38877 |
|
38878 | if (connectDataAssociation) {
|
38879 | return connectDataAssociation;
|
38880 | }
|
38881 |
|
38882 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
38883 | return {
|
38884 | type: 'bpmn:Association',
|
38885 | associationDirection: 'One'
|
38886 | };
|
38887 | }
|
38888 |
|
38889 | if (canConnectAssociation(source, target)) {
|
38890 |
|
38891 | return {
|
38892 | type: 'bpmn:Association'
|
38893 | };
|
38894 | }
|
38895 |
|
38896 | return false;
|
38897 | }
|
38898 |
|
38899 | |
38900 |
|
38901 |
|
38902 |
|
38903 |
|
38904 | function canDrop(element, target, position) {
|
38905 |
|
38906 |
|
38907 | if (isLabel(element)) {
|
38908 | return true;
|
38909 | }
|
38910 |
|
38911 |
|
38912 | if (is$1(target, 'bpmn:Participant') && !isExpanded(target)) {
|
38913 | return false;
|
38914 | }
|
38915 |
|
38916 |
|
38917 |
|
38918 | if (is$1(element, 'bpmn:Participant')) {
|
38919 | return is$1(target, 'bpmn:Process') || is$1(target, 'bpmn:Collaboration');
|
38920 | }
|
38921 |
|
38922 |
|
38923 | if (is$1(element, 'bpmn:Lane')) {
|
38924 | return is$1(target, 'bpmn:Participant') || is$1(target, 'bpmn:Lane');
|
38925 | }
|
38926 |
|
38927 | if (is$1(element, 'bpmn:BoundaryEvent')) {
|
38928 | return false;
|
38929 | }
|
38930 |
|
38931 |
|
38932 |
|
38933 | if (is$1(element, 'bpmn:FlowElement') && !is$1(element, 'bpmn:DataStoreReference')) {
|
38934 | if (is$1(target, 'bpmn:FlowElementsContainer')) {
|
38935 | return isExpanded(target);
|
38936 | }
|
38937 |
|
38938 | return isAny(target, [ 'bpmn:Participant', 'bpmn:Lane' ]);
|
38939 | }
|
38940 |
|
38941 |
|
38942 |
|
38943 |
|
38944 |
|
38945 | if (isAny(element, [ 'bpmn:Artifact', 'bpmn:DataAssociation', 'bpmn:DataStoreReference' ])) {
|
38946 | return isAny(target, [
|
38947 | 'bpmn:Collaboration',
|
38948 | 'bpmn:Lane',
|
38949 | 'bpmn:Participant',
|
38950 | 'bpmn:Process',
|
38951 | 'bpmn:SubProcess' ]);
|
38952 | }
|
38953 |
|
38954 | if (is$1(element, 'bpmn:MessageFlow')) {
|
38955 | return is$1(target, 'bpmn:Collaboration')
|
38956 | || element.source.parent == target
|
38957 | || element.target.parent == target;
|
38958 | }
|
38959 |
|
38960 | return false;
|
38961 | }
|
38962 |
|
38963 | function canPaste(tree, target) {
|
38964 | var topLevel = tree[0],
|
38965 | participants;
|
38966 |
|
38967 | if (is$1(target, 'bpmn:Collaboration')) {
|
38968 | return every(topLevel, function(e) {
|
38969 | return e.type === 'bpmn:Participant';
|
38970 | });
|
38971 | }
|
38972 |
|
38973 | if (is$1(target, 'bpmn:Process')) {
|
38974 | participants = some(topLevel, function(e) {
|
38975 | return e.type === 'bpmn:Participant';
|
38976 | });
|
38977 |
|
38978 | return !(participants && target.children.length > 0);
|
38979 | }
|
38980 |
|
38981 |
|
38982 | if (is$1(target, 'bpmn:Participant') && !isExpanded(target)) {
|
38983 | return false;
|
38984 | }
|
38985 |
|
38986 | if (is$1(target, 'bpmn:FlowElementsContainer')) {
|
38987 | return isExpanded(target);
|
38988 | }
|
38989 |
|
38990 | return isAny(target, [
|
38991 | 'bpmn:Collaboration',
|
38992 | 'bpmn:Lane',
|
38993 | 'bpmn:Participant',
|
38994 | 'bpmn:Process',
|
38995 | 'bpmn:SubProcess' ]);
|
38996 | }
|
38997 |
|
38998 | function isBoundaryEvent(element) {
|
38999 | return !isLabel(element) && is$1(element, 'bpmn:BoundaryEvent');
|
39000 | }
|
39001 |
|
39002 | function isLane(element) {
|
39003 | return is$1(element, 'bpmn:Lane');
|
39004 | }
|
39005 |
|
39006 | |
39007 |
|
39008 |
|
39009 |
|
39010 | function isBoundaryCandidate(element) {
|
39011 | return isBoundaryEvent(element) ||
|
39012 | (is$1(element, 'bpmn:IntermediateThrowEvent') && !element.parent);
|
39013 | }
|
39014 |
|
39015 | function isReceiveTaskAfterEventBasedGateway(element) {
|
39016 | return (
|
39017 | is$1(element, 'bpmn:ReceiveTask') &&
|
39018 | find(element.incoming, function(incoming) {
|
39019 | return is$1(incoming.source, 'bpmn:EventBasedGateway');
|
39020 | })
|
39021 | );
|
39022 | }
|
39023 |
|
39024 |
|
39025 | function canAttach(elements, target, source, position) {
|
39026 |
|
39027 | if (!Array.isArray(elements)) {
|
39028 | elements = [ elements ];
|
39029 | }
|
39030 |
|
39031 |
|
39032 | if (source) {
|
39033 | return false;
|
39034 | }
|
39035 |
|
39036 |
|
39037 | if (elements.length !== 1) {
|
39038 | return false;
|
39039 | }
|
39040 |
|
39041 | var element = elements[0];
|
39042 |
|
39043 |
|
39044 | if (isLabel(element)) {
|
39045 | return false;
|
39046 | }
|
39047 |
|
39048 |
|
39049 | if (!isBoundaryCandidate(element)) {
|
39050 | return false;
|
39051 | }
|
39052 |
|
39053 |
|
39054 | if (!target) {
|
39055 | return true;
|
39056 | }
|
39057 |
|
39058 |
|
39059 | if (isEventSubProcess(target)) {
|
39060 | return false;
|
39061 | }
|
39062 |
|
39063 |
|
39064 | if (!is$1(target, 'bpmn:Activity') || isForCompensation(target)) {
|
39065 | return false;
|
39066 | }
|
39067 |
|
39068 |
|
39069 | if (position && !getBoundaryAttachment(position, target)) {
|
39070 | return false;
|
39071 | }
|
39072 |
|
39073 |
|
39074 | if (isReceiveTaskAfterEventBasedGateway(target)) {
|
39075 | return false;
|
39076 | }
|
39077 |
|
39078 | return 'attach';
|
39079 | }
|
39080 |
|
39081 |
|
39082 | |
39083 |
|
39084 |
|
39085 |
|
39086 |
|
39087 |
|
39088 |
|
39089 |
|
39090 |
|
39091 |
|
39092 |
|
39093 |
|
39094 |
|
39095 |
|
39096 |
|
39097 |
|
39098 |
|
39099 |
|
39100 |
|
39101 | function canReplace(elements, target, position) {
|
39102 |
|
39103 | if (!target) {
|
39104 | return false;
|
39105 | }
|
39106 |
|
39107 | var canExecute = {
|
39108 | replacements: []
|
39109 | };
|
39110 |
|
39111 | forEach(elements, function(element) {
|
39112 |
|
39113 | if (!isEventSubProcess(target)) {
|
39114 |
|
39115 | if (is$1(element, 'bpmn:StartEvent') &&
|
39116 | element.type !== 'label' &&
|
39117 | canDrop(element, target)) {
|
39118 |
|
39119 |
|
39120 |
|
39121 | if (!isInterrupting(element)) {
|
39122 | canExecute.replacements.push({
|
39123 | oldElementId: element.id,
|
39124 | newElementType: 'bpmn:StartEvent'
|
39125 | });
|
39126 | }
|
39127 |
|
39128 |
|
39129 |
|
39130 | if (hasErrorEventDefinition(element) ||
|
39131 | hasEscalationEventDefinition(element) ||
|
39132 | hasCompensateEventDefinition(element)) {
|
39133 | canExecute.replacements.push({
|
39134 | oldElementId: element.id,
|
39135 | newElementType: 'bpmn:StartEvent'
|
39136 | });
|
39137 | }
|
39138 | }
|
39139 | }
|
39140 |
|
39141 | if (!is$1(target, 'bpmn:Transaction')) {
|
39142 | if (hasEventDefinition$2(element, 'bpmn:CancelEventDefinition') &&
|
39143 | element.type !== 'label') {
|
39144 |
|
39145 | if (is$1(element, 'bpmn:EndEvent') && canDrop(element, target)) {
|
39146 | canExecute.replacements.push({
|
39147 | oldElementId: element.id,
|
39148 | newElementType: 'bpmn:EndEvent'
|
39149 | });
|
39150 | }
|
39151 |
|
39152 | if (is$1(element, 'bpmn:BoundaryEvent') && canAttach(element, target, null, position)) {
|
39153 | canExecute.replacements.push({
|
39154 | oldElementId: element.id,
|
39155 | newElementType: 'bpmn:BoundaryEvent'
|
39156 | });
|
39157 | }
|
39158 | }
|
39159 | }
|
39160 | });
|
39161 |
|
39162 | return canExecute.replacements.length ? canExecute : false;
|
39163 | }
|
39164 |
|
39165 | function canMove(elements, target) {
|
39166 |
|
39167 |
|
39168 | if (some(elements, isBoundaryEvent)) {
|
39169 | return false;
|
39170 | }
|
39171 |
|
39172 |
|
39173 | if (some(elements, isLane)) {
|
39174 | return false;
|
39175 | }
|
39176 |
|
39177 |
|
39178 | if (!target) {
|
39179 | return true;
|
39180 | }
|
39181 |
|
39182 | return elements.every(function(element) {
|
39183 | return canDrop(element, target);
|
39184 | });
|
39185 | }
|
39186 |
|
39187 | function canCreate(shape, target, source, position) {
|
39188 |
|
39189 | if (!target) {
|
39190 | return false;
|
39191 | }
|
39192 |
|
39193 | if (isLabel(target)) {
|
39194 | return null;
|
39195 | }
|
39196 |
|
39197 | if (isSame(source, target)) {
|
39198 | return false;
|
39199 | }
|
39200 |
|
39201 |
|
39202 |
|
39203 | if (source && isParent(source, target)) {
|
39204 | return false;
|
39205 | }
|
39206 |
|
39207 | return canDrop(shape, target, position) || canInsert(shape, target, position);
|
39208 | }
|
39209 |
|
39210 | function canResize(shape, newBounds) {
|
39211 | if (is$1(shape, 'bpmn:SubProcess')) {
|
39212 | return (
|
39213 | isExpanded(shape) && (
|
39214 | !newBounds || (newBounds.width >= 100 && newBounds.height >= 80)
|
39215 | )
|
39216 | );
|
39217 | }
|
39218 |
|
39219 | if (is$1(shape, 'bpmn:Lane')) {
|
39220 | return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60);
|
39221 | }
|
39222 |
|
39223 | if (is$1(shape, 'bpmn:Participant')) {
|
39224 | return !newBounds || (newBounds.width >= 250 && newBounds.height >= 50);
|
39225 | }
|
39226 |
|
39227 | if (isTextAnnotation(shape)) {
|
39228 | return true;
|
39229 | }
|
39230 |
|
39231 | return false;
|
39232 | }
|
39233 |
|
39234 | |
39235 |
|
39236 |
|
39237 |
|
39238 | function isOneTextAnnotation(source, target) {
|
39239 |
|
39240 | var sourceTextAnnotation = isTextAnnotation(source),
|
39241 | targetTextAnnotation = isTextAnnotation(target);
|
39242 |
|
39243 | return (
|
39244 | (sourceTextAnnotation || targetTextAnnotation) &&
|
39245 | (sourceTextAnnotation !== targetTextAnnotation)
|
39246 | );
|
39247 | }
|
39248 |
|
39249 |
|
39250 | function canConnectAssociation(source, target) {
|
39251 |
|
39252 |
|
39253 | if (isConnection$1(source) || isConnection$1(target)) {
|
39254 | return false;
|
39255 | }
|
39256 |
|
39257 |
|
39258 | if (isCompensationBoundary(source) && isForCompensation(target)) {
|
39259 | return true;
|
39260 | }
|
39261 |
|
39262 |
|
39263 | if (isParent(target, source) || isParent(source, target)) {
|
39264 | return false;
|
39265 | }
|
39266 |
|
39267 |
|
39268 | return isOneTextAnnotation(source, target);
|
39269 | }
|
39270 |
|
39271 | function canConnectMessageFlow(source, target) {
|
39272 |
|
39273 | return isMessageFlowSource(source) &&
|
39274 | isMessageFlowTarget(target) &&
|
39275 | !isSameOrganization(source, target);
|
39276 | }
|
39277 |
|
39278 | function canConnectSequenceFlow(source, target) {
|
39279 |
|
39280 | return isSequenceFlowSource(source) &&
|
39281 | isSequenceFlowTarget(target) &&
|
39282 | isSameScope(source, target) &&
|
39283 | !(is$1(source, 'bpmn:EventBasedGateway') && !isEventBasedTarget(target));
|
39284 | }
|
39285 |
|
39286 |
|
39287 | function canConnectDataAssociation(source, target) {
|
39288 |
|
39289 | if (isAny(source, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
39290 | isAny(target, [ 'bpmn:Activity', 'bpmn:ThrowEvent' ])) {
|
39291 | return { type: 'bpmn:DataInputAssociation' };
|
39292 | }
|
39293 |
|
39294 | if (isAny(target, [ 'bpmn:DataObjectReference', 'bpmn:DataStoreReference' ]) &&
|
39295 | isAny(source, [ 'bpmn:Activity', 'bpmn:CatchEvent' ])) {
|
39296 | return { type: 'bpmn:DataOutputAssociation' };
|
39297 | }
|
39298 |
|
39299 | return false;
|
39300 | }
|
39301 |
|
39302 | function canInsert(shape, flow, position) {
|
39303 |
|
39304 | if (!flow) {
|
39305 | return false;
|
39306 | }
|
39307 |
|
39308 | if (Array.isArray(shape)) {
|
39309 | if (shape.length !== 1) {
|
39310 | return false;
|
39311 | }
|
39312 |
|
39313 | shape = shape[0];
|
39314 | }
|
39315 |
|
39316 | if (flow.source === shape ||
|
39317 | flow.target === shape) {
|
39318 | return false;
|
39319 | }
|
39320 |
|
39321 |
|
39322 |
|
39323 |
|
39324 |
|
39325 |
|
39326 |
|
39327 | return (
|
39328 | isAny(flow, [ 'bpmn:SequenceFlow', 'bpmn:MessageFlow' ]) &&
|
39329 | !isLabel(flow) &&
|
39330 | is$1(shape, 'bpmn:FlowNode') &&
|
39331 | !is$1(shape, 'bpmn:BoundaryEvent') &&
|
39332 | canDrop(shape, flow.parent, position));
|
39333 | }
|
39334 |
|
39335 | function contains(collection, element) {
|
39336 | return (collection && element) && collection.indexOf(element) !== -1;
|
39337 | }
|
39338 |
|
39339 | function canCopy(collection, element) {
|
39340 | if (is$1(element, 'bpmn:Lane') && !contains(collection, element.parent)) {
|
39341 | return false;
|
39342 | }
|
39343 |
|
39344 | if (is$1(element, 'bpmn:BoundaryEvent') && !contains(collection, element.host)) {
|
39345 | return false;
|
39346 | }
|
39347 |
|
39348 | return true;
|
39349 | }
|
39350 |
|
39351 | var RulesModule$1 = {
|
39352 | __depends__: [
|
39353 | RulesModule
|
39354 | ],
|
39355 | __init__: [ 'bpmnRules' ],
|
39356 | bpmnRules: [ 'type', BpmnRules ]
|
39357 | };
|
39358 |
|
39359 | |
39360 |
|
39361 |
|
39362 |
|
39363 |
|
39364 |
|
39365 |
|
39366 |
|
39367 |
|
39368 |
|
39369 |
|
39370 |
|
39371 |
|
39372 |
|
39373 |
|
39374 |
|
39375 |
|
39376 |
|
39377 |
|
39378 |
|
39379 |
|
39380 |
|
39381 |
|
39382 |
|
39383 |
|
39384 |
|
39385 |
|
39386 |
|
39387 |
|
39388 | function OrderingProvider(eventBus) {
|
39389 |
|
39390 | CommandInterceptor.call(this, eventBus);
|
39391 |
|
39392 |
|
39393 | var self = this;
|
39394 |
|
39395 | this.preExecute([ 'shape.create', 'connection.create' ], function(event) {
|
39396 |
|
39397 | var context = event.context,
|
39398 | element = context.shape || context.connection,
|
39399 | parent = context.parent;
|
39400 |
|
39401 | var ordering = self.getOrdering(element, parent);
|
39402 |
|
39403 | if (ordering) {
|
39404 |
|
39405 | if (ordering.parent !== undefined) {
|
39406 | context.parent = ordering.parent;
|
39407 | }
|
39408 |
|
39409 | context.parentIndex = ordering.index;
|
39410 | }
|
39411 | });
|
39412 |
|
39413 | this.preExecute([ 'shape.move', 'connection.move' ], function(event) {
|
39414 |
|
39415 | var context = event.context,
|
39416 | element = context.shape || context.connection,
|
39417 | parent = context.newParent || element.parent;
|
39418 |
|
39419 | var ordering = self.getOrdering(element, parent);
|
39420 |
|
39421 | if (ordering) {
|
39422 |
|
39423 | if (ordering.parent !== undefined) {
|
39424 | context.newParent = ordering.parent;
|
39425 | }
|
39426 |
|
39427 | context.newParentIndex = ordering.index;
|
39428 | }
|
39429 | });
|
39430 | }
|
39431 |
|
39432 | |
39433 |
|
39434 |
|
39435 |
|
39436 |
|
39437 |
|
39438 |
|
39439 |
|
39440 |
|
39441 |
|
39442 |
|
39443 |
|
39444 | OrderingProvider.prototype.getOrdering = function(element, newParent) {
|
39445 | return null;
|
39446 | };
|
39447 |
|
39448 | inherits_browser(OrderingProvider, CommandInterceptor);
|
39449 |
|
39450 | |
39451 |
|
39452 |
|
39453 |
|
39454 |
|
39455 |
|
39456 | function BpmnOrderingProvider(eventBus, canvas, translate) {
|
39457 |
|
39458 | OrderingProvider.call(this, eventBus);
|
39459 |
|
39460 | var orders = [
|
39461 | { type: 'bpmn:SubProcess', order: { level: 6 } },
|
39462 | {
|
39463 | type: 'bpmn:SequenceFlow',
|
39464 | order: {
|
39465 | level: 3,
|
39466 | containers: [
|
39467 | 'bpmn:Participant',
|
39468 | 'bpmn:FlowElementsContainer'
|
39469 | ]
|
39470 | }
|
39471 | },
|
39472 |
|
39473 | {
|
39474 | type: 'bpmn:DataAssociation',
|
39475 | order: {
|
39476 | level: 9,
|
39477 | containers: [
|
39478 | 'bpmn:Collaboration',
|
39479 | 'bpmn:Process'
|
39480 | ]
|
39481 | }
|
39482 | },
|
39483 | {
|
39484 | type: 'bpmn:MessageFlow', order: {
|
39485 | level: 9,
|
39486 | containers: [ 'bpmn:Collaboration' ]
|
39487 | }
|
39488 | },
|
39489 | {
|
39490 | type: 'bpmn:Association',
|
39491 | order: {
|
39492 | level: 6,
|
39493 | containers: [
|
39494 | 'bpmn:Participant',
|
39495 | 'bpmn:FlowElementsContainer',
|
39496 | 'bpmn:Collaboration'
|
39497 | ]
|
39498 | }
|
39499 | },
|
39500 | { type: 'bpmn:BoundaryEvent', order: { level: 8 } },
|
39501 | { type: 'bpmn:FlowElement', order: { level: 5 } },
|
39502 | { type: 'bpmn:Participant', order: { level: -2 } },
|
39503 | { type: 'bpmn:Lane', order: { level: -1 } }
|
39504 | ];
|
39505 |
|
39506 | function computeOrder(element) {
|
39507 | if (element.labelTarget) {
|
39508 | return { level: 10 };
|
39509 | }
|
39510 |
|
39511 | var entry = find(orders, function(o) {
|
39512 | return isAny(element, [ o.type ]);
|
39513 | });
|
39514 |
|
39515 | return entry && entry.order || { level: 1 };
|
39516 | }
|
39517 |
|
39518 | function getOrder(element) {
|
39519 |
|
39520 | var order = element.order;
|
39521 |
|
39522 | if (!order) {
|
39523 | element.order = order = computeOrder(element);
|
39524 | }
|
39525 |
|
39526 | return order;
|
39527 | }
|
39528 |
|
39529 | function findActualParent(element, newParent, containers) {
|
39530 |
|
39531 | var actualParent = newParent;
|
39532 |
|
39533 | while (actualParent) {
|
39534 |
|
39535 | if (isAny(actualParent, containers)) {
|
39536 | break;
|
39537 | }
|
39538 |
|
39539 | actualParent = actualParent.parent;
|
39540 | }
|
39541 |
|
39542 | if (!actualParent) {
|
39543 | throw new Error(translate('no parent for {element} in {parent}', {
|
39544 | element: element.id,
|
39545 | parent: newParent.id
|
39546 | }));
|
39547 | }
|
39548 |
|
39549 | return actualParent;
|
39550 | }
|
39551 |
|
39552 | this.getOrdering = function(element, newParent) {
|
39553 |
|
39554 |
|
39555 | if (element.labelTarget) {
|
39556 | return {
|
39557 | parent: canvas.getRootElement(),
|
39558 | index: -1
|
39559 | };
|
39560 | }
|
39561 |
|
39562 | var elementOrder = getOrder(element);
|
39563 |
|
39564 |
|
39565 | if (elementOrder.containers) {
|
39566 | newParent = findActualParent(element, newParent, elementOrder.containers);
|
39567 | }
|
39568 |
|
39569 |
|
39570 | var currentIndex = newParent.children.indexOf(element);
|
39571 |
|
39572 | var insertIndex = findIndex(newParent.children, function(child) {
|
39573 |
|
39574 |
|
39575 |
|
39576 |
|
39577 | if (!element.labelTarget && child.labelTarget) {
|
39578 | return false;
|
39579 | }
|
39580 |
|
39581 | return elementOrder.level < getOrder(child).level;
|
39582 | });
|
39583 |
|
39584 |
|
39585 |
|
39586 |
|
39587 |
|
39588 |
|
39589 | if (insertIndex !== -1) {
|
39590 | if (currentIndex !== -1 && currentIndex < insertIndex) {
|
39591 | insertIndex -= 1;
|
39592 | }
|
39593 | }
|
39594 |
|
39595 | return {
|
39596 | index: insertIndex,
|
39597 | parent: newParent
|
39598 | };
|
39599 | };
|
39600 | }
|
39601 |
|
39602 | BpmnOrderingProvider.$inject = [ 'eventBus', 'canvas', 'translate' ];
|
39603 |
|
39604 | inherits_browser(BpmnOrderingProvider, OrderingProvider);
|
39605 |
|
39606 | var OrderingModule = {
|
39607 | __depends__: [
|
39608 | translate$2
|
39609 | ],
|
39610 | __init__: [ 'bpmnOrderingProvider' ],
|
39611 | bpmnOrderingProvider: [ 'type', BpmnOrderingProvider ]
|
39612 | };
|
39613 |
|
39614 | |
39615 |
|
39616 |
|
39617 |
|
39618 |
|
39619 |
|
39620 |
|
39621 |
|
39622 |
|
39623 |
|
39624 |
|
39625 |
|
39626 |
|
39627 |
|
39628 |
|
39629 |
|
39630 |
|
39631 |
|
39632 |
|
39633 |
|
39634 |
|
39635 |
|
39636 |
|
39637 |
|
39638 |
|
39639 |
|
39640 |
|
39641 |
|
39642 |
|
39643 |
|
39644 |
|
39645 |
|
39646 |
|
39647 |
|
39648 |
|
39649 |
|
39650 |
|
39651 |
|
39652 |
|
39653 |
|
39654 |
|
39655 |
|
39656 |
|
39657 |
|
39658 |
|
39659 |
|
39660 |
|
39661 |
|
39662 |
|
39663 |
|
39664 |
|
39665 |
|
39666 |
|
39667 |
|
39668 |
|
39669 |
|
39670 |
|
39671 |
|
39672 |
|
39673 |
|
39674 |
|
39675 |
|
39676 |
|
39677 |
|
39678 |
|
39679 |
|
39680 |
|
39681 |
|
39682 |
|
39683 |
|
39684 |
|
39685 |
|
39686 |
|
39687 |
|
39688 |
|
39689 |
|
39690 | function CommandStack(eventBus, injector) {
|
39691 |
|
39692 | |
39693 |
|
39694 |
|
39695 |
|
39696 |
|
39697 | this._handlerMap = {};
|
39698 |
|
39699 | |
39700 |
|
39701 |
|
39702 |
|
39703 |
|
39704 | this._stack = [];
|
39705 |
|
39706 | |
39707 |
|
39708 |
|
39709 |
|
39710 |
|
39711 | this._stackIdx = -1;
|
39712 |
|
39713 | |
39714 |
|
39715 |
|
39716 |
|
39717 |
|
39718 | this._currentExecution = {
|
39719 | actions: [],
|
39720 | dirty: []
|
39721 | };
|
39722 |
|
39723 |
|
39724 | this._injector = injector;
|
39725 | this._eventBus = eventBus;
|
39726 |
|
39727 | this._uid = 1;
|
39728 |
|
39729 | eventBus.on([
|
39730 | 'diagram.destroy',
|
39731 | 'diagram.clear'
|
39732 | ], function() {
|
39733 | this.clear(false);
|
39734 | }, this);
|
39735 | }
|
39736 |
|
39737 | CommandStack.$inject = [ 'eventBus', 'injector' ];
|
39738 |
|
39739 |
|
39740 | |
39741 |
|
39742 |
|
39743 |
|
39744 |
|
39745 |
|
39746 | CommandStack.prototype.execute = function(command, context) {
|
39747 | if (!command) {
|
39748 | throw new Error('command required');
|
39749 | }
|
39750 |
|
39751 | var action = { command: command, context: context };
|
39752 |
|
39753 | this._pushAction(action);
|
39754 | this._internalExecute(action);
|
39755 | this._popAction(action);
|
39756 | };
|
39757 |
|
39758 |
|
39759 | |
39760 |
|
39761 |
|
39762 |
|
39763 |
|
39764 |
|
39765 |
|
39766 |
|
39767 |
|
39768 |
|
39769 |
|
39770 |
|
39771 |
|
39772 |
|
39773 |
|
39774 |
|
39775 |
|
39776 |
|
39777 |
|
39778 |
|
39779 | CommandStack.prototype.canExecute = function(command, context) {
|
39780 |
|
39781 | var action = { command: command, context: context };
|
39782 |
|
39783 | var handler = this._getHandler(command);
|
39784 |
|
39785 | var result = this._fire(command, 'canExecute', action);
|
39786 |
|
39787 |
|
39788 |
|
39789 | if (result === undefined) {
|
39790 | if (!handler) {
|
39791 | return false;
|
39792 | }
|
39793 |
|
39794 | if (handler.canExecute) {
|
39795 | result = handler.canExecute(context);
|
39796 | }
|
39797 | }
|
39798 |
|
39799 | return result;
|
39800 | };
|
39801 |
|
39802 |
|
39803 | |
39804 |
|
39805 |
|
39806 | CommandStack.prototype.clear = function(emit) {
|
39807 | this._stack.length = 0;
|
39808 | this._stackIdx = -1;
|
39809 |
|
39810 | if (emit !== false) {
|
39811 | this._fire('changed');
|
39812 | }
|
39813 | };
|
39814 |
|
39815 |
|
39816 | |
39817 |
|
39818 |
|
39819 | CommandStack.prototype.undo = function() {
|
39820 | var action = this._getUndoAction(),
|
39821 | next;
|
39822 |
|
39823 | if (action) {
|
39824 | this._pushAction(action);
|
39825 |
|
39826 | while (action) {
|
39827 | this._internalUndo(action);
|
39828 | next = this._getUndoAction();
|
39829 |
|
39830 | if (!next || next.id !== action.id) {
|
39831 | break;
|
39832 | }
|
39833 |
|
39834 | action = next;
|
39835 | }
|
39836 |
|
39837 | this._popAction();
|
39838 | }
|
39839 | };
|
39840 |
|
39841 |
|
39842 | |
39843 |
|
39844 |
|
39845 | CommandStack.prototype.redo = function() {
|
39846 | var action = this._getRedoAction(),
|
39847 | next;
|
39848 |
|
39849 | if (action) {
|
39850 | this._pushAction(action);
|
39851 |
|
39852 | while (action) {
|
39853 | this._internalExecute(action, true);
|
39854 | next = this._getRedoAction();
|
39855 |
|
39856 | if (!next || next.id !== action.id) {
|
39857 | break;
|
39858 | }
|
39859 |
|
39860 | action = next;
|
39861 | }
|
39862 |
|
39863 | this._popAction();
|
39864 | }
|
39865 | };
|
39866 |
|
39867 |
|
39868 | |
39869 |
|
39870 |
|
39871 |
|
39872 |
|
39873 |
|
39874 | CommandStack.prototype.register = function(command, handler) {
|
39875 | this._setHandler(command, handler);
|
39876 | };
|
39877 |
|
39878 |
|
39879 | |
39880 |
|
39881 |
|
39882 |
|
39883 |
|
39884 |
|
39885 |
|
39886 | CommandStack.prototype.registerHandler = function(command, handlerCls) {
|
39887 |
|
39888 | if (!command || !handlerCls) {
|
39889 | throw new Error('command and handlerCls must be defined');
|
39890 | }
|
39891 |
|
39892 | var handler = this._injector.instantiate(handlerCls);
|
39893 | this.register(command, handler);
|
39894 | };
|
39895 |
|
39896 | CommandStack.prototype.canUndo = function() {
|
39897 | return !!this._getUndoAction();
|
39898 | };
|
39899 |
|
39900 | CommandStack.prototype.canRedo = function() {
|
39901 | return !!this._getRedoAction();
|
39902 | };
|
39903 |
|
39904 |
|
39905 |
|
39906 | CommandStack.prototype._getRedoAction = function() {
|
39907 | return this._stack[this._stackIdx + 1];
|
39908 | };
|
39909 |
|
39910 |
|
39911 | CommandStack.prototype._getUndoAction = function() {
|
39912 | return this._stack[this._stackIdx];
|
39913 | };
|
39914 |
|
39915 |
|
39916 |
|
39917 |
|
39918 | CommandStack.prototype._internalUndo = function(action) {
|
39919 | var self = this;
|
39920 |
|
39921 | var command = action.command,
|
39922 | context = action.context;
|
39923 |
|
39924 | var handler = this._getHandler(command);
|
39925 |
|
39926 |
|
39927 | this._atomicDo(function() {
|
39928 | self._fire(command, 'revert', action);
|
39929 |
|
39930 | if (handler.revert) {
|
39931 | self._markDirty(handler.revert(context));
|
39932 | }
|
39933 |
|
39934 | self._revertedAction(action);
|
39935 |
|
39936 | self._fire(command, 'reverted', action);
|
39937 | });
|
39938 | };
|
39939 |
|
39940 |
|
39941 | CommandStack.prototype._fire = function(command, qualifier, event) {
|
39942 | if (arguments.length < 3) {
|
39943 | event = qualifier;
|
39944 | qualifier = null;
|
39945 | }
|
39946 |
|
39947 | var names = qualifier ? [ command + '.' + qualifier, qualifier ] : [ command ],
|
39948 | i, name, result;
|
39949 |
|
39950 | event = this._eventBus.createEvent(event);
|
39951 |
|
39952 | for (i = 0; (name = names[i]); i++) {
|
39953 | result = this._eventBus.fire('commandStack.' + name, event);
|
39954 |
|
39955 | if (event.cancelBubble) {
|
39956 | break;
|
39957 | }
|
39958 | }
|
39959 |
|
39960 | return result;
|
39961 | };
|
39962 |
|
39963 | CommandStack.prototype._createId = function() {
|
39964 | return this._uid++;
|
39965 | };
|
39966 |
|
39967 | CommandStack.prototype._atomicDo = function(fn) {
|
39968 |
|
39969 | var execution = this._currentExecution;
|
39970 |
|
39971 | execution.atomic = true;
|
39972 |
|
39973 | try {
|
39974 | fn();
|
39975 | } finally {
|
39976 | execution.atomic = false;
|
39977 | }
|
39978 | };
|
39979 |
|
39980 | CommandStack.prototype._internalExecute = function(action, redo) {
|
39981 | var self = this;
|
39982 |
|
39983 | var command = action.command,
|
39984 | context = action.context;
|
39985 |
|
39986 | var handler = this._getHandler(command);
|
39987 |
|
39988 | if (!handler) {
|
39989 | throw new Error('no command handler registered for <' + command + '>');
|
39990 | }
|
39991 |
|
39992 | this._pushAction(action);
|
39993 |
|
39994 | if (!redo) {
|
39995 | this._fire(command, 'preExecute', action);
|
39996 |
|
39997 | if (handler.preExecute) {
|
39998 | handler.preExecute(context);
|
39999 | }
|
40000 |
|
40001 | this._fire(command, 'preExecuted', action);
|
40002 | }
|
40003 |
|
40004 |
|
40005 | this._atomicDo(function() {
|
40006 |
|
40007 | self._fire(command, 'execute', action);
|
40008 |
|
40009 | if (handler.execute) {
|
40010 |
|
40011 | self._markDirty(handler.execute(context));
|
40012 | }
|
40013 |
|
40014 |
|
40015 | self._executedAction(action, redo);
|
40016 |
|
40017 | self._fire(command, 'executed', action);
|
40018 | });
|
40019 |
|
40020 | if (!redo) {
|
40021 | this._fire(command, 'postExecute', action);
|
40022 |
|
40023 | if (handler.postExecute) {
|
40024 | handler.postExecute(context);
|
40025 | }
|
40026 |
|
40027 | this._fire(command, 'postExecuted', action);
|
40028 | }
|
40029 |
|
40030 | this._popAction(action);
|
40031 | };
|
40032 |
|
40033 |
|
40034 | CommandStack.prototype._pushAction = function(action) {
|
40035 |
|
40036 | var execution = this._currentExecution,
|
40037 | actions = execution.actions;
|
40038 |
|
40039 | var baseAction = actions[0];
|
40040 |
|
40041 | if (execution.atomic) {
|
40042 | throw new Error('illegal invocation in <execute> or <revert> phase (action: ' + action.command + ')');
|
40043 | }
|
40044 |
|
40045 | if (!action.id) {
|
40046 | action.id = (baseAction && baseAction.id) || this._createId();
|
40047 | }
|
40048 |
|
40049 | actions.push(action);
|
40050 | };
|
40051 |
|
40052 |
|
40053 | CommandStack.prototype._popAction = function() {
|
40054 | var execution = this._currentExecution,
|
40055 | actions = execution.actions,
|
40056 | dirty = execution.dirty;
|
40057 |
|
40058 | actions.pop();
|
40059 |
|
40060 | if (!actions.length) {
|
40061 | this._eventBus.fire('elements.changed', { elements: uniqueBy('id', dirty) });
|
40062 |
|
40063 | dirty.length = 0;
|
40064 |
|
40065 | this._fire('changed');
|
40066 | }
|
40067 | };
|
40068 |
|
40069 |
|
40070 | CommandStack.prototype._markDirty = function(elements) {
|
40071 | var execution = this._currentExecution;
|
40072 |
|
40073 | if (!elements) {
|
40074 | return;
|
40075 | }
|
40076 |
|
40077 | elements = isArray(elements) ? elements : [ elements ];
|
40078 |
|
40079 | execution.dirty = execution.dirty.concat(elements);
|
40080 | };
|
40081 |
|
40082 |
|
40083 | CommandStack.prototype._executedAction = function(action, redo) {
|
40084 | var stackIdx = ++this._stackIdx;
|
40085 |
|
40086 | if (!redo) {
|
40087 | this._stack.splice(stackIdx, this._stack.length, action);
|
40088 | }
|
40089 | };
|
40090 |
|
40091 |
|
40092 | CommandStack.prototype._revertedAction = function(action) {
|
40093 | this._stackIdx--;
|
40094 | };
|
40095 |
|
40096 |
|
40097 | CommandStack.prototype._getHandler = function(command) {
|
40098 | return this._handlerMap[command];
|
40099 | };
|
40100 |
|
40101 | CommandStack.prototype._setHandler = function(command, handler) {
|
40102 | if (!command || !handler) {
|
40103 | throw new Error('command and handler required');
|
40104 | }
|
40105 |
|
40106 | if (this._handlerMap[command]) {
|
40107 | throw new Error('overriding handler for command <' + command + '>');
|
40108 | }
|
40109 |
|
40110 | this._handlerMap[command] = handler;
|
40111 | };
|
40112 |
|
40113 | var CommandModule = {
|
40114 | commandStack: [ 'type', CommandStack ]
|
40115 | };
|
40116 |
|
40117 |
|
40118 | var ids$2 = new IdGenerator('tt');
|
40119 |
|
40120 |
|
40121 | function createRoot$1(parent) {
|
40122 | var root = domify('<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />');
|
40123 | parent.insertBefore(root, parent.firstChild);
|
40124 |
|
40125 | return root;
|
40126 | }
|
40127 |
|
40128 |
|
40129 | function setPosition$1(el, x, y) {
|
40130 | assign(el.style, { left: x + 'px', top: y + 'px' });
|
40131 | }
|
40132 |
|
40133 | function setVisible$1(el, visible) {
|
40134 | el.style.display = visible === false ? 'none' : '';
|
40135 | }
|
40136 |
|
40137 |
|
40138 | var tooltipClass = 'djs-tooltip',
|
40139 | tooltipSelector = '.' + tooltipClass;
|
40140 |
|
40141 | |
40142 |
|
40143 |
|
40144 |
|
40145 |
|
40146 |
|
40147 |
|
40148 |
|
40149 |
|
40150 |
|
40151 |
|
40152 |
|
40153 |
|
40154 |
|
40155 |
|
40156 |
|
40157 |
|
40158 |
|
40159 |
|
40160 |
|
40161 |
|
40162 |
|
40163 |
|
40164 |
|
40165 |
|
40166 |
|
40167 |
|
40168 |
|
40169 |
|
40170 |
|
40171 |
|
40172 |
|
40173 |
|
40174 |
|
40175 |
|
40176 |
|
40177 |
|
40178 | function Tooltips(eventBus, canvas) {
|
40179 |
|
40180 | this._eventBus = eventBus;
|
40181 | this._canvas = canvas;
|
40182 |
|
40183 | this._ids = ids$2;
|
40184 |
|
40185 | this._tooltipDefaults = {
|
40186 | show: {
|
40187 | minZoom: 0.7,
|
40188 | maxZoom: 5.0
|
40189 | }
|
40190 | };
|
40191 |
|
40192 | |
40193 |
|
40194 |
|
40195 | this._tooltips = {};
|
40196 |
|
40197 |
|
40198 | this._tooltipRoot = createRoot$1(canvas.getContainer());
|
40199 |
|
40200 |
|
40201 | var self = this;
|
40202 |
|
40203 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mousedown', function(event) {
|
40204 | event.stopPropagation();
|
40205 | });
|
40206 |
|
40207 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseover', function(event) {
|
40208 | self.trigger('mouseover', event);
|
40209 | });
|
40210 |
|
40211 | delegateEvents.bind(this._tooltipRoot, tooltipSelector, 'mouseout', function(event) {
|
40212 | self.trigger('mouseout', event);
|
40213 | });
|
40214 |
|
40215 | this._init();
|
40216 | }
|
40217 |
|
40218 |
|
40219 | Tooltips.$inject = [ 'eventBus', 'canvas' ];
|
40220 |
|
40221 |
|
40222 | |
40223 |
|
40224 |
|
40225 |
|
40226 |
|
40227 |
|
40228 |
|
40229 |
|
40230 |
|
40231 |
|
40232 |
|
40233 |
|
40234 |
|
40235 |
|
40236 |
|
40237 |
|
40238 |
|
40239 |
|
40240 | Tooltips.prototype.add = function(tooltip) {
|
40241 |
|
40242 | if (!tooltip.position) {
|
40243 | throw new Error('must specifiy tooltip position');
|
40244 | }
|
40245 |
|
40246 | if (!tooltip.html) {
|
40247 | throw new Error('must specifiy tooltip html');
|
40248 | }
|
40249 |
|
40250 | var id = this._ids.next();
|
40251 |
|
40252 | tooltip = assign({}, this._tooltipDefaults, tooltip, {
|
40253 | id: id
|
40254 | });
|
40255 |
|
40256 | this._addTooltip(tooltip);
|
40257 |
|
40258 | if (tooltip.timeout) {
|
40259 | this.setTimeout(tooltip);
|
40260 | }
|
40261 |
|
40262 | return id;
|
40263 | };
|
40264 |
|
40265 | Tooltips.prototype.trigger = function(action, event) {
|
40266 |
|
40267 | var node = event.delegateTarget || event.target;
|
40268 |
|
40269 | var tooltip = this.get(attr(node, 'data-tooltip-id'));
|
40270 |
|
40271 | if (!tooltip) {
|
40272 | return;
|
40273 | }
|
40274 |
|
40275 | if (action === 'mouseover' && tooltip.timeout) {
|
40276 | this.clearTimeout(tooltip);
|
40277 | }
|
40278 |
|
40279 | if (action === 'mouseout' && tooltip.timeout) {
|
40280 |
|
40281 | tooltip.timeout = 1000;
|
40282 |
|
40283 | this.setTimeout(tooltip);
|
40284 | }
|
40285 | };
|
40286 |
|
40287 | |
40288 |
|
40289 |
|
40290 |
|
40291 |
|
40292 | Tooltips.prototype.get = function(id) {
|
40293 |
|
40294 | if (typeof id !== 'string') {
|
40295 | id = id.id;
|
40296 | }
|
40297 |
|
40298 | return this._tooltips[id];
|
40299 | };
|
40300 |
|
40301 | Tooltips.prototype.clearTimeout = function(tooltip) {
|
40302 |
|
40303 | tooltip = this.get(tooltip);
|
40304 |
|
40305 | if (!tooltip) {
|
40306 | return;
|
40307 | }
|
40308 |
|
40309 | var removeTimer = tooltip.removeTimer;
|
40310 |
|
40311 | if (removeTimer) {
|
40312 | clearTimeout(removeTimer);
|
40313 | tooltip.removeTimer = null;
|
40314 | }
|
40315 | };
|
40316 |
|
40317 | Tooltips.prototype.setTimeout = function(tooltip) {
|
40318 |
|
40319 | tooltip = this.get(tooltip);
|
40320 |
|
40321 | if (!tooltip) {
|
40322 | return;
|
40323 | }
|
40324 |
|
40325 | this.clearTimeout(tooltip);
|
40326 |
|
40327 | var self = this;
|
40328 |
|
40329 | tooltip.removeTimer = setTimeout(function() {
|
40330 | self.remove(tooltip);
|
40331 | }, tooltip.timeout);
|
40332 | };
|
40333 |
|
40334 | |
40335 |
|
40336 |
|
40337 |
|
40338 |
|
40339 | Tooltips.prototype.remove = function(id) {
|
40340 |
|
40341 | var tooltip = this.get(id);
|
40342 |
|
40343 | if (tooltip) {
|
40344 | remove(tooltip.html);
|
40345 | remove(tooltip.htmlContainer);
|
40346 |
|
40347 | delete tooltip.htmlContainer;
|
40348 |
|
40349 | delete this._tooltips[tooltip.id];
|
40350 | }
|
40351 | };
|
40352 |
|
40353 |
|
40354 | Tooltips.prototype.show = function() {
|
40355 | setVisible$1(this._tooltipRoot);
|
40356 | };
|
40357 |
|
40358 |
|
40359 | Tooltips.prototype.hide = function() {
|
40360 | setVisible$1(this._tooltipRoot, false);
|
40361 | };
|
40362 |
|
40363 |
|
40364 | Tooltips.prototype._updateRoot = function(viewbox) {
|
40365 | var a = viewbox.scale || 1;
|
40366 | var d = viewbox.scale || 1;
|
40367 |
|
40368 | var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')';
|
40369 |
|
40370 | this._tooltipRoot.style.transform = matrix;
|
40371 | this._tooltipRoot.style['-ms-transform'] = matrix;
|
40372 | };
|
40373 |
|
40374 |
|
40375 | Tooltips.prototype._addTooltip = function(tooltip) {
|
40376 |
|
40377 | var id = tooltip.id,
|
40378 | html = tooltip.html,
|
40379 | htmlContainer,
|
40380 | tooltipRoot = this._tooltipRoot;
|
40381 |
|
40382 |
|
40383 | if (html.get && html.constructor.prototype.jquery) {
|
40384 | html = html.get(0);
|
40385 | }
|
40386 |
|
40387 |
|
40388 |
|
40389 | if (isString(html)) {
|
40390 | html = domify(html);
|
40391 | }
|
40392 |
|
40393 | htmlContainer = domify('<div data-tooltip-id="' + id + '" class="' + tooltipClass + '" style="position: absolute">');
|
40394 |
|
40395 | htmlContainer.appendChild(html);
|
40396 |
|
40397 | if (tooltip.type) {
|
40398 | classes(htmlContainer).add('djs-tooltip-' + tooltip.type);
|
40399 | }
|
40400 |
|
40401 | if (tooltip.className) {
|
40402 | classes(htmlContainer).add(tooltip.className);
|
40403 | }
|
40404 |
|
40405 | tooltip.htmlContainer = htmlContainer;
|
40406 |
|
40407 | tooltipRoot.appendChild(htmlContainer);
|
40408 |
|
40409 | this._tooltips[id] = tooltip;
|
40410 |
|
40411 | this._updateTooltip(tooltip);
|
40412 | };
|
40413 |
|
40414 |
|
40415 | Tooltips.prototype._updateTooltip = function(tooltip) {
|
40416 |
|
40417 | var position = tooltip.position,
|
40418 | htmlContainer = tooltip.htmlContainer;
|
40419 |
|
40420 |
|
40421 |
|
40422 | setPosition$1(htmlContainer, position.x, position.y);
|
40423 | };
|
40424 |
|
40425 |
|
40426 | Tooltips.prototype._updateTooltipVisibilty = function(viewbox) {
|
40427 |
|
40428 | forEach(this._tooltips, function(tooltip) {
|
40429 | var show = tooltip.show,
|
40430 | htmlContainer = tooltip.htmlContainer,
|
40431 | visible = true;
|
40432 |
|
40433 | if (show) {
|
40434 | if (show.minZoom > viewbox.scale ||
|
40435 | show.maxZoom < viewbox.scale) {
|
40436 | visible = false;
|
40437 | }
|
40438 |
|
40439 | setVisible$1(htmlContainer, visible);
|
40440 | }
|
40441 | });
|
40442 | };
|
40443 |
|
40444 | Tooltips.prototype._init = function() {
|
40445 |
|
40446 | var self = this;
|
40447 |
|
40448 |
|
40449 |
|
40450 | function updateViewbox(viewbox) {
|
40451 | self._updateRoot(viewbox);
|
40452 | self._updateTooltipVisibilty(viewbox);
|
40453 |
|
40454 | self.show();
|
40455 | }
|
40456 |
|
40457 | this._eventBus.on('canvas.viewbox.changing', function(event) {
|
40458 | self.hide();
|
40459 | });
|
40460 |
|
40461 | this._eventBus.on('canvas.viewbox.changed', function(event) {
|
40462 | updateViewbox(event.viewbox);
|
40463 | });
|
40464 | };
|
40465 |
|
40466 | var TooltipsModule = {
|
40467 | __init__: [ 'tooltips' ],
|
40468 | tooltips: [ 'type', Tooltips ]
|
40469 | };
|
40470 |
|
40471 | |
40472 |
|
40473 |
|
40474 |
|
40475 |
|
40476 |
|
40477 |
|
40478 |
|
40479 |
|
40480 |
|
40481 |
|
40482 |
|
40483 |
|
40484 |
|
40485 |
|
40486 |
|
40487 | function saveClear(collection, removeFn) {
|
40488 |
|
40489 | if (typeof removeFn !== 'function') {
|
40490 | throw new Error('removeFn iterator must be a function');
|
40491 | }
|
40492 |
|
40493 | if (!collection) {
|
40494 | return;
|
40495 | }
|
40496 |
|
40497 | var e;
|
40498 |
|
40499 | while ((e = collection[0])) {
|
40500 | removeFn(e);
|
40501 | }
|
40502 |
|
40503 | return collection;
|
40504 | }
|
40505 |
|
40506 | var LOW_PRIORITY$9 = 250,
|
40507 | HIGH_PRIORITY$1 = 1400;
|
40508 |
|
40509 |
|
40510 | |
40511 |
|
40512 |
|
40513 |
|
40514 |
|
40515 |
|
40516 |
|
40517 |
|
40518 | function LabelSupport(injector, eventBus, modeling) {
|
40519 |
|
40520 | CommandInterceptor.call(this, eventBus);
|
40521 |
|
40522 | var movePreview = injector.get('movePreview', false);
|
40523 |
|
40524 |
|
40525 |
|
40526 | eventBus.on('shape.move.start', HIGH_PRIORITY$1, function(e) {
|
40527 |
|
40528 | var context = e.context,
|
40529 | shapes = context.shapes,
|
40530 | validatedShapes = context.validatedShapes;
|
40531 |
|
40532 | context.shapes = removeLabels(shapes);
|
40533 | context.validatedShapes = removeLabels(validatedShapes);
|
40534 | });
|
40535 |
|
40536 |
|
40537 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$9, function(e) {
|
40538 |
|
40539 | var context = e.context,
|
40540 | shapes = context.shapes;
|
40541 |
|
40542 | var labels = [];
|
40543 |
|
40544 | forEach(shapes, function(element) {
|
40545 |
|
40546 | forEach(element.labels, function(label) {
|
40547 |
|
40548 | if (!label.hidden && context.shapes.indexOf(label) === -1) {
|
40549 | labels.push(label);
|
40550 | }
|
40551 |
|
40552 | if (element.labelTarget) {
|
40553 | labels.push(element);
|
40554 | }
|
40555 | });
|
40556 | });
|
40557 |
|
40558 | forEach(labels, function(label) {
|
40559 | movePreview.makeDraggable(context, label, true);
|
40560 | });
|
40561 |
|
40562 | });
|
40563 |
|
40564 |
|
40565 | this.preExecuted('elements.move', HIGH_PRIORITY$1, function(e) {
|
40566 | var context = e.context,
|
40567 | closure = context.closure,
|
40568 | enclosedElements = closure.enclosedElements;
|
40569 |
|
40570 | var enclosedLabels = [];
|
40571 |
|
40572 |
|
40573 |
|
40574 | forEach(enclosedElements, function(element) {
|
40575 | forEach(element.labels, function(label) {
|
40576 |
|
40577 | if (!enclosedElements[label.id]) {
|
40578 | enclosedLabels.push(label);
|
40579 | }
|
40580 | });
|
40581 | });
|
40582 |
|
40583 | closure.addAll(enclosedLabels);
|
40584 | });
|
40585 |
|
40586 |
|
40587 | this.preExecute([
|
40588 | 'connection.delete',
|
40589 | 'shape.delete'
|
40590 | ], function(e) {
|
40591 |
|
40592 | var context = e.context,
|
40593 | element = context.connection || context.shape;
|
40594 |
|
40595 | saveClear(element.labels, function(label) {
|
40596 | modeling.removeShape(label, { nested: true });
|
40597 | });
|
40598 | });
|
40599 |
|
40600 |
|
40601 | this.execute('shape.delete', function(e) {
|
40602 |
|
40603 | var context = e.context,
|
40604 | shape = context.shape,
|
40605 | labelTarget = shape.labelTarget;
|
40606 |
|
40607 |
|
40608 | if (labelTarget) {
|
40609 | context.labelTargetIndex = indexOf$1(labelTarget.labels, shape);
|
40610 | context.labelTarget = labelTarget;
|
40611 |
|
40612 | shape.labelTarget = null;
|
40613 | }
|
40614 | });
|
40615 |
|
40616 | this.revert('shape.delete', function(e) {
|
40617 |
|
40618 | var context = e.context,
|
40619 | shape = context.shape,
|
40620 | labelTarget = context.labelTarget,
|
40621 | labelTargetIndex = context.labelTargetIndex;
|
40622 |
|
40623 |
|
40624 | if (labelTarget) {
|
40625 | add(labelTarget.labels, shape, labelTargetIndex);
|
40626 |
|
40627 | shape.labelTarget = labelTarget;
|
40628 | }
|
40629 | });
|
40630 |
|
40631 | }
|
40632 |
|
40633 | inherits_browser(LabelSupport, CommandInterceptor);
|
40634 |
|
40635 | LabelSupport.$inject = [
|
40636 | 'injector',
|
40637 | 'eventBus',
|
40638 | 'modeling'
|
40639 | ];
|
40640 |
|
40641 |
|
40642 | |
40643 |
|
40644 |
|
40645 |
|
40646 |
|
40647 |
|
40648 |
|
40649 |
|
40650 |
|
40651 | function removeLabels(elements) {
|
40652 |
|
40653 | return filter(elements, function(element) {
|
40654 |
|
40655 |
|
40656 |
|
40657 | return elements.indexOf(element.labelTarget) === -1;
|
40658 | });
|
40659 | }
|
40660 |
|
40661 | var LabelSupportModule = {
|
40662 | __init__: [ 'labelSupport'],
|
40663 | labelSupport: [ 'type', LabelSupport ]
|
40664 | };
|
40665 |
|
40666 | |
40667 |
|
40668 |
|
40669 |
|
40670 |
|
40671 |
|
40672 |
|
40673 |
|
40674 |
|
40675 | function getNewAttachPoint(point, oldBounds, newBounds) {
|
40676 | var oldCenter = center(oldBounds),
|
40677 | newCenter = center(newBounds),
|
40678 | oldDelta = delta(point, oldCenter);
|
40679 |
|
40680 | var newDelta = {
|
40681 | x: oldDelta.x * (newBounds.width / oldBounds.width),
|
40682 | y: oldDelta.y * (newBounds.height / oldBounds.height)
|
40683 | };
|
40684 |
|
40685 | return roundPoint({
|
40686 | x: newCenter.x + newDelta.x,
|
40687 | y: newCenter.y + newDelta.y
|
40688 | });
|
40689 | }
|
40690 |
|
40691 |
|
40692 | |
40693 |
|
40694 |
|
40695 |
|
40696 |
|
40697 |
|
40698 |
|
40699 |
|
40700 |
|
40701 |
|
40702 | function getNewAttachShapeDelta(shape, oldBounds, newBounds) {
|
40703 | var shapeCenter = center(shape),
|
40704 | oldCenter = center(oldBounds),
|
40705 | newCenter = center(newBounds),
|
40706 | shapeDelta = delta(shape, shapeCenter),
|
40707 | oldCenterDelta = delta(shapeCenter, oldCenter);
|
40708 |
|
40709 | var newCenterDelta = {
|
40710 | x: oldCenterDelta.x * (newBounds.width / oldBounds.width),
|
40711 | y: oldCenterDelta.y * (newBounds.height / oldBounds.height)
|
40712 | };
|
40713 |
|
40714 | var newShapeCenter = {
|
40715 | x: newCenter.x + newCenterDelta.x,
|
40716 | y: newCenter.y + newCenterDelta.y
|
40717 | };
|
40718 |
|
40719 | return roundPoint({
|
40720 | x: newShapeCenter.x + shapeDelta.x - shape.x,
|
40721 | y: newShapeCenter.y + shapeDelta.y - shape.y
|
40722 | });
|
40723 | }
|
40724 |
|
40725 | var LOW_PRIORITY$a = 251,
|
40726 | HIGH_PRIORITY$2 = 1401;
|
40727 |
|
40728 |
|
40729 | |
40730 |
|
40731 |
|
40732 |
|
40733 |
|
40734 |
|
40735 |
|
40736 |
|
40737 |
|
40738 |
|
40739 |
|
40740 |
|
40741 |
|
40742 |
|
40743 | function AttachSupport(injector, eventBus, rules, modeling) {
|
40744 |
|
40745 | CommandInterceptor.call(this, eventBus);
|
40746 |
|
40747 | var movePreview = injector.get('movePreview', false);
|
40748 |
|
40749 |
|
40750 |
|
40751 |
|
40752 | eventBus.on('shape.move.start', HIGH_PRIORITY$2, function(e) {
|
40753 |
|
40754 | var context = e.context,
|
40755 | shapes = context.shapes,
|
40756 | validatedShapes = context.validatedShapes;
|
40757 |
|
40758 | context.shapes = addAttached(shapes);
|
40759 |
|
40760 | context.validatedShapes = removeAttached(validatedShapes);
|
40761 | });
|
40762 |
|
40763 |
|
40764 | movePreview && eventBus.on('shape.move.start', LOW_PRIORITY$a, function(e) {
|
40765 |
|
40766 | var context = e.context,
|
40767 | shapes = context.shapes,
|
40768 | attachers = getAttachers(shapes);
|
40769 |
|
40770 | forEach(attachers, function(attacher) {
|
40771 | movePreview.makeDraggable(context, attacher, true);
|
40772 |
|
40773 | forEach(attacher.labels, function(label) {
|
40774 | movePreview.makeDraggable(context, label, true);
|
40775 | });
|
40776 | });
|
40777 | });
|
40778 |
|
40779 |
|
40780 |
|
40781 | this.preExecuted('elements.move', HIGH_PRIORITY$2, function(e) {
|
40782 | var context = e.context,
|
40783 | closure = context.closure,
|
40784 | shapes = context.shapes,
|
40785 | attachers = getAttachers(shapes);
|
40786 |
|
40787 | forEach(attachers, function(attacher) {
|
40788 | closure.add(attacher, closure.topLevel[attacher.host.id]);
|
40789 | });
|
40790 | });
|
40791 |
|
40792 |
|
40793 | this.postExecuted('elements.move', function(e) {
|
40794 |
|
40795 | var context = e.context,
|
40796 | shapes = context.shapes,
|
40797 | newHost = context.newHost,
|
40798 | attachers;
|
40799 |
|
40800 |
|
40801 | if (shapes.length > 1) {
|
40802 | return;
|
40803 | }
|
40804 |
|
40805 | if (newHost) {
|
40806 |
|
40807 | attachers = shapes;
|
40808 | } else {
|
40809 |
|
40810 | attachers = filter(shapes, function(s) {
|
40811 | return !!s.host;
|
40812 | });
|
40813 | }
|
40814 |
|
40815 | forEach(attachers, function(attacher) {
|
40816 | modeling.updateAttachment(attacher, newHost);
|
40817 | });
|
40818 | });
|
40819 |
|
40820 |
|
40821 | this.postExecuted('elements.move', function(e) {
|
40822 |
|
40823 | var shapes = e.context.shapes;
|
40824 |
|
40825 | forEach(shapes, function(shape) {
|
40826 |
|
40827 | forEach(shape.attachers, function(attacher) {
|
40828 |
|
40829 |
|
40830 | forEach(attacher.outgoing.slice(), function(connection) {
|
40831 | var allowed = rules.allowed('connection.reconnectStart', {
|
40832 | connection: connection,
|
40833 | source: connection.source,
|
40834 | target: connection.target
|
40835 | });
|
40836 |
|
40837 | if (!allowed) {
|
40838 | modeling.removeConnection(connection);
|
40839 | }
|
40840 | });
|
40841 |
|
40842 |
|
40843 | forEach(attacher.incoming.slice(), function(connection) {
|
40844 | var allowed = rules.allowed('connection.reconnectEnd', {
|
40845 | connection: connection,
|
40846 | source: connection.source,
|
40847 | target: connection.target
|
40848 | });
|
40849 |
|
40850 | if (!allowed) {
|
40851 | modeling.removeConnection(connection);
|
40852 | }
|
40853 | });
|
40854 | });
|
40855 | });
|
40856 | });
|
40857 |
|
40858 | this.postExecute('shape.create', function(e) {
|
40859 | var context = e.context,
|
40860 | shape = context.shape,
|
40861 | host = context.host;
|
40862 |
|
40863 | if (host) {
|
40864 | modeling.updateAttachment(shape, host);
|
40865 | }
|
40866 | });
|
40867 |
|
40868 |
|
40869 | this.postExecute('shape.replace', function(e) {
|
40870 |
|
40871 | var context = e.context,
|
40872 | oldShape = context.oldShape,
|
40873 | newShape = context.newShape;
|
40874 |
|
40875 |
|
40876 | saveClear(oldShape.attachers, function(attacher) {
|
40877 | var allowed = rules.allowed('elements.move', {
|
40878 | target: newShape,
|
40879 | shapes: [attacher]
|
40880 | });
|
40881 |
|
40882 | if (allowed === 'attach') {
|
40883 | modeling.updateAttachment(attacher, newShape);
|
40884 | } else {
|
40885 | modeling.removeShape(attacher);
|
40886 | }
|
40887 | });
|
40888 |
|
40889 |
|
40890 | if (newShape.attachers.length) {
|
40891 |
|
40892 | forEach(newShape.attachers, function(attacher) {
|
40893 | var delta = getNewAttachShapeDelta(attacher, oldShape, newShape);
|
40894 | modeling.moveShape(attacher, delta, attacher.parent);
|
40895 | });
|
40896 | }
|
40897 |
|
40898 | });
|
40899 |
|
40900 |
|
40901 | this.postExecute('shape.resize', function(event) {
|
40902 | var context = event.context,
|
40903 | shape = context.shape,
|
40904 | oldBounds = context.oldBounds,
|
40905 | newBounds = context.newBounds,
|
40906 | attachers = shape.attachers;
|
40907 |
|
40908 | forEach(attachers, function(attacher) {
|
40909 | var delta = getNewAttachShapeDelta(attacher, oldBounds, newBounds);
|
40910 |
|
40911 | modeling.moveShape(attacher, delta, attacher.parent);
|
40912 |
|
40913 | forEach(attacher.labels, function(label) {
|
40914 | modeling.moveShape(label, delta, label.parent);
|
40915 | });
|
40916 | });
|
40917 | });
|
40918 |
|
40919 |
|
40920 | this.preExecute('shape.delete', function(event) {
|
40921 |
|
40922 | var shape = event.context.shape;
|
40923 |
|
40924 | saveClear(shape.attachers, function(attacher) {
|
40925 | modeling.removeShape(attacher);
|
40926 | });
|
40927 |
|
40928 | if (shape.host) {
|
40929 | modeling.updateAttachment(shape, null);
|
40930 | }
|
40931 | });
|
40932 |
|
40933 |
|
40934 |
|
40935 |
|
40936 | eventBus.on('spaceTool.move', function(event) {
|
40937 |
|
40938 | var context = event.context,
|
40939 | initialized = context.initialized,
|
40940 | attachSupportInitialized = context.attachSupportInitialized;
|
40941 |
|
40942 | if (!initialized || attachSupportInitialized) {
|
40943 | return;
|
40944 | }
|
40945 |
|
40946 | var movingShapes = context.movingShapes;
|
40947 |
|
40948 |
|
40949 | var staticAttachers = filter(movingShapes, function(shape) {
|
40950 | var host = shape.host;
|
40951 |
|
40952 | return host && movingShapes.indexOf(host) === -1;
|
40953 | });
|
40954 |
|
40955 |
|
40956 | forEach(staticAttachers, function(shape) {
|
40957 | remove$2(movingShapes, shape);
|
40958 |
|
40959 | forEach(shape.labels, function(label) {
|
40960 | remove$2(movingShapes, shape.label);
|
40961 | });
|
40962 | });
|
40963 |
|
40964 | context.attachSupportInitialized = true;
|
40965 | });
|
40966 | }
|
40967 |
|
40968 | inherits_browser(AttachSupport, CommandInterceptor);
|
40969 |
|
40970 | AttachSupport.$inject = [
|
40971 | 'injector',
|
40972 | 'eventBus',
|
40973 | 'rules',
|
40974 | 'modeling'
|
40975 | ];
|
40976 |
|
40977 |
|
40978 | |
40979 |
|
40980 |
|
40981 |
|
40982 |
|
40983 |
|
40984 | function getAttachers(shapes) {
|
40985 | return flatten(map(shapes, function(s) {
|
40986 | return s.attachers || [];
|
40987 | }));
|
40988 | }
|
40989 |
|
40990 | |
40991 |
|
40992 |
|
40993 |
|
40994 |
|
40995 |
|
40996 |
|
40997 | function addAttached(elements) {
|
40998 | var attachers = getAttachers(elements);
|
40999 |
|
41000 | return unionBy('id', elements, attachers);
|
41001 | }
|
41002 |
|
41003 | |
41004 |
|
41005 |
|
41006 |
|
41007 |
|
41008 |
|
41009 |
|
41010 |
|
41011 |
|
41012 | function removeAttached(elements) {
|
41013 |
|
41014 | var ids = groupBy(elements, 'id');
|
41015 |
|
41016 | return filter(elements, function(element) {
|
41017 | while (element) {
|
41018 |
|
41019 |
|
41020 | if (element.host && ids[element.host.id]) {
|
41021 | return false;
|
41022 | }
|
41023 |
|
41024 | element = element.parent;
|
41025 | }
|
41026 |
|
41027 | return true;
|
41028 | });
|
41029 | }
|
41030 |
|
41031 | var AttachSupportModule = {
|
41032 | __depends__: [
|
41033 | RulesModule
|
41034 | ],
|
41035 | __init__: [ 'attachSupport' ],
|
41036 | attachSupport: [ 'type', AttachSupport ]
|
41037 | };
|
41038 |
|
41039 | var LOW_PRIORITY$b = 250;
|
41040 |
|
41041 | |
41042 |
|
41043 |
|
41044 |
|
41045 |
|
41046 |
|
41047 |
|
41048 | function ToolManager(eventBus, dragging) {
|
41049 | this._eventBus = eventBus;
|
41050 | this._dragging = dragging;
|
41051 |
|
41052 | this._tools = [];
|
41053 | this._active = null;
|
41054 | }
|
41055 |
|
41056 | ToolManager.$inject = [ 'eventBus', 'dragging' ];
|
41057 |
|
41058 | ToolManager.prototype.registerTool = function(name, events) {
|
41059 | var tools = this._tools;
|
41060 |
|
41061 | if (!events) {
|
41062 | throw new Error('A tool has to be registered with it\'s "events"');
|
41063 | }
|
41064 |
|
41065 | tools.push(name);
|
41066 |
|
41067 | this.bindEvents(name, events);
|
41068 | };
|
41069 |
|
41070 | ToolManager.prototype.isActive = function(tool) {
|
41071 | return tool && this._active === tool;
|
41072 | };
|
41073 |
|
41074 | ToolManager.prototype.length = function(tool) {
|
41075 | return this._tools.length;
|
41076 | };
|
41077 |
|
41078 | ToolManager.prototype.setActive = function(tool) {
|
41079 | var eventBus = this._eventBus;
|
41080 |
|
41081 | if (this._active !== tool) {
|
41082 | this._active = tool;
|
41083 |
|
41084 | eventBus.fire('tool-manager.update', { tool: tool });
|
41085 | }
|
41086 | };
|
41087 |
|
41088 | ToolManager.prototype.bindEvents = function(name, events) {
|
41089 | var eventBus = this._eventBus,
|
41090 | dragging = this._dragging;
|
41091 |
|
41092 | var eventsToRegister = [];
|
41093 |
|
41094 | eventBus.on(events.tool + '.init', function(event) {
|
41095 | var context = event.context;
|
41096 |
|
41097 |
|
41098 | if (!context.reactivate && this.isActive(name)) {
|
41099 | this.setActive(null);
|
41100 |
|
41101 | dragging.cancel();
|
41102 | return;
|
41103 | }
|
41104 |
|
41105 | this.setActive(name);
|
41106 |
|
41107 | }, this);
|
41108 |
|
41109 |
|
41110 | forEach(events, function(event) {
|
41111 | eventsToRegister.push(event + '.ended');
|
41112 | eventsToRegister.push(event + '.canceled');
|
41113 | });
|
41114 |
|
41115 | eventBus.on(eventsToRegister, LOW_PRIORITY$b, function(event) {
|
41116 | var originalEvent = event.originalEvent;
|
41117 |
|
41118 |
|
41119 |
|
41120 |
|
41121 | if (!this._active) {
|
41122 | return;
|
41123 | }
|
41124 |
|
41125 | if (originalEvent && closest(originalEvent.target, '.group[data-group="tools"]')) {
|
41126 | return;
|
41127 | }
|
41128 |
|
41129 | this.setActive(null);
|
41130 | }, this);
|
41131 | };
|
41132 |
|
41133 | var ToolManagerModule = {
|
41134 | __depends__: [
|
41135 | DraggingModule
|
41136 | ],
|
41137 | __init__: [ 'toolManager' ],
|
41138 | toolManager: [ 'type', ToolManager ]
|
41139 | };
|
41140 |
|
41141 | |
41142 |
|
41143 |
|
41144 |
|
41145 |
|
41146 |
|
41147 |
|
41148 |
|
41149 | function getDirection(axis, offset) {
|
41150 |
|
41151 | if (axis === 'x') {
|
41152 | if (offset > 0) {
|
41153 | return 'e';
|
41154 | }
|
41155 |
|
41156 | if (offset < 0) {
|
41157 | return 'w';
|
41158 | }
|
41159 | }
|
41160 |
|
41161 | if (axis === 'y') {
|
41162 | if (offset > 0) {
|
41163 | return 's';
|
41164 | }
|
41165 |
|
41166 | if (offset < 0) {
|
41167 | return 'n';
|
41168 | }
|
41169 | }
|
41170 |
|
41171 | return null;
|
41172 | }
|
41173 |
|
41174 |
|
41175 | |
41176 |
|
41177 |
|
41178 |
|
41179 |
|
41180 |
|
41181 |
|
41182 |
|
41183 |
|
41184 | function resizeBounds$1(bounds, direction, delta) {
|
41185 |
|
41186 | var dx = delta.x,
|
41187 | dy = delta.y;
|
41188 |
|
41189 | switch (direction) {
|
41190 |
|
41191 | case 'n':
|
41192 | return {
|
41193 | x: bounds.x,
|
41194 | y: bounds.y + dy,
|
41195 | width: bounds.width,
|
41196 | height: bounds.height - dy
|
41197 | };
|
41198 |
|
41199 | case 's':
|
41200 | return {
|
41201 | x: bounds.x,
|
41202 | y: bounds.y,
|
41203 | width: bounds.width,
|
41204 | height: bounds.height + dy
|
41205 | };
|
41206 |
|
41207 | case 'w':
|
41208 | return {
|
41209 | x: bounds.x + dx,
|
41210 | y: bounds.y,
|
41211 | width: bounds.width - dx,
|
41212 | height: bounds.height
|
41213 | };
|
41214 |
|
41215 | case 'e':
|
41216 | return {
|
41217 | x: bounds.x,
|
41218 | y: bounds.y,
|
41219 | width: bounds.width + dx,
|
41220 | height: bounds.height
|
41221 | };
|
41222 |
|
41223 | default:
|
41224 | throw new Error('unrecognized direction: ' + direction);
|
41225 | }
|
41226 | }
|
41227 |
|
41228 | var abs$5 = Math.abs,
|
41229 | round$6 = Math.round;
|
41230 |
|
41231 | var HIGH_PRIORITY$3 = 1500,
|
41232 | SPACE_TOOL_CURSOR = 'crosshair';
|
41233 |
|
41234 | var AXIS_TO_DIMENSION = { x: 'width', y: 'height' },
|
41235 | AXIS_INVERTED = { x: 'y', y: 'x' };
|
41236 |
|
41237 |
|
41238 | |
41239 |
|
41240 |
|
41241 |
|
41242 |
|
41243 | function SpaceTool(
|
41244 | eventBus, dragging, canvas,
|
41245 | modeling, rules, toolManager) {
|
41246 |
|
41247 | this._canvas = canvas;
|
41248 | this._dragging = dragging;
|
41249 | this._modeling = modeling;
|
41250 | this._rules = rules;
|
41251 | this._toolManager = toolManager;
|
41252 |
|
41253 | var self = this;
|
41254 |
|
41255 | toolManager.registerTool('space', {
|
41256 | tool: 'spaceTool.selection',
|
41257 | dragging: 'spaceTool'
|
41258 | });
|
41259 |
|
41260 | eventBus.on('spaceTool.selection.end', function(event) {
|
41261 | var target = event.originalEvent.target;
|
41262 |
|
41263 |
|
41264 |
|
41265 | if (!event.hover && !(target instanceof SVGElement)) {
|
41266 | return;
|
41267 | }
|
41268 |
|
41269 | eventBus.once('spaceTool.selection.ended', function() {
|
41270 | self.activateMakeSpace(event.originalEvent);
|
41271 | });
|
41272 | });
|
41273 |
|
41274 |
|
41275 | eventBus.on('spaceTool.move', HIGH_PRIORITY$3 , function(event) {
|
41276 |
|
41277 | var context = event.context;
|
41278 |
|
41279 | if (!context.initialized) {
|
41280 | context.initialized = self.initializeMakeSpace(event, context);
|
41281 | }
|
41282 | });
|
41283 |
|
41284 |
|
41285 | eventBus.on('spaceTool.end', function(event) {
|
41286 |
|
41287 | var context = event.context,
|
41288 | axis = context.axis,
|
41289 | direction = context.direction,
|
41290 | movingShapes = context.movingShapes,
|
41291 | resizingShapes = context.resizingShapes;
|
41292 |
|
41293 |
|
41294 | if (!context.initialized) {
|
41295 | return;
|
41296 | }
|
41297 |
|
41298 | var delta = { x: round$6(event.dx), y: round$6(event.dy) };
|
41299 | delta[ AXIS_INVERTED[ axis ] ] = 0;
|
41300 |
|
41301 | var insideBounds = true;
|
41302 |
|
41303 |
|
41304 |
|
41305 | forEach(resizingShapes, function(shape) {
|
41306 |
|
41307 | if ((direction === 'w' && event.x > shape.x + shape.width) ||
|
41308 | (direction === 'e' && event.x < shape.x) ||
|
41309 | (direction === 'n' && event.y > shape.y + shape.height) ||
|
41310 | (direction === 's' && event.y < shape.y)) {
|
41311 |
|
41312 | insideBounds = false;
|
41313 | return;
|
41314 | }
|
41315 | });
|
41316 |
|
41317 | if (insideBounds) {
|
41318 |
|
41319 | self.makeSpace(movingShapes, resizingShapes, delta, direction);
|
41320 | }
|
41321 |
|
41322 | eventBus.once('spaceTool.ended', function(event) {
|
41323 |
|
41324 | self.activateSelection(event.originalEvent, true, true);
|
41325 | });
|
41326 |
|
41327 | });
|
41328 | }
|
41329 |
|
41330 | SpaceTool.$inject = [
|
41331 | 'eventBus',
|
41332 | 'dragging',
|
41333 | 'canvas',
|
41334 | 'modeling',
|
41335 | 'rules',
|
41336 | 'toolManager'
|
41337 | ];
|
41338 |
|
41339 |
|
41340 | |
41341 |
|
41342 |
|
41343 |
|
41344 |
|
41345 |
|
41346 | SpaceTool.prototype.activateSelection = function(event, autoActivate, reactivate) {
|
41347 | this._dragging.init(event, 'spaceTool.selection', {
|
41348 | trapClick: false,
|
41349 | cursor: SPACE_TOOL_CURSOR,
|
41350 | autoActivate: autoActivate,
|
41351 | data: {
|
41352 | context: {
|
41353 | reactivate: reactivate
|
41354 | }
|
41355 | }
|
41356 | });
|
41357 | };
|
41358 |
|
41359 | |
41360 |
|
41361 |
|
41362 |
|
41363 |
|
41364 | SpaceTool.prototype.activateMakeSpace = function(event) {
|
41365 | this._dragging.init(event, 'spaceTool', {
|
41366 | autoActivate: true,
|
41367 | cursor: SPACE_TOOL_CURSOR,
|
41368 | data: {
|
41369 | context: {}
|
41370 | }
|
41371 | });
|
41372 | };
|
41373 |
|
41374 | |
41375 |
|
41376 |
|
41377 |
|
41378 |
|
41379 |
|
41380 |
|
41381 |
|
41382 | SpaceTool.prototype.makeSpace = function(movingShapes, resizingShapes, delta, direction) {
|
41383 | return this._modeling.createSpace(movingShapes, resizingShapes, delta, direction);
|
41384 | };
|
41385 |
|
41386 | |
41387 |
|
41388 |
|
41389 |
|
41390 |
|
41391 |
|
41392 |
|
41393 |
|
41394 | SpaceTool.prototype.initializeMakeSpace = function(event, context) {
|
41395 |
|
41396 | var axis = abs$5(event.dx) > abs$5(event.dy) ? 'x' : 'y',
|
41397 | offset = event['d' + axis],
|
41398 |
|
41399 | spacePos = event[axis] - offset;
|
41400 |
|
41401 | if (abs$5(offset) < 5) {
|
41402 | return false;
|
41403 | }
|
41404 |
|
41405 |
|
41406 | if (offset < 0) {
|
41407 | offset *= -1;
|
41408 | }
|
41409 |
|
41410 |
|
41411 |
|
41412 |
|
41413 | if (hasPrimaryModifier(event)) {
|
41414 | offset *= -1;
|
41415 | }
|
41416 |
|
41417 | var rootShape = this._canvas.getRootElement();
|
41418 |
|
41419 | var allShapes = selfAndAllChildren(rootShape, true);
|
41420 |
|
41421 | var adjustments = this.calculateAdjustments(allShapes, axis, offset, spacePos);
|
41422 |
|
41423 |
|
41424 | assign(context, adjustments, {
|
41425 | axis: axis,
|
41426 | direction: getDirection(axis, offset)
|
41427 | });
|
41428 |
|
41429 | set$1('resize-' + (axis === 'x' ? 'ew' : 'ns'));
|
41430 |
|
41431 | return true;
|
41432 | };
|
41433 |
|
41434 | /**
|
41435 | * Calculate adjustments needed when making space
|
41436 | *
|
41437 | * @param {Array<djs.model.Shape>} elements
|
41438 | * @param {String} axis
|
41439 | * @param {Number} offset
|
41440 | * @param {Number} spacePos
|
41441 | *
|
41442 | * @return {Object}
|
41443 | */
|
41444 | SpaceTool.prototype.calculateAdjustments = function(elements, axis, offset, spacePos) {
|
41445 |
|
41446 | var movingShapes = [],
|
41447 | resizingShapes = [];
|
41448 |
|
41449 | var rules = this._rules;
|
41450 |
|
41451 |
|
41452 |
|
41453 | elements.forEach(function(shape) {
|
41454 |
|
41455 | var shapeStart = shape[axis],
|
41456 | shapeEnd = shapeStart + shape[AXIS_TO_DIMENSION[axis]];
|
41457 |
|
41458 |
|
41459 | if (!shape.parent) {
|
41460 | return;
|
41461 | }
|
41462 |
|
41463 |
|
41464 | if (shape.waypoints) {
|
41465 | return;
|
41466 | }
|
41467 |
|
41468 |
|
41469 | if (offset > 0 && shapeStart > spacePos) {
|
41470 | return movingShapes.push(shape);
|
41471 | }
|
41472 |
|
41473 |
|
41474 | if (offset < 0 && shapeEnd < spacePos) {
|
41475 | return movingShapes.push(shape);
|
41476 | }
|
41477 |
|
41478 |
|
41479 | if (shapeStart < spacePos &&
|
41480 | shapeEnd > spacePos &&
|
41481 | rules.allowed('shape.resize', { shape: shape })) {
|
41482 |
|
41483 | return resizingShapes.push(shape);
|
41484 | }
|
41485 | });
|
41486 |
|
41487 | return {
|
41488 | movingShapes: movingShapes,
|
41489 | resizingShapes: resizingShapes
|
41490 | };
|
41491 | };
|
41492 |
|
41493 | SpaceTool.prototype.toggle = function() {
|
41494 | if (this.isActive()) {
|
41495 | this._dragging.cancel();
|
41496 | } else {
|
41497 | this.activateSelection();
|
41498 | }
|
41499 | };
|
41500 |
|
41501 | SpaceTool.prototype.isActive = function() {
|
41502 | var context = this._dragging.context();
|
41503 |
|
41504 | return context && /^spaceTool/.test(context.prefix);
|
41505 | };
|
41506 |
|
41507 | var MARKER_DRAGGING = 'djs-dragging',
|
41508 | MARKER_RESIZING$1 = 'djs-resizing';
|
41509 |
|
41510 | var LOW_PRIORITY$c = 250;
|
41511 |
|
41512 |
|
41513 | |
41514 |
|
41515 |
|
41516 |
|
41517 |
|
41518 |
|
41519 |
|
41520 |
|
41521 | function SpaceToolPreview(
|
41522 | eventBus, elementRegistry, canvas,
|
41523 | styles, previewSupport) {
|
41524 |
|
41525 | function addPreviewGfx(collection, dragGroup) {
|
41526 | forEach(collection, function(element) {
|
41527 | previewSupport.addDragger(element, dragGroup);
|
41528 |
|
41529 | canvas.addMarker(element, MARKER_DRAGGING);
|
41530 | });
|
41531 | }
|
41532 |
|
41533 |
|
41534 | eventBus.on('spaceTool.selection.start', function(event) {
|
41535 | var space = canvas.getLayer('space'),
|
41536 | context = event.context;
|
41537 |
|
41538 | var orientation = {
|
41539 | x: 'M 0,-10000 L 0,10000',
|
41540 | y: 'M -10000,0 L 10000,0'
|
41541 | };
|
41542 |
|
41543 | var crosshairGroup = create('g');
|
41544 | attr$1(crosshairGroup, styles.cls('djs-crosshair-group', [ 'no-events' ]));
|
41545 |
|
41546 | append(space, crosshairGroup);
|
41547 |
|
41548 |
|
41549 | var pathX = create('path');
|
41550 | attr$1(pathX, 'd', orientation.x);
|
41551 | classes$1(pathX).add('djs-crosshair');
|
41552 |
|
41553 | append(crosshairGroup, pathX);
|
41554 |
|
41555 |
|
41556 | var pathY = create('path');
|
41557 | attr$1(pathY, 'd', orientation.y);
|
41558 | classes$1(pathY).add('djs-crosshair');
|
41559 |
|
41560 | append(crosshairGroup, pathY);
|
41561 |
|
41562 | context.crosshairGroup = crosshairGroup;
|
41563 | });
|
41564 |
|
41565 |
|
41566 | eventBus.on('spaceTool.selection.move', function(event) {
|
41567 | var crosshairGroup = event.context.crosshairGroup;
|
41568 |
|
41569 | translate(crosshairGroup, event.x, event.y);
|
41570 | });
|
41571 |
|
41572 |
|
41573 | eventBus.on('spaceTool.selection.cleanup', function(event) {
|
41574 | var context = event.context,
|
41575 | crosshairGroup = context.crosshairGroup;
|
41576 |
|
41577 | if (crosshairGroup) {
|
41578 | remove$1(crosshairGroup);
|
41579 | }
|
41580 | });
|
41581 |
|
41582 |
|
41583 | eventBus.on('spaceTool.move', LOW_PRIORITY$c, function(event) {
|
41584 |
|
41585 | var context = event.context,
|
41586 | line = context.line,
|
41587 | axis = context.axis,
|
41588 | movingShapes = context.movingShapes,
|
41589 | resizingShapes = context.resizingShapes;
|
41590 |
|
41591 | if (!context.initialized) {
|
41592 | return;
|
41593 | }
|
41594 |
|
41595 | if (!context.dragGroup) {
|
41596 | var spaceLayer = canvas.getLayer('space');
|
41597 |
|
41598 | line = create('path');
|
41599 | attr$1(line, 'd', 'M0,0 L0,0');
|
41600 | classes$1(line).add('djs-crosshair');
|
41601 |
|
41602 | append(spaceLayer, line);
|
41603 |
|
41604 | context.line = line;
|
41605 |
|
41606 | var dragGroup = create('g');
|
41607 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
41608 |
|
41609 | append(canvas.getDefaultLayer(), dragGroup);
|
41610 |
|
41611 |
|
41612 | addPreviewGfx(movingShapes, dragGroup);
|
41613 |
|
41614 |
|
41615 | var movingConnections = context.movingConnections = elementRegistry.filter(function(element) {
|
41616 | var sourceIsMoving = false;
|
41617 |
|
41618 | forEach(movingShapes, function(shape) {
|
41619 | forEach(shape.outgoing, function(connection) {
|
41620 | if (element === connection) {
|
41621 | sourceIsMoving = true;
|
41622 | }
|
41623 | });
|
41624 | });
|
41625 |
|
41626 | var targetIsMoving = false;
|
41627 |
|
41628 | forEach(movingShapes, function(shape) {
|
41629 | forEach(shape.incoming, function(connection) {
|
41630 | if (element === connection) {
|
41631 | targetIsMoving = true;
|
41632 | }
|
41633 | });
|
41634 | });
|
41635 |
|
41636 | var sourceIsResizing = false;
|
41637 |
|
41638 | forEach(resizingShapes, function(shape) {
|
41639 | forEach(shape.outgoing, function(connection) {
|
41640 | if (element === connection) {
|
41641 | sourceIsResizing = true;
|
41642 | }
|
41643 | });
|
41644 | });
|
41645 |
|
41646 | var targetIsResizing = false;
|
41647 |
|
41648 | forEach(resizingShapes, function(shape) {
|
41649 | forEach(shape.incoming, function(connection) {
|
41650 | if (element === connection) {
|
41651 | targetIsResizing = true;
|
41652 | }
|
41653 | });
|
41654 | });
|
41655 |
|
41656 | return isConnection$2(element)
|
41657 | && (sourceIsMoving || sourceIsResizing)
|
41658 | && (targetIsMoving || targetIsResizing);
|
41659 | });
|
41660 |
|
41661 |
|
41662 | addPreviewGfx(movingConnections, dragGroup);
|
41663 |
|
41664 | context.dragGroup = dragGroup;
|
41665 | }
|
41666 |
|
41667 | if (!context.frameGroup) {
|
41668 | var frameGroup = create('g');
|
41669 | attr$1(frameGroup, styles.cls('djs-frame-group', [ 'no-events' ]));
|
41670 |
|
41671 | append(canvas.getDefaultLayer(), frameGroup);
|
41672 |
|
41673 | var frames = [];
|
41674 |
|
41675 | forEach(resizingShapes, function(shape) {
|
41676 | var frame = previewSupport.addFrame(shape, frameGroup);
|
41677 |
|
41678 | frames.push({
|
41679 | element: frame,
|
41680 | initialWidth: frame.getBBox().width,
|
41681 | initialHeight: frame.getBBox().height
|
41682 | });
|
41683 |
|
41684 | canvas.addMarker(shape, MARKER_RESIZING$1);
|
41685 | });
|
41686 |
|
41687 | context.frameGroup = frameGroup;
|
41688 | context.frames = frames;
|
41689 | }
|
41690 |
|
41691 | var orientation = {
|
41692 | x: 'M' + event.x + ', -10000 L' + event.x + ', 10000',
|
41693 | y: 'M -10000, ' + event.y + ' L 10000, ' + event.y
|
41694 | };
|
41695 |
|
41696 | attr$1(line, { path: orientation[ axis ], display: '' });
|
41697 |
|
41698 | var opposite = { x: 'y', y: 'x' };
|
41699 | var delta = { x: event.dx, y: event.dy };
|
41700 | delta[ opposite[ context.axis ] ] = 0;
|
41701 |
|
41702 |
|
41703 | translate(context.dragGroup, delta.x, delta.y);
|
41704 |
|
41705 |
|
41706 | forEach(context.frames, function(frame) {
|
41707 | if (frame.initialWidth + delta.x > 5) {
|
41708 | attr$1(frame.element, { width: frame.initialWidth + delta.x });
|
41709 | }
|
41710 |
|
41711 | if (frame.initialHeight + delta.y > 5) {
|
41712 | attr$1(frame.element, { height: frame.initialHeight + delta.y });
|
41713 | }
|
41714 | });
|
41715 |
|
41716 | });
|
41717 |
|
41718 |
|
41719 | eventBus.on('spaceTool.cleanup', function(event) {
|
41720 |
|
41721 | var context = event.context,
|
41722 | movingShapes = context.movingShapes,
|
41723 | movingConnections = context.movingConnections,
|
41724 | resizingShapes = context.resizingShapes,
|
41725 | line = context.line,
|
41726 | dragGroup = context.dragGroup,
|
41727 | frameGroup = context.frameGroup;
|
41728 |
|
41729 |
|
41730 | forEach(movingShapes, function(shape) {
|
41731 | canvas.removeMarker(shape, MARKER_DRAGGING);
|
41732 | });
|
41733 |
|
41734 |
|
41735 | forEach(movingConnections, function(connection) {
|
41736 | canvas.removeMarker(connection, MARKER_DRAGGING);
|
41737 | });
|
41738 |
|
41739 | if (dragGroup) {
|
41740 | remove$1(line);
|
41741 | remove$1(dragGroup);
|
41742 | }
|
41743 |
|
41744 | forEach(resizingShapes, function(shape) {
|
41745 | canvas.removeMarker(shape, MARKER_RESIZING$1);
|
41746 | });
|
41747 |
|
41748 | if (frameGroup) {
|
41749 | remove$1(frameGroup);
|
41750 | }
|
41751 | });
|
41752 | }
|
41753 |
|
41754 | SpaceToolPreview.$inject = [
|
41755 | 'eventBus',
|
41756 | 'elementRegistry',
|
41757 | 'canvas',
|
41758 | 'styles',
|
41759 | 'previewSupport'
|
41760 | ];
|
41761 |
|
41762 |
|
41763 |
|
41764 |
|
41765 | |
41766 |
|
41767 |
|
41768 | function isConnection$2(element) {
|
41769 | return element.waypoints;
|
41770 | }
|
41771 |
|
41772 | var SpaceToolModule = {
|
41773 | __init__: ['spaceToolPreview'],
|
41774 | __depends__: [
|
41775 | DraggingModule,
|
41776 | RulesModule,
|
41777 | ToolManagerModule,
|
41778 | PreviewSupportModule
|
41779 | ],
|
41780 | spaceTool: ['type', SpaceTool ],
|
41781 | spaceToolPreview: ['type', SpaceToolPreview ]
|
41782 | };
|
41783 |
|
41784 | function BpmnFactory(moddle) {
|
41785 | this._model = moddle;
|
41786 | }
|
41787 |
|
41788 | BpmnFactory.$inject = [ 'moddle' ];
|
41789 |
|
41790 |
|
41791 | BpmnFactory.prototype._needsId = function(element) {
|
41792 | return isAny(element, [
|
41793 | 'bpmn:RootElement',
|
41794 | 'bpmn:FlowElement',
|
41795 | 'bpmn:MessageFlow',
|
41796 | 'bpmn:DataAssociation',
|
41797 | 'bpmn:Artifact',
|
41798 | 'bpmn:Participant',
|
41799 | 'bpmn:Lane',
|
41800 | 'bpmn:LaneSet',
|
41801 | 'bpmn:Process',
|
41802 | 'bpmn:Collaboration',
|
41803 | 'bpmndi:BPMNShape',
|
41804 | 'bpmndi:BPMNEdge',
|
41805 | 'bpmndi:BPMNDiagram',
|
41806 | 'bpmndi:BPMNPlane',
|
41807 | 'bpmn:Property'
|
41808 | ]);
|
41809 | };
|
41810 |
|
41811 | BpmnFactory.prototype._ensureId = function(element) {
|
41812 |
|
41813 |
|
41814 |
|
41815 | var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';
|
41816 |
|
41817 | if (!element.id && this._needsId(element)) {
|
41818 | element.id = this._model.ids.nextPrefixed(prefix, element);
|
41819 | }
|
41820 | };
|
41821 |
|
41822 |
|
41823 | BpmnFactory.prototype.create = function(type, attrs) {
|
41824 | var element = this._model.create(type, attrs || {});
|
41825 |
|
41826 | this._ensureId(element);
|
41827 |
|
41828 | return element;
|
41829 | };
|
41830 |
|
41831 |
|
41832 | BpmnFactory.prototype.createDiLabel = function() {
|
41833 | return this.create('bpmndi:BPMNLabel', {
|
41834 | bounds: this.createDiBounds()
|
41835 | });
|
41836 | };
|
41837 |
|
41838 |
|
41839 | BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {
|
41840 |
|
41841 | return this.create('bpmndi:BPMNShape', assign({
|
41842 | bpmnElement: semantic,
|
41843 | bounds: this.createDiBounds(bounds)
|
41844 | }, attrs));
|
41845 | };
|
41846 |
|
41847 |
|
41848 | BpmnFactory.prototype.createDiBounds = function(bounds) {
|
41849 | return this.create('dc:Bounds', bounds);
|
41850 | };
|
41851 |
|
41852 |
|
41853 | BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
|
41854 | var self = this;
|
41855 |
|
41856 | return map(waypoints, function(pos) {
|
41857 | return self.createDiWaypoint(pos);
|
41858 | });
|
41859 | };
|
41860 |
|
41861 | BpmnFactory.prototype.createDiWaypoint = function(point) {
|
41862 | return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
|
41863 | };
|
41864 |
|
41865 |
|
41866 | BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
|
41867 | return this.create('bpmndi:BPMNEdge', assign({
|
41868 | bpmnElement: semantic
|
41869 | }, attrs));
|
41870 | };
|
41871 |
|
41872 | BpmnFactory.prototype.createDiPlane = function(semantic) {
|
41873 | return this.create('bpmndi:BPMNPlane', {
|
41874 | bpmnElement: semantic
|
41875 | });
|
41876 | };
|
41877 |
|
41878 | |
41879 |
|
41880 |
|
41881 |
|
41882 | function BpmnUpdater(
|
41883 | eventBus, bpmnFactory, connectionDocking,
|
41884 | translate) {
|
41885 |
|
41886 | CommandInterceptor.call(this, eventBus);
|
41887 |
|
41888 | this._bpmnFactory = bpmnFactory;
|
41889 | this._translate = translate;
|
41890 |
|
41891 | var self = this;
|
41892 |
|
41893 |
|
41894 |
|
41895 |
|
41896 |
|
41897 |
|
41898 | function cropConnection(e) {
|
41899 | var context = e.context,
|
41900 | connection;
|
41901 |
|
41902 | if (!context.cropped) {
|
41903 | connection = context.connection;
|
41904 | connection.waypoints = connectionDocking.getCroppedWaypoints(connection);
|
41905 | context.cropped = true;
|
41906 | }
|
41907 | }
|
41908 |
|
41909 | this.executed([
|
41910 | 'connection.layout',
|
41911 | 'connection.create',
|
41912 | 'connection.reconnectEnd',
|
41913 | 'connection.reconnectStart'
|
41914 | ], cropConnection);
|
41915 |
|
41916 | this.reverted([ 'connection.layout' ], function(e) {
|
41917 | delete e.context.cropped;
|
41918 | });
|
41919 |
|
41920 |
|
41921 |
|
41922 |
|
41923 |
|
41924 |
|
41925 |
|
41926 | function updateParent(e) {
|
41927 | var context = e.context;
|
41928 |
|
41929 | self.updateParent(context.shape || context.connection, context.oldParent);
|
41930 | }
|
41931 |
|
41932 | function reverseUpdateParent(e) {
|
41933 | var context = e.context;
|
41934 |
|
41935 | var element = context.shape || context.connection,
|
41936 |
|
41937 | oldParent = context.parent || context.newParent;
|
41938 |
|
41939 | self.updateParent(element, oldParent);
|
41940 | }
|
41941 |
|
41942 | this.executed([
|
41943 | 'shape.move',
|
41944 | 'shape.create',
|
41945 | 'shape.delete',
|
41946 | 'connection.create',
|
41947 | 'connection.move',
|
41948 | 'connection.delete'
|
41949 | ], ifBpmn(updateParent));
|
41950 |
|
41951 | this.reverted([
|
41952 | 'shape.move',
|
41953 | 'shape.create',
|
41954 | 'shape.delete',
|
41955 | 'connection.create',
|
41956 | 'connection.move',
|
41957 | 'connection.delete'
|
41958 | ], ifBpmn(reverseUpdateParent));
|
41959 |
|
41960 | |
41961 |
|
41962 |
|
41963 |
|
41964 |
|
41965 |
|
41966 |
|
41967 |
|
41968 | function updateRoot(event) {
|
41969 | var context = event.context,
|
41970 | oldRoot = context.oldRoot,
|
41971 | children = oldRoot.children;
|
41972 |
|
41973 | forEach(children, function(child) {
|
41974 | if (is$1(child, 'bpmn:BaseElement')) {
|
41975 | self.updateParent(child);
|
41976 | }
|
41977 | });
|
41978 | }
|
41979 |
|
41980 | this.executed([ 'canvas.updateRoot' ], updateRoot);
|
41981 | this.reverted([ 'canvas.updateRoot' ], updateRoot);
|
41982 |
|
41983 |
|
41984 |
|
41985 | function updateBounds(e) {
|
41986 | var shape = e.context.shape;
|
41987 |
|
41988 | if (!is$1(shape, 'bpmn:BaseElement')) {
|
41989 | return;
|
41990 | }
|
41991 |
|
41992 | self.updateBounds(shape);
|
41993 | }
|
41994 |
|
41995 | this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
41996 |
|
41997 |
|
41998 | if (event.context.shape.type === 'label') {
|
41999 | return;
|
42000 | }
|
42001 |
|
42002 | updateBounds(event);
|
42003 | }));
|
42004 |
|
42005 | this.reverted([ 'shape.move', 'shape.create', 'shape.resize' ], ifBpmn(function(event) {
|
42006 |
|
42007 |
|
42008 | if (event.context.shape.type === 'label') {
|
42009 | return;
|
42010 | }
|
42011 |
|
42012 | updateBounds(event);
|
42013 | }));
|
42014 |
|
42015 |
|
42016 |
|
42017 | eventBus.on('shape.changed', function(event) {
|
42018 | if (event.element.type === 'label') {
|
42019 | updateBounds({ context: { shape: event.element } });
|
42020 | }
|
42021 | });
|
42022 |
|
42023 |
|
42024 | function updateConnection(e) {
|
42025 | self.updateConnection(e.context);
|
42026 | }
|
42027 |
|
42028 | this.executed([
|
42029 | 'connection.create',
|
42030 | 'connection.move',
|
42031 | 'connection.delete',
|
42032 | 'connection.reconnectEnd',
|
42033 | 'connection.reconnectStart'
|
42034 | ], ifBpmn(updateConnection));
|
42035 |
|
42036 | this.reverted([
|
42037 | 'connection.create',
|
42038 | 'connection.move',
|
42039 | 'connection.delete',
|
42040 | 'connection.reconnectEnd',
|
42041 | 'connection.reconnectStart'
|
42042 | ], ifBpmn(updateConnection));
|
42043 |
|
42044 |
|
42045 |
|
42046 | function updateConnectionWaypoints(e) {
|
42047 | self.updateConnectionWaypoints(e.context.connection);
|
42048 | }
|
42049 |
|
42050 | this.executed([
|
42051 | 'connection.layout',
|
42052 | 'connection.move',
|
42053 | 'connection.updateWaypoints',
|
42054 | 'connection.reconnectEnd',
|
42055 | 'connection.reconnectStart'
|
42056 | ], ifBpmn(updateConnectionWaypoints));
|
42057 |
|
42058 | this.reverted([
|
42059 | 'connection.layout',
|
42060 | 'connection.move',
|
42061 | 'connection.updateWaypoints',
|
42062 | 'connection.reconnectEnd',
|
42063 | 'connection.reconnectStart'
|
42064 | ], ifBpmn(updateConnectionWaypoints));
|
42065 |
|
42066 |
|
42067 |
|
42068 | this.executed([
|
42069 | 'connection.reconnectEnd',
|
42070 | 'connection.reconnectStart'
|
42071 | ], ifBpmn(function(e) {
|
42072 | var context = e.context,
|
42073 | connection = context.connection,
|
42074 | businessObject = getBusinessObject(connection),
|
42075 | oldSource = getBusinessObject(context.oldSource),
|
42076 | oldTarget = getBusinessObject(context.oldTarget),
|
42077 | newSource = getBusinessObject(connection.source),
|
42078 | newTarget = getBusinessObject(connection.target);
|
42079 |
|
42080 | if (oldSource === newSource || oldTarget === newTarget) {
|
42081 | return;
|
42082 | }
|
42083 |
|
42084 |
|
42085 | if (oldSource && oldSource.default === businessObject) {
|
42086 | context.default = oldSource.default;
|
42087 | oldSource.default = undefined;
|
42088 | }
|
42089 |
|
42090 |
|
42091 | if ((businessObject.sourceRef && businessObject.sourceRef.default) &&
|
42092 | !(is$1(newTarget, 'bpmn:Activity') ||
|
42093 | is$1(newTarget, 'bpmn:EndEvent') ||
|
42094 | is$1(newTarget, 'bpmn:Gateway') ||
|
42095 | is$1(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
42096 | context.default = businessObject.sourceRef.default;
|
42097 | businessObject.sourceRef.default = undefined;
|
42098 | }
|
42099 |
|
42100 |
|
42101 | if (oldSource && (businessObject.conditionExpression) &&
|
42102 | !(is$1(newSource, 'bpmn:Activity') ||
|
42103 | is$1(newSource, 'bpmn:Gateway'))) {
|
42104 | context.conditionExpression = businessObject.conditionExpression;
|
42105 | businessObject.conditionExpression = undefined;
|
42106 | }
|
42107 |
|
42108 |
|
42109 | if (oldTarget && (businessObject.conditionExpression) &&
|
42110 | !(is$1(newTarget, 'bpmn:Activity') ||
|
42111 | is$1(newTarget, 'bpmn:EndEvent') ||
|
42112 | is$1(newTarget, 'bpmn:Gateway') ||
|
42113 | is$1(newTarget, 'bpmn:IntermediateThrowEvent'))) {
|
42114 | context.conditionExpression = businessObject.conditionExpression;
|
42115 | businessObject.conditionExpression = undefined;
|
42116 | }
|
42117 | }));
|
42118 |
|
42119 | this.reverted([
|
42120 | 'connection.reconnectEnd',
|
42121 | 'connection.reconnectStart'
|
42122 | ], ifBpmn(function(e) {
|
42123 | var context = e.context,
|
42124 | connection = context.connection,
|
42125 | businessObject = getBusinessObject(connection),
|
42126 | newSource = getBusinessObject(connection.source);
|
42127 |
|
42128 |
|
42129 | if (context.default) {
|
42130 | if (is$1(newSource, 'bpmn:ExclusiveGateway') || is$1(newSource, 'bpmn:InclusiveGateway') ||
|
42131 | is$1(newSource, 'bpmn:Activity')) {
|
42132 | newSource.default = context.default;
|
42133 | }
|
42134 | }
|
42135 |
|
42136 |
|
42137 | if (context.conditionExpression && is$1(newSource, 'bpmn:Activity')) {
|
42138 | businessObject.conditionExpression = context.conditionExpression;
|
42139 | }
|
42140 | }));
|
42141 |
|
42142 |
|
42143 | function updateAttachment(e) {
|
42144 | self.updateAttachment(e.context);
|
42145 | }
|
42146 |
|
42147 | this.executed([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
42148 | this.reverted([ 'element.updateAttachment' ], ifBpmn(updateAttachment));
|
42149 | }
|
42150 |
|
42151 | inherits_browser(BpmnUpdater, CommandInterceptor);
|
42152 |
|
42153 | BpmnUpdater.$inject = [
|
42154 | 'eventBus',
|
42155 | 'bpmnFactory',
|
42156 | 'connectionDocking',
|
42157 | 'translate'
|
42158 | ];
|
42159 |
|
42160 |
|
42161 |
|
42162 |
|
42163 | BpmnUpdater.prototype.updateAttachment = function(context) {
|
42164 |
|
42165 | var shape = context.shape,
|
42166 | businessObject = shape.businessObject,
|
42167 | host = shape.host;
|
42168 |
|
42169 | businessObject.attachedToRef = host && host.businessObject;
|
42170 | };
|
42171 |
|
42172 | BpmnUpdater.prototype.updateParent = function(element, oldParent) {
|
42173 |
|
42174 | if (element instanceof Label) {
|
42175 | return;
|
42176 | }
|
42177 |
|
42178 |
|
42179 | if (is$1(element, 'bpmn:DataStoreReference') &&
|
42180 | element.parent &&
|
42181 | is$1(element.parent, 'bpmn:Collaboration')) {
|
42182 | return;
|
42183 | }
|
42184 |
|
42185 | var parentShape = element.parent;
|
42186 |
|
42187 | var businessObject = element.businessObject,
|
42188 | parentBusinessObject = parentShape && parentShape.businessObject,
|
42189 | parentDi = parentBusinessObject && parentBusinessObject.di;
|
42190 |
|
42191 | if (is$1(element, 'bpmn:FlowNode')) {
|
42192 | this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
|
42193 | }
|
42194 |
|
42195 | if (is$1(element, 'bpmn:DataOutputAssociation')) {
|
42196 | if (element.source) {
|
42197 | parentBusinessObject = element.source.businessObject;
|
42198 | } else {
|
42199 | parentBusinessObject = null;
|
42200 | }
|
42201 | }
|
42202 |
|
42203 | if (is$1(element, 'bpmn:DataInputAssociation')) {
|
42204 | if (element.target) {
|
42205 | parentBusinessObject = element.target.businessObject;
|
42206 | } else {
|
42207 | parentBusinessObject = null;
|
42208 | }
|
42209 | }
|
42210 |
|
42211 | this.updateSemanticParent(businessObject, parentBusinessObject);
|
42212 |
|
42213 | if (is$1(element, 'bpmn:DataObjectReference') && businessObject.dataObjectRef) {
|
42214 | this.updateSemanticParent(businessObject.dataObjectRef, parentBusinessObject);
|
42215 | }
|
42216 |
|
42217 | this.updateDiParent(businessObject.di, parentDi);
|
42218 | };
|
42219 |
|
42220 |
|
42221 | BpmnUpdater.prototype.updateBounds = function(shape) {
|
42222 |
|
42223 | var di = shape.businessObject.di;
|
42224 |
|
42225 | var target = (shape instanceof Label) ? this._getLabel(di) : di;
|
42226 |
|
42227 | var bounds = target.bounds;
|
42228 |
|
42229 | if (!bounds) {
|
42230 | bounds = this._bpmnFactory.createDiBounds();
|
42231 | target.set('bounds', bounds);
|
42232 | }
|
42233 |
|
42234 | assign(bounds, {
|
42235 | x: shape.x,
|
42236 | y: shape.y,
|
42237 | width: shape.width,
|
42238 | height: shape.height
|
42239 | });
|
42240 | };
|
42241 |
|
42242 | BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainment, oldContainment) {
|
42243 |
|
42244 | if (oldContainment === newContainment) {
|
42245 | return;
|
42246 | }
|
42247 |
|
42248 | var oldRefs, newRefs;
|
42249 |
|
42250 | if (is$1 (oldContainment, 'bpmn:Lane')) {
|
42251 | oldRefs = oldContainment.get('flowNodeRef');
|
42252 | remove$2(oldRefs, businessObject);
|
42253 | }
|
42254 |
|
42255 | if (is$1(newContainment, 'bpmn:Lane')) {
|
42256 | newRefs = newContainment.get('flowNodeRef');
|
42257 | add(newRefs, businessObject);
|
42258 | }
|
42259 | };
|
42260 |
|
42261 |
|
42262 |
|
42263 | BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
|
42264 |
|
42265 | if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
|
42266 | di.sourceElement = newSource && newSource.di;
|
42267 | }
|
42268 |
|
42269 | if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
|
42270 | di.targetElement = newTarget && newTarget.di;
|
42271 | }
|
42272 |
|
42273 | };
|
42274 |
|
42275 |
|
42276 | BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
|
42277 |
|
42278 | if (parentDi && !is$1(parentDi, 'bpmndi:BPMNPlane')) {
|
42279 | parentDi = parentDi.$parent;
|
42280 | }
|
42281 |
|
42282 | if (di.$parent === parentDi) {
|
42283 | return;
|
42284 | }
|
42285 |
|
42286 | var planeElements = (parentDi || di.$parent).get('planeElement');
|
42287 |
|
42288 | if (parentDi) {
|
42289 | planeElements.push(di);
|
42290 | di.$parent = parentDi;
|
42291 | } else {
|
42292 | remove$2(planeElements, di);
|
42293 | di.$parent = null;
|
42294 | }
|
42295 | };
|
42296 |
|
42297 | function getDefinitions(element) {
|
42298 | while (element && !is$1(element, 'bpmn:Definitions')) {
|
42299 | element = element.$parent;
|
42300 | }
|
42301 |
|
42302 | return element;
|
42303 | }
|
42304 |
|
42305 | BpmnUpdater.prototype.getLaneSet = function(container) {
|
42306 |
|
42307 | var laneSet, laneSets;
|
42308 |
|
42309 |
|
42310 | if (is$1(container, 'bpmn:Lane')) {
|
42311 | laneSet = container.childLaneSet;
|
42312 |
|
42313 | if (!laneSet) {
|
42314 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
42315 | container.childLaneSet = laneSet;
|
42316 | laneSet.$parent = container;
|
42317 | }
|
42318 |
|
42319 | return laneSet;
|
42320 | }
|
42321 |
|
42322 |
|
42323 | if (is$1(container, 'bpmn:Participant')) {
|
42324 | container = container.processRef;
|
42325 | }
|
42326 |
|
42327 |
|
42328 | laneSets = container.get('laneSets');
|
42329 | laneSet = laneSets[0];
|
42330 |
|
42331 | if (!laneSet) {
|
42332 | laneSet = this._bpmnFactory.create('bpmn:LaneSet');
|
42333 | laneSet.$parent = container;
|
42334 | laneSets.push(laneSet);
|
42335 | }
|
42336 |
|
42337 | return laneSet;
|
42338 | };
|
42339 |
|
42340 | BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent, visualParent) {
|
42341 |
|
42342 | var containment,
|
42343 | translate = this._translate;
|
42344 |
|
42345 | if (businessObject.$parent === newParent) {
|
42346 | return;
|
42347 | }
|
42348 |
|
42349 | if (is$1(businessObject, 'bpmn:Lane')) {
|
42350 |
|
42351 | if (newParent) {
|
42352 | newParent = this.getLaneSet(newParent);
|
42353 | }
|
42354 |
|
42355 | containment = 'lanes';
|
42356 | } else
|
42357 |
|
42358 | if (is$1(businessObject, 'bpmn:FlowElement')) {
|
42359 |
|
42360 | if (newParent) {
|
42361 |
|
42362 | if (is$1(newParent, 'bpmn:Participant')) {
|
42363 | newParent = newParent.processRef;
|
42364 | } else
|
42365 |
|
42366 | if (is$1(newParent, 'bpmn:Lane')) {
|
42367 | do {
|
42368 |
|
42369 | newParent = newParent.$parent.$parent;
|
42370 | } while (is$1(newParent, 'bpmn:Lane'));
|
42371 |
|
42372 | }
|
42373 | }
|
42374 |
|
42375 | containment = 'flowElements';
|
42376 |
|
42377 | } else
|
42378 |
|
42379 | if (is$1(businessObject, 'bpmn:Artifact')) {
|
42380 |
|
42381 | while (newParent &&
|
42382 | !is$1(newParent, 'bpmn:Process') &&
|
42383 | !is$1(newParent, 'bpmn:SubProcess') &&
|
42384 | !is$1(newParent, 'bpmn:Collaboration')) {
|
42385 |
|
42386 | if (is$1(newParent, 'bpmn:Participant')) {
|
42387 | newParent = newParent.processRef;
|
42388 | break;
|
42389 | } else {
|
42390 | newParent = newParent.$parent;
|
42391 | }
|
42392 | }
|
42393 |
|
42394 | containment = 'artifacts';
|
42395 | } else
|
42396 |
|
42397 | if (is$1(businessObject, 'bpmn:MessageFlow')) {
|
42398 | containment = 'messageFlows';
|
42399 |
|
42400 | } else
|
42401 |
|
42402 | if (is$1(businessObject, 'bpmn:Participant')) {
|
42403 | containment = 'participants';
|
42404 |
|
42405 |
|
42406 |
|
42407 |
|
42408 | var process = businessObject.processRef,
|
42409 | definitions;
|
42410 |
|
42411 | if (process) {
|
42412 | definitions = getDefinitions(businessObject.$parent || newParent);
|
42413 |
|
42414 | if (businessObject.$parent) {
|
42415 | remove$2(definitions.get('rootElements'), process);
|
42416 | process.$parent = null;
|
42417 | }
|
42418 |
|
42419 | if (newParent) {
|
42420 | add(definitions.get('rootElements'), process);
|
42421 | process.$parent = definitions;
|
42422 | }
|
42423 | }
|
42424 | } else
|
42425 |
|
42426 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
42427 | containment = 'dataOutputAssociations';
|
42428 | } else
|
42429 |
|
42430 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
42431 | containment = 'dataInputAssociations';
|
42432 | }
|
42433 |
|
42434 | if (!containment) {
|
42435 | throw new Error(translate(
|
42436 | 'no parent for {element} in {parent}',
|
42437 | {
|
42438 | element: businessObject.id,
|
42439 | parent: newParent.id
|
42440 | }
|
42441 | ));
|
42442 | }
|
42443 |
|
42444 | var children;
|
42445 |
|
42446 | if (businessObject.$parent) {
|
42447 |
|
42448 | children = businessObject.$parent.get(containment);
|
42449 | remove$2(children, businessObject);
|
42450 | }
|
42451 |
|
42452 | if (!newParent) {
|
42453 | businessObject.$parent = null;
|
42454 | } else {
|
42455 |
|
42456 | children = newParent.get(containment);
|
42457 | children.push(businessObject);
|
42458 | businessObject.$parent = newParent;
|
42459 | }
|
42460 |
|
42461 | if (visualParent) {
|
42462 | var diChildren = visualParent.get(containment);
|
42463 |
|
42464 | remove$2(children, businessObject);
|
42465 |
|
42466 | if (newParent) {
|
42467 |
|
42468 | if (!diChildren) {
|
42469 | diChildren = [];
|
42470 | newParent.set(containment, diChildren);
|
42471 | }
|
42472 |
|
42473 | diChildren.push(businessObject);
|
42474 | }
|
42475 | }
|
42476 | };
|
42477 |
|
42478 |
|
42479 | BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
|
42480 | connection.businessObject.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
|
42481 | };
|
42482 |
|
42483 |
|
42484 | BpmnUpdater.prototype.updateConnection = function(context) {
|
42485 |
|
42486 | var connection = context.connection,
|
42487 | businessObject = getBusinessObject(connection),
|
42488 | newSource = getBusinessObject(connection.source),
|
42489 | newTarget = getBusinessObject(connection.target),
|
42490 | visualParent;
|
42491 |
|
42492 | if (!is$1(businessObject, 'bpmn:DataAssociation')) {
|
42493 |
|
42494 | var inverseSet = is$1(businessObject, 'bpmn:SequenceFlow');
|
42495 |
|
42496 | if (businessObject.sourceRef !== newSource) {
|
42497 | if (inverseSet) {
|
42498 | remove$2(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
|
42499 |
|
42500 | if (newSource && newSource.get('outgoing')) {
|
42501 | newSource.get('outgoing').push(businessObject);
|
42502 | }
|
42503 | }
|
42504 |
|
42505 | businessObject.sourceRef = newSource;
|
42506 | }
|
42507 |
|
42508 | if (businessObject.targetRef !== newTarget) {
|
42509 | if (inverseSet) {
|
42510 | remove$2(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
|
42511 |
|
42512 | if (newTarget && newTarget.get('incoming')) {
|
42513 | newTarget.get('incoming').push(businessObject);
|
42514 | }
|
42515 | }
|
42516 |
|
42517 | businessObject.targetRef = newTarget;
|
42518 | }
|
42519 | } else
|
42520 |
|
42521 | if (is$1(businessObject, 'bpmn:DataInputAssociation')) {
|
42522 |
|
42523 | businessObject.get('sourceRef')[0] = newSource;
|
42524 |
|
42525 | visualParent = context.parent || context.newParent || newTarget;
|
42526 |
|
42527 | this.updateSemanticParent(businessObject, newTarget, parent.businessObject);
|
42528 | } else
|
42529 |
|
42530 | if (is$1(businessObject, 'bpmn:DataOutputAssociation')) {
|
42531 | visualParent = context.parent || context.newParent || newSource;
|
42532 |
|
42533 | this.updateSemanticParent(businessObject, newSource, visualParent);
|
42534 |
|
42535 |
|
42536 | businessObject.targetRef = newTarget;
|
42537 | }
|
42538 |
|
42539 | this.updateConnectionWaypoints(connection);
|
42540 |
|
42541 | this.updateDiConnection(businessObject.di, newSource, newTarget);
|
42542 | };
|
42543 |
|
42544 |
|
42545 |
|
42546 |
|
42547 | BpmnUpdater.prototype._getLabel = function(di) {
|
42548 | if (!di.label) {
|
42549 | di.label = this._bpmnFactory.createDiLabel();
|
42550 | }
|
42551 |
|
42552 | return di.label;
|
42553 | };
|
42554 |
|
42555 |
|
42556 | |
42557 |
|
42558 |
|
42559 |
|
42560 |
|
42561 |
|
42562 |
|
42563 | function ifBpmn(fn) {
|
42564 |
|
42565 | return function(event) {
|
42566 |
|
42567 | var context = event.context,
|
42568 | element = context.shape || context.connection;
|
42569 |
|
42570 | if (is$1(element, 'bpmn:BaseElement')) {
|
42571 | fn(event);
|
42572 | }
|
42573 | };
|
42574 | }
|
42575 |
|
42576 | |
42577 |
|
42578 |
|
42579 | function ElementFactory$1(bpmnFactory, moddle, translate) {
|
42580 | ElementFactory.call(this);
|
42581 |
|
42582 | this._bpmnFactory = bpmnFactory;
|
42583 | this._moddle = moddle;
|
42584 | this._translate = translate;
|
42585 | }
|
42586 |
|
42587 | inherits_browser(ElementFactory$1, ElementFactory);
|
42588 |
|
42589 | ElementFactory$1.$inject = [
|
42590 | 'bpmnFactory',
|
42591 | 'moddle',
|
42592 | 'translate'
|
42593 | ];
|
42594 |
|
42595 | ElementFactory$1.prototype.baseCreate = ElementFactory.prototype.create;
|
42596 |
|
42597 | ElementFactory$1.prototype.create = function(elementType, attrs) {
|
42598 |
|
42599 |
|
42600 |
|
42601 | if (elementType === 'label') {
|
42602 | return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE$1, attrs));
|
42603 | }
|
42604 |
|
42605 | return this.createBpmnElement(elementType, attrs);
|
42606 | };
|
42607 |
|
42608 | ElementFactory$1.prototype.createBpmnElement = function(elementType, attrs) {
|
42609 | var size$$1,
|
42610 | translate = this._translate;
|
42611 |
|
42612 | attrs = attrs || {};
|
42613 |
|
42614 | var businessObject = attrs.businessObject;
|
42615 |
|
42616 | if (!businessObject) {
|
42617 | if (!attrs.type) {
|
42618 | throw new Error(translate('no shape type specified'));
|
42619 | }
|
42620 |
|
42621 | businessObject = this._bpmnFactory.create(attrs.type);
|
42622 | }
|
42623 |
|
42624 | if (!businessObject.di) {
|
42625 | if (elementType === 'root') {
|
42626 | businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
|
42627 | id: businessObject.id + '_di'
|
42628 | });
|
42629 | } else
|
42630 | if (elementType === 'connection') {
|
42631 | businessObject.di = this._bpmnFactory.createDiEdge(businessObject, [], {
|
42632 | id: businessObject.id + '_di'
|
42633 | });
|
42634 | } else {
|
42635 | businessObject.di = this._bpmnFactory.createDiShape(businessObject, {}, {
|
42636 | id: businessObject.id + '_di'
|
42637 | });
|
42638 | }
|
42639 | }
|
42640 |
|
42641 | if (attrs.colors) {
|
42642 | assign(businessObject.di, attrs.colors);
|
42643 |
|
42644 | delete attrs.colors;
|
42645 | }
|
42646 |
|
42647 | applyAttributes(businessObject, attrs, [
|
42648 | 'processRef',
|
42649 | 'isInterrupting',
|
42650 | 'associationDirection',
|
42651 | 'isForCompensation'
|
42652 | ]);
|
42653 |
|
42654 | if (attrs.isExpanded) {
|
42655 | applyAttribute(businessObject.di, attrs, 'isExpanded');
|
42656 | }
|
42657 |
|
42658 | if (is$1(businessObject, 'bpmn:ExclusiveGateway')) {
|
42659 | businessObject.di.isMarkerVisible = true;
|
42660 | }
|
42661 |
|
42662 | var eventDefinitions,
|
42663 | newEventDefinition;
|
42664 |
|
42665 | if (attrs.eventDefinitionType) {
|
42666 | eventDefinitions = businessObject.get('eventDefinitions') || [];
|
42667 | newEventDefinition = this._moddle.create(attrs.eventDefinitionType);
|
42668 |
|
42669 | if (attrs.eventDefinitionType === 'bpmn:ConditionalEventDefinition') {
|
42670 | newEventDefinition.condition = this._moddle.create('bpmn:FormalExpression');
|
42671 | }
|
42672 |
|
42673 | eventDefinitions.push(newEventDefinition);
|
42674 |
|
42675 | newEventDefinition.$parent = businessObject;
|
42676 | businessObject.eventDefinitions = eventDefinitions;
|
42677 |
|
42678 | delete attrs.eventDefinitionType;
|
42679 | }
|
42680 |
|
42681 | size$$1 = this._getDefaultSize(businessObject);
|
42682 |
|
42683 | attrs = assign({
|
42684 | businessObject: businessObject,
|
42685 | id: businessObject.id
|
42686 | }, size$$1, attrs);
|
42687 |
|
42688 | return this.baseCreate(elementType, attrs);
|
42689 | };
|
42690 |
|
42691 |
|
42692 | ElementFactory$1.prototype._getDefaultSize = function(semantic) {
|
42693 |
|
42694 | if (is$1(semantic, 'bpmn:SubProcess')) {
|
42695 |
|
42696 | if (isExpanded(semantic)) {
|
42697 | return { width: 350, height: 200 };
|
42698 | } else {
|
42699 | return { width: 100, height: 80 };
|
42700 | }
|
42701 | }
|
42702 |
|
42703 | if (is$1(semantic, 'bpmn:Task')) {
|
42704 | return { width: 100, height: 80 };
|
42705 | }
|
42706 |
|
42707 | if (is$1(semantic, 'bpmn:Gateway')) {
|
42708 | return { width: 50, height: 50 };
|
42709 | }
|
42710 |
|
42711 | if (is$1(semantic, 'bpmn:Event')) {
|
42712 | return { width: 36, height: 36 };
|
42713 | }
|
42714 |
|
42715 | if (is$1(semantic, 'bpmn:Participant')) {
|
42716 | if (!isExpanded(semantic)) {
|
42717 | return { width: 400, height: 100 };
|
42718 | } else {
|
42719 | return { width: 600, height: 250 };
|
42720 | }
|
42721 | }
|
42722 |
|
42723 | if (is$1(semantic, 'bpmn:Lane')) {
|
42724 | return { width: 400, height: 100 };
|
42725 | }
|
42726 |
|
42727 | if (is$1(semantic, 'bpmn:DataObjectReference')) {
|
42728 | return { width: 36, height: 50 };
|
42729 | }
|
42730 |
|
42731 | if (is$1(semantic, 'bpmn:DataStoreReference')) {
|
42732 | return { width: 50, height: 50 };
|
42733 | }
|
42734 |
|
42735 | if (is$1(semantic, 'bpmn:TextAnnotation')) {
|
42736 | return { width: 100, height: 30 };
|
42737 | }
|
42738 |
|
42739 | return { width: 100, height: 80 };
|
42740 | };
|
42741 |
|
42742 |
|
42743 | ElementFactory$1.prototype.createParticipantShape = function(collapsed) {
|
42744 |
|
42745 | var attrs = { type: 'bpmn:Participant' };
|
42746 |
|
42747 | if (!collapsed) {
|
42748 | attrs.processRef = this._bpmnFactory.create('bpmn:Process');
|
42749 | }
|
42750 |
|
42751 | return this.createShape(attrs);
|
42752 | };
|
42753 |
|
42754 |
|
42755 |
|
42756 |
|
42757 | |
42758 |
|
42759 |
|
42760 |
|
42761 |
|
42762 |
|
42763 |
|
42764 |
|
42765 | function applyAttributes(element, attrs, attributeNames) {
|
42766 |
|
42767 | forEach(attributeNames, function(property) {
|
42768 | if (attrs[property] !== undefined) {
|
42769 | applyAttribute(element, attrs, property);
|
42770 | }
|
42771 | });
|
42772 | }
|
42773 |
|
42774 | |
42775 |
|
42776 |
|
42777 |
|
42778 |
|
42779 |
|
42780 |
|
42781 |
|
42782 | function applyAttribute(element, attrs, attributeName) {
|
42783 | element[attributeName] = attrs[attributeName];
|
42784 |
|
42785 | delete attrs[attributeName];
|
42786 | }
|
42787 |
|
42788 | |
42789 |
|
42790 |
|
42791 |
|
42792 |
|
42793 |
|
42794 |
|
42795 |
|
42796 | function AppendShapeHandler(modeling) {
|
42797 | this._modeling = modeling;
|
42798 | }
|
42799 |
|
42800 | AppendShapeHandler.$inject = [ 'modeling' ];
|
42801 |
|
42802 |
|
42803 |
|
42804 |
|
42805 |
|
42806 | |
42807 |
|
42808 |
|
42809 |
|
42810 |
|
42811 |
|
42812 |
|
42813 |
|
42814 |
|
42815 | AppendShapeHandler.prototype.preExecute = function(context) {
|
42816 |
|
42817 | var source = context.source;
|
42818 |
|
42819 | if (!source) {
|
42820 | throw new Error('source required');
|
42821 | }
|
42822 |
|
42823 | var target = context.target || source.parent,
|
42824 | shape = context.shape;
|
42825 |
|
42826 | shape = context.shape =
|
42827 | this._modeling.createShape(
|
42828 | shape,
|
42829 | context.position,
|
42830 | target, { attach: context.attach });
|
42831 |
|
42832 | context.shape = shape;
|
42833 | };
|
42834 |
|
42835 | AppendShapeHandler.prototype.postExecute = function(context) {
|
42836 | var parent = context.connectionParent || context.shape.parent;
|
42837 |
|
42838 | if (!existsConnection(context.source, context.shape)) {
|
42839 |
|
42840 |
|
42841 | this._modeling.connect(context.source, context.shape, context.connection, parent);
|
42842 | }
|
42843 | };
|
42844 |
|
42845 |
|
42846 | function existsConnection(source, target) {
|
42847 | return some(source.outgoing, function(c) {
|
42848 | return c.target === target;
|
42849 | });
|
42850 | }
|
42851 |
|
42852 | var round$7 = Math.round;
|
42853 |
|
42854 |
|
42855 | |
42856 |
|
42857 |
|
42858 |
|
42859 |
|
42860 | function CreateShapeHandler(canvas) {
|
42861 | this._canvas = canvas;
|
42862 | }
|
42863 |
|
42864 | CreateShapeHandler.$inject = [ 'canvas' ];
|
42865 |
|
42866 |
|
42867 |
|
42868 |
|
42869 |
|
42870 | |
42871 |
|
42872 |
|
42873 |
|
42874 |
|
42875 |
|
42876 |
|
42877 | CreateShapeHandler.prototype.execute = function(context) {
|
42878 |
|
42879 | var shape = context.shape,
|
42880 | positionOrBounds = context.position,
|
42881 | parent = context.parent,
|
42882 | parentIndex = context.parentIndex;
|
42883 |
|
42884 | if (!parent) {
|
42885 | throw new Error('parent required');
|
42886 | }
|
42887 |
|
42888 | if (!positionOrBounds) {
|
42889 | throw new Error('position required');
|
42890 | }
|
42891 |
|
42892 |
|
42893 | if (positionOrBounds.width !== undefined) {
|
42894 | assign(shape, positionOrBounds);
|
42895 | } else {
|
42896 | assign(shape, {
|
42897 | x: positionOrBounds.x - round$7(shape.width / 2),
|
42898 | y: positionOrBounds.y - round$7(shape.height / 2)
|
42899 | });
|
42900 | }
|
42901 |
|
42902 |
|
42903 | this._canvas.addShape(shape, parent, parentIndex);
|
42904 |
|
42905 | return shape;
|
42906 | };
|
42907 |
|
42908 |
|
42909 | |
42910 |
|
42911 |
|
42912 | CreateShapeHandler.prototype.revert = function(context) {
|
42913 |
|
42914 |
|
42915 | this._canvas.removeShape(context.shape);
|
42916 | };
|
42917 |
|
42918 | |
42919 |
|
42920 |
|
42921 |
|
42922 | function DeleteShapeHandler(canvas, modeling) {
|
42923 | this._canvas = canvas;
|
42924 | this._modeling = modeling;
|
42925 | }
|
42926 |
|
42927 | DeleteShapeHandler.$inject = [ 'canvas', 'modeling' ];
|
42928 |
|
42929 |
|
42930 | |
42931 |
|
42932 |
|
42933 |
|
42934 | DeleteShapeHandler.prototype.preExecute = function(context) {
|
42935 |
|
42936 | var modeling = this._modeling;
|
42937 |
|
42938 | var shape = context.shape;
|
42939 |
|
42940 |
|
42941 | saveClear(shape.incoming, function(connection) {
|
42942 |
|
42943 |
|
42944 | modeling.removeConnection(connection, { nested: true });
|
42945 | });
|
42946 |
|
42947 | saveClear(shape.outgoing, function(connection) {
|
42948 | modeling.removeConnection(connection, { nested: true });
|
42949 | });
|
42950 |
|
42951 |
|
42952 | saveClear(shape.children, function(child) {
|
42953 | if (isConnection$3(child)) {
|
42954 | modeling.removeConnection(child, { nested: true });
|
42955 | } else {
|
42956 | modeling.removeShape(child, { nested: true });
|
42957 | }
|
42958 | });
|
42959 | };
|
42960 |
|
42961 | |
42962 |
|
42963 |
|
42964 | DeleteShapeHandler.prototype.execute = function(context) {
|
42965 | var canvas = this._canvas;
|
42966 |
|
42967 | var shape = context.shape,
|
42968 | oldParent = shape.parent;
|
42969 |
|
42970 | context.oldParent = oldParent;
|
42971 |
|
42972 |
|
42973 | context.oldParentIndex = indexOf$1(oldParent.children, shape);
|
42974 |
|
42975 |
|
42976 | canvas.removeShape(shape);
|
42977 |
|
42978 | return shape;
|
42979 | };
|
42980 |
|
42981 |
|
42982 | |
42983 |
|
42984 |
|
42985 | DeleteShapeHandler.prototype.revert = function(context) {
|
42986 |
|
42987 | var canvas = this._canvas;
|
42988 |
|
42989 | var shape = context.shape,
|
42990 | oldParent = context.oldParent,
|
42991 | oldParentIndex = context.oldParentIndex;
|
42992 |
|
42993 |
|
42994 | add(oldParent.children, shape, oldParentIndex);
|
42995 |
|
42996 | canvas.addShape(shape, oldParent);
|
42997 |
|
42998 | return shape;
|
42999 | };
|
43000 |
|
43001 | function isConnection$3(element) {
|
43002 | return element.waypoints;
|
43003 | }
|
43004 |
|
43005 | function getResizedSourceAnchor(connection, shape, oldBounds) {
|
43006 |
|
43007 | var waypoints = safeGetWaypoints(connection),
|
43008 | oldAnchor = waypoints[0];
|
43009 |
|
43010 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
43011 | }
|
43012 |
|
43013 |
|
43014 | function getResizedTargetAnchor(connection, shape, oldBounds) {
|
43015 |
|
43016 | var waypoints = safeGetWaypoints(connection),
|
43017 | oldAnchor = waypoints[waypoints.length - 1];
|
43018 |
|
43019 | return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
|
43020 | }
|
43021 |
|
43022 |
|
43023 | function getMovedSourceAnchor(connection, source, moveDelta) {
|
43024 | return getResizedSourceAnchor(connection, source, substractPosition(source, moveDelta));
|
43025 | }
|
43026 |
|
43027 |
|
43028 | function getMovedTargetAnchor(connection, target, moveDelta) {
|
43029 | return getResizedTargetAnchor(connection, target, substractPosition(target, moveDelta));
|
43030 | }
|
43031 |
|
43032 |
|
43033 |
|
43034 |
|
43035 | function substractPosition(bounds, delta) {
|
43036 | return {
|
43037 | x: bounds.x - delta.x,
|
43038 | y: bounds.y - delta.y,
|
43039 | width: bounds.width,
|
43040 | height: bounds.height
|
43041 | };
|
43042 | }
|
43043 |
|
43044 |
|
43045 | |
43046 |
|
43047 |
|
43048 |
|
43049 |
|
43050 |
|
43051 |
|
43052 | function safeGetWaypoints(connection) {
|
43053 |
|
43054 | var waypoints = connection.waypoints;
|
43055 |
|
43056 | if (!waypoints.length) {
|
43057 | throw new Error('connection#' + connection.id + ': no waypoints');
|
43058 | }
|
43059 |
|
43060 | return waypoints;
|
43061 | }
|
43062 |
|
43063 | function MoveClosure() {
|
43064 |
|
43065 | this.allShapes = {};
|
43066 | this.allConnections = {};
|
43067 |
|
43068 | this.enclosedElements = {};
|
43069 | this.enclosedConnections = {};
|
43070 |
|
43071 | this.topLevel = {};
|
43072 | }
|
43073 |
|
43074 |
|
43075 | MoveClosure.prototype.add = function(element, isTopLevel) {
|
43076 | return this.addAll([ element ], isTopLevel);
|
43077 | };
|
43078 |
|
43079 |
|
43080 | MoveClosure.prototype.addAll = function(elements, isTopLevel) {
|
43081 |
|
43082 | var newClosure = getClosure(elements, !!isTopLevel, this);
|
43083 |
|
43084 | assign(this, newClosure);
|
43085 |
|
43086 | return this;
|
43087 | };
|
43088 |
|
43089 | |
43090 |
|
43091 |
|
43092 |
|
43093 |
|
43094 |
|
43095 | function MoveHelper(modeling) {
|
43096 | this._modeling = modeling;
|
43097 | }
|
43098 |
|
43099 | |
43100 |
|
43101 |
|
43102 |
|
43103 |
|
43104 |
|
43105 |
|
43106 |
|
43107 |
|
43108 |
|
43109 |
|
43110 |
|
43111 | MoveHelper.prototype.moveRecursive = function(elements, delta, newParent) {
|
43112 | if (!elements) {
|
43113 | return [];
|
43114 | } else {
|
43115 | return this.moveClosure(this.getClosure(elements), delta, newParent);
|
43116 | }
|
43117 | };
|
43118 |
|
43119 | |
43120 |
|
43121 |
|
43122 |
|
43123 |
|
43124 |
|
43125 |
|
43126 |
|
43127 | MoveHelper.prototype.moveClosure = function(closure, delta, newParent, newHost, primaryShape) {
|
43128 | var modeling = this._modeling;
|
43129 |
|
43130 | var allShapes = closure.allShapes,
|
43131 | allConnections = closure.allConnections,
|
43132 | enclosedConnections = closure.enclosedConnections,
|
43133 | topLevel = closure.topLevel,
|
43134 | keepParent = false;
|
43135 |
|
43136 | if (primaryShape && primaryShape.parent === newParent) {
|
43137 | keepParent = true;
|
43138 | }
|
43139 |
|
43140 |
|
43141 | forEach(allShapes, function(shape) {
|
43142 |
|
43143 |
|
43144 | modeling.moveShape(shape, delta, topLevel[shape.id] && !keepParent && newParent, {
|
43145 | recurse: false,
|
43146 | layout: false
|
43147 | });
|
43148 | });
|
43149 |
|
43150 |
|
43151 | forEach(allConnections, function(c) {
|
43152 |
|
43153 | var sourceMoved = !!allShapes[c.source.id],
|
43154 | targetMoved = !!allShapes[c.target.id];
|
43155 |
|
43156 | if (enclosedConnections[c.id] && sourceMoved && targetMoved) {
|
43157 | modeling.moveConnection(c, delta, topLevel[c.id] && !keepParent && newParent);
|
43158 | } else {
|
43159 | modeling.layoutConnection(c, {
|
43160 | connectionStart: sourceMoved && getMovedSourceAnchor(c, c.source, delta),
|
43161 | connectionEnd: targetMoved && getMovedTargetAnchor(c, c.target, delta)
|
43162 | });
|
43163 | }
|
43164 | });
|
43165 | };
|
43166 |
|
43167 | |
43168 |
|
43169 |
|
43170 |
|
43171 |
|
43172 |
|
43173 | MoveHelper.prototype.getClosure = function(elements) {
|
43174 | return new MoveClosure().addAll(elements, true);
|
43175 | };
|
43176 |
|
43177 | |
43178 |
|
43179 |
|
43180 | function MoveShapeHandler(modeling) {
|
43181 | this._modeling = modeling;
|
43182 |
|
43183 | this._helper = new MoveHelper(modeling);
|
43184 | }
|
43185 |
|
43186 | MoveShapeHandler.$inject = [ 'modeling' ];
|
43187 |
|
43188 |
|
43189 | MoveShapeHandler.prototype.execute = function(context) {
|
43190 |
|
43191 | var shape = context.shape,
|
43192 | delta = context.delta,
|
43193 | newParent = context.newParent || shape.parent,
|
43194 | newParentIndex = context.newParentIndex,
|
43195 | oldParent = shape.parent;
|
43196 |
|
43197 | context.oldBounds = pick(shape, [ 'x', 'y', 'width', 'height']);
|
43198 |
|
43199 |
|
43200 | context.oldParent = oldParent;
|
43201 | context.oldParentIndex = remove$2(oldParent.children, shape);
|
43202 |
|
43203 |
|
43204 | add(newParent.children, shape, newParentIndex);
|
43205 |
|
43206 |
|
43207 | assign(shape, {
|
43208 | parent: newParent,
|
43209 | x: shape.x + delta.x,
|
43210 | y: shape.y + delta.y
|
43211 | });
|
43212 |
|
43213 | return shape;
|
43214 | };
|
43215 |
|
43216 | MoveShapeHandler.prototype.postExecute = function(context) {
|
43217 |
|
43218 | var shape = context.shape,
|
43219 | delta = context.delta,
|
43220 | hints = context.hints;
|
43221 |
|
43222 | var modeling = this._modeling;
|
43223 |
|
43224 | if (hints.layout !== false) {
|
43225 |
|
43226 | forEach(shape.incoming, function(c) {
|
43227 | modeling.layoutConnection(c, {
|
43228 | connectionEnd: getMovedTargetAnchor(c, shape, delta)
|
43229 | });
|
43230 | });
|
43231 |
|
43232 | forEach(shape.outgoing, function(c) {
|
43233 | modeling.layoutConnection(c, {
|
43234 | connectionStart: getMovedSourceAnchor(c, shape, delta)
|
43235 | });
|
43236 | });
|
43237 | }
|
43238 |
|
43239 | if (hints.recurse !== false) {
|
43240 | this.moveChildren(context);
|
43241 | }
|
43242 | };
|
43243 |
|
43244 | MoveShapeHandler.prototype.revert = function(context) {
|
43245 |
|
43246 | var shape = context.shape,
|
43247 | oldParent = context.oldParent,
|
43248 | oldParentIndex = context.oldParentIndex,
|
43249 | delta = context.delta;
|
43250 |
|
43251 |
|
43252 | add(oldParent.children, shape, oldParentIndex);
|
43253 |
|
43254 |
|
43255 | assign(shape, {
|
43256 | parent: oldParent,
|
43257 | x: shape.x - delta.x,
|
43258 | y: shape.y - delta.y
|
43259 | });
|
43260 |
|
43261 | return shape;
|
43262 | };
|
43263 |
|
43264 | MoveShapeHandler.prototype.moveChildren = function(context) {
|
43265 |
|
43266 | var delta = context.delta,
|
43267 | shape = context.shape;
|
43268 |
|
43269 | this._helper.moveRecursive(shape.children, delta, null);
|
43270 | };
|
43271 |
|
43272 | MoveShapeHandler.prototype.getNewParent = function(context) {
|
43273 | return context.newParent || context.shape.parent;
|
43274 | };
|
43275 |
|
43276 | |
43277 |
|
43278 |
|
43279 |
|
43280 |
|
43281 | function ResizeShapeHandler(modeling) {
|
43282 | this._modeling = modeling;
|
43283 | }
|
43284 |
|
43285 | ResizeShapeHandler.$inject = [ 'modeling' ];
|
43286 |
|
43287 | |
43288 |
|
43289 |
|
43290 |
|
43291 |
|
43292 |
|
43293 |
|
43294 |
|
43295 |
|
43296 |
|
43297 |
|
43298 |
|
43299 | ResizeShapeHandler.prototype.execute = function(context) {
|
43300 | var shape = context.shape,
|
43301 | newBounds = context.newBounds,
|
43302 | minBounds = context.minBounds;
|
43303 |
|
43304 | if (newBounds.x === undefined || newBounds.y === undefined ||
|
43305 | newBounds.width === undefined || newBounds.height === undefined) {
|
43306 | throw new Error('newBounds must have {x, y, width, height} properties');
|
43307 | }
|
43308 |
|
43309 | if (minBounds && (newBounds.width < minBounds.width
|
43310 | || newBounds.height < minBounds.height)) {
|
43311 | throw new Error('width and height cannot be less than minimum height and width');
|
43312 | } else if (!minBounds
|
43313 | && newBounds.width < 10 || newBounds.height < 10) {
|
43314 | throw new Error('width and height cannot be less than 10px');
|
43315 | }
|
43316 |
|
43317 |
|
43318 | context.oldBounds = {
|
43319 | width: shape.width,
|
43320 | height: shape.height,
|
43321 | x: shape.x,
|
43322 | y: shape.y
|
43323 | };
|
43324 |
|
43325 |
|
43326 | assign(shape, {
|
43327 | width: newBounds.width,
|
43328 | height: newBounds.height,
|
43329 | x: newBounds.x,
|
43330 | y: newBounds.y
|
43331 | });
|
43332 |
|
43333 | return shape;
|
43334 | };
|
43335 |
|
43336 | ResizeShapeHandler.prototype.postExecute = function(context) {
|
43337 |
|
43338 | var shape = context.shape,
|
43339 | oldBounds = context.oldBounds;
|
43340 |
|
43341 | var modeling = this._modeling;
|
43342 |
|
43343 | forEach(shape.incoming, function(c) {
|
43344 | modeling.layoutConnection(c, {
|
43345 | connectionEnd: getResizedTargetAnchor(c, shape, oldBounds)
|
43346 | });
|
43347 | });
|
43348 |
|
43349 | forEach(shape.outgoing, function(c) {
|
43350 | modeling.layoutConnection(c, {
|
43351 | connectionStart: getResizedSourceAnchor(c, shape, oldBounds)
|
43352 | });
|
43353 | });
|
43354 |
|
43355 | };
|
43356 |
|
43357 | ResizeShapeHandler.prototype.revert = function(context) {
|
43358 |
|
43359 | var shape = context.shape,
|
43360 | oldBounds = context.oldBounds;
|
43361 |
|
43362 |
|
43363 | assign(shape, {
|
43364 | width: oldBounds.width,
|
43365 | height: oldBounds.height,
|
43366 | x: oldBounds.x,
|
43367 | y: oldBounds.y
|
43368 | });
|
43369 |
|
43370 | return shape;
|
43371 | };
|
43372 |
|
43373 | |
43374 |
|
43375 |
|
43376 |
|
43377 |
|
43378 |
|
43379 |
|
43380 |
|
43381 |
|
43382 |
|
43383 | function ReplaceShapeHandler(modeling, rules) {
|
43384 | this._modeling = modeling;
|
43385 | this._rules = rules;
|
43386 | }
|
43387 |
|
43388 | ReplaceShapeHandler.$inject = [ 'modeling', 'rules' ];
|
43389 |
|
43390 |
|
43391 |
|
43392 |
|
43393 |
|
43394 | |
43395 |
|
43396 |
|
43397 |
|
43398 |
|
43399 |
|
43400 |
|
43401 |
|
43402 |
|
43403 |
|
43404 | ReplaceShapeHandler.prototype.preExecute = function(context) {
|
43405 |
|
43406 | var self = this,
|
43407 | modeling = this._modeling,
|
43408 | rules = this._rules;
|
43409 |
|
43410 | var oldShape = context.oldShape,
|
43411 | newData = context.newData,
|
43412 | hints = context.hints,
|
43413 | newShape;
|
43414 |
|
43415 | function canReconnect(type, source, target, connection) {
|
43416 | return rules.allowed(type, {
|
43417 | source: source,
|
43418 | target: target,
|
43419 | connection: connection
|
43420 | });
|
43421 | }
|
43422 |
|
43423 |
|
43424 |
|
43425 |
|
43426 | var position = {
|
43427 | x: newData.x,
|
43428 | y: newData.y
|
43429 | };
|
43430 |
|
43431 | newShape = context.newShape =
|
43432 | context.newShape ||
|
43433 | self.createShape(newData, position, oldShape.parent, hints);
|
43434 |
|
43435 |
|
43436 |
|
43437 |
|
43438 | if (oldShape.host) {
|
43439 | modeling.updateAttachment(newShape, oldShape.host);
|
43440 | }
|
43441 |
|
43442 |
|
43443 |
|
43444 |
|
43445 | var children;
|
43446 |
|
43447 | if (hints.moveChildren !== false) {
|
43448 | children = oldShape.children.slice();
|
43449 |
|
43450 | modeling.moveElements(children, { x: 0, y: 0 }, newShape);
|
43451 | }
|
43452 |
|
43453 |
|
43454 |
|
43455 | var incoming = oldShape.incoming.slice(),
|
43456 | outgoing = oldShape.outgoing.slice();
|
43457 |
|
43458 | forEach(incoming, function(connection) {
|
43459 | var waypoints = connection.waypoints,
|
43460 | docking = waypoints[waypoints.length - 1],
|
43461 | source = connection.source,
|
43462 | allowed = canReconnect('connection.reconnectEnd', source, newShape, connection);
|
43463 |
|
43464 | if (allowed) {
|
43465 | self.reconnectEnd(connection, newShape, docking);
|
43466 | }
|
43467 | });
|
43468 |
|
43469 | forEach(outgoing, function(connection) {
|
43470 | var waypoints = connection.waypoints,
|
43471 | docking = waypoints[0],
|
43472 | target = connection.target,
|
43473 | allowed = canReconnect('connection.reconnectStart', newShape, target, connection);
|
43474 |
|
43475 | if (allowed) {
|
43476 | self.reconnectStart(connection, newShape, docking);
|
43477 | }
|
43478 |
|
43479 | });
|
43480 | };
|
43481 |
|
43482 |
|
43483 | ReplaceShapeHandler.prototype.postExecute = function(context) {
|
43484 | var modeling = this._modeling;
|
43485 |
|
43486 | var oldShape = context.oldShape,
|
43487 | newShape = context.newShape;
|
43488 |
|
43489 |
|
43490 | forEach(newShape.incoming, function(c) {
|
43491 | modeling.layoutConnection(c, { endChanged: true });
|
43492 | });
|
43493 |
|
43494 | forEach(newShape.outgoing, function(c) {
|
43495 | modeling.layoutConnection(c, { startChanged: true });
|
43496 | });
|
43497 |
|
43498 | modeling.removeShape(oldShape);
|
43499 | };
|
43500 |
|
43501 |
|
43502 | ReplaceShapeHandler.prototype.execute = function(context) {};
|
43503 |
|
43504 | ReplaceShapeHandler.prototype.revert = function(context) {};
|
43505 |
|
43506 |
|
43507 | ReplaceShapeHandler.prototype.createShape = function(shape, position, target, hints) {
|
43508 | var modeling = this._modeling;
|
43509 | return modeling.createShape(shape, position, target, hints);
|
43510 | };
|
43511 |
|
43512 |
|
43513 | ReplaceShapeHandler.prototype.reconnectStart = function(connection, newSource, dockingPoint) {
|
43514 | var modeling = this._modeling;
|
43515 | modeling.reconnectStart(connection, newSource, dockingPoint);
|
43516 | };
|
43517 |
|
43518 |
|
43519 | ReplaceShapeHandler.prototype.reconnectEnd = function(connection, newTarget, dockingPoint) {
|
43520 | var modeling = this._modeling;
|
43521 | modeling.reconnectEnd(connection, newTarget, dockingPoint);
|
43522 | };
|
43523 |
|
43524 | |
43525 |
|
43526 |
|
43527 |
|
43528 |
|
43529 |
|
43530 | function ToggleShapeCollapseHandler(modeling) {
|
43531 | this._modeling = modeling;
|
43532 | }
|
43533 |
|
43534 | ToggleShapeCollapseHandler.$inject = [ 'modeling' ];
|
43535 |
|
43536 |
|
43537 | ToggleShapeCollapseHandler.prototype.execute = function(context) {
|
43538 |
|
43539 | var shape = context.shape,
|
43540 | children = shape.children;
|
43541 |
|
43542 |
|
43543 | context.oldChildrenVisibility = getElementsVisibility(children);
|
43544 |
|
43545 |
|
43546 | shape.collapsed = !shape.collapsed;
|
43547 |
|
43548 |
|
43549 | setHidden(children, shape.collapsed);
|
43550 |
|
43551 | return [shape].concat(children);
|
43552 | };
|
43553 |
|
43554 |
|
43555 | ToggleShapeCollapseHandler.prototype.revert = function(context) {
|
43556 |
|
43557 | var shape = context.shape,
|
43558 | oldChildrenVisibility = context.oldChildrenVisibility;
|
43559 |
|
43560 | var children = shape.children;
|
43561 |
|
43562 |
|
43563 | restoreVisibility(children, oldChildrenVisibility);
|
43564 |
|
43565 |
|
43566 | shape.collapsed = !shape.collapsed;
|
43567 |
|
43568 | return [shape].concat(children);
|
43569 | };
|
43570 |
|
43571 |
|
43572 |
|
43573 |
|
43574 | |
43575 |
|
43576 |
|
43577 |
|
43578 |
|
43579 |
|
43580 |
|
43581 | function getElementsVisibility(elements) {
|
43582 |
|
43583 | var result = {};
|
43584 |
|
43585 | elements.forEach(function(e) {
|
43586 | result[e.id] = e.hidden;
|
43587 | });
|
43588 |
|
43589 | return result;
|
43590 | }
|
43591 |
|
43592 |
|
43593 | function setHidden(elements, newHidden) {
|
43594 | elements.forEach(function(element) {
|
43595 | element.hidden = newHidden;
|
43596 | });
|
43597 | }
|
43598 |
|
43599 | function restoreVisibility(elements, lastState) {
|
43600 | elements.forEach(function(e) {
|
43601 | e.hidden = lastState[e.id];
|
43602 | });
|
43603 | }
|
43604 |
|
43605 | |
43606 |
|
43607 |
|
43608 |
|
43609 |
|
43610 |
|
43611 |
|
43612 |
|
43613 | function SpaceToolHandler(modeling) {
|
43614 | this._modeling = modeling;
|
43615 | }
|
43616 |
|
43617 | SpaceToolHandler.$inject = [ 'modeling' ];
|
43618 |
|
43619 |
|
43620 | SpaceToolHandler.prototype.preExecute = function(context) {
|
43621 |
|
43622 |
|
43623 | var modeling = this._modeling,
|
43624 | resizingShapes = context.resizingShapes,
|
43625 | delta = context.delta,
|
43626 | direction = context.direction;
|
43627 |
|
43628 | forEach(resizingShapes, function(shape) {
|
43629 | var newBounds = resizeBounds$1(shape, direction, delta);
|
43630 |
|
43631 | modeling.resizeShape(shape, newBounds);
|
43632 | });
|
43633 | };
|
43634 |
|
43635 | SpaceToolHandler.prototype.postExecute = function(context) {
|
43636 |
|
43637 | var modeling = this._modeling,
|
43638 | movingShapes = context.movingShapes,
|
43639 | delta = context.delta;
|
43640 |
|
43641 | modeling.moveElements(movingShapes, delta, undefined, { autoResize: false, attach: false });
|
43642 | };
|
43643 |
|
43644 | SpaceToolHandler.prototype.execute = function(context) {};
|
43645 | SpaceToolHandler.prototype.revert = function(context) {};
|
43646 |
|
43647 | |
43648 |
|
43649 |
|
43650 |
|
43651 |
|
43652 | function CreateLabelHandler(canvas) {
|
43653 | CreateShapeHandler.call(this, canvas);
|
43654 | }
|
43655 |
|
43656 | inherits_browser(CreateLabelHandler, CreateShapeHandler);
|
43657 |
|
43658 | CreateLabelHandler.$inject = [ 'canvas' ];
|
43659 |
|
43660 |
|
43661 |
|
43662 |
|
43663 |
|
43664 | var originalExecute = CreateShapeHandler.prototype.execute;
|
43665 |
|
43666 | |
43667 |
|
43668 |
|
43669 |
|
43670 |
|
43671 |
|
43672 |
|
43673 |
|
43674 |
|
43675 |
|
43676 | CreateLabelHandler.prototype.execute = function(context) {
|
43677 |
|
43678 | var label = context.shape;
|
43679 |
|
43680 | ensureValidDimensions(label);
|
43681 |
|
43682 | label.labelTarget = context.labelTarget;
|
43683 |
|
43684 | return originalExecute.call(this, context);
|
43685 | };
|
43686 |
|
43687 | var originalRevert = CreateShapeHandler.prototype.revert;
|
43688 |
|
43689 | |
43690 |
|
43691 |
|
43692 | CreateLabelHandler.prototype.revert = function(context) {
|
43693 | context.shape.labelTarget = null;
|
43694 |
|
43695 | return originalRevert.call(this, context);
|
43696 | };
|
43697 |
|
43698 |
|
43699 |
|
43700 |
|
43701 | function ensureValidDimensions(label) {
|
43702 |
|
43703 | [ 'width', 'height' ].forEach(function(prop) {
|
43704 | if (typeof label[prop] === 'undefined') {
|
43705 | label[prop] = 0;
|
43706 | }
|
43707 | });
|
43708 | }
|
43709 |
|
43710 | function CreateConnectionHandler(canvas, layouter) {
|
43711 | this._canvas = canvas;
|
43712 | this._layouter = layouter;
|
43713 | }
|
43714 |
|
43715 | CreateConnectionHandler.$inject = [ 'canvas', 'layouter' ];
|
43716 |
|
43717 |
|
43718 |
|
43719 |
|
43720 |
|
43721 | |
43722 |
|
43723 |
|
43724 |
|
43725 |
|
43726 |
|
43727 |
|
43728 |
|
43729 | CreateConnectionHandler.prototype.execute = function(context) {
|
43730 |
|
43731 | var connection = context.connection,
|
43732 | source = context.source,
|
43733 | target = context.target,
|
43734 | parent = context.parent,
|
43735 | parentIndex = context.parentIndex,
|
43736 | hints = context.hints;
|
43737 |
|
43738 | if (!source || !target) {
|
43739 | throw new Error('source and target required');
|
43740 | }
|
43741 |
|
43742 | if (!parent) {
|
43743 | throw new Error('parent required');
|
43744 | }
|
43745 |
|
43746 | connection.source = source;
|
43747 | connection.target = target;
|
43748 |
|
43749 | if (!connection.waypoints) {
|
43750 | connection.waypoints = this._layouter.layoutConnection(connection, hints);
|
43751 | }
|
43752 |
|
43753 |
|
43754 | this._canvas.addConnection(connection, parent, parentIndex);
|
43755 |
|
43756 | return connection;
|
43757 | };
|
43758 |
|
43759 | CreateConnectionHandler.prototype.revert = function(context) {
|
43760 | var connection = context.connection;
|
43761 |
|
43762 | this._canvas.removeConnection(connection);
|
43763 |
|
43764 | connection.source = null;
|
43765 | connection.target = null;
|
43766 | };
|
43767 |
|
43768 | |
43769 |
|
43770 |
|
43771 | function DeleteConnectionHandler(canvas, modeling) {
|
43772 | this._canvas = canvas;
|
43773 | this._modeling = modeling;
|
43774 | }
|
43775 |
|
43776 | DeleteConnectionHandler.$inject = [
|
43777 | 'canvas',
|
43778 | 'modeling'
|
43779 | ];
|
43780 |
|
43781 |
|
43782 | DeleteConnectionHandler.prototype.execute = function(context) {
|
43783 |
|
43784 | var connection = context.connection,
|
43785 | parent = connection.parent;
|
43786 |
|
43787 | context.parent = parent;
|
43788 |
|
43789 |
|
43790 | context.parentIndex = indexOf$1(parent.children, connection);
|
43791 |
|
43792 | context.source = connection.source;
|
43793 | context.target = connection.target;
|
43794 |
|
43795 | this._canvas.removeConnection(connection);
|
43796 |
|
43797 | connection.source = null;
|
43798 | connection.target = null;
|
43799 |
|
43800 | return connection;
|
43801 | };
|
43802 |
|
43803 | |
43804 |
|
43805 |
|
43806 | DeleteConnectionHandler.prototype.revert = function(context) {
|
43807 |
|
43808 | var connection = context.connection,
|
43809 | parent = context.parent,
|
43810 | parentIndex = context.parentIndex;
|
43811 |
|
43812 | connection.source = context.source;
|
43813 | connection.target = context.target;
|
43814 |
|
43815 |
|
43816 | add(parent.children, connection, parentIndex);
|
43817 |
|
43818 | this._canvas.addConnection(connection, parent);
|
43819 |
|
43820 | return connection;
|
43821 | };
|
43822 |
|
43823 | |
43824 |
|
43825 |
|
43826 |
|
43827 |
|
43828 |
|
43829 | function MoveConnectionHandler() { }
|
43830 |
|
43831 |
|
43832 | MoveConnectionHandler.prototype.execute = function(context) {
|
43833 |
|
43834 | var connection = context.connection,
|
43835 | delta = context.delta;
|
43836 |
|
43837 | var newParent = context.newParent || connection.parent,
|
43838 | newParentIndex = context.newParentIndex,
|
43839 | oldParent = connection.parent;
|
43840 |
|
43841 |
|
43842 | context.oldParent = oldParent;
|
43843 | context.oldParentIndex = remove$2(oldParent.children, connection);
|
43844 |
|
43845 |
|
43846 | add(newParent.children, connection, newParentIndex);
|
43847 |
|
43848 |
|
43849 | connection.parent = newParent;
|
43850 |
|
43851 |
|
43852 | forEach(connection.waypoints, function(p) {
|
43853 | p.x += delta.x;
|
43854 | p.y += delta.y;
|
43855 |
|
43856 | if (p.original) {
|
43857 | p.original.x += delta.x;
|
43858 | p.original.y += delta.y;
|
43859 | }
|
43860 | });
|
43861 |
|
43862 | return connection;
|
43863 | };
|
43864 |
|
43865 | MoveConnectionHandler.prototype.revert = function(context) {
|
43866 |
|
43867 | var connection = context.connection,
|
43868 | newParent = connection.parent,
|
43869 | oldParent = context.oldParent,
|
43870 | oldParentIndex = context.oldParentIndex,
|
43871 | delta = context.delta;
|
43872 |
|
43873 |
|
43874 | remove$2(newParent.children, connection);
|
43875 |
|
43876 |
|
43877 | add(oldParent.children, connection, oldParentIndex);
|
43878 |
|
43879 |
|
43880 | connection.parent = oldParent;
|
43881 |
|
43882 |
|
43883 | forEach(connection.waypoints, function(p) {
|
43884 | p.x -= delta.x;
|
43885 | p.y -= delta.y;
|
43886 |
|
43887 | if (p.original) {
|
43888 | p.original.x -= delta.x;
|
43889 | p.original.y -= delta.y;
|
43890 | }
|
43891 | });
|
43892 |
|
43893 | return connection;
|
43894 | };
|
43895 |
|
43896 | |
43897 |
|
43898 |
|
43899 | function LayoutConnectionHandler(layouter, canvas) {
|
43900 | this._layouter = layouter;
|
43901 | this._canvas = canvas;
|
43902 | }
|
43903 |
|
43904 | LayoutConnectionHandler.$inject = [ 'layouter', 'canvas' ];
|
43905 |
|
43906 | LayoutConnectionHandler.prototype.execute = function(context) {
|
43907 |
|
43908 | var connection = context.connection;
|
43909 |
|
43910 | var oldWaypoints = connection.waypoints;
|
43911 |
|
43912 | assign(context, {
|
43913 | oldWaypoints: oldWaypoints
|
43914 | });
|
43915 |
|
43916 | connection.waypoints = this._layouter.layoutConnection(connection, context.hints);
|
43917 |
|
43918 | return connection;
|
43919 | };
|
43920 |
|
43921 | LayoutConnectionHandler.prototype.revert = function(context) {
|
43922 |
|
43923 | var connection = context.connection;
|
43924 |
|
43925 | connection.waypoints = context.oldWaypoints;
|
43926 |
|
43927 | return connection;
|
43928 | };
|
43929 |
|
43930 | function UpdateWaypointsHandler() { }
|
43931 |
|
43932 | UpdateWaypointsHandler.prototype.execute = function(context) {
|
43933 |
|
43934 | var connection = context.connection,
|
43935 | newWaypoints = context.newWaypoints;
|
43936 |
|
43937 | context.oldWaypoints = connection.waypoints;
|
43938 |
|
43939 | connection.waypoints = newWaypoints;
|
43940 |
|
43941 | return connection;
|
43942 | };
|
43943 |
|
43944 | UpdateWaypointsHandler.prototype.revert = function(context) {
|
43945 |
|
43946 | var connection = context.connection,
|
43947 | oldWaypoints = context.oldWaypoints;
|
43948 |
|
43949 | connection.waypoints = oldWaypoints;
|
43950 |
|
43951 | return connection;
|
43952 | };
|
43953 |
|
43954 | |
43955 |
|
43956 |
|
43957 | function ReconnectConnectionHandler() { }
|
43958 |
|
43959 | ReconnectConnectionHandler.$inject = [ ];
|
43960 |
|
43961 | ReconnectConnectionHandler.prototype.execute = function(context) {
|
43962 |
|
43963 | var newSource = context.newSource,
|
43964 | newTarget = context.newTarget,
|
43965 | connection = context.connection,
|
43966 | dockingOrPoints = context.dockingOrPoints,
|
43967 | oldWaypoints = connection.waypoints,
|
43968 | newWaypoints;
|
43969 |
|
43970 | if (!newSource && !newTarget) {
|
43971 | throw new Error('newSource or newTarget are required');
|
43972 | }
|
43973 |
|
43974 | if (newSource && newTarget) {
|
43975 | throw new Error('must specify either newSource or newTarget');
|
43976 | }
|
43977 |
|
43978 | context.oldWaypoints = oldWaypoints;
|
43979 |
|
43980 | if (isArray(dockingOrPoints)) {
|
43981 | newWaypoints = dockingOrPoints;
|
43982 | } else {
|
43983 | newWaypoints = oldWaypoints.slice();
|
43984 |
|
43985 | newWaypoints.splice(newSource ? 0 : -1, 1, dockingOrPoints);
|
43986 | }
|
43987 |
|
43988 | if (newSource) {
|
43989 | context.oldSource = connection.source;
|
43990 | connection.source = newSource;
|
43991 | }
|
43992 |
|
43993 | if (newTarget) {
|
43994 | context.oldTarget = connection.target;
|
43995 | connection.target = newTarget;
|
43996 | }
|
43997 |
|
43998 | connection.waypoints = newWaypoints;
|
43999 |
|
44000 | return connection;
|
44001 | };
|
44002 |
|
44003 | ReconnectConnectionHandler.prototype.revert = function(context) {
|
44004 |
|
44005 | var newSource = context.newSource,
|
44006 | newTarget = context.newTarget,
|
44007 | connection = context.connection;
|
44008 |
|
44009 | if (newSource) {
|
44010 | connection.source = context.oldSource;
|
44011 | }
|
44012 |
|
44013 | if (newTarget) {
|
44014 | connection.target = context.oldTarget;
|
44015 | }
|
44016 |
|
44017 | connection.waypoints = context.oldWaypoints;
|
44018 |
|
44019 | return connection;
|
44020 | };
|
44021 |
|
44022 | |
44023 |
|
44024 |
|
44025 | function MoveElementsHandler(modeling) {
|
44026 | this._helper = new MoveHelper(modeling);
|
44027 | }
|
44028 |
|
44029 | MoveElementsHandler.$inject = [ 'modeling' ];
|
44030 |
|
44031 | MoveElementsHandler.prototype.preExecute = function(context) {
|
44032 | context.closure = this._helper.getClosure(context.shapes);
|
44033 | };
|
44034 |
|
44035 | MoveElementsHandler.prototype.postExecute = function(context) {
|
44036 |
|
44037 | var hints = context.hints,
|
44038 | primaryShape;
|
44039 |
|
44040 | if (hints && hints.primaryShape) {
|
44041 | primaryShape = hints.primaryShape;
|
44042 | hints.oldParent = primaryShape.parent;
|
44043 | }
|
44044 |
|
44045 | this._helper.moveClosure(
|
44046 | context.closure,
|
44047 | context.delta,
|
44048 | context.newParent,
|
44049 | context.newHost,
|
44050 | primaryShape
|
44051 | );
|
44052 | };
|
44053 |
|
44054 | function DeleteElementsHandler(modeling, elementRegistry) {
|
44055 | this._modeling = modeling;
|
44056 | this._elementRegistry = elementRegistry;
|
44057 | }
|
44058 |
|
44059 | DeleteElementsHandler.$inject = [
|
44060 | 'modeling',
|
44061 | 'elementRegistry'
|
44062 | ];
|
44063 |
|
44064 |
|
44065 | DeleteElementsHandler.prototype.postExecute = function(context) {
|
44066 |
|
44067 | var modeling = this._modeling,
|
44068 | elementRegistry = this._elementRegistry,
|
44069 | elements = context.elements;
|
44070 |
|
44071 | forEach(elements, function(element) {
|
44072 |
|
44073 |
|
44074 |
|
44075 | if (!elementRegistry.get(element.id)) {
|
44076 | return;
|
44077 | }
|
44078 |
|
44079 | if (element.waypoints) {
|
44080 | modeling.removeConnection(element);
|
44081 | } else {
|
44082 | modeling.removeShape(element);
|
44083 | }
|
44084 | });
|
44085 | };
|
44086 |
|
44087 | |
44088 |
|
44089 |
|
44090 | function DistributeElements$1(modeling) {
|
44091 | this._modeling = modeling;
|
44092 | }
|
44093 |
|
44094 | DistributeElements$1.$inject = [ 'modeling' ];
|
44095 |
|
44096 | var OFF_AXIS = {
|
44097 | x: 'y',
|
44098 | y: 'x'
|
44099 | };
|
44100 |
|
44101 | DistributeElements$1.prototype.preExecute = function(context) {
|
44102 | var modeling = this._modeling;
|
44103 |
|
44104 | var groups = context.groups,
|
44105 | axis = context.axis,
|
44106 | dimension = context.dimension;
|
44107 |
|
44108 | function updateRange(group, element) {
|
44109 | group.range.min = Math.min(element[axis], group.range.min);
|
44110 | group.range.max = Math.max(element[axis] + element[dimension], group.range.max);
|
44111 | }
|
44112 |
|
44113 | function center(element) {
|
44114 | return element[axis] + element[dimension] / 2;
|
44115 | }
|
44116 |
|
44117 | function lastIdx(arr) {
|
44118 | return arr.length - 1;
|
44119 | }
|
44120 |
|
44121 | function rangeDiff(range) {
|
44122 | return range.max - range.min;
|
44123 | }
|
44124 |
|
44125 | function centerElement(refCenter, element) {
|
44126 | var delta = { y: 0 };
|
44127 |
|
44128 | delta[axis] = refCenter - center(element);
|
44129 |
|
44130 | if (delta[axis]) {
|
44131 |
|
44132 | delta[OFF_AXIS[axis]] = 0;
|
44133 |
|
44134 | modeling.moveElements([ element ], delta, element.parent);
|
44135 | }
|
44136 | }
|
44137 |
|
44138 | var firstGroup = groups[0],
|
44139 | lastGroupIdx = lastIdx(groups),
|
44140 | lastGroup = groups[ lastGroupIdx ];
|
44141 |
|
44142 | var margin,
|
44143 | spaceInBetween,
|
44144 | groupsSize = 0;
|
44145 |
|
44146 | forEach(groups, function(group, idx) {
|
44147 | var sortedElements,
|
44148 | refElem,
|
44149 | refCenter;
|
44150 |
|
44151 | if (group.elements.length < 2) {
|
44152 | if (idx && idx !== groups.length - 1) {
|
44153 | updateRange(group, group.elements[0]);
|
44154 |
|
44155 | groupsSize += rangeDiff(group.range);
|
44156 | }
|
44157 | return;
|
44158 | }
|
44159 |
|
44160 | sortedElements = sortBy(group.elements, axis);
|
44161 |
|
44162 | refElem = sortedElements[0];
|
44163 |
|
44164 | if (idx === lastGroupIdx) {
|
44165 | refElem = sortedElements[lastIdx(sortedElements)];
|
44166 | }
|
44167 |
|
44168 | refCenter = center(refElem);
|
44169 |
|
44170 |
|
44171 | group.range = null;
|
44172 |
|
44173 | forEach(sortedElements, function(element) {
|
44174 |
|
44175 | centerElement(refCenter, element);
|
44176 |
|
44177 | if (group.range === null) {
|
44178 | group.range = {
|
44179 | min: element[axis],
|
44180 | max: element[axis] + element[dimension]
|
44181 | };
|
44182 |
|
44183 | return;
|
44184 | }
|
44185 |
|
44186 |
|
44187 | updateRange(group, element);
|
44188 | });
|
44189 |
|
44190 | if (idx && idx !== groups.length - 1) {
|
44191 | groupsSize += rangeDiff(group.range);
|
44192 | }
|
44193 | });
|
44194 |
|
44195 | spaceInBetween = Math.abs(lastGroup.range.min - firstGroup.range.max);
|
44196 |
|
44197 | margin = Math.round((spaceInBetween - groupsSize) / (groups.length - 1));
|
44198 |
|
44199 | if (margin < groups.length - 1) {
|
44200 | return;
|
44201 | }
|
44202 |
|
44203 | forEach(groups, function(group, groupIdx) {
|
44204 | var delta = {},
|
44205 | prevGroup;
|
44206 |
|
44207 | if (group === firstGroup || group === lastGroup) {
|
44208 | return;
|
44209 | }
|
44210 |
|
44211 | prevGroup = groups[groupIdx - 1];
|
44212 |
|
44213 | group.range.max = 0;
|
44214 |
|
44215 | forEach(group.elements, function(element, idx) {
|
44216 | delta[OFF_AXIS[axis]] = 0;
|
44217 | delta[axis] = (prevGroup.range.max - element[axis]) + margin;
|
44218 |
|
44219 | if (group.range.min !== element[axis]) {
|
44220 | delta[axis] += element[axis] - group.range.min;
|
44221 | }
|
44222 |
|
44223 | if (delta[axis]) {
|
44224 | modeling.moveElements([ element ], delta, element.parent);
|
44225 | }
|
44226 |
|
44227 | group.range.max = Math.max(element[axis] + element[dimension], idx ? group.range.max : 0);
|
44228 | });
|
44229 | });
|
44230 | };
|
44231 |
|
44232 | DistributeElements$1.prototype.postExecute = function(context) {
|
44233 |
|
44234 | };
|
44235 |
|
44236 | |
44237 |
|
44238 |
|
44239 |
|
44240 | function AlignElements$1(modeling, canvas) {
|
44241 | this._modeling = modeling;
|
44242 | this._canvas = canvas;
|
44243 | }
|
44244 |
|
44245 | AlignElements$1.$inject = [ 'modeling', 'canvas' ];
|
44246 |
|
44247 |
|
44248 | AlignElements$1.prototype.preExecute = function(context) {
|
44249 | var modeling = this._modeling;
|
44250 |
|
44251 | var elements = context.elements,
|
44252 | alignment = context.alignment;
|
44253 |
|
44254 |
|
44255 | forEach(elements, function(element) {
|
44256 | var delta = {
|
44257 | x: 0,
|
44258 | y: 0
|
44259 | };
|
44260 |
|
44261 | if (alignment.left) {
|
44262 | delta.x = alignment.left - element.x;
|
44263 |
|
44264 | } else if (alignment.right) {
|
44265 | delta.x = (alignment.right - element.width) - element.x;
|
44266 |
|
44267 | } else if (alignment.center) {
|
44268 | delta.x = (alignment.center - Math.round(element.width / 2)) - element.x;
|
44269 |
|
44270 | } else if (alignment.top) {
|
44271 | delta.y = alignment.top - element.y;
|
44272 |
|
44273 | } else if (alignment.bottom) {
|
44274 | delta.y = (alignment.bottom - element.height) - element.y;
|
44275 |
|
44276 | } else if (alignment.middle) {
|
44277 | delta.y = (alignment.middle - Math.round(element.height / 2)) - element.y;
|
44278 | }
|
44279 |
|
44280 | modeling.moveElements([ element ], delta, element.parent);
|
44281 | });
|
44282 | };
|
44283 |
|
44284 | AlignElements$1.prototype.postExecute = function(context) {
|
44285 |
|
44286 | };
|
44287 |
|
44288 | |
44289 |
|
44290 |
|
44291 | function UpdateAttachmentHandler(modeling) {
|
44292 | this._modeling = modeling;
|
44293 | }
|
44294 |
|
44295 | UpdateAttachmentHandler.$inject = [ 'modeling' ];
|
44296 |
|
44297 |
|
44298 | UpdateAttachmentHandler.prototype.execute = function(context) {
|
44299 | var shape = context.shape,
|
44300 | newHost = context.newHost,
|
44301 | oldHost = shape.host;
|
44302 |
|
44303 |
|
44304 | context.oldHost = oldHost;
|
44305 | context.attacherIdx = removeAttacher(oldHost, shape);
|
44306 |
|
44307 |
|
44308 | addAttacher(newHost, shape);
|
44309 |
|
44310 |
|
44311 | shape.host = newHost;
|
44312 |
|
44313 | return shape;
|
44314 | };
|
44315 |
|
44316 | UpdateAttachmentHandler.prototype.revert = function(context) {
|
44317 | var shape = context.shape,
|
44318 | newHost = context.newHost,
|
44319 | oldHost = context.oldHost,
|
44320 | attacherIdx = context.attacherIdx;
|
44321 |
|
44322 |
|
44323 | shape.host = oldHost;
|
44324 |
|
44325 |
|
44326 | removeAttacher(newHost, shape);
|
44327 |
|
44328 |
|
44329 | addAttacher(oldHost, shape, attacherIdx);
|
44330 |
|
44331 | return shape;
|
44332 | };
|
44333 |
|
44334 |
|
44335 | function removeAttacher(host, attacher) {
|
44336 |
|
44337 | return remove$2(host && host.attachers, attacher);
|
44338 | }
|
44339 |
|
44340 | function addAttacher(host, attacher, idx) {
|
44341 |
|
44342 | if (!host) {
|
44343 | return;
|
44344 | }
|
44345 |
|
44346 | var attachers = host.attachers;
|
44347 |
|
44348 | if (!attachers) {
|
44349 | host.attachers = attachers = [];
|
44350 | }
|
44351 |
|
44352 | add(attachers, attacher, idx);
|
44353 | }
|
44354 |
|
44355 | function removeProperties$1(element, properties) {
|
44356 | forEach(properties, function(prop) {
|
44357 | if (element[prop]) {
|
44358 | delete element[prop];
|
44359 | }
|
44360 | });
|
44361 | }
|
44362 |
|
44363 | |
44364 |
|
44365 |
|
44366 |
|
44367 |
|
44368 |
|
44369 |
|
44370 |
|
44371 |
|
44372 |
|
44373 | function PasteHandler(
|
44374 | eventBus, canvas, selection,
|
44375 | elementFactory, modeling, rules) {
|
44376 |
|
44377 | this._eventBus = eventBus;
|
44378 | this._canvas = canvas;
|
44379 | this._selection = selection;
|
44380 | this._elementFactory = elementFactory;
|
44381 | this._modeling = modeling;
|
44382 | this._rules = rules;
|
44383 | }
|
44384 |
|
44385 |
|
44386 | PasteHandler.$inject = [
|
44387 | 'eventBus',
|
44388 | 'canvas',
|
44389 | 'selection',
|
44390 | 'elementFactory',
|
44391 | 'modeling',
|
44392 | 'rules'
|
44393 | ];
|
44394 |
|
44395 |
|
44396 |
|
44397 |
|
44398 | |
44399 |
|
44400 |
|
44401 |
|
44402 |
|
44403 |
|
44404 |
|
44405 | PasteHandler.prototype.preExecute = function(context) {
|
44406 | var eventBus = this._eventBus,
|
44407 | self = this;
|
44408 |
|
44409 | var tree = context.tree,
|
44410 | topParent = context.topParent,
|
44411 | position = context.position;
|
44412 |
|
44413 | tree.createdElements = {};
|
44414 |
|
44415 | tree.labels = [];
|
44416 |
|
44417 | forEach(tree, function(elements, depthStr) {
|
44418 | var depth = parseInt(depthStr, 10);
|
44419 |
|
44420 | if (isNaN(depth)) {
|
44421 | return;
|
44422 | }
|
44423 |
|
44424 |
|
44425 | if (!depth) {
|
44426 | elements = map(elements, function(descriptor) {
|
44427 | descriptor.parent = topParent;
|
44428 |
|
44429 | return descriptor;
|
44430 | });
|
44431 | }
|
44432 |
|
44433 |
|
44434 | elements = sortBy(elements, 'priority');
|
44435 |
|
44436 | forEach(elements, function(descriptor) {
|
44437 | var id = descriptor.id,
|
44438 | parent = descriptor.parent,
|
44439 | hints = {},
|
44440 | newPosition;
|
44441 |
|
44442 | var element = assign({}, descriptor);
|
44443 |
|
44444 | if (depth) {
|
44445 | element.parent = self._getCreatedElement(parent, tree);
|
44446 | }
|
44447 |
|
44448 |
|
44449 | if (!parent) {
|
44450 | return;
|
44451 | }
|
44452 |
|
44453 | eventBus.fire('element.paste', {
|
44454 | createdElements: tree.createdElements,
|
44455 | descriptor: element
|
44456 | });
|
44457 |
|
44458 |
|
44459 | parent = element.parent;
|
44460 |
|
44461 | if (element.waypoints) {
|
44462 | element = self._createConnection(element, parent, position, tree);
|
44463 |
|
44464 | if (element) {
|
44465 | tree.createdElements[id] = {
|
44466 | element: element,
|
44467 | descriptor: descriptor
|
44468 | };
|
44469 | }
|
44470 |
|
44471 | return;
|
44472 | }
|
44473 |
|
44474 |
|
44475 |
|
44476 | if (element.parent !== topParent) {
|
44477 | hints.root = false;
|
44478 | }
|
44479 |
|
44480 |
|
44481 | if (element.host) {
|
44482 | hints.attach = true;
|
44483 |
|
44484 | parent = self._getCreatedElement(element.host, tree);
|
44485 | }
|
44486 |
|
44487 |
|
44488 | if (element.labelTarget) {
|
44489 | return tree.labels.push(element);
|
44490 | }
|
44491 |
|
44492 | newPosition = {
|
44493 | x: Math.round(position.x + element.delta.x + (element.width / 2)),
|
44494 | y: Math.round(position.y + element.delta.y + (element.height / 2))
|
44495 | };
|
44496 |
|
44497 | removeProperties$1(element, [
|
44498 | 'id',
|
44499 | 'parent',
|
44500 | 'delta',
|
44501 | 'host',
|
44502 | 'priority'
|
44503 | ]);
|
44504 |
|
44505 | element = self._createShape(element, parent, newPosition, hints);
|
44506 |
|
44507 | if (element) {
|
44508 | tree.createdElements[id] = {
|
44509 | element: element,
|
44510 | descriptor: descriptor
|
44511 | };
|
44512 | }
|
44513 | });
|
44514 | });
|
44515 | };
|
44516 |
|
44517 |
|
44518 | PasteHandler.prototype.postExecute = function(context) {
|
44519 | var modeling = this._modeling,
|
44520 | selection = this._selection,
|
44521 | self = this;
|
44522 |
|
44523 | var tree = context.tree,
|
44524 | labels = tree.labels,
|
44525 | topLevelElements = [];
|
44526 |
|
44527 | forEach(labels, function(labelDescriptor) {
|
44528 | var labelTarget = self._getCreatedElement(labelDescriptor.labelTarget, tree),
|
44529 | labels, labelTargetPos, newPosition;
|
44530 |
|
44531 | if (!labelTarget) {
|
44532 | return;
|
44533 | }
|
44534 |
|
44535 | labels = labelTarget.labels;
|
44536 |
|
44537 | if (!labels || !labels.length) {
|
44538 | return;
|
44539 | }
|
44540 |
|
44541 | labelTargetPos = {
|
44542 | x: labelTarget.x,
|
44543 | y: labelTarget.y
|
44544 | };
|
44545 |
|
44546 | if (labelTarget.waypoints) {
|
44547 | labelTargetPos = labelTarget.waypoints[0];
|
44548 | }
|
44549 |
|
44550 | forEach(labels, function(label) {
|
44551 | newPosition = {
|
44552 | x: Math.round((labelTargetPos.x - label.x) + labelDescriptor.delta.x),
|
44553 | y: Math.round((labelTargetPos.y - label.y) + labelDescriptor.delta.y)
|
44554 | };
|
44555 |
|
44556 | modeling.moveShape(label, newPosition, labelTarget.parent);
|
44557 | });
|
44558 | });
|
44559 |
|
44560 | forEach(tree[0], function(descriptor) {
|
44561 | var id = descriptor.id,
|
44562 | toplevel = tree.createdElements[id];
|
44563 |
|
44564 | if (toplevel) {
|
44565 | topLevelElements.push(toplevel.element);
|
44566 | }
|
44567 | });
|
44568 |
|
44569 | selection.select(topLevelElements);
|
44570 | };
|
44571 |
|
44572 |
|
44573 | PasteHandler.prototype._createConnection = function(element, parent, parentCenter, tree) {
|
44574 | var modeling = this._modeling,
|
44575 | rules = this._rules;
|
44576 |
|
44577 | var connection, source, target, canPaste;
|
44578 |
|
44579 | element.waypoints = map(element.waypoints, function(waypoint, idx) {
|
44580 | return {
|
44581 | x: Math.round(parentCenter.x + element.delta[idx].x),
|
44582 | y: Math.round(parentCenter.y + element.delta[idx].y)
|
44583 | };
|
44584 | });
|
44585 |
|
44586 | source = this._getCreatedElement(element.source, tree);
|
44587 | target = this._getCreatedElement(element.target, tree);
|
44588 |
|
44589 | if (!source || !target) {
|
44590 | return null;
|
44591 | }
|
44592 |
|
44593 | canPaste = rules.allowed('element.paste', {
|
44594 | source: source,
|
44595 | target: target
|
44596 | });
|
44597 |
|
44598 | if (!canPaste) {
|
44599 | return null;
|
44600 | }
|
44601 |
|
44602 | removeProperties$1(element, [
|
44603 | 'id',
|
44604 | 'parent',
|
44605 | 'delta',
|
44606 | 'source',
|
44607 | 'target',
|
44608 | 'width',
|
44609 | 'height',
|
44610 | 'priority'
|
44611 | ]);
|
44612 |
|
44613 | connection = modeling.createConnection(source, target, element, parent);
|
44614 |
|
44615 | return connection;
|
44616 | };
|
44617 |
|
44618 |
|
44619 | PasteHandler.prototype._createShape = function(element, parent, position, isAttach, hints) {
|
44620 | var modeling = this._modeling,
|
44621 | elementFactory = this._elementFactory,
|
44622 | rules = this._rules;
|
44623 |
|
44624 | var canPaste = rules.allowed('element.paste', {
|
44625 | element: element,
|
44626 | position: position,
|
44627 | parent: parent
|
44628 | });
|
44629 |
|
44630 | if (!canPaste) {
|
44631 | return null;
|
44632 | }
|
44633 |
|
44634 | var shape = elementFactory.createShape(element);
|
44635 |
|
44636 | modeling.createShape(shape, position, parent, isAttach, hints);
|
44637 |
|
44638 | return shape;
|
44639 | };
|
44640 |
|
44641 |
|
44642 | PasteHandler.prototype._getCreatedElement = function(id, tree) {
|
44643 | return tree.createdElements[id] && tree.createdElements[id].element;
|
44644 | };
|
44645 |
|
44646 | |
44647 |
|
44648 |
|
44649 |
|
44650 |
|
44651 |
|
44652 |
|
44653 | function Modeling(eventBus, elementFactory, commandStack) {
|
44654 | this._eventBus = eventBus;
|
44655 | this._elementFactory = elementFactory;
|
44656 | this._commandStack = commandStack;
|
44657 |
|
44658 | var self = this;
|
44659 |
|
44660 | eventBus.on('diagram.init', function() {
|
44661 |
|
44662 | self.registerHandlers(commandStack);
|
44663 | });
|
44664 | }
|
44665 |
|
44666 | Modeling.$inject = [ 'eventBus', 'elementFactory', 'commandStack' ];
|
44667 |
|
44668 |
|
44669 | Modeling.prototype.getHandlers = function() {
|
44670 | return {
|
44671 | 'shape.append': AppendShapeHandler,
|
44672 | 'shape.create': CreateShapeHandler,
|
44673 | 'shape.delete': DeleteShapeHandler,
|
44674 | 'shape.move': MoveShapeHandler,
|
44675 | 'shape.resize': ResizeShapeHandler,
|
44676 | 'shape.replace': ReplaceShapeHandler,
|
44677 | 'shape.toggleCollapse': ToggleShapeCollapseHandler,
|
44678 |
|
44679 | 'spaceTool': SpaceToolHandler,
|
44680 |
|
44681 | 'label.create': CreateLabelHandler,
|
44682 |
|
44683 | 'connection.create': CreateConnectionHandler,
|
44684 | 'connection.delete': DeleteConnectionHandler,
|
44685 | 'connection.move': MoveConnectionHandler,
|
44686 | 'connection.layout': LayoutConnectionHandler,
|
44687 |
|
44688 | 'connection.updateWaypoints': UpdateWaypointsHandler,
|
44689 |
|
44690 | 'connection.reconnectStart': ReconnectConnectionHandler,
|
44691 | 'connection.reconnectEnd': ReconnectConnectionHandler,
|
44692 |
|
44693 | 'elements.move': MoveElementsHandler,
|
44694 | 'elements.delete': DeleteElementsHandler,
|
44695 |
|
44696 | 'elements.distribute': DistributeElements$1,
|
44697 | 'elements.align': AlignElements$1,
|
44698 |
|
44699 | 'element.updateAttachment': UpdateAttachmentHandler,
|
44700 |
|
44701 | 'elements.paste': PasteHandler
|
44702 | };
|
44703 | };
|
44704 |
|
44705 | |
44706 |
|
44707 |
|
44708 |
|
44709 |
|
44710 | Modeling.prototype.registerHandlers = function(commandStack) {
|
44711 | forEach(this.getHandlers(), function(handler, id) {
|
44712 | commandStack.registerHandler(id, handler);
|
44713 | });
|
44714 | };
|
44715 |
|
44716 |
|
44717 |
|
44718 |
|
44719 | Modeling.prototype.moveShape = function(shape, delta, newParent, newParentIndex, hints) {
|
44720 |
|
44721 | if (typeof newParentIndex === 'object') {
|
44722 | hints = newParentIndex;
|
44723 | newParentIndex = null;
|
44724 | }
|
44725 |
|
44726 | var context = {
|
44727 | shape: shape,
|
44728 | delta: delta,
|
44729 | newParent: newParent,
|
44730 | newParentIndex: newParentIndex,
|
44731 | hints: hints || {}
|
44732 | };
|
44733 |
|
44734 | this._commandStack.execute('shape.move', context);
|
44735 | };
|
44736 |
|
44737 |
|
44738 | |
44739 |
|
44740 |
|
44741 |
|
44742 |
|
44743 |
|
44744 | Modeling.prototype.updateAttachment = function(shape, newHost) {
|
44745 | var context = {
|
44746 | shape: shape,
|
44747 | newHost: newHost
|
44748 | };
|
44749 |
|
44750 | this._commandStack.execute('element.updateAttachment', context);
|
44751 | };
|
44752 |
|
44753 |
|
44754 | |
44755 |
|
44756 |
|
44757 |
|
44758 |
|
44759 |
|
44760 |
|
44761 |
|
44762 |
|
44763 |
|
44764 | Modeling.prototype.moveElements = function(shapes, delta, target, hints) {
|
44765 |
|
44766 | hints = hints || {};
|
44767 |
|
44768 | var attach = hints.attach;
|
44769 |
|
44770 | var newParent = target,
|
44771 | newHost;
|
44772 |
|
44773 | if (attach === true) {
|
44774 | newHost = target;
|
44775 | newParent = target.parent;
|
44776 | } else
|
44777 |
|
44778 | if (attach === false) {
|
44779 | newHost = null;
|
44780 | }
|
44781 |
|
44782 | var context = {
|
44783 | shapes: shapes,
|
44784 | delta: delta,
|
44785 | newParent: newParent,
|
44786 | newHost: newHost,
|
44787 | hints: hints
|
44788 | };
|
44789 |
|
44790 | this._commandStack.execute('elements.move', context);
|
44791 | };
|
44792 |
|
44793 |
|
44794 | Modeling.prototype.moveConnection = function(connection, delta, newParent, newParentIndex, hints) {
|
44795 |
|
44796 | if (typeof newParentIndex === 'object') {
|
44797 | hints = newParentIndex;
|
44798 | newParentIndex = undefined;
|
44799 | }
|
44800 |
|
44801 | var context = {
|
44802 | connection: connection,
|
44803 | delta: delta,
|
44804 | newParent: newParent,
|
44805 | newParentIndex: newParentIndex,
|
44806 | hints: hints || {}
|
44807 | };
|
44808 |
|
44809 | this._commandStack.execute('connection.move', context);
|
44810 | };
|
44811 |
|
44812 |
|
44813 | Modeling.prototype.layoutConnection = function(connection, hints) {
|
44814 | var context = {
|
44815 | connection: connection,
|
44816 | hints: hints || {}
|
44817 | };
|
44818 |
|
44819 | this._commandStack.execute('connection.layout', context);
|
44820 | };
|
44821 |
|
44822 |
|
44823 | |
44824 |
|
44825 |
|
44826 |
|
44827 |
|
44828 |
|
44829 |
|
44830 |
|
44831 |
|
44832 |
|
44833 |
|
44834 |
|
44835 | Modeling.prototype.createConnection = function(source, target, parentIndex, connection, parent, hints) {
|
44836 |
|
44837 | if (typeof parentIndex === 'object') {
|
44838 | hints = parent;
|
44839 | parent = connection;
|
44840 | connection = parentIndex;
|
44841 | parentIndex = undefined;
|
44842 | }
|
44843 |
|
44844 | connection = this._create('connection', connection);
|
44845 |
|
44846 | var context = {
|
44847 | source: source,
|
44848 | target: target,
|
44849 | parent: parent,
|
44850 | parentIndex: parentIndex,
|
44851 | connection: connection,
|
44852 | hints: hints
|
44853 | };
|
44854 |
|
44855 | this._commandStack.execute('connection.create', context);
|
44856 |
|
44857 | return context.connection;
|
44858 | };
|
44859 |
|
44860 |
|
44861 | |
44862 |
|
44863 |
|
44864 |
|
44865 |
|
44866 |
|
44867 |
|
44868 |
|
44869 |
|
44870 |
|
44871 |
|
44872 |
|
44873 | Modeling.prototype.createShape = function(shape, position, target, parentIndex, hints) {
|
44874 |
|
44875 | if (typeof parentIndex !== 'number') {
|
44876 | hints = parentIndex;
|
44877 | parentIndex = undefined;
|
44878 | }
|
44879 |
|
44880 | hints = hints || {};
|
44881 |
|
44882 | var attach = hints.attach,
|
44883 | parent,
|
44884 | host;
|
44885 |
|
44886 | shape = this._create('shape', shape);
|
44887 |
|
44888 | if (attach) {
|
44889 | parent = target.parent;
|
44890 | host = target;
|
44891 | } else {
|
44892 | parent = target;
|
44893 | }
|
44894 |
|
44895 | var context = {
|
44896 | position: position,
|
44897 | shape: shape,
|
44898 | parent: parent,
|
44899 | parentIndex: parentIndex,
|
44900 | host: host,
|
44901 | hints: hints
|
44902 | };
|
44903 |
|
44904 | this._commandStack.execute('shape.create', context);
|
44905 |
|
44906 | return context.shape;
|
44907 | };
|
44908 |
|
44909 |
|
44910 | Modeling.prototype.createLabel = function(labelTarget, position, label, parent) {
|
44911 |
|
44912 | label = this._create('label', label);
|
44913 |
|
44914 | var context = {
|
44915 | labelTarget: labelTarget,
|
44916 | position: position,
|
44917 | parent: parent || labelTarget.parent,
|
44918 | shape: label
|
44919 | };
|
44920 |
|
44921 | this._commandStack.execute('label.create', context);
|
44922 |
|
44923 | return context.shape;
|
44924 | };
|
44925 |
|
44926 |
|
44927 | |
44928 |
|
44929 |
|
44930 |
|
44931 |
|
44932 |
|
44933 |
|
44934 |
|
44935 |
|
44936 |
|
44937 |
|
44938 |
|
44939 |
|
44940 |
|
44941 |
|
44942 | Modeling.prototype.appendShape = function(source, shape, position, target, hints) {
|
44943 |
|
44944 | hints = hints || {};
|
44945 |
|
44946 | shape = this._create('shape', shape);
|
44947 |
|
44948 | var context = {
|
44949 | source: source,
|
44950 | position: position,
|
44951 | target: target,
|
44952 | shape: shape,
|
44953 | connection: hints.connection,
|
44954 | connectionParent: hints.connectionParent,
|
44955 | attach: hints.attach
|
44956 | };
|
44957 |
|
44958 | this._commandStack.execute('shape.append', context);
|
44959 |
|
44960 | return context.shape;
|
44961 | };
|
44962 |
|
44963 |
|
44964 | Modeling.prototype.removeElements = function(elements) {
|
44965 | var context = {
|
44966 | elements: elements
|
44967 | };
|
44968 |
|
44969 | this._commandStack.execute('elements.delete', context);
|
44970 | };
|
44971 |
|
44972 |
|
44973 | Modeling.prototype.distributeElements = function(groups, axis, dimension) {
|
44974 | var context = {
|
44975 | groups: groups,
|
44976 | axis: axis,
|
44977 | dimension: dimension
|
44978 | };
|
44979 |
|
44980 | this._commandStack.execute('elements.distribute', context);
|
44981 | };
|
44982 |
|
44983 |
|
44984 | Modeling.prototype.removeShape = function(shape, hints) {
|
44985 | var context = {
|
44986 | shape: shape,
|
44987 | hints: hints || {}
|
44988 | };
|
44989 |
|
44990 | this._commandStack.execute('shape.delete', context);
|
44991 | };
|
44992 |
|
44993 |
|
44994 | Modeling.prototype.removeConnection = function(connection, hints) {
|
44995 | var context = {
|
44996 | connection: connection,
|
44997 | hints: hints || {}
|
44998 | };
|
44999 |
|
45000 | this._commandStack.execute('connection.delete', context);
|
45001 | };
|
45002 |
|
45003 | Modeling.prototype.replaceShape = function(oldShape, newShape, hints) {
|
45004 | var context = {
|
45005 | oldShape: oldShape,
|
45006 | newData: newShape,
|
45007 | hints: hints || {}
|
45008 | };
|
45009 |
|
45010 | this._commandStack.execute('shape.replace', context);
|
45011 |
|
45012 | return context.newShape;
|
45013 | };
|
45014 |
|
45015 | Modeling.prototype.pasteElements = function(tree, topParent, position) {
|
45016 | var context = {
|
45017 | tree: tree,
|
45018 | topParent: topParent,
|
45019 | position: position
|
45020 | };
|
45021 |
|
45022 | this._commandStack.execute('elements.paste', context);
|
45023 | };
|
45024 |
|
45025 | Modeling.prototype.alignElements = function(elements, alignment) {
|
45026 | var context = {
|
45027 | elements: elements,
|
45028 | alignment: alignment
|
45029 | };
|
45030 |
|
45031 | this._commandStack.execute('elements.align', context);
|
45032 | };
|
45033 |
|
45034 | Modeling.prototype.resizeShape = function(shape, newBounds, minBounds) {
|
45035 | var context = {
|
45036 | shape: shape,
|
45037 | newBounds: newBounds,
|
45038 | minBounds: minBounds
|
45039 | };
|
45040 |
|
45041 | this._commandStack.execute('shape.resize', context);
|
45042 | };
|
45043 |
|
45044 | Modeling.prototype.createSpace = function(movingShapes, resizingShapes, delta, direction) {
|
45045 | var context = {
|
45046 | movingShapes: movingShapes,
|
45047 | resizingShapes: resizingShapes,
|
45048 | delta: delta,
|
45049 | direction: direction
|
45050 | };
|
45051 |
|
45052 | this._commandStack.execute('spaceTool', context);
|
45053 | };
|
45054 |
|
45055 | Modeling.prototype.updateWaypoints = function(connection, newWaypoints, hints) {
|
45056 | var context = {
|
45057 | connection: connection,
|
45058 | newWaypoints: newWaypoints,
|
45059 | hints: hints || {}
|
45060 | };
|
45061 |
|
45062 | this._commandStack.execute('connection.updateWaypoints', context);
|
45063 | };
|
45064 |
|
45065 | Modeling.prototype.reconnectStart = function(connection, newSource, dockingOrPoints) {
|
45066 | var context = {
|
45067 | connection: connection,
|
45068 | newSource: newSource,
|
45069 | dockingOrPoints: dockingOrPoints
|
45070 | };
|
45071 |
|
45072 | this._commandStack.execute('connection.reconnectStart', context);
|
45073 | };
|
45074 |
|
45075 | Modeling.prototype.reconnectEnd = function(connection, newTarget, dockingOrPoints) {
|
45076 | var context = {
|
45077 | connection: connection,
|
45078 | newTarget: newTarget,
|
45079 | dockingOrPoints: dockingOrPoints
|
45080 | };
|
45081 |
|
45082 | this._commandStack.execute('connection.reconnectEnd', context);
|
45083 | };
|
45084 |
|
45085 | Modeling.prototype.connect = function(source, target, attrs, hints) {
|
45086 | return this.createConnection(source, target, attrs || {}, source.parent, hints);
|
45087 | };
|
45088 |
|
45089 | Modeling.prototype._create = function(type, attrs) {
|
45090 | if (attrs instanceof Base) {
|
45091 | return attrs;
|
45092 | } else {
|
45093 | return this._elementFactory.create(type, attrs);
|
45094 | }
|
45095 | };
|
45096 |
|
45097 | Modeling.prototype.toggleCollapse = function(shape, hints) {
|
45098 | var context = {
|
45099 | shape: shape,
|
45100 | hints: hints || {}
|
45101 | };
|
45102 |
|
45103 | this._commandStack.execute('shape.toggleCollapse', context);
|
45104 | };
|
45105 |
|
45106 | var DEFAULT_FLOW = 'default',
|
45107 | ID = 'id',
|
45108 | DI = 'di';
|
45109 |
|
45110 | var NULL_DIMENSIONS = {
|
45111 | width: 0,
|
45112 | height: 0
|
45113 | };
|
45114 |
|
45115 | |
45116 |
|
45117 |
|
45118 |
|
45119 |
|
45120 |
|
45121 |
|
45122 |
|
45123 |
|
45124 | function UpdatePropertiesHandler(
|
45125 | elementRegistry, moddle, translate,
|
45126 | modeling, textRenderer) {
|
45127 |
|
45128 | this._elementRegistry = elementRegistry;
|
45129 | this._moddle = moddle;
|
45130 | this._translate = translate;
|
45131 | this._modeling = modeling;
|
45132 | this._textRenderer = textRenderer;
|
45133 | }
|
45134 |
|
45135 | UpdatePropertiesHandler.$inject = [
|
45136 | 'elementRegistry',
|
45137 | 'moddle',
|
45138 | 'translate',
|
45139 | 'modeling',
|
45140 | 'textRenderer'
|
45141 | ];
|
45142 |
|
45143 |
|
45144 |
|
45145 |
|
45146 | |
45147 |
|
45148 |
|
45149 |
|
45150 |
|
45151 |
|
45152 |
|
45153 |
|
45154 |
|
45155 |
|
45156 | UpdatePropertiesHandler.prototype.execute = function(context) {
|
45157 |
|
45158 | var element = context.element,
|
45159 | changed = [ element ],
|
45160 | translate = this._translate;
|
45161 |
|
45162 | if (!element) {
|
45163 | throw new Error(translate('element required'));
|
45164 | }
|
45165 |
|
45166 | var elementRegistry = this._elementRegistry,
|
45167 | ids = this._moddle.ids;
|
45168 |
|
45169 | var businessObject = element.businessObject,
|
45170 | properties = unwrapBusinessObjects(context.properties),
|
45171 | oldProperties = context.oldProperties || getProperties$1(businessObject, properties);
|
45172 |
|
45173 | if (isIdChange(properties, businessObject)) {
|
45174 | ids.unclaim(businessObject[ID]);
|
45175 |
|
45176 | elementRegistry.updateId(element, properties[ID]);
|
45177 |
|
45178 | ids.claim(properties[ID], businessObject);
|
45179 | }
|
45180 |
|
45181 |
|
45182 | if (DEFAULT_FLOW in properties) {
|
45183 |
|
45184 | if (properties[DEFAULT_FLOW]) {
|
45185 | changed.push(elementRegistry.get(properties[DEFAULT_FLOW].id));
|
45186 | }
|
45187 |
|
45188 | if (businessObject[DEFAULT_FLOW]) {
|
45189 | changed.push(elementRegistry.get(businessObject[DEFAULT_FLOW].id));
|
45190 | }
|
45191 | }
|
45192 |
|
45193 |
|
45194 | setProperties$1(businessObject, properties);
|
45195 |
|
45196 |
|
45197 | context.oldProperties = oldProperties;
|
45198 | context.changed = changed;
|
45199 |
|
45200 |
|
45201 | return changed;
|
45202 | };
|
45203 |
|
45204 |
|
45205 | UpdatePropertiesHandler.prototype.postExecute = function(context) {
|
45206 | var element = context.element,
|
45207 | label = element.label;
|
45208 |
|
45209 | var text = label && getBusinessObject(label).name;
|
45210 |
|
45211 | if (!text) {
|
45212 | return;
|
45213 | }
|
45214 |
|
45215 |
|
45216 |
|
45217 | var newLabelBounds = this._textRenderer.getExternalLabelBounds(label, text);
|
45218 |
|
45219 | this._modeling.resizeShape(label, newLabelBounds, NULL_DIMENSIONS);
|
45220 | };
|
45221 |
|
45222 | |
45223 |
|
45224 |
|
45225 |
|
45226 |
|
45227 |
|
45228 |
|
45229 | UpdatePropertiesHandler.prototype.revert = function(context) {
|
45230 |
|
45231 | var element = context.element,
|
45232 | properties = context.properties,
|
45233 | oldProperties = context.oldProperties,
|
45234 | businessObject = element.businessObject,
|
45235 | elementRegistry = this._elementRegistry,
|
45236 | ids = this._moddle.ids;
|
45237 |
|
45238 |
|
45239 | setProperties$1(businessObject, oldProperties);
|
45240 |
|
45241 | if (isIdChange(properties, businessObject)) {
|
45242 | ids.unclaim(properties[ID]);
|
45243 |
|
45244 | elementRegistry.updateId(element, oldProperties[ID]);
|
45245 |
|
45246 | ids.claim(oldProperties[ID], businessObject);
|
45247 | }
|
45248 |
|
45249 | return context.changed;
|
45250 | };
|
45251 |
|
45252 |
|
45253 | function isIdChange(properties, businessObject) {
|
45254 | return ID in properties && properties[ID] !== businessObject[ID];
|
45255 | }
|
45256 |
|
45257 |
|
45258 | function getProperties$1(businessObject, properties) {
|
45259 | var propertyNames = keys(properties);
|
45260 |
|
45261 | return reduce(propertyNames, function(result, key) {
|
45262 |
|
45263 |
|
45264 | if (key !== DI) {
|
45265 | result[key] = businessObject.get(key);
|
45266 | } else {
|
45267 | result[key] = getDiProperties(businessObject.di, keys(properties.di));
|
45268 | }
|
45269 |
|
45270 | return result;
|
45271 | }, {});
|
45272 | }
|
45273 |
|
45274 |
|
45275 | function getDiProperties(di, propertyNames) {
|
45276 | return reduce(propertyNames, function(result, key) {
|
45277 | result[key] = di.get(key);
|
45278 |
|
45279 | return result;
|
45280 | }, {});
|
45281 | }
|
45282 |
|
45283 |
|
45284 | function setProperties$1(businessObject, properties) {
|
45285 | forEach(properties, function(value, key) {
|
45286 |
|
45287 | if (key !== DI) {
|
45288 | businessObject.set(key, value);
|
45289 | } else {
|
45290 |
|
45291 | if (businessObject.di) {
|
45292 | setDiProperties(businessObject.di, value);
|
45293 | }
|
45294 | }
|
45295 | });
|
45296 | }
|
45297 |
|
45298 |
|
45299 | function setDiProperties(di, properties) {
|
45300 | forEach(properties, function(value, key) {
|
45301 | di.set(key, value);
|
45302 | });
|
45303 | }
|
45304 |
|
45305 |
|
45306 | var referencePropertyNames = [ 'default' ];
|
45307 |
|
45308 | |
45309 |
|
45310 |
|
45311 |
|
45312 |
|
45313 |
|
45314 |
|
45315 |
|
45316 |
|
45317 | function unwrapBusinessObjects(properties) {
|
45318 |
|
45319 | var unwrappedProps = assign({}, properties);
|
45320 |
|
45321 | referencePropertyNames.forEach(function(name) {
|
45322 | if (name in properties) {
|
45323 | unwrappedProps[name] = getBusinessObject(unwrappedProps[name]);
|
45324 | }
|
45325 | });
|
45326 |
|
45327 | return unwrappedProps;
|
45328 | }
|
45329 |
|
45330 | function UpdateCanvasRootHandler(canvas, modeling) {
|
45331 | this._canvas = canvas;
|
45332 | this._modeling = modeling;
|
45333 | }
|
45334 |
|
45335 | UpdateCanvasRootHandler.$inject = [
|
45336 | 'canvas',
|
45337 | 'modeling'
|
45338 | ];
|
45339 |
|
45340 |
|
45341 | UpdateCanvasRootHandler.prototype.execute = function(context) {
|
45342 |
|
45343 | var canvas = this._canvas;
|
45344 |
|
45345 | var newRoot = context.newRoot,
|
45346 | newRootBusinessObject = newRoot.businessObject,
|
45347 | oldRoot = canvas.getRootElement(),
|
45348 | oldRootBusinessObject = oldRoot.businessObject,
|
45349 | bpmnDefinitions = oldRootBusinessObject.$parent,
|
45350 | diPlane = oldRootBusinessObject.di;
|
45351 |
|
45352 |
|
45353 | canvas.setRootElement(newRoot, true);
|
45354 |
|
45355 |
|
45356 | add(bpmnDefinitions.rootElements, newRootBusinessObject);
|
45357 | newRootBusinessObject.$parent = bpmnDefinitions;
|
45358 |
|
45359 | remove$2(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
45360 | oldRootBusinessObject.$parent = null;
|
45361 |
|
45362 |
|
45363 | oldRootBusinessObject.di = null;
|
45364 |
|
45365 | diPlane.bpmnElement = newRootBusinessObject;
|
45366 | newRootBusinessObject.di = diPlane;
|
45367 |
|
45368 | context.oldRoot = oldRoot;
|
45369 |
|
45370 |
|
45371 |
|
45372 | };
|
45373 |
|
45374 |
|
45375 | UpdateCanvasRootHandler.prototype.revert = function(context) {
|
45376 |
|
45377 | var canvas = this._canvas;
|
45378 |
|
45379 | var newRoot = context.newRoot,
|
45380 | newRootBusinessObject = newRoot.businessObject,
|
45381 | oldRoot = context.oldRoot,
|
45382 | oldRootBusinessObject = oldRoot.businessObject,
|
45383 | bpmnDefinitions = newRootBusinessObject.$parent,
|
45384 | diPlane = newRootBusinessObject.di;
|
45385 |
|
45386 |
|
45387 | canvas.setRootElement(oldRoot, true);
|
45388 |
|
45389 |
|
45390 | remove$2(bpmnDefinitions.rootElements, newRootBusinessObject);
|
45391 | newRootBusinessObject.$parent = null;
|
45392 |
|
45393 | add(bpmnDefinitions.rootElements, oldRootBusinessObject);
|
45394 | oldRootBusinessObject.$parent = bpmnDefinitions;
|
45395 |
|
45396 |
|
45397 | newRootBusinessObject.di = null;
|
45398 |
|
45399 | diPlane.bpmnElement = oldRootBusinessObject;
|
45400 | oldRootBusinessObject.di = diPlane;
|
45401 |
|
45402 |
|
45403 |
|
45404 | };
|
45405 |
|
45406 | |
45407 |
|
45408 |
|
45409 |
|
45410 |
|
45411 |
|
45412 | function AddLaneHandler(modeling, spaceTool) {
|
45413 | this._modeling = modeling;
|
45414 | this._spaceTool = spaceTool;
|
45415 | }
|
45416 |
|
45417 | AddLaneHandler.$inject = [
|
45418 | 'modeling',
|
45419 | 'spaceTool'
|
45420 | ];
|
45421 |
|
45422 |
|
45423 | AddLaneHandler.prototype.preExecute = function(context) {
|
45424 |
|
45425 | var spaceTool = this._spaceTool,
|
45426 | modeling = this._modeling;
|
45427 |
|
45428 | var shape = context.shape,
|
45429 | location = context.location;
|
45430 |
|
45431 | var lanesRoot = getLanesRoot(shape);
|
45432 |
|
45433 | var isRoot = lanesRoot === shape,
|
45434 | laneParent = isRoot ? shape : shape.parent;
|
45435 |
|
45436 | var existingChildLanes = getChildLanes(laneParent);
|
45437 |
|
45438 |
|
45439 | if (!existingChildLanes.length) {
|
45440 | modeling.createShape({ type: 'bpmn:Lane' }, {
|
45441 | x: shape.x + LANE_INDENTATION,
|
45442 | y: shape.y,
|
45443 | width: shape.width - LANE_INDENTATION,
|
45444 | height: shape.height
|
45445 | }, laneParent);
|
45446 | }
|
45447 |
|
45448 |
|
45449 | var allAffected = [];
|
45450 |
|
45451 | eachElement(lanesRoot, function(element) {
|
45452 | allAffected.push(element);
|
45453 |
|
45454 | if (element === shape) {
|
45455 | return [];
|
45456 | }
|
45457 |
|
45458 | return filter(element.children, function(c) {
|
45459 | return c !== shape;
|
45460 | });
|
45461 | });
|
45462 |
|
45463 | var offset = location === 'top' ? -120 : 120,
|
45464 | lanePosition = location === 'top' ? shape.y : shape.y + shape.height,
|
45465 | spacePos = lanePosition + (location === 'top' ? 10 : -10),
|
45466 | direction = location === 'top' ? 'n' : 's';
|
45467 |
|
45468 | var adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
45469 |
|
45470 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: offset }, direction);
|
45471 |
|
45472 |
|
45473 | context.newLane = modeling.createShape({ type: 'bpmn:Lane' }, {
|
45474 | x: shape.x + (isRoot ? LANE_INDENTATION : 0),
|
45475 | y: lanePosition - (location === 'top' ? 120 : 0),
|
45476 | width: shape.width - (isRoot ? LANE_INDENTATION : 0),
|
45477 | height: 120
|
45478 | }, laneParent);
|
45479 | };
|
45480 |
|
45481 | |
45482 |
|
45483 |
|
45484 |
|
45485 |
|
45486 |
|
45487 | function SplitLaneHandler(modeling, translate) {
|
45488 | this._modeling = modeling;
|
45489 | this._translate = translate;
|
45490 | }
|
45491 |
|
45492 | SplitLaneHandler.$inject = [
|
45493 | 'modeling',
|
45494 | 'translate'
|
45495 | ];
|
45496 |
|
45497 |
|
45498 | SplitLaneHandler.prototype.preExecute = function(context) {
|
45499 |
|
45500 | var modeling = this._modeling,
|
45501 | translate = this._translate;
|
45502 |
|
45503 | var shape = context.shape,
|
45504 | newLanesCount = context.count;
|
45505 |
|
45506 | var childLanes = getChildLanes(shape),
|
45507 | existingLanesCount = childLanes.length;
|
45508 |
|
45509 | if (existingLanesCount > newLanesCount) {
|
45510 | throw new Error(translate('more than {count} child lanes', { count: newLanesCount }));
|
45511 | }
|
45512 |
|
45513 | var newLanesHeight = Math.round(shape.height / newLanesCount);
|
45514 |
|
45515 |
|
45516 |
|
45517 |
|
45518 |
|
45519 |
|
45520 |
|
45521 | var laneY,
|
45522 | laneHeight,
|
45523 | laneBounds,
|
45524 | newLaneAttrs,
|
45525 | idx;
|
45526 |
|
45527 | for (idx = 0; idx < newLanesCount; idx++) {
|
45528 |
|
45529 | laneY = shape.y + idx * newLanesHeight;
|
45530 |
|
45531 |
|
45532 | if (idx === newLanesCount - 1) {
|
45533 | laneHeight = shape.height - (newLanesHeight * idx);
|
45534 | } else {
|
45535 | laneHeight = newLanesHeight;
|
45536 | }
|
45537 |
|
45538 | laneBounds = {
|
45539 | x: shape.x + LANE_INDENTATION,
|
45540 | y: laneY,
|
45541 | width: shape.width - LANE_INDENTATION,
|
45542 | height: laneHeight
|
45543 | };
|
45544 |
|
45545 | if (idx < existingLanesCount) {
|
45546 |
|
45547 | modeling.resizeShape(childLanes[idx], laneBounds);
|
45548 | } else {
|
45549 |
|
45550 | newLaneAttrs = {
|
45551 | type: 'bpmn:Lane'
|
45552 | };
|
45553 |
|
45554 | modeling.createShape(newLaneAttrs, laneBounds, shape);
|
45555 | }
|
45556 | }
|
45557 | };
|
45558 |
|
45559 | |
45560 |
|
45561 |
|
45562 |
|
45563 |
|
45564 | function ResizeLaneHandler(modeling, spaceTool) {
|
45565 | this._modeling = modeling;
|
45566 | this._spaceTool = spaceTool;
|
45567 | }
|
45568 |
|
45569 | ResizeLaneHandler.$inject = [
|
45570 | 'modeling',
|
45571 | 'spaceTool'
|
45572 | ];
|
45573 |
|
45574 |
|
45575 | ResizeLaneHandler.prototype.preExecute = function(context) {
|
45576 |
|
45577 | var shape = context.shape,
|
45578 | newBounds = context.newBounds,
|
45579 | balanced = context.balanced;
|
45580 |
|
45581 | if (balanced !== false) {
|
45582 | this.resizeBalanced(shape, newBounds);
|
45583 | } else {
|
45584 | this.resizeSpace(shape, newBounds);
|
45585 | }
|
45586 | };
|
45587 |
|
45588 |
|
45589 | |
45590 |
|
45591 |
|
45592 |
|
45593 |
|
45594 |
|
45595 | ResizeLaneHandler.prototype.resizeBalanced = function(shape, newBounds) {
|
45596 |
|
45597 | var modeling = this._modeling;
|
45598 |
|
45599 | var resizeNeeded = computeLanesResize(shape, newBounds);
|
45600 |
|
45601 |
|
45602 | modeling.resizeShape(shape, newBounds);
|
45603 |
|
45604 |
|
45605 | resizeNeeded.forEach(function(r) {
|
45606 | modeling.resizeShape(r.shape, r.newBounds);
|
45607 | });
|
45608 | };
|
45609 |
|
45610 |
|
45611 | |
45612 |
|
45613 |
|
45614 |
|
45615 |
|
45616 |
|
45617 | ResizeLaneHandler.prototype.resizeSpace = function(shape, newBounds) {
|
45618 | var spaceTool = this._spaceTool;
|
45619 |
|
45620 | var shapeTrbl = asTRBL(shape),
|
45621 | newTrbl = asTRBL(newBounds);
|
45622 |
|
45623 | var trblDiff = substractTRBL(newTrbl, shapeTrbl);
|
45624 |
|
45625 | var lanesRoot = getLanesRoot(shape);
|
45626 |
|
45627 | var allAffected = [],
|
45628 | allLanes = [];
|
45629 |
|
45630 | eachElement(lanesRoot, function(element) {
|
45631 | allAffected.push(element);
|
45632 |
|
45633 | if (is$1(element, 'bpmn:Lane') || is$1(element, 'bpmn:Participant')) {
|
45634 | allLanes.push(element);
|
45635 | }
|
45636 |
|
45637 | return element.children;
|
45638 | });
|
45639 |
|
45640 | var change,
|
45641 | spacePos,
|
45642 | direction,
|
45643 | offset,
|
45644 | adjustments;
|
45645 |
|
45646 | if (trblDiff.bottom || trblDiff.top) {
|
45647 |
|
45648 | change = trblDiff.bottom || trblDiff.top;
|
45649 | spacePos = shape.y + (trblDiff.bottom ? shape.height : 0) + (trblDiff.bottom ? -10 : 10);
|
45650 | direction = trblDiff.bottom ? 's' : 'n';
|
45651 |
|
45652 | offset = trblDiff.top > 0 || trblDiff.bottom < 0 ? -change : change;
|
45653 |
|
45654 | adjustments = spaceTool.calculateAdjustments(allAffected, 'y', offset, spacePos);
|
45655 |
|
45656 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: 0, y: change }, direction);
|
45657 | }
|
45658 |
|
45659 |
|
45660 | if (trblDiff.left || trblDiff.right) {
|
45661 |
|
45662 | change = trblDiff.right || trblDiff.left;
|
45663 | spacePos = shape.x + (trblDiff.right ? shape.width : 0) + (trblDiff.right ? -10 : 100);
|
45664 | direction = trblDiff.right ? 'e' : 'w';
|
45665 |
|
45666 | offset = trblDiff.left > 0 || trblDiff.right < 0 ? -change : change;
|
45667 |
|
45668 | adjustments = spaceTool.calculateAdjustments(allLanes, 'x', offset, spacePos);
|
45669 |
|
45670 | spaceTool.makeSpace(adjustments.movingShapes, adjustments.resizingShapes, { x: change, y: 0 }, direction);
|
45671 | }
|
45672 | };
|
45673 |
|
45674 | var FLOW_NODE_REFS_ATTR = 'flowNodeRef',
|
45675 | LANES_ATTR = 'lanes';
|
45676 |
|
45677 |
|
45678 | |
45679 |
|
45680 |
|
45681 | function UpdateFlowNodeRefsHandler(elementRegistry) {
|
45682 | this._elementRegistry = elementRegistry;
|
45683 | }
|
45684 |
|
45685 | UpdateFlowNodeRefsHandler.$inject = [
|
45686 | 'elementRegistry'
|
45687 | ];
|
45688 |
|
45689 |
|
45690 | UpdateFlowNodeRefsHandler.prototype.computeUpdates = function(flowNodeShapes, laneShapes) {
|
45691 |
|
45692 | var handledNodes = {};
|
45693 |
|
45694 | var updates = [];
|
45695 |
|
45696 | var participantCache = {};
|
45697 |
|
45698 | var allFlowNodeShapes = [];
|
45699 |
|
45700 | function isInLaneShape(element, laneShape) {
|
45701 |
|
45702 | var laneTrbl = asTRBL(laneShape);
|
45703 |
|
45704 | var elementMid = {
|
45705 | x: element.x + element.width / 2,
|
45706 | y: element.y + element.height / 2
|
45707 | };
|
45708 |
|
45709 | return elementMid.x > laneTrbl.left &&
|
45710 | elementMid.x < laneTrbl.right &&
|
45711 | elementMid.y > laneTrbl.top &&
|
45712 | elementMid.y < laneTrbl.bottom;
|
45713 | }
|
45714 |
|
45715 | function addFlowNodeShape(flowNodeShape) {
|
45716 | if (!handledNodes[flowNodeShape.id]) {
|
45717 | allFlowNodeShapes.push(flowNodeShape);
|
45718 | handledNodes[flowNodeShape.id] = flowNodeShape;
|
45719 | }
|
45720 | }
|
45721 |
|
45722 | function getAllLaneShapes(flowNodeShape) {
|
45723 |
|
45724 | var root = getLanesRoot(flowNodeShape);
|
45725 |
|
45726 | if (!participantCache[root.id]) {
|
45727 | participantCache[root.id] = collectLanes(root);
|
45728 | }
|
45729 |
|
45730 | return participantCache[root.id];
|
45731 | }
|
45732 |
|
45733 | function getNewLanes(flowNodeShape) {
|
45734 | if (!flowNodeShape.parent) {
|
45735 | return [];
|
45736 | }
|
45737 |
|
45738 | var allLaneShapes = getAllLaneShapes(flowNodeShape);
|
45739 |
|
45740 | return allLaneShapes.filter(function(l) {
|
45741 | return isInLaneShape(flowNodeShape, l);
|
45742 | }).map(function(shape) {
|
45743 | return shape.businessObject;
|
45744 | });
|
45745 | }
|
45746 |
|
45747 | laneShapes.forEach(function(laneShape) {
|
45748 | var root = getLanesRoot(laneShape);
|
45749 |
|
45750 | if (!root || handledNodes[root.id]) {
|
45751 | return;
|
45752 | }
|
45753 |
|
45754 | var children = root.children.filter(function(c) {
|
45755 | return is$1(c, 'bpmn:FlowNode');
|
45756 | });
|
45757 |
|
45758 | children.forEach(addFlowNodeShape);
|
45759 |
|
45760 | handledNodes[root.id] = root;
|
45761 | });
|
45762 |
|
45763 | flowNodeShapes.forEach(addFlowNodeShape);
|
45764 |
|
45765 |
|
45766 | allFlowNodeShapes.forEach(function(flowNodeShape) {
|
45767 |
|
45768 | var flowNode = flowNodeShape.businessObject;
|
45769 |
|
45770 | var lanes = flowNode.get(LANES_ATTR),
|
45771 | remove$$1 = lanes.slice(),
|
45772 | add$$1 = getNewLanes(flowNodeShape);
|
45773 |
|
45774 | updates.push({ flowNode: flowNode, remove: remove$$1, add: add$$1 });
|
45775 | });
|
45776 |
|
45777 | laneShapes.forEach(function(laneShape) {
|
45778 |
|
45779 | var lane = laneShape.businessObject;
|
45780 |
|
45781 |
|
45782 | if (!laneShape.parent) {
|
45783 | lane.get(FLOW_NODE_REFS_ATTR).forEach(function(flowNode) {
|
45784 | updates.push({ flowNode: flowNode, remove: [ lane ], add: [] });
|
45785 | });
|
45786 | }
|
45787 | });
|
45788 |
|
45789 | return updates;
|
45790 | };
|
45791 |
|
45792 | UpdateFlowNodeRefsHandler.prototype.execute = function(context) {
|
45793 |
|
45794 | var updates = context.updates;
|
45795 |
|
45796 | if (!updates) {
|
45797 | updates = context.updates = this.computeUpdates(context.flowNodeShapes, context.laneShapes);
|
45798 | }
|
45799 |
|
45800 |
|
45801 | updates.forEach(function(update) {
|
45802 |
|
45803 | var flowNode = update.flowNode,
|
45804 | lanes = flowNode.get(LANES_ATTR);
|
45805 |
|
45806 |
|
45807 | update.remove.forEach(function(oldLane) {
|
45808 | remove$2(lanes, oldLane);
|
45809 | remove$2(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
45810 | });
|
45811 |
|
45812 |
|
45813 | update.add.forEach(function(newLane) {
|
45814 | add(lanes, newLane);
|
45815 | add(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
45816 | });
|
45817 | });
|
45818 |
|
45819 |
|
45820 |
|
45821 | };
|
45822 |
|
45823 |
|
45824 | UpdateFlowNodeRefsHandler.prototype.revert = function(context) {
|
45825 |
|
45826 | var updates = context.updates;
|
45827 |
|
45828 | updates.forEach(function(update) {
|
45829 |
|
45830 | var flowNode = update.flowNode,
|
45831 | lanes = flowNode.get(LANES_ATTR);
|
45832 |
|
45833 |
|
45834 | update.add.forEach(function(newLane) {
|
45835 | remove$2(lanes, newLane);
|
45836 | remove$2(newLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
45837 | });
|
45838 |
|
45839 |
|
45840 | update.remove.forEach(function(oldLane) {
|
45841 | add(lanes, oldLane);
|
45842 | add(oldLane.get(FLOW_NODE_REFS_ATTR), flowNode);
|
45843 | });
|
45844 | });
|
45845 |
|
45846 |
|
45847 |
|
45848 | };
|
45849 |
|
45850 | function IdClaimHandler(moddle) {
|
45851 | this._moddle = moddle;
|
45852 | }
|
45853 |
|
45854 | IdClaimHandler.$inject = [ 'moddle' ];
|
45855 |
|
45856 |
|
45857 | IdClaimHandler.prototype.execute = function(context) {
|
45858 | var ids = this._moddle.ids,
|
45859 | id = context.id,
|
45860 | element = context.element,
|
45861 | claiming = context.claiming;
|
45862 |
|
45863 | if (claiming) {
|
45864 | ids.claim(id, element);
|
45865 | } else {
|
45866 | ids.unclaim(id);
|
45867 | }
|
45868 | };
|
45869 |
|
45870 | |
45871 |
|
45872 |
|
45873 | IdClaimHandler.prototype.revert = function(context) {
|
45874 | var ids = this._moddle.ids,
|
45875 | id = context.id,
|
45876 | element = context.element,
|
45877 | claiming = context.claiming;
|
45878 |
|
45879 | if (claiming) {
|
45880 | ids.unclaim(id);
|
45881 | } else {
|
45882 | ids.claim(id, element);
|
45883 | }
|
45884 | };
|
45885 |
|
45886 | var DEFAULT_COLORS = {
|
45887 | fill: undefined,
|
45888 | stroke: undefined
|
45889 | };
|
45890 |
|
45891 |
|
45892 | function SetColorHandler(commandStack) {
|
45893 | this._commandStack = commandStack;
|
45894 | }
|
45895 |
|
45896 | SetColorHandler.$inject = [
|
45897 | 'commandStack'
|
45898 | ];
|
45899 |
|
45900 |
|
45901 | SetColorHandler.prototype.postExecute = function(context) {
|
45902 | var elements = context.elements,
|
45903 | colors = context.colors || DEFAULT_COLORS;
|
45904 |
|
45905 | var self = this;
|
45906 |
|
45907 | var di = {};
|
45908 |
|
45909 | if ('fill' in colors) {
|
45910 | assign(di, { fill: colors.fill });
|
45911 | }
|
45912 |
|
45913 | if ('stroke' in colors) {
|
45914 | assign(di, { stroke: colors.stroke });
|
45915 | }
|
45916 |
|
45917 | forEach(elements, function(element) {
|
45918 |
|
45919 | self._commandStack.execute('element.updateProperties', {
|
45920 | element: element,
|
45921 | properties: {
|
45922 | di: di
|
45923 | }
|
45924 | });
|
45925 | });
|
45926 |
|
45927 | };
|
45928 |
|
45929 | var NULL_DIMENSIONS$1 = {
|
45930 | width: 0,
|
45931 | height: 0
|
45932 | };
|
45933 |
|
45934 |
|
45935 | |
45936 |
|
45937 |
|
45938 | function UpdateLabelHandler(modeling, textRenderer) {
|
45939 |
|
45940 | |
45941 |
|
45942 |
|
45943 |
|
45944 |
|
45945 |
|
45946 |
|
45947 |
|
45948 | function setText(element, text) {
|
45949 |
|
45950 |
|
45951 | var label = element.label || element;
|
45952 |
|
45953 | var labelTarget = element.labelTarget || element;
|
45954 |
|
45955 | setLabel(label, text, labelTarget !== label);
|
45956 |
|
45957 | return [ label, labelTarget ];
|
45958 | }
|
45959 |
|
45960 | function preExecute(ctx) {
|
45961 | var element = ctx.element,
|
45962 | businessObject = element.businessObject,
|
45963 | newLabel = ctx.newLabel;
|
45964 |
|
45965 | if (!isLabel(element)
|
45966 | && isLabelExternal(element)
|
45967 | && !hasExternalLabel(element)
|
45968 | && !isEmptyText$1(newLabel)) {
|
45969 |
|
45970 |
|
45971 | var paddingTop = 7;
|
45972 |
|
45973 | var labelCenter = getExternalLabelMid(element);
|
45974 |
|
45975 | labelCenter = {
|
45976 | x: labelCenter.x,
|
45977 | y: labelCenter.y + paddingTop
|
45978 | };
|
45979 |
|
45980 | modeling.createLabel(element, labelCenter, {
|
45981 | id: businessObject.id + '_label',
|
45982 | businessObject: businessObject
|
45983 | });
|
45984 | }
|
45985 | }
|
45986 |
|
45987 | function execute(ctx) {
|
45988 | ctx.oldLabel = getLabel(ctx.element);
|
45989 | return setText(ctx.element, ctx.newLabel);
|
45990 | }
|
45991 |
|
45992 | function revert(ctx) {
|
45993 | return setText(ctx.element, ctx.oldLabel);
|
45994 | }
|
45995 |
|
45996 | function postExecute(ctx) {
|
45997 | var element = ctx.element,
|
45998 | label = element.label || element,
|
45999 | newLabel = ctx.newLabel,
|
46000 | newBounds = ctx.newBounds,
|
46001 | hints = ctx.hints || {};
|
46002 |
|
46003 | if (isLabel(label) && isEmptyText$1(newLabel)) {
|
46004 |
|
46005 | if (hints.removeShape !== false) {
|
46006 | modeling.removeShape(label, { unsetLabel: false });
|
46007 | }
|
46008 |
|
46009 | return;
|
46010 | }
|
46011 |
|
46012 |
|
46013 | if (!isLabelExternal(element) && !is$1(element, 'bpmn:TextAnnotation')) {
|
46014 | return;
|
46015 | }
|
46016 |
|
46017 | var bo = getBusinessObject(label);
|
46018 |
|
46019 | var text = bo.name || bo.text;
|
46020 |
|
46021 |
|
46022 | if (!text) {
|
46023 | return;
|
46024 | }
|
46025 |
|
46026 |
|
46027 | if (typeof newBounds === 'undefined') {
|
46028 | newBounds = textRenderer.getExternalLabelBounds(label, text);
|
46029 | }
|
46030 |
|
46031 |
|
46032 |
|
46033 | if (newBounds) {
|
46034 | modeling.resizeShape(label, newBounds, NULL_DIMENSIONS$1);
|
46035 | }
|
46036 | }
|
46037 |
|
46038 |
|
46039 |
|
46040 | this.preExecute = preExecute;
|
46041 | this.execute = execute;
|
46042 | this.revert = revert;
|
46043 | this.postExecute = postExecute;
|
46044 | }
|
46045 |
|
46046 | UpdateLabelHandler.$inject = [
|
46047 | 'modeling',
|
46048 | 'textRenderer'
|
46049 | ];
|
46050 |
|
46051 |
|
46052 |
|
46053 |
|
46054 | function isEmptyText$1(label) {
|
46055 | return !label || !label.trim();
|
46056 | }
|
46057 |
|
46058 | |
46059 |
|
46060 |
|
46061 |
|
46062 |
|
46063 |
|
46064 |
|
46065 |
|
46066 | function Modeling$1(
|
46067 | eventBus, elementFactory, commandStack,
|
46068 | bpmnRules) {
|
46069 |
|
46070 | Modeling.call(this, eventBus, elementFactory, commandStack);
|
46071 |
|
46072 | this._bpmnRules = bpmnRules;
|
46073 | }
|
46074 |
|
46075 | inherits_browser(Modeling$1, Modeling);
|
46076 |
|
46077 | Modeling$1.$inject = [
|
46078 | 'eventBus',
|
46079 | 'elementFactory',
|
46080 | 'commandStack',
|
46081 | 'bpmnRules'
|
46082 | ];
|
46083 |
|
46084 |
|
46085 | Modeling$1.prototype.getHandlers = function() {
|
46086 | var handlers = Modeling.prototype.getHandlers.call(this);
|
46087 |
|
46088 | handlers['element.updateProperties'] = UpdatePropertiesHandler;
|
46089 | handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
|
46090 | handlers['lane.add'] = AddLaneHandler;
|
46091 | handlers['lane.resize'] = ResizeLaneHandler;
|
46092 | handlers['lane.split'] = SplitLaneHandler;
|
46093 | handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
|
46094 | handlers['id.updateClaim'] = IdClaimHandler;
|
46095 | handlers['element.setColor'] = SetColorHandler;
|
46096 | handlers['element.updateLabel'] = UpdateLabelHandler;
|
46097 |
|
46098 | return handlers;
|
46099 | };
|
46100 |
|
46101 |
|
46102 | Modeling$1.prototype.updateLabel = function(element, newLabel, newBounds, hints) {
|
46103 | this._commandStack.execute('element.updateLabel', {
|
46104 | element: element,
|
46105 | newLabel: newLabel,
|
46106 | newBounds: newBounds,
|
46107 | hints: hints || {}
|
46108 | });
|
46109 | };
|
46110 |
|
46111 |
|
46112 | Modeling$1.prototype.connect = function(source, target, attrs, hints) {
|
46113 |
|
46114 | var bpmnRules = this._bpmnRules;
|
46115 |
|
46116 | if (!attrs) {
|
46117 | attrs = bpmnRules.canConnect(source, target);
|
46118 | }
|
46119 |
|
46120 | if (!attrs) {
|
46121 | return;
|
46122 | }
|
46123 |
|
46124 | return this.createConnection(source, target, attrs, source.parent, hints);
|
46125 | };
|
46126 |
|
46127 |
|
46128 | Modeling$1.prototype.updateProperties = function(element, properties) {
|
46129 | this._commandStack.execute('element.updateProperties', {
|
46130 | element: element,
|
46131 | properties: properties
|
46132 | });
|
46133 | };
|
46134 |
|
46135 | Modeling$1.prototype.resizeLane = function(laneShape, newBounds, balanced) {
|
46136 | this._commandStack.execute('lane.resize', {
|
46137 | shape: laneShape,
|
46138 | newBounds: newBounds,
|
46139 | balanced: balanced
|
46140 | });
|
46141 | };
|
46142 |
|
46143 | Modeling$1.prototype.addLane = function(targetLaneShape, location) {
|
46144 | var context = {
|
46145 | shape: targetLaneShape,
|
46146 | location: location
|
46147 | };
|
46148 |
|
46149 | this._commandStack.execute('lane.add', context);
|
46150 |
|
46151 | return context.newLane;
|
46152 | };
|
46153 |
|
46154 | Modeling$1.prototype.splitLane = function(targetLane, count) {
|
46155 | this._commandStack.execute('lane.split', {
|
46156 | shape: targetLane,
|
46157 | count: count
|
46158 | });
|
46159 | };
|
46160 |
|
46161 | |
46162 |
|
46163 |
|
46164 |
|
46165 |
|
46166 | Modeling$1.prototype.makeCollaboration = function() {
|
46167 |
|
46168 | var collaborationElement = this._create('root', {
|
46169 | type: 'bpmn:Collaboration'
|
46170 | });
|
46171 |
|
46172 | var context = {
|
46173 | newRoot: collaborationElement
|
46174 | };
|
46175 |
|
46176 | this._commandStack.execute('canvas.updateRoot', context);
|
46177 |
|
46178 | return collaborationElement;
|
46179 | };
|
46180 |
|
46181 | Modeling$1.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {
|
46182 |
|
46183 | this._commandStack.execute('lane.updateRefs', {
|
46184 | flowNodeShapes: flowNodeShapes,
|
46185 | laneShapes: laneShapes
|
46186 | });
|
46187 | };
|
46188 |
|
46189 | |
46190 |
|
46191 |
|
46192 |
|
46193 |
|
46194 | Modeling$1.prototype.makeProcess = function() {
|
46195 |
|
46196 | var processElement = this._create('root', {
|
46197 | type: 'bpmn:Process'
|
46198 | });
|
46199 |
|
46200 | var context = {
|
46201 | newRoot: processElement
|
46202 | };
|
46203 |
|
46204 | this._commandStack.execute('canvas.updateRoot', context);
|
46205 | };
|
46206 |
|
46207 |
|
46208 | Modeling$1.prototype.claimId = function(id, moddleElement) {
|
46209 | this._commandStack.execute('id.updateClaim', {
|
46210 | id: id,
|
46211 | element: moddleElement,
|
46212 | claiming: true
|
46213 | });
|
46214 | };
|
46215 |
|
46216 |
|
46217 | Modeling$1.prototype.unclaimId = function(id, moddleElement) {
|
46218 | this._commandStack.execute('id.updateClaim', {
|
46219 | id: id,
|
46220 | element: moddleElement
|
46221 | });
|
46222 | };
|
46223 |
|
46224 | Modeling$1.prototype.setColor = function(elements, colors) {
|
46225 | if (!elements.length) {
|
46226 | elements = [ elements ];
|
46227 | }
|
46228 |
|
46229 | this._commandStack.execute('element.setColor', {
|
46230 | elements: elements,
|
46231 | colors: colors
|
46232 | });
|
46233 | };
|
46234 |
|
46235 | |
46236 |
|
46237 |
|
46238 |
|
46239 |
|
46240 | function BaseLayouter() {}
|
46241 |
|
46242 |
|
46243 | |
46244 |
|
46245 |
|
46246 |
|
46247 |
|
46248 |
|
46249 |
|
46250 |
|
46251 |
|
46252 |
|
46253 |
|
46254 |
|
46255 |
|
46256 | BaseLayouter.prototype.layoutConnection = function(connection, hints) {
|
46257 |
|
46258 | hints = hints || {};
|
46259 |
|
46260 | return [
|
46261 | hints.connectionStart || getMid(connection.source),
|
46262 | hints.connectionEnd || getMid(connection.target)
|
46263 | ];
|
46264 | };
|
46265 |
|
46266 | var MIN_SEGMENT_LENGTH = 20,
|
46267 | POINT_ORIENTATION_PADDING = 5;
|
46268 |
|
46269 | var round$8 = Math.round;
|
46270 |
|
46271 | var INTERSECTION_THRESHOLD$1 = 20,
|
46272 | ORIENTATION_THRESHOLD = {
|
46273 | 'h:h': 20,
|
46274 | 'v:v': 20,
|
46275 | 'h:v': -10,
|
46276 | 'v:h': -10
|
46277 | };
|
46278 |
|
46279 | function needsTurn(orientation, startDirection) {
|
46280 | return !{
|
46281 | t: /top/,
|
46282 | r: /right/,
|
46283 | b: /bottom/,
|
46284 | l: /left/,
|
46285 | h: /./,
|
46286 | v: /./
|
46287 | }[startDirection].test(orientation);
|
46288 | }
|
46289 |
|
46290 | function canLayoutStraight(direction, targetOrientation) {
|
46291 | return {
|
46292 | t: /top/,
|
46293 | r: /right/,
|
46294 | b: /bottom/,
|
46295 | l: /left/,
|
46296 | h: /left|right/,
|
46297 | v: /top|bottom/
|
46298 | }[direction].test(targetOrientation);
|
46299 | }
|
46300 |
|
46301 | function getSegmentBendpoints(a, b, directions) {
|
46302 | var orientation = getOrientation(b, a, POINT_ORIENTATION_PADDING);
|
46303 |
|
46304 | var startDirection = directions.split(':')[0];
|
46305 |
|
46306 | var xmid = round$8((b.x - a.x) / 2 + a.x),
|
46307 | ymid = round$8((b.y - a.y) / 2 + a.y);
|
46308 |
|
46309 | var segmentEnd, segmentDirections;
|
46310 |
|
46311 | var layoutStraight = canLayoutStraight(startDirection, orientation),
|
46312 | layoutHorizontal = /h|r|l/.test(startDirection),
|
46313 | layoutTurn = false;
|
46314 |
|
46315 | var turnNextDirections = false;
|
46316 |
|
46317 | if (layoutStraight) {
|
46318 | segmentEnd = layoutHorizontal ? { x: xmid, y: a.y } : { x: a.x, y: ymid };
|
46319 |
|
46320 | segmentDirections = layoutHorizontal ? 'h:h' : 'v:v';
|
46321 | } else {
|
46322 | layoutTurn = needsTurn(orientation, startDirection);
|
46323 |
|
46324 | segmentDirections = layoutHorizontal ? 'h:v' : 'v:h';
|
46325 |
|
46326 | if (layoutTurn) {
|
46327 |
|
46328 | if (layoutHorizontal) {
|
46329 | turnNextDirections = ymid === a.y;
|
46330 |
|
46331 | segmentEnd = {
|
46332 | x: a.x + MIN_SEGMENT_LENGTH * (/l/.test(startDirection) ? -1 : 1),
|
46333 | y: turnNextDirections ? ymid + MIN_SEGMENT_LENGTH : ymid
|
46334 | };
|
46335 | } else {
|
46336 | turnNextDirections = xmid === a.x;
|
46337 |
|
46338 | segmentEnd = {
|
46339 | x: turnNextDirections ? xmid + MIN_SEGMENT_LENGTH : xmid,
|
46340 | y: a.y + MIN_SEGMENT_LENGTH * (/t/.test(startDirection) ? -1 : 1)
|
46341 | };
|
46342 | }
|
46343 |
|
46344 | } else {
|
46345 | segmentEnd = {
|
46346 | x: xmid,
|
46347 | y: ymid
|
46348 | };
|
46349 | }
|
46350 | }
|
46351 |
|
46352 | return {
|
46353 | waypoints: getBendpoints(a, segmentEnd, segmentDirections).concat(segmentEnd),
|
46354 | directions: segmentDirections,
|
46355 | turnNextDirections: turnNextDirections
|
46356 | };
|
46357 | }
|
46358 |
|
46359 | function getStartSegment(a, b, directions) {
|
46360 | return getSegmentBendpoints(a, b, directions);
|
46361 | }
|
46362 |
|
46363 | function getEndSegment(a, b, directions) {
|
46364 | var invertedSegment = getSegmentBendpoints(b, a, invertDirections(directions));
|
46365 |
|
46366 | return {
|
46367 | waypoints: invertedSegment.waypoints.slice().reverse(),
|
46368 | directions: invertDirections(invertedSegment.directions),
|
46369 | turnNextDirections: invertedSegment.turnNextDirections
|
46370 | };
|
46371 | }
|
46372 |
|
46373 | function getMidSegment(startSegment, endSegment) {
|
46374 |
|
46375 | var startDirection = startSegment.directions.split(':')[1],
|
46376 | endDirection = endSegment.directions.split(':')[0];
|
46377 |
|
46378 | if (startSegment.turnNextDirections) {
|
46379 | startDirection = startDirection == 'h' ? 'v' : 'h';
|
46380 | }
|
46381 |
|
46382 | if (endSegment.turnNextDirections) {
|
46383 | endDirection = endDirection == 'h' ? 'v' : 'h';
|
46384 | }
|
46385 |
|
46386 | var directions = startDirection + ':' + endDirection;
|
46387 |
|
46388 | var bendpoints = getBendpoints(
|
46389 | startSegment.waypoints[startSegment.waypoints.length - 1],
|
46390 | endSegment.waypoints[0],
|
46391 | directions
|
46392 | );
|
46393 |
|
46394 | return {
|
46395 | waypoints: bendpoints,
|
46396 | directions: directions
|
46397 | };
|
46398 | }
|
46399 |
|
46400 | function invertDirections(directions) {
|
46401 | return directions.split(':').reverse().join(':');
|
46402 | }
|
46403 |
|
46404 | |
46405 |
|
46406 |
|
46407 | function getSimpleBendpoints(a, b, directions) {
|
46408 |
|
46409 | var xmid = round$8((b.x - a.x) / 2 + a.x),
|
46410 | ymid = round$8((b.y - a.y) / 2 + a.y);
|
46411 |
|
46412 |
|
46413 | if (directions === 'h:v') {
|
46414 | return [ { x: b.x, y: a.y } ];
|
46415 | }
|
46416 |
|
46417 |
|
46418 | if (directions === 'v:h') {
|
46419 | return [ { x: a.x, y: b.y } ];
|
46420 | }
|
46421 |
|
46422 |
|
46423 | if (directions === 'h:h') {
|
46424 | return [
|
46425 | { x: xmid, y: a.y },
|
46426 | { x: xmid, y: b.y }
|
46427 | ];
|
46428 | }
|
46429 |
|
46430 |
|
46431 | if (directions === 'v:v') {
|
46432 | return [
|
46433 | { x: a.x, y: ymid },
|
46434 | { x: b.x, y: ymid }
|
46435 | ];
|
46436 | }
|
46437 |
|
46438 | throw new Error('invalid directions: can only handle varians of [hv]:[hv]');
|
46439 | }
|
46440 |
|
46441 |
|
46442 | |
46443 |
|
46444 |
|
46445 |
|
46446 |
|
46447 |
|
46448 |
|
46449 |
|
46450 |
|
46451 |
|
46452 |
|
46453 |
|
46454 |
|
46455 |
|
46456 |
|
46457 |
|
46458 |
|
46459 |
|
46460 |
|
46461 |
|
46462 |
|
46463 |
|
46464 |
|
46465 |
|
46466 |
|
46467 |
|
46468 |
|
46469 | function getBendpoints(a, b, directions) {
|
46470 | directions = directions || 'h:h';
|
46471 |
|
46472 | if (!isValidDirections(directions)) {
|
46473 | throw new Error(
|
46474 | 'unknown directions: <' + directions + '>: ' +
|
46475 | 'must be specified as <start>:<end> ' +
|
46476 | 'with start/end in { h,v,t,r,b,l }'
|
46477 | );
|
46478 | }
|
46479 |
|
46480 |
|
46481 |
|
46482 | if (isExplicitDirections(directions)) {
|
46483 | var startSegment = getStartSegment(a, b, directions),
|
46484 | endSegment = getEndSegment(a, b, directions),
|
46485 | midSegment = getMidSegment(startSegment, endSegment);
|
46486 |
|
46487 | return [].concat(
|
46488 | startSegment.waypoints,
|
46489 | midSegment.waypoints,
|
46490 | endSegment.waypoints
|
46491 | );
|
46492 | }
|
46493 |
|
46494 |
|
46495 | return getSimpleBendpoints(a, b, directions);
|
46496 | }
|
46497 |
|
46498 | |
46499 |
|
46500 |
|
46501 |
|
46502 |
|
46503 |
|
46504 |
|
46505 |
|
46506 |
|
46507 |
|
46508 |
|
46509 |
|
46510 | function connectPoints(a, b, directions) {
|
46511 |
|
46512 | var points = getBendpoints(a, b, directions);
|
46513 |
|
46514 | points.unshift(a);
|
46515 | points.push(b);
|
46516 |
|
46517 | return withoutRedundantPoints(points);
|
46518 | }
|
46519 |
|
46520 |
|
46521 | |
46522 |
|
46523 |
|
46524 |
|
46525 |
|
46526 |
|
46527 |
|
46528 |
|
46529 |
|
46530 |
|
46531 |
|
46532 |
|
46533 |
|
46534 |
|
46535 |
|
46536 |
|
46537 | function connectRectangles(source, target, start, end, hints) {
|
46538 |
|
46539 | var preferredLayouts = hints && hints.preferredLayouts || [];
|
46540 |
|
46541 | var preferredLayout = without(preferredLayouts, 'straight')[0] || 'h:h';
|
46542 |
|
46543 | var threshold = ORIENTATION_THRESHOLD[preferredLayout] || 0;
|
46544 |
|
46545 | var orientation = getOrientation(source, target, threshold);
|
46546 |
|
46547 | var directions = getDirections(orientation, preferredLayout);
|
46548 |
|
46549 | start = start || getMid(source);
|
46550 | end = end || getMid(target);
|
46551 |
|
46552 | var directionSplit = directions.split(':');
|
46553 |
|
46554 |
|
46555 |
|
46556 |
|
46557 | var startDocking = getDockingPoint(start, source, directionSplit[0], invertOrientation(orientation)),
|
46558 | endDocking = getDockingPoint(end, target, directionSplit[1], orientation);
|
46559 |
|
46560 | return connectPoints(startDocking, endDocking, directions);
|
46561 | }
|
46562 |
|
46563 |
|
46564 | |
46565 |
|
46566 |
|
46567 |
|
46568 |
|
46569 |
|
46570 |
|
46571 |
|
46572 |
|
46573 |
|
46574 |
|
46575 |
|
46576 |
|
46577 |
|
46578 |
|
46579 | function repairConnection(source, target, start, end, waypoints, hints) {
|
46580 |
|
46581 | if (isArray(start)) {
|
46582 | waypoints = start;
|
46583 | hints = end;
|
46584 |
|
46585 | start = getMid(source);
|
46586 | end = getMid(target);
|
46587 | }
|
46588 |
|
46589 | hints = assign({ preferredLayouts: [] }, hints);
|
46590 | waypoints = waypoints || [];
|
46591 |
|
46592 | var preferredLayouts = hints.preferredLayouts,
|
46593 | preferStraight = preferredLayouts.indexOf('straight') !== -1,
|
46594 | repairedWaypoints;
|
46595 |
|
46596 |
|
46597 |
|
46598 |
|
46599 | if (preferStraight) {
|
46600 |
|
46601 | repairedWaypoints = layoutStraight(source, target, start, end, hints);
|
46602 | }
|
46603 |
|
46604 | if (!repairedWaypoints) {
|
46605 |
|
46606 | if (hints.connectionEnd) {
|
46607 | repairedWaypoints = _repairConnectionSide(target, source, end, waypoints.slice().reverse());
|
46608 | repairedWaypoints = repairedWaypoints && repairedWaypoints.reverse();
|
46609 | } else
|
46610 | if (hints.connectionStart) {
|
46611 | repairedWaypoints = _repairConnectionSide(source, target, start, waypoints);
|
46612 | } else
|
46613 |
|
46614 | if (waypoints && waypoints.length) {
|
46615 | repairedWaypoints = waypoints;
|
46616 | }
|
46617 | }
|
46618 |
|
46619 |
|
46620 | if (!repairedWaypoints) {
|
46621 | repairedWaypoints = connectRectangles(source, target, start, end, hints);
|
46622 | }
|
46623 |
|
46624 | return repairedWaypoints;
|
46625 | }
|
46626 |
|
46627 |
|
46628 | function inRange(a, start, end) {
|
46629 | return a >= start && a <= end;
|
46630 | }
|
46631 |
|
46632 | function isInRange(axis, a, b) {
|
46633 | var size$$1 = {
|
46634 | x: 'width',
|
46635 | y: 'height'
|
46636 | };
|
46637 |
|
46638 | return inRange(a[axis], b[axis], b[axis] + b[size$$1[axis]]);
|
46639 | }
|
46640 |
|
46641 | |
46642 |
|
46643 |
|
46644 |
|
46645 |
|
46646 |
|
46647 |
|
46648 |
|
46649 |
|
46650 |
|
46651 |
|
46652 | function layoutStraight(source, target, start, end, hints) {
|
46653 | var axis = {},
|
46654 | primaryAxis,
|
46655 | orientation;
|
46656 |
|
46657 | orientation = getOrientation(source, target);
|
46658 |
|
46659 |
|
46660 |
|
46661 | if (!/^(top|bottom|left|right)$/.test(orientation)) {
|
46662 | return null;
|
46663 | }
|
46664 |
|
46665 | if (/top|bottom/.test(orientation)) {
|
46666 | primaryAxis = 'x';
|
46667 | }
|
46668 |
|
46669 | if (/left|right/.test(orientation)) {
|
46670 | primaryAxis = 'y';
|
46671 | }
|
46672 |
|
46673 | if (hints.preserveDocking === 'target') {
|
46674 |
|
46675 | if (!isInRange(primaryAxis, end, source)) {
|
46676 | return null;
|
46677 | }
|
46678 |
|
46679 | axis[primaryAxis] = end[primaryAxis];
|
46680 |
|
46681 | return [
|
46682 | {
|
46683 | x: axis.x !== undefined ? axis.x : start.x,
|
46684 | y: axis.y !== undefined ? axis.y : start.y,
|
46685 | original: {
|
46686 | x: axis.x !== undefined ? axis.x : start.x,
|
46687 | y: axis.y !== undefined ? axis.y : start.y
|
46688 | }
|
46689 | },
|
46690 | {
|
46691 | x: end.x,
|
46692 | y: end.y
|
46693 | }
|
46694 | ];
|
46695 |
|
46696 | } else {
|
46697 |
|
46698 | if (!isInRange(primaryAxis, start, target)) {
|
46699 | return null;
|
46700 | }
|
46701 |
|
46702 | axis[primaryAxis] = start[primaryAxis];
|
46703 |
|
46704 | return [
|
46705 | {
|
46706 | x: start.x,
|
46707 | y: start.y
|
46708 | },
|
46709 | {
|
46710 | x: axis.x !== undefined ? axis.x : end.x,
|
46711 | y: axis.y !== undefined ? axis.y : end.y,
|
46712 | original: {
|
46713 | x: axis.x !== undefined ? axis.x : end.x,
|
46714 | y: axis.y !== undefined ? axis.y : end.y
|
46715 | }
|
46716 | }
|
46717 | ];
|
46718 | }
|
46719 |
|
46720 | }
|
46721 |
|
46722 |
|
46723 | |
46724 |
|
46725 |
|
46726 |
|
46727 |
|
46728 |
|
46729 |
|
46730 |
|
46731 |
|
46732 |
|
46733 | function _repairConnectionSide(moved, other, newDocking, points) {
|
46734 |
|
46735 | function needsRelayout(moved, other, points) {
|
46736 |
|
46737 | if (points.length < 3) {
|
46738 | return true;
|
46739 | }
|
46740 |
|
46741 | if (points.length > 4) {
|
46742 | return false;
|
46743 | }
|
46744 |
|
46745 |
|
46746 |
|
46747 | return !!find(points, function(p, idx) {
|
46748 | var q = points[idx - 1];
|
46749 |
|
46750 | return q && pointDistance(p, q) < 3;
|
46751 | });
|
46752 | }
|
46753 |
|
46754 | function repairBendpoint(candidate, oldPeer, newPeer) {
|
46755 |
|
46756 | var alignment = pointsAligned(oldPeer, candidate);
|
46757 |
|
46758 | switch (alignment) {
|
46759 | case 'v':
|
46760 |
|
46761 | return { x: candidate.x, y: newPeer.y };
|
46762 | case 'h':
|
46763 |
|
46764 | return { x: newPeer.x, y: candidate.y };
|
46765 | }
|
46766 |
|
46767 | return { x: candidate.x, y: candidate. y };
|
46768 | }
|
46769 |
|
46770 | function removeOverlapping(points, a, b) {
|
46771 | var i;
|
46772 |
|
46773 | for (i = points.length - 2; i !== 0; i--) {
|
46774 |
|
46775 |
|
46776 | if (pointInRect(points[i], a, INTERSECTION_THRESHOLD$1) ||
|
46777 | pointInRect(points[i], b, INTERSECTION_THRESHOLD$1)) {
|
46778 |
|
46779 |
|
46780 | return points.slice(i);
|
46781 | }
|
46782 | }
|
46783 |
|
46784 | return points;
|
46785 | }
|
46786 |
|
46787 |
|
46788 |
|
46789 |
|
46790 |
|
46791 |
|
46792 |
|
46793 | if (needsRelayout(moved, other, points)) {
|
46794 | return null;
|
46795 | }
|
46796 |
|
46797 | var oldDocking = points[0],
|
46798 | newPoints = points.slice(),
|
46799 | slicedPoints;
|
46800 |
|
46801 |
|
46802 |
|
46803 | newPoints[0] = newDocking;
|
46804 | newPoints[1] = repairBendpoint(newPoints[1], oldDocking, newDocking);
|
46805 |
|
46806 |
|
46807 |
|
46808 |
|
46809 |
|
46810 | slicedPoints = removeOverlapping(newPoints, moved, other);
|
46811 |
|
46812 | if (slicedPoints !== newPoints) {
|
46813 | return _repairConnectionSide(moved, other, newDocking, slicedPoints);
|
46814 | }
|
46815 |
|
46816 | return newPoints;
|
46817 | }
|
46818 |
|
46819 |
|
46820 | |
46821 |
|
46822 |
|
46823 |
|
46824 |
|
46825 |
|
46826 |
|
46827 |
|
46828 |
|
46829 |
|
46830 |
|
46831 |
|
46832 |
|
46833 |
|
46834 |
|
46835 |
|
46836 |
|
46837 |
|
46838 |
|
46839 |
|
46840 |
|
46841 | function getDirections(orientation, defaultLayout) {
|
46842 |
|
46843 |
|
46844 | if (isExplicitDirections(defaultLayout)) {
|
46845 | return defaultLayout;
|
46846 | }
|
46847 |
|
46848 | switch (orientation) {
|
46849 | case 'intersect':
|
46850 | return 't:t';
|
46851 |
|
46852 | case 'top':
|
46853 | case 'bottom':
|
46854 | return 'v:v';
|
46855 |
|
46856 | case 'left':
|
46857 | case 'right':
|
46858 | return 'h:h';
|
46859 |
|
46860 |
|
46861 |
|
46862 |
|
46863 |
|
46864 | default:
|
46865 | return defaultLayout;
|
46866 | }
|
46867 | }
|
46868 |
|
46869 | function isValidDirections(directions) {
|
46870 | return directions && /^h|v|t|r|b|l:h|v|t|r|b|l$/.test(directions);
|
46871 | }
|
46872 |
|
46873 | function isExplicitDirections(directions) {
|
46874 | return directions && /t|r|b|l/.test(directions);
|
46875 | }
|
46876 |
|
46877 | function invertOrientation(orientation) {
|
46878 | return {
|
46879 | 'top': 'bottom',
|
46880 | 'bottom': 'top',
|
46881 | 'left': 'right',
|
46882 | 'right': 'left',
|
46883 | 'top-left': 'bottom-right',
|
46884 | 'bottom-right': 'top-left',
|
46885 | 'top-right': 'bottom-left',
|
46886 | 'bottom-left': 'top-right',
|
46887 | }[orientation];
|
46888 | }
|
46889 |
|
46890 | function getDockingPoint(point, rectangle, dockingDirection, targetOrientation) {
|
46891 |
|
46892 |
|
46893 |
|
46894 |
|
46895 | if (dockingDirection === 'h') {
|
46896 | dockingDirection = /left/.test(targetOrientation) ? 'l' : 'r';
|
46897 | }
|
46898 |
|
46899 | if (dockingDirection === 'v') {
|
46900 | dockingDirection = /top/.test(targetOrientation) ? 't' : 'b';
|
46901 | }
|
46902 |
|
46903 | if (dockingDirection === 't') {
|
46904 | return { original: point, x: point.x, y: rectangle.y };
|
46905 | }
|
46906 |
|
46907 | if (dockingDirection === 'r') {
|
46908 | return { original: point, x: rectangle.x + rectangle.width, y: point.y };
|
46909 | }
|
46910 |
|
46911 | if (dockingDirection === 'b') {
|
46912 | return { original: point, x: point.x, y: rectangle.y + rectangle.height };
|
46913 | }
|
46914 |
|
46915 | if (dockingDirection === 'l') {
|
46916 | return { original: point, x: rectangle.x, y: point.y };
|
46917 | }
|
46918 |
|
46919 | throw new Error('unexpected dockingDirection: <' + dockingDirection + '>');
|
46920 | }
|
46921 |
|
46922 |
|
46923 | |
46924 |
|
46925 |
|
46926 |
|
46927 |
|
46928 |
|
46929 |
|
46930 |
|
46931 |
|
46932 |
|
46933 |
|
46934 |
|
46935 |
|
46936 |
|
46937 |
|
46938 |
|
46939 |
|
46940 |
|
46941 |
|
46942 |
|
46943 |
|
46944 | function withoutRedundantPoints(waypoints) {
|
46945 | return waypoints.reduce(function(points, p, idx) {
|
46946 |
|
46947 | var previous = points[points.length - 1],
|
46948 | next = waypoints[idx + 1];
|
46949 |
|
46950 | if (!pointsOnLine(previous, next, p, 0)) {
|
46951 | points.push(p);
|
46952 | }
|
46953 |
|
46954 | return points;
|
46955 | }, []);
|
46956 | }
|
46957 |
|
46958 | function BpmnLayouter() {}
|
46959 |
|
46960 | inherits_browser(BpmnLayouter, BaseLayouter);
|
46961 |
|
46962 |
|
46963 | BpmnLayouter.prototype.layoutConnection = function(connection, hints) {
|
46964 | hints = hints || {};
|
46965 |
|
46966 | var source = connection.source,
|
46967 | target = connection.target,
|
46968 | waypoints = connection.waypoints,
|
46969 | start = hints.connectionStart,
|
46970 | end = hints.connectionEnd;
|
46971 |
|
46972 | var manhattanOptions,
|
46973 | updatedWaypoints;
|
46974 |
|
46975 | if (!start) {
|
46976 | start = getConnectionDocking(waypoints && waypoints[0], source);
|
46977 | }
|
46978 |
|
46979 | if (!end) {
|
46980 | end = getConnectionDocking(waypoints && waypoints[waypoints.length - 1], target);
|
46981 | }
|
46982 |
|
46983 |
|
46984 |
|
46985 |
|
46986 | if (is$1(connection, 'bpmn:Association') ||
|
46987 | is$1(connection, 'bpmn:DataAssociation')) {
|
46988 |
|
46989 | if (waypoints && !isCompensationAssociation(connection)) {
|
46990 | return [].concat([ start ], waypoints.slice(1, -1), [ end ]);
|
46991 | }
|
46992 | }
|
46993 |
|
46994 |
|
46995 | if (is$1(connection, 'bpmn:MessageFlow')) {
|
46996 | manhattanOptions = getMessageFlowManhattanOptions(source, target);
|
46997 |
|
46998 | } else
|
46999 |
|
47000 |
|
47001 |
|
47002 |
|
47003 |
|
47004 |
|
47005 |
|
47006 |
|
47007 |
|
47008 |
|
47009 | if (is$1(connection, 'bpmn:SequenceFlow') ||
|
47010 | isCompensationAssociation(connection)) {
|
47011 |
|
47012 | if (source === target) {
|
47013 | manhattanOptions = {
|
47014 | preferredLayouts: [ 'b:l' ]
|
47015 | };
|
47016 | } else
|
47017 |
|
47018 | if (is$1(source, 'bpmn:BoundaryEvent')) {
|
47019 |
|
47020 | manhattanOptions = {
|
47021 | preferredLayouts: getBoundaryEventPreferredLayouts(source, target)
|
47022 | };
|
47023 |
|
47024 | } else
|
47025 |
|
47026 | if (is$1(source, 'bpmn:Gateway')) {
|
47027 |
|
47028 | manhattanOptions = {
|
47029 | preferredLayouts: [ 'v:h' ]
|
47030 | };
|
47031 | } else
|
47032 |
|
47033 | if (is$1(target, 'bpmn:Gateway')) {
|
47034 |
|
47035 | manhattanOptions = {
|
47036 | preferredLayouts: [ 'h:v' ]
|
47037 | };
|
47038 | }
|
47039 |
|
47040 | else {
|
47041 | manhattanOptions = {
|
47042 | preferredLayouts: [ 'h:h' ]
|
47043 | };
|
47044 | }
|
47045 |
|
47046 | }
|
47047 |
|
47048 | if (manhattanOptions) {
|
47049 |
|
47050 | manhattanOptions = assign(manhattanOptions, hints);
|
47051 |
|
47052 | updatedWaypoints =
|
47053 | withoutRedundantPoints(
|
47054 | repairConnection(
|
47055 | source, target,
|
47056 | start, end,
|
47057 | waypoints,
|
47058 | manhattanOptions
|
47059 | )
|
47060 | );
|
47061 | }
|
47062 |
|
47063 | return updatedWaypoints || [ start, end ];
|
47064 | };
|
47065 |
|
47066 |
|
47067 | function getAttachOrientation(attachedElement) {
|
47068 |
|
47069 | var hostElement = attachedElement.host,
|
47070 | padding = -10;
|
47071 |
|
47072 | return getOrientation(getMid(attachedElement), hostElement, padding);
|
47073 | }
|
47074 |
|
47075 |
|
47076 | function getMessageFlowManhattanOptions(source, target) {
|
47077 | return {
|
47078 | preferredLayouts: [ 'straight', 'v:v' ],
|
47079 | preserveDocking: getMessageFlowPreserveDocking(source, target)
|
47080 | };
|
47081 | }
|
47082 |
|
47083 |
|
47084 | function getMessageFlowPreserveDocking(source, target) {
|
47085 |
|
47086 |
|
47087 |
|
47088 | if (is$1(target, 'bpmn:Participant')) {
|
47089 | return 'source';
|
47090 | }
|
47091 |
|
47092 | if (is$1(source, 'bpmn:Participant')) {
|
47093 | return 'target';
|
47094 | }
|
47095 |
|
47096 |
|
47097 |
|
47098 | if (isExpandedSubProcess$1(target)) {
|
47099 | return 'source';
|
47100 | }
|
47101 |
|
47102 | if (isExpandedSubProcess$1(source)) {
|
47103 | return 'target';
|
47104 | }
|
47105 |
|
47106 |
|
47107 |
|
47108 | if (is$1(target, 'bpmn:Event')) {
|
47109 | return 'target';
|
47110 | }
|
47111 |
|
47112 | if (is$1(source, 'bpmn:Event')) {
|
47113 | return 'source';
|
47114 | }
|
47115 |
|
47116 | return null;
|
47117 | }
|
47118 |
|
47119 |
|
47120 | function getConnectionDocking(point, shape) {
|
47121 | return point ? (point.original || point) : getMid(shape);
|
47122 | }
|
47123 |
|
47124 | function isCompensationAssociation(connection) {
|
47125 |
|
47126 | var source = connection.source,
|
47127 | target = connection.target;
|
47128 |
|
47129 | return is$1(target, 'bpmn:Activity') &&
|
47130 | is$1(source, 'bpmn:BoundaryEvent') &&
|
47131 | target.businessObject.isForCompensation;
|
47132 | }
|
47133 |
|
47134 |
|
47135 | function isExpandedSubProcess$1(element) {
|
47136 | return is$1(element, 'bpmn:SubProcess') && isExpanded(element);
|
47137 | }
|
47138 |
|
47139 | function isSame$1(a, b) {
|
47140 | return a === b;
|
47141 | }
|
47142 |
|
47143 | function isAnyOrientation(orientation, orientations) {
|
47144 | return orientations.indexOf(orientation) !== -1;
|
47145 | }
|
47146 |
|
47147 | var oppositeOrientationMapping = {
|
47148 | 'top': 'bottom',
|
47149 | 'top-right': 'bottom-left',
|
47150 | 'top-left': 'bottom-right',
|
47151 | 'right': 'left',
|
47152 | 'bottom': 'top',
|
47153 | 'bottom-right': 'top-left',
|
47154 | 'bottom-left': 'top-right',
|
47155 | 'left': 'right'
|
47156 | };
|
47157 |
|
47158 | var orientationDirectionMapping = {
|
47159 | top: 't',
|
47160 | right: 'r',
|
47161 | bottom: 'b',
|
47162 | left: 'l'
|
47163 | };
|
47164 |
|
47165 | function getHorizontalOrientation(orientation) {
|
47166 | var matches = /right|left/.exec(orientation);
|
47167 |
|
47168 | return matches && matches[0];
|
47169 | }
|
47170 |
|
47171 | function getVerticalOrientation(orientation) {
|
47172 | var matches = /top|bottom/.exec(orientation);
|
47173 |
|
47174 | return matches && matches[0];
|
47175 | }
|
47176 |
|
47177 | function isOppositeOrientation(a, b) {
|
47178 | return oppositeOrientationMapping[a] === b;
|
47179 | }
|
47180 |
|
47181 | function isOppositeHorizontalOrientation(a, b) {
|
47182 | var horizontalOrientation = getHorizontalOrientation(a);
|
47183 |
|
47184 | var oppositeHorizontalOrientation = oppositeOrientationMapping[horizontalOrientation];
|
47185 |
|
47186 | return b.indexOf(oppositeHorizontalOrientation) !== -1;
|
47187 | }
|
47188 |
|
47189 | function isOppositeVerticalOrientation(a, b) {
|
47190 | var verticalOrientation = getVerticalOrientation(a);
|
47191 |
|
47192 | var oppositeVerticalOrientation = oppositeOrientationMapping[verticalOrientation];
|
47193 |
|
47194 | return b.indexOf(oppositeVerticalOrientation) !== -1;
|
47195 | }
|
47196 |
|
47197 | function isHorizontalOrientation(orientation) {
|
47198 | return orientation === 'right' || orientation === 'left';
|
47199 | }
|
47200 |
|
47201 | function getBoundaryEventPreferredLayouts(source, target) {
|
47202 | var sourceMid = getMid(source),
|
47203 | targetMid = getMid(target),
|
47204 | attachOrientation = getAttachOrientation(source),
|
47205 | sourceLayout,
|
47206 | targetlayout;
|
47207 |
|
47208 | var isLoop = isSame$1(source.host, target);
|
47209 |
|
47210 | var attachedToSide = isAnyOrientation(attachOrientation, [ 'top', 'right', 'bottom', 'left' ]);
|
47211 |
|
47212 | var isHorizontalAttachOrientation = isHorizontalOrientation(attachOrientation);
|
47213 |
|
47214 | var targetOrientation = getOrientation(targetMid, sourceMid, {
|
47215 | x: source.width / 2 + target.width / 2,
|
47216 | y: source.height / 2 + target.height / 2
|
47217 | });
|
47218 |
|
47219 |
|
47220 |
|
47221 |
|
47222 | if (attachedToSide) {
|
47223 |
|
47224 | sourceLayout = orientationDirectionMapping[
|
47225 | isHorizontalAttachOrientation ?
|
47226 | getHorizontalOrientation(attachOrientation) :
|
47227 | getVerticalOrientation(attachOrientation)
|
47228 | ];
|
47229 |
|
47230 | } else
|
47231 |
|
47232 |
|
47233 | {
|
47234 |
|
47235 |
|
47236 | if (isLoop ||
|
47237 | isSame$1(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) ||
|
47238 | isOppositeOrientation(getHorizontalOrientation(attachOrientation), getHorizontalOrientation(targetOrientation))
|
47239 | ) {
|
47240 | sourceLayout = orientationDirectionMapping[getVerticalOrientation(attachOrientation)];
|
47241 | } else {
|
47242 | sourceLayout = orientationDirectionMapping[getHorizontalOrientation(attachOrientation)];
|
47243 | }
|
47244 |
|
47245 | }
|
47246 |
|
47247 |
|
47248 |
|
47249 |
|
47250 | if (attachedToSide) {
|
47251 |
|
47252 |
|
47253 | if (
|
47254 | isLoop ||
|
47255 | (isHorizontalAttachOrientation ?
|
47256 | isOppositeHorizontalOrientation(attachOrientation, targetOrientation) :
|
47257 | isOppositeVerticalOrientation(attachOrientation, targetOrientation))
|
47258 | ) {
|
47259 | targetlayout = isHorizontalAttachOrientation ? 'h' : 'v';
|
47260 | } else {
|
47261 | targetlayout = isHorizontalAttachOrientation ? 'v' : 'h';
|
47262 | }
|
47263 |
|
47264 | } else
|
47265 |
|
47266 |
|
47267 | {
|
47268 |
|
47269 |
|
47270 |
|
47271 | if (
|
47272 | isHorizontalOrientation(targetOrientation) ||
|
47273 | (isSame$1(getVerticalOrientation(attachOrientation), getVerticalOrientation(targetOrientation)) &&
|
47274 | getHorizontalOrientation(targetOrientation))
|
47275 | ) {
|
47276 | targetlayout = 'h';
|
47277 | } else {
|
47278 | targetlayout = 'v';
|
47279 | }
|
47280 |
|
47281 | }
|
47282 |
|
47283 | return [ sourceLayout + ':' + targetlayout ];
|
47284 | }
|
47285 |
|
47286 | function dockingToPoint(docking) {
|
47287 |
|
47288 |
|
47289 | return assign({ original: docking.point.original || docking.point }, docking.actual);
|
47290 | }
|
47291 |
|
47292 |
|
47293 | |
47294 |
|
47295 |
|
47296 |
|
47297 |
|
47298 |
|
47299 | function CroppingConnectionDocking(elementRegistry, graphicsFactory) {
|
47300 | this._elementRegistry = elementRegistry;
|
47301 | this._graphicsFactory = graphicsFactory;
|
47302 | }
|
47303 |
|
47304 | CroppingConnectionDocking.$inject = [ 'elementRegistry', 'graphicsFactory' ];
|
47305 |
|
47306 |
|
47307 | |
47308 |
|
47309 |
|
47310 | CroppingConnectionDocking.prototype.getCroppedWaypoints = function(connection, source, target) {
|
47311 |
|
47312 | source = source || connection.source;
|
47313 | target = target || connection.target;
|
47314 |
|
47315 | var sourceDocking = this.getDockingPoint(connection, source, true),
|
47316 | targetDocking = this.getDockingPoint(connection, target);
|
47317 |
|
47318 | var croppedWaypoints = connection.waypoints.slice(sourceDocking.idx + 1, targetDocking.idx);
|
47319 |
|
47320 | croppedWaypoints.unshift(dockingToPoint(sourceDocking));
|
47321 | croppedWaypoints.push(dockingToPoint(targetDocking));
|
47322 |
|
47323 | return croppedWaypoints;
|
47324 | };
|
47325 |
|
47326 | |
47327 |
|
47328 |
|
47329 |
|
47330 |
|
47331 | CroppingConnectionDocking.prototype.getDockingPoint = function(connection, shape, dockStart) {
|
47332 |
|
47333 | var waypoints = connection.waypoints,
|
47334 | dockingIdx,
|
47335 | dockingPoint,
|
47336 | croppedPoint;
|
47337 |
|
47338 | dockingIdx = dockStart ? 0 : waypoints.length - 1;
|
47339 | dockingPoint = waypoints[dockingIdx];
|
47340 |
|
47341 | croppedPoint = this._getIntersection(shape, connection, dockStart);
|
47342 |
|
47343 | return {
|
47344 | point: dockingPoint,
|
47345 | actual: croppedPoint || dockingPoint,
|
47346 | idx: dockingIdx
|
47347 | };
|
47348 | };
|
47349 |
|
47350 |
|
47351 |
|
47352 |
|
47353 | CroppingConnectionDocking.prototype._getIntersection = function(shape, connection, takeFirst) {
|
47354 |
|
47355 | var shapePath = this._getShapePath(shape),
|
47356 | connectionPath = this._getConnectionPath(connection);
|
47357 |
|
47358 | return getElementLineIntersection(shapePath, connectionPath, takeFirst);
|
47359 | };
|
47360 |
|
47361 | CroppingConnectionDocking.prototype._getConnectionPath = function(connection) {
|
47362 | return this._graphicsFactory.getConnectionPath(connection);
|
47363 | };
|
47364 |
|
47365 | CroppingConnectionDocking.prototype._getShapePath = function(shape) {
|
47366 | return this._graphicsFactory.getShapePath(shape);
|
47367 | };
|
47368 |
|
47369 | CroppingConnectionDocking.prototype._getGfx = function(element) {
|
47370 | return this._elementRegistry.getGraphics(element);
|
47371 | };
|
47372 |
|
47373 | var ModelingModule = {
|
47374 | __init__: [
|
47375 | 'modeling',
|
47376 | 'bpmnUpdater'
|
47377 | ],
|
47378 | __depends__: [
|
47379 | BehaviorModule,
|
47380 | RulesModule$1,
|
47381 | OrderingModule,
|
47382 | ReplaceModule$1,
|
47383 | CommandModule,
|
47384 | TooltipsModule,
|
47385 | LabelSupportModule,
|
47386 | AttachSupportModule,
|
47387 | SelectionModule,
|
47388 | ChangeSupportModule,
|
47389 | SpaceToolModule
|
47390 | ],
|
47391 | bpmnFactory: [ 'type', BpmnFactory ],
|
47392 | bpmnUpdater: [ 'type', BpmnUpdater ],
|
47393 | elementFactory: [ 'type', ElementFactory$1 ],
|
47394 | modeling: [ 'type', Modeling$1 ],
|
47395 | layouter: [ 'type', BpmnLayouter ],
|
47396 | connectionDocking: [ 'type', CroppingConnectionDocking ]
|
47397 | };
|
47398 |
|
47399 | var LOW_PRIORITY$d = 500,
|
47400 | MEDIUM_PRIORITY = 1250,
|
47401 | HIGH_PRIORITY$4 = 1500;
|
47402 |
|
47403 | var round$9 = Math.round;
|
47404 |
|
47405 | function mid$1(element) {
|
47406 | return {
|
47407 | x: element.x + round$9(element.width / 2),
|
47408 | y: element.y + round$9(element.height / 2)
|
47409 | };
|
47410 | }
|
47411 |
|
47412 | |
47413 |
|
47414 |
|
47415 |
|
47416 |
|
47417 |
|
47418 |
|
47419 |
|
47420 |
|
47421 | function MoveEvents(
|
47422 | eventBus, dragging, modeling,
|
47423 | selection, rules) {
|
47424 |
|
47425 |
|
47426 |
|
47427 | function canMove(shapes, delta, position, target) {
|
47428 |
|
47429 | return rules.allowed('elements.move', {
|
47430 | shapes: shapes,
|
47431 | delta: delta,
|
47432 | position: position,
|
47433 | target: target
|
47434 | });
|
47435 | }
|
47436 |
|
47437 |
|
47438 |
|
47439 |
|
47440 |
|
47441 |
|
47442 |
|
47443 |
|
47444 |
|
47445 |
|
47446 |
|
47447 |
|
47448 |
|
47449 |
|
47450 |
|
47451 | eventBus.on('shape.move.start', HIGH_PRIORITY$4, function(event) {
|
47452 |
|
47453 | var context = event.context,
|
47454 | shape = event.shape,
|
47455 | shapes = selection.get().slice();
|
47456 |
|
47457 |
|
47458 |
|
47459 | if (shapes.indexOf(shape) === -1) {
|
47460 | shapes = [ shape ];
|
47461 | }
|
47462 |
|
47463 |
|
47464 |
|
47465 | shapes = removeNested(shapes);
|
47466 |
|
47467 |
|
47468 | assign(context, {
|
47469 | shapes: shapes,
|
47470 | validatedShapes: shapes,
|
47471 | shape: shape
|
47472 | });
|
47473 | });
|
47474 |
|
47475 |
|
47476 |
|
47477 |
|
47478 |
|
47479 |
|
47480 | eventBus.on('shape.move.start', MEDIUM_PRIORITY, function(event) {
|
47481 |
|
47482 | var context = event.context,
|
47483 | validatedShapes = context.validatedShapes,
|
47484 | canExecute;
|
47485 |
|
47486 | canExecute = context.canExecute = canMove(validatedShapes);
|
47487 |
|
47488 |
|
47489 | if (!canExecute) {
|
47490 | return false;
|
47491 | }
|
47492 | });
|
47493 |
|
47494 |
|
47495 |
|
47496 |
|
47497 |
|
47498 | eventBus.on('shape.move.move', LOW_PRIORITY$d, function(event) {
|
47499 |
|
47500 | var context = event.context,
|
47501 | validatedShapes = context.validatedShapes,
|
47502 | hover = event.hover,
|
47503 | delta = { x: event.dx, y: event.dy },
|
47504 | position = { x: event.x, y: event.y },
|
47505 | canExecute;
|
47506 |
|
47507 |
|
47508 | canExecute = canMove(validatedShapes, delta, position, hover);
|
47509 |
|
47510 | context.delta = delta;
|
47511 | context.canExecute = canExecute;
|
47512 |
|
47513 |
|
47514 | if (canExecute === null) {
|
47515 | context.target = null;
|
47516 |
|
47517 | return;
|
47518 | }
|
47519 |
|
47520 | context.target = hover;
|
47521 | });
|
47522 |
|
47523 | eventBus.on('shape.move.end', function(event) {
|
47524 |
|
47525 | var context = event.context;
|
47526 |
|
47527 | var delta = context.delta,
|
47528 | canExecute = context.canExecute,
|
47529 | isAttach = canExecute === 'attach',
|
47530 | shapes = context.shapes;
|
47531 |
|
47532 | if (!canExecute) {
|
47533 | return false;
|
47534 | }
|
47535 |
|
47536 |
|
47537 |
|
47538 | delta.x = round$9(delta.x);
|
47539 | delta.y = round$9(delta.y);
|
47540 |
|
47541 | modeling.moveElements(shapes, delta, context.target, {
|
47542 | primaryShape: context.shape,
|
47543 | attach: isAttach
|
47544 | });
|
47545 | });
|
47546 |
|
47547 |
|
47548 |
|
47549 |
|
47550 | eventBus.on('element.mousedown', function(event) {
|
47551 |
|
47552 | var originalEvent = getOriginal(event);
|
47553 |
|
47554 | if (!originalEvent) {
|
47555 | throw new Error('must supply DOM mousedown event');
|
47556 | }
|
47557 |
|
47558 | return start(originalEvent, event.element);
|
47559 | });
|
47560 |
|
47561 |
|
47562 | function start(event, element, activate) {
|
47563 |
|
47564 |
|
47565 | if (element.waypoints || !element.parent) {
|
47566 | return;
|
47567 | }
|
47568 |
|
47569 | var referencePoint = mid$1(element);
|
47570 |
|
47571 | dragging.init(event, referencePoint, 'shape.move', {
|
47572 | cursor: 'grabbing',
|
47573 | autoActivate: activate,
|
47574 | data: {
|
47575 | shape: element,
|
47576 | context: {}
|
47577 | }
|
47578 | });
|
47579 |
|
47580 |
|
47581 | return true;
|
47582 | }
|
47583 |
|
47584 |
|
47585 |
|
47586 | this.start = start;
|
47587 | }
|
47588 |
|
47589 | MoveEvents.$inject = [
|
47590 | 'eventBus',
|
47591 | 'dragging',
|
47592 | 'modeling',
|
47593 | 'selection',
|
47594 | 'rules'
|
47595 | ];
|
47596 |
|
47597 |
|
47598 | |
47599 |
|
47600 |
|
47601 |
|
47602 |
|
47603 |
|
47604 |
|
47605 |
|
47606 | function removeNested(elements) {
|
47607 |
|
47608 | var ids = groupBy(elements, 'id');
|
47609 |
|
47610 | return filter(elements, function(element) {
|
47611 | while ((element = element.parent)) {
|
47612 |
|
47613 |
|
47614 | if (ids[element.id]) {
|
47615 | return false;
|
47616 | }
|
47617 | }
|
47618 |
|
47619 | return true;
|
47620 | });
|
47621 | }
|
47622 |
|
47623 | var LOW_PRIORITY$e = 499;
|
47624 |
|
47625 | var MARKER_DRAGGING$1 = 'djs-dragging',
|
47626 | MARKER_OK$3 = 'drop-ok',
|
47627 | MARKER_NOT_OK$3 = 'drop-not-ok',
|
47628 | MARKER_NEW_PARENT$1 = 'new-parent',
|
47629 | MARKER_ATTACH$1 = 'attach-ok';
|
47630 |
|
47631 |
|
47632 | |
47633 |
|
47634 |
|
47635 |
|
47636 |
|
47637 |
|
47638 |
|
47639 |
|
47640 | function MovePreview(
|
47641 | eventBus, elementRegistry, canvas,
|
47642 | styles, previewSupport) {
|
47643 |
|
47644 | function getVisualDragShapes(shapes) {
|
47645 | var elements = getAllDraggedElements(shapes);
|
47646 |
|
47647 | var filteredElements = removeEdges(elements);
|
47648 |
|
47649 | return filteredElements;
|
47650 | }
|
47651 |
|
47652 | function getAllDraggedElements(shapes) {
|
47653 | var allShapes = selfAndAllChildren(shapes, true);
|
47654 |
|
47655 | var allConnections = map(allShapes, function(shape) {
|
47656 | return (shape.incoming || []).concat(shape.outgoing || []);
|
47657 | });
|
47658 |
|
47659 | return flatten(allShapes.concat(allConnections));
|
47660 | }
|
47661 |
|
47662 | |
47663 |
|
47664 |
|
47665 | function setMarker(element, marker) {
|
47666 |
|
47667 | [ MARKER_ATTACH$1, MARKER_OK$3, MARKER_NOT_OK$3, MARKER_NEW_PARENT$1 ].forEach(function(m) {
|
47668 |
|
47669 | if (m === marker) {
|
47670 | canvas.addMarker(element, m);
|
47671 | } else {
|
47672 | canvas.removeMarker(element, m);
|
47673 | }
|
47674 | });
|
47675 | }
|
47676 |
|
47677 | |
47678 |
|
47679 |
|
47680 |
|
47681 |
|
47682 |
|
47683 |
|
47684 | function makeDraggable(context, element, addMarker) {
|
47685 |
|
47686 | previewSupport.addDragger(element, context.dragGroup);
|
47687 |
|
47688 | if (addMarker) {
|
47689 | canvas.addMarker(element, MARKER_DRAGGING$1);
|
47690 | }
|
47691 |
|
47692 | if (context.allDraggedElements) {
|
47693 | context.allDraggedElements.push(element);
|
47694 | } else {
|
47695 | context.allDraggedElements = [ element ];
|
47696 | }
|
47697 | }
|
47698 |
|
47699 |
|
47700 |
|
47701 |
|
47702 | eventBus.on('shape.move.start', LOW_PRIORITY$e, function(event) {
|
47703 |
|
47704 | var context = event.context,
|
47705 | dragShapes = context.shapes,
|
47706 | allDraggedElements = context.allDraggedElements;
|
47707 |
|
47708 | var visuallyDraggedShapes = getVisualDragShapes(dragShapes);
|
47709 |
|
47710 | if (!context.dragGroup) {
|
47711 | var dragGroup = create('g');
|
47712 | attr$1(dragGroup, styles.cls('djs-drag-group', [ 'no-events' ]));
|
47713 |
|
47714 | var defaultLayer = canvas.getDefaultLayer();
|
47715 |
|
47716 | append(defaultLayer, dragGroup);
|
47717 |
|
47718 | context.dragGroup = dragGroup;
|
47719 | }
|
47720 |
|
47721 |
|
47722 | visuallyDraggedShapes.forEach(function(shape) {
|
47723 | previewSupport.addDragger(shape, context.dragGroup);
|
47724 | });
|
47725 |
|
47726 |
|
47727 |
|
47728 | if (!allDraggedElements) {
|
47729 | allDraggedElements = getAllDraggedElements(dragShapes);
|
47730 | } else {
|
47731 | allDraggedElements = flatten([
|
47732 | allDraggedElements,
|
47733 | getAllDraggedElements(dragShapes)
|
47734 | ]);
|
47735 | }
|
47736 |
|
47737 |
|
47738 | forEach(allDraggedElements, function(e) {
|
47739 | canvas.addMarker(e, MARKER_DRAGGING$1);
|
47740 | });
|
47741 |
|
47742 | context.allDraggedElements = allDraggedElements;
|
47743 |
|
47744 |
|
47745 | context.differentParents = haveDifferentParents(dragShapes);
|
47746 | });
|
47747 |
|
47748 |
|
47749 | eventBus.on('shape.move.move', LOW_PRIORITY$e, function(event) {
|
47750 |
|
47751 | var context = event.context,
|
47752 | dragGroup = context.dragGroup,
|
47753 | target = context.target,
|
47754 | parent = context.shape.parent,
|
47755 | canExecute = context.canExecute;
|
47756 |
|
47757 | if (target) {
|
47758 | if (canExecute === 'attach') {
|
47759 | setMarker(target, MARKER_ATTACH$1);
|
47760 | } else if (context.canExecute && target && target.id !== parent.id) {
|
47761 | setMarker(target, MARKER_NEW_PARENT$1);
|
47762 | } else {
|
47763 | setMarker(target, context.canExecute ? MARKER_OK$3 : MARKER_NOT_OK$3);
|
47764 | }
|
47765 | }
|
47766 |
|
47767 | translate(dragGroup, event.dx, event.dy);
|
47768 | });
|
47769 |
|
47770 | eventBus.on([ 'shape.move.out', 'shape.move.cleanup' ], function(event) {
|
47771 | var context = event.context,
|
47772 | target = context.target;
|
47773 |
|
47774 | if (target) {
|
47775 | setMarker(target, null);
|
47776 | }
|
47777 | });
|
47778 |
|
47779 |
|
47780 | eventBus.on('shape.move.cleanup', function(event) {
|
47781 |
|
47782 | var context = event.context,
|
47783 | allDraggedElements = context.allDraggedElements,
|
47784 | dragGroup = context.dragGroup;
|
47785 |
|
47786 |
|
47787 |
|
47788 | forEach(allDraggedElements, function(e) {
|
47789 | canvas.removeMarker(e, MARKER_DRAGGING$1);
|
47790 | });
|
47791 |
|
47792 | if (dragGroup) {
|
47793 | clear$1(dragGroup);
|
47794 | }
|
47795 | });
|
47796 |
|
47797 |
|
47798 |
|
47799 |
|
47800 | |
47801 |
|
47802 |
|
47803 |
|
47804 |
|
47805 |
|
47806 |
|
47807 | this.makeDraggable = makeDraggable;
|
47808 | }
|
47809 |
|
47810 | MovePreview.$inject = [
|
47811 | 'eventBus',
|
47812 | 'elementRegistry',
|
47813 | 'canvas',
|
47814 | 'styles',
|
47815 | 'previewSupport'
|
47816 | ];
|
47817 |
|
47818 |
|
47819 |
|
47820 |
|
47821 | |
47822 |
|
47823 |
|
47824 |
|
47825 | function removeEdges(elements) {
|
47826 |
|
47827 | var filteredElements = filter(elements, function(element) {
|
47828 |
|
47829 | if (!isConnection$4(element)) {
|
47830 | return true;
|
47831 | } else {
|
47832 |
|
47833 | return (
|
47834 | find(elements, matchPattern({ id: element.source.id })) &&
|
47835 | find(elements, matchPattern({ id: element.target.id }))
|
47836 | );
|
47837 | }
|
47838 | });
|
47839 |
|
47840 | return filteredElements;
|
47841 | }
|
47842 |
|
47843 | function haveDifferentParents(elements) {
|
47844 | return size(groupBy(elements, function(e) { return e.parent && e.parent.id; })) !== 1;
|
47845 | }
|
47846 |
|
47847 | |
47848 |
|
47849 |
|
47850 | function isConnection$4(element) {
|
47851 | return element.waypoints;
|
47852 | }
|
47853 |
|
47854 | var MoveModule = {
|
47855 | __depends__: [
|
47856 | InteractionEventsModule,
|
47857 | SelectionModule,
|
47858 | OutlineModule,
|
47859 | RulesModule,
|
47860 | DraggingModule,
|
47861 | PreviewSupportModule
|
47862 | ],
|
47863 | __init__: [
|
47864 | 'move',
|
47865 | 'movePreview'
|
47866 | ],
|
47867 | move: [ 'type', MoveEvents ],
|
47868 | movePreview: [ 'type', MovePreview ]
|
47869 | };
|
47870 |
|
47871 | var TOGGLE_SELECTOR = '.djs-palette-toggle',
|
47872 | ENTRY_SELECTOR = '.entry',
|
47873 | ELEMENT_SELECTOR = TOGGLE_SELECTOR + ', ' + ENTRY_SELECTOR;
|
47874 |
|
47875 | var PALETTE_OPEN_CLS = 'open',
|
47876 | PALETTE_TWO_COLUMN_CLS = 'two-column';
|
47877 |
|
47878 |
|
47879 | |
47880 |
|
47881 |
|
47882 | function Palette(eventBus, canvas) {
|
47883 |
|
47884 | this._eventBus = eventBus;
|
47885 | this._canvas = canvas;
|
47886 |
|
47887 | this._providers = [];
|
47888 |
|
47889 | var self = this;
|
47890 |
|
47891 | eventBus.on('tool-manager.update', function(event$$1) {
|
47892 | var tool = event$$1.tool;
|
47893 |
|
47894 | self.updateToolHighlight(tool);
|
47895 | });
|
47896 |
|
47897 | eventBus.on('i18n.changed', function() {
|
47898 | self._update();
|
47899 | });
|
47900 |
|
47901 | eventBus.on('diagram.init', function() {
|
47902 |
|
47903 | self._diagramInitialized = true;
|
47904 |
|
47905 |
|
47906 | if (self._providers.length) {
|
47907 | self._init();
|
47908 |
|
47909 | self._update();
|
47910 | }
|
47911 | });
|
47912 | }
|
47913 |
|
47914 | Palette.$inject = [ 'eventBus', 'canvas' ];
|
47915 |
|
47916 |
|
47917 | |
47918 |
|
47919 |
|
47920 |
|
47921 |
|
47922 | Palette.prototype.registerProvider = function(provider) {
|
47923 | this._providers.push(provider);
|
47924 |
|
47925 |
|
47926 | if (!this._diagramInitialized) {
|
47927 | return;
|
47928 | }
|
47929 |
|
47930 | if (!this._container) {
|
47931 | this._init();
|
47932 | }
|
47933 |
|
47934 | this._update();
|
47935 | };
|
47936 |
|
47937 |
|
47938 | |
47939 |
|
47940 |
|
47941 |
|
47942 |
|
47943 | Palette.prototype.getEntries = function() {
|
47944 |
|
47945 | var entries = {};
|
47946 |
|
47947 |
|
47948 |
|
47949 | forEach(this._providers, function(provider) {
|
47950 | var e = provider.getPaletteEntries();
|
47951 |
|
47952 | forEach(e, function(entry, id) {
|
47953 | entries[id] = entry;
|
47954 | });
|
47955 | });
|
47956 |
|
47957 | return entries;
|
47958 | };
|
47959 |
|
47960 |
|
47961 | |
47962 |
|
47963 |
|
47964 | Palette.prototype._init = function() {
|
47965 | var canvas = this._canvas,
|
47966 | eventBus = this._eventBus;
|
47967 |
|
47968 | var parent = canvas.getContainer(),
|
47969 | container = this._container = domify(Palette.HTML_MARKUP),
|
47970 | self = this;
|
47971 |
|
47972 | parent.appendChild(container);
|
47973 |
|
47974 | delegateEvents.bind(container, ELEMENT_SELECTOR, 'click', function(event$$1) {
|
47975 |
|
47976 | var target = event$$1.delegateTarget;
|
47977 |
|
47978 | if (matchesSelector$1(target, TOGGLE_SELECTOR)) {
|
47979 | return self.toggle();
|
47980 | }
|
47981 |
|
47982 | self.trigger('click', event$$1);
|
47983 | });
|
47984 |
|
47985 |
|
47986 | componentEvent.bind(container, 'mousedown', function(event$$1) {
|
47987 | event$$1.stopPropagation();
|
47988 | });
|
47989 |
|
47990 |
|
47991 | delegateEvents.bind(container, ENTRY_SELECTOR, 'dragstart', function(event$$1) {
|
47992 | self.trigger('dragstart', event$$1);
|
47993 | });
|
47994 |
|
47995 | eventBus.on('canvas.resized', this._layoutChanged, this);
|
47996 |
|
47997 | eventBus.fire('palette.create', {
|
47998 | container: container
|
47999 | });
|
48000 | };
|
48001 |
|
48002 | |
48003 |
|
48004 |
|
48005 |
|
48006 |
|
48007 | Palette.prototype._toggleState = function(state) {
|
48008 |
|
48009 | state = state || {};
|
48010 |
|
48011 | var parent = this._getParentContainer(),
|
48012 | container = this._container;
|
48013 |
|
48014 | var eventBus = this._eventBus;
|
48015 |
|
48016 | var twoColumn;
|
48017 |
|
48018 | var cls = classes(container);
|
48019 |
|
48020 | if ('twoColumn' in state) {
|
48021 | twoColumn = state.twoColumn;
|
48022 | } else {
|
48023 | twoColumn = this._needsCollapse(parent.clientHeight, this._entries || {});
|
48024 | }
|
48025 |
|
48026 |
|
48027 | cls.toggle(PALETTE_TWO_COLUMN_CLS, twoColumn);
|
48028 |
|
48029 | if ('open' in state) {
|
48030 | cls.toggle(PALETTE_OPEN_CLS, state.open);
|
48031 | }
|
48032 |
|
48033 | eventBus.fire('palette.changed', {
|
48034 | twoColumn: twoColumn,
|
48035 | open: this.isOpen()
|
48036 | });
|
48037 | };
|
48038 |
|
48039 | Palette.prototype._update = function() {
|
48040 |
|
48041 | var entriesContainer = query('.djs-palette-entries', this._container),
|
48042 | entries = this._entries = this.getEntries();
|
48043 |
|
48044 | clear(entriesContainer);
|
48045 |
|
48046 | forEach(entries, function(entry, id) {
|
48047 |
|
48048 | var grouping = entry.group || 'default';
|
48049 |
|
48050 | var container = query('[data-group=' + grouping + ']', entriesContainer);
|
48051 | if (!container) {
|
48052 | container = domify('<div class="group" data-group="' + grouping + '"></div>');
|
48053 | entriesContainer.appendChild(container);
|
48054 | }
|
48055 |
|
48056 | var html = entry.html || (
|
48057 | entry.separator ?
|
48058 | '<hr class="separator" />' :
|
48059 | '<div class="entry" draggable="true"></div>');
|
48060 |
|
48061 |
|
48062 | var control = domify(html);
|
48063 | container.appendChild(control);
|
48064 |
|
48065 | if (!entry.separator) {
|
48066 | attr(control, 'data-action', id);
|
48067 |
|
48068 | if (entry.title) {
|
48069 | attr(control, 'title', entry.title);
|
48070 | }
|
48071 |
|
48072 | if (entry.className) {
|
48073 | addClasses$1(control, entry.className);
|
48074 | }
|
48075 |
|
48076 | if (entry.imageUrl) {
|
48077 | control.appendChild(domify('<img src="' + entry.imageUrl + '">'));
|
48078 | }
|
48079 | }
|
48080 | });
|
48081 |
|
48082 |
|
48083 | this.open();
|
48084 | };
|
48085 |
|
48086 |
|
48087 | |
48088 |
|
48089 |
|
48090 |
|
48091 |
|
48092 |
|
48093 | Palette.prototype.trigger = function(action, event$$1, autoActivate) {
|
48094 | var entries = this._entries,
|
48095 | entry,
|
48096 | handler,
|
48097 | originalEvent,
|
48098 | button = event$$1.delegateTarget || event$$1.target;
|
48099 |
|
48100 | if (!button) {
|
48101 | return event$$1.preventDefault();
|
48102 | }
|
48103 |
|
48104 | entry = entries[attr(button, 'data-action')];
|
48105 |
|
48106 |
|
48107 | if (!entry) {
|
48108 | return;
|
48109 | }
|
48110 |
|
48111 | handler = entry.action;
|
48112 |
|
48113 | originalEvent = event$$1.originalEvent || event$$1;
|
48114 |
|
48115 |
|
48116 | if (isFunction(handler)) {
|
48117 | if (action === 'click') {
|
48118 | handler(originalEvent, autoActivate);
|
48119 | }
|
48120 | } else {
|
48121 | if (handler[action]) {
|
48122 | handler[action](originalEvent, autoActivate);
|
48123 | }
|
48124 | }
|
48125 |
|
48126 |
|
48127 | event$$1.preventDefault();
|
48128 | };
|
48129 |
|
48130 | Palette.prototype._layoutChanged = function() {
|
48131 | this._toggleState({});
|
48132 | };
|
48133 |
|
48134 | |
48135 |
|
48136 |
|
48137 |
|
48138 |
|
48139 |
|
48140 |
|
48141 |
|
48142 | Palette.prototype._needsCollapse = function(availableHeight, entries) {
|
48143 |
|
48144 |
|
48145 |
|
48146 |
|
48147 | var margin = 20 + 10 + 20;
|
48148 |
|
48149 | var entriesHeight = Object.keys(entries).length * 46;
|
48150 |
|
48151 | return availableHeight < entriesHeight + margin;
|
48152 | };
|
48153 |
|
48154 | |
48155 |
|
48156 |
|
48157 | Palette.prototype.close = function() {
|
48158 |
|
48159 | this._toggleState({
|
48160 | open: false,
|
48161 | twoColumn: false
|
48162 | });
|
48163 | };
|
48164 |
|
48165 |
|
48166 | |
48167 |
|
48168 |
|
48169 | Palette.prototype.open = function() {
|
48170 | this._toggleState({ open: true });
|
48171 | };
|
48172 |
|
48173 |
|
48174 | Palette.prototype.toggle = function(open) {
|
48175 | if (this.isOpen()) {
|
48176 | this.close();
|
48177 | } else {
|
48178 | this.open();
|
48179 | }
|
48180 | };
|
48181 |
|
48182 | Palette.prototype.isActiveTool = function(tool) {
|
48183 | return tool && this._activeTool === tool;
|
48184 | };
|
48185 |
|
48186 | Palette.prototype.updateToolHighlight = function(name) {
|
48187 | var entriesContainer,
|
48188 | toolsContainer;
|
48189 |
|
48190 | if (!this._toolsContainer) {
|
48191 | entriesContainer = query('.djs-palette-entries', this._container);
|
48192 |
|
48193 | this._toolsContainer = query('[data-group=tools]', entriesContainer);
|
48194 | }
|
48195 |
|
48196 | toolsContainer = this._toolsContainer;
|
48197 |
|
48198 | forEach(toolsContainer.children, function(tool) {
|
48199 | var actionName = tool.getAttribute('data-action');
|
48200 |
|
48201 | if (!actionName) {
|
48202 | return;
|
48203 | }
|
48204 |
|
48205 | var toolClasses = classes(tool);
|
48206 |
|
48207 | actionName = actionName.replace('-tool', '');
|
48208 |
|
48209 | if (toolClasses.contains('entry') && actionName === name) {
|
48210 | toolClasses.add('highlighted-entry');
|
48211 | } else {
|
48212 | toolClasses.remove('highlighted-entry');
|
48213 | }
|
48214 | });
|
48215 | };
|
48216 |
|
48217 |
|
48218 | |
48219 |
|
48220 |
|
48221 |
|
48222 |
|
48223 |
|
48224 |
|
48225 |
|
48226 |
|
48227 |
|
48228 |
|
48229 |
|
48230 |
|
48231 | Palette.prototype.isOpen = function() {
|
48232 | return classes(this._container).has(PALETTE_OPEN_CLS);
|
48233 | };
|
48234 |
|
48235 | |
48236 |
|
48237 |
|
48238 |
|
48239 |
|
48240 | Palette.prototype._getParentContainer = function() {
|
48241 | return this._canvas.getContainer();
|
48242 | };
|
48243 |
|
48244 |
|
48245 |
|
48246 |
|
48247 | Palette.HTML_MARKUP =
|
48248 | '<div class="djs-palette">' +
|
48249 | '<div class="djs-palette-entries"></div>' +
|
48250 | '<div class="djs-palette-toggle"></div>' +
|
48251 | '</div>';
|
48252 |
|
48253 |
|
48254 |
|
48255 |
|
48256 | function addClasses$1(element, classNames) {
|
48257 |
|
48258 | var classes$$1 = classes(element);
|
48259 |
|
48260 | var actualClassNames = isArray(classNames) ? classNames : classNames.split(/\s+/g);
|
48261 | actualClassNames.forEach(function(cls) {
|
48262 | classes$$1.add(cls);
|
48263 | });
|
48264 | }
|
48265 |
|
48266 | var PaletteModule = {
|
48267 | __init__: [ 'palette' ],
|
48268 | palette: [ 'type', Palette ]
|
48269 | };
|
48270 |
|
48271 | var LASSO_TOOL_CURSOR = 'crosshair';
|
48272 |
|
48273 |
|
48274 | function LassoTool(
|
48275 | eventBus, canvas, dragging,
|
48276 | elementRegistry, selection, toolManager) {
|
48277 |
|
48278 | this._selection = selection;
|
48279 | this._dragging = dragging;
|
48280 |
|
48281 | var self = this;
|
48282 |
|
48283 |
|
48284 |
|
48285 | |
48286 |
|
48287 |
|
48288 | var visuals = {
|
48289 |
|
48290 | create: function(context) {
|
48291 | var container = canvas.getDefaultLayer(),
|
48292 | frame;
|
48293 |
|
48294 | frame = context.frame = create('rect');
|
48295 | attr$1(frame, {
|
48296 | class: 'djs-lasso-overlay',
|
48297 | width: 1,
|
48298 | height: 1,
|
48299 | x: 0,
|
48300 | y: 0
|
48301 | });
|
48302 |
|
48303 | append(container, frame);
|
48304 | },
|
48305 |
|
48306 | update: function(context) {
|
48307 | var frame = context.frame,
|
48308 | bbox = context.bbox;
|
48309 |
|
48310 | attr$1(frame, {
|
48311 | x: bbox.x,
|
48312 | y: bbox.y,
|
48313 | width: bbox.width,
|
48314 | height: bbox.height
|
48315 | });
|
48316 | },
|
48317 |
|
48318 | remove: function(context) {
|
48319 |
|
48320 | if (context.frame) {
|
48321 | remove$1(context.frame);
|
48322 | }
|
48323 | }
|
48324 | };
|
48325 |
|
48326 | toolManager.registerTool('lasso', {
|
48327 | tool: 'lasso.selection',
|
48328 | dragging: 'lasso'
|
48329 | });
|
48330 |
|
48331 | eventBus.on('lasso.selection.end', function(event) {
|
48332 | var target = event.originalEvent.target;
|
48333 |
|
48334 |
|
48335 |
|
48336 | if (!event.hover && !(target instanceof SVGElement)) {
|
48337 | return;
|
48338 | }
|
48339 |
|
48340 | eventBus.once('lasso.selection.ended', function() {
|
48341 | self.activateLasso(event.originalEvent, true);
|
48342 | });
|
48343 | });
|
48344 |
|
48345 |
|
48346 |
|
48347 | eventBus.on('lasso.end', function(event) {
|
48348 |
|
48349 | var bbox = toBBox(event);
|
48350 |
|
48351 | var elements = elementRegistry.filter(function(element) {
|
48352 | return element;
|
48353 | });
|
48354 |
|
48355 | self.select(elements, bbox);
|
48356 | });
|
48357 |
|
48358 | eventBus.on('lasso.start', function(event) {
|
48359 |
|
48360 | var context = event.context;
|
48361 |
|
48362 | context.bbox = toBBox(event);
|
48363 | visuals.create(context);
|
48364 | });
|
48365 |
|
48366 | eventBus.on('lasso.move', function(event) {
|
48367 |
|
48368 | var context = event.context;
|
48369 |
|
48370 | context.bbox = toBBox(event);
|
48371 | visuals.update(context);
|
48372 | });
|
48373 |
|
48374 | eventBus.on('lasso.cleanup', function(event) {
|
48375 |
|
48376 | var context = event.context;
|
48377 |
|
48378 | visuals.remove(context);
|
48379 | });
|
48380 |
|
48381 |
|
48382 |
|
48383 |
|
48384 | eventBus.on('element.mousedown', 1500, function(event) {
|
48385 |
|
48386 | if (hasSecondaryModifier(event)) {
|
48387 | self.activateLasso(event.originalEvent);
|
48388 |
|
48389 |
|
48390 | return true;
|
48391 | }
|
48392 | });
|
48393 | }
|
48394 |
|
48395 | LassoTool.$inject = [
|
48396 | 'eventBus',
|
48397 | 'canvas',
|
48398 | 'dragging',
|
48399 | 'elementRegistry',
|
48400 | 'selection',
|
48401 | 'toolManager'
|
48402 | ];
|
48403 |
|
48404 |
|
48405 | LassoTool.prototype.activateLasso = function(event, autoActivate) {
|
48406 |
|
48407 | this._dragging.init(event, 'lasso', {
|
48408 | autoActivate: autoActivate,
|
48409 | cursor: LASSO_TOOL_CURSOR,
|
48410 | data: {
|
48411 | context: {}
|
48412 | }
|
48413 | });
|
48414 | };
|
48415 |
|
48416 | LassoTool.prototype.activateSelection = function(event) {
|
48417 |
|
48418 | this._dragging.init(event, 'lasso.selection', {
|
48419 | trapClick: false,
|
48420 | cursor: LASSO_TOOL_CURSOR,
|
48421 | data: {
|
48422 | context: {}
|
48423 | }
|
48424 | });
|
48425 | };
|
48426 |
|
48427 | LassoTool.prototype.select = function(elements, bbox) {
|
48428 | var selectedElements = getEnclosedElements(elements, bbox);
|
48429 |
|
48430 | this._selection.select(values(selectedElements));
|
48431 | };
|
48432 |
|
48433 | LassoTool.prototype.toggle = function() {
|
48434 | if (this.isActive()) {
|
48435 | this._dragging.cancel();
|
48436 | } else {
|
48437 | this.activateSelection();
|
48438 | }
|
48439 | };
|
48440 |
|
48441 | LassoTool.prototype.isActive = function() {
|
48442 | var context = this._dragging.context();
|
48443 |
|
48444 | return context && /^lasso/.test(context.prefix);
|
48445 | };
|
48446 |
|
48447 |
|
48448 |
|
48449 | function toBBox(event) {
|
48450 |
|
48451 | var start = {
|
48452 |
|
48453 | x: event.x - event.dx,
|
48454 | y: event.y - event.dy
|
48455 | };
|
48456 |
|
48457 | var end = {
|
48458 | x: event.x,
|
48459 | y: event.y
|
48460 | };
|
48461 |
|
48462 | var bbox;
|
48463 |
|
48464 | if ((start.x <= end.x && start.y < end.y) ||
|
48465 | (start.x < end.x && start.y <= end.y)) {
|
48466 |
|
48467 | bbox = {
|
48468 | x: start.x,
|
48469 | y: start.y,
|
48470 | width: end.x - start.x,
|
48471 | height: end.y - start.y
|
48472 | };
|
48473 | } else if ((start.x >= end.x && start.y < end.y) ||
|
48474 | (start.x > end.x && start.y <= end.y)) {
|
48475 |
|
48476 | bbox = {
|
48477 | x: end.x,
|
48478 | y: start.y,
|
48479 | width: start.x - end.x,
|
48480 | height: end.y - start.y
|
48481 | };
|
48482 | } else if ((start.x <= end.x && start.y > end.y) ||
|
48483 | (start.x < end.x && start.y >= end.y)) {
|
48484 |
|
48485 | bbox = {
|
48486 | x: start.x,
|
48487 | y: end.y,
|
48488 | width: end.x - start.x,
|
48489 | height: start.y - end.y
|
48490 | };
|
48491 | } else if ((start.x >= end.x && start.y > end.y) ||
|
48492 | (start.x > end.x && start.y >= end.y)) {
|
48493 |
|
48494 | bbox = {
|
48495 | x: end.x,
|
48496 | y: end.y,
|
48497 | width: start.x - end.x,
|
48498 | height: start.y - end.y
|
48499 | };
|
48500 | } else {
|
48501 |
|
48502 | bbox = {
|
48503 | x: end.x,
|
48504 | y: end.y,
|
48505 | width: 0,
|
48506 | height: 0
|
48507 | };
|
48508 | }
|
48509 | return bbox;
|
48510 | }
|
48511 |
|
48512 | var LassoToolModule = {
|
48513 | __depends__: [
|
48514 | ToolManagerModule
|
48515 | ],
|
48516 | __init__: [ 'lassoTool' ],
|
48517 | lassoTool: [ 'type', LassoTool ]
|
48518 | };
|
48519 |
|
48520 | var HIGH_PRIORITY$5 = 1500;
|
48521 | var HAND_CURSOR = 'grab';
|
48522 |
|
48523 |
|
48524 | function HandTool(eventBus, canvas, dragging, toolManager) {
|
48525 | this._dragging = dragging;
|
48526 |
|
48527 |
|
48528 | toolManager.registerTool('hand', {
|
48529 | tool: 'hand',
|
48530 | dragging: 'hand.move'
|
48531 | });
|
48532 |
|
48533 | eventBus.on('element.mousedown', HIGH_PRIORITY$5, function(event) {
|
48534 | if (hasPrimaryModifier(event)) {
|
48535 | this.activateMove(event.originalEvent);
|
48536 |
|
48537 | return false;
|
48538 | }
|
48539 | }, this);
|
48540 |
|
48541 |
|
48542 | eventBus.on('hand.end', function(event) {
|
48543 | var target = event.originalEvent.target;
|
48544 |
|
48545 |
|
48546 |
|
48547 | if (!event.hover && !(target instanceof SVGElement)) {
|
48548 | return false;
|
48549 | }
|
48550 |
|
48551 | eventBus.once('hand.ended', function() {
|
48552 | this.activateMove(event.originalEvent, { reactivate: true });
|
48553 | }, this);
|
48554 |
|
48555 | }, this);
|
48556 |
|
48557 |
|
48558 | eventBus.on('hand.move.move', function(event) {
|
48559 | var scale = canvas.viewbox().scale;
|
48560 |
|
48561 | canvas.scroll({
|
48562 | dx: event.dx * scale,
|
48563 | dy: event.dy * scale
|
48564 | });
|
48565 | });
|
48566 |
|
48567 | eventBus.on('hand.move.end', function(event) {
|
48568 | var context = event.context,
|
48569 | reactivate = context.reactivate;
|
48570 |
|
48571 |
|
48572 | if (!hasPrimaryModifier(event) && reactivate) {
|
48573 |
|
48574 | eventBus.once('hand.move.ended', function(event) {
|
48575 | this.activateHand(event.originalEvent, true, true);
|
48576 | }, this);
|
48577 |
|
48578 | }
|
48579 |
|
48580 | return false;
|
48581 | }, this);
|
48582 |
|
48583 | }
|
48584 |
|
48585 | HandTool.$inject = [
|
48586 | 'eventBus',
|
48587 | 'canvas',
|
48588 | 'dragging',
|
48589 | 'toolManager'
|
48590 | ];
|
48591 |
|
48592 |
|
48593 | HandTool.prototype.activateMove = function(event, autoActivate, context) {
|
48594 | if (typeof autoActivate === 'object') {
|
48595 | context = autoActivate;
|
48596 | autoActivate = false;
|
48597 | }
|
48598 |
|
48599 | this._dragging.init(event, 'hand.move', {
|
48600 | autoActivate: autoActivate,
|
48601 | cursor: HAND_CURSOR,
|
48602 | data: {
|
48603 | context: context || {}
|
48604 | }
|
48605 | });
|
48606 | };
|
48607 |
|
48608 | HandTool.prototype.activateHand = function(event, autoActivate, reactivate) {
|
48609 | this._dragging.init(event, 'hand', {
|
48610 | trapClick: false,
|
48611 | autoActivate: autoActivate,
|
48612 | cursor: HAND_CURSOR,
|
48613 | data: {
|
48614 | context: {
|
48615 | reactivate: reactivate
|
48616 | }
|
48617 | }
|
48618 | });
|
48619 | };
|
48620 |
|
48621 | HandTool.prototype.toggle = function() {
|
48622 | if (this.isActive()) {
|
48623 | this._dragging.cancel();
|
48624 | } else {
|
48625 | this.activateHand();
|
48626 | }
|
48627 | };
|
48628 |
|
48629 | HandTool.prototype.isActive = function() {
|
48630 | var context = this._dragging.context();
|
48631 |
|
48632 | return context && /^hand/.test(context.prefix);
|
48633 | };
|
48634 |
|
48635 | var HandToolModule = {
|
48636 | __depends__: [
|
48637 | ToolManagerModule
|
48638 | ],
|
48639 | __init__: [ 'handTool' ],
|
48640 | handTool: [ 'type', HandTool ]
|
48641 | };
|
48642 |
|
48643 | var MARKER_OK$4 = 'connect-ok',
|
48644 | MARKER_NOT_OK$4 = 'connect-not-ok';
|
48645 |
|
48646 | |
48647 |
|
48648 |
|
48649 |
|
48650 |
|
48651 |
|
48652 |
|
48653 |
|
48654 |
|
48655 |
|
48656 |
|
48657 | function GlobalConnect(
|
48658 | eventBus, dragging, connect,
|
48659 | canvas, toolManager, rules) {
|
48660 |
|
48661 | var self = this;
|
48662 |
|
48663 | this._dragging = dragging;
|
48664 | this._rules = rules;
|
48665 |
|
48666 | toolManager.registerTool('global-connect', {
|
48667 | tool: 'global-connect',
|
48668 | dragging: 'global-connect.drag'
|
48669 | });
|
48670 |
|
48671 | eventBus.on('global-connect.hover', function(event) {
|
48672 | var context = event.context,
|
48673 | startTarget = event.hover;
|
48674 |
|
48675 | var canStartConnect = context.canStartConnect = self.canStartConnect(startTarget);
|
48676 |
|
48677 |
|
48678 | if (canStartConnect === null) {
|
48679 | return;
|
48680 | }
|
48681 |
|
48682 | context.startTarget = startTarget;
|
48683 |
|
48684 | canvas.addMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
48685 | });
|
48686 |
|
48687 |
|
48688 | eventBus.on([ 'global-connect.out', 'global-connect.cleanup' ], function(event) {
|
48689 | var startTarget = event.context.startTarget,
|
48690 | canStartConnect = event.context.canStartConnect;
|
48691 |
|
48692 | if (startTarget) {
|
48693 | canvas.removeMarker(startTarget, canStartConnect ? MARKER_OK$4 : MARKER_NOT_OK$4);
|
48694 | }
|
48695 | });
|
48696 |
|
48697 |
|
48698 | eventBus.on([ 'global-connect.ended' ], function(event) {
|
48699 | var context = event.context,
|
48700 | startTarget = context.startTarget,
|
48701 | startPosition = {
|
48702 | x: event.x,
|
48703 | y: event.y
|
48704 | };
|
48705 |
|
48706 | var canStartConnect = self.canStartConnect(startTarget);
|
48707 |
|
48708 | if (!canStartConnect) {
|
48709 | return;
|
48710 | }
|
48711 |
|
48712 | eventBus.once('element.out', function() {
|
48713 | eventBus.once([ 'connect.ended', 'connect.canceled' ], function() {
|
48714 | eventBus.fire('global-connect.drag.ended');
|
48715 | });
|
48716 |
|
48717 | connect.start(null, startTarget, startPosition);
|
48718 | });
|
48719 |
|
48720 | return false;
|
48721 | });
|
48722 | }
|
48723 |
|
48724 | GlobalConnect.$inject = [
|
48725 | 'eventBus',
|
48726 | 'dragging',
|
48727 | 'connect',
|
48728 | 'canvas',
|
48729 | 'toolManager',
|
48730 | 'rules'
|
48731 | ];
|
48732 |
|
48733 | |
48734 |
|
48735 |
|
48736 | GlobalConnect.prototype.start = function(event) {
|
48737 | this._dragging.init(event, 'global-connect', {
|
48738 | trapClick: false,
|
48739 | data: {
|
48740 | context: {}
|
48741 | }
|
48742 | });
|
48743 | };
|
48744 |
|
48745 | GlobalConnect.prototype.toggle = function() {
|
48746 | if (this.isActive()) {
|
48747 | this._dragging.cancel();
|
48748 | } else {
|
48749 | this.start();
|
48750 | }
|
48751 | };
|
48752 |
|
48753 | GlobalConnect.prototype.isActive = function() {
|
48754 | var context = this._dragging.context();
|
48755 |
|
48756 | return context && /^global-connect/.test(context.prefix);
|
48757 | };
|
48758 |
|
48759 | |
48760 |
|
48761 |
|
48762 |
|
48763 |
|
48764 |
|
48765 | GlobalConnect.prototype.canStartConnect = function(startTarget) {
|
48766 | return this._rules.allowed('connection.start', { source: startTarget });
|
48767 | };
|
48768 |
|
48769 | var GlobalConnectModule = {
|
48770 | __depends__: [
|
48771 | ConnectModule,
|
48772 | RulesModule,
|
48773 | DraggingModule,
|
48774 | ToolManagerModule
|
48775 | ],
|
48776 | globalConnect: [ 'type', GlobalConnect ]
|
48777 | };
|
48778 |
|
48779 | |
48780 |
|
48781 |
|
48782 | function PaletteProvider(
|
48783 | palette, create, elementFactory,
|
48784 | spaceTool, lassoTool, handTool,
|
48785 | globalConnect, translate) {
|
48786 |
|
48787 | this._palette = palette;
|
48788 | this._create = create;
|
48789 | this._elementFactory = elementFactory;
|
48790 | this._spaceTool = spaceTool;
|
48791 | this._lassoTool = lassoTool;
|
48792 | this._handTool = handTool;
|
48793 | this._globalConnect = globalConnect;
|
48794 | this._translate = translate;
|
48795 |
|
48796 | palette.registerProvider(this);
|
48797 | }
|
48798 |
|
48799 | PaletteProvider.$inject = [
|
48800 | 'palette',
|
48801 | 'create',
|
48802 | 'elementFactory',
|
48803 | 'spaceTool',
|
48804 | 'lassoTool',
|
48805 | 'handTool',
|
48806 | 'globalConnect',
|
48807 | 'translate'
|
48808 | ];
|
48809 |
|
48810 |
|
48811 | PaletteProvider.prototype.getPaletteEntries = function(element) {
|
48812 |
|
48813 | var actions = {},
|
48814 | create = this._create,
|
48815 | elementFactory = this._elementFactory,
|
48816 | spaceTool = this._spaceTool,
|
48817 | lassoTool = this._lassoTool,
|
48818 | handTool = this._handTool,
|
48819 | globalConnect = this._globalConnect,
|
48820 | translate = this._translate;
|
48821 |
|
48822 | function createAction(type, group, className, title, options) {
|
48823 |
|
48824 | function createListener(event) {
|
48825 | var shape = elementFactory.createShape(assign({ type: type }, options));
|
48826 |
|
48827 | if (options) {
|
48828 | shape.businessObject.di.isExpanded = options.isExpanded;
|
48829 | }
|
48830 |
|
48831 | create.start(event, shape);
|
48832 | }
|
48833 |
|
48834 | var shortType = type.replace(/^bpmn:/, '');
|
48835 |
|
48836 | return {
|
48837 | group: group,
|
48838 | className: className,
|
48839 | title: title || translate('Create {type}', { type: shortType }),
|
48840 | action: {
|
48841 | dragstart: createListener,
|
48842 | click: createListener
|
48843 | }
|
48844 | };
|
48845 | }
|
48846 |
|
48847 | function createParticipant(event, collapsed) {
|
48848 | create.start(event, elementFactory.createParticipantShape(collapsed));
|
48849 | }
|
48850 |
|
48851 | assign(actions, {
|
48852 | 'hand-tool': {
|
48853 | group: 'tools',
|
48854 | className: 'bpmn-icon-hand-tool',
|
48855 | title: translate('Activate the hand tool'),
|
48856 | action: {
|
48857 | click: function(event) {
|
48858 | handTool.activateHand(event);
|
48859 | }
|
48860 | }
|
48861 | },
|
48862 | 'lasso-tool': {
|
48863 | group: 'tools',
|
48864 | className: 'bpmn-icon-lasso-tool',
|
48865 | title: translate('Activate the lasso tool'),
|
48866 | action: {
|
48867 | click: function(event) {
|
48868 | lassoTool.activateSelection(event);
|
48869 | }
|
48870 | }
|
48871 | },
|
48872 | 'space-tool': {
|
48873 | group: 'tools',
|
48874 | className: 'bpmn-icon-space-tool',
|
48875 | title: translate('Activate the create/remove space tool'),
|
48876 | action: {
|
48877 | click: function(event) {
|
48878 | spaceTool.activateSelection(event);
|
48879 | }
|
48880 | }
|
48881 | },
|
48882 | 'global-connect-tool': {
|
48883 | group: 'tools',
|
48884 | className: 'bpmn-icon-connection-multi',
|
48885 | title: translate('Activate the global connect tool'),
|
48886 | action: {
|
48887 | click: function(event) {
|
48888 | globalConnect.toggle(event);
|
48889 | }
|
48890 | }
|
48891 | },
|
48892 | 'tool-separator': {
|
48893 | group: 'tools',
|
48894 | separator: true
|
48895 | },
|
48896 | 'create.start-event': createAction(
|
48897 | 'bpmn:StartEvent', 'event', 'bpmn-icon-start-event-none'
|
48898 | ),
|
48899 | 'create.intermediate-event': createAction(
|
48900 | 'bpmn:IntermediateThrowEvent', 'event', 'bpmn-icon-intermediate-event-none',
|
48901 | translate('Create Intermediate/Boundary Event')
|
48902 | ),
|
48903 | 'create.end-event': createAction(
|
48904 | 'bpmn:EndEvent', 'event', 'bpmn-icon-end-event-none'
|
48905 | ),
|
48906 | 'create.exclusive-gateway': createAction(
|
48907 | 'bpmn:ExclusiveGateway', 'gateway', 'bpmn-icon-gateway-none',
|
48908 | translate('Create Gateway')
|
48909 | ),
|
48910 | 'create.task': createAction(
|
48911 | 'bpmn:Task', 'activity', 'bpmn-icon-task'
|
48912 | ),
|
48913 | 'create.data-object': createAction(
|
48914 | 'bpmn:DataObjectReference', 'data-object', 'bpmn-icon-data-object'
|
48915 | ),
|
48916 | 'create.data-store': createAction(
|
48917 | 'bpmn:DataStoreReference', 'data-store', 'bpmn-icon-data-store'
|
48918 | ),
|
48919 | 'create.subprocess-expanded': createAction(
|
48920 | 'bpmn:SubProcess', 'activity', 'bpmn-icon-subprocess-expanded',
|
48921 | translate('Create expanded SubProcess'),
|
48922 | { isExpanded: true }
|
48923 | ),
|
48924 | 'create.participant-expanded': {
|
48925 | group: 'collaboration',
|
48926 | className: 'bpmn-icon-participant',
|
48927 | title: translate('Create Pool/Participant'),
|
48928 | action: {
|
48929 | dragstart: createParticipant,
|
48930 | click: createParticipant
|
48931 | }
|
48932 | }
|
48933 | });
|
48934 |
|
48935 | return actions;
|
48936 | };
|
48937 |
|
48938 | var PaletteModule$1 = {
|
48939 | __depends__: [
|
48940 | PaletteModule,
|
48941 | CreateModule,
|
48942 | SpaceToolModule,
|
48943 | LassoToolModule,
|
48944 | HandToolModule,
|
48945 | GlobalConnectModule,
|
48946 | translate$2
|
48947 | ],
|
48948 | __init__: [ 'paletteProvider' ],
|
48949 | paletteProvider: [ 'type', PaletteProvider ]
|
48950 | };
|
48951 |
|
48952 | var LOW_PRIORITY$f = 250;
|
48953 |
|
48954 |
|
48955 | function BpmnReplacePreview(
|
48956 | eventBus, elementRegistry, elementFactory,
|
48957 | canvas, previewSupport) {
|
48958 |
|
48959 | CommandInterceptor.call(this, eventBus);
|
48960 |
|
48961 | |
48962 |
|
48963 |
|
48964 |
|
48965 |
|
48966 | function replaceVisual(context) {
|
48967 |
|
48968 | var replacements = context.canExecute.replacements;
|
48969 |
|
48970 | forEach(replacements, function(replacement) {
|
48971 |
|
48972 | var id = replacement.oldElementId;
|
48973 |
|
48974 | var newElement = {
|
48975 | type: replacement.newElementType
|
48976 | };
|
48977 |
|
48978 |
|
48979 | if (context.visualReplacements[id]) {
|
48980 | return;
|
48981 | }
|
48982 |
|
48983 | var element = elementRegistry.get(id);
|
48984 |
|
48985 | assign(newElement, { x: element.x, y: element.y });
|
48986 |
|
48987 |
|
48988 | var tempShape = elementFactory.createShape(newElement);
|
48989 |
|
48990 | canvas.addShape(tempShape, element.parent);
|
48991 |
|
48992 |
|
48993 | var gfx = query('[data-element-id="' + css_escape(element.id) + '"]', context.dragGroup);
|
48994 |
|
48995 | if (gfx) {
|
48996 | attr$1(gfx, { display: 'none' });
|
48997 | }
|
48998 |
|
48999 |
|
49000 | var dragger = previewSupport.addDragger(tempShape, context.dragGroup);
|
49001 |
|
49002 | context.visualReplacements[id] = dragger;
|
49003 |
|
49004 | canvas.removeShape(tempShape);
|
49005 | });
|
49006 | }
|
49007 |
|
49008 | |
49009 |
|
49010 |
|
49011 |
|
49012 |
|
49013 | function restoreVisual(context) {
|
49014 |
|
49015 | var visualReplacements = context.visualReplacements;
|
49016 |
|
49017 | forEach(visualReplacements, function(dragger, id) {
|
49018 |
|
49019 | var originalGfx = query('[data-element-id="' + css_escape(id) + '"]', context.dragGroup);
|
49020 |
|
49021 | if (originalGfx) {
|
49022 | attr$1(originalGfx, { display: 'inline' });
|
49023 | }
|
49024 |
|
49025 | dragger.remove();
|
49026 |
|
49027 | if (visualReplacements[id]) {
|
49028 | delete visualReplacements[id];
|
49029 | }
|
49030 | });
|
49031 | }
|
49032 |
|
49033 | eventBus.on('shape.move.move', LOW_PRIORITY$f, function(event) {
|
49034 |
|
49035 | var context = event.context,
|
49036 | canExecute = context.canExecute;
|
49037 |
|
49038 | if (!context.visualReplacements) {
|
49039 | context.visualReplacements = {};
|
49040 | }
|
49041 |
|
49042 | if (canExecute.replacements) {
|
49043 | replaceVisual(context);
|
49044 | } else {
|
49045 | restoreVisual(context);
|
49046 | }
|
49047 | });
|
49048 | }
|
49049 |
|
49050 | BpmnReplacePreview.$inject = [
|
49051 | 'eventBus',
|
49052 | 'elementRegistry',
|
49053 | 'elementFactory',
|
49054 | 'canvas',
|
49055 | 'previewSupport'
|
49056 | ];
|
49057 |
|
49058 | inherits_browser(BpmnReplacePreview, CommandInterceptor);
|
49059 |
|
49060 | var ReplacePreviewModule = {
|
49061 | __depends__: [
|
49062 | PreviewSupportModule
|
49063 | ],
|
49064 | __init__: [ 'bpmnReplacePreview' ],
|
49065 | bpmnReplacePreview: [ 'type', BpmnReplacePreview ]
|
49066 | };
|
49067 |
|
49068 | var abs$6 = Math.abs,
|
49069 | round$a = Math.round;
|
49070 |
|
49071 |
|
49072 | |
49073 |
|
49074 |
|
49075 |
|
49076 |
|
49077 |
|
49078 |
|
49079 |
|
49080 |
|
49081 | function snapTo(value, values, tolerance) {
|
49082 | tolerance = tolerance === undefined ? 10 : tolerance;
|
49083 |
|
49084 | var idx, snapValue;
|
49085 |
|
49086 | for (idx = 0; idx < values.length; idx++) {
|
49087 | snapValue = values[idx];
|
49088 |
|
49089 | if (abs$6(snapValue - value) <= tolerance) {
|
49090 | return snapValue;
|
49091 | }
|
49092 | }
|
49093 | }
|
49094 |
|
49095 |
|
49096 | function topLeft(bounds) {
|
49097 | return {
|
49098 | x: bounds.x,
|
49099 | y: bounds.y
|
49100 | };
|
49101 | }
|
49102 |
|
49103 |
|
49104 | function mid$2(bounds, defaultValue) {
|
49105 |
|
49106 | if (!bounds || isNaN(bounds.x) || isNaN(bounds.y)) {
|
49107 | return defaultValue;
|
49108 | }
|
49109 |
|
49110 | return {
|
49111 | x: round$a(bounds.x + bounds.width / 2),
|
49112 | y: round$a(bounds.y + bounds.height / 2)
|
49113 | };
|
49114 | }
|
49115 |
|
49116 |
|
49117 | function bottomRight(bounds) {
|
49118 | return {
|
49119 | x: bounds.x + bounds.width,
|
49120 | y: bounds.y + bounds.height
|
49121 | };
|
49122 | }
|
49123 |
|
49124 |
|
49125 | |
49126 |
|
49127 |
|
49128 |
|
49129 |
|
49130 |
|
49131 |
|
49132 |
|
49133 |
|
49134 | function isSnapped(event, axis) {
|
49135 | var snapped = event.snapped;
|
49136 |
|
49137 | if (!snapped) {
|
49138 | return false;
|
49139 | }
|
49140 |
|
49141 | if (typeof axis === 'string') {
|
49142 | return snapped[axis];
|
49143 | }
|
49144 |
|
49145 | return snapped.x && snapped.y;
|
49146 | }
|
49147 |
|
49148 |
|
49149 | |
49150 |
|
49151 |
|
49152 |
|
49153 |
|
49154 |
|
49155 |
|
49156 |
|
49157 |
|
49158 |
|
49159 |
|
49160 |
|
49161 | function setSnapped(event, axis, value) {
|
49162 | if (typeof axis !== 'string') {
|
49163 | throw new Error('axis must be in [x, y]');
|
49164 | }
|
49165 |
|
49166 | if (typeof value !== 'number' && value !== false) {
|
49167 | throw new Error('value must be Number or false');
|
49168 | }
|
49169 |
|
49170 | var delta,
|
49171 | previousValue = event[axis];
|
49172 |
|
49173 | var snapped = event.snapped = (event.snapped || {});
|
49174 |
|
49175 |
|
49176 | if (value === false) {
|
49177 | snapped[axis] = false;
|
49178 | } else {
|
49179 | snapped[axis] = true;
|
49180 |
|
49181 | delta = value - previousValue;
|
49182 |
|
49183 | event[axis] += delta;
|
49184 | event['d' + axis] += delta;
|
49185 | }
|
49186 |
|
49187 | return previousValue;
|
49188 | }
|
49189 |
|
49190 | |
49191 |
|
49192 |
|
49193 |
|
49194 |
|
49195 | function SnapContext() {
|
49196 |
|
49197 | |
49198 |
|
49199 |
|
49200 |
|
49201 |
|
49202 |
|
49203 | this._targets = {};
|
49204 |
|
49205 | |
49206 |
|
49207 |
|
49208 |
|
49209 |
|
49210 |
|
49211 | this._snapOrigins = {};
|
49212 |
|
49213 | |
49214 |
|
49215 |
|
49216 |
|
49217 |
|
49218 | this._snapLocations = [];
|
49219 |
|
49220 | |
49221 |
|
49222 |
|
49223 |
|
49224 |
|
49225 | this._defaultSnaps = {};
|
49226 | }
|
49227 |
|
49228 |
|
49229 | SnapContext.prototype.getSnapOrigin = function(snapLocation) {
|
49230 | return this._snapOrigins[snapLocation];
|
49231 | };
|
49232 |
|
49233 |
|
49234 | SnapContext.prototype.setSnapOrigin = function(snapLocation, initialValue) {
|
49235 | this._snapOrigins[snapLocation] = initialValue;
|
49236 |
|
49237 | if (this._snapLocations.indexOf(snapLocation) === -1) {
|
49238 | this._snapLocations.push(snapLocation);
|
49239 | }
|
49240 | };
|
49241 |
|
49242 |
|
49243 | SnapContext.prototype.addDefaultSnap = function(type, point) {
|
49244 |
|
49245 | var snapValues = this._defaultSnaps[type];
|
49246 |
|
49247 | if (!snapValues) {
|
49248 | snapValues = this._defaultSnaps[type] = [];
|
49249 | }
|
49250 |
|
49251 | snapValues.push(point);
|
49252 | };
|
49253 |
|
49254 | |
49255 |
|
49256 |
|
49257 |
|
49258 |
|
49259 |
|
49260 | SnapContext.prototype.getSnapLocations = function() {
|
49261 | return this._snapLocations;
|
49262 | };
|
49263 |
|
49264 | |
49265 |
|
49266 |
|
49267 |
|
49268 |
|
49269 |
|
49270 |
|
49271 | SnapContext.prototype.setSnapLocations = function(snapLocations) {
|
49272 | this._snapLocations = snapLocations;
|
49273 | };
|
49274 |
|
49275 | |
49276 |
|
49277 |
|
49278 |
|
49279 |
|
49280 | SnapContext.prototype.pointsForTarget = function(target) {
|
49281 |
|
49282 | var targetId = target.id || target;
|
49283 |
|
49284 | var snapPoints = this._targets[targetId];
|
49285 |
|
49286 | if (!snapPoints) {
|
49287 | snapPoints = this._targets[targetId] = new SnapPoints();
|
49288 | snapPoints.initDefaults(this._defaultSnaps);
|
49289 | }
|
49290 |
|
49291 | return snapPoints;
|
49292 | };
|
49293 |
|
49294 |
|
49295 | |
49296 |
|
49297 |
|
49298 |
|
49299 |
|
49300 |
|
49301 | function SnapPoints(defaultSnaps) {
|
49302 |
|
49303 | |
49304 |
|
49305 |
|
49306 |
|
49307 |
|
49308 |
|
49309 | this._snapValues = {};
|
49310 | }
|
49311 |
|
49312 | SnapPoints.prototype.add = function(snapLocation, point) {
|
49313 |
|
49314 | var snapValues = this._snapValues[snapLocation];
|
49315 |
|
49316 | if (!snapValues) {
|
49317 | snapValues = this._snapValues[snapLocation] = { x: [], y: [] };
|
49318 | }
|
49319 |
|
49320 | if (snapValues.x.indexOf(point.x) === -1) {
|
49321 | snapValues.x.push(point.x);
|
49322 | }
|
49323 |
|
49324 | if (snapValues.y.indexOf(point.y) === -1) {
|
49325 | snapValues.y.push(point.y);
|
49326 | }
|
49327 | };
|
49328 |
|
49329 |
|
49330 | SnapPoints.prototype.snap = function(point, snapLocation, axis, tolerance) {
|
49331 | var snappingValues = this._snapValues[snapLocation];
|
49332 |
|
49333 | return snappingValues && snapTo(point[axis], snappingValues[axis], tolerance);
|
49334 | };
|
49335 |
|
49336 | |
49337 |
|
49338 |
|
49339 |
|
49340 |
|
49341 | SnapPoints.prototype.initDefaults = function(defaultSnaps) {
|
49342 |
|
49343 | var self = this;
|
49344 |
|
49345 | forEach(defaultSnaps || {}, function(snapPoints, snapLocation) {
|
49346 | forEach(snapPoints, function(point) {
|
49347 | self.add(snapLocation, point);
|
49348 | });
|
49349 | });
|
49350 | };
|
49351 |
|
49352 | var HIGHER_PRIORITY$1 = 1250;
|
49353 |
|
49354 |
|
49355 | |
49356 |
|
49357 |
|
49358 |
|
49359 |
|
49360 |
|
49361 | function Snapping(eventBus, canvas) {
|
49362 |
|
49363 | this._canvas = canvas;
|
49364 |
|
49365 | var self = this;
|
49366 |
|
49367 | eventBus.on([ 'shape.move.start', 'create.start' ], function(event) {
|
49368 | self.initSnap(event);
|
49369 | });
|
49370 |
|
49371 | eventBus.on([ 'shape.move.move', 'shape.move.end', 'create.move', 'create.end' ], HIGHER_PRIORITY$1, function(event) {
|
49372 |
|
49373 | if (event.originalEvent && event.originalEvent.ctrlKey) {
|
49374 | return;
|
49375 | }
|
49376 |
|
49377 | if (isSnapped(event)) {
|
49378 | return;
|
49379 | }
|
49380 |
|
49381 | self.snap(event);
|
49382 | });
|
49383 |
|
49384 | eventBus.on([ 'shape.move.cleanup', 'create.cleanup' ], function(event) {
|
49385 | self.hide();
|
49386 | });
|
49387 |
|
49388 |
|
49389 | this._asyncHide = debounce(bind(this.hide, this), 1000);
|
49390 | }
|
49391 |
|
49392 | Snapping.$inject = [ 'eventBus', 'canvas' ];
|
49393 |
|
49394 |
|
49395 | Snapping.prototype.initSnap = function(event) {
|
49396 |
|
49397 | var context = event.context,
|
49398 | shape = context.shape,
|
49399 | snapContext = context.snapContext;
|
49400 |
|
49401 | if (!snapContext) {
|
49402 | snapContext = context.snapContext = new SnapContext();
|
49403 | }
|
49404 |
|
49405 | var snapMid = mid$2(shape, event);
|
49406 |
|
49407 | snapContext.setSnapOrigin('mid', {
|
49408 | x: snapMid.x - event.x,
|
49409 | y: snapMid.y - event.y
|
49410 | });
|
49411 |
|
49412 | return snapContext;
|
49413 | };
|
49414 |
|
49415 |
|
49416 | Snapping.prototype.snap = function(event) {
|
49417 |
|
49418 | var context = event.context,
|
49419 | snapContext = context.snapContext,
|
49420 | shape = context.shape,
|
49421 | target = context.target,
|
49422 | snapLocations = snapContext.getSnapLocations();
|
49423 |
|
49424 | if (!target) {
|
49425 | return;
|
49426 | }
|
49427 |
|
49428 | var snapPoints = snapContext.pointsForTarget(target);
|
49429 |
|
49430 | if (!snapPoints.initialized) {
|
49431 | this.addTargetSnaps(snapPoints, shape, target);
|
49432 |
|
49433 | snapPoints.initialized = true;
|
49434 | }
|
49435 |
|
49436 |
|
49437 | var snapping = {
|
49438 | x: isSnapped(event, 'x'),
|
49439 | y: isSnapped(event, 'y')
|
49440 | };
|
49441 |
|
49442 |
|
49443 | forEach(snapLocations, function(location) {
|
49444 |
|
49445 | var snapOrigin = snapContext.getSnapOrigin(location);
|
49446 |
|
49447 | var snapCurrent = {
|
49448 | x: event.x + snapOrigin.x,
|
49449 | y: event.y + snapOrigin.y
|
49450 | };
|
49451 |
|
49452 |
|
49453 | forEach([ 'x', 'y' ], function(axis) {
|
49454 | var locationSnapping;
|
49455 |
|
49456 | if (!snapping[axis]) {
|
49457 | locationSnapping = snapPoints.snap(snapCurrent, location, axis, 7);
|
49458 |
|
49459 | if (locationSnapping !== undefined) {
|
49460 | snapping[axis] = {
|
49461 | value: locationSnapping,
|
49462 | originValue: locationSnapping - snapOrigin[axis]
|
49463 | };
|
49464 | }
|
49465 | }
|
49466 | });
|
49467 |
|
49468 |
|
49469 | if (snapping.x && snapping.y) {
|
49470 | return false;
|
49471 | }
|
49472 | });
|
49473 |
|
49474 |
|
49475 |
|
49476 |
|
49477 | this.showSnapLine('vertical', snapping.x && snapping.x.value);
|
49478 | this.showSnapLine('horizontal', snapping.y && snapping.y.value);
|
49479 |
|
49480 |
|
49481 |
|
49482 | forEach([ 'x', 'y' ], function(axis) {
|
49483 |
|
49484 | var axisSnapping = snapping[axis];
|
49485 |
|
49486 | if (typeof axisSnapping === 'object') {
|
49487 |
|
49488 | setSnapped(event, axis, axisSnapping.originValue);
|
49489 | }
|
49490 | });
|
49491 | };
|
49492 |
|
49493 |
|
49494 | Snapping.prototype._createLine = function(orientation) {
|
49495 |
|
49496 | var root = this._canvas.getLayer('snap');
|
49497 |
|
49498 |
|
49499 |
|
49500 | var line = create('path');
|
49501 | attr$1(line, { d: 'M0,0 L0,0' });
|
49502 | classes$1(line).add('djs-snap-line');
|
49503 |
|
49504 | append(root, line);
|
49505 |
|
49506 | return {
|
49507 | update: function(position) {
|
49508 |
|
49509 | if (typeof position !== 'number') {
|
49510 | attr$1(line, { display: 'none' });
|
49511 | } else {
|
49512 | if (orientation === 'horizontal') {
|
49513 | attr$1(line, {
|
49514 | d: 'M-100000,' + position + ' L+100000,' + position,
|
49515 | display: ''
|
49516 | });
|
49517 | } else {
|
49518 | attr$1(line, {
|
49519 | d: 'M ' + position + ',-100000 L ' + position + ', +100000',
|
49520 | display: ''
|
49521 | });
|
49522 | }
|
49523 | }
|
49524 | }
|
49525 | };
|
49526 | };
|
49527 |
|
49528 |
|
49529 | Snapping.prototype._createSnapLines = function() {
|
49530 |
|
49531 | this._snapLines = {
|
49532 | horizontal: this._createLine('horizontal'),
|
49533 | vertical: this._createLine('vertical')
|
49534 | };
|
49535 | };
|
49536 |
|
49537 | Snapping.prototype.showSnapLine = function(orientation, position) {
|
49538 |
|
49539 | var line = this.getSnapLine(orientation);
|
49540 |
|
49541 | if (line) {
|
49542 | line.update(position);
|
49543 | }
|
49544 |
|
49545 | this._asyncHide();
|
49546 | };
|
49547 |
|
49548 | Snapping.prototype.getSnapLine = function(orientation) {
|
49549 | if (!this._snapLines) {
|
49550 | this._createSnapLines();
|
49551 | }
|
49552 |
|
49553 | return this._snapLines[orientation];
|
49554 | };
|
49555 |
|
49556 | Snapping.prototype.hide = function() {
|
49557 | forEach(this._snapLines, function(l) {
|
49558 | l.update();
|
49559 | });
|
49560 | };
|
49561 |
|
49562 | Snapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
|
49563 |
|
49564 | var siblings = this.getSiblings(shape, target);
|
49565 |
|
49566 | forEach(siblings, function(s) {
|
49567 | snapPoints.add('mid', mid$2(s));
|
49568 | });
|
49569 |
|
49570 | };
|
49571 |
|
49572 | Snapping.prototype.getSiblings = function(element, target) {
|
49573 |
|
49574 |
|
49575 | return target && filter(target.children, function(e) {
|
49576 | return !e.hidden && !e.labelTarget && e.host !== element && e !== element;
|
49577 | });
|
49578 | };
|
49579 |
|
49580 | var round$b = Math.round;
|
49581 |
|
49582 | var HIGH_PRIORITY$6 = 1500;
|
49583 |
|
49584 |
|
49585 | |
49586 |
|
49587 |
|
49588 |
|
49589 |
|
49590 |
|
49591 |
|
49592 |
|
49593 |
|
49594 | function BpmnSnapping(eventBus, canvas, bpmnRules, elementRegistry) {
|
49595 |
|
49596 |
|
49597 | Snapping.call(this, eventBus, canvas);
|
49598 |
|
49599 |
|
49600 | |
49601 |
|
49602 |
|
49603 | eventBus.on('create.start', function(event) {
|
49604 |
|
49605 | var context = event.context,
|
49606 | shape = context.shape,
|
49607 | rootElement = canvas.getRootElement();
|
49608 |
|
49609 |
|
49610 | if (is$1(shape, 'bpmn:Participant') && is$1(rootElement, 'bpmn:Process')) {
|
49611 | initParticipantSnapping(context, shape, rootElement.children);
|
49612 | }
|
49613 | });
|
49614 |
|
49615 | eventBus.on([ 'create.move', 'create.end' ], HIGH_PRIORITY$6, function(event) {
|
49616 |
|
49617 | var context = event.context,
|
49618 | shape = context.shape,
|
49619 | participantSnapBox = context.participantSnapBox;
|
49620 |
|
49621 | if (!isSnapped(event) && participantSnapBox) {
|
49622 | snapParticipant(participantSnapBox, shape, event);
|
49623 | }
|
49624 | });
|
49625 |
|
49626 | eventBus.on('shape.move.start', function(event) {
|
49627 |
|
49628 | var context = event.context,
|
49629 | shape = context.shape,
|
49630 | rootElement = canvas.getRootElement();
|
49631 |
|
49632 |
|
49633 | if (is$1(shape, 'bpmn:Participant') && is$1(rootElement, 'bpmn:Process')) {
|
49634 | initParticipantSnapping(context, shape, rootElement.children);
|
49635 | }
|
49636 | });
|
49637 |
|
49638 |
|
49639 | function canAttach(shape, target, position) {
|
49640 | return bpmnRules.canAttach([ shape ], target, null, position) === 'attach';
|
49641 | }
|
49642 |
|
49643 | function canConnect(source, target) {
|
49644 | return bpmnRules.canConnect(source, target);
|
49645 | }
|
49646 |
|
49647 | |
49648 |
|
49649 |
|
49650 | eventBus.on([
|
49651 | 'create.move',
|
49652 | 'create.end',
|
49653 | 'shape.move.move',
|
49654 | 'shape.move.end'
|
49655 | ], HIGH_PRIORITY$6, function(event) {
|
49656 |
|
49657 | var context = event.context,
|
49658 | target = context.target,
|
49659 | shape = context.shape;
|
49660 |
|
49661 | if (target && !isSnapped(event) && canAttach(shape, target, event)) {
|
49662 | snapBoundaryEvent(event, shape, target);
|
49663 | }
|
49664 | });
|
49665 |
|
49666 | |
49667 |
|
49668 |
|
49669 |
|
49670 | eventBus.on([
|
49671 | 'shape.move.hover',
|
49672 | 'shape.move.move',
|
49673 | 'shape.move.end',
|
49674 | 'create.hover',
|
49675 | 'create.move',
|
49676 | 'create.end'
|
49677 | ], HIGH_PRIORITY$6, function(event) {
|
49678 | var context = event.context,
|
49679 | shape = context.shape,
|
49680 | hover = event.hover;
|
49681 |
|
49682 | if (is$1(hover, 'bpmn:Lane') && !isAny(shape, [ 'bpmn:Lane', 'bpmn:Participant' ])) {
|
49683 | event.hover = getLanesRoot(hover);
|
49684 | event.hoverGfx = elementRegistry.getGraphics(event.hover);
|
49685 | }
|
49686 | });
|
49687 |
|
49688 | |
49689 |
|
49690 |
|
49691 | eventBus.on([
|
49692 | 'connect.move',
|
49693 | 'connect.hover',
|
49694 | 'connect.end'
|
49695 | ], HIGH_PRIORITY$6, function(event) {
|
49696 | var context = event.context,
|
49697 | source = context.source,
|
49698 | target = context.target;
|
49699 |
|
49700 | var connection = canConnect(source, target) || {};
|
49701 |
|
49702 | if (!context.initialSourcePosition) {
|
49703 | context.initialSourcePosition = context.sourcePosition;
|
49704 | }
|
49705 |
|
49706 | if (
|
49707 | target && (
|
49708 | connection.type === 'bpmn:Association' ||
|
49709 | connection.type === 'bpmn:DataOutputAssociation' ||
|
49710 | connection.type === 'bpmn:DataInputAssociation' ||
|
49711 | connection.type === 'bpmn:SequenceFlow'
|
49712 | )
|
49713 | ) {
|
49714 |
|
49715 | context.sourcePosition = mid$2(source);
|
49716 |
|
49717 |
|
49718 | snapToPosition(event, mid$2(target));
|
49719 | } else
|
49720 |
|
49721 | if (connection.type === 'bpmn:MessageFlow') {
|
49722 |
|
49723 | if (is$1(source, 'bpmn:Event')) {
|
49724 |
|
49725 | context.sourcePosition = mid$2(source);
|
49726 | }
|
49727 |
|
49728 | if (is$1(target, 'bpmn:Event')) {
|
49729 |
|
49730 | snapToPosition(event, mid$2(target));
|
49731 | }
|
49732 | }
|
49733 |
|
49734 | else {
|
49735 |
|
49736 | context.sourcePosition = context.initialSourcePosition;
|
49737 | }
|
49738 |
|
49739 | });
|
49740 |
|
49741 |
|
49742 | eventBus.on('resize.start', HIGH_PRIORITY$6, function(event) {
|
49743 | var context = event.context,
|
49744 | shape = context.shape;
|
49745 |
|
49746 | if (is$1(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
|
49747 | context.minDimensions = { width: 140, height: 120 };
|
49748 | }
|
49749 |
|
49750 | if (is$1(shape, 'bpmn:Participant')) {
|
49751 | context.minDimensions = { width: 300, height: 150 };
|
49752 | }
|
49753 |
|
49754 | if (is$1(shape, 'bpmn:Lane') || is$1(shape, 'bpmn:Participant')) {
|
49755 | context.resizeConstraints = getParticipantSizeConstraints(
|
49756 | shape,
|
49757 | context.direction,
|
49758 | context.balanced
|
49759 | );
|
49760 | }
|
49761 |
|
49762 | if (is$1(shape, 'bpmn:TextAnnotation')) {
|
49763 | context.minDimensions = { width: 50, height: 30 };
|
49764 | }
|
49765 | });
|
49766 |
|
49767 | }
|
49768 |
|
49769 | inherits_browser(BpmnSnapping, Snapping);
|
49770 |
|
49771 | BpmnSnapping.$inject = [
|
49772 | 'eventBus',
|
49773 | 'canvas',
|
49774 | 'bpmnRules',
|
49775 | 'elementRegistry'
|
49776 | ];
|
49777 |
|
49778 |
|
49779 | BpmnSnapping.prototype.initSnap = function(event) {
|
49780 |
|
49781 | var context = event.context,
|
49782 | shape = event.shape,
|
49783 | shapeMid,
|
49784 | shapeBounds,
|
49785 | shapeTopLeft,
|
49786 | shapeBottomRight,
|
49787 | snapContext;
|
49788 |
|
49789 |
|
49790 | snapContext = Snapping.prototype.initSnap.call(this, event);
|
49791 |
|
49792 | if (is$1(shape, 'bpmn:Participant')) {
|
49793 |
|
49794 | snapContext.setSnapLocations([ 'top-left', 'bottom-right', 'mid' ]);
|
49795 | }
|
49796 |
|
49797 |
|
49798 | if (shape) {
|
49799 |
|
49800 | shapeMid = mid$2(shape, event);
|
49801 |
|
49802 | shapeBounds = {
|
49803 | width: shape.width,
|
49804 | height: shape.height,
|
49805 | x: isNaN(shape.x) ? round$b(shapeMid.x - shape.width / 2) : shape.x,
|
49806 | y: isNaN(shape.y) ? round$b(shapeMid.y - shape.height / 2) : shape.y
|
49807 | };
|
49808 |
|
49809 | shapeTopLeft = topLeft(shapeBounds);
|
49810 | shapeBottomRight = bottomRight(shapeBounds);
|
49811 |
|
49812 | snapContext.setSnapOrigin('top-left', {
|
49813 | x: shapeTopLeft.x - event.x,
|
49814 | y: shapeTopLeft.y - event.y
|
49815 | });
|
49816 |
|
49817 | snapContext.setSnapOrigin('bottom-right', {
|
49818 | x: shapeBottomRight.x - event.x,
|
49819 | y: shapeBottomRight.y - event.y
|
49820 | });
|
49821 |
|
49822 | forEach(shape.outgoing, function(c) {
|
49823 | var docking = c.waypoints[0];
|
49824 |
|
49825 | docking = docking.original || docking;
|
49826 |
|
49827 | snapContext.setSnapOrigin(c.id + '-docking', {
|
49828 | x: docking.x - event.x,
|
49829 | y: docking.y - event.y
|
49830 | });
|
49831 | });
|
49832 |
|
49833 | forEach(shape.incoming, function(c) {
|
49834 | var docking = c.waypoints[c.waypoints.length - 1];
|
49835 |
|
49836 | docking = docking.original || docking;
|
49837 |
|
49838 | snapContext.setSnapOrigin(c.id + '-docking', {
|
49839 | x: docking.x - event.x,
|
49840 | y: docking.y - event.y
|
49841 | });
|
49842 | });
|
49843 |
|
49844 | }
|
49845 |
|
49846 | var source = context.source;
|
49847 |
|
49848 | if (source) {
|
49849 | snapContext.addDefaultSnap('mid', mid$2(source));
|
49850 | }
|
49851 | };
|
49852 |
|
49853 |
|
49854 | BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
|
49855 |
|
49856 |
|
49857 | if (is$1(shape, 'bpmn:BoundaryEvent') && shape.type !== 'label') {
|
49858 | target = target.parent;
|
49859 | }
|
49860 |
|
49861 |
|
49862 | if (is$1(target, 'bpmn:SequenceFlow')) {
|
49863 | this.addTargetSnaps(snapPoints, shape, target.parent);
|
49864 | }
|
49865 |
|
49866 | var siblings = this.getSiblings(shape, target) || [];
|
49867 |
|
49868 | forEach(siblings, function(sibling) {
|
49869 |
|
49870 |
|
49871 | if (is$1(sibling, 'bpmn:Lane')) {
|
49872 | return;
|
49873 | }
|
49874 |
|
49875 | if (sibling.waypoints) {
|
49876 |
|
49877 | forEach(sibling.waypoints.slice(1, -1), function(waypoint, i) {
|
49878 | var nextWaypoint = sibling.waypoints[i + 2],
|
49879 | previousWaypoint = sibling.waypoints[i];
|
49880 |
|
49881 | if (!nextWaypoint || !previousWaypoint) {
|
49882 | throw new Error('waypoints must exist');
|
49883 | }
|
49884 |
|
49885 | if (nextWaypoint.x === waypoint.x ||
|
49886 | nextWaypoint.y === waypoint.y ||
|
49887 | previousWaypoint.x === waypoint.x ||
|
49888 | previousWaypoint.y === waypoint.y) {
|
49889 | snapPoints.add('mid', waypoint);
|
49890 | }
|
49891 | });
|
49892 |
|
49893 | return;
|
49894 | }
|
49895 |
|
49896 | snapPoints.add('mid', mid$2(sibling));
|
49897 |
|
49898 | if (is$1(sibling, 'bpmn:Participant')) {
|
49899 | snapPoints.add('top-left', topLeft(sibling));
|
49900 | snapPoints.add('bottom-right', bottomRight(sibling));
|
49901 | }
|
49902 | });
|
49903 |
|
49904 |
|
49905 | forEach(shape.incoming, function(c) {
|
49906 |
|
49907 | if (siblings.indexOf(c.source) === -1) {
|
49908 | snapPoints.add('mid', mid$2(c.source));
|
49909 | }
|
49910 |
|
49911 | var docking = c.waypoints[0];
|
49912 | snapPoints.add(c.id + '-docking', docking.original || docking);
|
49913 | });
|
49914 |
|
49915 |
|
49916 | forEach(shape.outgoing, function(c) {
|
49917 |
|
49918 | if (siblings.indexOf(c.target) === -1) {
|
49919 | snapPoints.add('mid', mid$2(c.target));
|
49920 | }
|
49921 |
|
49922 | var docking = c.waypoints[c.waypoints.length - 1];
|
49923 | snapPoints.add(c.id + '-docking', docking.original || docking);
|
49924 | });
|
49925 | };
|
49926 |
|
49927 |
|
49928 |
|
49929 |
|
49930 | function initParticipantSnapping(context, shape, elements) {
|
49931 |
|
49932 | if (!elements.length) {
|
49933 | return;
|
49934 | }
|
49935 |
|
49936 | var snapBox = getBBox(elements.filter(function(e) {
|
49937 | return !e.labelTarget && !e.waypoints;
|
49938 | }));
|
49939 |
|
49940 | snapBox.x -= 50;
|
49941 | snapBox.y -= 20;
|
49942 | snapBox.width += 70;
|
49943 | snapBox.height += 40;
|
49944 |
|
49945 |
|
49946 | shape.width = Math.max(shape.width, snapBox.width);
|
49947 | shape.height = Math.max(shape.height, snapBox.height);
|
49948 |
|
49949 | context.participantSnapBox = snapBox;
|
49950 | }
|
49951 |
|
49952 | function snapParticipant(snapBox, shape, event, offset) {
|
49953 | offset = offset || 0;
|
49954 |
|
49955 | var shapeHalfWidth = shape.width / 2 - offset,
|
49956 | shapeHalfHeight = shape.height / 2;
|
49957 |
|
49958 | var currentTopLeft = {
|
49959 | x: event.x - shapeHalfWidth - offset,
|
49960 | y: event.y - shapeHalfHeight
|
49961 | };
|
49962 |
|
49963 | var currentBottomRight = {
|
49964 | x: event.x + shapeHalfWidth + offset,
|
49965 | y: event.y + shapeHalfHeight
|
49966 | };
|
49967 |
|
49968 | var snapTopLeft = snapBox,
|
49969 | snapBottomRight = bottomRight(snapBox);
|
49970 |
|
49971 | if (currentTopLeft.x >= snapTopLeft.x) {
|
49972 | setSnapped(event, 'x', snapTopLeft.x + offset + shapeHalfWidth);
|
49973 | } else
|
49974 | if (currentBottomRight.x <= snapBottomRight.x) {
|
49975 | setSnapped(event, 'x', snapBottomRight.x - offset - shapeHalfWidth);
|
49976 | }
|
49977 |
|
49978 | if (currentTopLeft.y >= snapTopLeft.y) {
|
49979 | setSnapped(event, 'y', snapTopLeft.y + shapeHalfHeight);
|
49980 | } else
|
49981 | if (currentBottomRight.y <= snapBottomRight.y) {
|
49982 | setSnapped(event, 'y', snapBottomRight.y - shapeHalfHeight);
|
49983 | }
|
49984 | }
|
49985 |
|
49986 |
|
49987 |
|
49988 |
|
49989 | function snapBoundaryEvent(event, shape, target) {
|
49990 | var targetTRBL = asTRBL(target);
|
49991 |
|
49992 | var direction = getBoundaryAttachment(event, target);
|
49993 |
|
49994 | if (/top/.test(direction)) {
|
49995 | setSnapped(event, 'y', targetTRBL.top);
|
49996 | } else
|
49997 | if (/bottom/.test(direction)) {
|
49998 | setSnapped(event, 'y', targetTRBL.bottom);
|
49999 | }
|
50000 |
|
50001 | if (/left/.test(direction)) {
|
50002 | setSnapped(event, 'x', targetTRBL.left);
|
50003 | } else
|
50004 | if (/right/.test(direction)) {
|
50005 | setSnapped(event, 'x', targetTRBL.right);
|
50006 | }
|
50007 | }
|
50008 |
|
50009 |
|
50010 | function snapToPosition(event, position) {
|
50011 | setSnapped(event, 'x', position.x);
|
50012 | setSnapped(event, 'y', position.y);
|
50013 | }
|
50014 |
|
50015 | var SnappingModule = {
|
50016 | __init__: [ 'snapping' ],
|
50017 | snapping: [ 'type', BpmnSnapping ]
|
50018 | };
|
50019 |
|
50020 | |
50021 |
|
50022 |
|
50023 | function SearchPad(canvas, eventBus, overlays, selection) {
|
50024 | this._open = false;
|
50025 | this._results = [];
|
50026 | this._eventMaps = [];
|
50027 |
|
50028 | this._canvas = canvas;
|
50029 | this._eventBus = eventBus;
|
50030 | this._overlays = overlays;
|
50031 | this._selection = selection;
|
50032 |
|
50033 |
|
50034 | this._container = domify(SearchPad.BOX_HTML);
|
50035 | this._searchInput = query(SearchPad.INPUT_SELECTOR, this._container);
|
50036 | this._resultsContainer = query(SearchPad.RESULTS_CONTAINER_SELECTOR, this._container);
|
50037 |
|
50038 |
|
50039 | this._canvas.getContainer().appendChild(this._container);
|
50040 |
|
50041 |
|
50042 | eventBus.on([ 'canvas.destroy', 'diagram.destroy' ], this.close, this);
|
50043 | }
|
50044 |
|
50045 |
|
50046 | SearchPad.$inject = [
|
50047 | 'canvas',
|
50048 | 'eventBus',
|
50049 | 'overlays',
|
50050 | 'selection'
|
50051 | ];
|
50052 |
|
50053 |
|
50054 | |
50055 |
|
50056 |
|
50057 | SearchPad.prototype._bindEvents = function() {
|
50058 | var self = this;
|
50059 |
|
50060 | function listen(el, selector, type, fn) {
|
50061 | self._eventMaps.push({
|
50062 | el: el,
|
50063 | type: type,
|
50064 | listener: delegateEvents.bind(el, selector, type, fn)
|
50065 | });
|
50066 | }
|
50067 |
|
50068 |
|
50069 | listen(document, 'html', 'click', function(e) {
|
50070 | self.close();
|
50071 | }, true);
|
50072 |
|
50073 |
|
50074 |
|
50075 | listen(this._container, SearchPad.INPUT_SELECTOR, 'click', function(e) {
|
50076 | e.stopPropagation();
|
50077 | e.delegateTarget.focus();
|
50078 | });
|
50079 |
|
50080 |
|
50081 | listen(this._container, SearchPad.RESULT_SELECTOR, 'mouseover', function(e) {
|
50082 | e.stopPropagation();
|
50083 | self._scrollToNode(e.delegateTarget);
|
50084 | self._preselect(e.delegateTarget);
|
50085 | });
|
50086 |
|
50087 |
|
50088 | listen(this._container, SearchPad.RESULT_SELECTOR, 'click', function(e) {
|
50089 | e.stopPropagation();
|
50090 | self._select(e.delegateTarget);
|
50091 | });
|
50092 |
|
50093 |
|
50094 |
|
50095 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keydown', function(e) {
|
50096 |
|
50097 | if (e.keyCode === 38) {
|
50098 | e.preventDefault();
|
50099 | }
|
50100 |
|
50101 |
|
50102 | if (e.keyCode === 40) {
|
50103 | e.preventDefault();
|
50104 | }
|
50105 | });
|
50106 |
|
50107 |
|
50108 | listen(this._container, SearchPad.INPUT_SELECTOR, 'keyup', function(e) {
|
50109 |
|
50110 | if (e.keyCode === 27) {
|
50111 | return self.close();
|
50112 | }
|
50113 |
|
50114 |
|
50115 | if (e.keyCode === 13) {
|
50116 | var selected = self._getCurrentResult();
|
50117 |
|
50118 | return selected ? self._select(selected) : self.close();
|
50119 | }
|
50120 |
|
50121 |
|
50122 | if (e.keyCode === 38) {
|
50123 | return self._scrollToDirection(true);
|
50124 | }
|
50125 |
|
50126 |
|
50127 | if (e.keyCode === 40) {
|
50128 | return self._scrollToDirection();
|
50129 | }
|
50130 |
|
50131 |
|
50132 |
|
50133 | if (e.keyCode === 37 || e.keyCode === 39) {
|
50134 | return;
|
50135 | }
|
50136 |
|
50137 |
|
50138 | self._search(e.delegateTarget.value);
|
50139 | });
|
50140 | };
|
50141 |
|
50142 |
|
50143 | |
50144 |
|
50145 |
|
50146 | SearchPad.prototype._unbindEvents = function() {
|
50147 | this._eventMaps.forEach(function(m) {
|
50148 | delegateEvents.unbind(m.el, m.type, m.listener);
|
50149 | });
|
50150 | };
|
50151 |
|
50152 |
|
50153 | |
50154 |
|
50155 |
|
50156 |
|
50157 |
|
50158 | SearchPad.prototype._search = function(pattern) {
|
50159 | var self = this;
|
50160 |
|
50161 | this._clearResults();
|
50162 |
|
50163 |
|
50164 | if (!pattern || pattern === '') {
|
50165 | return;
|
50166 | }
|
50167 |
|
50168 | var searchResults = this._searchProvider.find(pattern);
|
50169 |
|
50170 | if (!searchResults.length) {
|
50171 | return;
|
50172 | }
|
50173 |
|
50174 |
|
50175 | searchResults.forEach(function(result) {
|
50176 | var id = result.element.id;
|
50177 | var node = self._createResultNode(result, id);
|
50178 | self._results[id] = {
|
50179 | element: result.element,
|
50180 | node: node
|
50181 | };
|
50182 | });
|
50183 |
|
50184 |
|
50185 | var node = query(SearchPad.RESULT_SELECTOR, this._resultsContainer);
|
50186 | this._scrollToNode(node);
|
50187 | this._preselect(node);
|
50188 | };
|
50189 |
|
50190 |
|
50191 | |
50192 |
|
50193 |
|
50194 |
|
50195 | SearchPad.prototype._scrollToDirection = function(previous) {
|
50196 | var selected = this._getCurrentResult();
|
50197 | if (!selected) {
|
50198 | return;
|
50199 | }
|
50200 |
|
50201 | var node = previous ? selected.previousElementSibling : selected.nextElementSibling;
|
50202 | if (node) {
|
50203 | this._scrollToNode(node);
|
50204 | this._preselect(node);
|
50205 | }
|
50206 | };
|
50207 |
|
50208 |
|
50209 | |
50210 |
|
50211 |
|
50212 |
|
50213 |
|
50214 | SearchPad.prototype._scrollToNode = function(node) {
|
50215 | if (!node || node === this._getCurrentResult()) {
|
50216 | return;
|
50217 | }
|
50218 |
|
50219 | var nodeOffset = node.offsetTop;
|
50220 | var containerScroll = this._resultsContainer.scrollTop;
|
50221 |
|
50222 | var bottomScroll = nodeOffset - this._resultsContainer.clientHeight + node.clientHeight;
|
50223 |
|
50224 | if (nodeOffset < containerScroll) {
|
50225 | this._resultsContainer.scrollTop = nodeOffset;
|
50226 | } else if (containerScroll < bottomScroll) {
|
50227 | this._resultsContainer.scrollTop = bottomScroll;
|
50228 | }
|
50229 | };
|
50230 |
|
50231 |
|
50232 | |
50233 |
|
50234 |
|
50235 | SearchPad.prototype._clearResults = function() {
|
50236 | clear(this._resultsContainer);
|
50237 |
|
50238 | this._results = [];
|
50239 |
|
50240 | this._resetOverlay();
|
50241 |
|
50242 | this._eventBus.fire('searchPad.cleared');
|
50243 | };
|
50244 |
|
50245 |
|
50246 | |
50247 |
|
50248 |
|
50249 |
|
50250 |
|
50251 | SearchPad.prototype._getCurrentResult = function() {
|
50252 | return query(SearchPad.RESULT_SELECTED_SELECTOR, this._resultsContainer);
|
50253 | };
|
50254 |
|
50255 |
|
50256 | |
50257 |
|
50258 |
|
50259 |
|
50260 |
|
50261 |
|
50262 |
|
50263 |
|
50264 |
|
50265 |
|
50266 |
|
50267 |
|
50268 | SearchPad.prototype._createResultNode = function(result, id) {
|
50269 | var node = domify(SearchPad.RESULT_HTML);
|
50270 |
|
50271 |
|
50272 | if (result.primaryTokens.length > 0) {
|
50273 | createInnerTextNode(node, result.primaryTokens, SearchPad.RESULT_PRIMARY_HTML);
|
50274 | }
|
50275 |
|
50276 |
|
50277 | createInnerTextNode(node, result.secondaryTokens, SearchPad.RESULT_SECONDARY_HTML);
|
50278 |
|
50279 | attr(node, SearchPad.RESULT_ID_ATTRIBUTE, id);
|
50280 |
|
50281 | this._resultsContainer.appendChild(node);
|
50282 |
|
50283 | return node;
|
50284 | };
|
50285 |
|
50286 |
|
50287 | |
50288 |
|
50289 |
|
50290 |
|
50291 |
|
50292 |
|
50293 |
|
50294 |
|
50295 | SearchPad.prototype.registerProvider = function(provider) {
|
50296 | this._searchProvider = provider;
|
50297 | };
|
50298 |
|
50299 |
|
50300 | |
50301 |
|
50302 |
|
50303 | SearchPad.prototype.open = function() {
|
50304 | if (!this._searchProvider) {
|
50305 | throw new Error('no search provider registered');
|
50306 | }
|
50307 |
|
50308 | if (this.isOpen()) {
|
50309 | return;
|
50310 | }
|
50311 |
|
50312 | this._bindEvents();
|
50313 |
|
50314 | this._open = true;
|
50315 |
|
50316 | classes(this._container).add('open');
|
50317 |
|
50318 | this._searchInput.focus();
|
50319 |
|
50320 | this._eventBus.fire('searchPad.opened');
|
50321 | };
|
50322 |
|
50323 |
|
50324 | |
50325 |
|
50326 |
|
50327 | SearchPad.prototype.close = function() {
|
50328 | if (!this.isOpen()) {
|
50329 | return;
|
50330 | }
|
50331 |
|
50332 | this._unbindEvents();
|
50333 |
|
50334 | this._open = false;
|
50335 |
|
50336 | classes(this._container).remove('open');
|
50337 |
|
50338 | this._clearResults();
|
50339 |
|
50340 | this._searchInput.value = '';
|
50341 | this._searchInput.blur();
|
50342 |
|
50343 | this._resetOverlay();
|
50344 |
|
50345 | this._eventBus.fire('searchPad.closed');
|
50346 | };
|
50347 |
|
50348 |
|
50349 | |
50350 |
|
50351 |
|
50352 | SearchPad.prototype.toggle = function() {
|
50353 | this.isOpen() ? this.close() : this.open();
|
50354 | };
|
50355 |
|
50356 |
|
50357 | |
50358 |
|
50359 |
|
50360 | SearchPad.prototype.isOpen = function() {
|
50361 | return this._open;
|
50362 | };
|
50363 |
|
50364 |
|
50365 | |
50366 |
|
50367 |
|
50368 |
|
50369 |
|
50370 | SearchPad.prototype._preselect = function(node) {
|
50371 | var selectedNode = this._getCurrentResult();
|
50372 |
|
50373 |
|
50374 | if (node === selectedNode) {
|
50375 | return;
|
50376 | }
|
50377 |
|
50378 |
|
50379 | if (selectedNode) {
|
50380 | classes(selectedNode).remove(SearchPad.RESULT_SELECTED_CLASS);
|
50381 | }
|
50382 |
|
50383 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
50384 | var element = this._results[id].element;
|
50385 |
|
50386 | classes(node).add(SearchPad.RESULT_SELECTED_CLASS);
|
50387 |
|
50388 | this._resetOverlay(element);
|
50389 |
|
50390 | this._centerViewbox(element);
|
50391 |
|
50392 | this._selection.select(element);
|
50393 |
|
50394 | this._eventBus.fire('searchPad.preselected', element);
|
50395 | };
|
50396 |
|
50397 |
|
50398 | |
50399 |
|
50400 |
|
50401 |
|
50402 |
|
50403 | SearchPad.prototype._select = function(node) {
|
50404 | var id = attr(node, SearchPad.RESULT_ID_ATTRIBUTE);
|
50405 | var element = this._results[id].element;
|
50406 |
|
50407 | this.close();
|
50408 |
|
50409 | this._resetOverlay();
|
50410 |
|
50411 | this._centerViewbox(element);
|
50412 |
|
50413 | this._selection.select(element);
|
50414 |
|
50415 | this._eventBus.fire('searchPad.selected', element);
|
50416 | };
|
50417 |
|
50418 |
|
50419 | |
50420 |
|
50421 |
|
50422 |
|
50423 |
|
50424 | SearchPad.prototype._centerViewbox = function(element) {
|
50425 | var viewbox = this._canvas.viewbox();
|
50426 |
|
50427 | var box = getBBox(element);
|
50428 |
|
50429 | var newViewbox = {
|
50430 | x: (box.x + box.width/2) - viewbox.outer.width/2,
|
50431 | y: (box.y + box.height/2) - viewbox.outer.height/2,
|
50432 | width: viewbox.outer.width,
|
50433 | height: viewbox.outer.height
|
50434 | };
|
50435 |
|
50436 | this._canvas.viewbox(newViewbox);
|
50437 |
|
50438 | this._canvas.zoom(viewbox.scale);
|
50439 | };
|
50440 |
|
50441 |
|
50442 | |
50443 |
|
50444 |
|
50445 |
|
50446 |
|
50447 |
|
50448 | SearchPad.prototype._resetOverlay = function(element) {
|
50449 | if (this._overlayId) {
|
50450 | this._overlays.remove(this._overlayId);
|
50451 | }
|
50452 |
|
50453 | if (element) {
|
50454 | var box = getBBox(element);
|
50455 | var overlay = constructOverlay(box);
|
50456 | this._overlayId = this._overlays.add(element, overlay);
|
50457 | }
|
50458 | };
|
50459 |
|
50460 |
|
50461 | |
50462 |
|
50463 |
|
50464 |
|
50465 |
|
50466 |
|
50467 | function constructOverlay(box) {
|
50468 |
|
50469 | var offset = 6;
|
50470 | var w = box.width + offset * 2;
|
50471 | var h = box.height + offset * 2;
|
50472 |
|
50473 | var styles = [
|
50474 | 'width: '+ w +'px',
|
50475 | 'height: '+ h + 'px'
|
50476 | ].join('; ');
|
50477 |
|
50478 | return {
|
50479 | position: {
|
50480 | bottom: h - offset,
|
50481 | right: w - offset
|
50482 | },
|
50483 | show: true,
|
50484 | html: '<div style="' + styles + '" class="' + SearchPad.OVERLAY_CLASS + '"></div>'
|
50485 | };
|
50486 | }
|
50487 |
|
50488 |
|
50489 | |
50490 |
|
50491 |
|
50492 |
|
50493 |
|
50494 |
|
50495 |
|
50496 | function createInnerTextNode(parentNode, tokens, template) {
|
50497 | var text = createHtmlText(tokens);
|
50498 | var childNode = domify(template);
|
50499 | childNode.innerHTML = text;
|
50500 | parentNode.appendChild(childNode);
|
50501 | }
|
50502 |
|
50503 | |
50504 |
|
50505 |
|
50506 |
|
50507 |
|
50508 |
|
50509 |
|
50510 | function createHtmlText(tokens) {
|
50511 | var htmlText = '';
|
50512 |
|
50513 | tokens.forEach(function(t) {
|
50514 | if (t.matched) {
|
50515 | htmlText += '<strong class="' + SearchPad.RESULT_HIGHLIGHT_CLASS + '">' + t.matched + '</strong>';
|
50516 | } else {
|
50517 | htmlText += t.normal;
|
50518 | }
|
50519 | });
|
50520 |
|
50521 | return htmlText !== '' ? htmlText : null;
|
50522 | }
|
50523 |
|
50524 |
|
50525 | |
50526 |
|
50527 |
|
50528 | SearchPad.CONTAINER_SELECTOR = '.djs-search-container';
|
50529 | SearchPad.INPUT_SELECTOR = '.djs-search-input input';
|
50530 | SearchPad.RESULTS_CONTAINER_SELECTOR = '.djs-search-results';
|
50531 | SearchPad.RESULT_SELECTOR = '.djs-search-result';
|
50532 | SearchPad.RESULT_SELECTED_CLASS = 'djs-search-result-selected';
|
50533 | SearchPad.RESULT_SELECTED_SELECTOR = '.' + SearchPad.RESULT_SELECTED_CLASS;
|
50534 | SearchPad.RESULT_ID_ATTRIBUTE = 'data-result-id';
|
50535 | SearchPad.RESULT_HIGHLIGHT_CLASS = 'djs-search-highlight';
|
50536 | SearchPad.OVERLAY_CLASS = 'djs-search-overlay';
|
50537 |
|
50538 | SearchPad.BOX_HTML =
|
50539 | '<div class="djs-search-container djs-draggable djs-scrollable">' +
|
50540 | '<div class="djs-search-input">' +
|
50541 | '<input type="text"/>' +
|
50542 | '</div>' +
|
50543 | '<div class="djs-search-results"></div>' +
|
50544 | '</div>';
|
50545 |
|
50546 | SearchPad.RESULT_HTML =
|
50547 | '<div class="djs-search-result"></div>';
|
50548 |
|
50549 | SearchPad.RESULT_PRIMARY_HTML =
|
50550 | '<div class="djs-search-result-primary"></div>';
|
50551 |
|
50552 | SearchPad.RESULT_SECONDARY_HTML =
|
50553 | '<p class="djs-search-result-secondary"></p>';
|
50554 |
|
50555 | var SearchPadModule = {
|
50556 | __depends__: [
|
50557 | OverlaysModule,
|
50558 | SelectionModule
|
50559 | ],
|
50560 | searchPad: [ 'type', SearchPad ]
|
50561 | };
|
50562 |
|
50563 | |
50564 |
|
50565 |
|
50566 | function BpmnSearchProvider(elementRegistry, searchPad, canvas) {
|
50567 |
|
50568 | this._elementRegistry = elementRegistry;
|
50569 | this._canvas = canvas;
|
50570 |
|
50571 | searchPad.registerProvider(this);
|
50572 | }
|
50573 |
|
50574 | BpmnSearchProvider.$inject = [
|
50575 | 'elementRegistry',
|
50576 | 'searchPad',
|
50577 | 'canvas'
|
50578 | ];
|
50579 |
|
50580 |
|
50581 | |
50582 |
|
50583 |
|
50584 |
|
50585 |
|
50586 |
|
50587 |
|
50588 |
|
50589 |
|
50590 |
|
50591 |
|
50592 |
|
50593 |
|
50594 |
|
50595 |
|
50596 |
|
50597 |
|
50598 |
|
50599 | BpmnSearchProvider.prototype.find = function(pattern) {
|
50600 | var rootElement = this._canvas.getRootElement();
|
50601 |
|
50602 | var elements = this._elementRegistry.filter(function(element) {
|
50603 | if (element.labelTarget) {
|
50604 | return false;
|
50605 | }
|
50606 | return true;
|
50607 | });
|
50608 |
|
50609 |
|
50610 | elements = filter(elements, function(element) {
|
50611 | return element !== rootElement;
|
50612 | });
|
50613 |
|
50614 | elements = map(elements, function(element) {
|
50615 | return {
|
50616 | primaryTokens: matchAndSplit(getLabel(element), pattern),
|
50617 | secondaryTokens: matchAndSplit(element.id, pattern),
|
50618 | element: element
|
50619 | };
|
50620 | });
|
50621 |
|
50622 |
|
50623 | elements = filter(elements, function(element) {
|
50624 | return hasMatched(element.primaryTokens) || hasMatched(element.secondaryTokens);
|
50625 | });
|
50626 |
|
50627 | elements = sortBy(elements, function(element) {
|
50628 | return getLabel(element.element) + element.element.id;
|
50629 | });
|
50630 |
|
50631 | return elements;
|
50632 | };
|
50633 |
|
50634 |
|
50635 | function hasMatched(tokens) {
|
50636 | var matched = filter(tokens, function(t) {
|
50637 | return !!t.matched;
|
50638 | });
|
50639 |
|
50640 | return matched.length > 0;
|
50641 | }
|
50642 |
|
50643 |
|
50644 | function matchAndSplit(text, pattern) {
|
50645 | var tokens = [],
|
50646 | originalText = text;
|
50647 |
|
50648 | if (!text) {
|
50649 | return tokens;
|
50650 | }
|
50651 |
|
50652 | text = text.toLowerCase();
|
50653 | pattern = pattern.toLowerCase();
|
50654 |
|
50655 | var i = text.indexOf(pattern);
|
50656 |
|
50657 | if (i > -1) {
|
50658 | if (i !== 0) {
|
50659 | tokens.push({
|
50660 | normal: originalText.substr(0, i)
|
50661 | });
|
50662 | }
|
50663 |
|
50664 | tokens.push({
|
50665 | matched: originalText.substr(i, pattern.length)
|
50666 | });
|
50667 |
|
50668 | if (pattern.length + i < text.length) {
|
50669 | tokens.push({
|
50670 | normal: originalText.substr(pattern.length + i, text.length)
|
50671 | });
|
50672 | }
|
50673 | } else {
|
50674 | tokens.push({
|
50675 | normal: originalText
|
50676 | });
|
50677 | }
|
50678 |
|
50679 | return tokens;
|
50680 | }
|
50681 |
|
50682 | var SearchModule = {
|
50683 | __depends__: [
|
50684 | SearchPadModule
|
50685 | ],
|
50686 | __init__: [ 'bpmnSearch'],
|
50687 | bpmnSearch: [ 'type', BpmnSearchProvider ]
|
50688 | };
|
50689 |
|
50690 | var initialDiagram =
|
50691 | '<?xml version="1.0" encoding="UTF-8"?>' +
|
50692 | '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
50693 | 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
50694 | 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
|
50695 | 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
|
50696 | 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
|
50697 | 'id="Definitions_1">' +
|
50698 | '<bpmn:process id="Process_1" isExecutable="false">' +
|
50699 | '<bpmn:startEvent id="StartEvent_1"/>' +
|
50700 | '</bpmn:process>' +
|
50701 | '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
|
50702 | '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
|
50703 | '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
|
50704 | '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
|
50705 | '</bpmndi:BPMNShape>' +
|
50706 | '</bpmndi:BPMNPlane>' +
|
50707 | '</bpmndi:BPMNDiagram>' +
|
50708 | '</bpmn:definitions>';
|
50709 |
|
50710 |
|
50711 | |
50712 |
|
50713 |
|
50714 |
|
50715 |
|
50716 |
|
50717 |
|
50718 |
|
50719 |
|
50720 |
|
50721 |
|
50722 |
|
50723 |
|
50724 |
|
50725 |
|
50726 |
|
50727 |
|
50728 |
|
50729 |
|
50730 |
|
50731 |
|
50732 |
|
50733 |
|
50734 |
|
50735 |
|
50736 |
|
50737 |
|
50738 |
|
50739 |
|
50740 |
|
50741 |
|
50742 |
|
50743 |
|
50744 |
|
50745 |
|
50746 |
|
50747 |
|
50748 |
|
50749 |
|
50750 |
|
50751 |
|
50752 |
|
50753 |
|
50754 |
|
50755 |
|
50756 |
|
50757 |
|
50758 |
|
50759 |
|
50760 |
|
50761 |
|
50762 |
|
50763 |
|
50764 |
|
50765 |
|
50766 |
|
50767 |
|
50768 |
|
50769 |
|
50770 |
|
50771 |
|
50772 |
|
50773 |
|
50774 |
|
50775 |
|
50776 |
|
50777 |
|
50778 |
|
50779 |
|
50780 |
|
50781 |
|
50782 |
|
50783 | function Modeler(options) {
|
50784 | Viewer.call(this, options);
|
50785 |
|
50786 |
|
50787 | this.on('import.parse.complete', function(event) {
|
50788 | if (!event.error) {
|
50789 | this._collectIds(event.definitions, event.context);
|
50790 | }
|
50791 | }, this);
|
50792 |
|
50793 | this.on('diagram.destroy', function() {
|
50794 | this.get('moddle').ids.clear();
|
50795 | }, this);
|
50796 | }
|
50797 |
|
50798 | inherits_browser(Modeler, Viewer);
|
50799 |
|
50800 | Modeler.Viewer = Viewer;
|
50801 | Modeler.NavigatedViewer = NavigatedViewer;
|
50802 |
|
50803 | |
50804 |
|
50805 |
|
50806 |
|
50807 |
|
50808 | Modeler.prototype.createDiagram = function(done) {
|
50809 | return this.importXML(initialDiagram, done);
|
50810 | };
|
50811 |
|
50812 | |
50813 |
|
50814 |
|
50815 |
|
50816 |
|
50817 | Modeler.prototype._createModdle = function(options) {
|
50818 | var moddle = Viewer.prototype._createModdle.call(this, options);
|
50819 |
|
50820 |
|
50821 |
|
50822 |
|
50823 | moddle.ids = new ids([ 32, 36, 1 ]);
|
50824 |
|
50825 | return moddle;
|
50826 | };
|
50827 |
|
50828 | |
50829 |
|
50830 |
|
50831 |
|
50832 |
|
50833 |
|
50834 |
|
50835 | Modeler.prototype._collectIds = function(definitions, context) {
|
50836 |
|
50837 | var moddle = definitions.$model,
|
50838 | ids$$1 = moddle.ids,
|
50839 | id;
|
50840 |
|
50841 |
|
50842 | ids$$1.clear();
|
50843 |
|
50844 | for (id in context.elementsById) {
|
50845 | ids$$1.claim(id, context.elementsById[id]);
|
50846 | }
|
50847 | };
|
50848 |
|
50849 | Modeler.prototype._interactionModules = [
|
50850 |
|
50851 | KeyboardMoveModule,
|
50852 | MoveCanvasModule,
|
50853 | TouchModule$1,
|
50854 | ZoomScrollModule
|
50855 | ];
|
50856 |
|
50857 | Modeler.prototype._modelingModules = [
|
50858 |
|
50859 | AlignElementsModule,
|
50860 | AutoPlaceModule,
|
50861 | AutoScrollModule,
|
50862 | AutoResizeModule,
|
50863 | BendpointsModule,
|
50864 | ContextPadModule$1,
|
50865 | CopyPasteModule$1,
|
50866 | DistributeElementsModule$1,
|
50867 | EditorActionsModule$1,
|
50868 | KeyboardModule$1,
|
50869 | KeyboardMoveSelectionModule,
|
50870 | LabelEditingModule,
|
50871 | ModelingModule,
|
50872 | MoveModule,
|
50873 | PaletteModule$1,
|
50874 | ReplacePreviewModule,
|
50875 | ResizeModule,
|
50876 | SnappingModule,
|
50877 | SearchModule
|
50878 | ];
|
50879 |
|
50880 |
|
50881 |
|
50882 |
|
50883 |
|
50884 |
|
50885 |
|
50886 |
|
50887 | Modeler.prototype._modules = [].concat(
|
50888 | Modeler.prototype._modules,
|
50889 | Modeler.prototype._interactionModules,
|
50890 | Modeler.prototype._modelingModules);
|
50891 |
|
50892 | return Modeler;
|
50893 |
|
50894 | })));
|